Orchestrate multi-agent workflows using Microsoft AutoGen v0.4 with role-based task delegation, conversation patterns, and collaborative problem solving
/autogen-workflow--coding--agents="architect,coder,reviewer,tester""Build a user authentication system with OAuth2 support"
Command Content (3)
Additional code example for this command.
autogen-workflow.py
python
#GeneratedAutoGenv0.4workflowfromautogen_agentchat.agentsimportAssistantAgentfromautogen_agentchat.teamsimportRoundRobinGroupChatfromautogen_agentchat.conditionsimportMaxMessageTermination,TextMentionTerminationfromautogen_ext.modelsimportOpenAIChatCompletionClient#Configuremodelclientmodel_client=OpenAIChatCompletionClient(model="gpt-4o",temperature=0.7,)#Definespecializedagentsarchitect_agent=AssistantAgent(name="Architect",model_client=model_client,system_message=""" You are a software architect specializing in authentication systems. Your role is to: 1. Design the system architecture 2. Define data models and API contracts 3. Identify security requirements 4. Create technical specifications Focus on scalability, security, and best practices.""",description="Designs system architecture and technical specifications",)coder_agent=AssistantAgent(name="Coder",model_client=model_client,system_message=""" You are an expert full-stack developer. Your role is to: 1. Implement the architecture designed by the Architect 2. Write production-ready, type-safe code 3. Follow SOLID principles and design patterns 4. Add comprehensive error handling Use TypeScript, React, and Node.js.""",description="Implements the technical specifications",)reviewer_agent=AssistantAgent(name="Reviewer",model_client=model_client,system_message=""" You are a senior code reviewer and security expert. Your role is to: 1. Review code for security vulnerabilities 2. Ensure code quality and maintainability 3. Verify adherence to best practices 4. Identify potential bugs and edge cases Be thorough and constructive in your feedback.""",description="Reviews code quality and security",)tester_agent=AssistantAgent(name="Tester",model_client=model_client,system_message=""" You are a QA engineer specializing in test automation. Your role is to: 1. Write comprehensive test suites 2. Create unit, integration, and E2E tests 3. Identify test scenarios and edge cases 4. Ensure high code coverage Use Jest, Vitest, and Playwright.""",description="Creates comprehensive test suites",)#Createteamwithround-robinconversationpatternteam=RoundRobinGroupChat(participants=[architect_agent,coder_agent,reviewer_agent,tester_agent],max_turns=3,)#Defineterminationconditionstermination=MaxMessageTermination(max_messages=20)|TextMentionTermination("TASK_COMPLETE")#Runworkflowasyncdefrun_auth_workflow():result=awaitteam.run(task=""" Build a user authentication system with OAuth2 support. Requirements: 1. Support email/password and OAuth2 (Google, GitHub) 2. JWT-based session management 3. Role-based access control (RBAC) 4. Rate limiting and brute force protection 5. PKCE flow for OAuth2 6. Comprehensive test coverage Architect: Start by designing the system architecture.""",termination_condition=termination,)print("Workflow completed!")print(f"Messages exchanged: {len(result.messages)}")print(f"Final result: {result.messages[-1].content}")#Executeimportasyncioasyncio.run(run_auth_workflow())
Command Content (4)
Additional code example for this command.
autogen-workflow.txt
/autogen-workflow--research--agents="researcher,analyst,synthesizer"--tools="web-search""Analyze the current state of edge computing in 2025"
Command Content (5)
Additional code example for this command.
autogen-workflow.py
python
fromautogen_agentchat.agentsimportAssistantAgentfromautogen_agentchat.teamsimportSwarmfromautogen_agentchat.messagesimportHandoffMessagefromautogen_ext.toolsimportWebSearchTool#Initializetoolsweb_search_tool=WebSearchTool()#Researchagentwithwebsearchcapabilityresearcher_agent=AssistantAgent(name="Researcher",model_client=model_client,tools=[web_search_tool],system_message=""" You are a research specialist. Your role is to: 1. Search for relevant information using web search 2. Gather data from multiple sources 3. Identify key trends and developments 4. Compile raw research findings Be thorough and cite your sources.""",handoffs=["Analyst"],)#Analystagentanalyst_agent=AssistantAgent(name="Analyst",model_client=model_client,system_message=""" You are a data analyst and industry expert. Your role is to: 1. Analyze research findings 2. Identify patterns and insights 3. Evaluate market trends 4. Provide data-driven conclusions Focus on quantitative and qualitative analysis.""",handoffs=["Synthesizer"],)#Synthesizeragentsynthesizer_agent=AssistantAgent(name="Synthesizer",model_client=model_client,system_message=""" You are a technical writer and synthesizer. Your role is to: 1. Combine research and analysis into coherent report 2. Present findings in clear, structured format 3. Highlight key takeaways 4. Provide actionable recommendations Create executive summaries and detailed reports.""",)#Createswarmwithhandoffsteam=Swarm(participants=[researcher_agent,analyst_agent,synthesizer_agent],)asyncdefrun_research_workflow():result=awaitteam.run(task=""" Analyze the current state of edge computing in 2025. Focus on: 1. Market size and growth trends 2. Major players and technologies 3. Use cases and adoption rates 4. Future predictions Researcher: Begin by gathering data from multiple sources.""",termination_condition=TextMentionTermination("RESEARCH_COMPLETE"),)returnresult
fromautogen_agentchat.agentsimportAssistantAgentfromautogen_agentchat.teamsimportSelectorGroupChatfromautogen_ext.toolsimportFileReadTool,GrepTool#Toolsforcodeanalysisfile_read_tool=FileReadTool()grep_tool=GrepTool()#Securityauditorsecurity_agent=AssistantAgent(name="SecurityAuditor",model_client=model_client,tools=[file_read_tool,grep_tool],system_message=""" You are a security auditor specializing in OWASP Top 10. Review code for: 1. SQL injection vulnerabilities 2. XSS prevention 3. Authentication/authorization flaws 4. Sensitive data exposure 5. Security misconfigurations Provide specific recommendations for fixes.""",)#Performancereviewerperformance_agent=AssistantAgent(name="PerformanceReviewer",model_client=model_client,tools=[file_read_tool],system_message=""" You are a performance optimization expert. Review code for: 1. Inefficient algorithms 2. Memory leaks 3. Database query optimization 4. Caching opportunities 5. Resource usage Suggest performance improvements.""",)#Stylecheckerstyle_agent=AssistantAgent(name="StyleChecker",model_client=model_client,tools=[file_read_tool],system_message=""" You are a code quality expert. Review code for: 1. Adherence to style guide 2. Code readability 3. Proper error handling 4. Documentation completeness 5. Best practices Ensure maintainable, clean code.""",)#Createselector-basedteam(eachagentreviewsinparallel)team=SelectorGroupChat(participants=[security_agent,performance_agent,style_agent],model_client=model_client,selector_prompt="Select the agent that should review next based on the code aspect being discussed.",)asyncdefrun_review_workflow(file_path:str):result=awaitteam.run(task=f""" Review the authentication middleware at {file_path}. Each agent should: 1. Read the file 2. Analyze their specific area 3. Provide detailed findings 4. Suggest improvements Provide a comprehensive review report.""",termination_condition=MaxMessageTermination(max_messages=15),)returnresult
Command Content (8)
Additional code example for this command.
autogen-workflow.txt
/autogen-workflow--debug--agents="debugger,root-cause-analyst,fixer"--human-in-loop"Investigate failing user login tests"
Command Content (9)
Additional code example for this command.
autogen-workflow.py
python
fromautogen_agentchat.agentsimportAssistantAgentfromautogen_agentchat.teamsimportRoundRobinGroupChatfromautogen_ext.toolsimportShellTool,FileReadTool,FileWriteTool#Toolsfordebuggingshell_tool=ShellTool()file_read_tool=FileReadTool()file_write_tool=FileWriteTool()#Debuggeragentdebugger_agent=AssistantAgent(name="Debugger",model_client=model_client,tools=[shell_tool,file_read_tool],system_message=""" You are a debugging expert. Your role is to: 1. Reproduce the failing tests 2. Analyze error messages and stack traces 3. Identify symptoms of the issue 4. Gather relevant logs and data Use systematic debugging techniques.""",)#Rootcauseanalystanalyst_agent=AssistantAgent(name="RootCauseAnalyst",model_client=model_client,tools=[file_read_tool],system_message=""" You are a root cause analysis expert. Your role is to: 1. Analyze debugging findings 2. Identify the root cause of the issue 3. Consider all contributing factors 4. Explain the issue clearly Use the 5 Whys technique.""",)#Fixeragent(requireshumanapproval)fixer_agent=AssistantAgent(name="Fixer",model_client=model_client,tools=[file_write_tool,shell_tool],system_message=""" You are a senior developer who implements fixes. Your role is to: 1. Implement the fix based on root cause analysis 2. Write or update tests 3. Verify the fix resolves the issue 4. Ensure no regressions Request human approval before making changes.""",)team=RoundRobinGroupChat(participants=[debugger_agent,analyst_agent,fixer_agent],max_turns=2,)asyncdefrun_debug_workflow():result=awaitteam.run(task=""" Investigate and fix the failing user login tests. Steps: 1. Debugger: Run tests and gather error information 2. RootCauseAnalyst: Identify the root cause 3. Fixer: Implement fix (wait for human approval) Ensure all tests pass after the fix.""",termination_condition=TextMentionTermination("TESTS_PASSING"),)returnresult
#Sequentialpatternfromautogen_agentchat.teamsimportRoundRobinGroupChatteam=RoundRobinGroupChat(participants=[agent1,agent2,agent3],max_turns=2,#Eachagentspeakstwice)#Swarmwithhandoffsfromautogen_agentchat.teamsimportSwarmteam=Swarm(participants=[agent1,agent2,agent3],#Handoffsdefinedinagentsystemmessages)#Selector-based(dynamic)fromautogen_agentchat.teamsimportSelectorGroupChatteam=SelectorGroupChat(participants=[agent1,agent2,agent3],model_client=model_client,selector_prompt="Choose the best agent for the current task.",)
Features
Key capabilities and functionality
Multi-agent orchestration with 5+ conversation patterns (RoundRobinGroupChat, Swarm, SelectorGroupChat, sequential, hierarchical) for flexible workflow design
Role-based agent specialization with custom system messages, tool assignments, and handoff capabilities for complex task delegation
Workflow type templates for common scenarios (research, coding, review, debug, planning) with pre-configured agent roles and patterns
Tool integration support for web-search, file operations, shell commands, and custom tools with selective agent access control
Human-in-loop approval system for critical actions (deployments, deletions) with timeout and fallback mechanisms
Termination condition management with MaxMessageTermination, TextMentionTermination, and custom conditions to prevent infinite loops
Model flexibility supporting OpenAI, Azure OpenAI, Claude, and Gemini with configurable temperature, max_tokens, and API versions
Use Cases
Common scenarios and applications
Software development workflows - Orchestrate architect, coder, reviewer, and tester agents for end-to-end feature development with code generation, review, and testing
Research and analysis pipelines - Deploy researcher, analyst, and synthesizer agents with web-search tools to gather, analyze, and compile comprehensive reports
Code review automation - Parallel security auditor, performance reviewer, and style checker agents analyze code from multiple perspectives simultaneously
Debugging workflows - Coordinate debugger, root-cause analyst, and fixer agents with shell and file tools to systematically identify and resolve issues
Project planning and architecture - Multi-agent collaboration for technical design, requirement analysis, and architecture documentation
Quality assurance automation - Automated test generation, code coverage analysis, and regression testing with specialized QA agents
Documentation generation - Technical writer, reviewer, and formatter agents collaborate to create comprehensive documentation from code and specifications
Requirements
Prerequisites and dependencies
Create .claude/commands/ directory in project root (mkdir -p .claude/commands)
Create autogen-workflow.md file in .claude/commands/ directory with command instructions
Claude Code 1.0+ required for slash command support
Systematic debugging workflow with human-in-loop approval for fixes, ensuring safety before applying changes
debugging-workflow-with-human-approval.txt
plaintext
/autogen-workflow--debug--agents="debugger,root-cause-analyst,fixer"--human-in-loop"Investigate failing user login tests"
Project planning workflow
Hierarchical planning workflow with specialized agents for project planning, architecture design, and effort estimation
project-planning-workflow.txt
plaintext
/autogen-workflow--planning--agents="planner,architect,estimator"--conversation-pattern="hierarchical""Plan migration from monolith to microservices"
Custom model configuration
Custom workflow with specific model configuration, temperature tuning, and round limits for controlled agent interactions
custom-model-configuration.txt
plaintext
/autogen-workflow--coding--model="claude-sonnet-4"--temperature="0.3"--max-rounds="15"--agents="coder,reviewer""Implement REST API endpoints"
Swarm pattern with handoffs
Swarm conversation pattern with agent handoffs and multiple tools for complex research and documentation tasks
swarm-pattern-with-handoffs.txt
plaintext
/autogen-workflow--research--agents="researcher,analyst,synthesizer"--conversation-pattern="swarm"--tools="web-search,file-ops""Research and document API best practices"
Set termination conditions: use MaxMessageTermination(max_messages=20) | TextMentionTermination('TASK_COMPLETE'). Check max_turns in team config. Add explicit termination phrase to agent instructions.
Agents fail to handoff with 'handoffs not recognized' error
Verify AutoGen v0.4+ installed: pip show autogen-agentchat. Handoffs require Swarm team pattern. Check agent handoffs=["AgentName"] matches exactly. Use RoundRobinGroupChat for sequential turns instead.
Enable async messaging: use asyncio.run() wrapper. Check network latency to model API. Reduce max_tokens if excessive. AutoGen v0.4 reports 30% latency reduction vs v0.2; verify version migration complete.
Implement timeout for approval requests: use asyncio.wait_for(user_approval(), timeout=300). Add fallback: if timeout, default to safe action or abort. Log approval requests: track pending approvals in dashboard.
Cross-language agent communication fails between Python and .NET
Verify message serialization: AutoGen v0.4 uses JSON protocol. Check encoding matches: UTF-8 required. Use explicit message types: TextMessage, HandoffMessage. Test locally: start .NET agent with --test-mode flag.