pub struct RuntimeInvocation { /* private fields */ }Expand description
Transport-neutral invocation facade over AgentRuntime.
Wraps an Arc<AgentRuntime> and exposes emit / on semantics without
pulling in any wire protocol. Transport adapters build on top of this.
Implementations§
Source§impl RuntimeInvocation
impl RuntimeInvocation
Sourcepub fn new(runtime: Arc<AgentRuntime>) -> Self
pub fn new(runtime: Arc<AgentRuntime>) -> Self
Wraps a runtime in the invocation facade.
Uses MemorySessionDataStore as the default session data backend.
Sourcepub fn with_session_store(
runtime: Arc<AgentRuntime>,
store: Arc<dyn SessionDataStore>,
) -> Self
pub fn with_session_store( runtime: Arc<AgentRuntime>, store: Arc<dyn SessionDataStore>, ) -> Self
Wraps a runtime with a custom SessionDataStore backend.
Sourcepub fn runtime(&self) -> &AgentRuntime
pub fn runtime(&self) -> &AgentRuntime
Returns a reference to the underlying runtime.
Sourcepub fn set_data<T: Send + Sync + 'static>(&self, val: T)
pub fn set_data<T: Send + Sync + 'static>(&self, val: T)
Registers a typed value to be injected into every Control created
by emit and on.
This is analogous to actix-web::web::Data<T> — call it once during
setup, and every handler can retrieve the value via Control::data.
Sourcepub async fn emit<F, Fut>(&self, f: F) -> Result<RunOutput, InvocationError>where
F: FnOnce(InvocationSession, Control) -> Fut + Send,
Fut: Future<Output = EmitRequest> + Send,
pub async fn emit<F, Fut>(&self, f: F) -> Result<RunOutput, InvocationError>where
F: FnOnce(InvocationSession, Control) -> Fut + Send,
Fut: Future<Output = EmitRequest> + Send,
Emits a run request built by f and executes it via AgentRuntime::run.
The closure receives an InvocationSession (with no session known yet)
and a fresh Control handle, then returns an EmitRequest. The
request is converted to a RunRequest and handed to the runtime.
Cancellation is cooperative: Control::is_cancelled is checked before
the closure runs and before run is called. If cancelled,
InvocationError::TaskFailed is returned. Because Control is created
internally, external cancellation of emit is not exposed by the core
API — transport adapters wrap emit to provide that.
§Errors
Returns InvocationError::TaskFailed when cancelled, or
InvocationError::Runtime when the underlying run fails.
Sourcepub async fn on<F, Fut>(
&self,
kind: EventKind,
f: F,
) -> Result<InvocationHandle, InvocationError>where
F: Fn(RuntimeEventEnvelope, InvocationSession, Control) -> Fut + Send + Sync + 'static,
Fut: Future<Output = ()> + Send + 'static,
pub async fn on<F, Fut>(
&self,
kind: EventKind,
f: F,
) -> Result<InvocationHandle, InvocationError>where
F: Fn(RuntimeEventEnvelope, InvocationSession, Control) -> Fut + Send + Sync + 'static,
Fut: Future<Output = ()> + Send + 'static,
Registers an event handler for events matching kind.
Events are sourced from AgentRuntime::subscribe. When an event
matches, the handler runs on a freshly spawned task so slow handlers
do not block event reception. The returned InvocationHandle aborts
the listener on drop.
§Errors
Returns InvocationError::InvalidRequest only if subscription setup
is rejected. In the current implementation this always succeeds.
Trait Implementations§
Source§impl Clone for RuntimeInvocation
impl Clone for RuntimeInvocation
Source§fn clone(&self) -> RuntimeInvocation
fn clone(&self) -> RuntimeInvocation
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more