8000 chore: Fixes the sample of example_tool · devevignesh/adk-python@b08bdbc · GitHub
[go: up one dir, main page]

Skip to content

Commit b08bdbc

Browse files
Jacksunweicopybara-github
authored andcommitted
chore: Fixes the sample of example_tool
The `Example` objects should be strong typed. PiperOrigin-RevId: 770476132
1 parent fc65873 commit b08bdbc

File tree

1 file changed

+42
-37
lines changed
  • contributing/samples/hello_world_ma

1 file changed

+42
-37
lines changed

contributing/samples/hello_world_ma/agent.py

Lines changed: 42 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import random
1616

1717
from google.adk.agents import Agent
18+
from google.adk.examples.example import Example
1819
from google.adk.tools.example_tool import ExampleTool
1920
from google.genai import types
2021

@@ -66,43 +67,47 @@ def check_prime(nums: list[int]) -> str:
6667
)
6768

6869

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+
)
106111

107112
prime_agent = Agent(
108113
name="prime_agent",

0 commit comments

Comments
 (0)
0