Skip to content

fix(mistral): stream tool calls whole instead of fragmented - #7

Merged
JulienRabault merged 1 commit into
JulienRabault:mainfrom
efegokdemir:fix/mistral-streaming-tool-calls
Sep 24, 2026
Merged

JulienRabault merged 1 commit into
JulienRabault:mainfrom
efegokdemir:fix/mistral-streaming-tool-calls

Conversation

@efegokdemir

Copy link
Copy Markdown
Contributor

Summary

  • When streaming chat completions on /mistral/v1/chat/completions with tool calls, stream each tool call whole with its complete arguments, id, name, and index, grouping parallel tool calls into a single delta.
  • The real Mistral API does not fragment tool call arguments across chunks like OpenAI does. Fragmented chunks break downstream clients such as langchain-mistralai which expect complete tool calls.
  • Only the Mistral endpoint (/mistral/v1/chat/completions) is affected; other OpenAI-compatible endpoints continue to stream tool call argument fragments.

Fixes #6

Validation

  • python -m ruff check llmock tests examples/retry_with_openai.py
  • pytest -q
  • docs updated if install, config, or API behavior changed
  • Added test_mistral_streaming_tool_calls_arrive_whole in tests/test_mistral.py

Risks

  • None. Other OpenAI-compatible provider routes retain their default fragmented streaming behavior via fragment_tool_calls: bool = True.

The real Mistral API sends each tool call whole with complete arguments and groups parallel tool calls into a single delta.

- Add `fragment_tool_calls: bool = True` parameter to `openai_chat_chunks` and `openai_stream`.
- Pass `fragment_tool_calls=False` in the Mistral router so tool calls arrive whole in one chunk with index and full arguments.
- Add `test_mistral_streaming_tool_calls_arrive_whole` in `tests/test_mistral.py`.

Signed-off-by: Efe <efe@rexcode.co.uk>

@JulienRabault JulienRabault left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks! Matches what the real API sends, the OpenAI-compatible providers keep fragmenting, and CI is green on all platforms.

@JulienRabault
JulienRabault merged commit 3c1004a into JulienRabault:main Sep 24, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Mistral streaming: tool calls are fragmented OpenAI-style, the real API sends each call whole

2 participants