pub struct InvocationContext {
pub agent_session: AgentSession,
pub event_tx: Sender<AgentEvent>,
pub middleware: MiddlewareChain,
pub run_config: RunConfig,
pub session_id: Option<String>,
pub artifact_service: Option<Arc<dyn ArtifactService>>,
pub memory_service: Option<Arc<dyn MemoryService>>,
pub session_service: Option<Arc<dyn SessionService>>,
}Expand description
The context object that flows through agent execution. Holds everything a running agent needs.
Note: State is accessed via agent_session.state() — single source of truth.
Fields§
§agent_session: AgentSessionAgentSession wraps SessionHandle with fan-out + middleware. Replaces LiveSender — sends go directly through SessionHandle (one hop).
event_tx: Sender<AgentEvent>Event bus — agents emit events here, application code subscribes.
middleware: MiddlewareChainMiddleware chain for lifecycle hooks.
run_config: RunConfigConfiguration for this run.
session_id: Option<String>Session ID for session-aware runs.
artifact_service: Option<Arc<dyn ArtifactService>>Optional artifact service for this invocation.
memory_service: Option<Arc<dyn MemoryService>>Optional memory service for this invocation.
session_service: Option<Arc<dyn SessionService>>Optional session service for this invocation.
Implementations§
Source§impl InvocationContext
impl InvocationContext
Sourcepub fn new(agent_session: AgentSession) -> Self
pub fn new(agent_session: AgentSession) -> Self
Create a new invocation context with an empty middleware chain.
Sourcepub fn with_middleware(
agent_session: AgentSession,
middleware: MiddlewareChain,
) -> Self
pub fn with_middleware( agent_session: AgentSession, middleware: MiddlewareChain, ) -> Self
Create a new invocation context with a pre-configured middleware chain.
Sourcepub fn emit(&self, event: AgentEvent)
pub fn emit(&self, event: AgentEvent)
Emit an event to all subscribers.
Sourcepub fn subscribe(&self) -> Receiver<AgentEvent>
pub fn subscribe(&self) -> Receiver<AgentEvent>
Subscribe to agent events.
Sourcepub fn with_artifact_service(self, service: Arc<dyn ArtifactService>) -> Self
pub fn with_artifact_service(self, service: Arc<dyn ArtifactService>) -> Self
Set the artifact service for this invocation.
Sourcepub fn with_memory_service(self, service: Arc<dyn MemoryService>) -> Self
pub fn with_memory_service(self, service: Arc<dyn MemoryService>) -> Self
Set the memory service for this invocation.
Sourcepub fn with_session_service(self, service: Arc<dyn SessionService>) -> Self
pub fn with_session_service(self, service: Arc<dyn SessionService>) -> Self
Set the session service for this invocation.