From cc3dbb88cb1a2bbf12378de49afb9aaf9f986813 Mon Sep 17 00:00:00 2001 From: Mohamed Boudra Date: Tue, 21 Oct 2025 19:56:51 +0200 Subject: [PATCH] feat: add sessionMode parameter to send_agent_prompt and currentModeId to activity MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Allow setting session mode when sending prompts, and include current mode in activity output. Changes: - sendPrompt now accepts options object with maxWait and sessionMode - If sessionMode specified, sets mode before sending prompt - send_agent_prompt MCP tool exposes sessionMode parameter - get_agent_activity now returns currentModeId in output - Enables workflow: send_agent_prompt({ sessionMode: "plan", prompt: "..." }) 🤖 Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude Co-Authored-By: Happy --- .../src/server/acp/agent-manager.ts | 11 +++++++++-- .../src/server/acp/mcp-server.ts | 19 ++++++++++++++++--- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/packages/voice-assistant/src/server/acp/agent-manager.ts b/packages/voice-assistant/src/server/acp/agent-manager.ts index 89554c565..5b3d07464 100644 --- a/packages/voice-assistant/src/server/acp/agent-manager.ts +++ b/packages/voice-assistant/src/server/acp/agent-manager.ts @@ -212,13 +212,13 @@ export class AgentManager { * Send a prompt to an agent * @param agentId - Agent ID * @param prompt - The prompt text - * @param maxWait - Optional max milliseconds to wait for completion. If not provided, returns immediately without waiting. + * @param options - Optional settings: maxWait (ms), sessionMode to set before sending * @returns Object with didComplete boolean indicating if agent finished within maxWait time */ async sendPrompt( agentId: string, prompt: string, - maxWait?: number + options?: { maxWait?: number; sessionMode?: string } ): Promise<{ didComplete: boolean; stopReason?: string }> { const agent = this.agents.get(agentId); if (!agent) { @@ -229,6 +229,11 @@ export class AgentManager { throw new Error(`Agent ${agentId} is ${agent.status}`); } + // Set session mode if specified + if (options?.sessionMode) { + await this.setSessionMode(agentId, options.sessionMode); + } + agent.status = "processing"; this.notifySubscribers(agentId); @@ -270,6 +275,8 @@ export class AgentManager { ); }); + const maxWait = options?.maxWait; + // If no maxWait specified, return immediately if (maxWait === undefined) { console.log(`[Agent ${agentId}] Prompt sent (non-blocking, use get_agent_status to check completion)`); diff --git a/packages/voice-assistant/src/server/acp/mcp-server.ts b/packages/voice-assistant/src/server/acp/mcp-server.ts index 195a2e76c..f661b29bf 100644 --- a/packages/voice-assistant/src/server/acp/mcp-server.ts +++ b/packages/voice-assistant/src/server/acp/mcp-server.ts @@ -118,7 +118,7 @@ export async function createAgentMcpServer( { title: "Send Agent Prompt", description: - "Sends a task or prompt to an existing agent. By default, returns immediately without waiting (non-blocking). The agent will process the prompt in the background. Use get_agent_status or get_agent_activity to check progress. Optionally, you can specify maxWait to wait up to that many milliseconds for completion before returning.", + "Sends a task or prompt to an existing agent. By default, returns immediately without waiting (non-blocking). The agent will process the prompt in the background. Use get_agent_status or get_agent_activity to check progress. Optionally specify maxWait to wait for completion, or sessionMode to switch modes before sending.", inputSchema: { agentId: z.string().describe("Agent ID returned from create_coding_agent"), prompt: z @@ -126,6 +126,12 @@ export async function createAgentMcpServer( .describe( "The task, instruction, or feedback to send to the agent. Be specific about what you want the agent to accomplish." ), + sessionMode: z + .string() + .optional() + .describe( + "Optional: Session mode to set before sending the prompt (e.g., 'plan', 'code', 'default'). If specified, the agent's mode will be changed before processing the prompt." + ), maxWait: z .number() .optional() @@ -139,8 +145,11 @@ export async function createAgentMcpServer( stopReason: z.string().nullable().describe("Reason agent stopped if it completed: 'end_turn', 'max_tokens', 'max_turn_requests', 'refusal', 'cancelled'"), }, }, - async ({ agentId, prompt, maxWait }) => { - const response = await agentManager.sendPrompt(agentId, prompt, maxWait); + async ({ agentId, prompt, sessionMode, maxWait }) => { + const response = await agentManager.sendPrompt(agentId, prompt, { + maxWait, + sessionMode, + }); const result = { success: true, @@ -330,6 +339,7 @@ export async function createAgentMcpServer( agentId: z.string(), format: z.enum(["curated", "raw"]), updateCount: z.number().describe("Total number of updates available"), + currentModeId: z.string().nullable().describe("Current session mode of the agent"), content: z.string().describe("Formatted activity content (if curated) or empty string (if raw)"), updates: z.array( z.object({ @@ -342,6 +352,7 @@ export async function createAgentMcpServer( }, async ({ agentId, format = "curated", limit }) => { const updates = agentManager.getAgentUpdates(agentId); + const currentModeId = agentManager.getCurrentMode(agentId); if (format === "curated") { // Return curated, human-readable format @@ -353,6 +364,7 @@ export async function createAgentMcpServer( agentId, format: "curated" as const, updateCount: updates.length, + currentModeId, content: curatedText, updates: null, }, @@ -369,6 +381,7 @@ export async function createAgentMcpServer( agentId, format: "raw" as const, updateCount: updates.length, + currentModeId, content: "", updates: selectedUpdates.map((update) => ({ timestamp: update.timestamp.toISOString(),