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

[spring-ai] Bridge drops reasoning_content (thinking) — surface it as partial events and/or persist it

Open caps-xia opened this issue 1 month ago • 3 comments

Is your feature request related to a problem? Please describe.

Spring AI 2.0 already exposes reasoning content from thinking models such as DeepSeek-R1, Qwen-Thinking, and GLM via AssistantMessage metadata (reasoningContent). However, in the Spring AI bridge used by ADK, this field is not read or forwarded.

After decompiling 1.11.0, I confirmed the four core bridge classes — SpringAI, MessageConverter, StreamingResponseAggregator, and ConfigMapper — don't reference reasoningContent at all. The result is that reasoning is silently dropped: it is neither forwarded as partial events nor persisted to the session, and there is no warning. Users running thinking models through the bridge lose the entire reasoning stream.

Describe the solution you'd like

During streaming aggregation, the bridge should read reasoningContent and surface it to ADK consumers. For example:

  • emit it as dedicated reasoning parts on partial LlmResponses, persisted together with the final event; or
  • map it onto the thought flag if the Java SDK's Part supports it, similar to the Gemini path.

This would make thinking models actually usable through the bridge: UIs could render collapsible thinking panels, and session history would retain the reasoning trace for audit.

We already handle this in a production fork via a lightweight marker protocol around the reasoning text, with the frontend rendering collapsible thinking panels and per-segment timing. Happy to share the implementation or send a PR.

One thing the bridge would also need to normalize: OpenAI-compatible gateways differ in reasoning chunk semantics — some stream pure deltas, others return cumulative text per chunk. Consumers currently need prefix-detection heuristics to avoid duplication; if the bridge normalized to pure deltas once, all downstream code stays simple.

Describe alternatives you've considered

Keeping the status quo forces anyone using thinking models through the bridge to either fork it or lose reasoning entirely.

Additional context

Verified against 1.11.0 (current latest at the time of writing). No Spring AI changes are needed — the metadata is already there, waiting for the bridge to read it.

caps-xia avatar Oct 05 '26 12:10 caps-xia

Hi @caps-xia, Thank you for taking time and submitting this feature request. It is currently under review by our team and we will keep you posted if any additional information is required. thank you.

hemasekhar-p avatar Oct 05 '26 13:10 hemasekhar-p

Hi @hemasekhar-p, gentle follow-up on this feature request — it's been a couple of weeks since the team review started. Is there any update on the direction (thought-flag parts vs. a marker protocol), or anything else you need from my side to move the discussion forward? Happy to contribute the implementation whenever a direction is settled.

caps-xia avatar Oct 23 '26 09:10 caps-xia

Quick update while this is under review: with the aggregated-final streaming landed on main (#1721), the bridge now carries thought-flagged parts end to end — but the OpenAI-compatible path still drops reasoning, because the OpenAI provider exposes it under the reasoningContent message-metadata key while the converter only maps isThought (Google GenAI) and the Anthropic thinking signature.

The remaining gap is small and well-scoped, so I rebased my working branch onto main and it now reduces to just that mapping (+81 lines, 3 files):

  • MessageConverter reads reasoningContent and emits it as thought-flagged parts ahead of the answer text, normalized from cumulative to deltas (the OpenAI accumulator concatenates reasoning by response id; prefix detection takes the new suffix, a non-prefix value resets tracking, and each stream start resets the state);
  • the existing StreamAggregation then merges consecutive thought deltas into one part, keeping reasoning separate from the answer on the aggregated final — and out of the next turn's prompt;
  • end-to-end streaming test covers delta emission on partials and thought/answer separation on the final.

Branch: https://github.com/google/adk-java/compare/main...caps-xia:adk-java:feat/spring-ai-reasoning-content (307 tests green locally). Happy to open the PR if the direction sounds right.

caps-xia avatar Oct 30 '26 02:10 caps-xia