agentscope-java icon indicating copy to clipboard operation
agentscope-java copied to clipboard

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

Open PlanDoSome opened this issue 3 months ago • 2 comments

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事件的。只有恰好智能体流正在运行才可以收到

PlanDoSome avatar Aug 13 '26 07:08 PlanDoSome

I am investigating the Reactor subscriber-context loss in AsyncToolMiddleware on current main (6a056809a). 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.

breezeFur avatar Sep 26 '26 04:09 breezeFur

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

oss-maintainer avatar Sep 27 '26 07:09 oss-maintainer