Public declaration syntax from forge-rs/crates/forge-agent/src/observer.rs Original source SHA-256: 6464c48499058684caf9babfb3984946a35430473c15536e6ddb29a4be261d10 Function bodies and constant values are omitted. This is not the complete implementation. Source line 46 #[async_trait] pub trait AgentLoopObserver: Send + Sync { /// Called at the start of each tool loop turn. /// /// # Arguments /// /// * `turn` - The turn number (1-indexed). async fn on_turn_start(&self, _turn: u32) ; /// Called at the end of each tool loop turn. /// /// # Arguments /// /// * `turn` - The turn number (1-indexed). /// * `usage` - Cumulative token usage after this turn. async fn on_turn_end(&self, _turn: u32, _usage: Usage) ; /// Called when the model produces a text delta (during streaming). /// /// # Arguments /// /// * `text` - The text fragment. async fn on_text_delta(&self, _text: &str) ; /// Called when the model starts a tool call. /// /// # Arguments /// /// * `tool_call` - The tool call being initiated. async fn on_tool_call_start(&self, _tool_call: &ToolCall) ; /// Called when a tool call completes. /// /// Legacy hook -- prefer [`on_tool_invocation`](Self::on_tool_invocation) for /// per-tool latency, status (succeeded / failed / authorization-denied / /// not-found), and the tool name. This hook is preserved for backward /// compatibility and continues to fire alongside `on_tool_invocation`. /// /// # Arguments /// /// * `tool_call_id` - The tool call ID. /// * `result` - The result content. /// * `is_error` - Whether the tool execution failed. async fn on_tool_call_end(&self, _tool_call_id: &str, _result: &str, _is_error: bool) ; /// Called when a tool call completes, with the full invocation record. /// /// Symmetric counterpart to [`on_tool_call_start`](Self::on_tool_call_start) /// -- this hook receives the tool name, wall-clock duration, and the typed /// `ToolInvocationStatus` so observers can build per-tool latency /// histograms, structured audit entries, or richer UI states without /// having to maintain their own start-time bookkeeping. /// /// Default implementation is a no-op so existing observers compile /// unchanged. The streaming tool loop fires both this and /// [`on_tool_call_end`](Self::on_tool_call_end) for every invocation. /// /// # Arguments /// /// * `record` - The complete invocation record. async fn on_tool_invocation(&self, _record: &ToolInvocationRecord) ; /// Called when a model inference call completes. /// /// The record carries model/provider ids, token counts, latency, outcome, /// and governed prompt/completion refs. It does not carry raw prompt or /// completion text. /// /// # Arguments /// /// * `record` - The complete model inference record. async fn on_model_inference_completed(&self, _record: &ModelInferenceRecord) ; /// Called when a parent agent delegates work to a sub-agent. /// /// The record carries child agent/run identifiers and governed refs for /// instruction or handoff context. /// /// # Arguments /// /// * `record` - The delegation record. async fn on_subagent_delegation_started(&self, _record: &SubAgentDelegationRecord) ; /// Called when a stream chunk is received. /// /// # Arguments /// /// * `chunk` - The stream chunk. async fn on_stream_chunk(&self, _chunk: &StreamChunk) ; /// Called when the agent loop completes successfully. /// /// # Arguments /// /// * `final_message` - The final assistant message. /// * `total_turns` - Total number of turns executed. /// * `total_usage` - Total token usage across all turns. async fn on_complete( &self, _final_message: &ModelMessage, _total_turns: u32, _total_usage: Usage, ) ; /// Called when the agent loop encounters an error. /// /// # Arguments /// /// * `error` - A human-readable error description. /// * `turn` - The turn in which the error occurred. async fn on_error(&self, _error: &str, _turn: u32) ; /// Called when the agent loop is stopped by a stop condition. /// /// # Arguments /// /// * `reason` - Why the loop stopped. /// * `turn` - The turn at which the loop stopped. async fn on_stopped(&self, _reason: FinishReason, _turn: u32) ; } Source line 170 pub struct NoOpObserver;