pub struct ToolLoopExecutor { /* private fields */ }tool-loop only.Expand description
An AgentExecutor that answers each message by running a ToolLoop.
The loop is wholly inside one A2A task: the caller sees Working, the
answer artifact (ANSWER_ARTIFACT_ID), the trace artifact
(TRACE_ARTIFACT_ID) when a tool ran, and Completed. The prompt is
the message’s text parts, joined by newlines; a message with none is
refused as an invalid request.
A run that ends without an answer fails the task with the failure-class
extension (a2a_protocol_types::failure): transient when the model
provider may come back (HTTP 429, 502, 503 or 504, a timeout, no
connection), internal for any other provider failure or a tool that
returned ToolError::Fatal, budget-exhausted when the model was
still calling tools at the turn bound, the caller’s budget
(RequestContext::budget, ADR 0023) ran out (its token usage charged to
the tokens meter), or the model hit its output limit before writing
any text, and policy-refusal when the provider’s content filter
withheld the answer. A final reply with no text is such a run
(LoopError::EmptyAnswer). The status message says which, in words.
Cancellation ends the run at the next turn or call, with nothing
written: the cancel path writes Canceled.
A reply that has text but stopped at the output limit completes the task:
the answer artifact’s metadata and the Completed status message both
carry FINISH_REASON_METADATA_KEY, so a caller can tell a cut-off
answer from one that ended by itself.
Each run’s call keys are scoped to the task and the message it answers (ADR 0026): another message to the same task is new work, with new keys.
with_drafts also streams each turn’s text as it
arrives, to an artifact of its own.
Implementations§
Source§impl ToolLoopExecutor
impl ToolLoopExecutor
Sourcepub const fn new(tool_loop: ToolLoop) -> ToolLoopExecutor
pub const fn new(tool_loop: ToolLoop) -> ToolLoopExecutor
An executor running tool_loop for each message.
Sourcepub const fn with_steering(self) -> ToolLoopExecutor
pub const fn with_steering(self) -> ToolLoopExecutor
Reads the turn’s steering inbox
(RequestContext::inbox) before each
model turn, and adds each message’s text to the conversation as a
user turn, so a caller can correct course while the run works (ADR
0036). Off by default. Needs a handler built with
with_steering; without
one there is no inbox and this does nothing.
The text is the sender’s: it is user text like the prompt, with the
sender’s authority over the task and no more. It cannot cancel the run
(CancelTask does), approve an action, or lift a budget. A message
that arrives during the turn that answers is not read: the run is
over, and the message is counted as unread.
Sourcepub const fn with_drafts(self) -> ToolLoopExecutor
pub const fn with_drafts(self) -> ToolLoopExecutor
Streams each turn’s text, as the model sends it, to a draft artifact
of the turn’s own, draft-1, draft-2 and so on
(draft_artifact_id), each closed with
lastChunk when the next turn starts or the run ends; the answer
artifact is sent at the end, as without (audit L5). A turn’s text is
known to be the answer only when the turn ends, which is why it is
not streamed into the answer itself. Needs a model that streams
(ToolModel::complete_streaming;
OpenAiChatModel does); with one that
does not, no draft is sent. Off by default, since the drafts are
artifacts a client reading every artifact would now see.
Source§impl ToolLoopExecutor
impl ToolLoopExecutor
Sourcepub fn with_skills(
self,
catalog: &SkillCatalog,
) -> Result<ToolLoopExecutor, DuplicateTool>
pub fn with_skills( self, catalog: &SkillCatalog, ) -> Result<ToolLoopExecutor, DuplicateTool>
Gives the loop the skills in catalog: the catalog goes at the end of
the system prompt, and the model gets activate_skill (its name a
JSON Schema enum of the skills’ names) and, when some skill bundles
files, read_skill_file. A call to either is a tool call like any
other: traced as an execute_tool span, counted among the run’s tool
calls and bounded by the turn limit and the caller’s budget. No script
is run, and no skill adds a tool or approves one.
A catalog with no skills changes nothing: an empty catalog and a tool with no valid argument would only confuse the model.
The prompt is appended to the loop’s own preamble, after a blank line, so this is called on an executor whose loop already has its preamble (the executor has no way to set one afterwards).
§Errors
DuplicateTool when the loop’s tools already include one named
activate_skill or read_skill_file. The executor is consumed.
Trait Implementations§
Source§impl AgentExecutor for ToolLoopExecutor
impl AgentExecutor for ToolLoopExecutor
Source§fn execute<'a>(
&'a self,
ctx: &'a RequestContext,
queue: &'a (dyn EventQueueWriter + 'static),
) -> Pin<Box<dyn Future<Output = Result<(), A2aError>> + Send + 'a>>
fn execute<'a>( &'a self, ctx: &'a RequestContext, queue: &'a (dyn EventQueueWriter + 'static), ) -> Pin<Box<dyn Future<Output = Result<(), A2aError>> + Send + 'a>>
Source§fn cancel<'a>(
&'a self,
ctx: &'a RequestContext,
queue: &'a (dyn EventQueueWriter + 'static),
) -> Pin<Box<dyn Future<Output = Result<(), A2aError>> + Send + 'a>>
fn cancel<'a>( &'a self, ctx: &'a RequestContext, queue: &'a (dyn EventQueueWriter + 'static), ) -> Pin<Box<dyn Future<Output = Result<(), A2aError>> + Send + 'a>>
Source§fn resumes_after_hand_off(&self) -> bool
fn resumes_after_hand_off(&self) -> bool
Auto Trait Implementations§
impl !RefUnwindSafe for ToolLoopExecutor
impl !UnwindSafe for ToolLoopExecutor
impl Forget for ToolLoopExecutor
impl Freeze for ToolLoopExecutor
impl Move for ToolLoopExecutor
impl Send for ToolLoopExecutor
impl Sync for ToolLoopExecutor
impl Unpin for ToolLoopExecutor
impl UnsafeUnpin for ToolLoopExecutor
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].