Skip to main content

Runner

Struct Runner 

Source
pub struct Runner { /* private fields */ }
Expand description

Runs the agent tree within a session, persisting events and driving plugins.

Implementations§

Source§

impl Runner

Source

pub async fn run_live( &self, user_id: &str, session_id: &str, cfg: LiveRunConfig, opts: RunOptions, ) -> Result<(Arc<dyn LiveSession>, EventStream), AgentError>

Starts a live (bidirectional streaming) run of the agent that should handle the session’s next turn. Returns the session to send input on and the event stream. Dropping the stream at a yield runs the after-run callbacks first, on the still-live invocation context, and then cancels the invocation; dropped inside an await, it cancels at once. The live session task is detached rather than aborted, so a tool call already running finishes on its own (the after-run callbacks do not wait for it).

Must be called inside a Tokio runtime: the live flow spawns tasks. opts is accepted for symmetry with Runner::run and not applied.

The returned stream runs on the consumer’s fiber (FiberStream::consumer); this function’s own work (session lookup, before-run callbacks, starting the live flow) runs in the caller’s future.

Source§

impl Runner

Source

pub fn new(cfg: RunnerConfig) -> Result<Runner, AgentError>

Builds a runner from cfg.

Source

pub fn in_memory( app_name: &str, agent: Arc<dyn Agent>, ) -> Result<Runner, AgentError>

In-memory session, artifact and memory services with session auto-creation, for local development and tests.

Source

pub fn run( &self, user_id: &str, session_id: &str, msg: Option<Content>, cfg: RunConfig, opts: RunOptions, ) -> EventStream

Runs the agent for msg (None for no new message) in the session, yielding its events. Dropping the returned stream ends the invocation, depending on where it is dropped:

  • Dropped at a yield (the consumer stopped reading): work the run had already started (in-flight tool calls, ParallelAgent branches, workflow node tasks) is finished first (each component cancels it plainly and hands it to the invocation’s gadk_agent::Teardowns), then the after-run callbacks run on a spawned task with the invocation’s context still live, and only then is the invocation cancelled.
  • Dropped inside an await (the run was still waiting on a model call, tool or append): the invocation is cancelled at once; started work still finishes before the after-run callbacks, which see the cancellation.

Started work is never aborted, so a tool that ignores cancellation runs to completion and delays the after-run callbacks until it returns.

With compaction configured, a sliding-window compaction runs after the invocation’s events are persisted: inline when the stream ends (its error, if any, is the last item), or on a spawned task after the after-run callbacks when the stream is dropped early, in which case its error is logged. Dropping the stream does not cancel that task.

The stream runs on the consumer’s fiber (FiberStream::consumer: the one current at its first poll, else a new root it keeps); the after-run callbacks of a stream dropped early re-enter that fiber.

Source

pub fn run_with_context( &self, ctx: &InvocationContext, user_id: &str, session_id: &str, msg: Option<Content>, cfg: RunConfig, opts: RunOptions, ) -> EventStream

Runner::run started from a caller’s context; only the context’s plugin-inheritance mark is read (InvocationContext::with_inherited_plugins).

A runner with no plugins of its own, started with a context the agent tool marked, puts the marked (calling run’s) plugin manager in its invocation context, so those plugins also see the sub-run’s agents, models and tools. Any other runner uses only its own plugins. The mark is taken, so it applies to this runner only. Run-level callbacks (on_user_message, before_run, on_event, after_run) always stay with this runner’s own plugins.

Source

pub async fn close(&self) -> Result<(), AgentError>

Closes every plugin.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Runner

§

impl !UnwindSafe for Runner

§

impl Forget for Runner

§

impl Freeze for Runner
where *const ArcInner<RunnerInner> is !null: Freeze, PhantomData<ArcInner<RunnerInner>>: Freeze,

§

impl Move for Runner

§

impl Send for Runner
where Arc<RunnerInner>: Send,

§

impl Sync for Runner
where Arc<RunnerInner>: Sync,

§

impl Unpin for Runner
where Arc<RunnerInner>: Unpin,

§

impl UnsafeUnpin for Runner
where *const ArcInner<RunnerInner> is !null: UnsafeUnpin, PhantomData<ArcInner<RunnerInner>>: UnsafeUnpin,

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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: Sized + 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: Sized + 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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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 = !

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

fn try_from(value: U) -> Result<T, !>

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<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