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()))
150150
151151
152152@agent.tool
153- def update_state (ctx : RunContext[StateDeps[DocumentState]]) -> StateSnapshotEvent:
153+ async def update_state (ctx : RunContext[StateDeps[DocumentState]]) -> StateSnapshotEvent:
154154 return StateSnapshotEvent(
155155 type = EventType.STATE_SNAPSHOT ,
156156 snapshot = ctx.deps.state,
157157 )
158158
159159
160160@agent.tool_plain
161- def custom_events () -> list[CustomEvent]:
161+ async def custom_events () -> list[CustomEvent]:
162162 return [
163163 CustomEvent(
164164 type = EventType.CUSTOM ,
Original file line number Diff line number Diff line change @@ -67,7 +67,7 @@ class JSONPatchOp(BaseModel):
6767
6868
6969@agent .tool_plain
70- def create_plan (steps : list [str ]) -> StateSnapshotEvent :
70+ async def create_plan (steps : list [str ]) -> StateSnapshotEvent :
7171 """Create a plan with multiple steps.
7272
7373 Args:
@@ -86,7 +86,7 @@ def create_plan(steps: list[str]) -> StateSnapshotEvent:
8686
8787
8888@agent .tool_plain
89- def update_plan_step (
89+ async def update_plan_step (
9090 index : int , description : str | None = None , status : StepStatus | None = None
9191) -> StateDeltaEvent :
9292 """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):
2323# Tools which return AG-UI events will be sent to the client as part of the
2424# event stream, single events and iterables of events are supported.
2525@agent .tool_plain
26- def document_predict_state () -> list [CustomEvent ]:
26+ async def document_predict_state () -> list [CustomEvent ]:
2727 """Enable document state prediction.
2828
2929 Returns:
@@ -45,7 +45,7 @@ def document_predict_state() -> list[CustomEvent]:
4545
4646
4747@agent .instructions ()
48- def story_instructions (ctx : RunContext [StateDeps [DocumentState ]]) -> str :
48+ async def story_instructions (ctx : RunContext [StateDeps [DocumentState ]]) -> str :
4949 """Provide instructions for writing document if present.
5050
5151 Args:
Original file line number Diff line number Diff line change @@ -88,7 +88,7 @@ class RecipeSnapshot(BaseModel):
8888
8989
9090@agent .tool_plain
91- def display_recipe (recipe : Recipe ) -> StateSnapshotEvent :
91+ async def display_recipe (recipe : Recipe ) -> StateSnapshotEvent :
9292 """Display the recipe to the user.
9393
9494 Args:
@@ -104,7 +104,7 @@ def display_recipe(recipe: Recipe) -> StateSnapshotEvent:
104104
105105
106106@agent .instructions
107- def recipe_instructions (ctx : RunContext [StateDeps [RecipeSnapshot ]]) -> str :
107+ async def recipe_instructions (ctx : RunContext [StateDeps [RecipeSnapshot ]]) -> str :
108108 """Instructions for the recipe generation agent.
109109
110110 Args:
@@ -122,6 +122,7 @@ def recipe_instructions(ctx: RunContext[StateDeps[RecipeSnapshot]]) -> str:
122122 - Append new ingredients to the existing ones
123123 - Use the `display_recipe` tool to present the recipe to the user
124124 - 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
125126
126127 Once you have created the updated recipe and displayed it to the user,
127128 summarise the changes in one sentence, don't describe the recipe in
You can’t perform that action at this time.
0 commit comments