Skip to main content

AgentRunner

Struct AgentRunner 

Source
pub struct AgentRunner<S: CheckpointStore> { /* private fields */ }
Expand description

The robust agent runner — drives the tool call loop with retries, compaction, and multi-format parsing.

Implementations§

Source§

impl<S: CheckpointStore> AgentRunner<S>

Source

pub fn new(runner: Runner<S>, config: RunnerConfig) -> Self

Create a new AgentRunner wrapping an existing Runner.

Source

pub fn with_hook_registry(self, registry: Arc<HookRegistry>) -> Self

Set the hook registry for lifecycle hooks (SessionStart, UserPromptSubmit, PreToolUse, PostToolUse, SessionEnd).

Source

pub fn with_approval_checker(self, checker: Arc<dyn ApprovalChecker>) -> Self

Set an approval checker (PreToolUse). When set, each tool call is checked; if false, the tool is blocked.

Source

pub fn usage(&self) -> &UsageAccumulator

Get the cumulative usage statistics

Source

pub fn add_tool(self, tool: impl Tool + 'static) -> Self

Register a tool for use in the loop.

Source

pub fn add_tools(self, tools: Vec<Arc<dyn Tool>>) -> Self

Register multiple tools at once.

Source

pub fn inner(&self) -> &Runner<S>

Access the underlying runner.

Source

pub fn inner_mut(&mut self) -> &mut Runner<S>

Access the underlying runner mutably.

Source

pub async fn run( &mut self, callable: &dyn Callable, input: &str, project_dir: Option<&Path>, ) -> Result<LoopOutcome>

Run the robust agent loop.

This is the core method — it replaces both AgenticLoop::run (which was a skeleton) and LlmCallable::run (which had a basic loop but no retries, compaction, or multi-format parsing).

§Flow
  1. Call the callable with current input
  2. Parse the response for tool calls (JSON → XML → Markdown)
  3. If tool calls found: execute them, append results to history, loop
  4. If no tool calls: return the final response
  5. Throughout: check limits, retry on errors, compact history, checkpoint
Source§

impl AgentRunner<InMemoryCheckpointStore>

Source

pub fn default_new() -> Self

Create a new AgentRunner with default in-memory store and default config.

Source

pub fn with_config(config: RunnerConfig) -> Self

Create with a specific config.

Auto Trait Implementations§

§

impl<S> !Freeze for AgentRunner<S>

§

impl<S> !RefUnwindSafe for AgentRunner<S>

§

impl<S> Send for AgentRunner<S>

§

impl<S> Sync for AgentRunner<S>

§

impl<S> Unpin for AgentRunner<S>

§

impl<S> UnsafeUnpin for AgentRunner<S>

§

impl<S> !UnwindSafe for AgentRunner<S>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more