Skip to content

Python: Propagate conversation_id in Agent-as-Tool scenarios#3889

Open
giles17 wants to merge 4 commits intomicrosoft:mainfrom
giles17:agent_run_context_v2
Open

Python: Propagate conversation_id in Agent-as-Tool scenarios#3889
giles17 wants to merge 4 commits intomicrosoft:mainfrom
giles17:agent_run_context_v2

Conversation

@giles17
Copy link
Contributor

@giles17 giles17 commented Feb 12, 2026

Motivation and Context

When using the Agent-as-Tool pattern (a coordinator agent invoking sub-agents as tools), the parent agent's conversation_id is not propagated to sub-agents. This makes it impossible to correlate the full multi-agent interaction chain using a single identifier for persistence or observability.

Solution

Leverage the existing **kwargs forwarding pipeline (additional_function_arguments_auto_invoke_function → tool **kwargs) to propagate conversation_id from parent to child agents.

Closes #3411

Description

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.

Copilot AI review requested due to automatic review settings February 12, 2026 17:30
@markwallace-microsoft markwallace-microsoft added documentation Improvements or additions to documentation python labels Feb 12, 2026
@github-actions github-actions bot changed the title Propagate conversation_id in Agent-as-Tool scenarios Python: Propagate conversation_id in Agent-as-Tool scenarios Feb 12, 2026
@markwallace-microsoft
Copy link
Member

markwallace-microsoft commented Feb 12, 2026

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/core/agent_framework
   _agents.py3303589%474, 905, 942, 1042–1044, 1157, 1198, 1200, 1209–1214, 1220, 1222, 1232–1233, 1240, 1242–1243, 1251–1255, 1263–1264, 1266, 1271, 1273, 1307, 1347, 1367
   _mcp.py4066484%104–105, 115–120, 131, 136, 182–183, 193–198, 208–209, 261, 270, 333, 341, 362, 476, 543, 578, 580, 584–585, 587–588, 642, 657, 675, 716, 822, 835–840, 862, 899–900, 906–908, 927, 952–953, 957–961, 978–982, 1126
   _tools.py7578488%175–176, 306, 308, 326–328, 335, 353, 367, 379, 384, 386, 393, 430, 453–455, 504–506, 569, 591, 615–641, 676, 684, 925, 1187, 1244, 1248, 1327–1331, 1349, 1351–1352, 1464, 1468, 1518, 1520, 1536, 1538, 1602, 1629, 1686, 1754, 1933–1934, 1962, 1970, 1983, 1993–1994, 2029, 2086, 2118
packages/core/agent_framework/azure
   _responses_client.py51688%189, 221, 287–290
TOTAL21270327684% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
4107 225 💤 0 ❌ 0 🔥 1m 9s ⏱️

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 implements conversation ID propagation in Agent-as-Tool scenarios to enable correlation of multi-agent interactions. When a parent agent invokes a sub-agent as a tool, the parent's conversation_id is now automatically forwarded to the sub-agent via additional_function_arguments with the key parent_conversation_id. This solves issue #3411 where multi-agent conversations couldn't be correlated using a single identifier.

Changes:

  • Modified as_tool() wrapper to extract parent's conversation_id and pass it to sub-agents via additional_function_arguments
  • Updated _auto_invoke_function to forward conversation_id to tools instead of filtering it out
  • Added logic to populate additional_function_arguments["conversation_id"] when chat API returns a conversation ID
  • Added comprehensive test coverage for the new functionality
  • Included a well-documented sample demonstrating the feature

Reviewed changes

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

Show a summary per file
File Description
python/packages/core/agent_framework/_agents.py Modified as_tool() wrapper to propagate parent's conversation_id to sub-agent via additional_function_arguments with key parent_conversation_id
python/packages/core/agent_framework/_tools.py Removed conversation_id from filter list in _auto_invoke_function to allow forwarding; added conversation_id to additional_function_arguments when received from chat API
python/packages/core/tests/core/test_as_tool_kwargs_propagation.py Added tests for conversation_id propagation via options and handling when absent
python/packages/core/tests/core/test_agents.py Added tests for conversation_id propagation in agent-as-tool scenarios
python/packages/core/tests/core/test_tools.py Added tests for conversation_id forwarding and internal kwargs filtering
python/samples/getting_started/tools/agent_as_tool_conversation_id_propagation.py New comprehensive sample demonstrating conversation_id propagation with observability middleware
python/samples/getting_started/tools/README.md Added entry documenting the new sample
python/packages/core/agent_framework/_mcp.py Code formatting improvements (multi-line json.dumps calls)
python/packages/core/agent_framework/azure/_responses_client.py Code formatting improvements (line breaking)
python/packages/core/tests/core/test_mcp.py Alphabetical import reordering

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.

.NET: ConversationId not propagated in Agent-as-a-Tool scenarios

2 participants