Skip to content

Add 14 MAS coding exercises (no CrewAI) + workshop refresh#9

Open
jayjirayut wants to merge 7 commits intokwarodom:masterfrom
jayjirayut:jayjirayut/week11-mas-exercises
Open

Add 14 MAS coding exercises (no CrewAI) + workshop refresh#9
jayjirayut wants to merge 7 commits intokwarodom:masterfrom
jayjirayut:jayjirayut/week11-mas-exercises

Conversation

@jayjirayut
Copy link
Copy Markdown
Contributor

What

Adds 14 hands-on multi-agent system coding exercises (Beginner → Expert)
in a tiered folder structure under week11/exercises/, plus refreshes
the three week9/ workshop exercises to drop CrewAI. The five exercises
that originally specified CrewAI now use a dataclass Agent + raw
Anthropic SDK pattern instead. Adds architecture diagrams for Ex 13
(autonomous research agent with tool use).

Why

  • Smaller dependency surface. Dropping CrewAI removes ~70
    transitive packages from the venv (crewai + crewai-tools pull in
    chromadb, lancedb, instructor, etc.) without losing any coordination
    pattern the exercises teach.
  • Direct coordination mechanics. The dataclass Agent pattern
    exposes how output flows agent-to-agent in 3 lines instead of hiding
    it inside Process.sequential — better for understanding what's
    actually happening.
  • Modern AutoGen. PDF code uses AutoGen v0.2
    (import autogen; autogen.GroupChat), which doesn't resolve under
    the installed pyautogen 0.10. Ex 07 and Ex 14 are ported to the
    v0.4+ split-package API (autogen_agentchat.teams,
    autogen_ext.models.anthropic).
  • Visual mental model for the most complex exercise. Ex 13's
    Planner-Executor-Critic loop with bound tools is non-obvious from
    code alone — auto-generated topology + hand-authored architecture
    and sequence diagrams help.

Changes

week9/ — workshop refresh (commits 1–3)

File Change
verify_setup.py Switch import check from autogenautogen_agentchat
ex2_LangGraphSupportGraph.py Drop crewai import, switch LLM to ChatAnthropic
ex3_ParallelSwarm.py Drop crewai import, keep anthropic.AsyncAnthropic
requirements.txt Remove crewai>=1.13.0, crewai-tools>=1.13.0
ex1_sequential_pipeline.py (new) Pattern A — Researcher → Writer → Editor via dataclass Agent
ex2_graph_routing.py (new) Pattern B — LangGraph state-machine routing
ex3_parallel_swarm.py (new) Pattern C — asyncio.gather over 5 building-audit specialists

week11/exercises/ — 14 new exercises (commit 4)

Tier # File Framework
Beginner 01 ex01_two_agent_dialogue/ Anthropic
02 ex02_research_brief/ Anthropic (was CrewAI)
03 ex03_langgraph_router/ LangGraph
Easy 04 ex04_3agent_product_pipeline/ Anthropic (was CrewAI)
05 ex05_langgraph_faq_loop/ LangGraph
06 ex06_parallel_fact_checker/ Anthropic + asyncio
Intermediate 07 ex07_ag2_code_review/ AutoGen v0.4+
08 ex08_langgraph_escalation/ LangGraph
09 ex09_market_research_swarm/ Anthropic asyncio (was CrewAI)
Advanced 10 ex10_langgraph_self_healing/ LangGraph
11 ex11_negotiation_agents/ Anthropic
12 ex12_hybrid_energy_optimizer/ Anthropic + LangGraph (was CrewAI + LG)
Expert 13 ex13_autonomous_research/ LangGraph + tool_use
14 ex14_hotel_ops_command_center/ AutoGen + Anthropic (was AutoGen + CrewAI)

week11/exercises/README.md indexes all 14 with framework, key concept,
and setup instructions.

Ex 13 diagrams (commit 5)

  • graph.png (21 KB) + graph.mmd — auto-generated from
    graph.get_graph().draw_mermaid_png()
  • DIAGRAMS.md — three views: graph topology, system architecture
    (state schema + tool bindings), execution sequence

Validation

