Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
A direct command skips the review prompt. Inspect the source before running it.
Step-by-step workflow for building an AG2 multi-agent group chat
license
Apache-2.0
Build a Group Chat
Step 1: Imports
from ag2 import LLMConfig
from ag2.agentchat import AssistantAgent, UserProxyAgent
from ag2.agentchat.group import run_group_chat, DefaultPattern, Handoff
Step 2: Create Agents
Define agents inside an LLMConfig context manager. Give each agent a distinct role.
with LLMConfig(api_type="openai", model="gpt-4o"):
planner = AssistantAgent(
name="planner",
system_message=(
"You break down user requests into actionable steps. ""Hand off to coder when the plan is ready."
),
)
coder = AssistantAgent(
name="coder",
system_message=(
"You write Python code based on the plan. ""Hand off to reviewer when code is complete."
),
)
reviewer = AssistantAgent(
name="reviewer",
system_message=(
"You review code for correctness and style. "
),
)
executor = UserProxyAgent(
name=,
human_input_mode=,
)
"If changes are needed, hand off to coder. "
"If the code is correct, reply with TERMINATE."
"executor"
"NEVER"
Step 3: Choose a Pattern
DefaultPattern with handoffs (recommended)
Agents explicitly hand off to the next speaker. You define allowed transitions.
result = run_group_chat(
pattern=pattern,
messages="Build a CLI tool that converts CSV files to JSON.",
)
Complete Example
from ag2 import LLMConfig
from ag2.agentchat import AssistantAgent, UserProxyAgent
from ag2.agentchat.group import run_group_chat, DefaultPattern, Handoff
with LLMConfig(api_type="openai", model="gpt-4o"):
planner = AssistantAgent(
name="planner",
system_message="You create step-by-step plans. Hand off to coder when ready.",
)
coder = AssistantAgent(
name="coder",
system_message="You implement code from plans. Hand off to reviewer when done.",
)
reviewer = AssistantAgent(
name="reviewer",
system_message=(
"You review code quality. Hand off to coder for fixes. ""Reply TERMINATE when approved."
),
)
executor = UserProxyAgent(name="executor", human_input_mode="NEVER")
pattern = DefaultPattern(
initial_agent=planner,
agents=[planner, coder, reviewer, executor],
handoffs=[
Handoff(source=planner, target=coder),
Handoff(source=coder, target=reviewer),
Handoff(source=reviewer, target=coder),
],
group_manager_args={"llm_config": LLMConfig(api_type="openai", model="gpt-4o")},
)
result = run_group_chat(
pattern=pattern,
messages="Build a function that merges two sorted lists.",
)