← All trails
EP 04 / 236:24Live now

Two Agents, One Loop

The two-agent pattern, an executor and a planner pass control back and forth.

The simplest multi-agent system has just two players: a planner that decides and a proxy/executor that acts and reports back.

This is the canonical 'agent + human-in-the-loop' shape, and it's also the foundation for every more complex pattern in this season.

What we build: a planner agent that writes Python, a UserProxyAgent that runs it in a sandboxed working directory, and a feedback loop that lets the planner read errors and try again.

Heads up: code execution is powerful and dangerous. We use a working directory + Docker by default. Episode 17 covers safe execution properly.

Links

Code

from autogen import ConversableAgent, UserProxyAgent

planner = ConversableAgent(
    name="planner",
    llm_config={"model": "gpt-4o"},
    system_message="You write Python. Print output. Stop on TERMINATE.",
)

executor = UserProxyAgent(
    name="executor",
    human_input_mode="NEVER",
    code_execution_config={"work_dir": "out", "use_docker": True},
    is_termination_msg=lambda m: "TERMINATE" in m.get("content", ""),
)

executor.initiate_chat(
    planner,
    message="Build a script that summarizes this CSV: data/sales.csv",
)