Files
litellm/tests/test_litellm/completion_extras
Felipe Felix 504c70f4e0 fix(responses-api): return finish_reason='tool_calls' when response.completed contains function_call items (#19745)
When using the Responses API (e.g., Azure gpt-5.1-codex-mini), the response.completed
event was always returning finish_reason='stop', even when the response contained
function_call items in its output. This caused agents like OpenCode to incorrectly
conclude the stream ended without tools to execute, breaking tool/function calling
workflows.

The fix inspects the response.output field in the response.completed event to determine
the correct finish_reason:
- 'tool_calls' when output contains function_call items
- 'stop' otherwise (text-only responses)

Added tests to verify:
- response.completed with function_call output returns finish_reason='tool_calls'
- response.completed with message-only output returns finish_reason='stop'
- response.completed with empty output returns finish_reason='stop' (backward compat)

Co-authored-by: Krish Dholakia <krrishdholakia@gmail.com>
2026-02-16 09:19:57 -08:00
..