
Pydantic Ai Tool System
This covers the decorator patterns for registering tools in PydanticAI agents. The key thing to remember is that @agent.tool requires RunContext as the first parameter while @agent.tool_plain doesn't allow it at all. Mix them up and your tools won't work. The skill walks through docstring requirements (the LLM reads these to understand what your tools do), return type handling, and some useful patterns like prepare_tools for filtering capabilities based on user permissions. It's straightforward once you internalize the decorator rules, but the context parameter requirement trips people up initially. Worth referencing when you're adding function calling to agents.
- skills.sh installs
- 161
- GitHub stars
- 87
- last updated
- Aug 21, 2026
Install
$ npx -y skills add existential-birds/beagle --skill pydantic-ai-tool-system --agent claude-codeInstalls into .claude/skills of the current project.
Files
PydanticAI Tool System
Tool Registration
Two decorators based on whether you need context:
from pydantic_ai import Agent, RunContext
agent = Agent('openai:gpt-4o')
# @agent.tool - First param MUST be RunContext
@agent.tool
async def get_user_data(ctx: RunContext[MyDeps], user_id: int) -> str:
"""Get user data from database.
Args:
ctx: The run context with dependencies.
user_id: The user's ID.
"""
return await ctx.deps.db.get_user(user_id)
# @agent.tool_plain - NO context parameter allowed
@agent.tool_plain
def calculate_total(prices: list[float]) -> float:
"""Calculate total price.
Args:
prices: List of prices to sum.
"""
return sum(prices)
Critical Rules
- @agent.tool: First parameter MUST be
RunContext[DepsType] - @agent.tool_plain: MUST NOT have
RunContextparameter - Docstrings: Required for LLM to understand tool purpose
- Google-style docstrings: Used for parameter descriptions
Gates (verify in the file, not from memory)
Sponsors
Details
- Repository
- github.com/existential-birds/beagle
- Categories
- AI & Agent Building, Python
- First seen
- Jun 3, 2026
More from existential-birds/beagle
All 40- Deepagents Architecture160
- Langgraph Implementation160
- Pydantic Ai Testing146
- Pydantic Ai Dependency Injection141
- Deepagents Implementation140
- Deepagents Code Review132
- Github Projects120
- Pydantic Ai Model Integration120
- React Flow1.3K
- Python Code Review928
- Langgraph Code Review887
- Tailwind V4817
- React Flow Advanced643
- React Router V7577
- React Flow Architecture536
- Vitest Testing471
- Docling431
- Fastapi Code Review387
- React Flow Implementation374
- Shadcn Ui356
- React Flow Code Review324
- Langgraph Architecture282
- Swiftui Code Review273
- Tutorial Docs271