Skip to content

Commit 564d9c3

Browse files
committed
chore(ag-ui): improve naming and structure
Rename the adapter-ag-ui package to to pydantic-ai-ag-ui for clarity and consistency with other Pydantic packages. Rename AdapterAGUI to Adapter for simplicity of use.
1 parent 9f81820 commit 564d9c3

39 files changed

+116
-118
lines changed

docs/ag-ui.md

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,25 @@ 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-
[adapter-ag-ui](#adapter-ag-ui) library to make it easy to implement the AG-UI
12-
protocol with PydanticAI agents.
11+
[pydantic-ai-ag-ui](#ag-ui-adapter) package to make it easy to implement the
12+
AG-UI protocol with PydanticAI agents.
1313

14-
This also includes a convenience method that exposes PydanticAI agents as an
15-
AG-UI server, which can then be used by as part of a
14+
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]
16+
for PydanticAI agents, which can then be used by as part of a
1617
[fastapi](https://fastapi.tiangolo.com/) app. Let's have a quick look at how to
1718
use it:
1819

1920
```py {title="agent_to_ag_ui.py" py="3.10" hl_lines="17-27"}
2021
"""Basic example for AG-UI with FastAPI and Pydantic AI."""
22+
2123
from __future__ import annotations
2224

2325
from typing import TYPE_CHECKING, Annotated
2426

25-
from adapter_ag_ui import SSE_CONTENT_TYPE
2627
from fastapi import FastAPI, Header
2728
from fastapi.responses import StreamingResponse
29+
from pydantic_ai_ag_ui import SSE_CONTENT_TYPE
2830

2931
from pydantic_ai import Agent
3032

@@ -57,7 +59,7 @@ requests to it.
5759

5860
## AG-UI Adapter
5961

60-
The [AdapterAGUI][adapter_ag_ui.AdapterAGUI] class is an adapter between
62+
The [Adapter][pydantic_ai_ag_ui.Adapter] class is an adapter between
6163
PydanticAI agents and the AG-UI protocol written in Python. It provides support
6264
for all aspects of spec including:
6365

@@ -80,16 +82,16 @@ streamed back to the caller as Server-Sent Events (SSE).
8082
A user request may require multiple round trips between client UI and PydanticAI
8183
server, depending on the tools and events needed.
8284

83-
[AdapterAGUI][adapter_ag_ui.AdapterAGUI] can be used with any ASGI server.
85+
[Adapter][pydantic_ai_ag_ui.Adapter] can be used with any ASGI server.
8486

8587
### Installation
8688

87-
[AdapterAGUI][adapter_ag_ui.AdapterAGUI] is available on PyPI as
88-
[`adapter-ag-ui`](https://pypi.org/project/adapter-ag-ui/) so installation is as
89+
[Adapter][pydantic_ai_ag_ui.Adapter] is available on PyPI as
90+
[`pydantic-ai-ag-ui`](https://pypi.org/project/pydantic-ai-ag-ui/) so installation is as
8991
simple as:
9092

9193
```bash
92-
pip/uv-add adapter-ag-ui
94+
pip/uv-add pydantic-ai-ag-ui
9395
```
9496

9597
The only dependencies are:
@@ -107,7 +109,7 @@ To run the examples you'll also need:
107109
pip/uv-add 'fastapi'
108110
```
109111

110-
You can install PydanticAI with the `ag-ui` extra to include **AdapterAGUI**:
112+
You can install PydanticAI with the `ag-ui` extra to include **Adapter**:
111113

112114
```bash
113115
pip/uv-add 'pydantic-ai-slim[ag-ui]'
@@ -120,8 +122,8 @@ use the [`to_ag_ui`][pydantic_ai.agent.Agent.to_ag_ui] method in combination
120122
with fastapi.
121123

122124
In the example below we have document state which is shared between the UI and
123-
server using the [`StateDeps`][adapter_ag_ui.StateDeps] which implements the
124-
[`StateHandler`][adapter_ag_ui.StateHandler] that can be used to automatically
125+
server using the [`StateDeps`][pydantic_ai_ag_ui.StateDeps] which implements the
126+
[`StateHandler`][pydantic_ai_ag_ui.StateHandler] that can be used to automatically
125127
decode state contained in [`RunAgentInput.state`](https://docs.ag-ui.com/sdk/js/core/types#runagentinput)
126128
when processing requests.
127129

@@ -138,10 +140,10 @@ from __future__ import annotations
138140

139141
from typing import TYPE_CHECKING, Annotated
140142

141-
from adapter_ag_ui import SSE_CONTENT_TYPE, StateDeps
142143
from fastapi import FastAPI, Header
143144
from fastapi.responses import StreamingResponse
144145
from pydantic import BaseModel
146+
from pydantic_ai_ag_ui import SSE_CONTENT_TYPE, StateDeps
145147

146148
from pydantic_ai import Agent
147149

@@ -172,7 +174,6 @@ async def root(
172174
adapter.run(input_data, accept, deps=StateDeps(state_type=DocumentState)),
173175
media_type=SSE_CONTENT_TYPE,
174176
)
175-
176177
```
177178

178179
Since `app` is an ASGI application, it can be used with any ASGI server.
@@ -183,7 +184,7 @@ uvicorn agent_to_ag_ui:app --host 0.0.0.0 --port 8000
183184

184185
Since the goal of [`to_ag_ui`][pydantic_ai.agent.Agent.to_ag_ui] is to be a
185186
convenience method, it accepts the same arguments as the
186-
[`AdapterAGUI`][adapter_ag_ui.AdapterAGUI] constructor.
187+
[`Adapter`][pydantic_ai_ag_ui.Adapter] constructor.
187188

188189
#### Tools
189190

@@ -205,11 +206,11 @@ from __future__ import annotations
205206

206207
from typing import TYPE_CHECKING, Annotated
207208

208-
from adapter_ag_ui import SSE_CONTENT_TYPE, StateDeps
209209
from ag_ui.core import CustomEvent, EventType, StateSnapshotEvent
210210
from fastapi import FastAPI, Header
211211
from fastapi.responses import StreamingResponse
212212
from pydantic import BaseModel
213+
from pydantic_ai_ag_ui import SSE_CONTENT_TYPE, StateDeps
213214

214215
from pydantic_ai import Agent, RunContext
215216

@@ -224,7 +225,6 @@ class DocumentState(BaseModel):
224225

225226

226227
app = FastAPI(title='AG-UI Endpoint')
227-
228228
agent = Agent(
229229
'openai:gpt-4.1',
230230
instructions='Be fun!',
@@ -265,30 +265,29 @@ async def root(
265265
adapter.run(input_data, accept, deps=StateDeps(state_type=DocumentState)),
266266
media_type=SSE_CONTENT_TYPE,
267267
)
268-
269268
```
270269

271270
### Examples
272271

273-
For more examples of how to use [`AdapterAGUI`][adapter_ag_ui.AdapterAGUI] see
274-
[`adapter_ag_ui_examples`](https://github.com/pydantic/pydantic-ai/tree/main/examples/adapter_ag_ui_examples),
272+
For more examples of how to use [`Adapter`][pydantic_ai_ag_ui.Adapter] see
273+
[`pydantic_ai_ag_ui_examples`](https://github.com/pydantic/pydantic-ai/tree/main/examples/pydantic_ai_ag_ui_examples),
275274
which includes working server for the with the
276275
[AG-UI Dojo](https://docs.ag-ui.com/tutorials/debugging#the-ag-ui-dojo) which
277-
can be run from a clone of the repo or with the `adapter_ag_ui_examples` package
276+
can be run from a clone of the repo or with the `pydantic_ai_ag_ui_examples` package
278277
installed with either of the following:
279278

280279
```bash
281-
pip/uv-add 'adapter_ag_ui_examples'
280+
pip/uv-add 'pydantic_ai_ag_ui_examples'
282281
```
283282

284283
Direct:
285284

286285
```shell
287-
python -m adapter_ag_ui_examples.dojo_server
286+
python -m pydantic_ai_ag_ui_examples.dojo_server
288287
```
289288

290289
Using uvicorn:
291290

292291
```shell
293-
uvicorn adapter_ag_ui_examples.dojo_server:app --host 0.0.0.0 --port 8000
292+
uvicorn pydantic_ai_ag_ui_examples.dojo_server:app --host 0.0.0.0 --port 8000
294293
```

docs/api/adapter_ag_ui.md

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

docs/api/pydantic_ai_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/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 `adapter-ag-ui` [PyPI ↗](https://pypi.org/project/adapter-ag-ui){:target="_blank"}
59+
* `ag-ui` - installs `pydantic-ai-ag-ui` [PyPI ↗](https://pypi.org/project/pydantic-ai-ag-ui){:target="_blank"}
6060

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

examples/adapter_ag_ui_examples/README.md renamed to examples/pydantic_ai_ag_ui_examples/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ To run this integration you need to:
2323
cd jobs-agent
2424
just install-deps
2525
source .venv/bin/activate
26-
python -m examples.adapter_ag_ui.dojo_server
26+
python -m examples.pydantic_ai_ag_ui_examples.dojo_server
2727
```
2828

2929
5. Open another terminal in root directory of the `ag-ui` repository clone

examples/adapter_ag_ui_examples/api/agent.py renamed to examples/pydantic_ai_ag_ui_examples/api/agent.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
from types import NoneType
77
from typing import Generic
88

9-
from adapter_ag_ui import AdapterAGUI
109
from dotenv import load_dotenv
10+
from pydantic_ai_ag_ui import Adapter
1111

1212
from pydantic_ai import Agent
1313
from pydantic_ai.result import OutputDataT
@@ -19,7 +19,7 @@ class AGUIAgent(Generic[AgentDepsT, OutputDataT]):
1919
"""Pydantic AI agent with AG-UI adapter."""
2020

2121
agent: Agent[AgentDepsT, str]
22-
adapter: AdapterAGUI[AgentDepsT, str]
22+
adapter: Adapter[AgentDepsT, str]
2323
instructions: str | None
2424

2525
def __init__(

examples/adapter_ag_ui_examples/api/agentic_chat.py renamed to examples/pydantic_ai_ag_ui_examples/api/agentic_chat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
from typing import TYPE_CHECKING, Annotated
77
from zoneinfo import ZoneInfo
88

9-
from adapter_ag_ui.consts import SSE_CONTENT_TYPE
109
from ag_ui.core import RunAgentInput
1110
from fastapi import APIRouter, Header
1211
from fastapi.responses import StreamingResponse
12+
from pydantic_ai_ag_ui.consts import SSE_CONTENT_TYPE
1313

1414
from .agent import AGUIAgent
1515

examples/adapter_ag_ui_examples/api/agentic_generative_ui.py renamed to examples/pydantic_ai_ag_ui_examples/api/agentic_generative_ui.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
from enum import StrEnum
44
from typing import Annotated, Any, Literal
55

6-
from adapter_ag_ui.consts import SSE_CONTENT_TYPE
76
from ag_ui.core import EventType, RunAgentInput, StateDeltaEvent, StateSnapshotEvent
87
from fastapi import APIRouter, Header
98
from fastapi.responses import StreamingResponse
109
from pydantic import BaseModel, Field
10+
from pydantic_ai_ag_ui.consts import SSE_CONTENT_TYPE
1111

1212
from .agent import AGUIAgent
1313

0 commit comments

Comments
 (0)