feat: add structured-only tool results that skip the text mirror#1046
feat: add structured-only tool results that skip the text mirror#1046olaservo wants to merge 2 commits into
Conversation
CallToolResult::structured and structured_error always mirror the structured value into content as serialized text, doubling large payloads. Add explicit opt-outs, never the default since the mirror is the only compatibility path for clients that do not read structuredContent: - CallToolResult::structured_only / structured_error_only constructors that leave content empty - StructuredOnly<T> return-type wrapper, a sibling of Json<T>, for use with #[tool] methods; the tool macro derives outputSchema from it the same way it does for Json<T> Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…endering content and structuredContent need not match: with_content replaces the content blocks on any result, so a structured_only result can carry a short text summary while structuredContent holds the full value. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Thanks for posting this @olaservo I agree if we want to make an opt-out path explicit and do it by default this looks like a good way to do it! Given the spec says
I'd ask the question how often is this backwards compatibility relevant for callers out there in the ecosystem? How long has it been the case that tools could have relevant info in structured content. Wondering when it would be reasonable to drop the automatic mirroring all together from an SDK perspective... |
|
@alexhancock I was wondering the same thing. One thing we should consider here is that the mirror itself is only a month old. Given that, and with 3.0 GA targeted for 7/28, what do we think about flipping the default in this PR instead of adding an opt-out? It would also make the PR smaller since the second wrapper and the macro change wouldn't be needed. Happy to help with the rework if that makes sense. |
CallToolResult::structuredandstructured_erroralways mirror the structured value intocontentas serialized text, doubling large payloads. The spec marks that mirror as a SHOULD, not a MUST.This PR makes the mirror optional. Opting out is explicit, since the mirror is the compatibility path for clients that do not read
structuredContent:CallToolResult::structured_only/structured_error_only— constructors that leavecontentemptyStructuredOnly<T>— return-type wrapper, a sibling ofJson<T>, for#[tool]methods; the tool macro derivesoutputSchemafrom it the same way it does forJson<T>CallToolResult::with_content— replaces thecontentblocks, so a structured result can pairstructuredContentwith a custom rendering (e.g. a short text summary) instead of the verbatim mirror; the two fields need not carry the same data