Skip to main content

ToolOutput

Struct ToolOutput 

pub struct ToolOutput {
Show 14 fields pub content: String, pub is_error: bool, pub artifacts: Vec<Artifact>, pub answer: Option<String>, pub ends_turn: bool, pub sandbox: SandboxUsage, pub repeat_key: Option<Box<String>>, pub plan: Option<Box<Plan>>, pub kept: Option<Box<KeptOutput>>, pub reported: Vec<RunId>, pub pinned: bool, pub images: Vec<ImageRef>, pub loaded: Vec<Loaded>, pub kept_images: Box<[KeptImage]>,
}
Expand description

What a successful tool call returns.

Journaled, hence serializable.

Fields§

§content: String

Text handed back to the model as the tool result.

§is_error: bool

Whether the tool reports failure. The model still sees content (the run does not fail); the tool message is marked is_error.

§artifacts: Vec<Artifact>

Outputs of the run, emitted as [RunEvent::Artifact] (durable, see RunView::artifacts).

§answer: Option<String>

Words the tool announces as the run’s answer: when the run finishes, they are its output’s text (the A2A completed status message), not the closing words of the model. See announcing. Never read from an error result.

Journaled with the result, so a replay announces the same words; absent from a journal written before it existed, and not written while it is None.

§ends_turn: bool

The announced answer is also the end of the turn: once the calls the model asked for in this turn are answered, the run finishes with it and the model is not called again. See final_answer. Ignored without an answer, and never read from an error result.

Absent from a journal written before it existed, and not written while it is false.

§sandbox: SandboxUsage

The time the call’s commands ran in a sandbox, as the call reported it (ToolCtx::report_sandbox); the agent loop fills it in from what the call reported. Journaled with the result, so the run counts it once, and a replay counts the same.

Absent from a journal written before it existed, and not written while empty.

§repeat_key: Option<Box<String>>

What the tool says makes two results of the same call the same result for the repeated-call rule (doom_loop): two answers of one call (same tool, same arguments) that carry the same key count as equal, whatever their text says. A command that fails the same way twice prints a different duration or path each time, so its text never repeats to the byte; the key (exit:2) does (boxed, so that a Result<_, ToolOutput> stays small). See with_repeat_key.

Journaled with the result, so a replay decides the same; absent from a journal written before it existed, and not written while it is None.

§plan: Option<Box<Plan>>

The conversation’s plan as it is after this call (Plan): the whole plan, not a change. The loop makes it the run’s plan when the result is not an error, in the same commit as the result; a replay takes it from the journal. Read the plan a call starts from with ToolCtx::plan. Never read from an error result.

Absent from a journal written before it existed, and not written while it is None.

§kept: Option<Box<KeptOutput>>

A long text the tool wants the run to keep in its own state, for read_output to page through (keep_long makes it, and only when the agent has no KeptStore). The loop moves it into Conversation::kept_outputs; it is journaled with the result, so a replay keeps the same text.

Absent from a journal written before it existed, and not written while None.

§reported: Vec<RunId>

The rounds of child sessions whose reports this result gives the model (ADR 0045), as run ids. A result that gives one is the moment the loop counts the tokens of the rounds this run started that have ended, in the run’s totals, once each (Conversation::rounds_started); only whether the list is empty is read, because a run id differs between a run and a copy of its journal. Set by the session tools only. Never read from an error result.

Absent from a journal written before it existed, and not written while empty.

Honoured only from a tool that runs alone. The loop reads the rounds in a journaled step of its own right after the call; beside other calls (ADR 0049) that step has no place between them, so a call of a segment of several that reports rounds is answered with an error that tells the model to call the tool alone.

§pinned: bool

The result is pinned: a compaction that drops it from the history copies it into the marker that stands in for what was dropped (up to 32 KiB, and 64 KiB for all the results that were pinned), so what the model must keep knowing (a workspace’s path and branch, the instructions of a repository) outlives the summary. Set it only for a small result that is the tool’s own and whose loss would leave the model not knowing where it is: it is copied as text into a user message. Never read from an error result.

Absent from a journal written before it existed, and not written while it is false.

§images: Vec<ImageRef>

Images the result returns, by reference: keep_image admits and keeps them, with_image adds one. The history holds them on the tool’s message, and a model that sees is sent them after the run of tool messages; the references hold no byte. Never read from an error result.

Absent from a journal written before it existed, and not written while empty.

§loaded: Vec<Loaded>

