Skip to content

Commit 339a6b0

Browse files
authored
Improve docs index and README (#2058)
1 parent 2712d91 commit 339a6b0

File tree

8 files changed

+131
-125
lines changed

8 files changed

+131
-125
lines changed

README.md

Lines changed: 47 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
</a>
88
</div>
99
<div align="center">
10-
<em>Agent Framework / shim to use Pydantic with LLMs</em>
10+
<h3>GenAI Agent Framework, the Pydantic way</h3>
1111
</div>
1212
<div align="center">
1313
<a href="https://github.com/pydantic/pydantic-ai/actions/workflows/ci.yml?query=branch%3Amain"><img src="https://github.com/pydantic/pydantic-ai/actions/workflows/ci.yml/badge.svg?event=push" alt="CI"></a>
@@ -24,43 +24,48 @@
2424

2525
---
2626

27-
Pydantic AI is a Python agent framework designed to make it less painful to build production grade applications with Generative AI.
27+
### <em>Pydantic AI is a Python agent framework designed to help you quickly, confidently, and painlessly build production grade applications and workflows with Generative AI.</em>
2828

29-
FastAPI revolutionized web development by offering an innovative and ergonomic design, built on the foundation of [Pydantic Validation](https://docs.pydantic.dev).
3029

31-
Similarly, virtually every agent framework and LLM library in Python uses Pydantic Validation, yet when we began to use LLMs in [Pydantic Logfire](https://pydantic.dev/logfire), we couldn't find anything that gave us the same feeling.
30+
FastAPI revolutionized web development by offering an innovative and ergonomic design, built on the foundation of [Pydantic Validation](https://docs.pydantic.dev) and modern Python features like type hints.
3231

33-
We built Pydantic AI with one simple aim: to bring that FastAPI feeling to GenAI app development.
32+
Yet despite virtually every Python agent framework and LLM library using Pydantic Validation, when we began to use LLMs in [Pydantic Logfire](https://pydantic.dev/logfire), we couldn't find anything that gave us the same feeling.
33+
34+
We built Pydantic AI with one simple aim: to bring that FastAPI feeling to GenAI app and agent development.
3435

3536
## Why use Pydantic AI
3637

37-
- **Built by the Pydantic Team**
38-
Built by the team behind [Pydantic Validation](https://docs.pydantic.dev/latest/) (the validation layer of the OpenAI SDK, the Anthropic SDK, LangChain, LlamaIndex, AutoGPT, Transformers, CrewAI, Instructor and many more).
38+
1. **Built by the Pydantic Team**:
39+
[Pydantic Validation](https://docs.pydantic.dev/latest/) is the validation layer of the OpenAI SDK, the Google ADK, the Anthropic SDK, LangChain, LlamaIndex, AutoGPT, Transformers, CrewAI, Instructor and many more. _Why use the derivative when you can go straight to the source?_ :smiley:
40+
41+
2. **Model-agnostic**:
42+
Supports virtually every [model](https://ai.pydantic.dev/models/overview) and provider: OpenAI, Anthropic, Gemini, DeepSeek, Grok, Cohere, Mistral, and Perplexity; Azure AI Foundry, Amazon Bedrock, Google Vertex AI, Ollama, LiteLLM, Groq, OpenRouter, Together AI, Fireworks AI, Cerebras, Hugging Face, GitHub, Heroku, Vercel. If your favorite model or provider is not listed, you can easily implement a [custom model](https://ai.pydantic.dev/models/overview#custom-models).
43+
44+
3. **Seamless Observability**:
45+
Tightly [integrates](https://ai.pydantic.dev/logfire) with [Pydantic Logfire](https://pydantic.dev/logfire), our general-purpose OpenTelemetry observability platform, for real-time debugging, evals-based performance monitoring, and behavior, tracing, and cost tracking. If you already have an observability platform that supports OTel, you can [use that too](https://ai.pydantic.dev/logfire#alternative-observability-backends).
3946

40-
- **Model-agnostic**
41-
Supports OpenAI, Anthropic, Gemini, Deepseek, Ollama, Groq, Cohere, and Mistral, and there is a simple interface to implement support for [other models](https://ai.pydantic.dev/models/).
47+
4. **Fully Type-safe**:
48+
Designed to give your IDE or AI coding agent as much context as possible for auto-completion and [type checking](https://ai.pydantic.dev/agents#static-type-checking), moving entire classes of errors from runtime to write-time for a bit of that Rust "if it compiles, it works" feel.
4249

43-
- **Pydantic Logfire Integration**
44-
Seamlessly [integrates](https://ai.pydantic.dev/logfire/) with [Pydantic Logfire](https://pydantic.dev/logfire) for real-time debugging, performance monitoring, and behavior tracking of your LLM-powered applications.
50+
5. **Powerful Evals**:
51+
Enables you to systematically test and [evaluate](https://ai.pydantic.dev/evals) the performance and accuracy of the agentic systems you build, and monitor the performance over time in Pydantic Logfire.
4552

46-
- **Type-safe**
47-
Designed to make [type checking](https://ai.pydantic.dev/agents/#static-type-checking) as powerful and informative as possible for you.
53+
6. **MCP, A2A, and AG-UI**:
54+
Integrates the [Model Context Protocol](https://ai.pydantic.dev/mcp/client), [Agent2Agent](https://ai.pydantic.dev/a2a), and [AG-UI](https://ai.pydantic.dev/ag-ui) standards to give your agent access to external tools and data, let it interoperate with other agents, and build interactive applications with streaming event-based communication.
4855

49-
- **Python-centric Design**
50-
Leverages Python's familiar control flow and agent composition to build your AI-driven projects, making it easy to apply standard Python best practices you'd use in any other (non-AI) project.
56+
7. **Human-in-the-Loop Tool Approval**:
57+
Easily lets you flag that certain tool calls [require approval](https://ai.pydantic.dev/deferred-tools#human-in-the-loop-tool-approval) before they can proceed, possibly depending on tool call arguments, conversation history, or user preferences.
5158

52-
- **Structured Responses**
53-
Harnesses the power of [Pydantic Validation](https://docs.pydantic.dev/latest/) to [validate and structure](https://ai.pydantic.dev/output/#structured-output) model outputs, ensuring responses are consistent across runs.
59+
8. **Durable Execution**:
60+
Enables you to build [durable agents](https://ai.pydantic.dev/temporal) that can preserve their progress across transient API failures and application errors or restarts, and handle long-running, asynchronous, and human-in-the-loop workflows with production-grade reliability.
5461

55-
- **Dependency Injection System**
56-
Offers an optional [dependency injection](https://ai.pydantic.dev/dependencies/) system to provide data and services to your agent's [system prompts](https://ai.pydantic.dev/agents/#system-prompts), [tools](https://ai.pydantic.dev/tools/) and [output validators](https://ai.pydantic.dev/output/#output-validator-functions).
57-
This is useful for testing and eval-driven iterative development.
62+
9. **Streamed Outputs**:
63+
Provides the ability to [stream](https://ai.pydantic.dev/output#streamed-results) structured output continuously, with immediate validation, ensuring real time access to generated data.
5864

59-
- **Streamed Responses**
60-
Provides the ability to [stream](https://ai.pydantic.dev/output/#streamed-results) LLM outputs continuously, with immediate validation, ensuring rapid and accurate outputs.
65+
10. **Graph Support**:
66+
Provides a powerful way to define [graphs](https://ai.pydantic.dev/graph) using type hints, for use in complex applications where standard control flow can degrade to spaghetti code.
6167

62-
- **Graph Support**
63-
[Pydantic Graph](https://ai.pydantic.dev/graph) provides a powerful way to define graphs using typing hints, this is useful in complex applications where standard control flow can degrade to spaghetti code.
68+
Realistically though, no list is going to be as convincing as [giving it a try](#next-steps) and seeing how it makes you feel!
6469

6570
## Hello World Example
6671

@@ -71,25 +76,25 @@ from pydantic_ai import Agent
7176

7277
# Define a very simple agent including the model to use, you can also set the model when running the agent.
7378
agent = Agent(
74-
'google-gla:gemini-1.5-flash',
75-
# Register a static system prompt using a keyword argument to the agent.
76-
# For more complex dynamically-generated system prompts, see the example below.
77-
system_prompt='Be concise, reply with one sentence.',
79+
'anthropic:claude-sonnet-4-0',
80+
# Register static instructions using a keyword argument to the agent.
81+
# For more complex dynamically-generated instructions, see the example below.
82+
instructions='Be concise, reply with one sentence.',
7883
)
7984

8085
# Run the agent synchronously, conducting a conversation with the LLM.
81-
# Here the exchange should be very short: Pydantic AI will send the system prompt and the user query to the LLM,
82-
# the model will return a text response. See below for a more complex run.
8386
result = agent.run_sync('Where does "hello world" come from?')
8487
print(result.output)
8588
"""
8689
The first known use of "hello, world" was in a 1974 textbook about the C programming language.
8790
"""
8891
```
8992

90-
_(This example is complete, it can be run "as is")_
93+
_(This example is complete, it can be run "as is", assuming you've [installed the `pydantic_ai` package](https://ai.pydantic.dev/install))_
9194

92-
Not very interesting yet, but we can easily add "tools", dynamic system prompts, and structured responses to build more powerful agents.
95+
The exchange will be very short: Pydantic AI will send the instructions and the user prompt to the LLM, and the model will return a text response.
96+
97+
Not very interesting yet, but we can easily add [tools](https://ai.pydantic.dev/tools), [dynamic instructions](https://ai.pydantic.dev/agents#instructions), and [structured outputs](https://ai.pydantic.dev/output) to build more powerful agents.
9398

9499
## Tools & Dependency Injection Example
95100

@@ -107,14 +112,14 @@ from bank_database import DatabaseConn
107112

108113

109114
# SupportDependencies is used to pass data, connections, and logic into the model that will be needed when running
110-
# system prompt and tool functions. Dependency injection provides a type-safe way to customise the behavior of your agents.
115+
# instructions and tool functions. Dependency injection provides a type-safe way to customise the behavior of your agents.
111116
@dataclass
112117
class SupportDependencies:
113118
customer_id: int
114119
db: DatabaseConn
115120

116121

117-
# This pydantic model defines the structure of the output returned by the agent.
122+
# This Pydantic model defines the structure of the output returned by the agent.
118123
class SupportOutput(BaseModel):
119124
support_advice: str = Field(description='Advice returned to the customer')
120125
block_card: bool = Field(description="Whether to block the customer's card")
@@ -125,28 +130,28 @@ class SupportOutput(BaseModel):
125130
# Agents are generic in the type of dependencies they accept and the type of output they return.
126131
# In this case, the support agent has type `Agent[SupportDependencies, SupportOutput]`.
127132
support_agent = Agent(
128-
'openai:gpt-4o',
133+
'openai:gpt-5',
129134
deps_type=SupportDependencies,
130135
# The response from the agent will, be guaranteed to be a SupportOutput,
131136
# if validation fails the agent is prompted to try again.
132137
output_type=SupportOutput,
133-
system_prompt=(
138+
instructions=(
134139
'You are a support agent in our bank, give the '
135140
'customer support and judge the risk level of their query.'
136141
),
137142
)
138143

139144

140-
# Dynamic system prompts can make use of dependency injection.
145+
# Dynamic instructions can make use of dependency injection.
141146
# Dependencies are carried via the `RunContext` argument, which is parameterized with the `deps_type` from above.
142147
# If the type annotation here is wrong, static type checkers will catch it.
143-
@support_agent.system_prompt
148+
@support_agent.instructions
144149
async def add_customer_name(ctx: RunContext[SupportDependencies]) -> str:
145150
customer_name = await ctx.deps.db.customer_name(id=ctx.deps.customer_id)
146151
return f"The customer's name is {customer_name!r}"
147152

148153

149-
# `tool` let you register functions which the LLM may call while responding to a user.
154+
# The `tool` decorator let you register functions which the LLM may call while responding to a user.
150155
# Again, dependencies are carried via `RunContext`, any other arguments become the tool schema passed to the LLM.
151156
# Pydantic is used to validate these arguments, and errors are passed back to the LLM so it can retry.
152157
@support_agent.tool
@@ -187,8 +192,10 @@ async def main():
187192

188193
## Next Steps
189194

190-
To try Pydantic AI yourself, follow the instructions [in the examples](https://ai.pydantic.dev/examples/).
195+
To try Pydantic AI for yourself, [install it](https://ai.pydantic.dev/install) and follow the instructions [in the examples](https://ai.pydantic.dev/examples/setup).
191196

192197
Read the [docs](https://ai.pydantic.dev/agents/) to learn more about building applications with Pydantic AI.
193198

194199
Read the [API Reference](https://ai.pydantic.dev/api/agent/) to understand Pydantic AI's interface.
200+
201+
Join [Slack](https://logfire.pydantic.dev/docs/join-slack/) or file an issue on [GitHub](https://github.com/pydantic/pydantic-ai/issues) if you have any questions.

docs/.partials/index-header.html

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,10 @@
22
<img class="index-header off-glb" src="./img/pydantic-ai-dark.svg#only-dark" alt="Pydantic AI">
33
</div>
44
<div class="text-center">
5-
<img
6-
class="index-header off-glb"
7-
src="./img/pydantic-ai-light.svg#only-light"
8-
alt="Pydantic AI">
5+
<img class="index-header off-glb" src="./img/pydantic-ai-light.svg#only-light" alt="Pydantic AI">
96
</div>
107
<p class="text-center">
11-
<em>Agent Framework / shim to use Pydantic with LLMs</em>
8+
<em>GenAI Agent Framework, the Pydantic way</em>
129
</p>
1310
<p class="text-center">
1411
<a href="https://github.com/pydantic/pydantic-ai/actions/workflows/ci.yml?query=branch%3Amain">
@@ -36,6 +33,6 @@
3633
</p>
3734

3835
<p class="text-emphasis">
39-
Pydantic AI is a Python agent framework designed to make it less painful to build production grade
40-
applications with Generative AI.
36+
Pydantic AI is a Python agent framework designed to help you
37+
quickly, confidently, and painlessly build production grade applications and workflows with Generative AI.
4138
</p>

docs/agents.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ The [`Agent`][pydantic_ai.Agent] class has full API documentation, but conceptua
99

1010
| **Component** | **Description** |
1111
| --------------------------------------------------------- | --------------------------------------------------------------------------------------------------------- |
12-
| [System prompt(s)](#system-prompts) | A set of instructions for the LLM written by the developer. |
12+
| [Instructions](#instructions) | A set of instructions for the LLM written by the developer. |
1313
| [Function tool(s)](tools.md) and [toolsets](toolsets.md) | Functions that the LLM may call to get information while generating a response. |
1414
| [Structured output type](output.md) | The structured datatype the LLM must return at the end of a run, if specified. |
15-
| [Dependency type constraint](dependencies.md) | System prompt functions, tools, and output validators may all use dependencies when they're run. |
15+
| [Dependency type constraint](dependencies.md) | Dynamic instructions functions, tools, and output functions may all use dependencies when they're run. |
1616
| [LLM model](api/models/base.md) | Optional default LLM model associated with the agent. Can also be specified when running the agent. |
1717
| [Model Settings](#additional-configuration) | Optional default model settings to help fine tune requests. Can also be specified when running the agent. |
1818

@@ -928,10 +928,10 @@ Note that returning an empty string will result in no instruction message added.
928928

929929
Validation errors from both function tool parameter validation and [structured output validation](output.md#structured-output) can be passed back to the model with a request to retry.
930930

931-
You can also raise [`ModelRetry`][pydantic_ai.exceptions.ModelRetry] from within a [tool](tools.md) or [output validator function](output.md#output-validator-functions) to tell the model it should retry generating a response.
931+
You can also raise [`ModelRetry`][pydantic_ai.exceptions.ModelRetry] from within a [tool](tools.md) or [output function](output.md#output-functions) to tell the model it should retry generating a response.
932932

933-
- The default retry count is **1** but can be altered for the [entire agent][pydantic_ai.Agent.__init__], a [specific tool][pydantic_ai.Agent.tool], or an [output validator][pydantic_ai.Agent.__init__].
934-
- You can access the current retry count from within a tool or output validator via [`ctx.retry`][pydantic_ai.tools.RunContext].
933+
- The default retry count is **1** but can be altered for the [entire agent][pydantic_ai.Agent.__init__], a [specific tool][pydantic_ai.Agent.tool], or [outputs][pydantic_ai.Agent.__init__].
934+
- You can access the current retry count from within a tool or output function via [`ctx.retry`][pydantic_ai.tools.RunContext].
935935

936936
Here's an example:
937937

0 commit comments

Comments
 (0)