pub struct AgentResult { /* private fields */ }Expand description
The result of a successful agent invocation.
Wraps the raw AgentOutput and provides convenience accessors for the
response text, typed JSON deserialization, session metadata, and usage stats.
Implementations§
Source§impl AgentResult
impl AgentResult
Sourcepub fn text(&self) -> &str
pub fn text(&self) -> &str
Return the agent’s response as a plain text string.
If the underlying value is not a JSON string (e.g. when structured output was requested), returns an empty string and logs a warning.
Sourcepub fn json<T: DeserializeOwned>(&self) -> Result<T, OperationError>
pub fn json<T: DeserializeOwned>(&self) -> Result<T, OperationError>
Deserialize the agent’s response into the given type T.
This clones the underlying JSON value. If you no longer need the
AgentResult afterwards, use into_json
instead to avoid the clone.
§Errors
Returns OperationError::Deserialize if the JSON value does not match T.
Sourcepub fn into_json<T: DeserializeOwned>(self) -> Result<T, OperationError>
pub fn into_json<T: DeserializeOwned>(self) -> Result<T, OperationError>
Consume the result and deserialize the response into T without cloning.
§Errors
Returns OperationError::Deserialize if the JSON value does not match T.
Sourcepub fn session_id(&self) -> Option<&str>
pub fn session_id(&self) -> Option<&str>
Return the provider-assigned session ID, if available.
Sourcepub fn cost_usd(&self) -> Option<f64>
pub fn cost_usd(&self) -> Option<f64>
Return the cost of this invocation in USD, if reported by the provider.
Sourcepub fn input_tokens(&self) -> Option<u64>
pub fn input_tokens(&self) -> Option<u64>
Return the number of input tokens consumed, if reported.
Sourcepub fn output_tokens(&self) -> Option<u64>
pub fn output_tokens(&self) -> Option<u64>
Return the number of output tokens generated, if reported.
Sourcepub fn duration_ms(&self) -> u64
pub fn duration_ms(&self) -> u64
Return the wall-clock duration of the invocation in milliseconds.
Sourcepub fn model(&self) -> Option<&str>
pub fn model(&self) -> Option<&str>
Return the concrete model identifier used, if reported by the provider.
Sourcepub fn debug_messages(&self) -> Option<&[DebugMessage]>
pub fn debug_messages(&self) -> Option<&[DebugMessage]>
Return the conversation trace captured during a verbose invocation.
Returns None when Agent::verbose was not called. When present,
each DebugMessage contains the
assistant’s text and tool calls for one conversation turn.