Public declaration syntax from forge-rs/crates/forge-agent/src/loop_control.rs Original source SHA-256: c4f923438df92e802bb29640ae0d09666872aa85bba295e29f24dd39fd22b032 Function bodies and constant values are omitted. This is not the complete implementation. Source line 58 pub enum AgentStopCondition { /// Stop when the step count reaches or exceeds this value. /// /// Steps are counted starting from 1 (the first LLM call is step 1). MaxSteps(u32), /// Stop when cumulative token usage reaches or exceeds this value. /// /// Token count includes both prompt and completion tokens across all steps. MaxTokens(u64), /// Stop when a custom predicate returns `true`. /// /// The predicate receives the current step count and total token usage. /// It must be `Send + Sync` for use in async contexts. /// /// # Examples /// /// ``` /// use forge_agent::loop_control::AgentStopCondition; /// /// let stop = AgentStopCondition::Custom(Box::new(|steps, tokens| { /// steps >= 5 && tokens >= 2000 /// })); /// assert!(stop.should_stop(5, 2000)); /// assert!(!stop.should_stop(4, 2000)); /// assert!(!stop.should_stop(5, 1999)); /// ``` Custom(Box bool + Send + Sync>), } Source line 111 pub fn should_stop(&self, steps: u32, total_tokens: u64) -> bool; Source line 138 pub fn description(&self) -> String; Source line 191 pub trait StopWhen: Send + Sync { /// Determines whether the agent's tool loop should stop. /// /// # Arguments /// /// * `messages` - The current conversation history. /// * `step_count` - The number of tool loop steps completed (1-indexed). /// /// # Returns /// /// `true` if the loop should terminate, `false` to continue. fn should_stop(&self, messages: &[ModelMessage], step_count: u32) -> bool; } Source line 225 pub struct StopWhenTextGenerated; Source line 248 pub struct StopWhenMaxSteps(pub u32); Source line 272 pub struct StopWhenToolCalled { } Source line 282 pub fn new(tool_name: impl Into) -> Self; Source line 317 pub struct StopWhenCustom { } Source line 328 pub fn new(predicate: F) -> Self where F: Fn(&[ModelMessage], u32) -> bool + Send + Sync + 'static,; Source line 387 #[async_trait] pub trait PrepareStep: Send + Sync { /// Modifies the message list before the next LLM call. /// /// # Arguments /// /// * `messages` - The mutable message list that will be sent to the model. /// Implementors may add, remove, or modify messages. /// * `step` - The current step number (1-indexed). Step 1 is the first call. /// /// # Returns /// /// `Ok(())` on success, or a [`ForgeAgentError`](crate::error::ForgeAgentError) /// if preparation fails (which aborts the tool loop). /// /// # Errors /// /// Returning an error aborts the tool loop and propagates the error to /// the caller. async fn prepare(&self, messages: &mut Vec, step: u32) -> ForgeAgentResult<()>; } Source line 427 pub struct NoOpPrepare;