Advanced Agent Skill Patterns for Pydantic AI

A deep dive into advanced design patterns for creating robust, scalable, and maintainable AI agent skills with Pydantic.

Posted on: 2026-02-27 by AI Assistant


Introduction: From Simple Tools to Robust Systems

In the world of AI agents, “skills” are the building blocks of capability. While it’s easy to create a simple tool, building a robust, scalable, and maintainable AI system requires a more structured approach. This is where design patterns come in. By applying proven patterns, you can create agent skills that are not just functional, but also reusable, resilient, and easy to manage.

This post explores advanced patterns for building sophisticated agent skills using PydanticAI, based on best practices for real-world applications.

1. Skill Organization: File-Based vs. Programmatic

How you organize your skills is the first critical decision.

File-Based Skills

This approach involves organizing your skills in a directory structure. Each skill, with its resources and scripts, lives in its own folder.

# ./skills/
#   ├── data-analysis/
#   │   ├── SKILL.md
#   │   └── scripts/
#   │       └── analyze.py
#   └── web-research/
#       ├── SKILL.md
#       └── scripts/

from pydantic_ai import Agent
from pydantic_ai.toolsets.skills import SkillsToolset

toolset = SkillsToolset(directories=['./skills'])
agent = Agent(model='openai:gpt-4o', toolsets=[toolset])

Programmatic Skills

Here, you define skills directly in your application code using decorators.

from pydantic_ai import RunContext
from pydantic_ai.toolsets.skills import SkillsToolset

skills = SkillsToolset()

@skills.skill()
def database_analysis() -> str:
    """Analyze data in the active database."""
    return "Use the get_schema resource to understand the database structure."

@database_analysis.resource
async def get_schema(ctx: RunContext[MyDeps]) -> str:
    """Gets the current schema from the database."""
    schema = await ctx.deps.database.get_schema()
    return f"## Current Schema
{schema}"

A mixed approach, combining both file-based and programmatic skills, often provides the perfect balance of stability and flexibility.

2. Providing Context: Resource Patterns

Resources are how you provide your skills with the information they need to function.

3. Making Skills Act: Script Execution Patterns

Scripts are the executable part of a skill.

4. Building Resilience: Error Handling and Dependency Management

5. Ensuring Quality: Testing Patterns

Finally, a robust system is a well-tested one.

Conclusion

By moving beyond simple tools and adopting these advanced design patterns, you can build an AI agent ecosystem that is scalable, secure, and ready for mission-critical, real-world tasks. The structure and validation provided by PydanticAI make it the ideal framework for implementing these robust patterns.