Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 5 additions & 5 deletions docs/agents.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ There are three ways to run an agent:

Here's a simple example demonstrating all three:

```python title="run_agent.py"
```py title="run_agent.py"
from pydantic_ai import Agent

agent = Agent('openai:gpt-4o')
Expand Down Expand Up @@ -95,7 +95,7 @@ An agent **run** might represent an entire conversation — there's no limit to

Here's an example of a conversation comprised of multiple runs:

```python title="conversation_example.py" hl_lines="13"
```py title="conversation_example.py" hl_lines="13"
from pydantic_ai import Agent

agent = Agent('openai:gpt-4o')
Expand Down Expand Up @@ -131,7 +131,7 @@ You can add both to a single agent; they're concatenated in the order they're de

Here's an example using both types of system prompts:

```python title="system_prompts.py"
```py title="system_prompts.py"
from datetime import date

from pydantic_ai import Agent, CallContext
Expand Down Expand Up @@ -228,7 +228,7 @@ _(This example is complete, it can be run "as is")_

Let's print the messages from that game to see what happened:

```python title="dice_game_messages.py"
```py title="dice_game_messages.py"
from dice_game import dice_result

print(dice_result.all_messages())
Expand Down Expand Up @@ -417,7 +417,7 @@ If models behave unexpectedly (e.g., the retry limit is exceeded, or their API r

In these cases, [`agent.last_run_messages`][pydantic_ai.Agent.last_run_messages] can be used to access the messages exchanged during the run to help diagnose the issue.

```python
```py
from pydantic_ai import Agent, ModelRetry, UnexpectedModelBehaviour

agent = Agent('openai:gpt-4o')
Expand Down
6 changes: 3 additions & 3 deletions docs/dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ _(This example is complete, it can be run "as is")_
Dependencies are accessed through the [`CallContext`][pydantic_ai.dependencies.CallContext] type, this should be the first parameter of system prompt functions etc.


```python title="system_prompt_dependencies.py" hl_lines="20-27"
```py title="system_prompt_dependencies.py" hl_lines="20-27"
from dataclasses import dataclass

import httpx
Expand Down Expand Up @@ -113,7 +113,7 @@ to use `async` methods where dependencies perform IO, although synchronous depen

Here's the same example as above, but with a synchronous dependency:

```python title="sync_dependencies.py"
```py title="sync_dependencies.py"
from dataclasses import dataclass

import httpx
Expand Down Expand Up @@ -161,7 +161,7 @@ _(This example is complete, it can be run "as is")_

As well as system prompts, dependencies can be used in [retrievers](agents.md#retrievers) and [result validators](results.md#result-validators-functions).

```python title="full_example.py" hl_lines="27-35 38-48"
```py title="full_example.py" hl_lines="27-35 38-48"
from dataclasses import dataclass

import httpx
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ async def main():
10. The result will be validated with Pydantic to guarantee it is a `SupportResult`, since the agent is generic, it'll also be typed as a `SupportResult` to aid with static type checking.
11. In a real use case, you'd add many more retrievers and a longer system prompt to the agent to extend the context it's equipped with and support it can provide.
12. This is a simple sketch of a database connection, used to keep the example short and readable. In reality, you'd be connecting to an external database (e.g. PostgreSQL) to get information about customers.
13. This [Pydantic](https://docs.pydantic.dev) model is used to constrain the structured data returned by the agent. From this simple definition, Pydantic builds teh JSON Schema that tells the LLM how to return the data, and performs validation to guarantee the data is correct at the end of the conversation.
13. This [Pydantic](https://docs.pydantic.dev) model is used to constrain the structured data returned by the agent. From this simple definition, Pydantic builds the JSON Schema that tells the LLM how to return the data, and performs validation to guarantee the data is correct at the end of the conversation.

!!! tip "Complete `bank_support.py` example"
This example is incomplete for the sake of brevity (the definition of `DatabaseConn` is missing); you can find a complete `bank_support.py` example [here](examples/bank-support.md).
Expand Down
12 changes: 5 additions & 7 deletions docs/message-history.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ and [`StreamedRunResult`][pydantic_ai.result.StreamedRunResult] (returned by [`A

Example of accessing methods on a [`RunResult`][pydantic_ai.result.RunResult] :

```python title="run_result_messages.py" hl_lines="10 28"
```py title="run_result_messages.py" hl_lines="10 28"
from pydantic_ai import Agent

agent = Agent('openai:gpt-4o', system_prompt='Be a helpful assistant.')
Expand Down Expand Up @@ -73,7 +73,7 @@ _(This example is complete, it can be run "as is")_

Example of accessing methods on a [`StreamedRunResult`][pydantic_ai.result.StreamedRunResult] :

```python title="streamed_run_result_messages.py" hl_lines="9 31"
```py title="streamed_run_result_messages.py" hl_lines="9 31"
from pydantic_ai import Agent

agent = Agent('openai:gpt-4o', system_prompt='Be a helpful assistant.')
Expand All @@ -96,11 +96,9 @@ async def main():

async for text in result.stream():
print(text)
#> Did you
#> Did you hear about
#> Did you hear
#> Did you hear about the toothpaste
#> Did you hear about the toothpaste scandal? They
#> Did you hear about the toothpaste scandal? They called it
#> Did you hear about the toothpaste scandal? They called
#> Did you hear about the toothpaste scandal? They called it Colgate.

# complete messages once the stream finishes
Expand Down Expand Up @@ -190,7 +188,7 @@ Since messages are defined by simple dataclasses, you can manually create and ma

The message format is independent of the model used, so you can use messages in different agents, or the same agent with different models.

```python
```py
from pydantic_ai import Agent

agent = Agent('openai:gpt-4o', system_prompt='Be a helpful assistant.')
Expand Down
Loading
Loading