Add AG2 multi-agent tutorial - #49
Conversation
📝 WalkthroughWalkthroughA new AG2 (formerly AutoGen) multi-agent tutorial has been added to the repository, including a main README entry, tutorial documentation, a Jupyter notebook with step-by-step examples, an executable Python application demonstrating multi-agent orchestration with tool registration, and supporting configuration files. ChangesAG2 multi-agent tutorial
Sequence Diagram(s)sequenceDiagram
participant User
participant Manager as GroupChatManager
participant Planner as Planner Agent
participant Researcher as Researcher Agent
participant Writer as Writer Agent
participant Reviewer as Reviewer Agent
participant Tool as Tool Registry
User->>Manager: Initiate chat with query
Manager->>Manager: Select next speaker (auto mode)
activate Manager
Manager->>Planner: Execute turn
Planner->>Manager: Message/plan
Manager->>Manager: Select next speaker
Manager->>Researcher: Execute turn
Researcher->>Tool: search_knowledge_base()
Tool->>Researcher: Results
Researcher->>Manager: Report findings
Manager->>Manager: Select next speaker
Manager->>Writer: Execute turn
Writer->>Tool: generate_report()
Tool->>Writer: Formatted report
Writer->>Manager: Submit draft
Manager->>Manager: Select next speaker
Manager->>Reviewer: Execute turn
Reviewer->>Manager: Feedback/approval
Manager->>Manager: Max rounds reached?
deactivate Manager
Manager->>User: Return final message
Estimated Code Review Effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Hi @NirDiamant 👋 Thanks for building such an amazing resource — Agents Towards Production is a fantastic playbook for the community! We're from the AG2 team (formerly AutoGen), and we'd love to contribute a tutorial covering AG2's approach to multi-agent systems. AG2 has 500K+ monthly PyPI downloads and takes a conversation-centric approach that's quite different from graph-based frameworks — we think it would be a great addition alongside the existing LangGraph tutorial. What this PR adds:
We followed the CONTRIBUTING.md guidelines (UTM links, required file structure, explanatory markdown before every code cell, etc.). Happy to iterate on any feedback! Best, |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
tutorials/ag2-multi-agent/app.py (1)
27-27: Consider validatingOPENAI_API_KEYenvironment variable.The script loads environment variables but doesn't validate that
OPENAI_API_KEYis set. Users will get a confusing error from the AG2/OpenAI client if the key is missing.💡 Proposed enhancement
load_dotenv() + +if not os.getenv("OPENAI_API_KEY"): + raise EnvironmentError( + "OPENAI_API_KEY not found. Copy .env.example to .env and add your key." + )🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tutorials/ag2-multi-agent/app.py` at line 27, After calling load_dotenv(), add a validation check for the OPENAI_API_KEY environment variable (via os.getenv or similar) and fail fast with a clear error message if it's missing; update the startup flow (around load_dotenv()) so that when OPENAI_API_KEY is None or empty you log/raise a descriptive error and exit (e.g., raise RuntimeError or sys.exit(1)) to avoid confusing downstream AG2/OpenAI client errors.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@README.md`:
- Around line 548-554: The badge <img> tags are missing alt text; update the two
image elements (the NEW badge img with src
"https://img.shields.io/badge/NEW-brightgreen" and the GitHub badge img with src
"https://img.shields.io/badge/GitHub-View-blue") to include descriptive alt
attributes (e.g., alt="New tutorial" and alt="View on GitHub") so screen readers
can announce the badges.
In `@tutorials/ag2-multi-agent/README.md`:
- Line 1: The analytics tracking image uses markdown with no alt text
(``);
update that markdown to include an explicit empty alt attribute (e.g., change to
`` is not ideal — instead use `` or replace with HTML `<img
src="https://europe-west1-atp-views-tracker.cloudfunctions.net/working-analytics?notebook=tutorials--ag2-multi-agent--readme"
alt="" />`) so the tracking pixel is marked decorative and accessible.
---
Nitpick comments:
In `@tutorials/ag2-multi-agent/app.py`:
- Line 27: After calling load_dotenv(), add a validation check for the
OPENAI_API_KEY environment variable (via os.getenv or similar) and fail fast
with a clear error message if it's missing; update the startup flow (around
load_dotenv()) so that when OPENAI_API_KEY is None or empty you log/raise a
descriptive error and exit (e.g., raise RuntimeError or sys.exit(1)) to avoid
confusing downstream AG2/OpenAI client errors.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 15028284-d610-4451-a2fe-31654500b7e1
⛔ Files ignored due to path filters (1)
tutorials/ag2-multi-agent/assets/group-chat.pngis excluded by!**/*.png
📒 Files selected for processing (6)
README.mdtutorials/ag2-multi-agent/.env.exampletutorials/ag2-multi-agent/README.mdtutorials/ag2-multi-agent/ag2_tutorial.ipynbtutorials/ag2-multi-agent/app.pytutorials/ag2-multi-agent/requirements.txt
| @@ -0,0 +1,45 @@ | |||
|  | |||
There was a problem hiding this comment.
Add alt text to the analytics tracking image.
The tracking pixel lacks alt text. Even for tracking images, an empty alt (alt="") is recommended for accessibility compliance to indicate it's decorative.
🔧 Proposed fix
-
+Or use HTML for explicit empty alt:
<img src="https://europe-west1-atp-views-tracker.cloudfunctions.net/working-analytics?notebook=tutorials--ag2-multi-agent--readme" alt="" />🧰 Tools
🪛 markdownlint-cli2 (0.22.0)
[warning] 1-1: Images should have alternate text (alt text)
(MD045, no-alt-text)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@tutorials/ag2-multi-agent/README.md` at line 1, The analytics tracking image
uses markdown with no alt text
(``);
update that markdown to include an explicit empty alt attribute (e.g., change to
`` is not ideal — instead use `` or replace with HTML `<img
src="https://europe-west1-atp-views-tracker.cloudfunctions.net/working-analytics?notebook=tutorials--ag2-multi-agent--readme"
alt="" />`) so the tracking pixel is marked decorative and accessible.
NirDiamant
left a comment
There was a problem hiding this comment.
AG2 is a solid framework - a tutorial showing multi-agent coordination patterns would be a good addition.
Will review the notebook format and content quality.
|
hey @faridun-ag2 ! |
Add a comprehensive tutorial for AG2 (formerly AutoGen), covering conversation-centric multi-agent design, dual tool registration, GroupChat orchestration with automatic speaker selection, and production safety patterns. Tested and working with AG2 0.11.4.
- Add alt text to AG2 tutorial badges in README for accessibility - Validate OPENAI_API_KEY at startup in app.py with a clear error - Remove stray logs.txt run artifact
c6297f2 to
ddb6e18
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@tutorials/ag2-multi-agent/ag2_tutorial.ipynb`:
- Around line 70-77: The prose currently tells readers to pass llm_config to
each agent but the example omits it for UserProxyAgent; update the explanation
to state that llm_config is required only for LLM-backed agents (e.g.,
AssistantAgent) and is optional/omitted for proxy or non-LLM agents (e.g.,
UserProxyAgent), and add a short clarifying sentence next to the example
referencing AssistantAgent and UserProxyAgent by name so readers understand why
llm_config appears for one and not the other.
- Line 7: Replace the decorative markdown image token
""
with an explicit empty-alt HTML image tag (e.g. <img
src="https://europe-west1-atp-views-tracker.cloudfunctions.net/working-analytics?notebook=tutorials--ag2-multi-agent--ag2-tutorial"
alt=""/>) so the tracking pixel is still present but accessibility/lint checks
see an explicit alt="".
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 9acc6bc5-1c72-46b5-87b2-acd956c81489
⛔ Files ignored due to path filters (1)
tutorials/ag2-multi-agent/assets/group-chat.pngis excluded by!**/*.png
📒 Files selected for processing (6)
README.mdtutorials/ag2-multi-agent/.env.exampletutorials/ag2-multi-agent/README.mdtutorials/ag2-multi-agent/ag2_tutorial.ipynbtutorials/ag2-multi-agent/app.pytutorials/ag2-multi-agent/requirements.txt
✅ Files skipped from review due to trivial changes (1)
- tutorials/ag2-multi-agent/.env.example
🚧 Files skipped from review as they are similar to previous changes (2)
- tutorials/ag2-multi-agent/requirements.txt
- tutorials/ag2-multi-agent/app.py
| "cell_type": "markdown", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "\n", |
There was a problem hiding this comment.
Add explicit empty alt text for the tracking pixel.
This image is decorative, but  still trips accessibility/lint checks. Use an explicit empty alt or HTML with alt="".
🔧 Proposed fix
-
+<img src="https://europe-west1-atp-views-tracker.cloudfunctions.net/working-analytics?notebook=tutorials--ag2-multi-agent--ag2-tutorial" alt="" />🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@tutorials/ag2-multi-agent/ag2_tutorial.ipynb` at line 7, Replace the
decorative markdown image token
""
with an explicit empty-alt HTML image tag (e.g. <img
src="https://europe-west1-atp-views-tracker.cloudfunctions.net/working-analytics?notebook=tutorials--ag2-multi-agent--ag2-tutorial"
alt=""/>) so the tracking pixel is still present but accessibility/lint checks
see an explicit alt="".
| "source": "---\n\n## Part 1: Two-Agent Conversation\n\nAG2's fundamental pattern is a conversation between two agents:\n\n- **AssistantAgent** — LLM-powered agent that reasons and generates responses\n- **UserProxyAgent** — represents the human, can execute tools and provide input\n\nThis is the building block for all AG2 applications. Pass `llm_config` to each agent to configure which LLM it uses." | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": "assistant = AssistantAgent(\n name=\"Assistant\",\n system_message=(\n \"You are a helpful research assistant. Provide clear, well-structured \"\n \"answers with key facts and actionable insights.\"\n ),\n llm_config=llm_config,\n)\n\nuser_proxy = UserProxyAgent(\n name=\"User\",\n human_input_mode=\"NEVER\", # Automated mode (no manual input)\n max_consecutive_auto_reply=1,\n code_execution_config=False,\n)" |
There was a problem hiding this comment.
Tighten the llm_config guidance.
The prose says to pass llm_config to each agent, but the example intentionally omits it for UserProxyAgent. Clarify that only LLM-backed agents need it.
✏️ Proposed wording change
-Pass `llm_config` to each agent to configure which LLM it uses.
+Pass `llm_config` to each LLM-backed agent to configure which LLM it uses.📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| "source": "---\n\n## Part 1: Two-Agent Conversation\n\nAG2's fundamental pattern is a conversation between two agents:\n\n- **AssistantAgent** — LLM-powered agent that reasons and generates responses\n- **UserProxyAgent** — represents the human, can execute tools and provide input\n\nThis is the building block for all AG2 applications. Pass `llm_config` to each agent to configure which LLM it uses." | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": "assistant = AssistantAgent(\n name=\"Assistant\",\n system_message=(\n \"You are a helpful research assistant. Provide clear, well-structured \"\n \"answers with key facts and actionable insights.\"\n ),\n llm_config=llm_config,\n)\n\nuser_proxy = UserProxyAgent(\n name=\"User\",\n human_input_mode=\"NEVER\", # Automated mode (no manual input)\n max_consecutive_auto_reply=1,\n code_execution_config=False,\n)" | |
| "source": "---\n\n## Part 1: Two-Agent Conversation\n\nAG2's fundamental pattern is a conversation between two agents:\n\n- **AssistantAgent** — LLM-powered agent that reasons and generates responses\n- **UserProxyAgent** — represents the human, can execute tools and provide input\n\nThis is the building block for all AG2 applications. Pass `llm_config` to each LLM-backed agent to configure which LLM it uses." | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": "assistant = AssistantAgent(\n name=\"Assistant\",\n system_message=(\n \"You are a helpful research assistant. Provide clear, well-structured \"\n \"answers with key facts and actionable insights.\"\n ),\n llm_config=llm_config,\n)\n\nuser_proxy = UserProxyAgent(\n name=\"User\",\n human_input_mode=\"NEVER\", # Automated mode (no manual input)\n max_consecutive_auto_reply=1,\n code_execution_config=False,\n)" |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@tutorials/ag2-multi-agent/ag2_tutorial.ipynb` around lines 70 - 77, The prose
currently tells readers to pass llm_config to each agent but the example omits
it for UserProxyAgent; update the explanation to state that llm_config is
required only for LLM-backed agents (e.g., AssistantAgent) and is
optional/omitted for proxy or non-LLM agents (e.g., UserProxyAgent), and add a
short clarifying sentence next to the example referencing AssistantAgent and
UserProxyAgent by name so readers understand why llm_config appears for one and
not the other.
Summary
app.pywith CLI (default,--query,--interactivemodes)What's included
tutorials/ag2-multi-agent/— complete tutorial folderTutorial Contents
register_for_llm+register_for_executionpatternTest plan
pip install -r requirements.txtsucceeds (Python 3.10+)python app.pyruns default demo querypython app.py --query "test"runs custom querypython app.py --interactivestarts conversation loopSummary by CodeRabbit
New Features
Documentation
Chores