pub struct AgentRunner<S> { /* private fields */ }Expand description
Typestate-parameterized agent runner.
The type parameter S encodes the current FSM state:
Ready— can callinferAwaitingToolCall— can callprovide_tool_resultsFinished— can access the finalresponse
Implementations§
Source§impl AgentRunner<Ready>
impl AgentRunner<Ready>
Sourcepub fn new(
session_id: impl Into<String>,
model: impl Into<String>,
system_instructions: impl Into<String>,
policy: TurnPolicy,
session: SessionState,
) -> Self
pub fn new( session_id: impl Into<String>, model: impl Into<String>, system_instructions: impl Into<String>, policy: TurnPolicy, session: SessionState, ) -> Self
Create a new runner in the Ready state.
Sourcepub async fn infer(
self,
llm: &(impl LlmPort + ?Sized),
tools: &(impl ToolPort + ?Sized),
compactor: &(impl ContextCompactorPort + ?Sized),
) -> Result<AgentStepResult, AgentError>
pub async fn infer( self, llm: &(impl LlmPort + ?Sized), tools: &(impl ToolPort + ?Sized), compactor: &(impl ContextCompactorPort + ?Sized), ) -> Result<AgentStepResult, AgentError>
Perform LLM inference and transition to the next state.
Returns AgentStepResult::Finished if the LLM produces a final
response, or AgentStepResult::RequiresTool if tool calls are
needed.
§Errors
Returns an error if the LLM call fails or policy limits are exceeded.
Sourcepub async fn run_to_completion(
self,
llm: &(impl LlmPort + ?Sized),
tools: &(impl ToolPort + ?Sized),
compactor: &(impl ContextCompactorPort + ?Sized),
store: &(impl SessionStore + ?Sized),
) -> Result<AgentRunner<Finished>, AgentError>
pub async fn run_to_completion( self, llm: &(impl LlmPort + ?Sized), tools: &(impl ToolPort + ?Sized), compactor: &(impl ContextCompactorPort + ?Sized), store: &(impl SessionStore + ?Sized), ) -> Result<AgentRunner<Finished>, AgentError>
Source§impl AgentRunner<AwaitingToolCall>
impl AgentRunner<AwaitingToolCall>
Sourcepub fn pending_calls(&self) -> &[ToolCall]
pub fn pending_calls(&self) -> &[ToolCall]
Get the pending tool calls that need to be executed.
Sourcepub fn provide_tool_results(
self,
results: Vec<ToolResult>,
) -> AgentRunner<Ready>
pub fn provide_tool_results( self, results: Vec<ToolResult>, ) -> AgentRunner<Ready>
Provide tool execution results and transition back to Ready.
The results must correspond 1:1 with the pending calls in the same order.
Sourcepub fn cancel(self, reason: impl Into<String>) -> AgentRunner<Finished>
pub fn cancel(self, reason: impl Into<String>) -> AgentRunner<Finished>
Cancel the pending tool calls and transition to Finished.
Sourcepub fn require_approval(
self,
reason: impl Into<String>,
) -> AgentRunner<AwaitingApproval>
pub fn require_approval( self, reason: impl Into<String>, ) -> AgentRunner<AwaitingApproval>
Require human approval before executing tool calls.
Transitions to AwaitingApproval state, which prevents
direct tool execution. Callers must explicitly approve()
or deny() to proceed.
This provides compile-time safety: AwaitingToolCall can
directly execute tools via provide_tool_results(), but
AwaitingApproval cannot — it must go through the approval
gate first.
Source§impl AgentRunner<AwaitingApproval>
impl AgentRunner<AwaitingApproval>
Sourcepub fn pending_calls(&self) -> &[ToolCall]
pub fn pending_calls(&self) -> &[ToolCall]
Get the pending tool calls awaiting approval.
Sourcepub fn approval_reason(&self) -> &str
pub fn approval_reason(&self) -> &str
Get the reason approval was required.
Sourcepub fn approve(self) -> AgentRunner<AwaitingToolCall>
pub fn approve(self) -> AgentRunner<AwaitingToolCall>
Approve the tool calls and transition back to AwaitingToolCall.
After approval, call provide_tool_results() with the execution
results to continue the agent loop.
Source§impl AgentRunner<Finished>
impl AgentRunner<Finished>
Sourcepub fn response(&self) -> &AgentResponse
pub fn response(&self) -> &AgentResponse
Get a reference to the final response.
Sourcepub fn into_response(self) -> AgentResponse
pub fn into_response(self) -> AgentResponse
Consume the runner and return the final response.
Sourcepub fn session(&self) -> &SessionState
pub fn session(&self) -> &SessionState
Get the final session state (for persistence).
Sourcepub fn context(&self) -> &RunnerContext
pub fn context(&self) -> &RunnerContext
Get the execution context with usage stats.