Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/core/src/agents/agent-scheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import type { EditorType } from '../utils/editor.js';
export interface AgentSchedulingOptions {
/** The unique ID for this agent's scheduler. */
schedulerId: string;
/** The name of the subagent. */
subagent?: string;
/** The ID of the tool call that invoked this agent. */
parentCallId?: string;
/** The tool registry specific to this agent. */
Expand Down Expand Up @@ -46,6 +48,7 @@ export async function scheduleAgentTools(
): Promise<CompletedToolCall[]> {
const {
schedulerId,
subagent,
parentCallId,
toolRegistry,
signal,
Expand All @@ -69,6 +72,7 @@ export async function scheduleAgentTools(
messageBus: toolRegistry.getMessageBus(),
getPreferredEditor: getPreferredEditor ?? (() => undefined),
schedulerId,
subagent,
parentCallId,
onWaitingForConfirmation,
});
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/agents/local-executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1099,6 +1099,7 @@ export class LocalAgentExecutor<TOutput extends z.ZodTypeAny> {
toolRequests,
{
schedulerId: this.agentId,
subagent: this.definition.name,
parentCallId: this.parentCallId,
toolRegistry: this.toolRegistry,
signal,
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/scheduler/policy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ describe('policy.ts', () => {
{ name: 'test-tool', args: {} },
undefined,
undefined,
undefined,
);
});

Expand Down Expand Up @@ -97,6 +98,7 @@ describe('policy.ts', () => {
{ name: 'mcp-tool', args: {} },
'my-server',
{ readOnlyHint: true },
undefined,
);
});

Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/scheduler/policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export function getPolicyDenialError(
export async function checkPolicy(
toolCall: ValidatingToolCall,
config: Config,
subagent?: string,
): Promise<CheckResult> {
const serverName =
toolCall.tool instanceof DiscoveredMCPTool
Expand All @@ -66,6 +67,7 @@ export async function checkPolicy(
{ name: toolCall.request.name, args: toolCall.request.args },
serverName,
toolAnnotations,
subagent,
);

const { decision } = result;
Expand Down Expand Up @@ -115,6 +117,7 @@ export async function updatePolicy(
toolInvocation?: AnyToolInvocation,
): Promise<void> {
const deps = { ...context, toolInvocation };

// Mode Transitions (AUTO_EDIT)
if (isAutoEditTransition(tool, outcome)) {
deps.config.setApprovalMode(ApprovalMode.AUTO_EDIT);
Expand Down
26 changes: 26 additions & 0 deletions packages/core/src/scheduler/scheduler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,32 @@ describe('Scheduler (Orchestrator)', () => {
);
});

it('should propagate subagent name to checkPolicy', async () => {
const { checkPolicy } = await import('./policy.js');
const scheduler = new Scheduler({
context: mockConfig,
schedulerId: 'sub-scheduler',
subagent: 'my-agent',
getPreferredEditor: () => undefined,
});

const request: ToolCallRequestInfo = {
callId: 'call-1',
name: 'test-tool',
args: {},
isClientInitiated: false,
prompt_id: 'p1',
};

await scheduler.schedule([request], new AbortController().signal);

expect(checkPolicy).toHaveBeenCalledWith(
expect.anything(),
expect.anything(),
'my-agent',
);
});

it('should correctly build ValidatingToolCalls for happy path', async () => {
await scheduler.schedule(req1, signal);

Expand Down
9 changes: 8 additions & 1 deletion packages/core/src/scheduler/scheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export interface SchedulerOptions {
messageBus?: MessageBus;
getPreferredEditor: () => EditorType | undefined;
schedulerId: string;
subagent?: string;
parentCallId?: string;
onWaitingForConfirmation?: (waiting: boolean) => void;
}
Expand Down Expand Up @@ -102,6 +103,7 @@ export class Scheduler {
private readonly messageBus: MessageBus;
private readonly getPreferredEditor: () => EditorType | undefined;
private readonly schedulerId: string;
private readonly subagent?: string;
private readonly parentCallId?: string;
private readonly onWaitingForConfirmation?: (waiting: boolean) => void;

Expand All @@ -115,6 +117,7 @@ export class Scheduler {
this.messageBus = options.messageBus ?? this.context.messageBus;
this.getPreferredEditor = options.getPreferredEditor;
this.schedulerId = options.schedulerId;
this.subagent = options.subagent;
this.parentCallId = options.parentCallId;
this.onWaitingForConfirmation = options.onWaitingForConfirmation;
this.state = new SchedulerStateManager(
Expand Down Expand Up @@ -563,7 +566,11 @@ export class Scheduler {
const callId = toolCall.request.callId;

// Policy & Security
const { decision, rule } = await checkPolicy(toolCall, this.config);
const { decision, rule } = await checkPolicy(
toolCall,
this.config,
this.subagent,
);

if (decision === PolicyDecision.DENY) {
const { errorMessage, errorType } = getPolicyDenialError(
Expand Down
Loading