mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-24 20:14:44 -07:00
Steer outer agent to use expert subagents when present (#16763)
This commit is contained in:
committed by
GitHub
parent
4bb817de22
commit
a15978593a
@@ -68,6 +68,10 @@ type AgentTurnResult =
|
||||
finalResult: string | null;
|
||||
};
|
||||
|
||||
export function createUnauthorizedToolError(toolName: string): string {
|
||||
return `Unauthorized tool call: '${toolName}' is not available to this agent.`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes an agent loop based on an {@link AgentDefinition}.
|
||||
*
|
||||
@@ -883,7 +887,7 @@ export class LocalAgentExecutor<TOutput extends z.ZodTypeAny> {
|
||||
|
||||
// Handle standard tools
|
||||
if (!allowedToolNames.has(functionCall.name as string)) {
|
||||
const error = `Unauthorized tool call: '${functionCall.name}' is not available to this agent.`;
|
||||
const error = createUnauthorizedToolError(functionCall.name as string);
|
||||
|
||||
debugLogger.warn(`[LocalAgentExecutor] Blocked call: ${error}`);
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ import {
|
||||
type ModelConfig,
|
||||
ModelConfigService,
|
||||
} from '../services/modelConfigService.js';
|
||||
import { DELEGATE_TO_AGENT_TOOL_NAME } from '../tools/tool-names.js';
|
||||
|
||||
/**
|
||||
* Returns the model config alias for a given agent definition.
|
||||
@@ -434,8 +435,19 @@ export class AgentRegistry {
|
||||
}
|
||||
|
||||
let context = '## Available Sub-Agents\n';
|
||||
context +=
|
||||
'Use `delegate_to_agent` for complex tasks requiring specialized analysis.\n\n';
|
||||
context += `Sub-agents are specialized expert agents that you can use to assist you in
|
||||
the completion of all or part of a task.
|
||||
|
||||
ALWAYS use \`${DELEGATE_TO_AGENT_TOOL_NAME}\` to delegate to a subagent if one
|
||||
exists that has expertise relevant to your task.
|
||||
|
||||
For example:
|
||||
- Prompt: 'Fix test', Description: 'An agent with expertise in fixing tests.' -> should use the sub-agent.
|
||||
- Prompt: 'Update the license header', Description: 'An agent with expertise in licensing and copyright.' -> should use the sub-agent.
|
||||
- Prompt: 'Diagram the architecture of the codebase', Description: 'Agent with architecture experience'. -> should use the sub-agent.
|
||||
- Prompt: 'Implement a fix for [bug]' -> Should decompose the project into subtasks, which may utilize available agents like 'plan', 'validate', and 'fix-tests'.
|
||||
|
||||
The following are the available sub-agents:\n\n`;
|
||||
|
||||
for (const [name, def] of this.agents) {
|
||||
context += `- **${name}**: ${def.description}\n`;
|
||||
|
||||
@@ -127,6 +127,7 @@ export * from './prompts/mcp-prompts.js';
|
||||
// Export agent definitions
|
||||
export * from './agents/types.js';
|
||||
export * from './agents/agentLoader.js';
|
||||
export * from './agents/local-executor.js';
|
||||
|
||||
// Export specific tool logic
|
||||
export * from './tools/read-file.js';
|
||||
|
||||
Reference in New Issue
Block a user