Repository navigation
feat(agent): logical agentId - #2395
rudy2steiner wants to merge 8 commits into
Conversation
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
|
看描述和实现 |
yes |
|
AgentSkillRepository有考虑增加一个agentId回调? |
|
@chickenlj could you review this PR when you have time ? Thanks a lot! |
oss-maintainer
left a comment
There was a problem hiding this comment.
Summary
Introduces a logical agentId concept separate from the runtime UUID id. Clean separation of concerns across 22 files.
Analysis
Design is sound:
id= runtime UUID (unique per Java object instance)agentId= stable logical identity (user-provided, for routing/telemetry/state)name= display name (human-readable, for messages/logs)
Backward compatibility preserved:
getAgentId()defaults togetId()when no explicit agentId is set- Existing code that uses
getName()for resource paths is migrated togetAgentId()— this is the correct semantic change sincenamewas being overloaded
Key changes reviewed:
Agentinterface: defaultgetAgentId()with fallback — clean SPI extensionAgentBase: storesagentIdfield, constructor updatedReActAgent.Builder/HarnessAgent.Builder:agentId(String)builder method +fromAgent()propagation- Middleware (MemoryFlush, Compaction): correctly switched from
getName()togetAgentId()for state paths EventPublisher: usesgetAgentId()for event routing — correctHarnessAgent.defaultStateDir(): usesgetAgentId()— ensures state isolation by logical identity- Tests: comprehensive coverage of explicit agentId, name fallback, and UUID fallback
One consideration:
- The migration from
getName()togetAgentId()for state paths means existing deployments that relied onnamefor state directory naming will see a different directory on upgrade (unless they setagentIdto match the oldname). This should be noted in release notes.
Verdict
Well-structured feature. Addresses a real architectural concern (identity conflation). Build and tests pass. Approved.
This reverts commit 9c6418c.
zouyx
left a comment
There was a problem hiding this comment.
Concurrency issue: this change still keys per-invocation state by Agent.getId(), which identifies the agent instance rather than one call. ReActAgent explicitly permits concurrent calls for different userId/sessionId slots. In TrainingRouter, concurrent PreCall events from the same agent overwrite callInputs[id]; the first PostCall can train against the second request's input and the second receives no input. JsonlTraceExporter has the same run/turn correlation issue: concurrent PRE_CALL events overwrite one RunState for the shared instance. Please introduce a per-invocation correlation key propagated through hook events or call scope, and add a parallel, different-session regression test before merging.
| callInputs.put(agentId, event.getInputMessages()); | ||
| logger.debug("Saved input messages for agent: {}", agentId); | ||
| String id = event.getAgent().getId(); | ||
| callInputs.put(id, event.getInputMessages()); |
There was a problem hiding this comment.
is it right logical for multi session in the same agent?
There was a problem hiding this comment.
Good catch. Agent.getId() only isolates agent instances; it is still shared by concurrent calls on the same ReActAgent. I’ll add a per-invocation correlation id propagated through the hook event lifecycle
There was a problem hiding this comment.
I fixed the input/output message mismatch by using the request ID stored in the Reactor context. If no request ID is available, it falls back to the agent ID
…ns of the same agent
AgentScopeJavaBot
left a comment
There was a problem hiding this comment.
🤖 AI Review
This PR separates agent identity into two concepts: a stable logical agentId (user-settable, survives restarts/clones) and a per-instance runtime id (immutable UUID). All internal callers are migrated to use the correct getter based on their needs (isolation vs display). Tests are comprehensive. Note: PR title ("fix event ordering in async event bus") does not match actual changes.
(inline comments could not be attached — line numbers fell outside PR hunks. See archived report.)
AgentScopeJavaBot
left a comment
There was a problem hiding this comment.
🤖 AI Review
This PR separates agent identity into two concepts: a stable logical agentId (user-settable, survives restarts/clones) and a per-instance runtime id (immutable UUID). All internal callers are migrated to use the correct getter based on their needs (isolation vs display). Tests are comprehensive. Note: PR title ("fix event ordering in async event bus") does not match actual changes.
(inline comments could not be attached — line numbers fell outside PR hunks. See archived report.)
AgentScopeJavaBot
left a comment
There was a problem hiding this comment.
🤖 AI Review
This PR separates agent identity into two concepts: a stable logical agentId (user-settable, survives restarts/clones) and a per-instance runtime id (immutable UUID). All internal callers are migrated to use the correct getter based on their needs (isolation vs display). Tests are comprehensive. Note: PR title ("fix event ordering in async event bus") does not match actual changes.
(inline comments could not be attached — line numbers fell outside PR hunks. See archived report.)
|
#3360 和 当前 PR 做了一样的事情,当前 PR 多引入了一个 id 属性,相关代码修改面略大。 维护者按需选择合并哪个关闭哪个,本质都是提供 agentId 的设置。 |
oss-maintainer
left a comment
There was a problem hiding this comment.
Summary
Separates agent identity into a stable logical agentId (builder-settable, falls back to the random instance id) and a new immutable per-instance getId() (UUID), and migrates internal lifecycle/telemetry keying (GracefulShutdownManager state savers, JsonlTraceExporter run state, SubAgentTool forwarded metadata, TrainingRouter call inputs) to the instance/request id so multiple live instances sharing one logical id no longer collide. Re-review after the new push; the previous COMMENT/inline points on identity separation look addressed.
Well executed: backward-compatible constructor overloads, Agent#getId() default delegation for external implementors, blank/null fallback, solid new tests in core + harness + training, and bilingual (EN/ZH) docs.
Findings
- [Warning]
TrainingRouter.java:267(newcallId(...)) — pre/post-call key resolution can diverge across the context-keyed vsgetId()fallback paths, leaving entries incallInputs(unbounded growth). Suggest a defensive cleanup or a test pinning the mixed-context case. - [Warning]
SubAgentTool.java:406—subagent_idmetadata changes semantics from logical id to instance id; externally observable (Studio/AG-UI/custom hooks). Fine as a design choice, but should be called out in the changelog for 2.0.
Not blocking: the change is internal-consistent and well covered by tests. Comment-only review since the two items above are worth an explicit author answer / changelog note before merge.
Automated review by github-manager-bot
Additional notes (not anchored to a changed line)
- [WARNING]
agentscope-extensions/agentscope-extensions-training/src/main/java/io/agentscope/core/training/runner/TrainingRouter.java:667— [Warning]callId()now keyscallInputsby the lifecycle request id when the Reactor context carriesAgentBase.SHUTDOWN_REQUEST_ID_KEY, but falls back toagent.getId()otherwise. If aPRE_CALLis emitted outside the registered lifecycle (no request id in context) while the matchingPOST_CALLruns inside one (or vice versa), theremove(callId)inhandlePostCallmisses the entry and the map grows unboundedly — the previous code always used one stable key so pre/post could not diverge.
Could you either (a) assert/document that both hooks always resolve the same key, or (b) add a defensive cleanup, e.g. on PRE_CALL overwrite-by-instance and on ERROR/shadow-skip also remove the agent.getId() fallback key? A small test that fires PreCallEvent without the context key and PostCallEvent with it would pin the behaviour down. (line outside diff)
| @@ -402,7 +403,7 @@ private void forwardEvent(Event event, ToolEmitter emitter, Agent agent, String | |||
| Map<String, Object> metadata = new HashMap<>(); | |||
| metadata.put("subagent_event", event == null ? "" : event); | |||
| metadata.put("subagent_name", agent.getName() == null ? "" : agent.getName()); | |||
| metadata.put("subagent_id", agent.getAgentId() == null ? "" : agent.getAgentId()); | |||
| metadata.put("subagent_id", agent.getId() == null ? "" : agent.getId()); | |||
There was a problem hiding this comment.
[Warning] subagent_id in forwarded ToolResultBlock metadata switches from the logical getAgentId() to the per-instance getId() (same class of change in GracefulShutdownManager.stateSavers and JsonlTraceExporter run-state keys). Internally consistent here, but it is an observable wire/telemetry semantics change for downstream consumers (Studio, AG-UI, custom hooks) that may have been aggregating events by subagent_id. Since Agent.getId() previously did not exist and getAgentId() was the only id, worth calling this out explicitly in the changelog / release notes for 2.0 so integrators can switch to agentId-keyed aggregation deliberately.
|
原有代码中至少 |
agentId 本就表示唯一标识,使用UUID生成。自持传入,自然应由传入者决定唯一(谁管理谁保证的原则),相关doc和文档写清楚即可。况且这个只是支持传入并不是必须传入,不传入则框架默认UUID。 |
我理解主要是我们对agentId 的含义及定位理解不一致导致的。当前的agent接口定义的agentId含义上是实例id 不支持同一个jvm里有多个相同的agentId(否则导致GracefulShutdownManage等类维护的agent状态被覆盖)。但是HarnessAgent的agentid 是会影响namespace 同一个逻辑agent的agentId是一样的且HarnessAgent设计上支持多实例 一旦打通这两个agent的id在原始定义上有冲突,所以我设计上用id 实现原实例id的功能, agentId作为agent的逻辑唯一标识 将两个含义拆开了。 |
Why
agentIdcurrently serves several different purposes in AgentScope Java:These meanings conflict when the same logical Agent is recreated or scaled to multiple runtime instances. The current random UUID changes for every instance, so platforms must maintain an additional mapping between their stable Agent ID and AgentScope's generated ID which discussed in #2313. However, simply making the existing ID configurable would allow multiple instances to share a value that internal state maps currently assume is unique, potentially causing state, trace, or training data to be overwritten or mixed.
This change separates the two identity concepts:
agentIdis the stable, caller-defined logical Agent ID.idis the random UUID of a specific runtime Agent instance.This allows platform integrations to use a stable logical identity while preserving the existing
instance-level isolation.
Main Changes
Agent#getId()for runtime instance identity.AgentBasealways generates an immutableUUID for it, while the default interface implementation falls back to
getAgentId()forcompatibility with existing custom
Agentimplementations.agentId. If it is null or blank, it fallsback to the generated runtime
id, preserving the previous default behavior.ReActAgent.Builder.agentId(String).ReActAgent, soHarnessAgent#getAgentId()now matches the logical ID already used by Harness resourcenamespaces. The existing Harness resolution order and resource paths remain unchanged.
id, including graceful-shutdown state savers,JSONL trace run state, and TrainingRouter input correlation. This prevents collisions when
multiple runtime instances share one logical
agentId.SubAgentTool.subagent_idcontinues to identify a unique runtime sub-agent instance by usingid.default UUID behavior, Harness propagation, and isolation between instances sharing the same
logical ID.