Skip to content

[Bug]:agentscope.agent.event.emitter 和 AsyncToolMiddleware #2681

Open

Description

@PlanDoSome

AsyncToolMiddleware 开启后, next.apply 没有把contextview putall一份,导致后续拿不到agentscope.agent.event.emitter,agentSpawnTool没法向agent输出子agent事件 source标识子智能体 Optional emitterOpt = AgentEventEmitter.fromContext(ctxView);

然后目前转后台工具执行,AsyncToolMiddleware虽然如果超时会捕获事件 添加到buffer,但是对于工具执行next.apply内部还是会发送ToolCallResult事件。

Image Ai分析以及我自己确认过了,这个是属于BUG还是什么。但是如果Agent当此streamEvents执行完,又是收不到这个ToolcallResult事件的。只有恰好智能体流正在运行才可以收到

Activity

  1. added
    bug
    on Aug 13, 2026
  2. added
    area/core/agent
    area/core/tool
    on Aug 15, 2026
  3. breezeFur commented on Sep 26, 2026

    @breezeFur

    I am investigating the Reactor subscriber-context loss in AsyncToolMiddleware on current main (6a05680). I will first add a deterministic regression covering AgentEventEmitter and caller context propagation across the detached subscription, then validate a minimal fix. I will keep the separate post-timeout event-routing semantics out of scope unless the regression demonstrates they must change. This work uses AI assistance; any proposed PR will remain draft pending independent review.

  4. oss-maintainer commented on Sep 27, 2026

    @oss-maintainer
    Collaborator

    Issue Evaluation

    Category: bug | Status: Confirmed on current main

    Verified against the codebase:

    • Root Cause: AsyncToolMiddleware (agentscope-harness/.../middleware/AsyncToolMiddleware.java:99-179) subscribes to next.apply(input) inside a Flux.create sink without deferContextual/contextWrite, so the Reactor subscriber Context is not propagated across that boundary. AgentEventEmitter.fromContext(ctxView) (the emitter stored under agentscope.agent.event.emitter, see AgentEventEmitter.java:45) therefore finds nothing, and AgentSpawnTool cannot stream sub-agent events to the parent.
    • Second symptom is also real: after the async timeout path, only ToolResultTextDeltaEvent is forwarded from the background buffer to the inbox (AsyncToolMiddleware.java:237-289) and the sink is completed (:234), so a ToolCallResultEvent emitted later inside next.apply never reaches the caller's stream — matching the "only received if the agent stream happens to still be running" observation.
    • Impact: sub-agent event streaming and background tool results are lost whenever AsyncToolMiddleware is enabled; middleware chain construction (MiddlewareChain.java:46-62) does not restore context across next.apply either.
    • Severity: high (breaks observable event flow for harness sub-agents).

    Note: community PR #3299 ("fix(harness): preserve subscriber context in async tool execution") targets exactly this and is still open, not yet merged into main. To avoid duplicate work, we should review/merge #3299 rather than generate a competing fix; a regression test that pins the AgentEventEmitter context propagation through the async path would strengthen it.


    Automated evaluation by github-manager-bot

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/toolbug

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions