Skip to content

2.0版本streamEvents增加结构化输出参数 #1717

Closed

Description

@lqx26164541

在1.0版本,流式输出可以定义结构化输出,在2.0,目前还不支持流式输出JSON结构化数据

Activity

  1. changed the title [-]streamEvents增加结构化输出参数[/-] [+]2.0版本streamEvents增加结构化输出参数[/+] on Jun 11, 2026
  2. added
    enhancement
    area/core/agent
    on Jun 12, 2026
  3. liyujiang-gzu commented on Aug 7, 2026

    @liyujiang-gzu

    很需要这个特性,目前我是@Tool定义结构化输出工具给大模型调用+结构化输出Middleware兜底重试。。

  4. moved this from Backlog to In progress in AgentScope Javaon Aug 31, 2026
  5. Letter2025 commented on Aug 31, 2026

    @Letter2025
    Contributor

    Just noting this is now implemented — see #2919.

    The root cause: ReActAgent#streamEvents(List, RuntimeContext) hard-codes this::doCall, and buildAgentStream(...) is private, so there was no way to inject the structured-output variants (doCall(m, schema) / doCall(m, structuredModel)) that already back the non-streaming call(msgs, schema/class, ctx).

    #2919 adds the missing fine-grained overloads (JsonNode + Class, on both ReActAgent and HarnessAgent) by routing through the same buildAgentStream core, so:

    • native response_format (strict json_schema) → TextBlockDeltaEvent JSON deltas;
    • fallback generate_response tool → ToolCallStartEvent / ToolCallDeltaEvent in the stream;
    • final AgentResultEvent carries a Msg with hasStructuredData() == true plus aggregated usage, identical to call(...).

    Tests cover both overloads on both paths (native + fallback) and verify semantic equivalence with call(...).

  6. dargoner commented on Sep 12, 2026

    @dargoner
    Contributor

    补充一个信息:这个诉求已经有对应 PR——#2919(feat(agent): support structured output in streamEvents),目前两个人工 approve、CI 全绿,但还挂在未合并状态。

    如果对期望形状有倾向,建议直接写到 #2919 里一起收敛,例如:

    • 是否只要 List 形式,还是也接受 Msg / String 便捷重载;
    • Class<?> 与 JsonNode 两种入口是否都要;
    • core 与 harness 是否统一支持。

    这样才能一次定形状,避免再开一个 PR 重复讨论。相关讨论:#2919 (comment)

  7. added a commit that references this issue on Sep 15, 2026
    4e29ce2
  8. oss-maintainer commented on Sep 25, 2026

    @oss-maintainer
    Collaborator

    Issue Evaluation

    Category: enhancement (area/core/agent) | Status: Evaluated — request is still unmet on main, and the shape is a maintainer call | Feasibility: feasible (plumbing already exists)

    Verified against main @ 3c1c29c0 (engine-assisted static read; this issue sat below the newest-open scan window, so this is its first evaluation).

    1. The gap is real today — no streamEvents overload takes a schema.

    Item Result Evidence
    ReActAgent.streamEvents(...) overloads carry no structured-output parameter TRUE agentscope-core/src/main/java/io/agentscope/core/ReActAgent.java:1123, :1133, :1148, :1160, :1170, :1182 — none accepts Class / JsonNode
    streamEvents(List, RuntimeContext) hard-codes the plain call target TRUE ReActAgent.java:1149 → buildAgentStream(msgs, context, this::doCall), while the structured variants doCall(m, Class) (:1240) and doCall(m, JsonNode) (:1245) exist but are unreachable from the stream path
    buildAgentStream(...) is still private TRUE ReActAgent.java:1038 — the only reachable wrapper is callInternal (:1012), which cannot inject a structured doCall
    HarnessAgent adds no structured streaming either TRUE agentscope-harness/src/main/java/io/agentscope/harness/agent/HarnessAgent.java:861, :869, :881, :889, :901, :920; :923 just delegates to delegate.streamEvents(msgs, effective)
    Repo-wide, no Flux<AgentEvent> streamEvents(..., Class/JsonNode/schema) in any src/main TRUE 0 matches — PR #2919 is not merged (state: OPEN, reviewDecision: APPROVED, last updated 2026-09-16)

    2. Why "already implemented per #2919" is not yet true for users of main. Structured output today is reachable only through the non-streaming call(List, Class, RuntimeContext) (ReActAgent.java:853) / call(List, JsonNode, RuntimeContext) (:857), which route to doStructuredCall (:1254) → doNativeStructuredCall (:1302) / doFallbackStructuredCall (:1358) and return Mono<Msg>: callInternal (:1014-1019) filters the pipeline down to AgentResultEvent and takeLast(1), discarding the event stream. The 1.0-style structured streaming survives only in the @Deprecated(forRemoval = true) stream(..., Class/JsonNode) overloads (ReActAgent.java:982, :995; StreamableAgent.java:68, :124, :139, :197, :210) — whose own javadoc tells users to migrate to the API that lacks the feature. So the migration path advertised by the deprecation is currently a downgrade.

    3. The useful finding: the work is wiring, not new machinery. The structured doCall variants already bind the per-subscription event sink (EVENT_SINK_KEY, ReActAgent.java:1308-1319), i.e. the events are produced internally and then thrown away by callInternal. Exposing them needs no change to the structured-output execution itself.

    Shape decision this issue still needs (three separate asks have landed in-thread, which is why no patch was generated here):

    1. Which inputs: only List<Msg>, or also Msg / String convenience overloads?
    2. Which schema carriers: both Class<?> and JsonNode, or JsonNode only?
    3. Scope: agentscope-core only, or HarnessAgent in the same change (its six overloads at :861-:923 would need the matching delegate, and agentscope-core interface changes cascade to harness / distribution / extensions)?

    @Letter2025 #2919 already answers these implicitly by its chosen surface — since it is approved and green, converging on it is cheaper than a parallel implementation. If a core owner confirms the shape there, this issue can be closed from the PR rather than from a new one. If instead the team prefers the overload set to be decided before merge, say so on #2919 and reply /approve or /revise <shape> here and a patch against the agreed surface will be generated.

    Testability. Yes, no external services needed — extend the existing structured-output tests to assert that the streamed events from a structured call reach the subscriber (partial AgentResultEvent/chunk sequence plus a final message parsed into the target type), and that the deprecated stream(..., Class) behaviour is reproduced by streamEvents(...). No test today asserts anything about structured output on the streamEvents path.


    Automated evaluation by github-manager-bot

  9. oss-maintainer commented on Sep 28, 2026

    @oss-maintainer
    Collaborator

    Status: no automated PR will be generated — this proposal window here is closed.

    The 72-hour feedback window opened by the evaluation comment above (5824400015,
    2026-09-25T00:10:12Z) expired at 2026-09-28T00:10:12Z with no community reply carrying
    an approval, a revision request or a rejection, so we skip PR generation.

    This is not a judgement about the request itself. The implementation path for
    structured output in streamEvents is already owned by community PR #2919
    (Letter2025, open, unmerged, head d036339270 at the time of writing), which remains
    the place to review, extend or comment on that work. If the maintainers would rather
    see this change tracked separately from #2919, please say so on this issue and the
    evaluation will be re-opened as a fresh proposal with a new window.

  10. added a commit that references this issue on Nov 20, 2026
    29ed288
  11. moved this from In progress to Done in AgentScope Javaon Nov 20, 2026
  12. added a commit that references this issue on Nov 20, 2026
    131e3fe
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/agentenhancement

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions