Skip to content

fix: Azure OpenAI Tool Calls#7727

Merged
yuhongsun96 merged 4 commits intomainfrom
azure-openai-handling
Jan 24, 2026
Merged

fix: Azure OpenAI Tool Calls#7727
yuhongsun96 merged 4 commits intomainfrom
azure-openai-handling

Conversation

@yuhongsun96
Copy link
Copy Markdown
Contributor

@yuhongsun96 yuhongsun96 commented Jan 24, 2026

Description

Tool Calls in Azure OpenAI are not given back as streamed objects but rather just a final response.completed object. This now correctly extracts them.

How Has This Been Tested?

Works locally where previously it didnt.

Additional Options

  • [Optional] Override Linear Check

Summary by cubic

Fixes Azure OpenAI tool calls in streaming by extracting function_call items from response.completed and emitting delta.tool_calls with a tool_calls finish reason. Tracks streamed tool calls to avoid duplicates and correctly signal completion, so tools execute reliably with the Azure Responses API.

Written for commit f3a82ad. Summary will update on new commits.

@yuhongsun96 yuhongsun96 requested a review from a team as a code owner January 24, 2026 00:21
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Jan 24, 2026

Greptile Overview

Greptile Summary

Fixes Azure OpenAI tool calls in streaming responses by extracting function_call items from the response.completed event and emitting them as ChatCompletionToolCallChunk objects with a tool_calls finish reason.

What changed:

  • Previously, the code only detected tool calls and set finish_reason="tool_calls" but returned tool_use=None
  • Now, the code extracts actual tool call data (id, name, arguments) from response.completed.output and returns it as tool_use=tool_calls[0]

Why this matters:
Azure's Responses API behaves differently from standard OpenAI - it includes all tool calls in the final response.completed event rather than streaming them incrementally. Without extracting this data, tool calls were being ignored despite being detected.

Confidence Score: 4/5

  • This PR is safe to merge with minimal risk, addressing a specific Azure OpenAI integration bug
  • The change is well-scoped to fixing a specific issue with Azure OpenAI tool calls. The logic correctly extracts tool call data from the response.completed event. One minor concern is that only the first tool call is returned when multiple exist, but the comment indicates the streaming handler will merge them. The fix has been tested locally and resolves the reported issue.
  • Verify that the streaming handler correctly processes multiple tool calls when only the first is returned from response.completed

Important Files Changed

Filename Overview
backend/onyx/llm/litellm_singleton/monkey_patches.py Extracts tool calls from Azure OpenAI response.completed events, fixing issue where tool calls were detected but not returned

Sequence Diagram

sequenceDiagram
    participant Azure as Azure OpenAI API
    participant Parser as chunk_parser
    participant Handler as Streaming Handler
    participant Client as Onyx Client
    
    Azure->>Parser: response.created event
    Parser->>Handler: GenericStreamingChunk (empty)
    
    Azure->>Parser: response.output_item.added (function_call)
    Parser->>Handler: GenericStreamingChunk (with tool_use)
    
    Azure->>Parser: response.function_call_arguments.delta
    Parser->>Handler: GenericStreamingChunk (arguments delta)
    
    Azure->>Parser: response.output_item.done
    Parser->>Handler: GenericStreamingChunk (tool complete)
    
    Note over Azure,Parser: Azure sends ALL tool calls in final event
    
    Azure->>Parser: response.completed (with all function_calls)
    Note over Parser: OLD: Just set finish_reason="tool_calls"
    Note over Parser: NEW: Extract tool calls, return first one
    Parser->>Handler: GenericStreamingChunk (tool_use=tool_calls[0], finish_reason="tool_calls")
    
    Handler->>Client: Merged tool call data
Loading

Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

1 file reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Comment on lines +515 to +523
if tool_calls:
# Return first tool call - the streaming handler will merge them
return GenericStreamingChunk(
text="",
tool_use=tool_calls[0],
is_finished=True,
finish_reason="tool_calls",
usage=None,
)
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.

Only returning the first tool call when multiple exist. Verify that either: (1) Azure sends each tool call in separate response.output_item.added events before response.completed, or (2) the streaming handler properly merges tool calls even when only the first is returned here.

Prompt To Fix With AI
This is a comment left during a code review.
Path: backend/onyx/llm/litellm_singleton/monkey_patches.py
Line: 515:523

Comment:
Only returning the first tool call when multiple exist. Verify that either: (1) Azure sends each tool call in separate `response.output_item.added` events before `response.completed`, or (2) the streaming handler properly merges tool calls even when only the first is returned here.

How can I resolve this? If you propose a fix, please make it concise.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 1 file

Copy link
Copy Markdown
Contributor

@justin-tahara justin-tahara left a comment

Choose a reason for hiding this comment

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

If you can validate the Greptile comment and ideally if you can add a simple unit test that would be great.

Approving to unblock

@yuhongsun96 yuhongsun96 enabled auto-merge January 24, 2026 00:48
@yuhongsun96 yuhongsun96 added this pull request to the merge queue Jan 24, 2026
Merged via the queue into main with commit 0464083 Jan 24, 2026
77 checks passed
@yuhongsun96 yuhongsun96 deleted the azure-openai-handling branch January 24, 2026 01:51
yuhongsun96 added a commit that referenced this pull request Jan 24, 2026
justin-tahara pushed a commit that referenced this pull request Jan 24, 2026
justin-tahara pushed a commit that referenced this pull request Jan 24, 2026
jmelahman pushed a commit that referenced this pull request Jan 25, 2026
jmelahman pushed a commit that referenced this pull request Jan 25, 2026
@wenxi-onyx wenxi-onyx mentioned this pull request Jan 26, 2026
1 task
yuhongsun96 added a commit that referenced this pull request Jan 27, 2026
yuhongsun96 added a commit that referenced this pull request Jan 27, 2026
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.

2 participants