Skip to content

Commit ca75004

Browse files
author
Amaad Martin
committed
Fix: use a plain Record for the built-in tool table
Review feedback: prefer Record<string, BaseTool> over a Map. The lookup goes through Object.hasOwn so a YAML string naming an inherited member such as 'constructor' still falls through to findToolOrThrow instead of resolving to Object.prototype.constructor. Object.hasOwn is already the guard used elsewhere in this package (test_runner.ts).
1 parent a519152 commit ca75004

2 files changed

Lines changed: 21 additions & 5 deletions

File tree

dev/src/integration/agent_registry.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@ import {IntegrationRegistry} from './integration_registry.js';
2828
/**
2929
* Built-in tools that a YAML config can name directly, mirroring adk-python's
3030
* `LlmAgent._resolve_tools`, which resolves a bare built-in name to the real
31-
* tool object.
31+
* tool object. Looked up with `Object.hasOwn` so that a YAML string naming an
32+
* inherited member such as `constructor` does not resolve to one.
3233
*/
33-
const BUILTIN_TOOLS = new Map<string, BaseTool>([['exit_loop', EXIT_LOOP]]);
34+
const BUILTIN_TOOLS: Record<string, BaseTool> = {exit_loop: EXIT_LOOP};
3435

3536
/**
3637
* Server-side built-ins that are dropped instead of resolved: they are executed
@@ -149,9 +150,8 @@ export class AgentRegistry {
149150

150151
const tools = config.tools
151152
?.map((toolConfig) => {
152-
const builtinTool = BUILTIN_TOOLS.get(toolConfig.name);
153-
if (builtinTool) {
154-
return builtinTool;
153+
if (Object.hasOwn(BUILTIN_TOOLS, toolConfig.name)) {
154+
return BUILTIN_TOOLS[toolConfig.name];
155155
}
156156

157157
if (SKIPPED_BUILTIN_TOOLS.includes(toolConfig.name)) {

dev/test/integration/agent_registry_test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,4 +293,20 @@ describe('AgentRegistry', () => {
293293

294294
expect(retrieved.tools.length).toBe(0);
295295
});
296+
297+
it('should not resolve an inherited Object member as a built-in tool', () => {
298+
const config = {
299+
name: 'bad_agent',
300+
model: 'model',
301+
description: 'desc',
302+
instruction: 'inst',
303+
agentClass: 'LlmAgent',
304+
tools: [{name: 'constructor'}],
305+
} as unknown as YamlAgentConfig;
306+
307+
agentRegistry.registerAgentConfig('bad_agent', config);
308+
expect(() => agentRegistry.getAgent('bad_agent')).toThrow(
309+
'Tool constructor not found in registry',
310+
);
311+
});
296312
});

0 commit comments

Comments
 (0)