@@ -194,16 +194,16 @@ agent = Agent(
194
194
' gemini-1.5-flash' , # (1)!
195
195
deps_type = str , # (2)!
196
196
system_prompt = (
197
- " You're a dice game, you should roll the dice and see if the number "
198
- " you got back matches the user's guess, if so tell them they're a winner. "
197
+ " You're a dice game, you should roll the die and see if the number "
198
+ " you get back matches the user's guess. If so, tell them they're a winner. "
199
199
" Use the player's name in the response."
200
200
),
201
201
)
202
202
203
203
204
204
@agent.retriever_plain # (3)!
205
- def roll_dice () -> str :
206
- """ Roll a six-sided dice and return the result."""
205
+ def roll_die () -> str :
206
+ """ Roll a six-sided die and return the result."""
207
207
return str (random.randint(1 , 6 ))
208
208
209
209
@@ -235,7 +235,7 @@ print(dice_result.all_messages())
235
235
"""
236
236
[
237
237
SystemPrompt(
238
- content="You're a dice game, you should roll the dice and see if the number you got back matches the user's guess, if so tell them they're a winner. Use the player's name in the response.",
238
+ content="You're a dice game, you should roll the die and see if the number you get back matches the user's guess. If so, tell them they're a winner. Use the player's name in the response.",
239
239
role='system',
240
240
),
241
241
UserPrompt(
@@ -246,14 +246,14 @@ print(dice_result.all_messages())
246
246
ModelStructuredResponse(
247
247
calls=[
248
248
ToolCall(
249
- tool_name='roll_dice ', args=ArgsObject(args_object={}), tool_id=None
249
+ tool_name='roll_die ', args=ArgsObject(args_object={}), tool_id=None
250
250
)
251
251
],
252
252
timestamp=datetime.datetime(...),
253
253
role='model-structured-response',
254
254
),
255
255
ToolReturn(
256
- tool_name='roll_dice ',
256
+ tool_name='roll_die ',
257
257
content='4',
258
258
tool_id=None,
259
259
timestamp=datetime.datetime(...),
@@ -286,10 +286,41 @@ print(dice_result.all_messages())
286
286
"""
287
287
```
288
288
289
- We can represent that as a flow diagram, thus:
290
-
291
- ![ Dice game flow diagram] ( ./img/dice-diagram-light.svg#only-light )
292
- ![ Dice game flow diagram] ( ./img/dice-diagram-dark.svg#only-dark )
289
+ We can represent this with a diagram:
290
+
291
+ ``` mermaid
292
+ sequenceDiagram
293
+ participant Agent
294
+ participant LLM
295
+
296
+ Note over Agent: Send prompts
297
+ Agent ->> LLM: System: "You're a dice game..."<br>User: "My guess is 4"
298
+ activate LLM
299
+ Note over LLM: LLM decides to use<br>a retriever
300
+
301
+ LLM ->> Agent: Call retriever<br>roll_die()
302
+ deactivate LLM
303
+ activate Agent
304
+ Note over Agent: Rolls a six-sided die
305
+
306
+ Agent -->> LLM: ToolReturn<br>"4"
307
+ deactivate Agent
308
+ activate LLM
309
+ Note over LLM: LLM decides to use<br>another retriever
310
+
311
+ LLM ->> Agent: Call retriever<br>get_player_name()
312
+ deactivate LLM
313
+ activate Agent
314
+ Note over Agent: Retrieves player name
315
+ Agent -->> LLM: ToolReturn<br>"Adam"
316
+ deactivate Agent
317
+ activate LLM
318
+ Note over LLM: LLM constructs final response
319
+
320
+ LLM ->> Agent: ModelTextResponse<br>"Congratulations Adam, ..."
321
+ deactivate LLM
322
+ Note over Agent: Game session complete
323
+ ```
293
324
294
325
### Retrievers, tools, and schema
295
326
0 commit comments