PydanticAI Tool System for Openclaw

A comprehensive system for registering, documenting, and managing function-calling tools within the PydanticAI framework.

anderskev
v1.0.1
Apr 22, 2026
0
957
0

Install & Download

1. ClawHub CLI

The fastest way to install a skill directly from the registry.

npx clawhub@latest install pydantic-ai-tool-system

2. Manual Installation

Copy the skill folder to one of these locations

Global
~/.openclaw/skills/
Workspace
<project>/skills/

Priority: Workspace > Local > Bundled

3. Prompt Installation

Copy this prompt to OpenClaw to install it automatically.

Help me install pydantic-ai-tool-system using Clawhub. If Clawhub is not installed, install it first (npm i -g clawhub).

Prefer to download?

Get the raw skill files in a ZIP archive.

What is PydanticAI Tool System?

The PydanticAI Tool System provides a structured way to extend AI agents with custom capabilities through function calling. By leveraging Python's type hinting and Pydantic's validation, it allows developers to create robust interfaces that LLMs can reliably interact with. This Openclaw Skills component ensures that your agent can perform real-world actions like database queries, API calls, and complex calculations while maintaining strict type safety.

At its core, the system distinguishes between tools that require execution context (dependencies, usage tracking, and message history) and plain tools that operate independently. By using specialized decorators and standard docstring formats, it bridges the gap between raw Python code and AI-readable instructions, making it a vital part of any Openclaw Skills implementation focused on agentic workflows.

PydanticAI Tool System Use Cases

  • Building AI agents that need to interact with external databases or secure APIs.
  • Implementing dynamic tool access where capabilities change based on user roles or permissions.
  • Creating multi-agent systems where tools are grouped into modular sets for better organization.
  • Developing data-driven agents that return complex Pydantic models or media content like images.

How PydanticAI Tool System Works

  1. Define the tool function using either the @agent.tool or @agent.tool_plain decorator based on whether access to RunContext is needed.
  2. Apply strict type annotations to all parameters and return types to ensure the LLM receives accurate schema information.
  3. Write descriptive docstrings (Google or Sphinx style) to provide the AI model with the necessary instructions on when and how to use the tool.
  4. Register the tools with an Agent instance, optionally grouping them into FunctionToolsets for larger projects.
  5. During execution, the agent evaluates the user prompt and selects the appropriate tool, passing parameters that match the defined Pydantic schema.

PydanticAI Tool System Setup

To get started with this tool system within your Openclaw Skills project, ensure you have pydantic-ai installed:

pip install pydantic-ai

Basic implementation example:

from pydantic_ai import Agent

agent = Agent('openai:gpt-4o')

@agent.tool_plain
def get_weather(location: str) -> str:
    """Get the current weather for a location.

    Args:
        location: The city and state.
    """
    return f"The weather in {location} is sunny."

PydanticAI Tool System Data Schema & Taxonomy

The PydanticAI Tool System organizes data through structured schemas and metadata to ensure seamless LLM integration:

Component Description
RunContext Contains deps (dependencies), usage (tokens), and messages (history).
ToolDefinition Metadata including tool name, description, and JSON schema for parameters.
ToolReturn A wrapper for complex return types like ImageUrl or specialized binary data.
FunctionToolset A collection of related tools that can be shared across multiple agents.

PydanticAI Tool System Advanced Features

  • Dynamic Tool Preparation: Use prepare_tools to filter or modify available functions at runtime based on the specific request context.
  • Custom Return Types: Support for ToolReturn objects allowing agents to return non-textual data like images directly from tools.
  • Combined Toolsets: Ability to merge multiple FunctionToolset objects to create complex, multi-domain agent capabilities.
  • Usage Tracking: Access real-time token usage and retry counts directly within the tool logic via RunContext.

SKILL.md


Loading

Related Openclaw Skills

METADATA

Github Stars: 0
forks: 0

Featured*