Skip to content

A2aAgent 不支持 Middleware 机制, 仅能通过 deprecated Hook API 拦截事件流 — 请求支持 Middleware #2612

Closed

Description

@zcw888

问题描述

在基于 AgentScope Java 2.0 构建 A2A 多智能体应用时,期望通过统一的 MiddlewareBase 机制拦截事件流。但 A2aAgent 仅支持 deprecated Hook API,事件流(如 ReasoningChunkEvent)只经由 ClientEventContext.publishReasoningChunk 通过 hooks 列表发布。

期望行为

A2aAgent.Builder 只提供 .hook(Hook),没有 .middleware(MiddlewareBase)。

期望支持

希望 A2aAgent 支持 MiddlewareBase,使 ReasoningChunkEvent 等 A2A 客户端事件也能进入 middleware 管道(onReasoning 链)。

影合

Hook API 已 deprecated,长期维护存在风险;A2A 场景无法用统一 Middleware 风格做事件透传。

环境

AgentScope Java v2.0.0 GA | agentscope-extensions-a2a-client | JDK 17

Activity

  1. added
    enhancement
    area/build
    area/core/agent
    area/ext/integration
    on Aug 11, 2026
  2. wmh123wmh1 commented on Sep 3, 2026

    @wmh123wmh1
    Contributor

    Hi maintainers, I would like to work on #2612.

    I traced the current A2A client flow on the main branch. A2aAgent currently exposes only hook()/hooks(). A2A client events are routed through ClientEventContext, where PreReasoningEvent, ReasoningChunkEvent, and PostReasoningEvent are dispatched to the Hook list. The MiddlewareBase/MiddlewareChain path used by ReActAgent is not involved.

    To keep the change small and backward compatible, I propose an initial implementation that:

    1. Adds MiddlewareBase configuration to A2aAgent.
    2. Routes the remote reasoning event stream through MiddlewareBase.onReasoning().
    3. Keeps the existing Hook API and legacy stream behavior unchanged.
    4. Adds focused tests for event ordering and Hook compatibility.

    I will not change onActing(), onModelCall(), onSystemPrompt(), or add a new streamEvents() API in this initial change unless that is required.

    Could you please confirm whether this scope and the proposed compatibility approach are acceptable?

  3. moved this from Backlog to In progress in AgentScope Javaon Oct 21, 2026
  4. moved this from In progress to Done in AgentScope Javaon Oct 21, 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/buildarea/core/agentarea/ext/integrationenhancement

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions