Skip to content

Commit 6063844

Browse files
authored
Replace dice diagram svgs with mermaid (#74)
1 parent 7e2ba87 commit 6063844

File tree

4 files changed

+44
-35
lines changed

4 files changed

+44
-35
lines changed

docs/agents.md

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -194,16 +194,16 @@ agent = Agent(
194194
'gemini-1.5-flash', # (1)!
195195
deps_type=str, # (2)!
196196
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. "
199199
"Use the player's name in the response."
200200
),
201201
)
202202

203203

204204
@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."""
207207
return str(random.randint(1, 6))
208208

209209

@@ -235,7 +235,7 @@ print(dice_result.all_messages())
235235
"""
236236
[
237237
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.",
239239
role='system',
240240
),
241241
UserPrompt(
@@ -246,14 +246,14 @@ print(dice_result.all_messages())
246246
ModelStructuredResponse(
247247
calls=[
248248
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
250250
)
251251
],
252252
timestamp=datetime.datetime(...),
253253
role='model-structured-response',
254254
),
255255
ToolReturn(
256-
tool_name='roll_dice',
256+
tool_name='roll_die',
257257
content='4',
258258
tool_id=None,
259259
timestamp=datetime.datetime(...),
@@ -286,10 +286,41 @@ print(dice_result.all_messages())
286286
"""
287287
```
288288

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+
```
293324

294325
### Retrievers, tools, and schema
295326

docs/img/dice-diagram-dark.svg

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

docs/img/dice-diagram-light.svg

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

tests/test_examples.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ async def async_http_request(url: str, **kwargs: Any) -> httpx.Response:
149149
'What is the date?': 'Hello Frank, the date today is 2032-01-02.',
150150
'Put my money on square eighteen': ToolCall(tool_name='roulette_wheel', args=ArgsObject({'square': 18})),
151151
'I bet five is the winner': ToolCall(tool_name='roulette_wheel', args=ArgsObject({'square': 5})),
152-
'My guess is 4': ToolCall(tool_name='roll_dice', args=ArgsObject({})),
152+
'My guess is 4': ToolCall(tool_name='roll_die', args=ArgsObject({})),
153153
'Send a message to John Doe asking for coffee next week': ToolCall(
154154
tool_name='get_user_by_name', args=ArgsObject({'name': 'John'})
155155
),
@@ -186,7 +186,7 @@ async def model_logic(messages: list[Message], info: AgentInfo) -> ModelAnyRespo
186186
elif m.role == 'tool-return' and m.tool_name == 'roulette_wheel':
187187
win = m.content == 'winner'
188188
return ModelStructuredResponse(calls=[ToolCall(tool_name='final_result', args=ArgsObject({'response': win}))])
189-
elif m.role == 'tool-return' and m.tool_name == 'roll_dice':
189+
elif m.role == 'tool-return' and m.tool_name == 'roll_die':
190190
return ModelStructuredResponse(calls=[ToolCall(tool_name='get_player_name', args=ArgsObject({}))])
191191
elif m.role == 'tool-return' and m.tool_name == 'get_player_name':
192192
return ModelTextResponse(content="Congratulations Adam, you guessed correctly! You're a winner!")

0 commit comments

Comments
 (0)