pub struct Runner { /* private fields */ }Expand description
Runs the agent tree within a session, persisting events and driving plugins.
Implementations§
Source§impl Runner
impl Runner
Sourcepub async fn run_live(
&self,
user_id: &str,
session_id: &str,
cfg: LiveRunConfig,
opts: RunOptions,
) -> Result<(Arc<dyn LiveSession>, EventStream), AgentError>
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
impl Runner
Sourcepub fn new(cfg: RunnerConfig) -> Result<Runner, AgentError>
pub fn new(cfg: RunnerConfig) -> Result<Runner, AgentError>
Builds a runner from cfg.
Sourcepub fn in_memory(
app_name: &str,
agent: Arc<dyn Agent>,
) -> Result<Runner, AgentError>
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.
Sourcepub fn run(
&self,
user_id: &str,
session_id: &str,
msg: Option<Content>,
cfg: RunConfig,
opts: RunOptions,
) -> EventStream
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.
Sourcepub fn run_with_context(
&self,
ctx: &InvocationContext,
user_id: &str,
session_id: &str,
msg: Option<Content>,
cfg: RunConfig,
opts: RunOptions,
) -> EventStream
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.
Sourcepub async fn close(&self) -> Result<(), AgentError>
pub async fn close(&self) -> Result<(), AgentError>
Closes every plugin.