Repository navigation
fix(adk): parse Mistral reasoning content chunks - #3214
Open
helloxjade wants to merge 2 commits into
Open
helloxjade wants to merge 2 commits into
helloxjade wants to merge 2 commits into
Conversation
Decode typed content arrays from the raw OpenAI response in streaming and non-streaming completions. Keep thinking separate from answer text and preserve native thinking chunks for history replay. Fixes kagent-dev#3126 Signed-off-by: helloxjade <52953016+helloxjade@users.noreply.github.com>
moezdil
reviewed
Oct 15, 2026
| aggregatedParts = append(aggregatedParts, &genai.Part{Text: aggregatedText.String()}) | ||
| aggregatedText.Reset() | ||
| } | ||
| aggregatedParts = append(aggregatedParts, part) |
Contributor
There was a problem hiding this comment.
streamed thinking deltas replay as separate blocks, closed:false mid-history
moezdil
reviewed
Oct 15, 2026
| PartMetadata: map[string]any{mistralThinkingChunkKey: string(rawChunk)}, | ||
| }) | ||
| default: | ||
| return nil, fmt.Errorf("unsupported OpenAI content chunk type %q", chunk.Type) |
Contributor
There was a problem hiding this comment.
unknown chunk types fail the whole turn, e.g. references
Persist streamed Mistral thinking as one complete closed block before history replay. Skip unsupported non-text chunks without aborting valid answers, while still rejecting malformed known chunks. Signed-off-by: helloxjade <52953016+helloxjade@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3126.
Mistral reasoning models return typed thinking/text arrays in
message.contentanddelta.content. The OpenAI SDK exposes those arrays as strings, so the adapter previously included raw chunk JSON in answers and structured output.Decode the raw content field for streaming and non-streaming completions and emit thinking as ADK thought parts. Aggregate streamed thinking deltas into one complete, closed block before persistence and assistant history replay. Closing-only deltas do not produce display content.
Skip unsupported non-text chunks, including references, without interrupting valid answer text. Malformed known text/thinking chunks still return errors. Plain string responses, including strings containing JSON arrays, keep their original text.
Validation:
go test ./adk/pkg/models -count=1go vet ./adk/pkg/modelsbin/golangci-lint run ./adk/pkg/models— 0 issuesGOFLAGS=-p=2 make lint— 0 issues in both Kubernetes API lint and Go lintMock HTTP/SSE regression coverage includes structured JSON answers, a single closed thinking block after persistence and history replay, closing-only deltas, thinking deltas individually marked closed, unsupported references/extensions, tool calls, empty deltas, and malformed known chunks.