pub struct AgentCtx<'a> { /* private fields */ }Expand description
Handed to an AgentHandler::handle so it can reply, send, request, or fan out
without holding Laser itself. Causality (conversation_id, causal_parent,
root) is wired automatically off the message being handled.
Implementations§
Source§impl<'a> AgentCtx<'a>
impl<'a> AgentCtx<'a>
Sourcepub fn request_at(&self) -> Option<LogPosition>
pub fn request_at(&self) -> Option<LogPosition>
Where the handled record sits on the log, when the runtime knows it.
Sourcepub fn laser(&self) -> &Laser
pub fn laser(&self) -> &Laser
The Laser handle, for operations the ctx helpers do not cover (kv, query, …).
Sourcepub fn message(&self) -> &AgentMessage
pub fn message(&self) -> &AgentMessage
The message currently being handled.
Sourcepub fn session(&self) -> Session
pub fn session(&self) -> Session
The session of the handled record, written as this agent and acting on
the handled record: graph writes take it as source and remembered
items as origin. A lens only: it holds no lease and starts no
heartbeat. Its pending_control
reports the pause and cancel requests the runtime observed.
Sourcepub async fn respond(
&self,
payload: impl Into<Vec<u8>>,
) -> Result<(), LaserError>
pub async fn respond( &self, payload: impl Into<Vec<u8>>, ) -> Result<(), LaserError>
Reply on the agent’s configured respond_on topic, chaining causality
(causal_parent = this message) and routing back to its sender. Errors with
NoRespondTopic if the agent was built without respond_on.
An agent built with a signing key answers a correlated command with a signed AGDX response instead, so a verifying caller (and the contract path’s signer binding) accepts this agent’s terminal and no one else’s.
Sourcepub async fn reply_on(
&self,
topic: AgentTopic<'_>,
payload: impl Into<Vec<u8>>,
) -> Result<(), LaserError>
pub async fn reply_on( &self, topic: AgentTopic<'_>, payload: impl Into<Vec<u8>>, ) -> Result<(), LaserError>
A reply provenance for topic, chained off this message. The caller sets
routing and usage as needed. Useful when replying somewhere other than respond_on.
Sourcepub async fn send(
&self,
topic: AgentTopic<'_>,
payload: impl Into<Vec<u8>>,
provenance: &Provenance,
) -> Result<(), LaserError>
pub async fn send( &self, topic: AgentTopic<'_>, payload: impl Into<Vec<u8>>, provenance: &Provenance, ) -> Result<(), LaserError>
Send payload to topic with an explicit provenance (no automatic causality).
Sourcepub async fn request(
&self,
request_topic: AgentTopic<'_>,
reply_topic: AgentTopic<'_>,
payload: impl Into<Vec<u8>>,
provenance: &Provenance,
timeout: Duration,
) -> Result<AgentMessage, LaserError>
pub async fn request( &self, request_topic: AgentTopic<'_>, reply_topic: AgentTopic<'_>, payload: impl Into<Vec<u8>>, provenance: &Provenance, timeout: Duration, ) -> Result<AgentMessage, LaserError>
Send a request and await its correlated reply (see Laser::request).
Sourcepub async fn respond_input(
&self,
reply_topic: AgentTopic<'static>,
response: impl Into<Vec<u8>>,
) -> Result<(), LaserError>
pub async fn respond_input( &self, reply_topic: AgentTopic<'static>, response: impl Into<Vec<u8>>, ) -> Result<(), LaserError>
Resolve the human-in-the-loop interrupt being handled: publish an AGDX
response on reply_topic carrying the handled command’s interrupt
correlation, so the paused Agdx::request_input
caller resumes with response. The pairing is the correlation, so the
reply reaches the right waiter even when several share reply_topic.
An agent built with a signing key signs the response, so a verifying
interrupt caller accepts this agent’s decision and no one else’s.
Errors if the handled message is not an AGDX envelope carrying a
correlation, or the agent was built without an id.
Sourcepub async fn approval_gate(
&self,
reply_topic: AgentTopic<'_>,
prompt: impl Into<Vec<u8>>,
timeout: Duration,
) -> Result<Vec<u8>, LaserError>
pub async fn approval_gate( &self, reply_topic: AgentTopic<'_>, prompt: impl Into<Vec<u8>>, timeout: Duration, ) -> Result<Vec<u8>, LaserError>
Pause this handler on a human decision: publish prompt as an interrupt on
the human-input topic and await the approver’s correlated reply on
reply_topic, up to timeout, chained to the handled conversation. Returns
the decision body on approval, or LaserError::Rejected when the approver
rejects (the approver answers with respond_input).
A convenience over Agdx::request_input,
so it adds nothing to the wire. Errors if the agent was built without an id.
Sourcepub fn spawn_subconversation(&self) -> Result<Provenance, LaserError>
pub fn spawn_subconversation(&self) -> Result<Provenance, LaserError>
A child conversation of the handled message, linked by parent/root ids.
Sourcepub async fn fan_out(
&self,
selector: CapabilitySelector,
payload: impl Into<Vec<u8>>,
policy: GatherPolicy,
deadline: Duration,
) -> Result<Gather, LaserError>
pub async fn fan_out( &self, selector: CapabilitySelector, payload: impl Into<Vec<u8>>, policy: GatherPolicy, deadline: Duration, ) -> Result<Gather, LaserError>
Fan out to every agent advertising selector’s skill, gathering replies
under policy within deadline. Each branch is a sub-conversation routed
to one agent’s own inbox, resolved through the ctx’s
InboxRoute (the per-agent live-presence inbox
by default, or a fixed topic the caller set at build time), never a shared
topic name baked into the SDK. Replies are collected on the orchestrator’s
own response topic (respond_on), so a deployment that scopes each user
to its own stream and each workflow to its own topic routes correctly.
A target that resolves no inbox (advertised none, or refresh_presence
surfaced none) is a per-branch Gather::failures entry, never silently
rerouted. Under GatherPolicy::Quorum the remaining branches are dropped
once the quorum lands rather than waited on (signing a cancel to the losing
branches on the control channel is a follow-on). Errors only on an
infrastructure failure (no capable agent, no response topic, registry read),
not on a branch failure.
Auto Trait Implementations§
impl<'a> !RefUnwindSafe for AgentCtx<'a>
impl<'a> !UnwindSafe for AgentCtx<'a>
impl<'a> Freeze for AgentCtx<'a>
impl<'a> Send for AgentCtx<'a>
impl<'a> Sync for AgentCtx<'a>
impl<'a> Unpin for AgentCtx<'a>
impl<'a> UnsafeUnpin for AgentCtx<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.