Skip to content

Commit 452c15f

Browse files
Fix Go multi-tool tutorial snippet to include two tools (#1577)
* Fix Go multi-tool tutorial snippet to include two tools * Update model string in multi-tool snippets to gemini-flash-latest in Python, TS, Java --------- Co-authored-by: Kristopher Overholt <koverholt@google.com>
1 parent c5f9b2d commit 452c15f

4 files changed

Lines changed: 70 additions & 8 deletions

File tree

  • examples
    • go/snippets/get-started/multi_tool_agent
    • java/cloud-run/src/main/java/agents/multitool
    • python/snippets/get-started/multi_tool_agent
    • typescript/snippets/get-started/multi_tool_agent

examples/go/snippets/get-started/multi_tool_agent/main.go

Lines changed: 67 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import (
1919
"context"
2020
"log"
2121
"os"
22+
"strings"
23+
"time"
2224

2325
"google.golang.org/genai"
2426

@@ -28,9 +30,13 @@ import (
2830
"google.golang.org/adk/v2/cmd/launcher/full"
2931
"google.golang.org/adk/v2/model/gemini"
3032
"google.golang.org/adk/v2/tool"
31-
"google.golang.org/adk/v2/tool/geminitool"
33+
"google.golang.org/adk/v2/tool/functiontool"
3234
)
3335

36+
type CityArgs struct {
37+
City string `json:"city"`
38+
}
39+
3440
func main() {
3541
ctx := context.Background()
3642

@@ -43,14 +49,70 @@ func main() {
4349
log.Fatalf("Failed to create model: %v", err)
4450
}
4551

52+
weatherTool, err := functiontool.New[CityArgs, map[string]any](
53+
functiontool.Config{
54+
Name: "get_weather",
55+
Description: "Retrieves the current weather report for a specified city.",
56+
},
57+
func(ctx agent.Context, args CityArgs) (map[string]any, error) {
58+
if strings.EqualFold(args.City, "new york") {
59+
return map[string]any{
60+
"status": "success",
61+
"report": "The weather in New York is sunny with a temperature of 25 degrees Celsius (77 degrees Fahrenheit).",
62+
}, nil
63+
}
64+
return map[string]any{
65+
"status": "error",
66+
"error_message": "Weather information for '" + args.City + "' is not available.",
67+
}, nil
68+
},
69+
)
70+
if err != nil {
71+
log.Fatalf("Failed to create get_weather tool: %v", err)
72+
}
73+
74+
currentTimeTool, err := functiontool.New[CityArgs, map[string]any](
75+
functiontool.Config{
76+
Name: "get_current_time",
77+
Description: "Returns the current time in a specified city.",
78+
},
79+
func(ctx agent.Context, args CityArgs) (map[string]any, error) {
80+
var tzIdentifier string
81+
if strings.EqualFold(args.City, "new york") {
82+
tzIdentifier = "America/New_York"
83+
} else {
84+
return map[string]any{
85+
"status": "error",
86+
"error_message": "Sorry, I don't have timezone information for " + args.City + ".",
87+
}, nil
88+
}
89+
90+
tz, err := time.LoadLocation(tzIdentifier)
91+
if err != nil {
92+
return nil, err
93+
}
94+
95+
now := time.Now().In(tz)
96+
report := "The current time in " + args.City + " is " + now.Format("2006-01-02 15:04:05 MST-0700")
97+
return map[string]any{
98+
"status": "success",
99+
"report": report,
100+
}, nil
101+
},
102+
)
103+
if err != nil {
104+
log.Fatalf("Failed to create get_current_time tool: %v", err)
105+
}
106+
46107
// 2. Define the agent.
47108
a, err := llmagent.New(llmagent.Config{
48-
Name: "multi_tool_agent",
109+
Name: "weather_time_agent",
49110
Model: model,
50-
Description: "An agent that can answer questions using Google Search.",
51-
Instruction: "You are a helpful assistant. Use the available tools to answer questions.",
111+
Description: "Agent to answer questions about the time and weather in a city.",
112+
Instruction: "You are a helpful agent who can answer user questions about the time and weather in a city.",
52113
Tools: []tool.Tool{
53-
geminitool.GoogleSearch{},
114+
weatherTool,
115+
currentTimeTool,
54116
},
55117
})
56118
if err != nil {

examples/java/cloud-run/src/main/java/agents/multitool/MultiToolAgent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public class MultiToolAgent {
3131
public static BaseAgent initAgent() {
3232
return LlmAgent.builder()
3333
.name(NAME)
34-
.model("gemini-2.0-flash")
34+
.model("gemini-flash-latest")
3535
.description("Agent to answer questions about the time and weather in a city.")
3636
.instruction(
3737
"You are a helpful agent who can answer user questions about the time and weather"

examples/python/snippets/get-started/multi_tool_agent/agent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def get_current_time(city: str) -> dict:
7070

7171
root_agent = Agent(
7272
name="weather_time_agent",
73-
model="gemini-2.5-flash",
73+
model="gemini-flash-latest",
7474
description=(
7575
"Agent to answer questions about the time and weather in a city."
7676
),

examples/typescript/snippets/get-started/multi_tool_agent/agent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const getCurrentTime = new FunctionTool({
5050

5151
export const rootAgent = new LlmAgent({
5252
name: 'weather_time_agent',
53-
model: 'gemini-2.5-flash',
53+
model: 'gemini-flash-latest',
5454
description: 'Agent to answer questions about the time and weather in a city.',
5555
instruction: 'You are a helpful agent who can answer user questions about the time and weather in a city.',
5656
tools: [getWeather, getCurrentTime],

0 commit comments

Comments
 (0)