8 of 14 exercises run end-to-end against claude-haiku-4-5-20251001:

  • Ex 01 — 3-turn teacher/student dialogue, separate histories preserved
  • Ex 02 — Researcher → Writer pipeline, 9.3s linear (4.8 + 4.5)
  • Ex 03 — 3/3 tickets routed correctly at 95% confidence
  • Ex 06 — Confidence-weighted vote: false claim flagged FALSE @ 95% conf
  • Ex 07 — RoundRobinGroupChat: 12 pytest tests generated
  • Ex 08 — Triage routing: low→L1→L2, high→L2 direct, critical→Emergency
  • Ex 13 — All 3 tools fired (market_data, competitor_lookup, roi_calc)
  • Ex 14 — SelectorGroupChat over 5 dept agents, terminated on "BRIEFING COMPLETE"

Workshop refresh validated:

  • Ex 1 — 35.0s total (15.0 + 13.9 + 6.1, perfectly linear)
  • Ex 2 — 3/3 tickets routed at 95% confidence
  • Ex 3 — 4.4× speedup vs hypothetical sequential

Notes

  • Required env: ANTHROPIC_API_KEY (no other provider keys needed).
  • Required new package: autogen-ext[anthropic] (already added during
    development; not yet in requirements.txt — flagging as a known
    follow-up).
  • load_dotenv() walks up CWD, so exercises must be run from the repo
    root for .env to resolve. Documented in
    week11/exercises/README.md.

🤖 Generated with Claude Code

Jirayut Chatphet and others added 7 commits April 29, 2026 11:35
AutoGen v0.4 split the package into autogen_agentchat and autogen_core.
The bare `autogen` import no longer resolves under pyautogen 0.10, so
verify_setup.py fails 1/9 even on a healthy install. Switch the check to
autogen_agentchat (the installed top-level module) so verification
reflects reality.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The two state-machine and parallel-swarm workshop scripts no longer need
CrewAI — Ex 2 uses LangGraph + ChatAnthropic directly, Ex 3 uses
anthropic.AsyncAnthropic. Switching the LLM client to Claude removes a
heavy dependency tree (crewai + crewai-tools pull in ~70 transitive
packages) and aligns the workshop with the no-CrewAI direction of the
new exercises in this branch.

requirements.txt: drop crewai>=1.13.0 and crewai-tools>=1.13.0.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Reimplements the three Multi-Agent Systems workshop exercises (from
week9_2_multi_agent_theory_workshop.pdf) without CrewAI, exposing the
coordination mechanics directly:

- ex1_sequential_pipeline.py: Pattern A (organisational structuring) —
  Researcher -> Writer -> Editor chain via dataclass Agent + raw
  Anthropic SDK. Each agent's output is templated into the next agent's
  task; total time stacks linearly.

- ex2_graph_routing.py: Pattern B (centralised planning / Contract Net
  modern equivalent) — LangGraph state-machine routing with a classifier
  node + conditional edges to billing/technical/general specialists.
  Confidence score in shared state enables stretch goal kwarodom#1 (escalation).

- ex3_parallel_swarm.py: Pattern C (distributed sensing / stigmergy) —
  asyncio.gather across 5 building-audit specialists, with shared
  results list as the modern blackboard. Reports parallel vs hypothetical
  sequential time so the speedup is observable, not just claimed.

All three use claude-haiku-4-5-20251001 and write deterministic outputs
beside the script. Validated end-to-end: Ex 1 ran in 35.0s (15.0+13.9+
6.1, perfectly linear), Ex 2 routed 3/3 tickets at 95% confidence each,
Ex 3 hit 4.4x speedup vs sequential.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Implements all 14 hands-on exercises from week9/week9_3_mas_coding_
exercises.pdf, organised into a tiered folder structure under
week11/exercises/. Each exercise is self-contained in its own folder
(exNN_name/exNN_name.py).

