feat: add structured-only tool results that skip the text mirror#1046
Open
olaservo wants to merge 2 commits into
Open
feat: add structured-only tool results that skip the text mirror#1046olaservo wants to merge 2 commits into
olaservo 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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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