mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-28 05:55:17 -07:00
feat: add explicit policy override for subagents
This commit is contained in:
@@ -31,6 +31,7 @@ describe('agent-scheduler', () => {
|
|||||||
mockConfig = {
|
mockConfig = {
|
||||||
getMessageBus: vi.fn().mockReturnValue(mockMessageBus),
|
getMessageBus: vi.fn().mockReturnValue(mockMessageBus),
|
||||||
getToolRegistry: vi.fn().mockReturnValue(mockToolRegistry),
|
getToolRegistry: vi.fn().mockReturnValue(mockToolRegistry),
|
||||||
|
getAgentsSettings: vi.fn().mockReturnValue({}),
|
||||||
} as unknown as Mocked<Config>;
|
} as unknown as Mocked<Config>;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -47,6 +48,7 @@ describe('agent-scheduler', () => {
|
|||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
schedulerId: 'subagent-1',
|
schedulerId: 'subagent-1',
|
||||||
|
agentName: 'mock-agent',
|
||||||
parentCallId: 'parent-1',
|
parentCallId: 'parent-1',
|
||||||
toolRegistry: mockToolRegistry as unknown as ToolRegistry,
|
toolRegistry: mockToolRegistry as unknown as ToolRegistry,
|
||||||
signal: new AbortController().signal,
|
signal: new AbortController().signal,
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import type {
|
|||||||
} from '../scheduler/types.js';
|
} from '../scheduler/types.js';
|
||||||
import type { ToolRegistry } from '../tools/tool-registry.js';
|
import type { ToolRegistry } from '../tools/tool-registry.js';
|
||||||
import type { EditorType } from '../utils/editor.js';
|
import type { EditorType } from '../utils/editor.js';
|
||||||
|
import { ApprovalMode } from '../policy/types.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Options for scheduling agent tools.
|
* Options for scheduling agent tools.
|
||||||
@@ -19,6 +20,8 @@ import type { EditorType } from '../utils/editor.js';
|
|||||||
export interface AgentSchedulingOptions {
|
export interface AgentSchedulingOptions {
|
||||||
/** The unique ID for this agent's scheduler. */
|
/** The unique ID for this agent's scheduler. */
|
||||||
schedulerId: string;
|
schedulerId: string;
|
||||||
|
/** The name of the agent executing the tools. */
|
||||||
|
agentName: string;
|
||||||
/** The ID of the tool call that invoked this agent. */
|
/** The ID of the tool call that invoked this agent. */
|
||||||
parentCallId?: string;
|
parentCallId?: string;
|
||||||
/** The tool registry specific to this agent. */
|
/** The tool registry specific to this agent. */
|
||||||
@@ -46,6 +49,7 @@ export async function scheduleAgentTools(
|
|||||||
): Promise<CompletedToolCall[]> {
|
): Promise<CompletedToolCall[]> {
|
||||||
const {
|
const {
|
||||||
schedulerId,
|
schedulerId,
|
||||||
|
agentName,
|
||||||
parentCallId,
|
parentCallId,
|
||||||
toolRegistry,
|
toolRegistry,
|
||||||
signal,
|
signal,
|
||||||
@@ -57,6 +61,16 @@ export async function scheduleAgentTools(
|
|||||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||||
const agentConfig: Config = Object.create(config);
|
const agentConfig: Config = Object.create(config);
|
||||||
agentConfig.getToolRegistry = () => toolRegistry;
|
agentConfig.getToolRegistry = () => toolRegistry;
|
||||||
|
|
||||||
|
// Apply any subagent-specific approval mode override, fallback to the main config mode.
|
||||||
|
const override = config.getAgentsSettings()?.overrides?.[agentName];
|
||||||
|
if (override?.approvalMode) {
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
||||||
|
agentConfig.getApprovalMode = () => override.approvalMode as ApprovalMode;
|
||||||
|
} else {
|
||||||
|
// Subagents operate in YOLO mode by default, unless overridden.
|
||||||
|
agentConfig.getApprovalMode = () => ApprovalMode.YOLO;
|
||||||
|
}
|
||||||
|
|
||||||
const scheduler = new Scheduler({
|
const scheduler = new Scheduler({
|
||||||
config: agentConfig,
|
config: agentConfig,
|
||||||
|
|||||||
@@ -1073,6 +1073,7 @@ export class LocalAgentExecutor<TOutput extends z.ZodTypeAny> {
|
|||||||
toolRequests,
|
toolRequests,
|
||||||
{
|
{
|
||||||
schedulerId: this.agentId,
|
schedulerId: this.agentId,
|
||||||
|
agentName: this.definition.name,
|
||||||
parentCallId: this.parentCallId,
|
parentCallId: this.parentCallId,
|
||||||
toolRegistry: this.toolRegistry,
|
toolRegistry: this.toolRegistry,
|
||||||
signal,
|
signal,
|
||||||
|
|||||||
@@ -234,6 +234,7 @@ export interface AgentOverride {
|
|||||||
modelConfig?: ModelConfig;
|
modelConfig?: ModelConfig;
|
||||||
runConfig?: AgentRunConfig;
|
runConfig?: AgentRunConfig;
|
||||||
enabled?: boolean;
|
enabled?: boolean;
|
||||||
|
approvalMode?: ApprovalMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AgentSettings {
|
export interface AgentSettings {
|
||||||
|
|||||||
@@ -254,6 +254,7 @@ export class GeminiCliSession {
|
|||||||
toolCallsToSchedule,
|
toolCallsToSchedule,
|
||||||
{
|
{
|
||||||
schedulerId: sessionId,
|
schedulerId: sessionId,
|
||||||
|
agentName: 'sdk-agent',
|
||||||
toolRegistry: scopedRegistry,
|
toolRegistry: scopedRegistry,
|
||||||
signal: abortSignal,
|
signal: abortSignal,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -2225,6 +2225,11 @@
|
|||||||
"enabled": {
|
"enabled": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"description": "Whether to enable the agent."
|
"description": "Whether to enable the agent."
|
||||||
|
},
|
||||||
|
"approvalMode": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "Approval mode for this subagent's internal tool calls.",
|
||||||
|
"enum": ["default", "yolo", "plan", "autoEdit"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user