Tiers and frameworks:

  Beginner — core concepts, raw API calls, 2-agent dialogues
    01 two_agent_dialogue        Anthropic
    02 research_brief            Anthropic (was CrewAI)
    03 langgraph_router          LangGraph

  Easy — 3-agent pipelines, state machines, parallel calls
    04 3agent_product_pipeline   Anthropic (was CrewAI)
    05 langgraph_faq_loop        LangGraph
    06 parallel_fact_checker     Anthropic + asyncio

  Intermediate — tool use, group chats, escalation logic
    07 ag2_code_review           AutoGen v0.4+
    08 langgraph_escalation      LangGraph
    09 market_research_swarm     Anthropic asyncio (was CrewAI)

  Advanced — self-healing, negotiation, hybrid frameworks
    10 langgraph_self_healing    LangGraph
    11 negotiation_agents        Anthropic
    12 hybrid_energy_optimizer   Anthropic + LangGraph (was CrewAI+LG)

  Expert — autonomous systems, long-horizon planning, full MAS
    13 autonomous_research       LangGraph + tool_use
    14 hotel_ops_command_center  AutoGen + Anthropic (was AutoGen+CrewAI)

Two deliberate deviations from the PDF:

1. No CrewAI. The five exercises that originally specified CrewAI
   (02, 04, 09, 12, 14) use a `dataclass Agent` with `system_prompt()`
   and `run()` methods instead, calling the Anthropic SDK directly. The
   coordination patterns (sequential pipelines, parallel-then-synthesis,
   nested sub-crews) are preserved without the framework dependency.

2. AutoGen v0.4+ instead of v0.2. The PDF code uses
   `import autogen; autogen.GroupChat`, which doesn't exist in the
   modern split-package release. Ex 07 uses
   `autogen_agentchat.teams.RoundRobinGroupChat`; Ex 14 uses
   `SelectorGroupChat` for LLM-driven turn taking.
   `autogen-ext[anthropic]` is now required.

Validation: 8 of 14 ran end-to-end against Claude Haiku 4.5 (Ex 01, 02,
03, 06, 07, 08, 13, 14). The remaining 6 use patterns already validated
by those runs.

README.md indexes all 14 exercises with framework, key concept, and
setup instructions.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Three views of the autonomous research agent (Planner-Executor-Critic
loop) for ex13_autonomous_research:

- graph.png + graph.mmd: auto-generated LangGraph topology via
  graph.get_graph().draw_mermaid_png(). Shows the planner ->
  researcher (self-loop) -> synthesiser -> critic -> finalise flow with
  conditional vs unconditional edges distinguished.

- DIAGRAMS.md: hand-authored architecture and sequence diagrams that
  surface what the auto-diagram cannot — the bound tools
  (market_data, competitor_lookup, roi_calc), the ResState TypedDict
  schema, and a step-by-step sequence of one execution. Tools aren't
  graph nodes (they're attached to the LLM via llm.bind_tools), so the
  auto-diagram alone doesn't tell the full story.

Sources:
- LangGraph 1.1.6 graph rendering API (draw_mermaid, draw_mermaid_png)
- mermaid.ink for PNG rendering (used by draw_mermaid_png by default)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Ex 07 (Code Review Committee) and Ex 14 (Hotel Ops Command Center) use
the modern AutoGen v0.4+ split-package API:
  - autogen-agentchat for AssistantAgent, RoundRobinGroupChat,
    SelectorGroupChat, MaxMessageTermination
  - autogen-ext[anthropic] for AnthropicChatCompletionClient

These were installed manually during development but never written to
requirements.txt, so a clean install would fail Ex 07 and Ex 14.

pyautogen>=0.10.0 is left in place — it's a stub package now, but
removing it is a separate concern.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Several exercises write their LLM output to disk for inspection
(e.g. ex02_brief_output.md, ex09_swarm_output.md, ex3_audit_output.json).
These are non-deterministic by design — every run produces different
phrasing, different findings — so committing them adds noise without
adding signal.

Patterns added:
  ex*_output.md          # ex02/04/09/12/14 brief/swarm/pipeline outputs
  ex*_output.json        # ex3_audit_output.json
  ex*_brief_output.md    # explicit pattern for brief outputs
  ex*_audit_output.*     # explicit pattern for audit outputs (md + json)

Deterministic outputs like Ex 13's graph.png and graph.mmd
(generated from graph structure, not LLM) are NOT ignored.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant