Emit StreamEndEvent when calling tools & reaching max steps #846
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.
Description
Hi prism! Great package, I love the way you structured so many providers into one approachable framework.
I recently discovered that when streaming text, tool calls - combined with a low max steps value - do not respond with a StreamEndEvent.
This is problematic in my case because only the StreamEndEvent tracks usage data.
I adapted all providers to send a StreamEndEvent when reaching max steps.
It seems DeepSeek, Groq, Mistral and XAI handled tool calls diffently, they threw "Maximum tool call chain depth exceeded" instead of stopping gracefully.
I adapted those as well and wrote tests for all providers, but I only have access to test Anthropic, Gemini, Ollama, OpenAI and Mistral with real credentials.
Feel free to ask questions, make or request changes.
Test code
I tested real credentials with the code below
Results
OpenAI (gpt-4.1-mini):
Gemini (gemini-2.5-flash):
Anthropic (claude-haiku-4-5-20251001):
Mistral (via Google Vertex AI) (mistral-small-2503):
Breaking Changes
Text Streaming now emits StreamEndEvent after StepFinishEvent of tool calls