-
Notifications
You must be signed in to change notification settings - Fork 1k
Python: Filter conversation_id when passing kwargs to agent as tool #3266
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Python Test Coverage Report •
Python Unit Test Overview
|
||||||||||||||||||||||||||||||
There was a problem hiding this 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.pyto filter outconversation_idfrom forwarded kwargs - Added a test case to verify
conversation_idis 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 |
python/samples/getting_started/agents/openai/openai_responses_client_with_agent_as_tool.py
Outdated
Show resolved
Hide resolved
python/samples/getting_started/agents/azure_ai/azure_ai_with_agent_as_tool.py
Outdated
Show resolved
Hide resolved
Co-authored-by: Copilot <[email protected]>
…client_with_agent_as_tool.py Co-authored-by: Copilot <[email protected]>
…gent_as_tool.py Co-authored-by: Copilot <[email protected]>
Motivation and Context
Resolves: #3101
There was a change added recently that enabled
kwargspropagation withinas_tool()logic for user-defined runtime context (e.g. api_token, session_id etc):agent-framework/python/packages/core/agent_framework/_agents.py
Lines 468 to 478 in 9e3b2fa
When a parent agent delegates to a nested agent via
as_tool(), the parent'sconversation_idis being forwarded. Theconversation_idis set inkwargsduring function invocation loop:agent-framework/python/packages/core/agent_framework/_tools.py
Line 1743 in 9e3b2fa
The nested agent accepts
conversation_idand attempts to perform API calls on the parent's conversation, which is in a "waiting for tool outputs" state, resulting in:This PR excludes
conversation_idfrom forwarded kwargs inas_tool()method, allowing nested agent to run a new conversation.Contribution Checklist