|
15 | 15 | import random
|
16 | 16 |
|
17 | 17 | from google.adk.agents import Agent
|
| 18 | +from google.adk.examples.example import Example |
18 | 19 | from google.adk.tools.example_tool import ExampleTool
|
19 | 20 | from google.genai import types
|
20 | 21 |
|
@@ -66,43 +67,47 @@ def check_prime(nums: list[int]) -> str:
|
66 | 67 | )
|
67 | 68 |
|
68 | 69 |
|
69 |
| -example_tool = ExampleTool([ |
70 |
| - { |
71 |
| - "input": { |
72 |
| - "role": "user", |
73 |
| - "parts": [{"text": "Roll a 6-sided die."}], |
74 |
| - }, |
75 |
| - "output": [ |
76 |
| - {"role": "model", "parts": [{"text": "I rolled a 4 for you."}]} |
77 |
| - ], |
78 |
| - }, |
79 |
| - { |
80 |
| - "input": { |
81 |
| - "role": "user", |
82 |
| - "parts": [{"text": "Is 7 a prime number?"}], |
83 |
| - }, |
84 |
| - "output": [{ |
85 |
| - "role": "model", |
86 |
| - "parts": [{"text": "Yes, 7 is a prime number."}], |
87 |
| - }], |
88 |
| - }, |
89 |
| - { |
90 |
| - "input": { |
91 |
| - "role": "user", |
92 |
| - "parts": [{"text": "Roll a 10-sided die and check if it's prime."}], |
93 |
| - }, |
94 |
| - "output": [ |
95 |
| - { |
96 |
| - "role": "model", |
97 |
| - "parts": [{"text": "I rolled an 8 for you."}], |
98 |
| - }, |
99 |
| - { |
100 |
| - "role": "model", |
101 |
| - "parts": [{"text": "8 is not a prime number."}], |
102 |
| - }, |
103 |
| - ], |
104 |
| - }, |
105 |
| -]) |
| 70 | +example_tool = ExampleTool( |
| 71 | + examples=[ |
| 72 | + Example( |
| 73 | + input=types.UserContent( |
| 74 | + parts=[types.Part(text="Roll a 6-sided die.")] |
| 75 | + ), |
| 76 | + output=[ |
| 77 | + types.ModelContent( |
| 78 | + parts=[types.Part(text="I rolled a 4 for you.")] |
| 79 | + ) |
| 80 | + ], |
| 81 | + ), |
| 82 | + Example( |
| 83 | + input=types.UserContent( |
| 84 | + parts=[types.Part(text="Is 7 a prime number?")] |
| 85 | + ), |
| 86 | + output=[ |
| 87 | + types.ModelContent( |
| 88 | + parts=[types.Part(text="Yes, 7 is a prime number.")] |
| 89 | + ) |
| 90 | + ], |
| 91 | + ), |
| 92 | + Example( |
| 93 | + input=types.UserContent( |
| 94 | + parts=[ |
| 95 | + types.Part( |
| 96 | + text="Roll a 10-sided die and check if it's prime." |
| 97 | + ) |
| 98 | + ] |
| 99 | + ), |
| 100 | + output=[ |
| 101 | + types.ModelContent( |
| 102 | + parts=[types.Part(text="I rolled an 8 for you.")] |
| 103 | + ), |
| 104 | + types.ModelContent( |
| 105 | + parts=[types.Part(text="8 is not a prime number.")] |
| 106 | + ), |
| 107 | + ], |
| 108 | + ), |
| 109 | + ] |
| 110 | +) |
106 | 111 |
|
107 | 112 | prime_agent = Agent(
|
108 | 113 | name="prime_agent",
|
|
0 commit comments