Skip to content

fix(azure): handle None values in streaming tool_calls#7178

Open
VedantMadane wants to merge 1 commit intomicrosoft:mainfrom
VedantMadane:fix/azure-streaming-none-fields
Open

fix(azure): handle None values in streaming tool_calls#7178
VedantMadane wants to merge 1 commit intomicrosoft:mainfrom
VedantMadane:fix/azure-streaming-none-fields

Conversation

@VedantMadane
Copy link

Summary

Fixes TypeError when streaming tool calls via AzureAIChatCompletionClient when delta chunks have None values.

Problem

When using AzureAIChatCompletionClient with streaming enabled (model_client_stream=True) and tool calls, the code crashes with:

TypeError: can only concatenate str (not "NoneType") to str
  at autogen_ext/models/azure/_azure_ai_client.py line ~550

This occurs because tool_call_chunk.id, tool_call_chunk.function.name, or tool_call_chunk.function.arguments can be None in streamed deltas from Azure AI (GitHub Models / Azure AI Foundry).

Root Cause

The Azure client unconditionally concatenates these fields:

full_tool_calls[idx].id += tool_call_chunk.id
full_tool_calls[idx].name += tool_call_chunk.function.name
full_tool_calls[idx].arguments += tool_call_chunk.function.arguments

Solution

Add None guards before concatenation, matching the pattern already used in the OpenAI client:

if tool_call_chunk.id is not None:
    full_tool_calls[idx].id += tool_call_chunk.id
if tool_call_chunk.function is not None:
    if tool_call_chunk.function.name is not None:
        full_tool_calls[idx].name += tool_call_chunk.function.name
    if tool_call_chunk.function.arguments is not None:
        full_tool_calls[idx].arguments += tool_call_chunk.function.arguments

Testing

This fix follows the same pattern as the OpenAI client (_openai_client.py lines 986-993), which already handles None values correctly.

Environment

  • Windows 11
  • Python 3.13
  • autogen-ext 0.7.5
  • Using GitHub Models via Azure AI Foundry endpoint

Fixes #7157

When streaming tool calls via AzureAIChatCompletionClient, the delta can
have None values for id, function.name, or function.arguments. This
causes a TypeError when concatenating strings.

This fix adds None guards before concatenation, matching the pattern
already used in the OpenAI client implementation.

Fixes microsoft#7157
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.

AzureAIChatCompletionClient streaming tool_calls can include None fields, causing TypeError

1 participant