Skip to content

Commit 95b6e6a

Browse files
committed
refactor(ag-ui): move AG-UI to pydantic_ai_slim
Move pydantic_ai_ag_ui to pydantic_ai_slim as ag_ui, updating references and documentation accordingly.
1 parent 1683839 commit 95b6e6a

33 files changed

+1202
-1358
lines changed

docs/ag-ui.md

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ an open protocol. Think of it as a universal translator for AI-driven systems
88
no matter what language an agent speaks: AG-UI ensures fluent communication.
99

1010
The team at [Rocket Science](https://www.rocketscience.gg/), contributed the
11-
[pydantic-ai-ag-ui](#ag-ui-adapter) package to make it easy to implement the
12-
AG-UI protocol with PydanticAI agents.
11+
[AG-UI integration](#ag-ui-adapter) to make it easy to implement the AG-UI
12+
protocol with PydanticAI agents.
1313

1414
This also includes an [`Agent.to_ag_ui`][pydantic_ai.Agent.to_ag_ui] convenience
15-
method which simplifies the creation of [`Adapter`][pydantic_ai_ag_ui.Adapter]
15+
method which simplifies the creation of [`Adapter`][pydantic_ai.ag_ui.Adapter]
1616
for PydanticAI agents, which can then be used by as part of a
1717
[fastapi](https://fastapi.tiangolo.com/) app.
1818

1919
## AG-UI Adapter
2020

21-
The [Adapter][pydantic_ai_ag_ui.Adapter] class is an adapter between
21+
The [Adapter][pydantic_ai.ag_ui.Adapter] class is an adapter between
2222
PydanticAI agents and the AG-UI protocol written in Python. It provides support
2323
for all aspects of spec including:
2424

@@ -31,14 +31,6 @@ Let's have a quick look at how to use it:
3131

3232
### Installation
3333

34-
[Adapter][pydantic_ai_ag_ui.Adapter] is available on PyPI as
35-
[`pydantic-ai-ag-ui`](https://pypi.org/project/pydantic-ai-ag-ui/) so installation is as
36-
simple as:
37-
38-
```bash
39-
pip/uv-add pydantic-ai-ag-ui
40-
```
41-
4234
The only dependencies are:
4335

4436
- [ag-ui-protocol](https://docs.ag-ui.com/introduction): to provide the AG-UI
@@ -54,7 +46,8 @@ To run the examples you'll also need:
5446
pip/uv-add 'fastapi'
5547
```
5648

57-
You can install PydanticAI with the `ag-ui` extra to include **Adapter**:
49+
You can install PydanticAI with the `ag-ui` extra to include
50+
[Adapter][pydantic_ai.ag_ui.Adapter] run:
5851

5952
```bash
6053
pip/uv-add 'pydantic-ai-slim[ag-ui]'
@@ -71,7 +64,7 @@ from typing import TYPE_CHECKING, Annotated
7164

7265
from fastapi import FastAPI, Header
7366
from fastapi.responses import StreamingResponse
74-
from pydantic_ai_ag_ui import SSE_CONTENT_TYPE
67+
from pydantic_ai.ag_ui import SSE_CONTENT_TYPE
7568

7669
from pydantic_ai import Agent
7770

@@ -116,7 +109,7 @@ streamed back to the caller as Server-Sent Events (SSE).
116109
A user request may require multiple round trips between client UI and PydanticAI
117110
server, depending on the tools and events needed.
118111

119-
[Adapter][pydantic_ai_ag_ui.Adapter] can be used with any ASGI server.
112+
[Adapter][pydantic_ai.ag_ui.Adapter] can be used with any ASGI server.
120113

121114
### Features
122115

@@ -125,8 +118,8 @@ use the [`to_ag_ui`][pydantic_ai.agent.Agent.to_ag_ui] method in combination
125118
with [fastapi](https://fastapi.tiangolo.com/).
126119

127120
In the example below we have document state which is shared between the UI and
128-
server using the [`StateDeps`][pydantic_ai_ag_ui.StateDeps] which implements the
129-
[`StateHandler`][pydantic_ai_ag_ui.StateHandler] that can be used to automatically
121+
server using the [`StateDeps`][pydantic_ai.ag_ui.StateDeps] which implements the
122+
[`StateHandler`][pydantic_ai.ag_ui.StateHandler] that can be used to automatically
130123
decode state contained in [`RunAgentInput.state`](https://docs.ag-ui.com/sdk/js/core/types#runagentinput)
131124
when processing requests.
132125

@@ -146,7 +139,7 @@ from typing import TYPE_CHECKING, Annotated
146139
from fastapi import FastAPI, Header
147140
from fastapi.responses import StreamingResponse
148141
from pydantic import BaseModel
149-
from pydantic_ai_ag_ui import SSE_CONTENT_TYPE, StateDeps
142+
from pydantic_ai.ag_ui import SSE_CONTENT_TYPE, StateDeps
150143

151144
from pydantic_ai import Agent
152145

@@ -187,7 +180,7 @@ uvicorn agent_to_ag_ui:app --host 0.0.0.0 --port 8000
187180

188181
Since the goal of [`to_ag_ui`][pydantic_ai.agent.Agent.to_ag_ui] is to be a
189182
convenience method, it accepts the same arguments as the
190-
[`Adapter`][pydantic_ai_ag_ui.Adapter] constructor.
183+
[`Adapter`][pydantic_ai.ag_ui.Adapter] constructor.
191184

192185
#### Tools
193186

@@ -213,7 +206,7 @@ from ag_ui.core import CustomEvent, EventType, StateSnapshotEvent
213206
from fastapi import FastAPI, Header
214207
from fastapi.responses import StreamingResponse
215208
from pydantic import BaseModel
216-
from pydantic_ai_ag_ui import SSE_CONTENT_TYPE, StateDeps
209+
from pydantic_ai.ag_ui import SSE_CONTENT_TYPE, StateDeps
217210

218211
from pydantic_ai import Agent, RunContext
219212

@@ -272,8 +265,8 @@ async def root(
272265

273266
### Examples
274267

275-
For more examples of how to use [`Adapter`][pydantic_ai_ag_ui.Adapter] see
276-
[`pydantic_ai_ag_ui_examples`](https://github.com/pydantic/pydantic-ai/tree/main/examples/pydantic_ai_ag_ui_examples),
268+
For more examples of how to use [`Adapter`][pydantic_ai.ag_ui.Adapter] see
269+
[`pydantic_ai.ag_ui_examples`](https://github.com/pydantic/pydantic-ai/tree/main/examples/pydantic_ai.ag_ui_examples),
277270
which includes working server for the with the
278271
[AG-UI Dojo](https://docs.ag-ui.com/tutorials/debugging#the-ag-ui-dojo) which
279272
can be run from a clone of the repo or with the `pydantic-ai-examples` package
@@ -286,7 +279,7 @@ pip/uv-add pydantic-ai-examples
286279
Direct, which supports command line flags:
287280

288281
```shell
289-
python -m pydantic_ai_ag_ui_examples.dojo_server --help
282+
python -m pydantic_ai.ag_ui_examples.dojo_server --help
290283
usage: dojo_server.py [-h] [--port PORT] [--reload] [--no-reload] [--log-level {critical,error,warning,info,debug,trace}]
291284

292285
PydanticAI AG-UI Dojo server
@@ -303,11 +296,11 @@ options:
303296
Run with adapter debug logging:
304297

305298
```shell
306-
python -m pydantic_ai_ag_ui_examples.dojo_server --log-level debug
299+
python -m pydantic_ai.ag_ui_examples.dojo_server --log-level debug
307300
```
308301

309302
Using uvicorn:
310303

311304
```shell
312-
uvicorn pydantic_ai_ag_ui_examples.dojo_server:app --port 9000
305+
uvicorn pydantic_ai.ag_ui_examples.dojo_server:app --port 9000
313306
```

docs/api/ag_ui.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# `pydantic_ai.ag_ui`
2+
3+
::: pydantic_ai.ag_ui

docs/api/pydantic_ai_ag_ui.md

Lines changed: 0 additions & 3 deletions
This file was deleted.

docs/install.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ pip/uv-add "pydantic-ai-slim[openai]"
5656
* `cohere` - installs `cohere` [PyPI ↗](https://pypi.org/project/cohere){:target="_blank"}
5757
* `duckduckgo` - installs `duckduckgo-search` [PyPI ↗](https://pypi.org/project/duckduckgo-search){:target="_blank"}
5858
* `tavily` - installs `tavily-python` [PyPI ↗](https://pypi.org/project/tavily-python){:target="_blank"}
59-
* `ag-ui` - installs `pydantic-ai-ag-ui` [PyPI ↗](https://pypi.org/project/pydantic-ai-ag-ui){:target="_blank"}
59+
* `ag-ui` - installs `ag-ui-protocol` [PyPI ↗](https://pypi.org/project/ag-ui-protocol){:target="_blank"}
6060

6161
See the [models](models/index.md) documentation for information on which optional dependencies are required for each model.
6262

examples/pydantic_ai_ag_ui_examples/api/agent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
from typing import Generic
88

99
from dotenv import load_dotenv
10-
from pydantic_ai_ag_ui import Adapter
1110

1211
from pydantic_ai import Agent
12+
from pydantic_ai.ag_ui import Adapter
1313
from pydantic_ai.result import OutputDataT
1414
from pydantic_ai.tools import AgentDepsT
1515

examples/pydantic_ai_ag_ui_examples/api/agentic_chat.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
from ag_ui.core import RunAgentInput
1010
from fastapi import APIRouter, Header
1111
from fastapi.responses import StreamingResponse
12-
from pydantic_ai_ag_ui.consts import SSE_CONTENT_TYPE
12+
13+
from pydantic_ai.ag_ui import SSE_CONTENT_TYPE
1314

1415
from .agent import AGUIAgent
1516

examples/pydantic_ai_ag_ui_examples/api/agentic_generative_ui.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
from fastapi import APIRouter, Header
88
from fastapi.responses import StreamingResponse
99
from pydantic import BaseModel, Field
10-
from pydantic_ai_ag_ui.consts import SSE_CONTENT_TYPE
10+
11+
from pydantic_ai.ag_ui import SSE_CONTENT_TYPE
1112

1213
from .agent import AGUIAgent
1314

examples/pydantic_ai_ag_ui_examples/api/human_in_the_loop.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
from ag_ui.core import RunAgentInput
1111
from fastapi import APIRouter, Header
1212
from fastapi.responses import StreamingResponse
13-
from pydantic_ai_ag_ui.consts import SSE_CONTENT_TYPE
13+
14+
from pydantic_ai.ag_ui import SSE_CONTENT_TYPE
1415

1516
from .agent import AGUIAgent
1617

examples/pydantic_ai_ag_ui_examples/api/predictive_state_updates.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
from fastapi import APIRouter, Header
1010
from fastapi.responses import StreamingResponse
1111
from pydantic import BaseModel
12-
from pydantic_ai_ag_ui.consts import SSE_CONTENT_TYPE
13-
from pydantic_ai_ag_ui.deps import StateDeps
12+
13+
from pydantic_ai.ag_ui import SSE_CONTENT_TYPE, StateDeps
1414

1515
from .agent import AGUIAgent
1616

examples/pydantic_ai_ag_ui_examples/api/shared_state.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
from fastapi import APIRouter, Header
1212
from fastapi.responses import StreamingResponse
1313
from pydantic import BaseModel, Field
14-
from pydantic_ai_ag_ui.consts import SSE_CONTENT_TYPE
15-
from pydantic_ai_ag_ui.deps import StateDeps
14+
15+
from pydantic_ai.ag_ui import SSE_CONTENT_TYPE, StateDeps
1616

1717
from .agent import AGUIAgent
1818

0 commit comments

Comments
 (0)