pub trait ManagedAgentRuntime: Send + Sync {
// Required methods
fn create<'life0, 'async_trait>(
&'life0 self,
def: ManagedAgentDef,
) -> Pin<Box<dyn Future<Output = Result<AgentHandle, RuntimeError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn start_session<'life0, 'life1, 'async_trait>(
&'life0 self,
agent: &'life1 AgentHandle,
env: Option<EnvironmentConfig>,
) -> Pin<Box<dyn Future<Output = Result<SessionHandle, RuntimeError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn send_event<'life0, 'life1, 'async_trait>(
&'life0 self,
session: &'life1 SessionHandle,
event: UserEvent,
) -> Pin<Box<dyn Future<Output = Result<(), RuntimeError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn stream_events<'life0, 'life1, 'async_trait>(
&'life0 self,
session: &'life1 SessionHandle,
from_seq: Option<u64>,
) -> Pin<Box<dyn Future<Output = Result<BoxStream<'static, SessionEvent>, RuntimeError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn interrupt<'life0, 'life1, 'async_trait>(
&'life0 self,
session: &'life1 SessionHandle,
) -> Pin<Box<dyn Future<Output = Result<(), RuntimeError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn pause<'life0, 'life1, 'async_trait>(
&'life0 self,
session: &'life1 SessionHandle,
) -> Pin<Box<dyn Future<Output = Result<(), RuntimeError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn resume<'life0, 'life1, 'async_trait>(
&'life0 self,
session: &'life1 SessionHandle,
) -> Pin<Box<dyn Future<Output = Result<(), RuntimeError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn status<'life0, 'life1, 'async_trait>(
&'life0 self,
session: &'life1 SessionHandle,
) -> Pin<Box<dyn Future<Output = Result<SessionStatus, RuntimeError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn archive<'life0, 'life1, 'async_trait>(
&'life0 self,
session: &'life1 SessionHandle,
) -> Pin<Box<dyn Future<Output = Result<(), RuntimeError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn delete_session<'life0, 'life1, 'async_trait>(
&'life0 self,
session: &'life1 SessionHandle,
) -> Pin<Box<dyn Future<Output = Result<(), RuntimeError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
}Expand description
The central async trait defining the managed agent lifecycle.
Implementations of this trait encapsulate the full agent lifecycle: creating agents from declarative definitions, starting durable sessions, sending/receiving events, pausing/resuming, interrupting, and archiving.
The trait is provider-agnostic: it takes a ManagedAgentDef with a
ModelRef and behaves identically regardless
of which LLM provider powers the agent.
§Implementors
DefaultManagedAgentRuntime— the default implementation composed fromRunner+ pluggableSessionService+ optional sandbox/memory.
§Design Notes
- All methods return
Result<_, RuntimeError>for structured error handling. stream_eventsreturns aBoxStreamfor SSE-compatible event delivery.from_seqonstream_eventsenablesLast-Event-IDreconnection.- The runtime is
Send + Syncfor use across async task boundaries.
Required Methods§
Sourcefn create<'life0, 'async_trait>(
&'life0 self,
def: ManagedAgentDef,
) -> Pin<Box<dyn Future<Output = Result<AgentHandle, RuntimeError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn create<'life0, 'async_trait>(
&'life0 self,
def: ManagedAgentDef,
) -> Pin<Box<dyn Future<Output = Result<AgentHandle, RuntimeError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Create a managed agent from a declarative definition.
Resolves the ModelRef, builds a runnable
agent, and stores it in the internal registry. Returns an opaque handle
for use with start_session.
Sourcefn start_session<'life0, 'life1, 'async_trait>(
&'life0 self,
agent: &'life1 AgentHandle,
env: Option<EnvironmentConfig>,
) -> Pin<Box<dyn Future<Output = Result<SessionHandle, RuntimeError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn start_session<'life0, 'life1, 'async_trait>(
&'life0 self,
agent: &'life1 AgentHandle,
env: Option<EnvironmentConfig>,
) -> Pin<Box<dyn Future<Output = Result<SessionHandle, RuntimeError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Start a new session for the given agent.
Creates a session in Queued status, initializes the session loop,
and returns a handle for event interaction. The optional
EnvironmentConfig provides env vars and working directory.
Sourcefn send_event<'life0, 'life1, 'async_trait>(
&'life0 self,
session: &'life1 SessionHandle,
event: UserEvent,
) -> Pin<Box<dyn Future<Output = Result<(), RuntimeError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn send_event<'life0, 'life1, 'async_trait>(
&'life0 self,
session: &'life1 SessionHandle,
event: UserEvent,
) -> Pin<Box<dyn Future<Output = Result<(), RuntimeError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Send an event from the client to the agent session.
Dispatches the UserEvent to the session loop. The event type
determines behavior:
user.message— enqueues a message for processinguser.interrupt— signals the session to stop at next boundaryuser.custom_tool_result— delivers a result to a parked tool calluser.tool_confirmation— approves or denies a pending tool use
Sourcefn stream_events<'life0, 'life1, 'async_trait>(
&'life0 self,
session: &'life1 SessionHandle,
from_seq: Option<u64>,
) -> Pin<Box<dyn Future<Output = Result<BoxStream<'static, SessionEvent>, RuntimeError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn stream_events<'life0, 'life1, 'async_trait>(
&'life0 self,
session: &'life1 SessionHandle,
from_seq: Option<u64>,
) -> Pin<Box<dyn Future<Output = Result<BoxStream<'static, SessionEvent>, RuntimeError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Subscribe to the session’s event stream.
Returns a stream of SessionEvents. If from_seq is provided,
replays all events with seq > from_seq before attaching to the
live broadcast (enabling SSE Last-Event-ID reconnection).
Sourcefn interrupt<'life0, 'life1, 'async_trait>(
&'life0 self,
session: &'life1 SessionHandle,
) -> Pin<Box<dyn Future<Output = Result<(), RuntimeError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn interrupt<'life0, 'life1, 'async_trait>(
&'life0 self,
session: &'life1 SessionHandle,
) -> Pin<Box<dyn Future<Output = Result<(), RuntimeError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Interrupt the session at the next safe boundary.
Signals the session loop’s cancellation token. The loop will stop
processing at the next inter-event boundary and emit status.idle.
Sourcefn pause<'life0, 'life1, 'async_trait>(
&'life0 self,
session: &'life1 SessionHandle,
) -> Pin<Box<dyn Future<Output = Result<(), RuntimeError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn pause<'life0, 'life1, 'async_trait>(
&'life0 self,
session: &'life1 SessionHandle,
) -> Pin<Box<dyn Future<Output = Result<(), RuntimeError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Pause the session, checkpointing current state.
Stops consuming new input and persists the current run-state.
The session transitions to Paused status.
Sourcefn resume<'life0, 'life1, 'async_trait>(
&'life0 self,
session: &'life1 SessionHandle,
) -> Pin<Box<dyn Future<Output = Result<(), RuntimeError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn resume<'life0, 'life1, 'async_trait>(
&'life0 self,
session: &'life1 SessionHandle,
) -> Pin<Box<dyn Future<Output = Result<(), RuntimeError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Resume a paused session from its last checkpoint.
Clears the pause flag, rehydrates state if needed, and returns the session to active processing.
Sourcefn status<'life0, 'life1, 'async_trait>(
&'life0 self,
session: &'life1 SessionHandle,
) -> Pin<Box<dyn Future<Output = Result<SessionStatus, RuntimeError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn status<'life0, 'life1, 'async_trait>(
&'life0 self,
session: &'life1 SessionHandle,
) -> Pin<Box<dyn Future<Output = Result<SessionStatus, RuntimeError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Query the current status of a session.
Sourcefn archive<'life0, 'life1, 'async_trait>(
&'life0 self,
session: &'life1 SessionHandle,
) -> Pin<Box<dyn Future<Output = Result<(), RuntimeError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn archive<'life0, 'life1, 'async_trait>(
&'life0 self,
session: &'life1 SessionHandle,
) -> Pin<Box<dyn Future<Output = Result<(), RuntimeError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Archive a session (terminal state).
Sets the session to Archived status and stops the session loop.
Archived sessions retain their event log for read access.
Sourcefn delete_session<'life0, 'life1, 'async_trait>(
&'life0 self,
session: &'life1 SessionHandle,
) -> Pin<Box<dyn Future<Output = Result<(), RuntimeError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn delete_session<'life0, 'life1, 'async_trait>(
&'life0 self,
session: &'life1 SessionHandle,
) -> Pin<Box<dyn Future<Output = Result<(), RuntimeError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Delete a session and its associated data.
Archives the session (if not already terminal) and removes all persisted data including events and checkpoints.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".