v0.17.0
v0.17.0 Release Summary
What Changed
The ResponseAdapter trait now supports unified extraction of model name, finish reason, token usage, and tool calls across all LLM provider response types. A new ChatResponse::from_response_value method enables dynamic deserialization of unknown JSON payloads into the correct provider variant.
Breaking Changes
The ResponseAdapter trait gains 6 new required methods. Any type implementing ResponseAdapter outside of this crate must add the following:
| Method | Return type |
|---|---|
model_name() |
Option<&str> |
finish_reason() |
Option<&str> |
input_tokens() |
Option<i64> |
output_tokens() |
Option<i64> |
total_tokens() |
Option<i64> |
get_tool_calls() |
Vec<ToolCallInfo> |
ToolCallInfo is a new public struct in potato_type::tools.
Changes
ResponseAdapter trait extensions
Six methods added to ResponseAdapter in potato_type::traits. Each provider implements them against its native response schema:
- OpenAI: Reads from
choices[0].finish_reason,usage.prompt_tokens/completion_tokens/total_tokens, andchoices[*].message.tool_calls. - Anthropic: Maps
stop_reasonenum variants to string slices ("end_turn","max_tokens","stop_sequence","tool_use"). Extracts tool calls fromcontentblocks of typeToolUse. - Google Gemini / Vertex Generate: Reads
candidates[0].finish_reason(via newFinishReason::as_str()),usage_metadatatoken counts, andfunctionCallparts.FinishReasonalso gains aDisplayimpl. - Google Vertex Predict (embeddings): All new methods return
Noneor empty — embeddings have no finish reason, token counts, or tool calls.
ToolCallInfo
New struct in potato_type::tools:
pub struct ToolCallInfo {
pub name: String,
pub arguments: serde_json::Value,
pub call_id: Option<String>,
pub result: Option<serde_json::Value>,
}Provides a provider-agnostic representation of a tool call. Each provider's get_tool_calls() maps its native format (OpenAI's stringified JSON arguments, Anthropic's direct Value input, Google's Map<String, Value> args) into this struct.
ChatResponse::from_response_value
Discriminant-based JSON router on the ChatResponse enum. Inspects top-level keys to select the correct variant:
| Key(s) present | Deserializes as |
|---|---|
choices |
OpenAIChatResponse |
predictions |
PredictResponse (Vertex) |
candidates |
GenerateContentResponse (Gemini) |
stop_reason + content |
AnthropicMessageResponse |
Returns ProviderError::DeserializationError (new variant) if no pattern matches or deserialization fails.
ChatResponse trait dispatch
ChatResponse now delegates all 6 new ResponseAdapter methods to the inner variant, matching the existing pattern for the other trait methods.
Test coverage
98 new tests across 5 files covering all ResponseAdapter implementations, ChatResponse dispatch, from_response_value routing, and JSON deserialization from raw strings.
Upgrading from v0.16.1
- If you implement
ResponseAdapteron custom types, add the 6 new methods listed in Breaking Changes above. - Add
use potato_type::tools::ToolCallInfowhere needed forget_tool_calls()return values. - No schema changes, no config changes, no migration required beyond the trait additions.