-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
Description
What happened?
When using HandoffBuilder with agents that have a context_provider configured, the context provider is silently ignored during the workflow execution. The issue occurs in the agent cloning logic at line 315 of python/packages/orchestrations/agent_framework_orchestrations/_handoff.py in the HandoffAgentExecutor._clone_chat_agent() method.
The code incorrectly uses context_providers= (plural) when passing the context provider to the cloned ChatAgent, but the ChatAgent constructor expects context_provider= (singular).
What did you expect to happen?
When a ChatAgent is created with a context_provider and passed to HandoffBuilder, the context provider should be preserved and function correctly throughout the handoff workflow. The cloned agents should maintain the same context provider as the original agent.
Steps to reproduce the issue
- Create a
ChatAgentwith acontext_provider(e.g., memory provider, RAG provider) - Pass the agent to
HandoffBuilderusing.participants()orregister_participants() - Build and run the workflow
- Observe that the context provider functionality is not working (e.g., memory not being retrieved, RAG not being used)
Code Sample
import asyncio
from agent_framework import ChatAgent, Context, ContextProvider, HandoffBuilder
from agent_framework.azure import AzureOpenAIChatClient
from azure.identity import AzureCliCredential
# Create custom context provider
class SimpleContextProvider(ContextProvider):
def __init__(self):
self.called = False
async def invoking(self, messages, **kwargs):
self.called = True
return Context(instructions="User name is John.")
async def run():
client = AzureOpenAIChatClient(credential=AzureCliCredential())
mem_provider = SimpleContextProvider()
# Create agent with context provider
agent = ChatAgent(
name="test_agent",
chat_client=client,
instructions="You are an assistant.",
context_provider=mem_provider
)
workflow = HandoffBuilder(participants=[agent]).with_start_agent(agent).build()
# Run workflow - context provider is not used
async for event in workflow.run_stream("What is my name?"):
if hasattr(event, 'data') and hasattr(event.data, 'text'):
print(event.data.text, end='', flush=True)
print(f"\n\nContext provider called: {mem_provider.called}")
asyncio.run(run())Bug location:
File: python/packages/orchestrations/agent_framework_orchestrations/_handoff.py
Line: 315
Current code (incorrect, context_providers parameter was renamed in PR #3139 ):
return ChatAgent(
chat_client=agent.chat_client,
id=agent.id,
name=agent.name,
description=agent.description,
chat_message_store_factory=agent.chat_message_store_factory,
context_providers=agent.context_provider,
middleware=middleware,
default_options=cloned_options,
)Error Messages / Stack Traces
No error is raised. This is a silent failure, the incorrect parameter name causes the context provider to be ignored without any warning, making the issue difficult to debug.Package Versions
agent-framework-core: 1.0.0b260130
Python Version
Python 3.12.10
Additional Context
No response
Metadata
Metadata
Assignees
Labels
Type
Projects
Status