The groups and tools the run has loaded, as this result says: the whole list the call saw, with the one it loaded, in the order they were loaded. The loop applies it to the run’s state (Conversation::loaded) when the result is not an error, in the same commit as the result, and records the turn of the next request in Conversation::tools_appended; a replay takes the list from the journal. A load appends its tools to the tools array, never inserts them (ADR 0044, decision 1). Only a group loader (load__group__…) sets it. Never read from an error result.

Absent from a journal written before it existed, and not written while empty.

§kept_images: Box<[KeptImage]>

The bytes of images, for the run to keep in its own state: only when the agent has no ImageStore (keep_image says which). Journaled with the result, like kept, so a replay keeps the same images.

Absent from a journal written before it existed, and not written while empty.

Implementations§

§

impl ToolOutput

pub fn text(content: impl Into<String>) -> ToolOutput

A successful result with no artifacts.

pub fn error(content: impl Into<String>) -> ToolOutput

A failed result the model should see and react to (for example invalid arguments). It does not fail the run.

pub fn with_image(self, outcome: ImageOutcome) -> ToolOutput

Add the image outcome admitted (keep_image) to the result. An image that was not admitted adds nothing: its line is ImageOutcome::stand_in, for the text.

pub fn with_loaded(self, loaded: impl IntoIterator<Item = Loaded>) -> ToolOutput

Say what the run has loaded (loaded): the whole list this call saw, with its own entry added, in the order they were loaded. The next model call is the first whose tools array has the loaded groups’ tools appended.

pub fn announcing(self, text: impl Into<String>) -> ToolOutput

Announce text as the run’s answer: once the run finishes, text is what it answered, and what the model says in its last turn is not. A later call that announces replaces it (the last announcement wins), and one that fails announces nothing: an error result’s answer is ignored. The announcement lasts until a new message reaches the run.

For a tool that hands the final answer over by another route (the thread tool turn_output of adam-ui does), so that a client that reads only the run’s output reads the same answer the person was shown.

pub fn final_answer(self, text: impl Into<String>) -> ToolOutput

Announce text as the run’s answer and end the turn with it: like announcing, and once the calls of this model turn are answered the run finishes with text as its output, with no further model call, so the model has no closing line to write after an answer the person has already read. A message that reached the run meanwhile is read first: the model is called again with it, and the announcement ends there as a new turn’s would. A call that fails ends nothing.

For a tool whose call is the model’s answer (turn_output of adam-ui).

pub fn with_repeat_key(self, key: impl Into<String>) -> ToolOutput

Say what makes this result the same as another of the same call for the repeated-call rule: three calls in a row with the same tool and arguments are refused when the two before carried the same key (or gave equal results, or both were errors). Set it only for a failure whose text varies and whose cause does not (exit:2), never on a success: a poll that succeeds with a changing text must keep running.

pub fn pinned(self) -> ToolOutput

Pin the result: see pinned.

pub fn with_plan(self, plan: Plan) -> ToolOutput

Make plan the conversation’s plan, when this result is not an error: see plan.

pub fn with_artifact(self, artifact: Artifact) -> ToolOutput

Add an artifact.

Trait Implementations§

§

impl Clone for ToolOutput

§

fn clone(&self) -> ToolOutput

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
§

impl Debug for ToolOutput

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl Default for ToolOutput

§

fn default() -> ToolOutput

Returns the “default value” for a type. Read more
§

impl<'de> Deserialize<'de> for ToolOutput

§

fn deserialize<__D>( __deserializer: __D, ) -> Result<ToolOutput, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
§

impl IntoToolOutput for ToolOutput

§

fn into_tool_output(self) -> ToolOutput

The output the model sees.
§

impl PartialEq for ToolOutput

§

fn eq(&self, other: &ToolOutput) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl Serialize for ToolOutput

§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
§

impl StructuralPartialEq for ToolOutput

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

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

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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

§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
§

impl<T> IntoToolResult for T
where T: IntoToolOutput,

§

fn into_tool_result(self) -> Result<ToolOutput, ToolError>

The result handed to the agent loop.
§

impl<L> LayerExt<L> for L

§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in [Layered].
§

impl<T> PolicyExt for T
where T: ?Sized,

§

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
§

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<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<T> ServiceExt for T

§

fn map_response_body<F>(self, f: F) -> MapResponseBody<Self, F>
where Self: Sized,

Apply a transformation to the response body. Read more
§

fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>
where Self: Sized,

High level tracing that classifies responses using HTTP status codes. Read more
§

fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>
where Self: Sized,

High level tracing that classifies responses using gRPC headers. Read more
§

fn follow_redirects(self) -> FollowRedirect<Self>
where Self: Sized,

Follow redirect resposes using the Standard policy. Read more
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 = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more