AutoGen SelectorGroupChat Not Maintaining Agent Continuity for Health-Related Chat Flow #5683
Replies: 4 comments 5 replies
-
Also created this - #5535 |
Beta Was this translation helpful? Give feedback.
-
Hi @glarunsingh, Why can't you try RoundRobinGroupChat? supervisor_agent summary_agent takes the response from both agents and responds with the most accurate answer based on the history. as shown here: https://github.com/iamchandanys/chatbot-az-autogen/blob/main/03-x-agent.py |
Beta Was this translation helpful? Give feedback.
-
Can custom See SelectorGroupChat's custom selector function: https://microsoft.github.io/autogen/dev/user-guide/agentchat-user-guide/selector-group-chat.html#custom-selector-function |
Beta Was this translation helpful? Give feedback.
-
Hey @ekzhu, i have achieved the flow using the SelectorGroupChat itself. it really worked. However, i want to call a agent after a function/tool is returned the response. how to achieve that? basically i have this function calling def vitals_check(): I have this agent: When the function returns the vitals, that information should pass into the symptom_checker_agent and should suggest whether the vitals or normal or not. (.venv) ar20572127@FVFHXFN8Q6LR Autogen_Zoe % python3 app_autogenv0.4_enhancements.py Could you please tell me more about this headache? How severe is it on a scale of 1 to 10, and where exactly is it located? Would you like to go ahead and check your vitals? I recommend reaching out to a healthcare professional immediately to review these findings, as they may require prompt attention. In the above conversation, it is not happening. It returned the response to me and i'm manually asking it the model should shouldn't be our scenario. I tried using the selector_func but it is not working: def selector_func(messages: Sequence[AgentEvent | ChatMessage]) -> str | None: Can you help here please |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm building a simple chat application using AutoGen with Flask-SocketIO (
async_mode='eventlet'
) to integrate real-time communication. The setup includes two agents: aSupervisorAgent
(for routing and general queries) and aHealthcareAgent
(for health-related queries). The goal is a seamless health-focused conversation where:SupervisorAgent
only responds to the initial message (e.g., greeting) or explicit non-health topic shifts (e.g., "What’s the time?").HealthcareAgent
handles all health-related messages and their follow-ups once a health topic is introduced, based on conversation history.However, the
SelectorGroupChat
inconsistently routes follow-up messages. After an initial health-related message (e.g., "I have a headache"), subsequent responses like "It’s mild around my temples" or "Yes to light" are sometimes routed toSupervisorAgent
instead ofHealthcareAgent
, disrupting the conversation flow. TheSupervisorAgent
shouldn’t comment during health discussions—it should silently route toHealthcareAgent
.Scenario
User: I have a headache
Healthcare: How would you describe the headache—sharp, dull, or throbbing?
User: It’s mild around my temples
Healthcare: Thanks for the details. How long has it lasted?
User: Yes to light
Healthcare: Sensitivity to light could indicate a migraine. How long has it been?
SupervisorAgent
interrupts health follow-ups with routing messages like "Please wait for the HealthcareAgent," even though the context is clearly health-related.Current Response
Here’s the latest terminal output I’m getting:
Running updated script with improved selector logic
(17019) wsgi starting up on http://127.0.0.1:5000
...
Result: TaskResult(messages=[TextMessage(source='user', ..., content='i have head ache', ...), TextMessage(source='HealthcareAgent', ..., content="I'm sorry to hear that. How would you describe the headache—sharp, dull, or throbbing? And how long have you been experiencing it?", ...)], stop_reason='Maximum number of turns 1 reached.')
user: i have head ache
Healthcare: I'm sorry to hear that. How would you describe the headache—sharp, dull, or throbbing? And how long have you been experiencing it?
Result: TaskResult(messages=[TextMessage(source='user', ..., content='its mild around my temples', ...), TextMessage(source='SupervisorAgent', ..., content='Please wait for the HealthcareAgent to assist you with that.', ...)], stop_reason='Maximum number of turns 1 reached.')
user: its mild around my temples
Supervisor: Please wait for the HealthcareAgent to assist you with that.
Result: TaskResult(messages=[TextMessage(source='user', ..., content='ok', ...), TextMessage(source='HealthcareAgent', ..., content='Mild headaches around the temples can be due to tension or stress. Have you experienced any other symptoms, like sensitivity to light or nausea?', ...)], stop_reason='Maximum number of turns 1 reached.')
user: ok
Healthcare: Mild headaches around the temples can be due to tension or stress. Have you experienced any other symptoms, like sensitivity to light or nausea?
Result: TaskResult(messages=[TextMessage(source='user', ..., content='yes to light', ...), TextMessage(source='SupervisorAgent', ..., content='Please continue discussing your symptoms with the HealthcareAgent for proper guidance.', ...)], stop_reason='Maximum number of turns 1 reached.')
user: yes to light
Supervisor: Please continue discussing your symptoms with the HealthcareAgent for proper guidance.
What’s Happening
Initial Health Query: "i have head ache" correctly triggers HealthcareAgent.
Follow-Up Issues: "its mild around my temples" and "yes to light" are routed to SupervisorAgent, which responds with routing messages instead of letting HealthcareAgent continue seamlessly.
Selector Failure: Despite a refined selector_prompt emphasizing {history} and agent stickiness, the selector still picks SupervisorAgent for health follow-ups, suggesting a deeper issue with how SelectorGroupChat interprets context or applies the prompt.
Possible Solutions to Triage
I’ve tried refining the selector_prompt multiple times, but the issue persists. Could the community suggest:
Prompt Optimization: Is there a more effective selector_prompt to ensure HealthcareAgent persists for health-related follow-ups without SupervisorAgent interrupting? Perhaps a stricter syntax or additional context cues?
Manual State Tracking: Should I bypass SelectorGroupChat’s built-in selector and implement a manual state tracker (e.g., a variable tracking the current topic) to force HealthcareAgent after a health topic starts? How would this integrate with team.run?
Alternative Approach: Would using team.run_stream with explicit agent selection (instead of team.run with a selector) provide better control over agent continuity? Any examples of this approach?
Debugging Selector Decisions: Is there a way to log the selector’s reasoning (e.g., why it chose SupervisorAgent) to diagnose its logic? This could help pinpoint where it’s misinterpreting {history}.
Any insights or code snippets to triage this would be greatly appreciated! I’d like to avoid SupervisorAgent responses entirely once a health topic is active, ensuring a smooth chat flow with HealthcareAgent.
Current Code
Here’s the simplified code I’m using:
Beta Was this translation helpful? Give feedback.
All reactions