Skip to content

[Feature]: 2.0 version how to get the requestId by the inference service provider #2231

Open

Description

@huazaizhang

AgentScope-Java is an open-source project. To involve a broader community, we recommend asking your questions in English.

Describe the solution you'd like
In AgentScope 1.0, the request ID returned by the inference service provider could be obtained via gen_ai.response.id. However, this is no longer accessible in version 2.0. Would you consider adding this capability back?

Activity

  1. added
    enhancement
    on Jul 15, 2026
  2. added
    area/core/model
    on Jul 16, 2026
  3. huazaizhang commented on Sep 14, 2026

    @huazaizhang
    Author

    这个问题修复了没有呢?

  4. oss-maintainer commented on Sep 24, 2026

    @oss-maintainer
    Collaborator

    Issue Evaluation

    Category: enhancement | Status: Partly available today, real gap confirmed (reviewed against main@3c1c29c01, read-only static inspection; no runtime reproduction)

    What already works. The provider-side response/request id is captured for most providers and reachable without a telemetry span:

    • ChatResponse.getId() — agentscope-core/src/main/java/io/agentscope/core/model/ChatResponse.java:64-66
      • OpenAI HTTP: OpenAIResponseParser.java:363 (non-streaming) and :624 (stream chunk), from OpenAIResponse.id (OpenAIResponse.java:71-73)
      • DashScope: DashScopeResponseParser.java:132 maps the JSON request_id field
      • Anthropic non-streaming: AnthropicResponseParser.java:108
      • Gemini: GeminiResponseParser.java:119 (response.responseId())
    • The final assistant Msg carries it too: ReasoningContext.java:87 stores chunk.getId(), :202 applies it in buildFinalMessage().
    • The GenAI attribute still exists on the legacy studio tracer path: GenAiIncubatingAttributes.GEN_AI_RESPONSE_ID (:90), populated in AttributesExtractors.java:223 and emitted by TelemetryTracer.java:150.

    Confirmed gaps — these are what make 2.0 feel like a regression versus 1.0:

    1. The 2.0-recommended OTel path never emits gen_ai.response.id. OtelTracingMiddleware.setModelResponseAttributes(...) (agentscope-core/src/main/java/io/agentscope/core/tracing/OtelTracingMiddleware.java:354-368) sets only usage/token attributes. TracerRegistry is @Deprecated(forRemoval = true, since = "2.0.0") and its javadoc directs new applications to OtelTracingMiddleware — so anyone migrating off the studio tracer silently loses the attribute they had in 1.0.
    2. Anthropic streaming drops the provider id on the final message. messageId is assigned only inside the message_start branch (AnthropicResponseParser.java:157,163); other stream events return .id(null) (:264), and ChatResponse.Builder.build() then substitutes a random UUID (ChatResponse.java:198-203).
    3. Ollama has no provider id at all, so its value is always that synthetic UUID — worth stating in the docs so users do not key idempotency/correlation on it.
    4. No transport reads a request-id response header (x-request-id appears only as an outbound test header); providers that surface the id solely in a header are unreachable.
    5. ModelCallEndEvent.getReplyId() is not the provider id. It is a framework correlation UUID (ReActAgent.java:2651 → new ModelCallEndEvent(replyId, ...) at :2696), and ModelCallInput carries inputs only, so a MiddlewareBase.onModelCall hook has no access to the provider id today.

    Feasibility / scope: low-risk and additive. Minimum shape: (a) set GEN_AI_RESPONSE_ID from the aggregated response in OtelTracingMiddleware, (b) keep messageId across Anthropic streaming events so it lands on the final ChatResponse/Msg. Existing per-provider parser tests already assert id propagation (AnthropicResponseParserTest, GeminiResponseParserTest:70, DashScopeResponseParserTest:78, OpenAIClientTest:129); no test asserts the telemetry attribute, so that assertion would need to be added.

    We deliberately are not opening a PR yet: (a) this is a feature request rather than a defect, and (b) a maintainer signal is needed on whether the provider id should be a span attribute on the middleware path, a field on ModelCallEndEvent, or both. Reply /approve and we will generate a spec and a PR scoped to gaps 1 and 2.


    Automated evaluation by github-manager-bot

  5. oss-maintainer commented on Sep 27, 2026

    @oss-maintainer
    Collaborator

    Status: 72 h feedback window expired — no automated PR will be generated, the proposal window here is closed

    The evaluation above (5823839932, posted 2026-09-24T23:16:34Z) reached its 72-hour feedback limit at 2026-09-27T23:16:34Z. Nobody has replied in this thread since, no line in it starts with an approve, revise or reject command, and the evaluation comment drew no reactions, so per our workflow we skip PR generation and this proposal window is closed. No action is needed from anyone.

    Standing the window down is a timing call about the bot's own wait, not a verdict on the report or on the request. The issue stays open, and the two gaps the evaluation recorded for the minimum scope still stand as written there: the recommended OpenTelemetry path never emits gen_ai.response.id, and the provider response id is dropped on the Anthropic streaming path before it can reach the final message.

    If a first-party patch is wanted later, a reply here carrying a direction is enough to get a spec and a PR generated against current main — specifically, whether the provider id should live as a span attribute on the middleware path, on the model-call end event, or both. The bot simply stops waiting on this thread.

    Automated by github-manager-bot

  6. CCCLL commented on Oct 5, 2026

    @CCCLL

    I'd like to contribute a focused fix for the Anthropic streaming response ID loss identified in this issue.

    I reproduced it on main@9e43ed836d68f5d054bc0b4af3704d81cd49cecb: message_start contains the provider's message ID, but later content and usage chunks get generated UUIDs, so the final assistant Msg loses the provider ID.

    The local patch retains the ID in the existing per-subscription stream state. It preserves the missing/blank-ID compatibility added in #3394, using one generated fallback ID per subscription. Six regression cases cover provider IDs, missing/empty/blank IDs, repeated subscriptions, overlapping subscriptions, and the final accumulated message. All six fail on the original parser and pass with the fix. The Core and Anthropic test suites also pass (2,744 tests reported, 10 existing skips, no failures or errors).

    This addresses only the Anthropic parser part of #2231. It does not restore gen_ai.response.id in OtelTracingMiddleware, add a field to ModelCallEndEvent, or capture HTTP request-id headers. I also noticed that #2233 and #2418 touch the parser for thinking/signature support; this patch does not change that behavior, although #2233 overlaps in the stream state class.

    Would this narrow fix be welcome as a separate PR? I'm happy to coordinate with those changes.

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

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions