Skip to content

Conversation

@moonbox3
Copy link
Contributor

@moonbox3 moonbox3 commented Feb 4, 2026

Motivation and Context

When using the OpenAI Responses API with tool calls, the framework would fail with:

No tool call found for function call output with call_id <call_id>

This occurred in checkpoint/resume scenarios with handoff workflows, but could affect any multi-turn tool invocation.

In _tools.py, both function_invocation_wrapper and streaming_function_invocation_wrapper update kwargs with the new conversation_id after each API response, but the options dict (which is passed to subsequent API calls) was not being updated.

The flow:

  1. API call returns tool call + new response_id
  2. Framework invokes tool locally
  3. Next API call needs previous_response_id = new response_id to link the tool result
  4. Bug: options["conversation_id"] still had the OLD value
  5. API rejects: "that call_id doesn't exist in the response chain"

The fix:

Update options["conversation_id"] alongside kwargs when a new conversation_id is received:

 if response.conversation_id is not None:
     _update_conversation_id(kwargs, response.conversation_id)
     # Also update options dict so subsequent API calls use the new conversation_id
     if options is not None:
         options["conversation_id"] = response.conversation_id
     prepped_messages = []

Description

  • Fix conversation_id not updated in options during tool invocation loop

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.

@moonbox3 moonbox3 self-assigned this Feb 4, 2026
@moonbox3 moonbox3 added the python label Feb 4, 2026
Copilot AI review requested due to automatic review settings February 4, 2026 03:53
@moonbox3 moonbox3 added the agents Issues related to single agents label Feb 4, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes a tool-invocation loop bug where a newly returned conversation_id (from hosted/server-managed conversations such as OpenAI Responses) was applied to kwargs but not propagated into the options dict used for subsequent API calls, which could break multi-turn tool execution in checkpoint/resume workflows.

Changes:

  • Update options["conversation_id"] whenever a response returns a new conversation_id (non-streaming + streaming tool loops).
  • Add a regression test that verifies the updated conversation_id is used on the next iteration for both non-streaming and streaming flows.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
python/packages/core/agent_framework/_tools.py Ensures conversation_id updates are applied to options between tool-loop iterations so subsequent API calls remain on the correct server-side response chain.
python/packages/core/tests/core/test_function_invocation_logic.py Adds coverage proving the next API call receives the updated conversation_id after a tool-call response (streaming and non-streaming).

@markwallace-microsoft
Copy link
Member

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/core/agent_framework
   _tools.py7737290%226, 272, 323, 325, 353, 523, 558–559, 661, 663, 683, 701, 715, 727, 732, 734, 741, 774, 845–847, 888, 913–922, 928–937, 973, 981, 1222, 1559, 1646–1650, 1672–1673, 1789, 1791, 1857, 1949, 1955, 2000–2001, 2014–2015, 2058, 2142, 2223–2225, 2274, 2331–2332, 2339–2340
TOTAL16342197887% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
3823 221 💤 0 ❌ 0 🔥 1m 8s ⏱️

eavanvalkenburg added a commit to eavanvalkenburg/agent-framework that referenced this pull request Feb 4, 2026
…ations

Port test from PR microsoft#3664 with updates for new streaming API pattern.
Tests that conversation_id is properly updated in options dict during
function invocation loop iterations.
eavanvalkenburg added a commit to eavanvalkenburg/agent-framework that referenced this pull request Feb 4, 2026
When tool_choice is 'required', the user's intent is to force exactly one
tool call. After the tool executes, return immediately with the function
call and result - don't continue to call the model again.

This fixes integration tests that were failing with empty text responses
because with tool_choice=required, the model would keep returning function
calls instead of text.

Also adds regression tests for:
- conversation_id propagation between tool iterations (from PR microsoft#3664)
- tool_choice=required returns after tool execution
eavanvalkenburg added a commit to eavanvalkenburg/agent-framework that referenced this pull request Feb 4, 2026
…ations

Port test from PR microsoft#3664 with updates for new streaming API pattern.
Tests that conversation_id is properly updated in options dict during
function invocation loop iterations.
eavanvalkenburg added a commit to eavanvalkenburg/agent-framework that referenced this pull request Feb 4, 2026
When tool_choice is 'required', the user's intent is to force exactly one
tool call. After the tool executes, return immediately with the function
call and result - don't continue to call the model again.

This fixes integration tests that were failing with empty text responses
because with tool_choice=required, the model would keep returning function
calls instead of text.

Also adds regression tests for:
- conversation_id propagation between tool iterations (from PR microsoft#3664)
- tool_choice=required returns after tool execution
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Issues related to single agents python

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants