fix: Fix/azure native tool calls from main#705
Merged
Henry-811 merged 3 commits intodev/v0.1.31from Dec 29, 2025
Merged
Conversation
This commit fixes the Azure OpenAI backend architecture to use native tool_calls from the Azure API, making it consistent with Claude, ChatCompletions, and Grok backends. Problem: - Azure backend was converting native tool_calls to plain text - Then trying to extract them back using regex patterns - Custom system prompts were injected asking for specific JSON format - This caused tool call detection to fail, especially for Ministral-3B - Led to infinite "coordination in progress" loops without consensus Solution: 1. Fixed _convert_chunk_to_stream_chunk() to yield native tool_calls - Changed from converting to text to returning proper StreamChunk - Lines 746-753: Now returns StreamChunk(type="tool_calls") 2. Added tool call accumulation in stream_with_tools() - Added accumulated_tool_calls dictionary (line 226) - Accumulates tool call deltas during streaming (lines 260-279) - Yields complete tool_calls after streaming (lines 311-323) - Replaced text extraction with native tool call yielding 3. Removed custom system prompt injection - Line 153: Now uses messages as-is - Tools are passed to API natively via api_params["tools"] Benefits: - Works with ALL Azure models (GPT-4o, GPT-4.1-mini, Ministral-3B, etc.) - No model-specific code needed - More reliable (native API vs regex parsing) - Simpler architecture (net removal of ~30 lines) - Future-proof (works with new models automatically) Testing: - Tested with 3-agent setup (GPT-4o, GPT-4.1-mini, Ministral-3B) - All agents successfully use workflow tools - Consensus reached without infinite loops - No regression for existing agents
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.
This pull request updates the Azure OpenAI backend to improve how tool calls are handled and streamed. The main change is that tool calls are now accumulated and yielded as structured
tool_callschunks, rather than being ignored or treated as plain content. This results in more accurate and structured streaming of tool call information to downstream consumers.Tool Call Streaming Improvements:
tool_callschunks, rather than being ignored or appended as plain content. This allows downstream consumers to process tool calls more reliably. [1] [2] [3]_convert_chunk_to_stream_chunknow emitstool_callschunks when tool calls are present, instead of flattening them into content.Code Simplification and API Alignment:
Your PR title must follow the format:
<type>: <brief description>Valid types:
fix:- Bug fixesfeat:- New featuresbreaking:- Breaking changesdocs:- Documentation updatesrefactor:- Code refactoringtest:- Test additions/modificationschore:- Maintenance tasksperf:- Performance improvementsstyle:- Code style changesci:- CI/CD configuration changesExamples:
fix: resolve memory leak in data processingfeat: add export to CSV functionalitybreaking: change API response formatdocs: update installation guideDescription
Brief description of the changes in this PR
Type of change
fix:) - Non-breaking change which fixes an issuefeat:) - Non-breaking change which adds functionalitybreaking:) - Fix or feature that would cause existing functionality to not work as expecteddocs:) - Documentation updatesrefactor:) - Code changes that neither fix a bug nor add a featuretest:) - Adding missing tests or correcting existing testschore:) - Maintenance tasks, dependency updates, etc.perf:) - Code changes that improve performancestyle:) - Changes that do not affect the meaning of the code (formatting, missing semi-colons, etc.)ci:) - Changes to CI/CD configuration files and scriptsChecklist
Pre-commit status
How to Test
Add test method for this PR.
Test CLI Command
Write down the test bash command. If there is pre-requests, please emphasize.
Expected Results
Description/screenshots of expected results.
Additional context
Add any other context about the PR here.