pub struct Agent {
pub phase: Phase,
/* private fields */
}Expand description
The agent state machine. Purely synchronous; the host drives progress.
Fields§
§phase: PhaseImplementations§
Source§impl Agent
impl Agent
pub fn new(options: AgentOptions) -> Self
Sourcepub fn start_turn(
&mut self,
prompt: AgentMessage,
) -> (Vec<AgentEvent>, Vec<AgentAction>)
pub fn start_turn( &mut self, prompt: AgentMessage, ) -> (Vec<AgentEvent>, Vec<AgentAction>)
Start processing a new prompt.
Sourcepub fn continue_turn(&mut self) -> (Vec<AgentEvent>, Vec<AgentAction>)
pub fn continue_turn(&mut self) -> (Vec<AgentEvent>, Vec<AgentAction>)
Continue from the current transcript without adding a new message.
Sourcepub fn feed_llm_chunk(&mut self, chunk: LlmChunk) -> Vec<AgentEvent>
pub fn feed_llm_chunk(&mut self, chunk: LlmChunk) -> Vec<AgentEvent>
Feed a streaming chunk from the LLM.
Sourcepub fn on_llm_done(
&mut self,
result: LlmResult,
) -> (Vec<AgentEvent>, Vec<AgentAction>)
pub fn on_llm_done( &mut self, result: LlmResult, ) -> (Vec<AgentEvent>, Vec<AgentAction>)
Called by the host when the LLM stream ends.
Sourcepub fn on_tool_done(
&mut self,
tool_call_id: ToolCallId,
result: Result<ToolResult, ToolError>,
) -> (Vec<AgentEvent>, Vec<AgentAction>)
pub fn on_tool_done( &mut self, tool_call_id: ToolCallId, result: Result<ToolResult, ToolError>, ) -> (Vec<AgentEvent>, Vec<AgentAction>)
Called by the host when a tool finishes executing.
Sourcepub fn on_tool_started(&mut self, tool_call_id: ToolCallId) -> Vec<AgentEvent>
pub fn on_tool_started(&mut self, tool_call_id: ToolCallId) -> Vec<AgentEvent>
Called by the host when a tool starts executing. Emits a ToolExecutionUpdate event for trace/observability. Does not change the core state machine phase.
Sourcepub fn on_tool_update(&mut self, update: ToolExecutionUpdate) -> Vec<AgentEvent>
pub fn on_tool_update(&mut self, update: ToolExecutionUpdate) -> Vec<AgentEvent>
Called by the host with a streaming chunk from a running tool. Emits a ToolExecutionUpdate event for trace/observability only. Does NOT add to the canonical model transcript.
Sourcepub fn on_tool_cancelled(
&mut self,
tool_call_id: ToolCallId,
reason: CancelReason,
) -> (Vec<AgentEvent>, Vec<AgentAction>)
pub fn on_tool_cancelled( &mut self, tool_call_id: ToolCallId, reason: CancelReason, ) -> (Vec<AgentEvent>, Vec<AgentAction>)
Called by the host when a tool is cancelled. Treats cancellation like a tool error result so the state machine can advance.
Sourcepub fn steer(&mut self, message: AgentMessage) -> Vec<AgentEvent>
pub fn steer(&mut self, message: AgentMessage) -> Vec<AgentEvent>
Inject a steering message mid-run.
Sourcepub fn follow_up(&mut self, message: AgentMessage)
pub fn follow_up(&mut self, message: AgentMessage)
Queue a follow-up message for after the run would otherwise stop.
Sourcepub fn abort(&mut self) -> Vec<AgentEvent>
pub fn abort(&mut self) -> Vec<AgentEvent>
Abort the current run.
Sourcepub fn state(&self) -> &AgentState
pub fn state(&self) -> &AgentState
Read-only access to current state.