pub struct ModelResponse {
pub id: String,
pub model: String,
pub stop_reason: StopReason,
pub content: Vec<ContentPart>,
pub usage: Usage,
pub rate_limit: Option<RateLimitSnapshot>,
pub warnings: Vec<ModelWarning>,
pub provider_echoes: Vec<ProviderEchoSnapshot>,
}Expand description
One reply from a model invocation, after decoding.
Fields§
§id: StringVendor-assigned response ID (used for tracing and replay).
model: StringEcho of the model that produced this response — useful when the codec
resolved an alias (e.g. claude-opus → claude-opus-4-7-20260415).
stop_reason: StopReasonWhy the model stopped producing tokens.
content: Vec<ContentPart>Returned content blocks (text, tool calls, etc.).
usage: UsageToken / cache accounting from the vendor.
rate_limit: Option<RateLimitSnapshot>Provider rate-limit state at response time, when the codec could
extract it from response headers (Codec::extract_rate_limit).
warnings: Vec<ModelWarning>Codec-emitted warnings (lossy encoding, unknown stop reasons, etc.). Always non-fatal; consumers may surface them in observability.
provider_echoes: Vec<ProviderEchoSnapshot>Vendor-keyed opaque round-trip tokens that ride at the
response root (rather than on a single content part) —
OpenAI Responses Response.id is the canonical example,
captured here so the next ModelRequest::continued_from
can chain via previous_response_id. Codecs only populate
entries matching their own Codec::name.
Implementations§
Source§impl ModelResponse
impl ModelResponse
Sourcepub fn first_text(&self) -> Option<&str>
pub fn first_text(&self) -> Option<&str>
Borrow the first text block, if any. Convenient when the
model is expected to reply with a single text answer (the
5-line-agent path) — saves the manual match &response.content[0] { ContentPart::Text { text, .. } => …, _ => panic!() } dance at every call site.
Returns None when the response has no text block (e.g. the
reply is purely a ToolUse block).
Sourcepub fn full_text(&self) -> String
pub fn full_text(&self) -> String
Concatenate every text block in order. Useful when the model
emits multiple Text blocks interleaved with Thinking or
ToolUse blocks and the caller only wants the user-visible
answer string.
Sourcepub fn tool_uses(&self) -> Vec<ToolUseRef<'_>>
pub fn tool_uses(&self) -> Vec<ToolUseRef<'_>>
Borrow every ToolUse block in declaration order. Empty
when the response carried no tool calls. Used by ReAct-style
agents to drive the next dispatch round.
Sourcepub fn has_tool_uses(&self) -> bool
pub fn has_tool_uses(&self) -> bool
True iff the response has at least one ToolUse block —
hot path for agent loops that branch on “did the model ask
to call a tool?”.
Trait Implementations§
Source§impl Clone for ModelResponse
impl Clone for ModelResponse
Source§fn clone(&self) -> ModelResponse
fn clone(&self) -> ModelResponse
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ModelResponse
impl Debug for ModelResponse
Source§impl<'de> Deserialize<'de> for ModelResponse
impl<'de> Deserialize<'de> for ModelResponse
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl PartialEq for ModelResponse
impl PartialEq for ModelResponse
Source§fn eq(&self, other: &ModelResponse) -> bool
fn eq(&self, other: &ModelResponse) -> bool
self and other values to be equal, and is used by ==.Source§impl Serialize for ModelResponse
impl Serialize for ModelResponse
impl Eq for ModelResponse
impl StructuralPartialEq for ModelResponse
Auto Trait Implementations§
impl Freeze for ModelResponse
impl RefUnwindSafe for ModelResponse
impl Send for ModelResponse
impl Sync for ModelResponse
impl Unpin for ModelResponse
impl UnsafeUnpin for ModelResponse
impl UnwindSafe for ModelResponse
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.