feat: auto-inject parentAgentId in MCP create_agent tool
When an agent calls the MCP create_agent tool to spawn a child agent, the parent-child relationship is now automatically established: - Added setManagedAgentId() to AgentSession interface (optional method) - ClaudeAgentSession stores its managed agent ID and includes it as X-Caller-Agent-Id header when connecting to the agent-control MCP - AgentManager.registerSession() calls setManagedAgentId() after registration so the session knows its ID before first prompt - MCP server extracts X-Caller-Agent-Id header from init request and stores it as callerAgentId - create_agent handler auto-injects callerAgentId as parentAgentId if not explicitly provided This enables parent agents to spawn child agents that are correctly associated, so they appear in the parent's Sub-Agents menu instead of on the homepage. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.5
parent
99338d3b34
commit
b2850aea23
@@ -706,6 +706,9 @@ export class AgentManager {
|
||||
throw new Error(`Agent with id ${agentId} already exists`);
|
||||
}
|
||||
|
||||
// Inform the session of its managed agent ID for MCP parent-child relationships
|
||||
session.setManagedAgentId?.(agentId);
|
||||
|
||||
const managed = {
|
||||
id: agentId,
|
||||
provider: config.provider,
|
||||
|
||||
Reference in New Issue
Block a user