Python: Propagate conversation_id in Agent-as-Tool scenarios#3889
Open
giles17 wants to merge 4 commits intomicrosoft:mainfrom
Open
Python: Propagate conversation_id in Agent-as-Tool scenarios#3889giles17 wants to merge 4 commits intomicrosoft:mainfrom
conversation_id in Agent-as-Tool scenarios#3889giles17 wants to merge 4 commits intomicrosoft:mainfrom
Conversation
conversation_id in Agent-as-Tool scenariosconversation_id in Agent-as-Tool scenarios
Member
Python Test Coverage Report •
Python Unit Test Overview
|
||||||||||||||||||||||||||||||||||||||||||||||||||
Contributor
There was a problem hiding this comment.
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'sconversation_idand pass it to sub-agents viaadditional_function_arguments - Updated
_auto_invoke_functionto forwardconversation_idto 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation and Context
When using the Agent-as-Tool pattern (a coordinator agent invoking sub-agents as tools), the parent agent's
conversation_idis 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
**kwargsforwarding pipeline (additional_function_arguments→_auto_invoke_function→ tool**kwargs) to propagateconversation_idfrom parent to child agents.Closes #3411
Description
Contribution Checklist