Skip to content

fix(adk): parse Mistral reasoning content chunks - #3214

Open
helloxjade wants to merge 2 commits into
kagent-dev:mainfrom
helloxjade:fix/mistral-reasoning-chunks-3126
Open

helloxjade wants to merge 2 commits into
kagent-dev:mainfrom
helloxjade:fix/mistral-reasoning-chunks-3126

Conversation

@helloxjade

@helloxjade helloxjade commented Oct 15, 2026 •

Copy link
Copy Markdown

Fixes #3126.

Mistral reasoning models return typed thinking/text arrays in message.content and delta.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=1
  • go vet ./adk/pkg/models
  • bin/golangci-lint run ./adk/pkg/models — 0 issues
  • GOFLAGS=-p=2 make lint — 0 issues in both Kubernetes API lint and Go lint

Mock 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.

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>
@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Oct 15, 2026
aggregatedParts = append(aggregatedParts, &genai.Part{Text: aggregatedText.String()})
aggregatedText.Reset()
}
aggregatedParts = append(aggregatedParts, part)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

streamed thinking deltas replay as separate blocks, closed:false mid-history

Comment thread go/adk/pkg/models/openai_content.go Outdated
PartMetadata: map[string]any{mistralThinkingChunkKey: string(rawChunk)},
})
default:
return nil, fmt.Errorf("unsupported OpenAI content chunk type %q", chunk.Type)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Oct 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] OpenAI-compat adapter stringifies Mistral reasoning chunks (ThinkChunk/TextChunk) into agent answers as raw JSON

2 participants