feat: add sessionMode parameter to send_agent_prompt and currentModeId to activity

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 <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
Mohamed Boudra
2025-10-21 19:56:51 +02:00
co-authored by Claude Happy
parent 6106e5f65f
commit cc3dbb88cb
2 changed files with 25 additions and 5 deletions
@@ -212,13 +212,13 @@ export class AgentManager {
* Send a prompt to an agent * Send a prompt to an agent
* @param agentId - Agent ID * @param agentId - Agent ID
* @param prompt - The prompt text * @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 * @returns Object with didComplete boolean indicating if agent finished within maxWait time
*/ */
async sendPrompt( async sendPrompt(
agentId: string, agentId: string,
prompt: string, prompt: string,
maxWait?: number options?: { maxWait?: number; sessionMode?: string }
): Promise<{ didComplete: boolean; stopReason?: string }> { ): Promise<{ didComplete: boolean; stopReason?: string }> {
const agent = this.agents.get(agentId); const agent = this.agents.get(agentId);
if (!agent) { if (!agent) {
@@ -229,6 +229,11 @@ export class AgentManager {
throw new Error(`Agent ${agentId} is ${agent.status}`); 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"; agent.status = "processing";
this.notifySubscribers(agentId); this.notifySubscribers(agentId);
@@ -270,6 +275,8 @@ export class AgentManager {
); );
}); });
const maxWait = options?.maxWait;
// If no maxWait specified, return immediately // If no maxWait specified, return immediately
if (maxWait === undefined) { if (maxWait === undefined) {
console.log(`[Agent ${agentId}] Prompt sent (non-blocking, use get_agent_status to check completion)`); console.log(`[Agent ${agentId}] Prompt sent (non-blocking, use get_agent_status to check completion)`);
@@ -118,7 +118,7 @@ export async function createAgentMcpServer(
{ {
title: "Send Agent Prompt", title: "Send Agent Prompt",
description: 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: { inputSchema: {
agentId: z.string().describe("Agent ID returned from create_coding_agent"), agentId: z.string().describe("Agent ID returned from create_coding_agent"),
prompt: z prompt: z
@@ -126,6 +126,12 @@ export async function createAgentMcpServer(
.describe( .describe(
"The task, instruction, or feedback to send to the agent. Be specific about what you want the agent to accomplish." "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 maxWait: z
.number() .number()
.optional() .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'"), stopReason: z.string().nullable().describe("Reason agent stopped if it completed: 'end_turn', 'max_tokens', 'max_turn_requests', 'refusal', 'cancelled'"),
}, },
}, },
async ({ agentId, prompt, maxWait }) => { async ({ agentId, prompt, sessionMode, maxWait }) => {
const response = await agentManager.sendPrompt(agentId, prompt, maxWait); const response = await agentManager.sendPrompt(agentId, prompt, {
maxWait,
sessionMode,
});
const result = { const result = {
success: true, success: true,
@@ -330,6 +339,7 @@ export async function createAgentMcpServer(
agentId: z.string(), agentId: z.string(),
format: z.enum(["curated", "raw"]), format: z.enum(["curated", "raw"]),
updateCount: z.number().describe("Total number of updates available"), 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)"), content: z.string().describe("Formatted activity content (if curated) or empty string (if raw)"),
updates: z.array( updates: z.array(
z.object({ z.object({
@@ -342,6 +352,7 @@ export async function createAgentMcpServer(
}, },
async ({ agentId, format = "curated", limit }) => { async ({ agentId, format = "curated", limit }) => {
const updates = agentManager.getAgentUpdates(agentId); const updates = agentManager.getAgentUpdates(agentId);
const currentModeId = agentManager.getCurrentMode(agentId);
if (format === "curated") { if (format === "curated") {
// Return curated, human-readable format // Return curated, human-readable format
@@ -353,6 +364,7 @@ export async function createAgentMcpServer(
agentId, agentId,
format: "curated" as const, format: "curated" as const,
updateCount: updates.length, updateCount: updates.length,
currentModeId,
content: curatedText, content: curatedText,
updates: null, updates: null,
}, },
@@ -369,6 +381,7 @@ export async function createAgentMcpServer(
agentId, agentId,
format: "raw" as const, format: "raw" as const,
updateCount: updates.length, updateCount: updates.length,
currentModeId,
content: "", content: "",
updates: selectedUpdates.map((update) => ({ updates: selectedUpdates.map((update) => ({
timestamp: update.timestamp.toISOString(), timestamp: update.timestamp.toISOString(),