Skip to main content

InvocationContext

Struct InvocationContext 

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

The context of one agent invocation.

Implementations§

Source§

impl InvocationContext

Source

pub fn builder() -> ContextBuilder

A ContextBuilder with documented defaults.

Source

pub fn agent(&self) -> Arc<dyn Agent> ⓘ

The current agent.

Source

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.

Source

pub fn memory(&self) -> Option<Arc<dyn Memory>>

The memory of the user, if a memory service is configured.

Source

pub fn session(&self) -> Arc<dyn Session> ⓘ

The session.

Source

pub fn isolation_scope(&self) -> String

The isolation scope; events with a different non-empty scope are not visible.

Source

pub fn run_config(&self) -> &RunConfig

The run configuration.

Source

pub fn end_invocation(&self)

Ends the invocation: the agent stops at its next check.

Source

pub fn ended(&self) -> bool

Whether the invocation has ended.

Source

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.

Source

pub fn resumed_input(&self, interrupt_id: &str) -> Option<Value>

This context’s resume input for interrupt_id.

Source

pub fn cancellation_token(&self) -> &CancellationToken

The cancellation token.

Source

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.

Source

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()).

Source

pub fn platform(&self) -> &Platform

The platform (time, UUIDs, task runner).

Source

pub fn plugin_manager(&self) -> Option<Arc<PluginManager>>

The plugin manager, if plugins are configured.

Source

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.

Source

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.

Source

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.

Source

pub fn graph_resume_done(&self) -> bool

Whether the context is marked by InvocationContext::with_graph_resume_done.

Source

pub fn parent_map(&self) -> Option<Arc<ParentMap>>

The agent tree’s parent map, if set.

Source

pub fn session_service(&self) -> Option<Arc<dyn SessionService>>

The session service, if set.

Source

pub fn bound_modes(&self) -> &BoundModes

The bound agent modes.

Source

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.

Source

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.

Source

pub fn with_delta(&self, d: ContextDelta) -> InvocationContext

A derived context with d applied; the receiver is unchanged.

Source

pub fn into_context(self) -> Context

The same fields, seen as a Context.

Source

pub fn as_readonly(&self) -> &ReadonlyContext

The read-only view.

Source§

impl InvocationContext

Source

pub fn teardowns(&self) -> Option<Arc<Teardowns>>

The invocation’s teardown registry, if the runner installed one (crate::ContextBuilder::teardowns).

Source

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.

Source

pub fn spawn_teardown<F>(&self, work: F)
where F: Future<Output = ()> + Send + 'static,

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

Source

pub fn user_content(&self) -> Option<&Content>

The user content that started the invocation.

Source

pub fn invocation_id(&self) -> &str

The invocation id.

Source

pub fn agent_name(&self) -> String

The name of the current agent.

Source

pub fn readonly_state(&self) -> Arc<dyn ReadonlyState> ⓘ

The session’s state, without the actions overlay.

Source

pub fn user_id(&self) -> &str

The session’s user id, read from the session on every call, never cached.

Source

pub fn app_name(&self) -> &str

The session’s app name, read from the session on every call.

Source

pub fn session_id(&self) -> &str

The session id, read from the session on every call.

Source

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.

Source

pub fn branch(&self) -> String

The branch, like agent_1.agent_2.agent_3.

Source

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.

Trait Implementations§

Source§

impl Clone for InvocationContext

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Deref for InvocationContext

Source§

type Target = ReadonlyContext

The resulting type after dereferencing.
Source§

fn deref(&self) -> &ReadonlyContext

Dereferences the value.

Auto Trait Implementations§

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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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