fix(harness): stamp taskId on remote subagent forwarded events - #2575
Merged
Conversation
Source alone cannot distinguish two same-turn remote calls to the same agent; attach metadata.taskId so consumers can correlate events to the harness TaskRecord / Agent Protocol task.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves traceability for remote subagent event forwarding in the harness by ensuring forwarded AgentEvents carry a stable metadata.taskId (in addition to source). This allows multiple same-turn invocations of the same remote agent (same source path) to still be correlated back to distinct harness task executions.
Changes:
- Add
AgentEvent.METADATA_TASK_IDand a merge-safeAgentEvent.withMetadataEntry(...)helper for updating metadata without clobbering existing entries. - Stamp forwarded remote events with both
sourceandmetadata.taskIdviaAgentSpawnTool.tagRemoteForwardedEvent(...). - Ensure
RemoteEventCodec.toAgentEvent(...)copies wiretaskIdintometadata.taskId, and update docs + tests accordingly.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| docs/v2/zh/docs/harness/subagent.md | Documents metadata.taskId on forwarded remote subagent events for correlation. |
| docs/v2/zh/docs/building-blocks/message-and-event.md | Adds getMetadata() documentation and notes remote forwarding sets taskId. |
| docs/v2/en/docs/harness/subagent.md | Documents metadata.taskId on forwarded remote subagent events for correlation. |
| docs/v2/en/docs/building-blocks/message-and-event.md | Adds getMetadata() documentation and notes remote forwarding sets taskId. |
| agentscope-harness/src/test/java/io/agentscope/harness/agent/tool/AgentSpawnToolRemoteHelpersTest.java | Tests that remote-forwarded events preserve metadata while setting source + metadata.taskId. |
| agentscope-harness/src/test/java/io/agentscope/harness/agent/subagent/protocol/RemoteEventCodecTest.java | Tests that wire taskId is copied into AgentEvent metadata. |
| agentscope-harness/src/main/java/io/agentscope/harness/agent/tool/AgentSpawnTool.java | Implements tagging of forwarded remote events with source and metadata.taskId. |
| agentscope-harness/src/main/java/io/agentscope/harness/agent/subagent/protocol/RemoteEventCodec.java | Copies wire taskId onto AgentEvent.METADATA_TASK_ID during DTO→event mapping. |
| agentscope-core/src/main/java/io/agentscope/core/event/AgentEvent.java | Introduces the well-known metadata key and a merge-safe per-entry metadata updater. |
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
streamEventsforwarding now setsAgentEvent.metadata.taskId(AgentEvent.METADATA_TASK_ID) alongsidesource, so two same-turn calls to the same remote subagent remain correlatable to distinctTaskRecordsRemoteEventCodec.toAgentEventcopies wiretaskIdinto that metadata key;AgentEvent.withMetadataEntrysupports merge-safe updatesTest plan
mvn -pl agentscope-core,agentscope-harness -am test -Dtest=AgentSpawnToolRemoteHelpersTest,RemoteEventCodecTest[SRE_DEMO_MAIN_EVENT] ... taskId=is non-null and distinct per spawnsourceremainsparentSession/agentId(identity), whiletaskIdidentifies the task run