Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
178 commits
Select commit Hold shift + click to select a range
57e568b
Add `builtin_tools` to `Agent`
Kludex May 14, 2025
97ab44b
make AbstractBuiltinTool serializable
Kludex May 14, 2025
e3dda9d
Add more work on it
Kludex May 14, 2025
3ad6d38
Merge remote-tracking branch 'origin/main' into add-builtin-tools
Kludex May 23, 2025
0b43f65
Add builtin tools
Kludex May 23, 2025
fa7fd11
merge
Kludex May 26, 2025
32324fa
add more built-in-tools
Kludex May 27, 2025
f33e568
Fix test
Kludex May 27, 2025
13d7433
Add support on Groq
Kludex May 27, 2025
ac85205
Add support for Google
Kludex May 28, 2025
c93633f
Add support for MCP's Streamable HTTP transport (#1716)
BrandonShar May 26, 2025
3a8b640
Timeout for initializing MCP client (#1833)
alexmojaki May 27, 2025
360de87
Require mcp 1.9.0+ (#1840)
DouweM May 27, 2025
cb4e539
Don't send empty messages to Anthropic (#1027)
oscar-broman May 27, 2025
4e3769a
Add `vendor_id` and `finish_reason` to Gemini/Google model responses …
davide-andreoli May 27, 2025
ebb536f
Fix units of `sse_read_timeout` `timedelta` (#1843)
alexmojaki May 27, 2025
c8bb611
Support functions as output_type, as well as lists of functions and o…
DouweM May 27, 2025
6bcc1a8
Enhance Gemini usage tracking to collect comprehensive token data (#1…
kiqaps May 28, 2025
97ff651
more
Kludex May 30, 2025
1d47e1e
merge
Kludex May 30, 2025
5f89444
merge
Kludex Jun 1, 2025
9512987
merge
Kludex Jun 20, 2025
800a71a
Pass tests
Kludex Jun 20, 2025
d0f4643
Merge main into builtin-tool branch and resolve conflicts
mattbrandman Jul 1, 2025
bc298d6
Fix remaining merge conflict markers in openai.py, anthropic.py, and …
mattbrandman Jul 1, 2025
46c06c2
add extra google
mattbrandman Jul 1, 2025
3496567
fix formatting
mattbrandman Jul 1, 2025
c193059
fix codespell
mattbrandman Jul 1, 2025
427dec2
fixing types
mattbrandman Jul 1, 2025
866ad21
fixing types in gemini
mattbrandman Jul 1, 2025
4c2622d
misspells are on purpose oops
mattbrandman Jul 1, 2025
c13736e
ignore misspellings
mattbrandman Jul 1, 2025
a42a75d
ignore misspellings
mattbrandman Jul 1, 2025
e2f1daa
fixing comment
mattbrandman Jul 1, 2025
3094a9a
fixing tests and coverage
mattbrandman Jul 1, 2025
6a3c987
fixing types
mattbrandman Jul 1, 2025
ac0edb6
Revert "ignore misspellings"
mattbrandman Jul 2, 2025
374e034
revert to known good
mattbrandman Jul 2, 2025
7cccdd2
merging main
mattbrandman Jul 2, 2025
2393c87
adding anthropic test coverage
mattbrandman Jul 2, 2025
21094a7
adding pragma no cover to has_content
mattbrandman Jul 2, 2025
8ac5294
Merge branch 'main' into builtin-tool
mattbrandman Jul 5, 2025
de8f32d
Merge branch 'main' into builtin-tool
mattbrandman Jul 7, 2025
13bc865
Merge branch 'main' into builtin-tool
Kludex Jul 16, 2025
c0fc35c
Support WebSearch streaming for OpenAI
Kludex Jul 16, 2025
b4b3752
Handle Anthropic streaming
Kludex Jul 16, 2025
3a2481a
Drop extra from dependencies on test
Kludex Jul 16, 2025
306514e
move import up
Kludex Jul 16, 2025
c84be82
add coverage-n
Kludex Jul 16, 2025
a77030b
add coverage-n
Kludex Jul 16, 2025
93e26d6
drop pragma
Kludex Jul 16, 2025
bfb4eef
Update pydantic_ai_slim/pydantic_ai/builtin_tools.py
Kludex Jul 16, 2025
4376fc2
Apply suggestions from code review
mattbrandman Jul 18, 2025
c029d4b
Merge branch 'main' into builtin-tool
mattbrandman Jul 21, 2025
87f59f1
updates types
mattbrandman Jul 21, 2025
3fca6d4
updating types
mattbrandman Jul 21, 2025
7d50564
Add `async with self` in `agent_to_a2a` (#2266)
Kludex Jul 21, 2025
37a1845
fixing event
mattbrandman Jul 21, 2025
5b031d6
Merge branch 'main' into builtin-tool
mattbrandman Jul 21, 2025
9ca4bca
Fix include_content not working as expected (#2206)
adtyavrdhn Jul 21, 2025
e1085fa
updates
mattbrandman Jul 21, 2025
ae1d4d9
Merge branch 'main' into builtin-tool
mattbrandman Jul 21, 2025
09bd7dd
Support streamable HTTP in mcp-run-python (#2230)
Kigstn Jul 21, 2025
3ee4aa9
Merge branch 'main' into builtin-tool
mattbrandman Jul 21, 2025
091c499
change `format_as_xml` defaults (#2228)
samuelcolvin Jul 21, 2025
9d24f5b
Merge branch 'main' into builtin-tool
mattbrandman Jul 21, 2025
87871b3
Fix LLMJudge input handling to preserve BinaryContent as separate mes…
adtyavrdhn Jul 21, 2025
772af1d
validate OpenAI responses (#2226)
samuelcolvin Jul 22, 2025
c78fa3f
Remove duplicate field on GeminiModelSettings (#2269)
strawgate Jul 22, 2025
3ceff58
Fix AG-UI shared state example (#2272)
stevenh Jul 22, 2025
932c888
Correct code snippet for native output (#2271)
minhduc0711 Jul 22, 2025
2b180f3
chore: simplify output function call with model retry (#2273)
bitnahian Jul 22, 2025
8112002
Fix pydantic-evals panel rendering with evaluators (#2274)
dmontagu Jul 22, 2025
66f1868
Reduce duplication between StreamedRunResult and AgentStream (#2275)
DouweM Jul 22, 2025
07f7892
Merge branch 'main' into builtin-tool
mattbrandman Jul 22, 2025
0f46928
Fix mp3 handling (#2279)
dmontagu Jul 23, 2025
a589f30
fix: use `FileUrl.format` to find the extension (#2280)
Kludex Jul 23, 2025
07e46b3
chore: add `CLAUDE.md` (#2281)
Kludex Jul 23, 2025
7d867ee
Merge branch 'main' into builtin-tool
mattbrandman Jul 23, 2025
1e18729
Handle built-in tool errors better in tool registration (#2252)
fswair Jul 23, 2025
f3ad3e6
Enable URL and binary PDF for Mistral (#2267)
pintaf Jul 23, 2025
0b3d020
Speed up function `_estimate_string_tokens` (#2156)
misrasaurabh1 Jul 23, 2025
ba3f6b2
Update pydantic_ai_slim/pydantic_ai/agent.py
Kludex Jul 23, 2025
903f11e
Ignore empty text alongside tool calls when streaming from Ollama (#2…
DouweM Jul 23, 2025
b686001
Handle `None` `created` timestamp coming from OpenRouter API (#2247)
R0boji Jul 23, 2025
e295e5e
Rename `MCPServer` `sse_read_timeout` to `read_timeout` and pass to `…
AntSan813 Jul 23, 2025
a0c3abb
Update cohere and MCP, add support for MCP ResourceLink returned from…
medaminezghal Jul 24, 2025
2af4db6
Add Vercel AI Gateway provider (#2277)
joshualipman123 Jul 24, 2025
7eb4491
Parse '<think>' tags in streamed text as thinking parts (#2290)
DouweM Jul 24, 2025
da80f5d
Fix AG-UI parallel tool calls (#2301)
DouweM Jul 24, 2025
fc6a2b2
Support passing files uploaded to Gemini Files API and setting custom…
dprov Jul 24, 2025
6d8a4df
Update MCP docs to show you can pass SSL/TLS options via the `http_cl…
assadyousuf Jul 24, 2025
7728c2a
Add MoonshotAI provider with Kimi-K2 model support (#2211)
zachmayer Jul 24, 2025
bc4facd
Include ThinkingPart in messages.md API documentation graph (#2299)
lfloeer Jul 24, 2025
94b4305
Fix docs build failure by adding MoonshotAIProvider to API docs (#2304)
DouweM Jul 24, 2025
4104aca
Fix initial tool call args not being streamed with AG-UI (#2303)
DouweM Jul 24, 2025
41dd069
Ignore leading whitespace when streaming text, fixing run_stream + Ol…
DouweM Jul 24, 2025
5cf372a
fix: close initialized MCP server if any MCP server fails to initaliz…
hartungstenio Jul 25, 2025
4941468
Add tenacity utilities/integration for improved retry handling (#2282)
dmontagu Jul 25, 2025
6e60677
Adding thinkingpart to otel_events in ModelResponse (#2237)
adtyavrdhn Jul 25, 2025
6207ac6
Add Claude Code action so we can tag @claude on issues and PRs (#2315)
DouweM Jul 25, 2025
1ae6155
addressing comments
mattbrandman Jul 26, 2025
3f8cc2d
Merge branch 'main' into builtin-tool
mattbrandman Jul 26, 2025
ba962a7
updates
mattbrandman Jul 26, 2025
bfd9b21
fixing lint
mattbrandman Jul 26, 2025
e2fef42
fixing lint
mattbrandman Jul 26, 2025
b1ef2f8
fix misspellings
mattbrandman Jul 26, 2025
e9cacc3
rename servertool to builtin tool everywhere
mattbrandman Jul 26, 2025
aa91640
fixing ordering
mattbrandman Jul 28, 2025
806d56d
Fix: TypeError in MCPServerSSE due to improper initialization (#2319)
tradeqvest Jul 28, 2025
2d451a7
Merge branch 'main' into builtin-tool
mattbrandman Jul 28, 2025
33aaef1
Pin tokenizers <= 0.21.2 as later 0.21.4 doesn't have required wheels…
DouweM Jul 28, 2025
86d70b5
Fix: AG-UI assistant text and tool call order (#2328)
ChuckJonas Jul 28, 2025
004d63b
Revert "Pin tokenizers <= 0.21.2 as later 0.21.4 doesn't have require…
DouweM Jul 28, 2025
0260a31
Allow `default` in tool schema with Gemini (#2309)
strawgate Jul 28, 2025
168680a
Fix AgentStream.stream_output and StreamedRunResult.stream_structured…
DouweM Jul 28, 2025
2fca506
Ensure AG-UI state is isolated between requests. (#2343)
DouweM Jul 28, 2025
ab92e67
Refine retry logic for parallel tool calling (#2317)
DouweM Jul 28, 2025
362dcbf
Set up environment for @claude, allow it make and uv, and reading CI …
DouweM Jul 29, 2025
8f20f9b
Remove older deprecated models of Anthropic (#2345)
medaminezghal Jul 29, 2025
c7a3591
Revert "Remove older deprecated models of Anthropic" (#2358)
DouweM Jul 29, 2025
3e1f634
Fix parallel tool calling with tools returning ToolReturn with conten…
DouweM Jul 29, 2025
0584724
Add HTTP Referer request header to Vercel AI Gateway provider (#2369)
joshualipman123 Jul 30, 2025
29c72a6
Always enter Toolset context when running agent (#2361)
strawgate Jul 30, 2025
80a7284
Add `priority` `service_tier` to `OpenAIModelSettings` and respect it…
akenarsari Jul 30, 2025
69e90bc
Add an example of using RunContext to pass data among tools (#2316)
tonyxwz Aug 1, 2025
749dc98
Rename gemini-2.5-flash-lite-preview-06-17 to gemini-2.5-flash-lite a…
ethan01x Aug 1, 2025
6354c7f
Fix toggleable toolset example so toolset state is not shared across …
DouweM Aug 1, 2025
6515302
Support custom thinking tags specified on the model profile (#2364)
xjose97x Aug 1, 2025
7746f77
Add convenience functions to handle AG-UI requests with request-speci…
DouweM Aug 1, 2025
4e75448
docs: add missing optional packages in `install.md` (#2412)
Kludex Aug 4, 2025
ef98e33
Include default values in tool arguments JSON schema (#2418)
DouweM Aug 4, 2025
f8dbc31
Fix "test_download_item_no_content_type test fails on macOS" (#2404)
strawgate Aug 4, 2025
f36aaa6
Allow string format, pattern and others in OpenAI strict JSON mode (#…
DouweM Aug 4, 2025
d78b77e
Let more `BaseModel`s use OpenAI strict JSON mode by defaulting to `a…
DouweM Aug 4, 2025
97834d6
BREAKING CHANGE: Change type of 'source' field on EvaluationResult (#…
dmontagu Aug 4, 2025
5510e81
Fix ImageUrl, VideoUrl, AudioUrl and DocumentUrl not being serializab…
DouweM Aug 4, 2025
74d94ec
BREAKING CHANGE: Support printing reasons in the console output for p…
dmontagu Aug 4, 2025
07f54f9
Document performance implications of async vs sync tools (#2298)
GuillermoBlasco Aug 4, 2025
d75fd42
Mention that tools become toolset internally (#2395)
HamzaFarhan Aug 4, 2025
c2940ff
Fix tests for Logfire>=3.22.0 (#2346)
medaminezghal Aug 5, 2025
544ff88
tests: speed up the test suite (#2414)
Kludex Aug 5, 2025
f7947f4
google: add more information about schema on union (#2426)
Kludex Aug 5, 2025
d914918
typo in output docs (#2427)
Tiksagol Aug 6, 2025
505b594
Deprecate `GeminiModel` in favor of `GoogleModel` (#2416)
Kludex Aug 6, 2025
3ae5e6c
Use `httpx` on `GoogleProvider` (#2438)
Kludex Aug 6, 2025
223a58f
Remove older deprecated models and add new model of Anthropic (#2435)
medaminezghal Aug 6, 2025
d80ed96
Remove `next()` method from `Graph` (#2440)
Kludex Aug 6, 2025
b6fa8e7
BREAKING CHANGE: Remove `data` from `FinalResult` (#2443)
Kludex Aug 6, 2025
622d3ac
BREAKING CHANGE: Remove `get_data` and `validate_structured_result` f…
Kludex Aug 6, 2025
8f131eb
docs: add `griffe_warnings_deprecated` (#2444)
Kludex Aug 6, 2025
a822df9
BREAKING CHANGE: Remove `format_as_xml` module (#2446)
Kludex Aug 6, 2025
d51906b
BREAKING CHANGE: Remove `result_type` parameter and similar from `Age…
Kludex Aug 6, 2025
7787334
Deprecate `GoogleGLAProvider` and `GoogleVertexProvider` (#2450)
Kludex Aug 6, 2025
13b712f
BREAKING CHANGE: drop 4 months old deprecation warnings (#2451)
Kludex Aug 6, 2025
6d4eb06
Automatically use OpenAI strict mode for strict-compatible native out…
DouweM Aug 6, 2025
38b5b7d
addressing comments
mattbrandman Aug 6, 2025
359b9e1
Merge upstream/main into builtin-tool branch - resolved conflicts
mattbrandman Aug 6, 2025
bd6e5f7
Fix failing tests after merge - update snapshots for builtin tools
mattbrandman Aug 6, 2025
69267ca
fixing types
mattbrandman Aug 6, 2025
1ad1369
Make `InlineDefsJsonSchemaTransformer` public (#2455)
DouweM Aug 6, 2025
915135f
Send `ThinkingPart`s back to Anthropic used through Bedrock (#2454)
DouweM Aug 6, 2025
c2f3899
Bump boto3 to support `AWS_BEARER_TOKEN_BEDROCK` API key env var (#2456)
DouweM Aug 6, 2025
1a4a0f3
Merge remote-tracking branch 'origin/main' into builtin-tool
Kludex Aug 7, 2025
c9d0d18
Remove deprecated stuff from yesterday
Kludex Aug 7, 2025
37a5ddd
Add new Heroku models (#2459)
Kludex Aug 7, 2025
a631229
Merge branch 'main' into builtin-tool
Kludex Aug 7, 2025
78fe612
Simplify cohere
Kludex Aug 7, 2025
a673c90
refactor a bit
Kludex Aug 7, 2025
df2ad47
Handle Google builtin tools
Kludex Aug 7, 2025
b4add90
Add test for unsupported builtin tools
Kludex Aug 7, 2025
dec1ba3
Add 100% coverage
Kludex Aug 7, 2025
e134d43
fix linting issue
Kludex Aug 7, 2025
ef4ab6a
Add API documentation for builtin tools
Kludex Aug 7, 2025
bb98ccf
Add documentation
Kludex Aug 7, 2025
739f142
pass docs tests
Kludex Aug 7, 2025
cc7ab39
Add Groq model profile for compound models that always have web searc…
DouweM Aug 7, 2025
5534bf4
add pragma
Kludex Aug 7, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 17 additions & 13 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ jobs:
env:
UV_PYTHON: ${{ matrix.python-version }}
CI: true
COVERAGE_PROCESS_START: ./pyproject.toml
steps:
- uses: actions/checkout@v4

Expand All @@ -151,20 +152,20 @@ jobs:
with:
deno-version: v2.x

- run: mkdir coverage
- run: mkdir .coverage

# run tests with just `pydantic-ai-slim` dependencies
- run: uv run --package pydantic-ai-slim coverage run -m pytest
- run: uv run --package pydantic-ai-slim coverage run -m pytest -n auto --dist=loadgroup
env:
COVERAGE_FILE: coverage/.coverage.${{ runner.os }}-py${{ matrix.python-version }}-slim
COVERAGE_FILE: .coverage/.coverage.${{ runner.os }}-py${{ matrix.python-version }}-slim

- run: uv run coverage run -m pytest
- run: uv run coverage run -m pytest -n auto --dist=loadgroup
env:
COVERAGE_FILE: coverage/.coverage.${{ runner.os }}-py${{ matrix.python-version }}-standard
COVERAGE_FILE: .coverage/.coverage.${{ runner.os }}-py${{ matrix.python-version }}-standard

- run: uv run --all-extras coverage run -m pytest
- run: uv run --all-extras coverage run -m pytest -n auto --dist=loadgroup
env:
COVERAGE_FILE: coverage/.coverage.${{ runner.os }}-py${{ matrix.python-version }}-all-extras
COVERAGE_FILE: .coverage/.coverage.${{ runner.os }}-py${{ matrix.python-version }}-all-extras

- run: uv run --all-extras python tests/import_examples.py

Expand All @@ -173,15 +174,15 @@ jobs:
if: matrix.python-version != '3.9'
run: |
unset UV_FROZEN
uv run --all-extras --resolution lowest-direct coverage run -m pytest
uv run --all-extras --resolution lowest-direct coverage run -m pytest -n auto --dist=loadgroup
env:
COVERAGE_FILE: coverage/.coverage.${{ runner.os }}-py${{ matrix.python-version }}-lowest-versions
COVERAGE_FILE: .coverage/.coverage.${{ runner.os }}-py${{ matrix.python-version }}-lowest-versions

- name: store coverage files
uses: actions/upload-artifact@v4
with:
name: coverage-${{ matrix.python-version }}
path: coverage
path: .coverage
include-hidden-files: true

coverage:
Expand All @@ -197,15 +198,15 @@ jobs:
uses: actions/download-artifact@v4
with:
merge-multiple: true
path: coverage
path: .coverage

- uses: astral-sh/setup-uv@v5
with:
enable-cache: true

- run: uv sync --package pydantic-ai-slim --only-dev
- run: rm coverage/.coverage.*-py3.9-* # Exclude 3.9 coverage as it gets the wrong line numbers, causing invalid failures.
- run: uv run coverage combine coverage
- run: rm .coverage/.coverage.*-py3.9-* # Exclude 3.9 coverage as it gets the wrong line numbers, causing invalid failures.
- run: uv run coverage combine

- run: uv run coverage html --show-contexts --title "Pydantic AI coverage for ${{ github.sha }}"

Expand All @@ -228,7 +229,10 @@ jobs:

- run: uv run coverage report --fail-under 100
- run: uv run diff-cover coverage.xml --fail-under 100

- run: uv run strict-no-cover
env:
COVERAGE_FILE: .coverage/.coverage

test-mcp-run-python:
runs-on: ubuntu-latest
Expand Down
58 changes: 58 additions & 0 deletions .github/workflows/claude.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Claude Code

on:
issue_comment:
types: [created]
pull_request_review_comment:
types: [created]
issues:
types: [opened, assigned]
pull_request_review:
types: [submitted]

env:
UV_PYTHON: 3.13
UV_FROZEN: "1"

jobs:
claude-code-action:
if: |
(github.event_name == 'issue_comment' && contains(github.event.comment.body, '@claude')) ||
(github.event_name == 'pull_request_review_comment' && contains(github.event.comment.body, '@claude')) ||
(github.event_name == 'pull_request_review' && contains(github.event.review.body, '@claude')) ||
(github.event_name == 'issues' && contains(github.event.issue.body, '@claude'))
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: read
issues: read
id-token: write
actions: read
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 1

- uses: astral-sh/setup-uv@v5
with:
enable-cache: true

- uses: denoland/setup-deno@v2
with:
deno-version: v2.x

- run: uv tool install pre-commit

- run: make install

- name: Run Claude PR Action
uses: anthropics/claude-code-action@beta
with:
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
timeout_minutes: "60"
additional_permissions: |
actions: read
allowed_tools: |
Bash(make:*)
Bash(uv:*)
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ examples/pydantic_ai_examples/.chat_app_messages.sqlite
.vscode/
/question_graph_history.json
/docs-site/.wrangler/
/CLAUDE.md
node_modules/
**.idea/
.coverage*
/test_tmp/
.mcp.json
127 changes: 127 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
# CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

## Development Commands

### Core Development Tasks
- **Install dependencies**: `make install` (requires uv, pre-commit, and deno)
- **Run all checks**: `make` (format, lint, typecheck, test with coverage)
- **Format code**: `make format`
- **Lint code**: `make lint`
- **Type checking**: `make typecheck` (uses pyright) or `make typecheck-both` (pyright + mypy)
- **Run tests**: `make test` (with coverage)
- **Build docs**: `make docs` or `make docs-serve` (local development)

### Single Test Commands
- **Run specific test**: `uv run pytest tests/test_agent.py::test_function_name -v`
- **Run test file**: `uv run pytest tests/test_agent.py -v`
- **Run with debug**: `uv run pytest tests/test_agent.py -v -s`

### Multi-Python Testing
- **Install all Python versions**: `make install-all-python`
- **Test all Python versions**: `make test-all-python`

## Project Architecture

### Core Components

**Agent System (`pydantic_ai_slim/pydantic_ai/agent.py`)**
- `Agent[AgentDepsT, OutputDataT]`: Main orchestrator class with generic types for dependency injection and output validation
- Entry points: `run()`, `run_sync()`, `run_stream()` methods
- Handles tool management, system prompts, and model interaction

**Model Integration (`pydantic_ai_slim/pydantic_ai/models/`)**
- Unified interface across providers: OpenAI, Anthropic, Google, Groq, Cohere, Mistral, Bedrock, HuggingFace
- Model strings: `"openai:gpt-4o"`, `"anthropic:claude-3-5-sonnet"`, `"google:gemini-1.5-pro"`
- `ModelRequestParameters` for configuration, `StreamedResponse` for streaming

**Graph-based Execution (`pydantic_graph/` + `_agent_graph.py`)**
- State machine execution through: `UserPromptNode` → `ModelRequestNode` → `CallToolsNode`
- `GraphAgentState` maintains message history and usage tracking
- `GraphRunContext` provides execution context

**Tool System (`tools.py`, `toolsets/`)**
- `@agent.tool` decorator for function registration
- `RunContext[AgentDepsT]` provides dependency injection in tools
- Support for sync/async functions with automatic schema generation

**Output Handling**
- `TextOutput`: Plain text responses
- `ToolOutput`: Structured data via tool calls
- `NativeOutput`: Provider-specific structured output
- `PromptedOutput`: Prompt-based structured extraction

### Key Design Patterns

**Dependency Injection**
```python
@dataclass
class MyDeps:
database: DatabaseConn

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

@agent.tool
async def get_data(ctx: RunContext[MyDeps]) -> str:
return await ctx.deps.database.fetch_data()
```

**Type-Safe Agents**
```python
class OutputModel(BaseModel):
result: str
confidence: float

agent: Agent[MyDeps, OutputModel] = Agent(
'openai:gpt-4o',
deps_type=MyDeps,
output_type=OutputModel
)
```

## Workspace Structure

This is a uv workspace with multiple packages:
- **`pydantic_ai_slim/`**: Core framework (minimal dependencies)
- **`pydantic_evals/`**: Evaluation system
- **`pydantic_graph/`**: Graph execution engine
- **`examples/`**: Example applications
- **`clai/`**: CLI tool
- **`mcp-run-python/`**: MCP server implementation (Deno/TypeScript)

## Testing Strategy

- **Unit tests**: `tests/` directory with comprehensive model and component coverage
- **VCR cassettes**: `tests/cassettes/` for recorded LLM API interactions
- **Test models**: Use `TestModel` for deterministic testing
- **Examples testing**: `tests/test_examples.py` validates all documentation examples
- **Multi-version testing**: Python 3.9-3.13 support

## Key Configuration Files

- **`pyproject.toml`**: Main workspace configuration with dependency groups
- **`pydantic_ai_slim/pyproject.toml`**: Core package with model optional dependencies
- **`Makefile`**: Development task automation
- **`uv.lock`**: Locked dependencies for reproducible builds

## Important Implementation Notes

- **Model Provider Integration**: Each provider in `models/` directory implements the `Model` abstract base class
- **Message System**: Vendor-agnostic message format in `messages.py` with rich content type support
- **Streaming Architecture**: Real-time response processing with validation during streaming
- **Error Handling**: Specific exception types with retry mechanisms at multiple levels
- **OpenTelemetry Integration**: Built-in observability support

## Documentation Development

- **Local docs**: `make docs-serve` (serves at http://localhost:8000)
- **Docs source**: `docs/` directory (MkDocs with Material theme)
- **API reference**: Auto-generated from docstrings using mkdocstrings

## Dependencies Management

- **Package manager**: uv (fast Python package manager)
- **Lock file**: `uv.lock` (commit this file)
- **Sync command**: `make sync` to update dependencies
- **Optional extras**: Define groups in `pyproject.toml` optional-dependencies
7 changes: 2 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,10 @@ typecheck-both: typecheck-pyright typecheck-mypy

.PHONY: test
test: ## Run tests and collect coverage data
uv run coverage run -m pytest
COVERAGE_PROCESS_START=./pyproject.toml uv run coverage run -m pytest -n auto --dist=loadgroup
@uv run coverage combine
@uv run coverage report

.PHONY: test-fast
test-fast: ## Same as test except no coverage and 4x faster depending on hardware
uv run pytest -n auto --dist=loadgroup

.PHONY: test-all-python
test-all-python: ## Run tests on Python 3.9 to 3.13
UV_PROJECT_ENVIRONMENT=.venv39 uv run --python 3.9 --all-extras --all-packages coverage run -p -m pytest
Expand Down
Loading
Loading