autogen-development
Expert guidance for Microsoft AutoGen multi-agent framework development including agent creation, conversations, tool integration, and orchestration patterns.
What this skill does
# AutoGen Multi-Agent Development
You are an expert in Microsoft AutoGen, a framework for building multi-agent AI systems with Python, focusing on agent orchestration, tool integration, and scalable AI applications.
## Key Principles
- Write concise, technical responses with accurate Python examples
- Use async/await patterns for agent communication
- Implement proper error handling and logging
- Follow event-driven architecture patterns
- Use type hints for all function signatures
## Setup and Installation
### Environment Setup
```python
# Install AutoGen
# pip install autogen-agentchat autogen-ext
from autogen_agentchat.agents import AssistantAgent
from autogen_agentchat.teams import RoundRobinGroupChat
from autogen_ext.models.openai import OpenAIChatCompletionClient
```
### Model Configuration
```python
import os
# Configure the model client
model_client = OpenAIChatCompletionClient(
model="gpt-4o",
api_key=os.environ.get("OPENAI_API_KEY")
)
```
## Core Concepts
### Agent Types
AutoGen provides several agent types:
- **AssistantAgent**: AI-powered agent for conversations and task completion
- **UserProxyAgent**: Represents human users, can execute code
- **GroupChat**: Orchestrates multi-agent conversations
- **ConversableAgent**: Base class for custom agents
## Creating Agents
### Basic Assistant Agent
```python
from autogen_agentchat.agents import AssistantAgent
from autogen_ext.models.openai import OpenAIChatCompletionClient
model_client = OpenAIChatCompletionClient(model="gpt-4o")
assistant = AssistantAgent(
name="assistant",
model_client=model_client,
system_message="""You are a helpful AI assistant.
Provide clear, concise responses.
Ask clarifying questions when needed."""
)
```
### Agent with Tools
```python
from autogen_agentchat.agents import AssistantAgent
from autogen_core.tools import FunctionTool
def search_database(query: str) -> str:
"""Search the database for information.
Args:
query: The search query string
Returns:
Search results as a string
"""
# Implementation
return f"Results for: {query}"
def calculate(expression: str) -> str:
"""Evaluate a mathematical expression.
Args:
expression: Mathematical expression to evaluate
Returns:
The result of the calculation
"""
try:
result = eval(expression)
return str(result)
except Exception as e:
return f"Error: {str(e)}"
# Create tools
search_tool = FunctionTool(search_database, description="Search the database")
calc_tool = FunctionTool(calculate, description="Perform calculations")
# Create agent with tools
agent = AssistantAgent(
name="tool_agent",
model_client=model_client,
tools=[search_tool, calc_tool],
system_message="You are an assistant with access to search and calculation tools."
)
```
## Multi-Agent Conversations
### Two-Agent Chat
```python
from autogen_agentchat.agents import AssistantAgent
from autogen_agentchat.conditions import TextMentionTermination
from autogen_agentchat.teams import RoundRobinGroupChat
# Create agents
researcher = AssistantAgent(
name="researcher",
model_client=model_client,
system_message="You are a research assistant. Gather and analyze information."
)
writer = AssistantAgent(
name="writer",
model_client=model_client,
system_message="You are a technical writer. Create clear documentation."
)
# Create termination condition
termination = TextMentionTermination("TASK_COMPLETE")
# Create group chat
team = RoundRobinGroupChat(
[researcher, writer],
termination_condition=termination
)
# Run the conversation
async def run_team():
result = await team.run(task="Research and document Python best practices")
return result
```
### Group Chat with Multiple Agents
```python
from autogen_agentchat.teams import SelectorGroupChat
from autogen_agentchat.conditions import MaxMessageTermination
# Create specialized agents
planner = AssistantAgent(
name="planner",
model_client=model_client,
system_message="You are a project planner. Break down tasks and create plans."
)
coder = AssistantAgent(
name="coder",
model_client=model_client,
system_message="You are a software developer. Write clean, efficient code."
)
reviewer = AssistantAgent(
name="reviewer",
model_client=model_client,
system_message="You are a code reviewer. Review code for quality and best practices."
)
# Selector-based group chat
team = SelectorGroupChat(
[planner, coder, reviewer],
model_client=model_client,
termination_condition=MaxMessageTermination(20)
)
```
## Code Execution
### Setting Up Code Execution
```python
from autogen_ext.code_executors.local import LocalCommandLineCodeExecutor
from autogen_agentchat.agents import AssistantAgent
# Create code executor
code_executor = LocalCommandLineCodeExecutor(
work_dir="./workspace",
timeout=60
)
# Agent that can execute code
coding_agent = AssistantAgent(
name="coder",
model_client=model_client,
code_executor=code_executor,
system_message="""You are a Python developer.
Write code to solve problems.
Test your code before providing final answers."""
)
```
### Docker-Based Execution
```python
from autogen_ext.code_executors.docker import DockerCommandLineCodeExecutor
# Secure code execution in Docker
docker_executor = DockerCommandLineCodeExecutor(
image="python:3.11-slim",
timeout=120,
work_dir="./workspace"
)
```
## Conversation Patterns
### Sequential Workflow
```python
from autogen_agentchat.teams import Swarm
from autogen_agentchat.agents import AssistantAgent
# Define agents for each step
analyst = AssistantAgent(
name="analyst",
model_client=model_client,
handoffs=["developer"],
system_message="Analyze requirements and hand off to developer."
)
developer = AssistantAgent(
name="developer",
model_client=model_client,
handoffs=["tester"],
system_message="Implement the solution and hand off to tester."
)
tester = AssistantAgent(
name="tester",
model_client=model_client,
system_message="Test the implementation and report results."
)
# Create swarm for handoff-based workflow
team = Swarm([analyst, developer, tester])
```
### Hierarchical Structure
```python
# Manager agent that coordinates others
manager = AssistantAgent(
name="manager",
model_client=model_client,
system_message="""You are a project manager.
Coordinate between team members.
Delegate tasks appropriately.
Synthesize results into final deliverables."""
)
# Worker agents
workers = [
AssistantAgent(name="researcher", model_client=model_client, ...),
AssistantAgent(name="analyst", model_client=model_client, ...),
AssistantAgent(name="writer", model_client=model_client, ...)
]
```
## Memory and State
### Conversation Memory
```python
from autogen_agentchat.messages import TextMessage
# Agents maintain conversation history automatically
# Access through the team's message history
async def run_with_memory():
result = await team.run(task="Initial task")
# Continue with context
result = await team.run(task="Follow-up question")
# Access message history
for message in result.messages:
print(f"{message.source}: {message.content}")
```
## Event-Driven Architecture
### Custom Event Handling
```python
from autogen_core import Event
# Subscribe to events
async def on_message_received(event: Event):
print(f"Message received: {event.data}")
# Events enable reactive patterns
# - Agent activation
# - Tool execution
# - Error handling
# - State changes
```
## Error Handling
### Robust Agent Design
```python
from autogen_agentchat.agents import AssistantAgent
import logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
async def safe_run_team(team, task: str, max_retries: int = 3):
"""Run team with error handling anRelated in AI Agents
skill-development
IncludedComprehensive meta-skill for creating, managing, validating, auditing, and distributing Claude Code skills and slash commands (unified in v2.1.3+). Provides skill templates, creation workflows, validation patterns, audit checklists, naming conventions, YAML frontmatter guidance, progressive disclosure examples, and best practices lookup. Use when creating new skills, validating existing skills, auditing skill quality, understanding skill architecture, needing skill templates, learning about YAML frontmatter requirements, progressive disclosure patterns, tool restrictions (allowed-tools), skill composition, skill naming conventions, troubleshooting skill activation issues, creating custom slash commands, configuring command frontmatter, using command arguments ($ARGUMENTS, $1, $2), bash execution in commands, file references in commands, command namespacing, plugin commands, MCP slash commands, Skill tool configuration, or deciding between skills vs slash commands. Delegates to docs-management skill for official documentation.
reprompter
IncludedTransform messy prompts into well-structured, effective prompts — single or multi-agent. Use when: "reprompt", "reprompt this", "clean up this prompt", "structure my prompt", rough text needing XML tags and best practices, "reprompter teams", "repromptception", "run with quality", "smart run", "smart agents", multi-agent tasks, audits, parallel work, anything going to agent teams. Don't use when: simple Q&A, pure chat, immediate execution-only tasks. See "Don't Use When" section for details. Outputs: Structured XML/Markdown prompt, quality score (before/after), optional team brief + per-agent sub-prompts, agent team output files. Success criteria: Single mode quality score ≥ 7/10; Repromptception per-agent prompt quality score 8+/10; all required sections present, actionable and specific.
adaptive-compaction
IncludedAdaptive add-on policy and recovery layer that decides WHEN to compact, prune, snapshot, or fork -- replacing fixed-percent auto-compaction across Claude Code, Codex, and MCP-capable hosts. Trigger on auto-compact timing or damage: "when should I compact", "is it safe to compact now or start a fresh session", "auto-compact fires too early/mid-task", "switching to an unrelated task but the window still has space", "context rot", "answers get worse the longer the session runs", "the agent forgot the plan or my decisions after it summarized", "add a layer on top that manages context without changing the agent", raising autoCompactWindow to give the policy room, or installing/tuning a cross-tool compaction policy or PreCompact hook -- even when "compaction" is never said but the problem is context-window pressure or post-summarization memory loss. Do NOT use to summarize a conversation, build RAG, write a summarization prompt (decides WHEN not HOW), or answer max-context-length trivia.
agent-skill-creator
IncludedCreate cross-platform agent skills from workflow descriptions. Activates when users ask to create an agent, automate a repetitive workflow, create a custom skill, or need advanced agent creation. Triggers on phrases like create agent for, automate workflow, create skill for, every day I have to, daily I need to, turn process into agent, need to automate, create a cross-platform skill, validate this skill, export this skill, migrate this skill. Supports single skills, multi-agent suites, transcript processing, template-based creation, interactive configuration, cross-platform export, and spec validation.
llm-wiki
IncludedUse when building or maintaining a persistent personal knowledge base (second brain) in Obsidian where an LLM incrementally ingests sources, updates entity/concept pages, maintains cross-references, and keeps a synthesis current. Triggers include "second brain", "Obsidian wiki", "personal knowledge management", "ingest this paper/article/book", "build a research wiki", "compound knowledge", "Memex", or whenever the user wants knowledge to accumulate across sessions instead of being re-derived by RAG on every query.
skill-master
IncludedAgent Skills authoring, evaluation, and optimization. Create, edit, validate, benchmark, and improve skills following the agentskills.io specification. Use when designing SKILL.md files, structuring skill folders (references, scripts, assets), ingesting external documentation into skills, running trigger evals, benchmarking skill quality, optimizing descriptions, or performing blind A/B comparisons. Keywords: agentskills.io, SKILL.md, skill authoring, eval, benchmark, trigger optimization.