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
parent 6106e5f65f
commit cc3dbb88cb
2 changed files with 25 additions and 5 deletions

View File

@@ -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)`);

View File

@@ -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(),