> ## Documentation Index
> Fetch the complete documentation index at: https://docs.decimal.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Pydantic AI

> Auto-load registry skills into every Pydantic AI Agent, with the live load_skill tool for on-demand skill bodies.

The Pydantic AI adapter is a **skills integration**: it auto-loads your skill menu into every `Agent`'s system prompt and registers the live `load_skill` tool so the model can pull full skill bodies mid-turn. It does not have its own tracing — Pydantic AI calls the provider SDK underneath, so tracing flows through a provider integration you install alongside.

## Install

```bash theme={null}
pip install "decimalai[pydantic-ai]"
```

## Use

```python theme={null}
import decimalai
decimalai.init(api_key="dai_sk_...")

from decimalai.pydantic_ai import install
install(enable_skill_loader=True)

from pydantic_ai import Agent
agent = Agent("openai:gpt-4o", system_prompt="You are helpful")
# Skills are now auto-loaded into every agent.run() call.
```

<Note>
  **`install()`-only integration.** There is no `init(pydantic_ai=True)` flag and no `DECIMAL_AUTO_TRACE` value for Pydantic AI — call `decimalai.pydantic_ai.install()` explicitly after `init()`. The one parameter is `enable_skill_loader` (default `False`; the install is a no-op without it).
</Note>

## How it works

`install(enable_skill_loader=True)` monkeypatches `pydantic_ai.Agent.__init__` so every Agent constructed afterwards gets:

1. **A skills system prompt** — a registered `system_prompt` function that calls `SkillRouter.build_prompt_fragment()` per turn and prepends the skill menu to your base system prompt.
2. **The `load_skill` tool** — registered via `tool_plain`. Pydantic AI owns its tool loop, so when the model calls `load_skill("name")`, the full skill body routes back mid-turn. A body served this way counts as *delivered and activated* on the [usage ladder](/sdk/python/skills); menu rows alone count as *offered*.

The tool is on by default whenever the loader is enabled. Kill switch: `decimalai.init(load_skill_tool=False)` or `DECIMALAI_LOAD_SKILL_TOOL=0`.

## Menu mode: full menu, not smart routing

The user message isn't available to a Pydantic AI system-prompt function, so the loader runs in **full-menu mode** — every active skill's name + description is offered each turn. If you want query-aware smart routing instead, skip the loader and build the fragment yourself with explicit context:

```python theme={null}
from decimalai.skill_router import SkillRouter

router = SkillRouter(api_key="dai_sk_...")
fragment, routing_id = router.build_prompt_fragment(query=user_message)

agent = Agent("openai:gpt-4o", system_prompt=f"You are helpful.\n{fragment}")
```

## Tracing

Pair the skill loader with a tracing integration for the provider underneath:

```python theme={null}
# OpenAI models under Pydantic AI:
decimalai.init(api_key="dai_sk_...", openai=True)     # raw OpenAI SDK tracing

# Anthropic models:
decimalai.init(api_key="dai_sk_...", anthropic=True)
```

Provider flags drive OpenInference instrumentors, so install the matching package too — `openinference-instrumentation-openai` / `openinference-instrumentation-anthropic` — or the flag warns and skips tracing.

Manifests aren't auto-detected on this adapter — use [`register_manifest()`](/sdk/python/manifests) if you want regression checks over your Pydantic AI agent's config.

## Caveats

* `install()` only affects Agents constructed **after** it runs — call it before you build your agents.
* This adapter never reads or writes disk skills (no `disk_sync` parameter). If you run inside a disk-loading runtime (Claude Code, Cursor), the SDK logs a one-shot warning about duplicate-injection risk when the loader is enabled.
* Skill-loader failures are non-fatal by design: if the router is unreachable, the system prompt gains no skills and `load_skill` returns an error string the model can read — your agent keeps running.

<Check>
  **Checkpoint:** construct an Agent after `install(enable_skill_loader=True)` and run it once with a query matching one of your skills. Logs show `DecimalAI SkillRouter loader installed (Pydantic AI)`, and the model's tool log shows a `load_skill` call when it needs a body. If no skills appear, the router had none to offer — check your workspace has forked skills (see the silent no-ops list in the [Quickstart](/quickstart#if-something-looks-wrong-the-six-silent-no-ops)).
</Check>

## What's next

<CardGroup cols={2}>
  <Card title="Skills" icon="puzzle-piece" href="/sdk/python/skills">
    Menu vs body delivery, the load\_skill tool, and the usage ladder.
  </Card>

  <Card title="Manifests" icon="layer-group" href="/sdk/python/manifests">
    Register a manifest explicitly for regression checks.
  </Card>
</CardGroup>
