Two agents that chat, one writing code and one running it, solved 69.48% of the MATH test set where plain GPT-4 solved 55.18%. They also cut one app's workflow code from 430 lines to 100.
Pick how the same task runs, then press Play the chat. Watch what a chat between agents can do that one model call cannot. Then we build, piece by piece, the agents, the auto-reply loop and the group chat behind it.
You need a rough idea of what a chatbot is and a little Python. We build the rest from zero.
Based on AutoGen: Enabling Next-Gen LLM Applications via Multi-Agent Conversation (arXiv 2308.08155) by Qingyun Wu, Gagan Bansal, Jieyu Zhang, Yiran Wu, Beibin Li, Erkang Zhu, Li Jiang, Xiaoyun Zhang, Shaokun Zhang, Jiale Liu, Ahmed Awadallah, Ryen W. White, Doug Burger and Chi Wang, of Microsoft Research, Penn State University, the University of Washington and Xidian University. It is a reading for Stanford CS 329Z, Lecture 8. Every idea is re-taught here in our own words and devices.
The task and the order of events are the paper's Figure 1: plot META and TESLA stock price change year to date, hit a missing package, fix it, then redirect from price to percent change. Message wording is shortened, and the counts (2, 6 and 9 messages) are this page's schematic of that figure, not a measured result.
Chapter 0
See why the person who copies code and errors back and forth is the real bottleneck, and what it means to hand that job to another agent
You ask a chat model: “Plot the stock price change of META and TESLA this year.” It answers with neat Python code. You paste the code into a terminal and run it. The terminal prints an error: a package called yfinance is not installed.
So you copy the error and paste it back into the chat. The model says sorry and tells you to install the package first. You install it, run the code again, and get a chart. But the chart shows dollars, and you wanted percent change. You type that into the chat, and the loop starts again.
Count your own work in that story. You carried code out, and you carried errors back. The model never saw its code run. You were the go-between, and you were slow.
What if a second program did the carrying? It would take the model’s code, run it, and send back whatever happened: the output or the error. The model would read that message and try again. Two programs would talk until the job was done, and you would watch.
That is the whole bet of this paper. The paper is AutoGen, an open-source library from Microsoft Research, Penn State University and others. A few words first, because the whole lesson uses them.
An LLM (large language model) is a program that reads text and writes the text that most likely comes next. A chat model is an LLM tuned to answer messages. An agent is a program that wraps an LLM, and sometimes tools, so it can act toward a goal instead of only answering once. Think of it as a chat model with hands. A multi-agent conversation is several agents sending messages to each other until the task is done.
The paper opens with a simple observation. Tasks for LLMs keep getting bigger. An easy way to scale up is to use several agents that cooperate. Earlier work had shown three benefits. Agents think in more varied ways (Liang et al.), reason better (Du et al.), and check each other’s work (Wu et al.).
The authors then give three reasons why conversation is the right glue. First, chat-tuned models such as GPT-4 can take feedback, so agents can critique and correct each other in messages. Second, one model with a different prompt can play a different role, so a chat between differently prompted agents combines skills in a modular way. Third, a model solves hard tasks better when the task is cut into smaller parts, and a conversation is a natural way to cut and rejoin them.
That leaves two design questions, and the paper builds its whole answer around them. How do you make one agent that is capable, reusable and easy to customize? And how do you give developers one simple interface for many chat patterns: a single reply or many turns, with or without a human, fixed order or flexible order?
The paper compares AutoGen with earlier tools in its Appendix A. Some are single-agent systems: AutoGPT, ChatGPT with plugins, LangChain agents and Transformers Agent. They give one model many tools, but they do not let several agents collaborate.
Others are multi-agent but narrow. BabyAGI passes work between agents in a fixed order. CAMEL lets two chat agents play roles, but it cannot run code. Multi-agent debate makes each agent a plain LLM call that argues in a set order, with no tools and no human. MetaGPT runs a software team of agents, but it is built for that one job. Use the device to see the gaps side by side.
Each column is a system, each row is an ability from the paper’s Table 1. Pick a system and see which abilities it has. Green means it has it.
The cells are the paper’s Table 1 (Appendix A). “Has it” here means a tick, “flexible” patterns, or human input with a skip option. The counts of abilities per system are this page’s tally of that table.
Read the AutoGen column against the others. Only AutoGen is general infrastructure, allows flexible chat patterns, runs code, and lets a human join the chat or skip it. Every other system has one of those four at most. The paper does not claim AutoGen invented any single ability. Its claim is that one small design gives all four together.
Let us count the hand-offs in the opening story, using made-up round numbers so the arithmetic is clear. Say the code needs 3 rounds to work: the first run fails on the missing package, the second fails on a typo, and the third works.
hand-offs by hand = 3 rounds × (1 code paste out + 1 error paste back) = 6
hand-offs with a user proxy agent = 0
The 6 is not the cost that matters. What matters is that each hand-off stops the loop until you act. With a proxy agent, the loop runs at machine speed, and you only step in when you choose. This is an illustrative count, not a result from the paper.
The instrument at the top of this page is a small version of the paper’s Figure 1. Each part of it gets its own chapter. First we cover what you need to know about chat models. Then the agent, then the loop that makes agents reply, then the examples the paper tested, with numbers.
Chapter 1
Learn what a chat model actually reads, why it forgets everything between calls, and why code it writes still needs someone to run it
Open any chat app and send two messages. Your second message can say “make it shorter”, and the bot knows what “it” means. It feels like the bot remembers you. It does not. Every time you press send, the app sends the whole conversation again, from the first message to the last.
This chapter teaches that one fact and one more: a chat model writes text, and it never runs anything. These two facts explain almost every design choice in AutoGen.
A chat model is an LLM tuned to continue a conversation. Its input is a list of messages. Each message has a role, a label that says who wrote it. Three roles cover almost everything: system for standing instructions from the builder, user for the person or program talking to the model, and assistant for the model’s own earlier replies.
The model reads the full list and writes one new assistant message. That is all it does. It has no memory outside the list, so the list is the memory. The paper calls the list an agent’s internal context: it “maintains its internal context based on sent and received messages”.
Here is the data flow as code. The structure below is the common shape of chat APIs, shown as a sketch. It is not AutoGen’s own source.
python# one call to a chat model: a list of role-tagged messages goes in, one string comes out chat = [ {"role": "system", "content": "You are a helpful AI assistant. Solve tasks using code."}, {"role": "user", "content": "Plot META and TESLA stock price change YTD."}, {"role": "assistant", "content": "```python\nimport yfinance as yf ...```"}, {"role": "user", "content": "Error: No module named 'yfinance'"}, ] reply = llm(chat) # -> "Sorry! Please first pip install yfinance and then execute the code" chat.append({"role": "assistant", "content": reply}) # the list is the only memory
Now put two agents in one chat. Whose message is a “user” message? It depends on who is reading. For the assistant agent, what the proxy sends is the user side, and what the assistant sent earlier is the assistant side. For a second LLM-backed agent in the same chat, the labels would flip.
So one chat becomes two lists, one per agent, with the same words and opposite labels. Drag the slider and watch both views grow. This role flip is the usual way to feed a shared chat to a chat model. The paper states only that each agent keeps its own context from messages it sent and received.
Left: what the assistant reads. Right: what a second LLM agent in the same chat would read. Drag the slider to add messages. Watch the labels flip, and watch the token count the assistant must re-read.
Illustrative sizes: a 100-token system message and messages of 40, 150, 60, 130, 70 and 5 tokens. The six messages follow the order of the hero chat. The flipped labels follow the usual chat-API convention; the paper itself says only that an agent keeps a context of messages it sent and received.
Because the whole list goes in on every call, a long chat costs more with each reply. Let S be the size of the system message in tokens. A token is a small piece of text, roughly a short word or part of a word. Let ti be the size of message i. When an agent writes its reply after m messages, it reads this many tokens.
Work the hero chat with the sizes in the device. The assistant’s first reply happens after m = 1 message (the 40-token task). So C1 = 100 + 40 = 140 tokens. Its second reply happens after m = 3 messages (task, code v1, error). So C2 = 100 + 40 + 150 + 60 = 350 tokens. The two calls together read 140 + 350 = 490 tokens, although the chat holds only 380 tokens of messages. Every message is read again on every later call.
Back to the stock chart. The assistant’s reply contains Python code. But a reply is only a string. The model has no Python interpreter, no network and no file system. When it writes plt.show(), nothing is shown.
Something outside the model has to take the string, find the code block, run it, and return what happened. That something is a tool: a program the agent can call. Running code is the most useful tool, because code can do almost anything else: fetch a web page, read a file, call an API. A related idea is function calling. The model writes a structured request such as “call ask_for_expert with this text”, and the host program runs that function and returns the result. Chapter 6 uses it.
The paper’s ethics statement names the risk plainly. Letting LLM agents change the outside world, for example by installing packages, “could be risky”. Whoever runs the proxy must decide what the code may touch. Treat any code a model wrote like code from a stranger.
Chapter 2
Build one agent class that can send, receive and answer messages, and give it any mix of a model, a human and a tool
Picture three coworkers in a team chat. One writes drafts. One runs the spreadsheet and reports the numbers. One is the boss, who reads the thread and says “yes” or “no, try again”. They all get the same kind of message, a block of text. Yet each one answers it in a different way.
AutoGen builds its agents on that picture. Every agent speaks the same message language. What differs is what the agent does when a message arrives.
The paper defines a conversable agent as an entity with a specific role that can pass messages to send and receive information to and from other conversable agents. It keeps an internal context built from the messages it sent and received. And it can be configured with a set of capabilities.
Three kinds of capability can be switched on, alone or together.
The first is an LLM. An LLM-backed agent can play a role, infer where a task stands from the chat history, give feedback, adapt to feedback, and write code. The paper also adds an inference layer around the model with result caching, error handling and message templating, so developers do not rebuild those each time.
The second is a human. A human-backed agent asks a real person for input at chosen moments. The default user proxy agent lets the developer set how often it asks, and under what conditions, including the option for the person to skip.
The third is a tool. A tool-backed agent can run code, or run a function the model asked for. The default user proxy does this: it executes code that an LLM suggested, or makes an LLM-suggested function call.
The paper ships a small family of classes, drawn in the top of its Figure 2. ConversableAgent sits at the top. By default it can use an LLM, a human and tools. The other classes are pre-set versions of it.
Why a pair of presets? Because two jobs come up in almost every application: a brain that writes, and a pair of hands that acts. The first is the assistant. The second is the proxy. It is called a proxy because it acts on behalf of the user, either by asking the user or by running tools for them.
All agents share three functions, which the paper calls the unified conversation interface. send passes a message to another agent. receive takes one in. generate_reply works out what to say back. A custom agent only changes how generate_reply works. Everything else stays the same, so any agent can talk to any other.
For the user proxy, Figure 2 gives the rule in one sentence. When the assistant sends it a message, the proxy typically replies with the human’s input. If there is no input, it executes any code in the assistant’s message instead. Try it below. The gate order in the device is that rule, plus one fallback to the LLM that this page adds for agents that have one.
Switch abilities on or off, then choose the message that arrives. A message goes through three gates in order. The first gate that applies answers.
The human, then tool, then LLM order is this page’s simplification of the user proxy rule in the paper’s Figure 2 (human input first, else run the code). The paper does not give one fixed order for every agent. The class labels follow Figure 2 and Section 2.1.
Try three settings. Turn on only the LLM: the agent answers every message with a model call, like AssistantAgent. Turn on Human and Tools: it asks you first, runs code when you stay silent, and never calls a model, like UserProxyAgent. Turn everything off: nothing can answer, and the chat stops. That last case is a real failure mode. An agent with no applicable reply ends the conversation without a word.
Go back to the six-message chat from the top of this page. The proxy sent the task. Then the work alternated. List each message, and name the capability that produced it.
| Message | Sent by | Capability used |
|---|---|---|
| 1 Task | User proxy | Start of chat (no model call) |
| 2 Code v1 | Assistant | LLM |
| 3 Error | User proxy | Tool: ran the code |
| 4 Fix | Assistant | LLM |
| 5 Chart output | User proxy | Tool: ran the code |
| 6 TERMINATE | Assistant | LLM |
Count them. The chat used 3 LLM calls (messages 2, 4 and 6), 2 tool runs (messages 3 and 5), and 0 human inputs. If the proxy had human input switched on, a person would have been asked before each of messages 3 and 5, with a chance to skip. Same agents, same messages, different settings.
The developer code is short. This sketch follows the paper’s Figure 2; exact argument names differ between library versions.
python# two agents, as in the paper's Figure 2 (a sketch, not a full program) assistant = AssistantAgent("B") # LLM-backed, writes code user_proxy = UserProxyAgent("A", human_input_mode="NEVER", # never ask a person code_execution_config={"work_dir": "coding"}) # runs code it receives user_proxy.initiate_chat(assistant, message="Plot a chart of META and TESLA stock price change YTD.")
Notice what the developer did not write. There is no loop, no parser for the model’s reply, and no “now run it” step. Chapter 3 shows why the chat runs itself.
Chapter 3
See how one simple rule, answer every message you receive, runs a whole workflow with no manager in charge
Two friends have walkie-talkies and one rule. When you hear a message, you reply. When someone says “over and out”, you stop. Nobody stands in the middle and says whose turn it is. The talk still goes back and forth until the job is done.
That rule is the engine of AutoGen. The paper builds its whole way of writing programs on it. It calls the approach conversation programming.
Any multi-step program has to settle two questions. What does each step compute? And in what order do the steps run, and under what conditions? The paper names them. Computation is the action an agent takes to make its reply. Control flow is the sequence, or the conditions, under which those computations happen.
In an ordinary program you write control flow yourself, with loops and if statements. Many agent systems add a separate manager to do it, which the paper calls a control plane: a special module that steers the conversation. AutoGen has none by default. Both parts live inside the conversation. Computation is conversation-centric: each agent acts on the messages it is part of. Control flow is conversation-driven: who speaks next, and when to stop, follows from the messages themselves.
The paper states the rule exactly. Once an agent receives a message from another agent, it automatically calls generate_reply and sends the reply back to the sender, unless a termination condition is satisfied. That is all. Start one chat, and the flow follows. The paper calls this a decentralized, modular and unified way to define a workflow.
We can write the loop as a short recurrence. Call the first message m0, the task. Then repeat the following.
Read it aloud. Each message comes from the receiver of the one before, and it depends only on that agent’s reply function and its history. No other line of code decides the order. The chat stops at the first stop word or when the cap N is reached, whichever comes first.
The paper offers both kinds of stop. In natural language, you tell the assistant in its prompt to reply “TERMINATE” when the task is done. In code, you set a maximum number of auto-replies. They fail in different ways. The word depends on the model obeying. The cap does not depend on the model, but it can cut a chat off before the work is finished. Use the device to see both.
The chat is the hero’s plotting task. Turn the stop word on or off, and move the cap on auto-replies. See which rule ends the chat, and whether the chart exists by then.
Messages 1 to 6 are the hero chat. Without the stop word, messages 7 to 10 are this page’s illustration of agents that keep replying because nothing tells them to stop; the paper does not show that transcript. A cap of N counts replies after the first task message.
With the stop word on and a cap of 9, the chat ends by itself after 6 messages. That is 5 replies, so the cap never fires. Pull the cap down to 3 and the chat ends after 4 messages, before the chart. The cap saved money and lost the answer. Now switch the stop word off. The chat does not know it is finished, so it runs to the cap. With a cap of 9 that is 10 messages, and 5 of them come after the chart is made.
This sketch implements the rule in about twenty lines. It is a teaching sketch of the mechanism, not AutoGen’s source. Note what is missing: there is no while loop and no scheduler. Sending a message calls receive, and receive sends the reply, so the chat advances by itself.
pythonclass Agent: def __init__(self, name, reply_funcs, max_auto_reply=10): self.name, self.reply_funcs = name, reply_funcs # reply_funcs: history -> str or None self.history = [] # the agent's internal context self.max_auto_reply, self.n_auto = max_auto_reply, 0 def send(self, msg, to): self.history.append((self.name, msg)) # remember what I said to.receive(msg, sender=self) def receive(self, msg, sender): self.history.append((sender.name, msg)) if "TERMINATE" in msg or self.n_auto >= self.max_auto_reply: return # a termination condition holds: stay silent reply = self.generate_reply() if reply is not None: self.n_auto += 1 self.send(reply, to=sender) # auto-reply goes back to the sender def generate_reply(self): for fn in self.reply_funcs: # the first function that answers wins out = fn(self.history) if out is not None: return out return None # start a chat: a.send("task", to=b), and the rest runs by itself
The list reply_funcs is where customization lives. The paper’s Figure 2 shows a call A.register_reply(B, reply_func_A2B). It adds a custom reply function for messages from B. In the paper’s example the function first asks a person. If the person gives nothing, and the message holds code, it runs the code. When no custom function is registered, a list of default reply functions is used.
The design has a price. With no central manager, nobody sees the whole picture. A chat that loops, or two agents that keep thanking each other, will not notice. Only the stop word and the cap protect you. Chapter 10 returns to this limit.
Chapter 4
Read the assistant’s default system message line by line, and see how sentences of English steer a chat the way if statements steer code
You leave a note on the fridge for a house-sitter. “If the dog barks, give her a treat. When you leave, lock the door. Write ‘done’ on the board when you finish.” The note has conditions, actions and a stop signal. It is a program, written in English, and a person runs it.
AutoGen leans on this idea. The paper says control of a conversation can be a fusion of programming and natural language. Some of the steering is code. Some is a note to the model. The assistant agent’s system message is that note: the standing instructions sent to the model on every call (Chapter 1).
The paper lists three styles of control.
Natural-language control via the LLM. You prompt an LLM-backed agent in words. The default assistant message tells it to fix errors and write the code again if the last result shows an error. It also tells the model to keep its output in a fixed shape, so a tool-backed agent can read it. And it tells the model to reply “TERMINATE” when everything is done.
Programming-language control. You write Python. Code sets the stop rule, the human input mode, and what tool execution does, for example the maximum number of auto-replies. You can also register your own reply function, as in Chapter 3.
Moving between the two. From code to words: a custom reply function can call an LLM with a prompt that holds control logic. From words to code: the LLM can propose a function call, and then the host program runs real code. The paper cites function calling for this second path.
Why mix them? Code is exact but rigid. Words are flexible but the model may ignore them. The paper’s idea is to use each where it fits.
| Control style | Good at | Risk |
|---|---|---|
| Words in the system message | Judgement: “if the result shows an error, try another way” | The model may skip or misread an instruction |
| Python settings and reply functions | Hard limits: a cap on replies, which code may run | Rigid: it cannot judge whether the work is truly done |
Appendix C and Figure 5 print the assistant’s default system message (version 0.1.1 of the library). The paper colors it to show five prompting techniques. It is about 380 words long, so every assistant call re-reads it, which is the fixed cost S from Chapter 1.
The five techniques, in plain words, are these. Role play tells the model who it is. Control flow uses “if” and “when” triggers to say what to do in each state of the chat. Output confine sets the shape of the output. Facilitate automation gives the model facts about its partner so its reply works with no human touch-up. Grounding asks the model to check its work against real results.
Eight lines from the default system message. Pick a technique to light the lines that use it. Some lines do two jobs.
The excerpts and which technique marks each are read from the colors in the paper’s Figure 5 (Appendix C). A line with two badges is colored in two techniques. The one-line meanings of the five names are this page’s plain-word gloss.
Pick Control flow. Four of the eight lines light up, and each is a trigger: “when using code”, “if the error can’t be fixed”, “when you find an answer”, “when everything is done”. These lines do the work of if statements. The model must notice for itself that the state has been reached. The paper calls this relying on implicit state inference: the model works out where the chat stands from the history, with no state variable.
Replay the hero chat and find the line behind each step.
The proxy ran the code and sent back a failure: no yfinance. The assistant’s next message said to install the package first. That step follows the control-flow line “if the result indicates there is an error, fix the error and output the code again”. Nothing in Python forced it.
The assistant’s code printed its result. That follows the automation line “do not ask users to copy and paste the result; instead use print”, because the proxy can only send back what the code prints. This is also why the paper’s AutoGPT comparison failed on math: it gave code “without the print function”, so the result was never shown (Chapter 5).
The chat ended with “TERMINATE”. That is the output-confine line plus its control-flow trigger: “reply TERMINATE in the end when everything is done”. Chapter 3’s auto-reply rule then stopped.
The paper is frank about the weak spot. LLMs “do not follow all the instructions perfectly”, so the system needs other mechanisms to handle faults. Some instructions are ambiguous. The designer should either make them exact, or keep the ambiguity on purpose for flexibility and handle each case in another agent. And the paper observes that GPT-4 follows instructions better than GPT-3.5-turbo.
That is why a good design splits trust. Put the judgement in words. Put the hard limits in code. If a word-based stop fails, the code-based cap still ends the chat.
python# the code side of control (setting names come from the open-source library; the paper describes them in words) user_proxy = UserProxyAgent("A", human_input_mode="NEVER", # when to ask a person max_consecutive_auto_reply=5, # a hard cap, whatever the model says is_termination_msg=lambda m: "TERMINATE" in m["content"], # the stop word, checked in code code_execution_config={"work_dir": "coding"})
Chapter 5
Follow the write, run, read, repair loop that two built-in agents run on their own, and see what it bought on the MATH benchmark
A student asks a tutor: “Simplify the square root of 3 over 8.” The tutor does it in their head and says a decimal. It is wrong in the third digit. Another tutor writes two lines of code, runs them, and reads the exact answer off the screen. Same question, same brain. The second tutor had a calculator and checked the result.
Language models are the first tutor. They can write the steps well and still slip on arithmetic. The paper’s first application gives the model a calculator and a partner who keeps pressing the keys.
Take the two built-in agents from Chapter 2, with no changes. The assistant is the LLM-backed agent. The user proxy is the tool-backed agent that runs code. They repeat four steps.
That is all, and it matches the opening scene of this lesson. The assistant’s default message tells it to fix errors, give the full corrected code, verify its answer with evidence, and end with TERMINATE (Chapter 4). The proxy’s default behavior is to run code (Chapter 2). The auto-reply rule from Chapter 3 keeps the loop turning.
A repair loop gives the model more than one try. How much does that help? Start with a simple toy. Say each round has the same chance p of producing working code, and rounds do not affect each other. The chance that every one of k rounds fails is (1 − p) multiplied by itself k times. So the chance that at least one round works is one minus that.
Work one case by hand. Let p = 0.3 and k = 3. One round fails with chance 1 − 0.3 = 0.7. Three rounds all fail with chance 0.7 × 0.7 × 0.7 = 0.343. So P3 = 1 − 0.343 = 0.657. A 30% tool becomes a 66% tool in three rounds. Slide the knobs and watch the curve.
Each bar is the chance the loop has working code by that round. Move the first knob to change the chance for one round. Move the second to pick the cap on rounds.
A toy model, not a result from the paper. It assumes every round is an independent try with the same chance. A real repair round reads the error and may do better than that. It can also do worse, if the model repeats the same mistake.
Real loops are not independent. The error message is new information, and good repairs use it. The toy shows only the shape: the first retries help a lot, and later ones help less. It also shows why a cap is cheap insurance.
MATH (Hendrycks et al., 2021) is a set of competition math problems, with 5,000 in its test set. Problems have five difficulty levels. Level 5 is the hardest. The paper runs everything with GPT-4 as the model, and pre-installs the sympy math library in the execution environment so the proxy has something to compute with.
It compares AutoGen’s two plain built-in agents against several others: vanilla GPT-4, ChatGPT with the Code Interpreter, ChatGPT with the Wolfram Alpha plugin, multi-agent debate, and the LangChain ReAct agent. Two test sets are used. One has 120 level-5 problems, 20 from each of six categories (geometry left out). The other is the entire 5,000-problem test set.
Choose a test set. Bars are the success rate in percent, exactly as printed in the paper’s Figure 4a.
Percentages are the paper’s Figure 4a. The problem counts out of 120 are computed from those percentages. The paper did not run ChatGPT on the whole set because it needs manual effort and has an hourly message limit, and it skipped debate and ReAct there because they scored below vanilla GPT-4 on the smaller set.
On the hardest 120, AutoGen’s plain pair solves 52.5%, which is 63 problems. GPT-4 alone solves 30.0%, which is 36 problems. The commercial ChatGPT with Code Interpreter gets 48.33% (58) and with the Wolfram plugin 45.0% (54). On the whole test set, AutoGen reaches 69.48% against 55.18% for GPT-4. That is 14.30 points higher, or about 26% more problems solved.
The authors also ran two hard level-5 problems, three trials each. The table shows how many trials gave the right answer, and the paper’s reasons for failure.
| System | Problem 1 | Problem 2 | Main failure reason in the paper |
|---|---|---|---|
| AutoGen | 3/3 | 2/3 | Problem 2: the final answer from code execution was wrong |
| AutoGPT | 0/3 | 0/3 | Code without a print statement, so nothing was shown |
| ChatGPT + Plugin | 1/3 | 1/3 | Chose the wrong one of two Wolfram results; once got stuck |
| ChatGPT + Code Interpreter | 2/3 | 0/3 | Wrong decimal result; three different wrong answers |
| LangChain ReAct | 0/3 | 0/3 | Three different wrong answers each time |
| Multi-agent debate | 0/3 | 0/3 | Calculation errors, different each time |
Add the rows. AutoGen got 5 of 6 trials right. Code Interpreter and the plugin got 2 of 6 each. The others got 0. Look at AutoGen’s one miss: the code ran with no error, and the answer was still wrong. A runner proves that code ran. It does not prove the answer is right. That is why the default message asks the assistant to verify its answer with evidence.
The sample is tiny, two problems and six trials, and the paper presents it as a qualitative look at user experience. Treat the large MATH numbers as the evidence, and this table as a story about why.
pythonimport re, subprocess def code_reply(history): """A tool-backed reply function: run the last code block, send back what happened.""" last = history[-1][1] # the assistant's newest message blocks = re.findall(r"```(?:python|sh)?\n(.*?)```", last, re.S) if not blocks: return None # nothing to run: let another reply function answer run = subprocess.run(["python", "-c", blocks[0]], capture_output=True, text=True, timeout=60) return f"exitcode: {run.returncode}\n{run.stdout}{run.stderr}" # output or error, as a message
This is a sketch of the idea. A real runner needs a sandbox, a working folder, and limits on time and files. The paper’s ethics statement warns that agents that can install packages or change the outside world “could be risky”.
Chapter 6
Learn where a person joins the chat with one setting, and how an agent can call a second person on its own
The code loop from Chapter 5 is fast, but it has a ceiling. Some problems are too hard for the model alone, and it keeps running code that gives the wrong answer. A good teacher does not take the pencil away. The teacher sits beside the student and says: “Not that. Start with the distance between the point and each plane.” One hint, and the student finishes.
AutoGen has a built-in seat for that teacher. It is one setting on the user proxy.
Recall from Chapter 2 that a person is one of the proxy’s three possible backends. Switching it on takes one line. The paper says that to add human feedback to the math system, one only needs to set human_input_mode=‘ALWAYS’ on the user proxy. Now before every reply, the proxy pauses and asks you. You can type feedback, or skip. If you skip, the proxy falls back to its other abilities and runs the code.
The paper’s guidelines give a method for using the seat. Start with the human always in the loop, even if you plan to run fully on your own later. This lets you judge how well the assistant works, tune the prompt and find corner cases. Once small tests succeed, set the mode to ‘NEVER’ and let the system run alone.
For this test the authors picked one hard problem that none of the compared systems solved in three autonomous trials.
“Find the equation of the plane which bisects the angle between the planes 3x − 6y + 2z + 5 = 0 and 4x − 12y + 3z − 3 = 0, and which contains the point (−5, −1, −5). Give the answer as Ax + By + Cz + D = 0 with whole numbers, A > 0 and no common factor.”
They gave every system the same three hints, in this order, whenever it went wrong.
Let us do the math the hints describe, so the device below is not a black box. The distance from a point (x, y, z) to a plane ax + by + cz + d = 0 is |ax + by + cz + d| divided by the length of (a, b, c). The first plane has length √(9 + 36 + 4) = 7. The second has length √(16 + 144 + 9) = 13. Equal distances give an equation.
|3x − 6y + 2z + 5| / 7 = |4x − 12y + 3z − 3| / 13
Multiply both sides by 91. Remove the absolute values with a plus or a minus sign, which is hint 2. The plus case gives 13(3x − 6y + 2z + 5) = 7(4x − 12y + 3z − 3), which simplifies to 11x + 6y + 5z + 86 = 0. The minus case gives 67x − 162y + 47z + 44 = 0.
Now apply hint 3, the point (−5, −1, −5). In the first plane: 11(−5) + 6(−1) + 5(−5) + 86 = −55 − 6 − 25 + 86 = 0. The point fits. In the second: 67(−5) − 162(−1) + 47(−5) + 44 = −335 + 162 − 235 + 44 = −364, which is not zero. So the answer is 11x + 6y + 5z + 86 = 0, the answer printed in the paper.
Choose how many hints the human has given. The track shows how far the solution gets. The bars show how often each system solved it with all three hints.
The three hints and the final answer are the paper’s (Appendix D, scenario 2). The work at each step is the algebra above, done here by hand. Trial counts are the paper’s: three trials per system, each given the same hints.
With all three hints, AutoGen solved the problem in all three trials. ChatGPT with Code Interpreter and ChatGPT with the plugin solved it in two of three. AutoGPT solved it in none. The paper’s reasons: Code Interpreter once “failed to adhere to human hints”, the plugin once gave a nearly right answer with a wrong sign, and AutoGPT hit code-execution errors. Three trials is a small sample, so read the gap as a hint of better behavior, not a measured rate.
So far the human sits at the proxy. The paper’s third math scenario flips it: the assistant decides it needs a person, and goes to find one.
Picture a student and an expert, each with their own proxy and assistant, six agents in all (the paper’s Figure 6). The student chats with their assistant. When the assistant cannot solve the problem well, or the result does not match what the student expected, it calls a function named ask_for_expert. That is function calling from Chapter 1: the model writes a structured request, and the host program runs real code.
The function does something simple. It writes the first message, which might be the problem or a request to check a solution. It then starts a chat between the expert and the expert’s own assistant. When that chat ends, its final message goes back to the student’s assistant as the function’s result. The student’s assistant resumes with the student, now holding the expert’s answer.
The only new code is the function itself. The paper says it needs “several lines”, and then becomes part of the assistant’s configuration. Adding more experts means one function per expert. Adding more students means sharing one expert function between them.
python# a sketch of the paper's scenario 3 (names are illustrative, not the library's exact API) def ask_for_expert(message: str) -> str: """The student's assistant calls this when it cannot solve the problem well.""" expert_proxy.initiate_chat(expert_assistant, message=message) # a person plus their own assistant chat return expert_proxy.last_message_from(expert_assistant) # this text becomes the function result student_assistant = AssistantAgent("student_assistant", functions=[ask_for_expert]) student_proxy.initiate_chat(student_assistant, message=problem) # the student's own chat resumes with the answer
This is the second way the paper makes a chat dynamic: the model, not a fixed script, chooses whether to start a new conversation. The flow now depends on the content. If the first answer is good, the expert is never called.
Chapter 7
Meet the manager agent that picks who speaks next, and see what a four-agent room gained over a two-agent chat in the paper’s pilot study
In a chat between two agents, the next speaker is never in doubt. You send a message, and the other one replies. Now put four agents in a room: one holds the task, one writes code, one runs it, one reviews it. When the code fails, who speaks? The engineer, to fix it. When the fix runs, who speaks? Maybe the reviewer. The order depends on what just happened.
Someone has to choose. In AutoGen, that someone is an agent too.
The paper calls this pattern dynamic group chat. The agents share the same context, and they talk in an order that is not fixed in advance. A built-in agent, the GroupChatManager, acts as the conductor. It repeats three steps.
Note the contrast with Chapter 3. In a two-agent chat, control is the auto-reply rule: whoever receives replies. In a group chat, a reply goes to the manager, and the manager decides. The paper reuses the same building block: the manager’s own reply function reuses the built-in LLM reply to pick the next speaker.
Step through a small room and watch all three steps. The task is from the paper’s pilot study. Buy 200 AAPL shares at the lowest price of the last 30 days, sell at the highest, and save the profit to a file.
Press Next step to move through select, ask and broadcast. The numbers in each box count the messages that agent holds.
The four roles and the three steps are the paper’s (Section 3, A5, Figure 12). The turn-by-turn script is a made-up illustration of one plausible run, not a transcript from the paper.
After the last turn, every box in the device shows the same count. That is the point of step three. Broadcasting keeps one shared history, so any agent can be picked next without a catch-up message.
The choice is only as good as the prompt behind it. The authors tried two styles. In the task-based style, they append role information, the chat history and the next speaker’s task into one prompt. In the role-play style, the prompt frames the choice as a game: you are the manager, here are the roles, read the conversation, and say which role should play next. The paper does not print its prompt, so the sketch below is only in that style.
pythondef group_chat(agents, task, max_round=12): chat = [("user_proxy", task)] # one shared list of (speaker, text) for _ in range(max_round): speaker = pick_speaker(agents, chat) # step 1: select, one LLM call reply = speaker.generate_reply(chat) # step 2: ask the chosen agent chat.append((speaker.name, reply)) # step 3: broadcast = everyone reads this list if "TERMINATE" in reply: break return chat def pick_speaker(agents, chat): # a role-play style prompt (illustrative wording) roles = "\n".join(f"{a.name}: {a.role}" for a in agents) prompt = f"You are the manager in a role-play game. Roles:\n{roles}\n" \ "Read the conversation, then name the one role that should speak next.\n" + show(chat) return by_name(agents, llm(prompt))
To test whether the room and the role-play prompt are worth it, the authors ran 12 hand-written, complex tasks. They compared three setups: a plain two-agent chat (assistant plus proxy), the four-agent group chat with the role-play prompt, and the same group chat with the task-based prompt. They tried each with GPT-3.5-turbo and with GPT-4. Choose a model below.
Top bars: tasks solved out of 12, higher is better. Bottom bars: average model calls per task, lower is better. The number in brackets is the count of tasks that failed to end properly.
All numbers are the paper’s Tables 5 and 6, from a pilot study of 12 hand-written tasks. In Table 6 the paper reports two numbers per cell: the average calls, and the number of termination failures.
Read GPT-4. The role-play group chat solved 11 of 12 tasks. The two-agent chat solved 9. The task-based group chat solved 8. In GPT-4’s two-agent chat, 3 tasks failed to terminate, and the average task took 6.8 model calls. The role-play group chat needed 4.5 calls and had no termination failures. With GPT-3.5-turbo the pattern is the same but louder: the two-agent chat failed to terminate on 9 of the 12 tasks.
Now the honest part. The paper says role-play selection gives “a higher success rate, fewer LLM calls and fewer termination failures”. The success and termination claims hold against both rivals. The calls claim holds only against the two-agent chat. The task-based prompt actually used fewer calls: 4.0 for both models, against 5.3 and 4.5 for role play. It simply solved fewer tasks. Cheap and wrong is not a win.
Also remember the size of the sample. Twelve tasks means one task is worth 8.3 percentage points. The gaps here are 1 to 3 tasks. This is a pilot study, as the paper says, and it is a reason to try group chat, not proof that role-play prompts are always better.
Chapter 8
See how a two-word reply, UPDATE CONTEXT, turns a one-shot lookup into a conversation that keeps searching until it finds the answer
You sit an open-book exam. A librarian hears your question and hands you the three pages that look most like it. You read them. The answer is not there. A normal pipeline stops, and you write “I don’t know”. A better librarian lets you say: “These pages do not help. Give me the next three.”
That small request is the paper’s second application. It builds retrieval-augmented question answering as a chat between two agents, and the chat can ask for more.
A language model knows only what was in its training data. It does not know your private files, or an API released after it was trained. Retrieval-augmented generation (RAG) fixes that. Before the model answers, a program finds relevant text and puts it in the prompt.
Finding relevant text works in four parts. First, split each document into chunks of a set size. Second, turn each chunk into an embedding, a list of numbers that places the chunk’s meaning at a point in space, so similar meanings sit close together. Third, store the embeddings in a vector database. The paper uses Chroma, with SentenceTransformers as the embedder. Fourth, embed the question too, and fetch the chunks whose points are nearest.
A common way to measure “nearest” is cosine similarity, the angle between two arrows. The paper says only that it retrieves by embedding similarity, so this is the usual choice, shown as an example.
A toy case with two numbers each. Let the question be q = (3, 4) and a chunk be d = (4, 3). The dot product is 3×4 + 4×3 = 24. Each length is √(9 + 16) = 5. So sim = 24 / (5 × 5) = 0.96, nearly the same direction. A chunk e = (−4, 3) gives 3×(−4) + 4×3 = 0, so sim = 0: unrelated. Real embeddings have hundreds of numbers, but the arithmetic is the same.
The paper extends the two built-in agents. The Retrieval-augmented User Proxy owns the vector database. It downloads the documents, splits them into chunks, embeds and stores them. It also runs code, as before. The Retrieval-augmented Assistant is an LLM agent that writes code or text from the question and the context it is handed. The workflow in Figure 7 has four message types.
The control flow here is not a Python while loop. It is two sentences in the assistant’s prompt. Because the reply is a fixed phrase, the proxy’s code can look for it. This is the output-confine technique from Chapter 4, used for control.
The question, from the Natural Questions benchmark: “who carried the usa flag in opening ceremony”. The most similar chunk is about a baseball game in 1899. It has nothing to do with the question.
ProxyQuestion, plus context: “On January 17, 1899 … The Astros beat the Yankees that night, 2 to 1.”
AssistantSorry, I cannot find any information about who carried the USA flag in the opening ceremony. UPDATE CONTEXT.
ProxyQuestion, plus the next chunk: a table that includes “Erin Hamlin”.
AssistantErin Hamlin carried the USA flag in the opening ceremony.
Without that phrase, the ablation prompt tells the assistant to say “sorry, I don’t know”, and the chat ends after message 2. The same question is answered wrongly. The only difference is the fixed phrase. Try it with the device.
Chunks are ranked by similarity to the question. Slide to place the chunk that holds the answer. Turn interactive retrieval off and on, and press Run.
A toy. The chunk contents are placeholders, and the 7 setting means the answer is not among the 6 chunks. The paper’s own example is the flag question above, where the answer is in the second chunk. Each read costs one model call in this toy.
The authors tested on the Natural Questions benchmark, with 5,332 non-redundant context documents and 6,775 queries, using GPT-3.5-turbo. They compared against DPR (dense passage retrieval), scored as in a prior evaluation. They report two measures. F1 scores how well the answer words match the true answer (a balance of precision and recall). Recall measures how much of the true answer the reply covers.
| System | F1 | Recall |
|---|---|---|
| AutoGen, with UPDATE CONTEXT | 25.88% | 66.65% |
| AutoGen, without it (says “I don’t know”) | 22.79% | 62.59% |
| DPR | 15.12% | 58.56% |
The interactive feature adds 3.09 F1 points and 4.06 recall points. In relative terms that is about 13.6% more F1. About 19.4% of questions triggered at least one UPDATE CONTEXT, which is about 1,314 of the 6,775 (computed here), and each one costs extra model calls.
One caution from the authors themselves. AutoGen without the feature still beats DPR. They credit the retriever difference, a simple vector search with all-MiniLM-L6-v2, and not the chat. So only the 3-point gap between the first two rows isolates what conversation adds.
The paper also asks how to use FLAML, an AutoML library, to train a classifier with Spark for 30 seconds and cancel jobs at the limit. The Spark options came out in December 2022, after GPT-4’s training data. GPT-4 alone invents a parameter spark set to True, which does not exist. With the latest docs retrieved, GPT-4 sets the real options use_spark and force_cancel to True. It is a single example, and it shows the goal: use documents the model has never seen.
pythondef retrieval_chat(question, db, assistant, max_chunks=6): for n in range(max_chunks): # each round fetches the next most similar chunk context = db.query(question, skip=n) # embedding similarity search reply = assistant(question, context) # the LLM: an answer, or exactly "UPDATE CONTEXT" if "UPDATE CONTEXT" not in reply: return reply # a satisfied answer (or code the proxy will run) return None # no more documents: terminate
Chapter 9
See three jobs for an extra agent, a source of common sense, a referee and a code checker, and what each gained in the paper’s tests
A student writes an essay and also marks it. The marks are always generous. A school fixes this with a second person: a marker who never wrote the essay and has one job, to find mistakes. The writer and the marker can be equally clever. What matters is that they are separate.
Three of the paper’s applications use that idea. Each adds an agent whose job is to check or correct the agent doing the work. Because every agent speaks the same message language, adding one is cheap.
ALFWorld is a text game set in a house. The agent gets a goal such as “put a hot apple in the fridge” and a description of the rooms. It must explore and act through text commands. A task can need more than 40 steps, so the agent has to split the goal into subtasks.
The authors first built a two-agent system, called ALFChat. The assistant is an LLM that plans and picks the next action. The executor is a custom proxy for ALFWorld. It performs each action in the game and sends back what happened. Because the game needs exact action text, the executor compares the assistant’s words with all valid actions using the BLEU similarity score, and takes the closest one.
This pair has a typical flaw. The assistant mixes up finding an object with taking it. In the paper’s example, the assistant finds a bowl on a desk and goes to the desklamp. It then turns the lamp on again and again, because it never picked up the bowl. It is stuck in a loop.
The fix is a third agent, the grounding agent. It holds a few facts about the household world, such as “you must find and take the object before you can examine it”. It speaks at two moments: when the task begins, and whenever the assistant gives the same action three times in a row. The paper shows the trace: after the hint, the assistant takes the bowl, goes to the lamp and finishes the task.
Pick a task type and a score. Bars compare ReAct, the two-agent chat and the three-agent chat with the grounding agent. Success is the percent of tasks finished.
All values are the paper’s Table 3, on 134 unseen ALFWorld tasks, three attempts per task. The ReAct numbers come from its official code, which uses text-davinci-003 (the paper’s footnote 7), while ALFChat uses GPT-3.5-turbo. The two do not use the same model.
Read the “All tasks” row on the average score. ReAct gets 54 and the two-agent chat gets 54: a tie. The three-agent chat gets 69, a gain of 15 points, the same 15% the paper reports. Switch to task types. The gain is largest on Heat (48 to 70, +22) and smallest on Cool (71 to 76, +5). On best of three, the three-agent chat reaches 77 against 66.
Two cautions. First, the baseline model differs, as the fine print says. Second, the authors wrote the grounding facts by reading the failed runs and summarizing what the assistant lacked. So the facts are tuned to this benchmark’s failures. The experiment shows that a grounding agent can fix a known failure, not that one would fix an unknown one.
In Conversational Chess, two players chat and play. Each player is an agent that can be a person, an LLM, or a mix. A third agent, the board agent, knows the rules. It uses an LLM to read each player’s message and turn it into a legal move in a strict format. It then tries the move on the board. If the move is illegal, it replies with an error, and the player must try again.
PlayerAlright, I’ll move my pawn from e4 to e5, attacking your knight.
Board agentError: illegal uci: ‘e4e5’ …
PlayerI’ll move my pawn from d2 to d4, opening up lines for my queen and bishop.
This chat between a player and the board agent is hidden from the other player, which keeps each player’s message list short and clean. The ablation is a story, not a number. The authors removed the board agent and only told both players to “make sure both you and the opponent are making legal moves”. Illegal moves then broke the game. In their example, a player moved a knight from b8 and changed the rook on a8 into a knight. A prompt asked for care. A referee checked.
The same idea of splitting off the agent that touches the world appears in the paper’s browser application, MiniWobChat. An assistant picks actions, and an executor agent runs them in the browser and reports back. On the 49 tasks the authors had available, it reached a 52.8% success rate, 3.6 points below RCI (a method built for that benchmark). It is not a safeguard story, but it shows the same split.
OptiGuide answers questions about an optimization plan, such as a coffee supply chain. A user asks: “What if we prohibit shipping from supplier 1 to roastery 2?” The system must write code that changes the optimization model and reads the result. Running wrong code is costly, and running unsafe code is worse.
The paper’s version has three agents. The Commander talks to the user, keeps the shared memory and runs code. The Writer writes code and also explains the output. The Safeguard reviews each piece of code for safety, for example no leaked data and no malicious commands. The flow has eight steps. The Writer drafts code. The Commander asks the Safeguard to screen it. Only when the Safeguard clears it does the Commander run it. The Writer then explains the result, and the Commander gives the user the final answer. If the Safeguard raises a flag or the code fails, the Commander sends the log back to the Writer, and the loop repeats until it is solved or times out.
Is a separate Safeguard needed? The authors tested it. They built a single agent that both wrote code and checked its safety. They ran both designs on 100 coding tasks, equal numbers safe and unsafe, and scored how well each one flagged the unsafe code.
Choose a model. Bars show how well each design finds the unsafe code, as F1 and as recall, in percent.
All values are read from the paper’s Figure 4d: 100 coding tasks, half safe and half unsafe. The F1 gains of 8 and 35 points are stated in the paper’s text. The recall gains of 20 and 40 points are the differences of the printed bars.
With GPT-4, separating the safeguard lifts F1 from 88 to 96, and recall from 78 to 98. With the weaker GPT-3.5-turbo, it lifts F1 from 48 to 83, and recall from 32 to 72. The weaker the model, the more the split helped. The paper says role-playing keeps each agent’s memory isolated, which prevents shortcuts and hallucinations, and calls the Safeguard a “virtual adversarial checker”. One plausible reading is that a reviewer that sees only the code cannot be talked into approving it by the writer’s own explanation. The paper does not test that reading.
python# the Commander's loop, as a sketch of the paper's steps 2 to 8 def commander(question, writer, safeguard, run, max_round=5): feedback = question for _ in range(max_round): code = writer.write_code(feedback) # Writer drafts code verdict = safeguard.review(code) # Safeguard sees only the code if verdict != "SAFE": feedback = f"Safeguard flagged: {verdict}"; continue # back to the Writer ok, log = run(code) # external tool executes it if not ok: feedback = f"Execution failed: {log}"; continue return writer.explain(log) # Writer turns output into an answer return "timed out"
Chapter 10
Weigh the paper’s savings in lines, minutes and prompts, then list what its experiments do not prove
Imagine you must decide whether your team adopts this library. Two questions matter. Does it help? And how sure can we be? A good report answers the second as carefully as the first. This chapter does both.
The paper measures effort on one application, OptiGuide (Chapter 9). It reports three savings.
Code. The core workflow code went from over 430 lines to 100 lines. That is about 4.3 times fewer, which the paper rounds to 4. The authors credit the merge of two roles into one Writer agent, and the built-in message passing.
Time. The authors ran a small user study. An expert Python programmer, skilled with the Gurobi solver, answered 10 randomly chosen questions on a coffee supply chain. They used two tools, ChatGPT with Code Interpreter and AutoGen-based OptiGuide. Both tools answered 8 of the 10 correctly. The Code Interpreter took 4 minutes 35 seconds on average (about 275 seconds, with a spread of about 2.5 minutes). OptiGuide took around 1.5 minutes, most of it waiting for GPT-4. That is about 3 times faster. Code Interpreter was slower because it cannot run code that needs private packages such as Gurobi, so the person had to copy code, paste it and run it by hand.
Prompts. The authors also counted how many prompts a user had to type over 2,000 questions across five OptiGuide applications. The multi-agent design cut the typing by 3.03 to 4.88 times, depending on the application (Table 4). Use the device to see all three.
Choose a measure. Lower bars are better in the first two. The third shows how many times fewer prompts the user typed.
Lines (430 and 100) are from the paper’s Section 3, A4. Times are from the user study in Appendix D (4 minutes 35 seconds and about 1.5 minutes; one expert, 10 questions). The prompt savings are Table 4’s ratios with GPT-4. The five-dataset mean of 3.51 is computed here.
The mean of the five prompt savings is 3.51 times, so the paper’s “3 to 5 times” fits. These are real gains. They also come from one application, with one user in the time study.
A fair reader keeps a short list of limits. We take them from the paper’s own text and its tables.
The paper points to three open areas. The first is the best design for a workflow: how many agents, which roles and abilities, how they interact, and which parts to automate. It expects no one-size answer, and asks for which tasks multi-agent chats help and what the cheapest good workflow is.
The second is building highly capable agents. The authors saw CAMEL fail on most problems, mainly because it lacks tools and code execution. They conclude that chat and simple role play are not enough, and that agents need diverse skills, a shared library of agents, and ways to find and upgrade their own skills.
The third is scale, safety and human control. As workflows grow, they become hard to log and adjust. Without tracking and debugging tools they risk “incomprehensible, unintelligible chatter among agents”. Fully autonomous chats need care, especially in high-risk settings. The authors call for fail-safes against cascading failures and misuse, for guarding against reward hacking and out-of-control behavior, and for human oversight. The ethics statement adds privacy, bias, accountability, trust and the risk of code that changes the outside world, such as installing packages.
Appendix B gives five practical rules. Use the built-in agents first. Start with a simple topology, a two-agent chat or a group chat. Reuse the built-in reply methods before writing your own. Start with a human always in the loop, then switch to autonomous mode once small tests succeed. And use other tools when they fit: for a one-way pipeline with no back-and-forth, a simpler library will do.
That last rule is the most honest line in the paper. A conversation costs messages. Use it where feedback loops, roles or humans repay that cost, and not where one call would do.
Chapter 11
Keep the whole paper on one page: the numbers, the terms, the core code, where it sits in the field, and how to cite it
AutoGen is a small idea with a wide reach. Make every agent able to send, receive and answer messages. Let each agent be backed by a model, a person, a tool, or any mix. Then let the conversation itself be the program: each received message gets a reply, and a stop word or a cap ends the chat. Add a manager when the order must be dynamic, a function call when an agent should start another chat, and a third agent when something needs checking.
| Application | What the paper measured | Result |
|---|---|---|
| A1 Math, whole MATH test set | Success rate, GPT-4 (Figure 4a) | AutoGen 69.48%, GPT-4 alone 55.18% |
| A1 Math, 120 level-5 problems | Success rate (Figure 4a) | AutoGen 52.5%, Code Interpreter 48.33%, plugin 45.0%, GPT-4 30.0%, debate 26.67%, ReAct 23.33% |
| A1 Math, plane problem with 3 hints | Trials solved out of 3 (Appendix D) | AutoGen 3, Code Interpreter 2, plugin 2, AutoGPT 0 |
| A2 Retrieval, Natural Questions | F1 and recall, GPT-3.5-turbo (Figure 4b) | F1 25.88 / 22.79 (no UPDATE CONTEXT) / 15.12 (DPR); recall 66.65 / 62.59 / 58.56; 19.4% of questions updated context |
| A3 ALFWorld, 134 tasks | Success rate (Table 3) | Average: ReAct 54, 2 agents 54, 3 agents 69. Best of 3: 66, 63, 77 |
| A4 OptiGuide, 100 tasks | F1 at flagging unsafe code (Figure 4d) | GPT-4: 96 vs 88 (single agent). GPT-3.5-turbo: 83 vs 48 |
| A4 OptiGuide, effort | Code, time, prompts | 430 to 100 lines; 4 min 35 s to about 1.5 min; 3.03 to 4.88 times fewer prompts |
| A5 Group chat, 12 tasks | Successes and calls (Tables 5, 6) | GPT-4: role-play 11, two-agent 9, task-based 8; calls 4.5, 6.8, 4.0 |
| A6 Chess | Case study, no score | A board agent kept moves legal; prompting alone did not |
| A7 MiniWob++, 49 tasks | Success rate (Figure 18) | MiniWobChat 52.8%, 3.6 points under RCI (so RCI is 56.4%, computed) |
This sketch joins the pieces from Chapters 1, 3 and 5. It is our own teaching code that follows the paper’s mechanism. It is not the library’s source, and you must add a sandbox before running model-written code.
pythonimport re, subprocess class Agent: # a conversable agent (Chapters 2 and 3) def __init__(self, name, reply_funcs, max_auto_reply=10): self.name, self.reply_funcs, self.history = name, reply_funcs, [] self.max_auto_reply, self.n_auto = max_auto_reply, 0 def send(self, msg, to): self.history.append((self.name, msg)); to.receive(msg, sender=self) def receive(self, msg, sender): self.history.append((sender.name, msg)) if "TERMINATE" in msg or self.n_auto >= self.max_auto_reply: return # stop rules reply = self.generate_reply() if reply is not None: self.n_auto += 1; self.send(reply, to=sender) # the auto-reply rule def generate_reply(self): for fn in self.reply_funcs: # first function that answers wins out = fn(self.history) if out is not None: return out def llm_reply(name, system, llm): # a model-backed reply function (Chapter 1) def fn(history): chat = [{"role": "system", "content": system}] + [ {"role": "assistant" if who == name else "user", "content": text} for who, text in history] return llm(chat) return fn def code_reply(history): # a tool-backed reply function (Chapter 5) blocks = re.findall(r"```(?:python|sh)?\n(.*?)```", history[-1][1], re.S) if not blocks: return None run = subprocess.run(["python", "-c", blocks[0]], capture_output=True, text=True, timeout=60) return f"exitcode: {run.returncode}\n{run.stdout}{run.stderr}" SYSTEM = "You are a helpful AI assistant. Solve tasks with code. Reply TERMINATE when done." assistant = Agent("assistant", [llm_reply("assistant", SYSTEM, my_llm)]) user_proxy = Agent("user_proxy", [code_reply], max_auto_reply=5) # a hard cap as a backstop user_proxy.send("Plot META and TESLA stock price change YTD.", to=assistant) # the chat now runs itself
Read it line by line. The stop rules sit in receive. The auto-reply rule sits in the last two lines of receive. The model is one reply function and the tool is another, so adding a human means adding a third function that asks for input first. Everything else in the paper is a variation: a manager that picks among many agents, a function that starts a second chat, or a third agent that checks the first.
The paper compares itself with single-agent tools (AutoGPT, LangChain agents, ChatGPT plugins) and fixed-order multi-agent systems (BabyAGI, CAMEL, debate, MetaGPT). Its claim is generality: one conversation layer for static and dynamic chats, code, tools and people. The Stanford CS 329Z lecture on frameworks compares ways to split control between the model and your code, which makes a good next read.
Qingyun Wu, Gagan Bansal, Jieyu Zhang, Yiran Wu, Beibin Li, Erkang Zhu, Li Jiang, Xiaoyun Zhang, Shaokun Zhang, Jiale Liu, Ahmed Awadallah, Ryen W. White, Doug Burger and Chi Wang. “AutoGen: Enabling Next-Gen LLM Applications via Multi-Agent Conversation.” arXiv:2308.08155, 2023. Read the paper. Code: github.com/microsoft/autogen. This lesson re-teaches the paper in our own words and devices; every number comes from the paper, or is labelled as computed or illustrative.
Now press Present or Teach and explain from memory why the hero chat ran itself. Name the three abilities, the auto-reply rule, the two ways to stop, and one thing the paper does not prove. Then go back to the instrument and run the three modes again.