Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add asyncio in multi-agent-applications.md to make examples can be run "as is". #630

Closed
wants to merge 3 commits into from
Closed
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
13 changes: 13 additions & 0 deletions docs/multi-agent-applications.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ Generally the delegate agent needs to either have the same [dependencies](depend
from dataclasses import dataclass

import httpx
import asyncio

from pydantic_ai import Agent, RunContext

Expand Down Expand Up @@ -154,6 +155,11 @@ async def main():
details=None,
)
"""


if __name__ == '__main__':
asyncio.run(main())

```

1. Define a dataclass to hold the client and API key dependencies.
Expand Down Expand Up @@ -192,6 +198,8 @@ Here we show two agents used in succession, the first to find a flight and the s
```python {title="programmatic_handoff.py"}
from typing import Literal, Union

import asyncio

from pydantic import BaseModel, Field
from rich.prompt import Prompt

Expand Down Expand Up @@ -296,6 +304,11 @@ async def main(): # (7)!
seat_preference = await find_seat(usage)
print(f'Seat preference: {seat_preference}')
#> Seat preference: row=1 seat='A'


if __name__ == '__main__':
asyncio.run(main())

```

1. Define the first agent, which finds a flight. We use an explicit type annotation until [PEP-747](https://peps.python.org/pep-0747/) lands, see [structured results](results.md#structured-result-validation). We use a union as the result type so the model can communicate if it's unable to find a satisfactory choice; internally, each member of the union will be registered as a separate tool.
Expand Down
Loading