SkillsToolset API Reference
Bases: FunctionToolset[Any]
Pydantic AI toolset for automatic skill discovery and integration.
See skills docs for more information.
This is the primary interface for integrating skills with Pydantic AI agents. It manages skills directly and provides tools for skill interaction.
Provides the following tools to agents: - list_skills(): List all available skills - load_skill(skill_name): Load a specific skill's instructions - read_skill_resource(skill_name, resource_name): Read a skill resource file - run_skill_script(skill_name, script_name, args): Execute a skill script
Example
from pydantic_ai import Agent, SkillsToolset
# Default: uses ./skills directory
agent = Agent(
model='openai:gpt-5.2',
instructions="You are a helpful assistant.",
toolsets=[SkillsToolset()]
)
# Multiple directories
agent = Agent(
model='openai:gpt-5.2',
toolsets=[SkillsToolset(directories=["./skills", "./more-skills"])]
)
# Programmatic skills
from pydantic_ai.toolsets.skills import Skill, SkillMetadata
custom_skill = Skill(
name="my-skill",
uri="./custom",
metadata=SkillMetadata(name="my-skill", description="Custom skill"),
content="Instructions here",
)
agent = Agent(
model='openai:gpt-5.2',
toolsets=[SkillsToolset(skills=[custom_skill])]
)
# Combined mode: both programmatic skills and directories
agent = Agent(
model='openai:gpt-5.2',
toolsets=[SkillsToolset(
skills=[custom_skill],
directories=["./skills"]
)]
)
# Using SkillsDirectory instances directly
from pydantic_ai.toolsets.skills import SkillsDirectory
dir1 = SkillsDirectory(path="./skills")
agent = Agent(
model='openai:gpt-5.2',
toolsets=[SkillsToolset(directories=[dir1, "./more-skills"])]
)
# Skills instructions are automatically injected via get_instructions()
Source code in pydantic_ai_skills/toolset.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 | |
__init__
__init__(*, skills: list[Skill] | None = None, directories: list[str | Path | SkillsDirectory] | None = None, registries: list[SkillRegistry] | None = None, validate: bool = True, max_depth: int | None = 3, id: str | None = None, instruction_template: str | None = None, exclude_tools: set[str] | list[str] | None = None) -> None
Initialize the skills toolset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
skills
|
list[Skill] | None
|
List of pre-loaded Skill objects. Can be combined with |
None
|
directories
|
list[str | Path | SkillsDirectory] | None
|
List of directories or SkillsDirectory instances to discover skills from.
Can be combined with |
None
|
registries
|
list[SkillRegistry] | None
|
List of SkillRegistry instances (e.g. GitSkillsRegistry) to load
skills from. Registry skills are fetched lazily on the first async call
( |
None
|
validate
|
bool
|
Validate skill structure during discovery (used when creating SkillsDirectory from str/Path). |
True
|
max_depth
|
int | None
|
Maximum depth for skill discovery (None for unlimited, used when creating SkillsDirectory from str/Path). |
3
|
id
|
str | None
|
Unique identifier for this toolset. |
None
|
instruction_template
|
str | None
|
Custom instruction template for skills system prompt.
Must include |
None
|
exclude_tools
|
set[str] | list[str] | None
|
Set or list of tool names to exclude from registration (e.g., ['run_skill_script']). Useful for security or capability restrictions such as disabling script execution. Valid tool names: 'list_skills', 'load_skill', 'read_skill_resource', 'run_skill_script'. |
None
|
Example
# Default: uses ./skills directory
toolset = SkillsToolset()
# Multiple directories
toolset = SkillsToolset(directories=["./skills", "./more-skills"])
# Programmatic skills
toolset = SkillsToolset(skills=[skill1, skill2])
# Combined mode
toolset = SkillsToolset(
skills=[skill1, skill2],
directories=["./skills", skills_dir_instance]
)
# Using SkillsDirectory instances directly
dir1 = SkillsDirectory(path="./skills")
toolset = SkillsToolset(directories=[dir1])
# Excluding specific tools (disable script execution with a set)
toolset = SkillsToolset(exclude_tools=['run_skill_script'])
# Git registry: clone a remote repo and load skills
from pydantic_ai_skills.registries.git import GitSkillsRegistry
registry = GitSkillsRegistry(
repo_url="https://github.com/anthropics/skills",
path="skills",
)
toolset = SkillsToolset(registries=[registry])
Source code in pydantic_ai_skills/toolset.py
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | |
skills
property
skills: dict[str, Skill]
Get the dictionary of loaded skills.
Returns:
| Type | Description |
|---|---|
dict[str, Skill]
|
Dictionary mapping skill names to Skill objects. |
get_skill
get_skill(name: str) -> Skill
Get a specific skill by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name of the skill to get. |
required |
Returns:
| Type | Description |
|---|---|
Skill
|
The requested Skill object. |
Raises:
| Type | Description |
|---|---|
SkillNotFoundError
|
If skill is not found. |
Source code in pydantic_ai_skills/toolset.py
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 | |
get_instructions
async
get_instructions(ctx: RunContext[Any]) -> str | None
Return instructions to inject into the agent's system prompt.
Returns the skills system prompt containing usage guidance and all skill metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
RunContext[Any]
|
The run context for this agent run. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
The skills system prompt, or None if no skills are loaded. |
Source code in pydantic_ai_skills/toolset.py
613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 | |
skill
skill(func: Callable[[], str] | None = None, *, name: str | None = None, description: str | None = None, license: str | None = None, compatibility: str | None = None, metadata: dict[str, Any] | None = None, resources: list[SkillResource] | None = None, scripts: list[SkillScript] | None = None) -> Any
Decorator to define a skill using a function.
The decorated function should return a string containing the skill's instructions/content.
The skill name is derived from the function name (underscores replaced with hyphens)
unless explicitly provided via the name parameter.
Example
from pydantic_ai import RunContext
from pydantic_ai.toolsets.skills import SkillsToolset
skills = SkillsToolset()
@skills.skill(resources=[], metadata={'version': '1.0'})
def data_analyzer() -> str:
'''Analyze data from various sources.'''
return '''
Use this skill for data analysis tasks.
The skill provides tools for querying and analyzing data.
'''
@data_analyzer.resource
async def get_schema(ctx: RunContext[MyDeps]) -> str:
return await ctx.deps.database.get_schema()
@data_analyzer.script
async def run_analysis(ctx: RunContext[MyDeps], query: str) -> str:
result = await ctx.deps.database.execute(query)
return str(result)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
Callable[[], str] | None
|
The function that returns skill content (must return str). |
None
|
name
|
str | None
|
Skill name (defaults to normalized function name: underscores → hyphens). |
None
|
description
|
str | None
|
Skill description (inferred from docstring if not provided). |
None
|
license
|
str | None
|
Optional license information (e.g., "Apache-2.0"). |
None
|
compatibility
|
str | None
|
Optional environment requirements (e.g., "Requires Python 3.10+"). |
None
|
metadata
|
dict[str, Any] | None
|
Additional metadata fields as a dictionary. |
None
|
resources
|
list[SkillResource] | None
|
Initial list of resources to attach to the skill. |
None
|
scripts
|
list[SkillScript] | None
|
Initial list of scripts to attach to the skill. |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
A SkillWrapper instance that can be used to attach resources and scripts. |
Source code in pydantic_ai_skills/toolset.py
644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 | |
options: members: - init - get_instructions - get_skill - skills show_source: true heading_level: 2
Constructor Parameters
The SkillsToolset.__init__() accepts the following parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
skills |
list[Skill] \| None |
None |
Pre-loaded Skill objects. Can be combined with directories. |
directories |
list[str \| Path \| SkillsDirectory] \| None |
None |
Directories or SkillsDirectory instances to discover skills from. Defaults to ["./skills"] if neither skills nor directories provided. |
registries |
list[SkillRegistry] \| None |
None |
List of SkillRegistry instances (e.g. GitSkillsRegistry) to load skills from. Can be combined with skills and directories. Registries have the lowest priority. |
validate |
bool |
True |
Validate skill structure during discovery. Used when creating SkillsDirectory from str/Path entries. |
max_depth |
int \| None |
3 |
Maximum depth for skill discovery. None for unlimited depth. Used when creating SkillsDirectory from str/Path entries. |
id |
str \| None |
None |
Unique identifier for this toolset. |
instruction_template |
str \| None |
None |
Custom instruction template for skills system prompt. Must include {skills_list} placeholder. If None, uses default template. |
Properties
| Property | Type | Description |
|---|---|---|
skills |
dict[str, Skill] |
Dictionary of all available skills, keyed by skill name. |
Methods
| Method | Description |
|---|---|
get_skill(skill_name: str) -> Skill |
Retrieve a specific skill by name. Raises SkillNotFoundError if not found. |
get_instructions(ctx: RunContext[Any]) -> str |
Returns formatted system prompt with skills instructions. Used via @agent.instructions. |
Usage Examples
Initialize with File-Based Skills
from pydantic_ai_skills import SkillsToolset
# Basic initialization - defaults to ./skills directory
toolset = SkillsToolset()
# Explicit single directory
toolset = SkillsToolset(directories=["./skills"])
# Multiple directories
toolset = SkillsToolset(
directories=["./skills", "./shared", "./custom"],
validate=True,
max_depth=3,
id="my-skills"
)
# Using SkillsDirectory instances directly
from pydantic_ai.toolsets.skills import SkillsDirectory
skills_dir = SkillsDirectory(
path="./skills",
validate=True,
max_depth=3
)
toolset = SkillsToolset(directories=[skills_dir])
Initialize with Git Registry
from pydantic_ai_skills import SkillsToolset
from pydantic_ai_skills.registries import GitSkillsRegistry, GitCloneOptions
# Clone a remote Git repository and load its skills
registry = GitSkillsRegistry(
repo_url='https://github.com/anthropics/skills',
path='skills',
target_dir='./anthropics-skills',
clone_options=GitCloneOptions(depth=1, single_branch=True),
)
toolset = SkillsToolset(registries=[registry])
# Combine with local skills
toolset = SkillsToolset(
directories=['./skills'],
registries=[registry],
)
See Skill Registries for composition patterns (filtering, prefixing, combining).
Initialize with Programmatic Skills
from pydantic_ai import RunContext
from pydantic_ai.toolsets.skills import Skill, SkillsToolset
# Create a simple programmatic skill
my_skill = Skill(
name='custom-skill',
description='Custom programmatic skill',
content='Instructions for this skill...'
)
# Initialize toolset with programmatic skill
toolset = SkillsToolset(skills=[my_skill])
# Use the @skill() decorator to define skills inline
skills = SkillsToolset()
@skills.skill()
def data_analyzer() -> str:
"""Analyze data from various sources."""
return "Provide data analysis capabilities..."
@data_analyzer.resource
def get_schema() -> str:
"""Get available schema information."""
return "## Schema\n\nAvailable columns..."
@data_analyzer.script
async def analyze(ctx: RunContext[MyDeps], query: str) -> str:
"""Run analysis query."""
return await ctx.deps.database.execute(query)
Mix File-Based and Programmatic Skills
from pydantic_ai.toolsets.skills import Skill, SkillsToolset
# Create programmatic skills
programmatic_skill = Skill(
name='runtime-skill',
description='Created at runtime',
content='Dynamic skill content...'
)
# Combine both types in a single toolset
toolset = SkillsToolset(
directories=["./skills"], # File-based skills from directory
skills=[programmatic_skill], # Programmatic skills
max_depth=3 # Limit directory discovery depth
)
# Programmatic skills can also be added via decorator
@toolset.skill()
def extra_skill() -> str:
return "Additional dynamically-defined skill..."
print(f"Total skills loaded: {len(toolset.skills)}")
Custom Instruction Template
from pydantic_ai import Agent
from pydantic_ai.toolsets.skills import SkillsToolset
custom_instructions = """\
You have specialized skills available for specific domains.
Each skill includes instructions, resources, and executable scripts.
Available skills:
{skills_list}
Use `load_skill` to explore any skill that's relevant to the user's request.
"""
toolset = SkillsToolset(
directories=["./skills"],
instruction_template=custom_instructions
)
agent = Agent(
model='openai:gpt-4o',
toolsets=[toolset]
)
Use @skill() Decorator
from pydantic_ai.toolsets.skills import SkillsToolset
skills = SkillsToolset(directories=["./skills"])
@skills.skill(
name='custom-analyzer', # Override function name
license='Apache-2.0',
compatibility='Python 3.10+',
metadata={'version': '1.0.0', 'author': 'my-team'}
)
def data_analyzer() -> str:
"""Analyze data from various sources."""
return """
# Data Analysis Skill
Use this skill to analyze datasets and generate insights.
## Instructions
Load the full skill with `load_skill` to see available resources and scripts.
"""
# Now 'data-analyzer' skill is registered and available to agents
Get Skills Instructions for Agent
from pydantic_ai import Agent, RunContext
from pydantic_ai_skills import SkillsToolset
toolset = SkillsToolset(directories=["./skills"])
agent = Agent(
model='openai:gpt-4o',
instructions="You are a helpful assistant.",
toolsets=[toolset]
)
@agent.instructions
async def add_skills(ctx: RunContext) -> str | None:
"""Inject skills instructions into agent context."""
return toolset.get_instructions(ctx)
# The agent will receive skill metadata in system prompt
result = agent.run_sync('Analyze the quarterly data')
The instructions include: - List of available skills with descriptions - How to use the four skill tools - Best practices for progressive disclosure
Access Skills
# Get all skills
all_skills = toolset.skills
# Get specific skill
skill = toolset.get_skill("arxiv-search")
print(f"Name: {skill.name}")
print(f"Description: {skill.metadata.description}")
print(f"Scripts: {[s.name for s in skill.scripts]}")
Tools Provided
The SkillsToolset automatically registers four tools with agents:
list_skills()
Lists all available skills with descriptions.
Returns: Formatted markdown string
Example:
# Available Skills
## arxiv-search
Search arXiv for research papers (scripts: arxiv_search)
## web-research
Structured approach to web research
load_skill(skill_name: str)
Loads full instructions for a specific skill.
Parameters:
skill_name(str): Name of the skill to load
Returns: Full skill content including metadata and instructions
read_skill_resource(skill_name: str, resource_name: str)
Reads a resource file from a skill.
Parameters:
skill_name(str): Name of the skillresource_name(str): Resource filename (e.g., "REFERENCE.md")
Returns: Resource file content
run_skill_script(skill_name: str, script_name: str, args: dict[str, Any] | None = None)
Executes a skill script with optional arguments.
Parameters:
skill_name(str): Name of the skillscript_name(str): Name of the script within the skillargs(dict[str, Any], optional): Dictionary of arguments to pass to the script- For file-based scripts: Converted to command-line flags (e.g.,
{"query": "test"}→--query test) - For callable scripts: Passed as function arguments
Returns: String output from script execution
Raises:
SkillNotFoundError: If the skill doesn't existSkillScriptNotFoundError: If the script doesn't exist in the skillSkillScriptExecutionError: If script execution fails or times out
Example:
# Agent calls the tool
agent.run_sync('Run the arxiv search script with query "machine learning"')
# Internally calls:
# result = await toolset.run_skill_script(
# 'arxiv-search',
# 'arxiv_search',
# {'query': 'machine learning'}
# )
Decorator: @toolset.skill()
The @toolset.skill() decorator enables defining skills directly on the toolset instance.
Signature:
def skill(
func: Callable[[], str] | None = None,
*,
name: str | None = None,
description: str | None = None,
license: str | None = None,
compatibility: str | None = None,
metadata: dict[str, Any] | None = None,
resources: list[SkillResource] | None = None,
scripts: list[SkillScript] | None = None,
) -> SkillWrapper[Any]
Parameters:
| Parameter | Type | Description |
|---|---|---|
func |
Callable[[], str] |
Function returning skill instructions/content. Used as decorator. |
name |
str \| None |
Override skill name (default: normalize function name). Must match ^[a-z0-9]+(-[a-z0-9]+)*$, max 64 chars. |
description |
str \| None |
Skill description (default: function docstring). Max 1024 chars. |
license |
str \| None |
License identifier (e.g., "Apache-2.0"). |
compatibility |
str \| None |
Environment/dependency requirements (e.g., "Requires git, docker"). Max 500 chars. |
metadata |
dict[str, Any] \| None |
Custom metadata fields (e.g., version, author, tags). |
resources |
list[SkillResource] \| None |
Initial resources to attach. Can be extended with @skill.resource. |
scripts |
list[SkillScript] \| None |
Initial scripts to attach. Can be extended with @skill.script. |
Returns: SkillWrapper[Any] - Decorated skill that supports @skill.resource and @skill.script decorators
Example:
from pydantic_ai.toolsets.skills import SkillsToolset
skills = SkillsToolset()
@skills.skill(
name='data-analyzer',
license='MIT',
compatibility='Python 3.10+',
metadata={'version': '1.0.0', 'author': 'data-team'}
)
def my_analyzer() -> str:
"""Analyze and process data."""
return "# Data Analysis Skill\n\nUse for data analysis tasks."
# Extended with resources and scripts
@my_analyzer.resource
def get_schema() -> str:
return "## Schema\n\nDatabase schema information..."
@my_analyzer.script
async def analyze_data(query: str) -> str:
return f"Analyzed: {query}"
See Advanced Features for detailed decorator documentation.
See Also
- Advanced Features - Skill decorators, custom templates, dependency injection
- Skill Registries - Load skills from Git repos and remote sources
- Types Reference - Type definitions and data structures
- Registries Reference - Registry API documentation
- Exceptions Reference - Exception classes