Skip to content

Conversation

@dmytrostruk
Copy link
Member

Motivation and Context

Resolves: #3101

There was a change added recently that enabled kwargs propagation within as_tool() logic for user-defined runtime context (e.g. api_token, session_id etc):

async def agent_wrapper(**kwargs: Any) -> str:
"""Wrapper function that calls the agent."""
# Extract the input from kwargs using the specified arg_name
input_text = kwargs.get(arg_name, "")
# Forward all kwargs except the arg_name to support runtime context propagation
forwarded_kwargs = {k: v for k, v in kwargs.items() if k != arg_name}
if stream_callback is None:
# Use non-streaming mode
return (await self.run(input_text, **forwarded_kwargs)).text

When a parent agent delegates to a nested agent via as_tool(), the parent's conversation_id is being forwarded. The conversation_id is set in kwargs during function invocation loop:

def _update_conversation_id(kwargs: dict[str, Any], conversation_id: str | None) -> None:

The nested agent accepts conversation_id and attempts to perform API calls on the parent's conversation, which is in a "waiting for tool outputs" state, resulting in:

Error code: 400 - {'error': {'message': 'No tool output found for function call call_xxx'}}

This PR excludes conversation_id from forwarded kwargs in as_tool() method, allowing nested agent to run a new conversation.

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.

@dmytrostruk dmytrostruk self-assigned this Jan 17, 2026
Copilot AI review requested due to automatic review settings January 17, 2026 10:16
@markwallace-microsoft markwallace-microsoft added the documentation Improvements or additions to documentation label Jan 17, 2026
@markwallace-microsoft
Copy link
Member

markwallace-microsoft commented Jan 17, 2026

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/core/agent_framework
   _agents.py3055581%51, 90, 96, 99, 102, 404–406, 452, 506, 649, 818, 821–823, 940–943, 945, 948–950, 1051, 1092, 1094, 1103–1108, 1114, 1116, 1126–1127, 1134, 1136–1137, 1145–1149, 1157–1158, 1160, 1165, 1167, 1201, 1246–1247, 1249, 1251, 1262
TOTAL17429266384% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
3149 213 💤 0 ❌ 0 🔥 1m 6s ⏱️

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

This PR fixes a bug where conversation_id was being forwarded from parent agents to nested agents when using the agent-as-tool pattern, causing "No tool output found" API errors. The fix excludes conversation_id from kwargs propagation in the as_tool() method, allowing nested agents to run their own conversations independently.

Changes:

  • Modified as_tool() in _agents.py to filter out conversation_id from forwarded kwargs
  • Added a test case to verify conversation_id is not forwarded to sub-agents
  • Added two new sample files demonstrating the agent-as-tool pattern for OpenAI and Azure AI

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
python/packages/core/agent_framework/_agents.py Updated kwargs filtering to exclude both arg_name and conversation_id from forwarded kwargs
python/packages/core/tests/core/test_as_tool_kwargs_propagation.py Added test case verifying conversation_id exclusion while confirming other kwargs are still forwarded
python/samples/getting_started/agents/openai/openai_responses_client_with_agent_as_tool.py New sample demonstrating agent-as-tool pattern with OpenAI Responses Client
python/samples/getting_started/agents/openai/README.md Added entry for the new OpenAI agent-as-tool sample
python/samples/getting_started/agents/azure_ai/azure_ai_with_agent_as_tool.py New sample demonstrating agent-as-tool pattern with Azure AI
python/samples/getting_started/agents/azure_ai/README.md Added entry for the new Azure AI agent-as-tool sample

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: [Issue]: Do we have any Python samples showing how to use agents as tools with Azure AI V2 (azure-ai-projects 2.x)?

2 participants