feat(pydantic-ai): Add tool description to execute_tool spans#5596
feat(pydantic-ai): Add tool description to execute_tool spans#5596ericapisani merged 27 commits intomasterfrom
Conversation
Include the tool's description (from its docstring) in gen_ai.execute_tool spans via the gen_ai.tool.description span data attribute. The description is sourced from the tool's ToolDefinition, which is derived from the tool's docstring. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Semver Impact of This PR🟡 Minor (new features) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨
Bug Fixes 🐛
Documentation 📚
Internal Changes 🔧Openai Agents
Other
🤖 This preview updates automatically when you update the PR. |
Codecov Results 📊✅ 13 passed | Total: 13 | Pass Rate: 100% | Execution Time: 7.66s 📊 Comparison with Base Branch
✨ No test changes detected All tests are passing successfully. ❌ Patch coverage is 0.00%. Project has 13870 uncovered lines. Files with missing lines (2)
Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
+ Coverage 25.63% 30.72% +5.09%
==========================================
Files 189 189 —
Lines 20016 20020 +4
Branches 6476 6478 +2
==========================================
+ Hits 5131 6150 +1019
- Misses 14885 13870 -1015
- Partials 421 468 +47Generated by Codecov Action |
Move Optional inside quotes for consistency with type annotation style conventions. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
….com:getsentry/sentry-python into ep/add-tool-description-to-pydantic-ai-spans
When a tool has no description, the tool_description field should be present in the span data but have a None value. Update the assertion to check for field presence rather than field absence. Also use `is None` instead of `== None` for proper Python style. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Use getattr with a None default when accessing tool_definition.description to prevent AttributeError if the attribute is missing. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
alexander-alderman-webb
left a comment
There was a problem hiding this comment.
Very nice work! See the two comments I've left.
I know there are plenty of existing pydantic-ai tests calling execute_tool_span() as if it's part of the public API we offer. I don't believe it's intended for users to call these functions directly however. As such, they are considered private.
Add the tool's description to
gen_ai.execute_toolspans via thegen_ai.tool.descriptionspan data attribute.When a pydantic-ai tool is defined with a docstring, that docstring becomes the tool's description in its
ToolDefinition. This PR surfaces that description in the corresponding Sentry span, making it easier to understand what each tool does when inspecting traces.The description is sourced from
tool.tool_def.descriptionon the internal tool object. If no description is available (e.g. the tool has no docstring), the attribute value is None.