fix(subagent): propagate parent RuntimeContext to child agents#1833
Conversation
DefaultAgentManager.invokeAgent() built a fresh RuntimeContext with only sessionId and userId, discarding all parent context extras (typed attributes, string attributes, ToolExecutionContext, etc.). This caused subagents to lose tenant info, outbound addresses, MCP metadata, and other per-call context set by the parent. Add overloaded invokeAgent/invokeAgentStream methods that accept an optional parent RuntimeContext and use RuntimeContext.builder(parentRc) to preserve extras while overriding session identity. Update all call sites in AgentSpawnTool to forward the parent context. Fixes #1739 Fixes #1731
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
AgentScopeJavaBot
left a comment
There was a problem hiding this comment.
🤖 AI Review
This PR fixes a real and important bug: DefaultAgentManager.invokeAgent() / invokeAgentStream() built a fresh RuntimeContext that discarded all parent context extras (typed attributes, string attributes, ToolExecutionContext, tenant info, etc.), causing child agents to lose critical contextual information. The fix uses RuntimeContext.builder(parentRc) to inherit parent attributes while overriding session identity, and all 6 call sites in AgentSpawnTool are consistently updated. The approach is backward-compatible via delegation from the old signatures. One defensive-programming suggestion: explicitly null out agentState in the child builder to prevent parent state leakage into child agents that don't manage their own state (e.g., HarnessAgent).
AgentScopeJavaBot
left a comment
There was a problem hiding this comment.
🤖 AI Review
This PR fixes a real and important bug: DefaultAgentManager.invokeAgent() / invokeAgentStream() built a fresh RuntimeContext that discarded all parent context extras (typed attributes, string attributes, ToolExecutionContext, tenant info, etc.), causing child agents to lose critical contextual information. The fix uses RuntimeContext.builder(parentRc) to inherit parent attributes while overriding session identity, and all 6 call sites in AgentSpawnTool are consistently updated. The approach is backward-compatible via delegation from the old signatures. One defensive-programming suggestion: explicitly null out agentState in the child builder to prevent parent state leakage into child agents that don't manage their own state (e.g., HarnessAgent).
itxaiohanglover
left a comment
There was a problem hiding this comment.
Clean implementation — the overloaded invokeAgent and invokeAgentStream methods preserve backward compatibility while allowing parent RuntimeContext propagation. The conditional builder pattern (parentRc != null ? RuntimeContext.builder(parentRc) : RuntimeContext.builder()) is the right approach — it doesn't force callers to pass parentRc.
Summary
DefaultAgentManager.invokeAgent()built a freshRuntimeContextwith onlysessionId/userId, discarding all parent context extras (typed attributes, string attributes,ToolExecutionContext, tenant info, outbound addresses, etc.).invokeAgent/invokeAgentStreammethods that accept an optional parentRuntimeContextand useRuntimeContext.builder(parentRc)to preserve extras while overriding session identity.AgentSpawnTool(5 locations) to forward the parent context.Fixes #1739
Fixes #1731