-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Description
What happened?
Description
When implementing a Human-in-the-Loop condition with MagenticOneGroupChat
, the group chat does not preserve conversation context after a handoff to the user. Instead, user input is treated as a completely new request.
This same setup works as expected with RoundRobinGroupChat
— the context is preserved and the team continues the conversation correctly after user input.
Code to Reproduce
agent.py
from urllib import response
from autogen_agentchat.teams import MagenticOneGroupChat, RoundRobinGroupChat
import httpx
from autogen_ext.models.openai import OpenAIChatCompletionClient
from autogen_agentchat.agents import AssistantAgent
from autogen_agentchat.messages import TextMessage
from dotenv import load_dotenv
import os
import asyncio
from typing import Optional, Dict
from autogen_agentchat.conditions import HandoffTermination, TextMentionTermination
from autogen_agentchat.base import Handoff
load_dotenv()
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
OPENAI_MODEL_NAME = os.getenv("OPENAI_MODEL_NAME")
httpx_client = httpx.AsyncClient(verify=False)
model_client = OpenAIChatCompletionClient(
model=OPENAI_MODEL_NAME,
api_key=OPENAI_API_KEY,
httpx=httpx_client
)
class HostAgent:
def __init__(self):
print("Initializing HostAgent...")
self.teams: Dict[str, MagenticOneGroupChat] = {}
self.context_id: Optional[str] = None
async def get_team(self, context_id):
self.context_id = context_id
if context_id in self.teams:
return self.teams[context_id]
host_agent = AssistantAgent(
"HostAgent",
model_client=model_client,
handoffs=[Handoff(target="user", message="Transfer to user.")],
system_message="You are an AI assistant agent. Your job is to answer the user's question. If you cannot complete the task, transfer to user. Otherwise, when finished, respond with 'TERMINATE'."
)
handoff_termination = HandoffTermination(target="user")
text_termination = TextMentionTermination("TERMINATE")
# Works as expected
# team = RoundRobinGroupChat([host_agent], description="Only perform the requested task.", termination_condition=handoff_termination | text_termination)
# Issue occurs here
team = MagenticOneGroupChat([host_agent], model_client=model_client, max_stalls=2, description="Only perform the requested task.", termination_condition=handoff_termination | text_termination)
self.teams[context_id] = team
return team
agent_chat.py
from autogen_agentchat.ui import Console
from agent import HostAgent
session_id = '112'
async def chat_loop():
agents = {}
while True:
task = input("User input : ")
if session_id not in agents:
agents[session_id] = HostAgent()
agent = agents[session_id]
team = await agent.get_team(session_id)
await Console(team.run_stream(task=task), output_stats=True)
if __name__ == "__main__":
import asyncio
asyncio.run(chat_loop())
Steps to Reproduce
-
Run
agent_chat.py
with RoundRobinGroupChat enabled inagent.py
.- Handoff to user works as expected.
- After user provides input, the team continues the conversation with context. ✅
-
Run the same setup but switch to MagenticOneGroupChat.
- Handoff to user works.
- After user provides input, the team forgets context and treats input as a completely new request. ❌
Expected Behavior
- After handoff, when the user provides input, the
MagenticOneGroupChat
should continue from the preserved state (same asRoundRobinGroupChat
), instead of resetting and treating input as a new conversation.
Actual Behavior
- With
MagenticOneGroupChat
, the orchestrator restarts the workflow after handoff, ignoring prior context.
Terminal Logs
Working (RoundRobinGroupChat
)
- Context preserved after handoff → team answers based on last message.
(Logs show successful handoff + contextual response)
Not Working (MagenticOneGroupChat
)
- Context lost after handoff → user input is treated as new request.
(Logs show orchestrator starting fresh planning phase for "Green" input)
Notes
- Tried
UserProxyAgent
earlier, but as documented it blocks execution until user input is received, which is not suitable for longer waits. - Documentation suggests
handoff termination
should allow saving and resuming team state, but this doesn’t seem to work withMagenticOneGroupChat
. - Both group chat types return the same stored team instance from memory — but only
RoundRobinGroupChat
preserves context.
Docs reference: Human-in-the-Loop tutorial
Request
Could you clarify if MagenticOneGroupChat
is expected to handle handoff-based Human-in-the-Loop the same way as RoundRobinGroupChat
? If so, this may be a bug in how team state is preserved after handoff.
Which packages was the bug in?
Python AgentChat (autogen-agentchat>=0.4.0)
AutoGen library version.
Python 0.7.4
Other library version.
No response
Model used
gpt-4o-mini
Model provider
OpenAI
Other model provider
No response
Python version
3.13
.NET version
None
Operating system
Windows