Skip to content

[Bug]:AgentScope 2.0 GA 单例 Agent 并发时工具组跨会话串扰 #2439

Closed

Description

Describe the bug(问题描述)

AgentScope Java 2.0.0 (GA),同一个共享的 HarnessAgent/ReActAgent 单例在多个会话
并发执行时,激活的工具组(active tool groups)会跨会话串。原因是 AgentState 已按调用
隔离,但 Toolkit 仍是实例级共享可变对象:activateSlotForContext 里的
toolkit.setActiveGroups(...) 改的是共享实例,并发调用互相覆盖;syncToolkitToState
还会把它回写进错误会话的状态并持久化,导致该会话之后每轮都带着别人的工具组。

关联 #2256(该 issue 说 2.x 支持单例并发):本问题是另一种症状——工具组静默跨会话
串扰,不是 "agent is still running" 等待。若单例并发确为支持用法,这看起来是缺陷。

Expected behavior(期望行为)

活动工具组应像 AgentState 一样按 (userId, sessionId) 调用隔离,会话之间互不影响。

Environment(环境)

  • AgentScope-Java Version: 2.0.0 (GA)
  • Java Version: 21

Additional context(补充信息)

建议把工具组活动状态改为按调用隔离(随 CallExecution/Reactor Context 携带),
与 AgentState 一致。请问:单实例并发多会话是否为官方支持用法?若是则这是 bug,
若推荐每会话独立实例,能否在文档中说明?

Activity

  1. added
    bug
    on Jul 28, 2026
  2. logicwu0 commented on Jul 28, 2026

    @logicwu0
    Contributor

    I reproduced this with a deterministic concurrent-session regression test: two sessions loaded with different active tool groups overwrite one another through the shared Toolkit state. I am working on a fix that keeps tool-group activation and persistence scoped to each call/session, including runtime group changes, and will add the regression test to the PR.

  3. oss-maintainer commented on Jul 28, 2026

    @oss-maintainer
  4. added
    area/core/agent
    area/core/memory
    area/core/tool
    area/docs
    area/harness
    on Aug 11, 2026
  5. xuchaoguo1983 commented on Sep 26, 2026

    @xuchaoguo1983

    Confirmed still present on 2.0.3, reproduced deterministically with a HarnessAgent singleton, a Redis AgentStateStore and AG-UI.

    Steps: session B's model call is blocked mid-turn. Meanwhile session A activates a META group via reset_equipped_tools, then B is released. B's end-of-call save runs syncToolkitToState, which persists the shared toolkit's active groups, including A's group, into B's state. On B's next turn, the group's tools appear in B's tool list, although B never activated it.

    Tool-schema selection per call already uses state.getToolContext().getActivatedGroups(), so the leak comes in through persistence. ToolExecutor's availability check also reads the shared toolkit (Unauthorized tool call: ... is not available), which suggests a concurrent session can also make a legitimately activated tool unavailable.

  6. xzxiaoshan commented on Oct 9, 2026

    @xzxiaoshan
    Collaborator

    complated as v2.0.4

  7. moved this from In progress to Done in AgentScope Javaon Oct 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/core/agentarea/core/memoryarea/core/toolarea/docsarea/harnessbug

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions