Skip to content

Commit 0099e5f

Browse files
Jacksunweicopybara-github
authored andcommitted
fix(tool): Fixes ExitLoopTool by adding Schema and description
- The description now matches the prompt in python. - Also add it to ComponentRegistry for use in ADK Config. PiperOrigin-RevId: 795350942
1 parent f4f8309 commit 0099e5f

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

core/src/main/java/com/google/adk/tools/ExitLoopTool.java

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,32 @@
1616

1717
package com.google.adk.tools;
1818

19-
/** Exits the loop. */
19+
import com.google.adk.tools.Annotations.Schema;
20+
21+
/** Tool for exiting execution of {@link com.google.adk.agents.LoopAgent}. */
2022
public final class ExitLoopTool {
23+
public static final FunctionTool INSTANCE = FunctionTool.create(ExitLoopTool.class, "exitLoop");
24+
25+
/**
26+
* Exit the {@link com.google.adk.agents.LoopAgent} execution.
27+
*
28+
* <p>Usage example in an LlmAgent:
29+
*
30+
* <pre>{@code
31+
* LlmAgent subAgent = LlmAgent.builder()
32+
* .addTool(ExitLoopTool.INSTANCE)
33+
* .build();
34+
* }</pre>
35+
*
36+
* <p>The @Schema name and description is consistent with the Python version.
37+
*
38+
* <p>Refer to:
39+
* https://github.com/google/adk-python/blob/main/src/google/adk/tools/exit_loop_tool.py
40+
*/
41+
@Schema(
42+
name = "exit_loop",
43+
description = "Exits the loop.\n\nCall this function only when you are instructed to do so.")
2144
public static void exitLoop(ToolContext toolContext) {
22-
// Exits the loop.
23-
// Call this function only when you are instructed to do so.
2445
toolContext.setActions(toolContext.actions().toBuilder().escalate(true).build());
2546
}
2647

core/src/main/java/com/google/adk/utils/ComponentRegistry.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.google.adk.agents.SequentialAgent;
2626
import com.google.adk.tools.AgentTool;
2727
import com.google.adk.tools.BaseTool;
28+
import com.google.adk.tools.ExitLoopTool;
2829
import com.google.adk.tools.GoogleSearchTool;
2930
import com.google.adk.tools.LoadArtifactsTool;
3031
import java.util.Map;
@@ -97,6 +98,7 @@ private void initializePreWiredEntries() {
9798

9899
registerAdkToolInstance("google_search", new GoogleSearchTool());
99100
registerAdkToolInstance("load_artifacts", new LoadArtifactsTool());
101+
registerAdkToolInstance("exit_loop", ExitLoopTool.INSTANCE);
100102

101103
registerAdkToolClass(AgentTool.class);
102104
// TODO: add all python tools that also exist in Java.

0 commit comments

Comments
 (0)