agentscope-java icon indicating copy to clipboard operation
agentscope-java copied to clipboard

[Feature]: subagent-inherit-parent-context

Open nonking opened this issue 5 months ago • 3 comments

fix(harness): inherit parent business context into spawned subagents

Problem: When a subagent is spawned, DefaultAgentManager.invokeAgent / invokeAgentStream build a fresh RuntimeContext carrying only (sessionId, userId). The parent's custom typed/string attributes — request-scoped business POJOs injected via RuntimeContext.put(Class, …) — are dropped. Tools relying on framework auto-injection of those POJOs (non-@ToolParam params resolved by ToolMethodInvoker → RuntimeContext.get(Class)) therefore receive null inside a spawned subagent, though they work on the main agent. Only userId is propagated today.

Fix: invokeAgent/invokeAgentStream gain an overload taking an optional parentRc; the child RC is built via RuntimeContext.builder().from(parentRc) then overlaid with the child's own sessionId/userId. AgentState is rebound per-call in beforeAgentExecution, so carrying the parent's reference is harmless. AgentSpawnTool forwards the parent RC on both sync (execLocalSync) and async (task) paths. Old signatures preserved (parentRc = null) → backward compatible.

nonking avatar Jun 25 '26 09:06 nonking

我看这次提交是不是修复的这个问题#1833

hansiweicn-debug avatar Jun 25 '26 10:06 hansiweicn-debug

提交错了,我重新提交一下

nonking avatar Jun 25 '26 10:06 nonking

是https://github.com/agentscope-ai/agentscope-java/pull/1833这个问题,我自己在本地修改了,是提交pr还是您这边改一下然后发包

nonking avatar Jun 26 '26 03:06 nonking