Skip to content

fix: preserve parent RuntimeContext in harness subagent delegation#1756

Open
guslegend0510 wants to merge 8 commits into
agentscope-ai:mainfrom
guslegend0510:fix/issue-1731-runtime-context
Open

fix: preserve parent RuntimeContext in harness subagent delegation#1756
guslegend0510 wants to merge 8 commits into
agentscope-ai:mainfrom
guslegend0510:fix/issue-1731-runtime-context

Conversation

@guslegend0510

Copy link
Copy Markdown

Summary

  • add RuntimeContext.fork() to carry string extras, typed attributes, and ToolExecutionContext into child calls
  • pass the parent RuntimeContext through harness subagent invocation paths
  • add regression tests for invokeAgent and invokeAgentStream

Validation

  • mvn -pl agentscope-harness -am "-Dtest=RuntimeContextTest,DefaultAgentManagerRuntimeContextTest" test

@guslegend0510 guslegend0510 requested a review from a team June 14, 2026 02:39
@codecov

codecov Bot commented Jun 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 82.75862% with 5 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
.../java/io/agentscope/core/agent/RuntimeContext.java 80.00% 1 Missing and 3 partials ⚠️
.../agentscope/harness/agent/tool/AgentSpawnTool.java 50.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@AgentScopeJavaBot AgentScopeJavaBot added bug Something isn't working area/harness agentscope-harness (test/runtime support) labels Jun 14, 2026

@AgentScopeJavaBot AgentScopeJavaBot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 AI Review

This PR adds RuntimeContext.fork() to preserve parent context (string extras, typed attributes, and ToolExecutionContext) when delegating to harness subagents, and threads the parent RuntimeContext through DefaultAgentManager and AgentSpawnTool invocation paths. The design is clean: fork() creates isolated snapshot copies of attribute maps (copy-on-fork semantics), preventing parent-child interference, while sharing the ToolExecutionContext by reference (appropriate for a DI container). The old overloads delegate to new ones with null parentContext, maintaining backwards compatibility. Test coverage is solid, verifying both sync and stream paths with typed attributes, string extras, ToolExecutionContext identity, and agentState isolation. One pre-existing gap worth noting: the plain Agent fallback in invokeAgent/invokeAgentStream still calls agent.call(prompt) without the computed ctx — not introduced by this PR, but now more visible.

@AgentScopeJavaBot AgentScopeJavaBot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 AI Review

This PR adds RuntimeContext.fork() to preserve parent context (string extras, typed attributes, and ToolExecutionContext) when delegating to harness subagents, and threads the parent RuntimeContext through DefaultAgentManager and AgentSpawnTool invocation paths. The design is clean: fork() creates isolated snapshot copies of attribute maps (copy-on-fork semantics), preventing parent-child interference, while sharing the ToolExecutionContext by reference (appropriate for a DI container). The old overloads delegate to new ones with null parentContext, maintaining backwards compatibility. Test coverage is solid, verifying both sync and stream paths with typed attributes, string extras, ToolExecutionContext identity, and agentState isolation. One pre-existing gap worth noting: the plain Agent fallback in invokeAgent/invokeAgentStream still calls agent.call(prompt) without the computed ctx — not introduced by this PR, but now more visible.

@iuin8

iuin8 commented Jun 15, 2026

Copy link
Copy Markdown

We're building an enterprise agent-governance platform on AgentScope-Java RC3, and this PR fixes a blocker for us: harness subagent delegation drops the parent RuntimeContext, so our typed governance identity (tenant + granted capabilities) never reaches spawned subagents — the whole permission/audit arc silently no-ops at the subagent layer.

We reviewed the patch against RC3 and it looks complete on the delegation surface: RuntimeContext.fork(sessionId, userId) deep-copies string + typed attributes and shares ToolExecutionContext, and parentCtx is now threaded into all AgentSpawnTool call sites (spawn/send + the three execLocalSync paths + execSpawnTask). 👍

Two notes that might help it land:

Looking forward to seeing this in a release.

@guslegend0510

Copy link
Copy Markdown
Author

@chickenlj 回复你了,麻烦看一下,谢谢您

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/harness agentscope-harness (test/runtime support) bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants