Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit46acd66

Browse files
committed
chore(ag-ui): refactor examples and docs
Refactor examples and documentation for the AG-UI integration, includingrenaming and restructuring files for clarity and consistency. Thisincludes moving examples to a dedicated directory and updatingreferences in the documentation.Use Pydantic AI instead of PydanticAI for consistency.Fix import orders in the examples.
1 parent145f71d commit46acd66

File tree

18 files changed

+86
-60
lines changed

18 files changed

+86
-60
lines changed

‎docs/ag-ui.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,6 @@ uvicorn ag_ui_tool_events:app --host 0.0.0.0 --port 9000
182182
##Examples
183183

184184
For more examples of how to use[`to_ag_ui()`][pydantic_ai.Agent.to_ag_ui] see
185-
[`pydantic_ai_ag_ui_examples`](https://github.com/pydantic/pydantic-ai/tree/main/examples/pydantic_ai_ag_ui_examples),
185+
[`pydantic_ai_examples.ag_ui`](https://github.com/pydantic/pydantic-ai/tree/main/examples/pydantic_ai_examples/ag_ui),
186186
which includes a server for use with the
187187
[AG-UI Dojo](https://docs.ag-ui.com/tutorials/debugging#the-ag-ui-dojo).

‎examples/pydantic_ai_ag_ui_examples/README.mdrenamed to ‎docs/examples/ag-ui.md

Lines changed: 57 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,64 @@
1-
#PydanticAIAG-UI Examples
1+
#Agent User Interaction (AG-UI) Protocol
22

3-
This example uses PydanticAI agents with the[AG-UI Dojo](https://github.com/ag-ui-protocol/ag-ui/tree/main/typescript-sdk/apps/dojo) example app.
3+
Example of using Pydantic AI agents with the[AG-UI Dojo](https://github.com/ag-ui-protocol/ag-ui/tree/main/typescript-sdk/apps/dojo) example app.
4+
5+
See the[AG-UI docs](../ag-ui.md) for more information about the AG-UI integration.
6+
7+
Demonstrates:
8+
9+
-[AG-UI](../ag-ui.md)
10+
-[Tools](../tools.md)
411

512
##Prerequisites
613

7-
1. An[OpenAI API key](https://help.openai.com/en/articles/4936850-where-do-i-find-my-openai-api-key)
8-
2. A clone of the[AG-UI repository](https://github.com/ag-ui-protocol/ag-ui)
14+
- An[OpenAI API key](https://help.openai.com/en/articles/4936850-where-do-i-find-my-openai-api-key)
15+
16+
##Running the Example
917

10-
##Running
18+
With[dependencies installed and environment variables set](./index.md#usage)
19+
you will need two command line windows.
1120

12-
1. Run the Pydantic AI AG-UI example backend
21+
###Pydantic AI AG-UI backend
22+
23+
Start by running the Pydantic AI AG-UI example backend.
24+
25+
```bash
26+
export OPENAI_API_KEY=<your api key>
27+
python/uv-run -m pydantic_ai_examples.ag_ui
28+
```
1329

14-
1. Install the`pydantic-ai-examples` package
30+
###AG-UI Dojo example frontend
1531

16-
```shell
17-
pip/uv-add pydantic-ai-examples
18-
```
32+
Next run the AG-UI Dojo example frontend.
1933

20-
2. Run theexampleAG-UIapp
34+
1. Clone the[AG-UIrepository](https://github.com/ag-ui-protocol/ag-ui)
2135

22-
```shell
23-
python/uv-run -m pydantic_ai_ag_ui_examples.dojo_server
24-
```
36+
```shell
37+
git clone https://github.com/ag-ui-protocol/ag-ui.git
38+
```
2539

26-
2. Run the AG-UI Dojo example frontend
27-
1. Move to the cloned AG-UI repository directory
28-
2. In the`typescript-sdk/integrations/pydantic-ai` directory, copy`.env-sample` to`.env`
29-
3. Open itin your editor andset`OPENAI_API_KEY` to a valid OpenAI key
30-
4. Open a terminalin the`typescript-sdk` directory
31-
5. Run the Dojo app following the [official instructions](https://github.com/ag-ui-protocol/ag-ui/tree/main/typescript-sdk/apps/dojo#development-setup)
40+
2. Change into to the`ag-ui/typescript-sdk` directory
3241

33-
3. Finally visit<http://localhost:3000/pydantic-ai>
42+
```shell
43+
cd ag-ui/typescript-sdk
44+
```
3445

35-
## Feature Demos
46+
3. Run the Dojo app following the [official instructions](https://github.com/ag-ui-protocol/ag-ui/tree/main/typescript-sdk/apps/dojo#development-setup)
47+
4. Visit<http://localhost:3000/pydantic-ai>
48+
5. Select View`Pydantic AI` from the sidebar
3649

37-
### [Agentic Chat](http://localhost:3000/pydantic-ai/feature/agentic_chat)
50+
## Feature Examples
3851

39-
This demonstrates a basic agent interaction including PydanticAI server side
52+
### Agentic Chat
53+
54+
This demonstrates a basic agent interaction including Pydantic AI server side
4055
tools and AG-UI client side tools.
4156

57+
View the [Agentic Chat example](http://localhost:3000/pydantic-ai/feature/agentic_chat).
58+
4259
#### Agent Tools
4360

44-
-`time` -PydanticAI tool to check the currenttimefor atime zone
61+
-`time` -Pydantic AI tool to check the currenttimefor atime zone
4562
-`background` - AG-UI tool toset the background color of the client window
4663

4764
#### Agent Prompts
@@ -54,7 +71,7 @@ What is the time in New York?
5471
Change the background to blue
5572
```
5673

57-
A complex example which mixes both AG-UI andPydanticAI tools:
74+
A complex example which mixes both AG-UI andPydantic AI tools:
5875

5976
```text
6077
Perform the following steps, waitingfor the response of each step before continuing:
@@ -64,18 +81,20 @@ Perform the following steps, waiting for the response of each step before contin
6481
4. Report how long the backgroundset took by diffing the twotimes
6582
```
6683

67-
###[Agentic Generative UI](http://localhost:3000/pydantic-ai/feature/agentic_generative_ui)
84+
### Agentic Generative UI
6885

6986
Demonstrates a long running task where the agent sends updates to the frontend
7087
tolet the user know what's happening.
7188
89+
View the [Agentic Generative UI example](http://localhost:3000/pydantic-ai/feature/agentic_generative_ui).
90+
7291
#### Plan Prompts
7392
7493
```text
7594
Create a plan for breakfast and execute it
7695
```
7796
78-
###[Human in the Loop](http://localhost:3000/pydantic-ai/feature/human_in_the_loop)
97+
### Human in the Loop
7998
8099
Demonstrates simple human in the loop workflow where the agent comes up with a
81100
plan and the user can approve it using checkboxes.
@@ -90,16 +109,18 @@ plan and the user can approve it using checkboxes.
90109
Generate a list of steps for cleaning a car for me to review
91110
```
92111
93-
###[Predictive State Updates](http://localhost:3000/pydantic-ai/feature/predictive_state_updates)
112+
### Predictive State Updates
94113
95114
Demonstrates how to use the predictive state updates feature to update the state
96115
of the UI based on agent responses, including user interaction via user
97116
confirmation.
98117
118+
View the [Predictive State Updates example](http://localhost:3000/pydantic-ai/feature/predictive_state_updates).
119+
99120
#### Story Tools
100121
101122
- `write_document` - AG-UI tool to write the document to a window
102-
- `document_predict_state` -PydanticAI tool that enables document state
123+
- `document_predict_state` -Pydantic AI tool that enables document state
103124
prediction for the `write_document` tool
104125
105126
This also shows how to use custom instructions based on shared state information.
@@ -118,14 +139,16 @@ Agent prompt
118139
Help me complete my story about bruce the dog, is should be no longer than a sentence.
119140
```
120141
121-
###[Shared State](http://localhost:3000/pydantic-ai/feature/shared_state)
142+
### Shared State
122143
123144
Demonstrates how to use the shared state between the UI and the agent.
124145
125146
State sent to the agent is detected by a function based instruction. This then
126147
validates the data using a custom pydantic model before using to create the
127148
instructions for the agent to follow and send to the client using a AG-UI tool.
128149
150+
View the [Shared State example](http://localhost:3000/pydantic-ai/feature/shared_state).
151+
129152
#### Recipe Tools
130153
131154
- `display_recipe` - AG-UI tool to display the recipe in a graphical format
@@ -135,10 +158,12 @@ instructions for the agent to follow and send to the client using a AG-UI tool.
135158
1. Customise the basic settings of your recipe
136159
2. Click `Improve with AI`
137160
138-
###[Tool Based Generative UI](http://localhost:3000/pydantic-ai/feature/tool_based_generative_ui)
161+
### Tool Based Generative UI
139162
140163
Demonstrates customised rendering for tool output with used confirmation.
141164
165+
View the [Tool Based Generative UI example](http://localhost:3000/pydantic-ai/feature/tool_based_generative_ui).
166+
142167
#### Haiku Tools
143168
144169
- `generate_haiku` - AG-UI tool to display a haiku in English and Japanese

‎docs/tools.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ For more advanced use cases, the [toolsets](toolsets.md) feature lets you manage
1717
!!! info "Function tools vs. RAG"
1818
Function tools are basically the "R" of RAG (Retrieval-Augmented Generation) — they augment what the model can do by letting it request extra information.
1919

20-
The main semantic difference betweenPydanticAITools and RAG is RAG is synonymous with vector search, whilePydanticAI tools are more general-purpose. (Note: we may add support for vector search functionality in the future, particularly an API for generating embeddings. See [#58](https://github.com/pydantic/pydantic-ai/issues/58))
20+
The main semantic difference betweenPydantic AITools and RAG is RAG is synonymous with vector search, whilePydantic AI tools are more general-purpose. (Note: we may add support for vector search functionality in the future, particularly an API for generating embeddings. See [#58](https://github.com/pydantic/pydantic-ai/issues/58))
2121

2222
!!! info "Function Tools vs. Structured Outputs"
2323
As the name suggests, function tools use the model's "tools" or "functions" API to let the model know what is available to call. Tools or functions are also used to define the schema(s) for[structured output](output.md) when using the default[tool output mode](output.md#tool-output), thus a model might have access to many tools, some of which call function tools while others end the run and produce a final output.

‎examples/pydantic_ai_ag_ui_examples/__init__.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

‎examples/pydantic_ai_ag_ui_examples/dojo_server.pyrenamed to ‎examples/pydantic_ai_examples/ag_ui/__init__.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
"""Example usage of the AG-UI adapter forPydanticAI.
1+
"""Example usage of the AG-UI adapter forPydantic AI.
22
33
This provides a FastAPI application that demonstrates how to use the
4-
PydanticAI agent with the AG-UI protocol. It includes examples for
4+
Pydantic AI agent with the AG-UI protocol. It includes examples for
55
each of the AG-UI dojo features:
66
- Agentic Chat
77
- Human in the Loop
@@ -24,7 +24,7 @@
2424
tool_based_generative_ui_app,
2525
)
2626

27-
app=FastAPI(title='PydanticAI AG-UI server')
27+
app=FastAPI(title='Pydantic AI AG-UI server')
2828
app.mount('/agentic_chat',agentic_chat_app,'Agentic Chat')
2929
app.mount('/agentic_generative_ui',agentic_generative_ui_app,'Agentic Generative UI')
3030
app.mount('/human_in_the_loop',human_in_the_loop_app,'Human in the Loop')
@@ -39,9 +39,3 @@
3939
tool_based_generative_ui_app,
4040
'Tool Based Generative UI',
4141
)
42-
43-
44-
if__name__=='__main__':
45-
importuvicorn
46-
47-
uvicorn.run('pydantic_ai_ag_ui_examples.dojo_server:app',port=9000)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
"""Very simply CLI to run the AG-UI example.
2+
3+
See https://ai.pydantic.dev/examples/ag-ui/ for more information.
4+
"""
5+
6+
if__name__=='__main__':
7+
importuvicorn
8+
9+
uvicorn.run('pydantic_ai_examples.ag_ui:app',port=9000)

‎examples/pydantic_ai_ag_ui_examples/api/agentic_generative_ui.pyrenamed to ‎examples/pydantic_ai_examples/ag_ui/api/agentic_generative_ui.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
fromtextwrapimportdedent
66
fromtypingimportAny,Literal
77

8-
fromag_ui.coreimportEventType,StateDeltaEvent,StateSnapshotEvent
98
frompydanticimportBaseModel,Field
109

10+
fromag_ui.coreimportEventType,StateDeltaEvent,StateSnapshotEvent
1111
frompydantic_aiimportAgent
1212

1313
StepStatus=Literal['pending','completed']

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp