existential-birds avatar

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-code

Installs 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

  1. @agent.tool: First parameter MUST be RunContext[DepsType]
  2. @agent.tool_plain: MUST NOT have RunContext parameter
  3. Docstrings: Required for LLM to understand tool purpose
  4. 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
1rohitg00 avatarllm-gaterohitg00/pro-workflowLLM-powered quality verification using prompt hooks. Validates commit messages, code patterns, and conventions using AI before allowing operations. Use to set u158skills.sh installs
2openserv-labs avataropenserv-agent-sdkopenserv-labs/skillsBuild and deploy autonomous AI agents using the OpenServ SDK (@openserv-labs/sdk). IMPORTANT - Always read the companion skill openserv-client alongside this sk151skills.sh installs
3existential-birds avatarpydantic-ai-model-integrationexistential-birds/beagleConfigure LLM providers, use fallback models, handle streaming, and manage model settings in PydanticAI. Use when selecting models, implementing resilience, or 120skills.sh installs
4bankrbot avatarBankr Agent - Job Workflowbankrbot/claude-pluginsThis skill should be used when executing Bankr requests, submitting prompts to Bankr API, polling for job status, checking job progress, using Bankr MCP tools, 0skills.sh installs
5davila7 avatarAgent Developmentdavila7/claude-code-templatesThis skill should be used when the user asks to "create an agent", "add an agent", "write a subagent", "agent frontmatter", "when to use description", "agent ex0skills.sh installs
6PostHog avatarimplementing-agent-modesPostHog/posthog-fossGuidelines to create/update a new mode for PostHog AI agent. Modes are a way to limit what tools, prompts, and prompt injections are applied and under what cond0skills.sh installs