Skip to content

Conversation

@ryx2
Copy link
Contributor

@ryx2 ryx2 commented Dec 2, 2025

Summary

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 header when input_examples is used

Supported by Anthropic models.
See https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/tool-use-examples

Test plan

  • Added unit tests in tests/models/anthropic/test_input_examples.py
  • All tests pass
  • No new pyright errors introduced

Related

Split from #3550 per @DouweM's recommendation to separate the features into individual PRs.

🤖 Generated with Claude Code

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
Copy link
Collaborator

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
Copy link
Collaborator

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')
Copy link
Collaborator

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.

@DouweM DouweM changed the title feat: Add input_examples field to ToolDefinition Add examples field to ToolDefinition and send it to Anthropic Dec 2, 2025
@DouweM DouweM self-assigned this Dec 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants