#[non_exhaustive]pub struct AgentResult { /* private fields */ }Expand description
The result of an agent invocation (AgentResult).
Serializes to type, stopReason, lastMessage and, when present, structuredOutput.
Traces, metrics, the invocation context and the invocation state stay out of the JSON so a
result can be forwarded over the wire without bloat.
Display writes the interrupts as JSON when there are any, else the structured output as JSON,
else the text of the last message.
Implementations§
Source§impl AgentResult
impl AgentResult
Sourcepub fn new(stop_reason: StopReason, last_message: Message) -> Self
pub fn new(stop_reason: StopReason, last_message: Message) -> Self
Creates a result with a stop reason and the last message, and empty invocation state.
Sourcepub fn with_traces(self, traces: Vec<AgentTrace>) -> Self
pub fn with_traces(self, traces: Vec<AgentTrace>) -> Self
Sets the traces.
Sourcepub fn with_structured_output(self, structured_output: JsonValue) -> Self
pub fn with_structured_output(self, structured_output: JsonValue) -> Self
Sets the validated structured output.
Sourcepub fn with_metrics(self, metrics: AgentMetrics) -> Self
pub fn with_metrics(self, metrics: AgentMetrics) -> Self
Sets the metrics.
Sourcepub fn with_invocation_context(
self,
invocation_context: InvocationContext,
) -> Self
pub fn with_invocation_context( self, invocation_context: InvocationContext, ) -> Self
Sets the invocation context.
Sourcepub fn with_invocation_state(self, invocation_state: InvocationState) -> Self
pub fn with_invocation_state(self, invocation_state: InvocationState) -> Self
Sets the invocation state.
Sourcepub fn with_interrupts(self, interrupts: Vec<Interrupt>) -> Self
pub fn with_interrupts(self, interrupts: Vec<Interrupt>) -> Self
Sets the interrupts that stopped the agent.
Sourcepub fn stop_reason(&self) -> StopReason
pub fn stop_reason(&self) -> StopReason
Why the invocation stopped.
Sourcepub fn last_message(&self) -> &Message
pub fn last_message(&self) -> &Message
The last message added to the conversation.
Sourcepub fn traces(&self) -> Option<&[AgentTrace]>
pub fn traces(&self) -> Option<&[AgentTrace]>
Local execution traces collected during the invocation.
Sourcepub fn structured_output_value(&self) -> Option<&JsonValue>
pub fn structured_output_value(&self) -> Option<&JsonValue>
The validated structured output as raw JSON, when a schema was given.
Sourcepub fn structured_output<T: DeserializeOwned>(&self) -> Result<T>
pub fn structured_output<T: DeserializeOwned>(&self) -> Result<T>
The structured output deserialized into T.
§Errors
Error::StructuredOutput when the result has no structured output, or a decoding error
when it does not fit T.
Sourcepub fn metrics(&self) -> Option<&AgentMetrics>
pub fn metrics(&self) -> Option<&AgentMetrics>
Aggregated loop metrics of the agent.
Sourcepub fn invocation_context(&self) -> Option<&InvocationContext>
pub fn invocation_context(&self) -> Option<&InvocationContext>
The request this call ran in. Its usage covers the whole request; pass it to a later call to continue on the same limits and usage.
Sourcepub fn invocation_state(&self) -> &InvocationState
pub fn invocation_state(&self) -> &InvocationState
The invocation state passed through hooks and tools.
Sourcepub fn interrupts(&self) -> &[Interrupt]
pub fn interrupts(&self) -> &[Interrupt]
The unanswered interrupts when the stop reason is StopReason::Interrupt.
Sourcepub fn context_size(&self) -> Option<u64>
pub fn context_size(&self) -> Option<u64>
The whole prompt the model processed on the last call.
Sourcepub fn projected_context_size(&self) -> Option<u64>
pub fn projected_context_size(&self) -> Option<u64>
Projected context size of the next model call.
Trait Implementations§
Source§impl Clone for AgentResult
impl Clone for AgentResult
Source§impl Debug for AgentResult
impl Debug for AgentResult
Source§impl<'de> Deserialize<'de> for AgentResult
impl<'de> Deserialize<'de> for AgentResult
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Reads the serialized shape. The fields it leaves out (traces, metrics, invocation context and state) start empty.
Source§impl Display for AgentResult
impl Display for AgentResult
Auto Trait Implementations§
impl !RefUnwindSafe for AgentResult
impl !UnwindSafe for AgentResult
impl Freeze for AgentResult
impl Send for AgentResult
impl Sync for AgentResult
impl Unpin for AgentResult
impl UnsafeUnpin for AgentResult
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
§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> ⓘ
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