File tree Expand file tree Collapse file tree 4 files changed +9
-8
lines changed
examples/pydantic_ai_examples/ag_ui/api Expand file tree Collapse file tree 4 files changed +9
-8
lines changed Original file line number Diff line number Diff line change @@ -150,15 +150,15 @@ app = agent.to_ag_ui(deps=StateDeps(DocumentState()))
150
150
151
151
152
152
@agent.tool
153
- def update_state (ctx : RunContext[StateDeps[DocumentState]]) -> StateSnapshotEvent:
153
+ async def update_state (ctx : RunContext[StateDeps[DocumentState]]) -> StateSnapshotEvent:
154
154
return StateSnapshotEvent(
155
155
type = EventType.STATE_SNAPSHOT ,
156
156
snapshot = ctx.deps.state,
157
157
)
158
158
159
159
160
160
@agent.tool_plain
161
- def custom_events () -> list[CustomEvent]:
161
+ async def custom_events () -> list[CustomEvent]:
162
162
return [
163
163
CustomEvent(
164
164
type = EventType.CUSTOM ,
Original file line number Diff line number Diff line change @@ -67,7 +67,7 @@ class JSONPatchOp(BaseModel):
67
67
68
68
69
69
@agent .tool_plain
70
- def create_plan (steps : list [str ]) -> StateSnapshotEvent :
70
+ async def create_plan (steps : list [str ]) -> StateSnapshotEvent :
71
71
"""Create a plan with multiple steps.
72
72
73
73
Args:
@@ -86,7 +86,7 @@ def create_plan(steps: list[str]) -> StateSnapshotEvent:
86
86
87
87
88
88
@agent .tool_plain
89
- def update_plan_step (
89
+ async def update_plan_step (
90
90
index : int , description : str | None = None , status : StepStatus | None = None
91
91
) -> StateDeltaEvent :
92
92
"""Update the plan with new steps or changes.
Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ class DocumentState(BaseModel):
23
23
# Tools which return AG-UI events will be sent to the client as part of the
24
24
# event stream, single events and iterables of events are supported.
25
25
@agent .tool_plain
26
- def document_predict_state () -> list [CustomEvent ]:
26
+ async def document_predict_state () -> list [CustomEvent ]:
27
27
"""Enable document state prediction.
28
28
29
29
Returns:
@@ -45,7 +45,7 @@ def document_predict_state() -> list[CustomEvent]:
45
45
46
46
47
47
@agent .instructions ()
48
- def story_instructions (ctx : RunContext [StateDeps [DocumentState ]]) -> str :
48
+ async def story_instructions (ctx : RunContext [StateDeps [DocumentState ]]) -> str :
49
49
"""Provide instructions for writing document if present.
50
50
51
51
Args:
Original file line number Diff line number Diff line change @@ -88,7 +88,7 @@ class RecipeSnapshot(BaseModel):
88
88
89
89
90
90
@agent .tool_plain
91
- def display_recipe (recipe : Recipe ) -> StateSnapshotEvent :
91
+ async def display_recipe (recipe : Recipe ) -> StateSnapshotEvent :
92
92
"""Display the recipe to the user.
93
93
94
94
Args:
@@ -104,7 +104,7 @@ def display_recipe(recipe: Recipe) -> StateSnapshotEvent:
104
104
105
105
106
106
@agent .instructions
107
- def recipe_instructions (ctx : RunContext [StateDeps [RecipeSnapshot ]]) -> str :
107
+ async def recipe_instructions (ctx : RunContext [StateDeps [RecipeSnapshot ]]) -> str :
108
108
"""Instructions for the recipe generation agent.
109
109
110
110
Args:
@@ -122,6 +122,7 @@ def recipe_instructions(ctx: RunContext[StateDeps[RecipeSnapshot]]) -> str:
122
122
- Append new ingredients to the existing ones
123
123
- Use the `display_recipe` tool to present the recipe to the user
124
124
- Do NOT repeat the recipe in the message, use the tool instead
125
+ - Do NOT run the `display_recipe` tool multiple times in a row
125
126
126
127
Once you have created the updated recipe and displayed it to the user,
127
128
summarise the changes in one sentence, don't describe the recipe in
You can’t perform that action at this time.
0 commit comments