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.
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.
Trait Implementations§
Auto Trait Implementations§
impl<S> Freeze for AgentRunner<S>where
S: Freeze,
impl<S> RefUnwindSafe for AgentRunner<S>where
S: RefUnwindSafe,
impl<S> Send for AgentRunner<S>where
S: Send,
impl<S> Sync for AgentRunner<S>where
S: Sync,
impl<S> Unpin for AgentRunner<S>where
S: Unpin,
impl<S> UnsafeUnpin for AgentRunner<S>where
S: UnsafeUnpin,
impl<S> UnwindSafe for AgentRunner<S>where
S: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more