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
9 changes: 0 additions & 9 deletions packages/agent-core-v2/src/agent/tools/agent/agentTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,15 +344,6 @@ export class SubagentTool implements ISubagentTool {
});
}

const runInBackground = args.run_in_background === true;
emitAgentRunSpawned(requester, agentId, {
profileName,
parentToolCallId: toolCallId,
description: args.description,
runInBackground,
model: displayModel,
});

const target = this.lifecycle.findAgentHandle(agentId);
if (target === undefined) throw new Error(`Agent "${agentId}" does not exist`);
const run = await this.subagents.run(
Expand Down
23 changes: 23 additions & 0 deletions packages/agent-core-v2/test/tool/tool.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1335,6 +1335,29 @@ describe('Agent tool execution contract', () => {
expect(result.output).toContain('child result');
});

it('emits subagent.spawned exactly once, after task registration, carrying the task id', async () => {
const lifecycle = createAgentLifecycleStub({
createAgentIds: ['agent-child'],
runCompletion: async () => ({ summary: 'child result' }),
});
const context = createAgentToolContext(lifecycle);

await executeAgentTool(context, {
prompt: 'Investigate',
description: 'Find cause',
subagent_type: 'explore',
});

const spawned = lifecycle.publishedEvents.filter(
(event) => event.type === 'subagent.spawned',
);
expect(spawned).toHaveLength(1);
expect(spawned[0]).toMatchObject({
subagentId: 'agent-child',
taskId: expect.any(String),
});
});

it('spawns the subagent on the pool default model when the tool call omits model', async () => {
const lifecycle = createAgentLifecycleStub({ createAgentIds: ['agent-child'] });
const context = createAgentToolContext(lifecycle, secondaryModelFlags(), {
Expand Down
Loading