-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Add examples field to ToolDefinition and send it to Anthropic
#3619
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
This adds support for providing example inputs to help the model understand correct tool usage patterns. - Add `input_examples` field to `ToolDefinition` dataclass - Add `input_examples` parameter to `Tool` class - Update `FunctionToolset.tool`, `add_function` decorators - Update `Agent.tool_plain` decorator - Update Anthropic model to pass `input_examples` to API - Automatically enable `advanced-tool-use-2025-11-20` beta when used - Add tests in `tests/models/anthropic/test_input_examples.py` Supported by Anthropic models. See https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/tool-use-examples 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
| For MCP tools, this contains the `meta`, `annotations`, and `output_schema` fields from the tool definition. | ||
| """ | ||
|
|
||
| input_examples: list[dict[str, Any]] | None = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Anthropic calls them input_examples because they have input_schema, but we have parameters_json_schema, so let's call it either parameters_examples or, better, just examples.
| sequential: bool | ||
| requires_approval: bool | ||
| metadata: dict[str, Any] | None | ||
| input_examples: list[dict[str, Any]] | None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should also add this to OutputTool!
| # Check if any tools use input_examples (advanced tool use feature) | ||
| has_input_examples = any(tool.get('input_examples') for tool in tools) | ||
| if has_input_examples: | ||
| betas.add('advanced-tool-use-2025-11-20') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a different beta header for Vertex and Bedrock: https://platform.claude.com/docs/en/agents-and-tools/tool-use/implement-tool-use#providing-tool-use-examples
That's relevant when using AnthropicModel with AnthropicProvider and a custom anthropic_client like AsyncAnthropicVertex. So we should check the type of self._client to send the right header.
examples field to ToolDefinition and send it to Anthropic
Summary
Adds support for providing example inputs to help the model understand correct tool usage patterns.
input_examplesfield toToolDefinitiondataclassinput_examplesparameter toToolclassFunctionToolset.tool,add_functiondecoratorsAgent.tool_plaindecoratorinput_examplesto APIadvanced-tool-use-2025-11-20beta header wheninput_examplesis usedSupported by Anthropic models.
See https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/tool-use-examples
Test plan
tests/models/anthropic/test_input_examples.pyRelated
Split from #3550 per @DouweM's recommendation to separate the features into individual PRs.
🤖 Generated with Claude Code