Repository guide · overview · v6
pydantic / pydantic-ai
“How Python does AI. Agents, realtime voice, image generation, embeddings. Every model, every interface, typed end to end.” — as described by its authors
- AI Agents
- Python
- MIT · open-source license
- Original repository
- pydantic/pydantic-ai
- Source platform
- GitHub
- Repository owner / organization
- pydantic
- License
- MIT · open-source license
- Analyzed revision
- a0022cd089c90121f101f7966fdb492a092d4330
- Last verified
Newer revision observed; parts of this guide may be outdated. The default branch moved to f93bcff0c72c, checked 2026-11-15. The whole guide describes revision a0022cd089c9. A revision diff found changes in 10 code regions it cites (listed below); statements about those regions may not hold at the new revision and have not been rechecked yet.
- pydantic_ai_slim/pydantic_ai/agent/__init__.py:531-4856 · lines changed
- pydantic_ai_slim/pydantic_ai/messages.py:232-291 · lines changed
- pydantic_ai_slim/pydantic_ai/messages.py:575-621 · lines changed
- pydantic_ai_slim/pydantic_ai/messages.py:780-932 · lines changed
- pydantic_ai_slim/pydantic_ai/exceptions.py:172-187 · lines changed
- pydantic_ai_slim/pydantic_ai/models/__init__.py:747-2140 · lines changed
- … and 4 more
pydantic/pydantic-ai repository overview
Terms used on this page
- Entrypoint record
- A file the analyzer marks as a place where execution can start. When it carries a __main__ guard excerpt, the file contains an if __name__ == "__main__": block and the excerpt shows what that block calls; without an excerpt, the file was flagged by its name only.
- Bounded static execution path
- A call chain reconstructed from the source code without running it, stopped after a fixed number of steps. It shows how far the code can be followed on paper, not what happens at run time.
- Unresolved boundary
- Where a static path stops because the next call goes into an external library or cannot be resolved without running the code. It marks the edge of this analysis, not a defect in the repository.
- Static relations
- Calls and imports found in the source. "External or unresolved" relations point outside the analyzed files.
- Module role
- The analyzer's label for a file, inferred from how many calls go in and out (for example core, entry/orchestration, leaf). It describes a position in the call graph, not the authors' design.
- Test-like files
- Files whose names or locations look like tests. This analysis counts them; it does not run them.
- Observed · inferred · author-claimed · unresolved
- How each statement is supported: read directly from the analyzed files; derived by the analyzer from them; stated by the repository's authors (metadata, README); or not established by this analysis.
- Verified
- Two uses on these pages. In an analyzer record ("verified provenance", "a verified entrypoint") it means the record was read directly from the analyzed files, which these guides call observed; for an entrypoint, the __main__ guard text is present. Since the analyzer fix of 2026-10-04, a file that only has an entrypoint-like name such as cli.py or main.py is recorded as inferred; guides analyzed before that still call such a file verified, and it is still only a guess about how the file is used. It does not mean the code was run or tested. "Last verified" is the date the guide last passed the lab's checks against the analysis record of the stated revision; it is not a review of the repository itself.
A multi-package repository, mostly Python and MIT-licensed. It holds a core library in pydantic_ai_slim, plus pydantic_graph, pydantic_evals, CLI packages, examples and a very large test suite. Static call degree points to the messages, models and agent modules as the core. Most relations stay unresolved, and nothing was executed for this overview.
What it is
Platform metadata describes the project as a typed Python toolkit for AI that covers agents, realtime voice, image generation and embeddings across models and interfaces. This is an author claim.
Its GitHub topics include agent-framework, genai, llm and pydantic. The primary language is Python and the license is MIT. By bytes the code is overwhelmingly Python, with smaller amounts of TypeScript, PLpgSQL, Shell and CSS.
Structurally it is a multi-package repository:
- the core library lives in
pydantic_ai_slim/pydantic_ai, which contains theAgentclass; pydantic_graphandpydantic_evalseach carry their ownpyproject.toml;claihas another manifest.
The analyzer's own auto-summary calls the repository a web or Node.js application whose main starting place is a .claude helper script. That label conflicts with the platform metadata and is not relied on here.
How it starts
Many files carry a __main__ guard, spread across .github/scripts, examples, scripts and tests. They fall into groups:
- user-facing CLIs:
pydantic_ai_slim/pydantic_ai/__main__.py(callscli_exit()),clai/clai/__main__.pyandsrc/pydantic_clai2/pydantic_clai2/__main__.py; - runnable examples in
examples/pydantic_ai_examples, some serving ASGI apps through uvicorn and others usingasyncio.run; - automation and maintenance scripts in
.github/scriptsandscripts, plus MCP test servers undertests.
Some further entrypoints are only guessed from file names. These include slack_lead_qualifier/app.py, ui/_web/app.py and the pydantic_clai2 cli/cli.py.
The only bounded static flow in the packet runs through .claude/skills/testing-skill/parse_cassette.py. It goes from __main__ to main and ends at unresolved calls such as argparse.ArgumentParser and parser.parse_args. This file appears to be a test-tooling helper, not the library's request path. How a CLI call reaches Agent and a model is not established by this analysis.
Structure and most connected modules
By file count, the largest top-level directories are tests (3423), src (787), pydantic_ai_slim (490), docs (454), .github (255) and examples (63). The analyzer flags docs, src and tests as likely subsystems.
Resolved static call degree inside pydantic_ai_slim/pydantic_ai suggests the following roles:
messages.py(497 in / 102 out),exceptions.py(541 in / 0 out) and_utils.py(313 in) look like widely shared building blocks.agent/__init__.py(4 in / 244 out) and_agent_graph.py(29 in / 157 out) look like orchestration layers that call into the rest.models/__init__.py(165 in / 127 out) sits in the middle, likely as the model abstraction hub.ui/vercel_ai/_adapter.py(0 in / 138 out) andrealtime/_openai_protocol.py(84 in / 39 out) look like integration-facing modules.
The two highest-incoming modules are test helpers: tests/clai2/menu_script.py (699) and tests/clai2/dialog_script.py (558). Degree alone therefore does not equal architectural importance.
Dependencies and tests
Dependency records are partial. The packet shows:
pydantic_graphdeclares runtime dependencies on anyio, logfire-api, pydantic (>=2.12) and typing-inspection.pydantic_evalslists logfire as optional.- The root
pyproject.tomldev group includes pytest, pytest-xdist, pytest-mock, inline-snapshot, dirty-equals, hypothesis, coverage and cassetter, plus mypy, pyright and ruff. src/pydantic_clai2/web-ui/package.jsondeclares a React/Vite frontend using react, marked, highlight.js and dompurify.tests/ui_roundtrip/package.jsonlists @ag-ui/client, ai and rxjs.
The repository has 10 build/dependency manifests. The parser reads pyproject.toml, requirements files and package.json, but not setup.py, setup.cfg, Pipfile or lock files. No dependency records for the core pydantic_ai_slim package appear here, so its runtime requirements are not established.
The analyzer counts 3447 test or test-like files. Even the .github/scripts automation has its own tests, such as test_agent_provider_health.py.
What to read first
README.mdand the rootpyproject.toml, both flagged as project-level important files.pydantic_ai_slim/pydantic_ai/__main__.pyfor the CLI entry, thenagent/__init__.pyfor theAgentclass.messages.py,models/__init__.pyand_agent_graph.py, the high-degree core candidates.- A small example such as
examples/pydantic_ai_examples/pydantic_model.py. Its main block callsagent.run_syncand prints the result's output and usage.
The analyzer's important-file list also ranks .claude/skills/testing-skill/parse_cassette.py and several .github/scripts files highly. They are listed only because they are likely entrypoints. They appear to be repository tooling and can wait.
Limits of this analysis
- Of 150000 extracted relations, 125235 are external or unresolved and 24765 are local.
- Extraction is capped at 150000 relations per repository, and that cap was hit. Files late in the scan have no edges, so the degree figures above are incomplete.
- Nine files over 400 kB were inventoried but not parsed. These include
pydantic_ai_slim/pydantic_ai/models/openai.pyandtests/test_agent.py. - The analysis is static only: dynamic imports, dependency injection, framework wiring and dynamic dispatch are not resolved.
pydantic_clai2contains abuiltin_pluginsdirectory; any dynamic loading of its contents would not be resolved by static analysis. - Install, build and run inference is partial. No commands were checked, and no code was executed for this overview.
Notable symbols
Agentinagent/__init__.pyis a very large class, spanning lines 531 to 4856.messages.pydefines prompt and content types such asSystemPromptPart,ImageUrl,AudioUrl,VideoUrl,DocumentUrlandBinaryContent.exceptions.pydefines exception types includingModelRetry,ToolFailed,ApprovalRequired,CallDeferred,UserError,AgentRunErrorandRunCancelled.models/__init__.pydefines theModelclass,StreamedResponse,ModelRequestParametersand thecheck_allow_model_requests/override_allow_model_requestspair.
What this analysis could not establish
The writing model's own notes on the analysis record. Identifiers such as lim_3, exec_* or claim_… name records of that analysis; the claims table cites the same records.
- The analyzer's purpose summary ('web or Node.js application', main start in .claude/skills/testing-skill/parse_cassette.py) contradicts the Python-dominant metadata and appears to be a heuristic artifact.
- A teaching claim names examples/pydantic_ai_examples/slack_lead_qualifier/app.py as a starting point, but that file is only a filename-heuristic entrypoint.
- Runtime dependencies of the core pydantic_ai_slim package are not in the packet's partial dependency list.
- The relation cap was reached (files after tests/clai2/test_web_keys.py have no edges), so call-degree rankings are approximate.
- pydantic_ai_slim/pydantic_ai/models/openai.py was skipped as oversized, so its relations are absent from the degree figures.
- How the clai, pydantic_clai2 and src/pydantic_ai_harness packages relate to the core library is not established statically.
- One of the analyzer's teaching claims says no bounded execution path is available, while the packet lists exec_* paths; the paths that do exist cover only a tooling script.
Claims and evidence — 38 claims, 38 supported by an independent verifier
Every statement above is a claim that cites grounding IDs from the analysis. IDs are internal to the analysis run; the columns show what each claim rests on and how strong that ground is.
Every substantive statement above is a claim bound to grounding IDs of the analyzed revision. Global grounding IDs are namespaced by the analysis run.
| Claim | Epistemic status | Verifier | Grounding (global IDs) |
|---|---|---|---|
| c1 Platform metadata describes the project as a typed Python AI toolkit covering agents, realtime voice, image generation and embeddings across models and interfaces. | author_claimed | supported | analysis_947322335585c32a:meta_description |
| c2 GitHub topics include agent-framework, genai, llm and pydantic; the primary language is Python and the license is MIT. | observed | supported | analysis_947322335585c32a:meta_topics, analysis_947322335585c32a:meta_primary_language, analysis_947322335585c32a:meta_license |
| c3 Language byte counts are dominated by Python, with smaller amounts of TypeScript, PLpgSQL, Shell and CSS. | observed | supported | analysis_947322335585c32a:meta_language_bytes |
| c4 The repository holds several packages: pydantic_ai_slim/pydantic_ai contains the Agent class; pydantic_graph and pydantic_evals have their own pyproject.toml; clai has its own manifest. | observed | supported | analysis_947322335585c32a:py_class_517362e262dd, analysis_947322335585c32a:dep_2, analysis_947322335585c32a:dep_1, analysis_947322335585c32a:ev_manifest_1 |
| c5 The analyzer's auto-summary labels the repository a web or Node.js application starting at a .claude helper script, which conflicts with the Python primary-language metadata. | inferred | supported | analysis_947322335585c32a:summary_repository, analysis_947322335585c32a:meta_primary_language |
| c6 Many files contain a __main__ guard, including scripts under .github/scripts and scripts, examples under examples/pydantic_ai_examples, and MCP servers under tests. | observed | supported | analysis_947322335585c32a:py_entry_74efdc9541b6, analysis_947322335585c32a:py_entry_e20e97f19c72, analysis_947322335585c32a:py_entry_711b9329c9af, analysis_947322335585c32a:py_entry_bea51f9f5f67 |
| c7 CLI-style entrypoints exist: pydantic_ai_slim/pydantic_ai/__main__.py calls cli_exit(), clai/clai/__main__.py calls _cli.cli_exit('clai'), and src/pydantic_clai2/pydantic_clai2/__main__.py calls main(). | observed | supported | analysis_947322335585c32a:py_entry_34c79207455c, analysis_947322335585c32a:py_entry_ced396f72e87, analysis_947322335585c32a:py_entry_af9725b4ce2e |
| c8 Some examples start ASGI apps with uvicorn (ag_ui, chat_app), while others such as weather_agent.py use asyncio.run. | observed | supported | analysis_947322335585c32a:py_entry_effc9a1ba135, analysis_947322335585c32a:py_entry_a74ded2e260e, analysis_947322335585c32a:py_entry_38713d80fa6e |
| c9 slack_lead_qualifier/app.py, pydantic_ai/ui/_web/app.py and pydantic_clai2/cli/cli.py are flagged as entrypoints only by a filename heuristic. | inferred | supported | analysis_947322335585c32a:entry_26, analysis_947322335585c32a:entry_34, analysis_947322335585c32a:entry_51 |
| c10 The bounded static paths go from parse_cassette.py __main__ to main and end at unresolved boundaries such as argparse.ArgumentParser and parser.parse_args. This is test tooling, not the library request path. | inferred | supported | analysis_947322335585c32a:exec_bb0400b95179, analysis_947322335585c32a:exec_06af0227393f |
| c11 How a CLI invocation reaches Agent and a model at runtime is not established by the packet. | unresolved | supported | analysis_947322335585c32a:py_entry_34c79207455c, analysis_947322335585c32a:lim_1 |
| c12 By file count the largest top-level directories are tests (3423), src (787), pydantic_ai_slim (490), docs (454), .github (255) and examples (63). | inferred | supported | analysis_947322335585c32a:summary_repository |
| c13 The analyzer flags docs, src and tests as likely subsystems. | observed | supported | analysis_947322335585c32a:subsys_1, analysis_947322335585c32a:subsys_2, analysis_947322335585c32a:subsys_3 |
| c14 messages.py (497 in/102 out), exceptions.py (541 in/0 out) and _utils.py (313 in) have high incoming degree, suggesting widely shared building blocks. | inferred | supported | analysis_947322335585c32a:role_215, analysis_947322335585c32a:role_195, analysis_947322335585c32a:role_110 |
| c15 agent/__init__.py (4 in/244 out) and _agent_graph.py (29 in/157 out) are mostly callers, suggesting orchestration layers. | inferred | supported | analysis_947322335585c32a:role_113, analysis_947322335585c32a:role_66 |
| c16 models/__init__.py has 165 incoming and 127 outgoing calls, suggesting it acts as a central model abstraction hub. | inferred | supported | analysis_947322335585c32a:role_216 |
| c17 ui/vercel_ai/_adapter.py (0 in/138 out) is an orchestration candidate and realtime/_openai_protocol.py (84 in/39 out) a service candidate; both look integration-facing. | inferred | supported | analysis_947322335585c32a:role_355, analysis_947322335585c32a:role_305 |
| c18 The highest-incoming modules are test helpers tests/clai2/menu_script.py (699) and tests/clai2/dialog_script.py (558), so call degree alone does not indicate architectural importance. | inferred | supported | analysis_947322335585c32a:role_451, analysis_947322335585c32a:role_450 |
| c19 The Agent class in pydantic_ai_slim/pydantic_ai/agent/__init__.py spans lines 531 to 4856. | observed | supported | analysis_947322335585c32a:py_class_517362e262dd |
| c20 messages.py defines SystemPromptPart, ImageUrl, AudioUrl, VideoUrl, DocumentUrl and BinaryContent classes. | observed | supported | analysis_947322335585c32a:py_class_f03b7148046e, analysis_947322335585c32a:py_class_88d890e791ae, analysis_947322335585c32a:py_class_53d036101117, analysis_947322335585c32a:py_class_79818bbe4915, analysis_947322335585c32a:py_class_7d9ee00f2022, analysis_947322335585c32a:py_class_e35c8c774bfa |
| c21 exceptions.py defines ModelRetry, ToolFailed, ApprovalRequired, CallDeferred, UserError, AgentRunError and RunCancelled classes. | observed | supported | analysis_947322335585c32a:py_class_dd1ef28e575a, analysis_947322335585c32a:py_class_d525faa46c8c, analysis_947322335585c32a:py_class_4cb32d30d919, analysis_947322335585c32a:py_class_4cba1244d383, analysis_947322335585c32a:py_class_1a7aa408702e, analysis_947322335585c32a:py_class_a9d76143391e, analysis_947322335585c32a:py_class_b369b4dafdf8 |
| c22 models/__init__.py defines Model, StreamedResponse, ModelRequestParameters, check_allow_model_requests and override_allow_model_requests. | observed | supported | analysis_947322335585c32a:py_class_5cc493c3d87b, analysis_947322335585c32a:py_class_4407e19a57c9, analysis_947322335585c32a:py_class_43dbde63f4b6, analysis_947322335585c32a:py_func_f45b4390fe45, analysis_947322335585c32a:py_func_1f0af8e6b010 |
| c23 pydantic_graph declares runtime dependencies anyio, logfire-api, pydantic (>=2.12) and typing-inspection; pydantic_evals lists logfire as optional. | observed | supported | analysis_947322335585c32a:dep_2, analysis_947322335585c32a:dep_3, analysis_947322335585c32a:dep_4, analysis_947322335585c32a:dep_5, analysis_947322335585c32a:dep_1 |
| c24 The root pyproject.toml dev group includes pytest, pytest-xdist, pytest-mock, inline-snapshot, dirty-equals, hypothesis, coverage, cassetter, mypy, pyright and ruff. | observed | supported | analysis_947322335585c32a:dep_19, analysis_947322335585c32a:dep_25, analysis_947322335585c32a:dep_22, analysis_947322335585c32a:dep_18, analysis_947322335585c32a:dep_12, analysis_947322335585c32a:dep_41, analysis_947322335585c32a:dep_11, analysis_947322335585c32a:dep_40, analysis_947322335585c32a:dep_43, analysis_947322335585c32a:dep_44, analysis_947322335585c32a:dep_45 |
| c25 src/pydantic_clai2/web-ui/package.json declares react, marked, highlight.js, dompurify and vite; tests/ui_roundtrip/package.json lists @ag-ui/client, ai and rxjs. | observed | supported | analysis_947322335585c32a:dep_50, analysis_947322335585c32a:dep_49, analysis_947322335585c32a:dep_48, analysis_947322335585c32a:dep_47, analysis_947322335585c32a:dep_56, analysis_947322335585c32a:dep_57, analysis_947322335585c32a:dep_58, analysis_947322335585c32a:dep_59 |
| c26 The repository has 10 build/dependency manifests; dependency parsing covers requirements files, package.json and pyproject.toml but not setup.py, setup.cfg, Pipfile or lock files. | observed | supported | analysis_947322335585c32a:ev_manifest_1, analysis_947322335585c32a:lim_3a |
| c27 No dependency records for the core pydantic_ai_slim package appear in the packet, so its runtime requirements are not established. | unresolved | supported | analysis_947322335585c32a:lim_3a, analysis_947322335585c32a:ev_manifest_1 |
| c28 The analyzer counts 3447 test or test-like files, including tests for .github/scripts automation such as test_agent_provider_health.py. | observed | supported | analysis_947322335585c32a:ev_tests_1 |
| c29 README.md and pyproject.toml are flagged as project-level important files. | observed | supported | analysis_947322335585c32a:important_1, analysis_947322335585c32a:important_2 |
| c30 pydantic_ai_slim/pydantic_ai/__main__.py is a CLI entry with a __main__ guard, and agent/__init__.py holds the Agent class. | observed | supported | analysis_947322335585c32a:py_entry_34c79207455c, analysis_947322335585c32a:py_class_517362e262dd |
| c31 messages.py, models/__init__.py and _agent_graph.py are high-degree service/core candidates and a reasonable next read. | inferred | supported | analysis_947322335585c32a:role_215, analysis_947322335585c32a:role_216, analysis_947322335585c32a:role_66 |
| c32 examples/pydantic_ai_examples/pydantic_model.py has a main block that calls agent.run_sync and prints result.output and result.usage. | observed | supported | analysis_947322335585c32a:py_entry_e76ff878e091 |
| c33 parse_cassette.py and .github/scripts files rank as important only because they are likely entrypoints; they appear to be repository tooling rather than library API. | inferred | supported | analysis_947322335585c32a:important_4, analysis_947322335585c32a:important_5, analysis_947322335585c32a:important_8 |
| c34 Of 150000 static relations, 125235 are external or unresolved and 24765 are local. | observed | supported | analysis_947322335585c32a:relation_counts |
| c35 Relation extraction is capped at 150000 per repository and the total equals that cap, so later files lack edges and the reported degrees are incomplete. | inferred | supported | analysis_947322335585c32a:lim_6, analysis_947322335585c32a:relation_counts |
| c36 Nine files over 400 kB were inventoried but not parsed, including pydantic_ai_slim/pydantic_ai/models/openai.py and tests/test_agent.py. | inferred | supported | analysis_947322335585c32a:claim_cc68ccd3be32, analysis_947322335585c32a:lim_6 |
| c37 The analysis is static only and does not resolve dynamic imports, dependency injection, framework wiring or dynamic dispatch. pydantic_clai2 contains a builtin_plugins directory; whether its contents are loaded dynamically is not established. | inferred | supported | analysis_947322335585c32a:lim_1, analysis_947322335585c32a:entry_49 |
| c38 Install, build and run inference is partial and installation commands are not verified; no code was executed for this overview. | observed | supported | analysis_947322335585c32a:lim_2, analysis_947322335585c32a:lim_1 |
Sources, rights and disclosure · attribution-license-templates/v0.1
Rights notice. Original repository hosted on GitHub. Repository source code, documentation, names, media, and related project materials remain subject to the rights of their respective authors, contributors, and other rights holders and to applicable repository license terms.
Platform notice. GitHub is the source hosting platform for the linked repository. GitHub and related marks are trademarks of GitHub, Inc. EVEMISS Technology is not affiliated with or endorsed by GitHub unless explicitly stated otherwise.
How this page is produced. This page was produced using revision-aware repository analysis and AI-assisted editorial tooling. Technical claims are tied to the analyzed repository revision and may be revalidated when the source repository changes.
AI-assisted analysis. Reviewed by EVEMISS Technology through human–AI collaborative review. · Report a rights concern · All repository guides