Add examples field to ToolDefinition and send it to Anthropic
#3785
+214
−0
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.
Summary
This PR revives and improves upon the stale PR #3619 to add support for providing example inputs to tools. This feature allows developers to provide 1-5 realistic examples of tool usage, helping models (specifically Anthropic models) understand correct usage patterns, optional fields, and complex nested structures.
Key Changes
input_examplestoexamplesacross the codebase (per maintainer feedback), aligning withparameters_json_schema.examplesfield toToolDefinitionandToolclass.examplessupport toToolOutput, enabling examples for the final result tool.Agent.tool,Agent.tool_plain, andFunctionToolsetmethods to acceptexamples.examplestoinput_examplesin the Anthropic API payload.advanced-tool-use-2025-11-20for standard Anthropic API.tool-examples-2025-10-29for Amazon Bedrock and Google Vertex AI.Test Plan
tests/test_tools.pyverifyingexamplescan be set viaTool, decorators, andToolOutput.tests/models/test_anthropic.pyverifying:examples->input_examples.Related
examplesfield toToolDefinitionand send it to Anthropic #3619