-
Notifications
You must be signed in to change notification settings - Fork 184
Fix: resolve the exit_loop built-in tool in YAML agent configs #572
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
AmaadMartin
wants to merge
4
commits into
google:main
Choose a base branch
from
AmaadMartin:fix/conformance-exit-loop-builtin-tool
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
c676490
Fix: resolve the exit_loop built-in tool in YAML agent configs
a73f149
Fix: replay the exit_loop side effects in ReplayPlugin
a519152
Fix: un-skip the workflow/loop_001 conformance test
ca75004
Fix: use a plain Record for the built-in tool table
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| /** | ||
| * @license | ||
| * Copyright 2026 Google LLC | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| import { | ||
| Context, | ||
| createEventActions, | ||
| EventActions, | ||
| EXIT_LOOP, | ||
| FunctionTool, | ||
| } from '@google/adk'; | ||
| import {beforeEach, describe, expect, it} from 'vitest'; | ||
| import {ReplayPlugin} from '../../src/integration/replay_plugin.js'; | ||
| import {Recording} from '../../src/integration/test_types.js'; | ||
|
|
||
| const AGENT_NAME = 'refiner_agent'; | ||
|
|
||
| const TRANSFER_TO_AGENT = new FunctionTool({ | ||
| name: 'transfer_to_agent', | ||
| description: 'Transfers to another agent.', | ||
| execute: async () => ({}), | ||
| }); | ||
|
|
||
| const GREET = new FunctionTool({ | ||
| name: 'greet', | ||
| description: 'Greets the user.', | ||
| execute: async () => ({}), | ||
| }); | ||
|
|
||
| function toolRecording( | ||
| name: string, | ||
| response: Record<string, unknown>, | ||
| ): Recording { | ||
| return { | ||
| userMessageIndex: 0, | ||
| agentName: AGENT_NAME, | ||
| toolRecording: {toolCall: {name}, toolResponse: {response}}, | ||
| }; | ||
| } | ||
|
|
||
| describe('ReplayPlugin', () => { | ||
| let actions: EventActions; | ||
| let toolContext: Context; | ||
|
|
||
| beforeEach(() => { | ||
| actions = createEventActions(); | ||
| toolContext = { | ||
| actions, | ||
| invocationContext: {agent: {name: AGENT_NAME}}, | ||
| } as unknown as Context; | ||
| }); | ||
|
|
||
| it('replays the recorded response and escalates for exit_loop', async () => { | ||
| const plugin = new ReplayPlugin( | ||
| [toolRecording('exit_loop', {result: null})], | ||
| { | ||
| userMessageIndex: 0, | ||
| }, | ||
| ); | ||
|
|
||
| const response = await plugin.beforeToolCallback({ | ||
| tool: EXIT_LOOP, | ||
| toolArgs: {}, | ||
| toolContext, | ||
| }); | ||
|
|
||
| expect(response).toEqual({result: null}); | ||
| expect(actions.escalate).toBe(true); | ||
| expect(actions.skipSummarization).toBe(true); | ||
| }); | ||
|
|
||
| it('replays transfer_to_agent by setting transferToAgent', async () => { | ||
| const plugin = new ReplayPlugin( | ||
| [toolRecording('transfer_to_agent', {result: null})], | ||
| {userMessageIndex: 0}, | ||
| ); | ||
|
|
||
| await plugin.beforeToolCallback({ | ||
| tool: TRANSFER_TO_AGENT, | ||
| toolArgs: {agentName: 'writer_agent'}, | ||
| toolContext, | ||
| }); | ||
|
|
||
| expect(actions.transferToAgent).toBe('writer_agent'); | ||
| expect(actions.escalate).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('replays a plain tool without touching the actions', async () => { | ||
| const plugin = new ReplayPlugin( | ||
| [toolRecording('greet', {greeting: 'hi'})], | ||
| { | ||
| userMessageIndex: 0, | ||
| }, | ||
| ); | ||
|
|
||
| const response = await plugin.beforeToolCallback({ | ||
| tool: GREET, | ||
| toolArgs: {}, | ||
| toolContext, | ||
| }); | ||
|
|
||
| expect(response).toEqual({greeting: 'hi'}); | ||
| expect(actions).toEqual(createEventActions()); | ||
| }); | ||
|
|
||
| it('throws when no recording matches the tool call', async () => { | ||
| const plugin = new ReplayPlugin([], {userMessageIndex: 0}); | ||
|
|
||
| await expect( | ||
| plugin.beforeToolCallback({tool: GREET, toolArgs: {}, toolContext}), | ||
| ).rejects.toThrow( | ||
| `No tool recording found for agent ${AGENT_NAME}, tool greet at turn 0`, | ||
| ); | ||
| }); | ||
|
|
||
| it('consumes each recording only once', async () => { | ||
| const plugin = new ReplayPlugin( | ||
| [toolRecording('greet', {greeting: 'hi'})], | ||
| { | ||
| userMessageIndex: 0, | ||
| }, | ||
| ); | ||
| const call = () => | ||
| plugin.beforeToolCallback({tool: GREET, toolArgs: {}, toolContext}); | ||
|
|
||
| await call(); | ||
|
|
||
| await expect(call()).rejects.toThrow( | ||
| `No tool recording found for agent ${AGENT_NAME}, tool greet at turn 0`, | ||
| ); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can it be a plain Record instead of the map? (
Record<string, BaseTool>)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, switched to a plain
Recordin ca75004 (dev/src/integration/agent_registry.ts:34):One deviation worth flagging so you can object: the lookup key comes straight from user YAML, so I read it through
Object.hasOwn(agent_registry.ts:153) rather than a bareif (BUILTIN_TOOLS[toolConfig.name]). With a bare index,tools: [{name: constructor}]resolves toObject.prototype.constructorand gets handed toLlmAgentas a "tool" instead of falling through tofindToolOrThrow. TheMapdid not have that hazard, so the guard is just paying for the shape change.Object.hasOwnis already the idiom used elsewhere in this package (dev/src/integration/test_runner.ts:170).Added a regression test for it,
should not resolve an inherited Object member as a built-in tool(dev/test/integration/agent_registry_test.ts:297), and confirmed it fails without the guard (the config instantiates withObjectas a tool and no error is thrown).Happy to drop the guard and index directly if you would rather keep the lookup bare.