Public declaration syntax from forge-rs/crates/forge-generate/src/step.rs Original source SHA-256: d15bc5689f67f7cc67c65f340c8f5b094c158ddd4f6ef2bafa0bbb62ea843d67 Function bodies and constant values are omitted. This is not the complete implementation. Source line 70 pub enum StopCondition { /// Stop after a maximum number of generation steps. MaxSteps(u32), /// Stop when the cumulative token usage exceeds this threshold. MaxTokens(u64), /// Stop when the model's text output contains this substring. TextMatch(String), /// Stop based on a custom predicate applied to each step's result. /// /// The function receives the latest `GenerateResult` and returns `true` /// if generation should stop. Custom(Box bool + Send + Sync>), } Source line 113 #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub enum StopReason { /// The model produced a terminal response (no more tool calls). ModelStopped, /// The maximum step limit was reached. StepLimitReached { /// The number of steps completed. steps: u32, /// The configured step limit. limit: u32, }, /// The cumulative token budget was exceeded. TokenLimitReached { /// Total tokens consumed. total_tokens: u64, /// The configured token limit. limit: u64, }, /// The model's output matched the target text. TextMatchFound { /// The text pattern that was matched. pattern: String, }, /// A custom stop condition was triggered. CustomCondition, } Source line 181 #[derive(Debug, Clone, Serialize, Deserialize)] pub struct StepResult { /// The ordered sequence of generation results, one per step. pub steps: Vec, /// Cumulative token usage across all steps. pub total_usage: Usage, /// Why multi-step generation stopped. pub stop_reason: StopReason } Source line 198 pub fn final_text(&self) -> String; Source line 203 pub fn step_count(&self) -> usize; Source line 208 pub fn completed_naturally(&self) -> bool; Source line 261 pub async fn generate_steps( model: &dyn LanguageModel, initial_messages: Vec, tools: &[ToolDefinition], options: &GenerateOptions, stop: StopCondition, ) -> Result;