Skip to main content

StopCondition

Trait StopCondition 

Source
pub trait StopCondition: Send + Sync {
    // Required method
    fn should_stop(&self, steps: &[Step]) -> bool;
}
Expand description

A condition, checked after every round trip alongside max_steps, that can end run_text early.

Attach one or more with PendingTextRequest::with_stop_when. The loop stops as soon as any attached condition (or max_steps, or the model simply not asking for another tool call) says to – useful for things max_steps alone can’t express, like stopping once a specific tool has been called, or once a cumulative token budget is spent.

use llmprism::text::Step;
use llmprism::tool_loop::StopCondition;

struct ToolWasCalled(&'static str);

impl StopCondition for ToolWasCalled {
    fn should_stop(&self, steps: &[Step]) -> bool {
        steps
            .last()
            .is_some_and(|step| step.tool_calls.iter().any(|call| call.name == self.0))
    }
}

Required Methods§

Source

fn should_stop(&self, steps: &[Step]) -> bool

steps is every round trip so far, oldest first, including the one that was just produced – return true to stop before running any tool calls that step asked for.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<F> StopCondition for F
where F: Fn(&[Step]) -> bool + Send + Sync,