pub struct InvocationContext { /* private fields */ }Expand description
The context of one agent invocation.
Implementations§
Source§impl InvocationContext
impl InvocationContext
Sourcepub fn builder() -> ContextBuilder
pub fn builder() -> ContextBuilder
A ContextBuilder with documented defaults.
Sourcepub fn artifacts(&self) -> Option<Arc<dyn Artifacts>>
pub fn artifacts(&self) -> Option<Arc<dyn Artifacts>>
The artifacts of the session: tracked (records saves into the actions’ artifact_delta)
when the context has actions, as for callback and tool contexts; the raw handle otherwise;
None without an artifact service.
Sourcepub fn memory(&self) -> Option<Arc<dyn Memory>>
pub fn memory(&self) -> Option<Arc<dyn Memory>>
The memory of the user, if a memory service is configured.
Sourcepub fn isolation_scope(&self) -> String
pub fn isolation_scope(&self) -> String
The isolation scope; events with a different non-empty scope are not visible.
Sourcepub fn run_config(&self) -> &RunConfig
pub fn run_config(&self) -> &RunConfig
The run configuration.
Sourcepub fn end_invocation(&self)
pub fn end_invocation(&self)
Ends the invocation: the agent stops at its next check.
Sourcepub fn activation_id(&self) -> ActivationId
pub fn activation_id(&self) -> ActivationId
The identity of this context’s end flag (see ActivationId): equal for every callback
and tool context of one agent run, distinct across runs and forks, never reused.
Sourcepub fn resumed_input(&self, interrupt_id: &str) -> Option<Value>
pub fn resumed_input(&self, interrupt_id: &str) -> Option<Value>
This context’s resume input for interrupt_id.
Sourcepub fn cancellation_token(&self) -> &CancellationToken
pub fn cancellation_token(&self) -> &CancellationToken
The cancellation token.
Sourcepub fn cancel_with_cause(&self, cause: CancelCause)
pub fn cancel_with_cause(&self, cause: CancelCause)
Cancels this context’s own
cancel scope with cause, unless it is already cancelled (first cause wins). Contexts
sharing the scope (every delta but a raw cancellation_token, and contexts derived by
Context::with_agent_cancel from it) are cancelled
with it.
Sourcepub fn cause(&self) -> Option<CancelCause>
pub fn cause(&self) -> Option<CancelCause>
The cancel cause: None while the cancellation token is live; else the cause recorded
by the nearest cancelled scope walking outward from this context’s own (a scope cancelled
only by its parent defers to it), else Canceled (e.g. a raw token.cancel()).
Sourcepub fn plugin_manager(&self) -> Option<Arc<PluginManager>>
pub fn plugin_manager(&self) -> Option<Arc<PluginManager>>
The plugin manager, if plugins are configured.
Sourcepub fn with_inherited_plugins(&self) -> InvocationContext
pub fn with_inherited_plugins(&self) -> InvocationContext
A derived context marked so that the
next runner started with it (Runner::run_with_context) keeps this context’s plugin
manager (InvocationContext::plugin_manager) when that runner has no
plugins of its own. Only the agent tool sets this mark, for the sub-runner it starts; any
other runner uses only its own plugins. The receiver is unchanged.
Sourcepub fn take_inherited_plugins(
&self,
) -> (InvocationContext, Option<Arc<PluginManager>>)
pub fn take_inherited_plugins( &self, ) -> (InvocationContext, Option<Arc<PluginManager>>)
Takes the plugin manager marked by
InvocationContext::with_inherited_plugins (None without a mark) and a derived context
with the mark cleared, so that the mark applies to one runner only and not to runners
started further down.
Sourcepub fn with_graph_resume_done(&self) -> InvocationContext
pub fn with_graph_resume_done(&self) -> InvocationContext
A derived context marked so that resuming a nested graph workflow is done for it and every context derived from it (a loop agent runs its later passes with it: only the first pass narrows to the sub-agents holding the callers of the user’s function responses). The receiver is unchanged.
Sourcepub fn graph_resume_done(&self) -> bool
pub fn graph_resume_done(&self) -> bool
Whether the context is marked by InvocationContext::with_graph_resume_done.
Sourcepub fn parent_map(&self) -> Option<Arc<ParentMap>>
pub fn parent_map(&self) -> Option<Arc<ParentMap>>
The agent tree’s parent map, if set.
Sourcepub fn session_service(&self) -> Option<Arc<dyn SessionService>>
pub fn session_service(&self) -> Option<Arc<dyn SessionService>>
The session service, if set.
Sourcepub fn bound_modes(&self) -> &BoundModes
pub fn bound_modes(&self) -> &BoundModes
The bound agent modes.
Sourcepub fn live_session_resumption_handle(&self) -> String
pub fn live_session_resumption_handle(&self) -> String
The active live session’s resumption handle, used to resume a bidirectional streaming session after a reconnect.
Sourcepub fn set_live_session_resumption_handle(&self, handle: &str)
pub fn set_live_session_resumption_handle(&self, handle: &str)
Stores the latest handle received from the model, visible to every context of this invocation.
Sourcepub fn with_delta(&self, d: ContextDelta) -> InvocationContext
pub fn with_delta(&self, d: ContextDelta) -> InvocationContext
A derived context with d applied; the receiver is unchanged.
Sourcepub fn into_context(self) -> Context
pub fn into_context(self) -> Context
The same fields, seen as a Context.
Sourcepub fn as_readonly(&self) -> &ReadonlyContext
pub fn as_readonly(&self) -> &ReadonlyContext
The read-only view.
Source§impl InvocationContext
impl InvocationContext
Sourcepub fn teardowns(&self) -> Option<Arc<Teardowns>>
pub fn teardowns(&self) -> Option<Arc<Teardowns>>
The invocation’s teardown registry, if the runner installed one
(crate::ContextBuilder::teardowns).
Sourcepub fn register_teardown(&self, task: JoinHandle<()>)
pub fn register_teardown(&self, task: JoinHandle<()>)
Hands an already spawned task that finishes started work to the invocation’s teardown
registry; without a registry the task is detached (it still runs to completion). A task
registered after Teardowns::wait returned (the runner’s after-run already started) is
never awaited: it runs to completion detached.
Sourcepub fn spawn_teardown<F>(&self, work: F)
pub fn spawn_teardown<F>(&self, work: F)
Spawns work (the rest of the started work of a component being dropped) on the current
tokio runtime, in the current fiber and tracing span, and registers it
(InvocationContext::register_teardown). Outside a runtime work is dropped (there is
nothing to run it on).
Methods from Deref<Target = ReadonlyContext>§
Sourcepub fn user_content(&self) -> Option<&Content>
pub fn user_content(&self) -> Option<&Content>
The user content that started the invocation.
Sourcepub fn invocation_id(&self) -> &str
pub fn invocation_id(&self) -> &str
The invocation id.
Sourcepub fn agent_name(&self) -> String
pub fn agent_name(&self) -> String
The name of the current agent.
Sourcepub fn readonly_state(&self) -> Arc<dyn ReadonlyState> ⓘ
pub fn readonly_state(&self) -> Arc<dyn ReadonlyState> ⓘ
The session’s state, without the actions overlay.
Sourcepub fn user_id(&self) -> &str
pub fn user_id(&self) -> &str
The session’s user id, read from the session on every call, never cached.
Sourcepub fn session_id(&self) -> &str
pub fn session_id(&self) -> &str
The session id, read from the session on every call.
Sourcepub fn identity(&self) -> Identity
pub fn identity(&self) -> Identity
The invocation’s identity from one
session read, then one accessor call per field, so the identity cannot be torn.
Sourcepub fn cancellation_token(&self) -> &CancellationToken
pub fn cancellation_token(&self) -> &CancellationToken
The invocation’s cancellation token: the
same token InvocationContext::cancellation_token
returns, so a toolset’s tools can stop when the invocation is cancelled.
Sourcepub fn record_prompt(&self, used: PromptUse)
pub fn record_prompt(&self, used: PromptUse)
Records used as the prompt version this context’s agent rendered its instruction from,
replacing an earlier record of the same agent. Every context of the invocation (including
fresh_invocation deltas such as parallel branches) sees it; each runner invocation starts
with none. Records are keyed by agent name, so two agents with the same name in one
invocation share one record.
Sourcepub fn clear_recorded_prompt(&self)
pub fn clear_recorded_prompt(&self)
Removes the prompt version recorded for this context’s agent.
Sourcepub fn recorded_prompt(&self) -> Option<PromptUse>
pub fn recorded_prompt(&self) -> Option<PromptUse>
The prompt version recorded for this context’s agent, if any.