GroupChat is a powerful multi-agent management system that coordinates multiple agents in collaborative conversations. It manages speaking order, routes messages between agents, and supports both AI agents and human participants.
GroupChat is ideal for complex workflows that benefit from specialized agents working together, such as code review teams, research discussions, or customer support scenarios.
from qwen_agent.agents import GroupChatconfig = { 'background': 'Customer support team', 'agents': [ { 'name': 'SupportBot', 'description': 'AI assistant for common questions', 'instructions': 'Help customers with common questions' }, { 'name': 'HumanAgent', 'description': 'Human support specialist', 'is_human': True } ]}group = GroupChat( agents=config, agent_selection_method='auto', llm={'model': 'qwen-max', 'model_type': 'qwen_dashscope'})# When HumanAgent is selected, the system will wait for inputmessages = [{'role': 'user', 'content': 'I need help with my order'}]for response in group.run(messages=messages): if 'PENDING_USER_INPUT' in str(response): # Prompt human for input human_input = input('Human Agent: ') messages.append({'role': 'user', 'content': human_input, 'name': 'HumanAgent'}) else: print(response)
from qwen_agent.agents import GroupChat, Assistant# Create specialized agentsresearcher = Assistant( llm={'model': 'qwen-max', 'model_type': 'qwen_dashscope'}, name='Researcher', description='Finds and analyzes information using web search', function_list=['web_search'], system_message='You are a research specialist. Find relevant information and cite sources.')analyst = Assistant( llm={'model': 'qwen-max', 'model_type': 'qwen_dashscope'}, name='Analyst', description='Analyzes data and creates visualizations', function_list=['code_interpreter'], system_message='You are a data analyst. Analyze data and create clear visualizations.')writer = Assistant( llm={'model': 'qwen-max', 'model_type': 'qwen_dashscope'}, name='Writer', description='Writes clear, engaging content', system_message='You are a technical writer. Create clear, well-structured content.')reviewer = Assistant( llm={'model': 'qwen-max', 'model_type': 'qwen_dashscope'}, name='Reviewer', description='Reviews work and provides feedback', system_message='You are an editor. Review content for accuracy and clarity.')# Create groupteam = GroupChat( agents=[researcher, analyst, writer, reviewer], agent_selection_method='auto', llm={'model': 'qwen-max', 'model_type': 'qwen_dashscope'})# Run collaborative taskmessages = [{ 'role': 'user', 'content': 'Research the growth of renewable energy, analyze trends, and write a report'}]for response in team.run(messages=messages): agent_name = response[-1].get('name', 'Unknown') content = response[-1]['content'] print(f"\n{agent_name}:\n{content}\n{'-'*50}")