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
14 changes: 13 additions & 1 deletion apps/server/src/server/mcp-handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,18 @@ const AGENT_LATEST_EVENT_TYPES = [
const CODEX_FULL_ACCESS_ARG = "--dangerously-bypass-approvals-and-sandbox";
const CLAUDE_FULL_ACCESS_ARG = "--dangerously-skip-permissions";

function buildChildAgentInitialPrompt(
parentAgentId: string,
prompt: string
): string {
return [
`You were launched by Dispatch agent "${parentAgentId}" via dispatch_launch_agent.`,
"Use that parent agent ID when coordinating back with dispatch_send_message.",
"",
prompt,
].join("\n");
}

type AgentLatestEventType = (typeof AGENT_LATEST_EVENT_TYPES)[number];

type PublishUiEvent = (event: unknown) => void;
Expand Down Expand Up @@ -727,7 +739,7 @@ export function createMcpHandlers(deps: CreateMcpHandlersDeps) {
worktreeBranch: input.worktreeBranch,
parentAgentId: agentId,
cliSessionId,
initialPrompt: input.prompt,
initialPrompt: buildChildAgentInitialPrompt(agentId, input.prompt),
templateId: input.templateId,
});

Expand Down
24 changes: 24 additions & 0 deletions apps/server/test/mcp-handlers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -983,6 +983,30 @@ describe("createMcpHandlers", () => {
});
});

describe("launchAgent", () => {
it("includes the launching agent id in the child initial prompt", async () => {
await handlers.launchAgent("agt_test1", {
name: "worker",
prompt: "Investigate the flaky test.",
});

expect(deps.agentManager.createAgent).toHaveBeenCalledWith(
expect.objectContaining({
name: "worker",
parentAgentId: "agt_test1",
initialPrompt: expect.stringContaining(
'You were launched by Dispatch agent "agt_test1"'
),
})
);
expect(deps.agentManager.createAgent).toHaveBeenCalledWith(
expect.objectContaining({
initialPrompt: expect.stringContaining("Investigate the flaky test."),
})
);
});
});

describe("sendMessage", () => {
it("delivers message to matching running agent", async () => {
const target = {
Expand Down