A 2023 AutoGen Tutorial: Local Agent Setup and Code Execution

Matthew Berman builds a local assistant and user-proxy workflow, then tests how the agents generate and run Python. AutoGen’s packages and APIs have changed since this tutorial.

MBMatthew BermanPonente · Forward Future
Canal
Matthew Berman
Publicado
10 oct 2023
Vídeo
15:03
Lectura
5 min
Diapositivas
5
Original
inglés
Abrir en YouTube
Al desplazarte, el vídeo se reduce a la esquina inferior derecha y sigue reproduciéndose. Los subtítulos siguen tu idioma de lectura.
Idioma de lecturaDisponible en 2 idiomas
Este artículo aún no está en español, así que se muestra el original en inglés.
RESUMEN

En 30 segundos

In this October 2023 tutorial, Matthew Berman sets up an early AutoGen project in VS Code with a conda environment and an OpenAI model. He configures an assistant and user proxy, tests caching and termination, and observes both successful code execution and instructions the agents misunderstand. This is a historical walkthrough, not a current installation guide. Microsoft’s [migration guide](https://microsoft.github.io/autogen/dev/user-guide/agentchat-user-guide/migration-guide.html) describes breaking API changes and says later releases of the `pyautogen` package are no longer from Microsoft. The video displays a key that Berman says he revoked; the article does not reproduce it.

  1. 1Local environmentThe video creates a Python 3.11.4 conda environment and installs the then-used AutoGen package.
  2. 2Model configuration and cachingThe example configures a model, timeout, cache seed and temperature; modern versions use different APIs and settings.
  3. 3Assistant and user proxyThe proxy controls human input, automatic replies, termination and code execution in the demonstrated legacy design.
  4. 4A stalled first testThe GPT-3.5 example loops without completing the article task, showing why a reply limit matters.
  5. 5Check the actual outputThe GPT-4 examples write numbers and code to files, but do not always follow the intended instruction.

Conclusiones

  1. The tutorial pairs an assistant agent with a user proxy that can exchange messages and execute code.
  2. Human-input and automatic-reply limits control supervision and conversation length, but do not guarantee safe or correct execution.
  3. Berman’s first GPT-3.5 test stalls, while later GPT-4 examples demonstrate both useful output and failures to follow the exact request.
  4. A cache hit can reuse an identical request, but cache configuration and seed names changed in later versions.
  5. Keep API keys out of source control and isolate or disable execution of untrusted generated code.
  6. The package, model names and APIs in this 2023 demonstration are historical; consult the current migration documentation.
TEXTO COMPLETO

Lee el texto editado por capítulos

Solo la transcripción
01

Set up the local environment

Berman introduces AutoGen and creates a conda environment in VS Code. He installs the package used by the 2023 tutorial.

I previously introduced AutoGen and now want to walk through a local Python setup, line by line. The idea is to have AI agents communicate and use tools or code on a user’s behalf. This video dates from October 2023: its library interfaces and model choices are historical, and a later AutoGen version may require different code.

I describe AutoGen as a way to assemble customizable agents that collaborate on tasks. An assistant can generate a response or code, while another agent can represent the user and potentially run that code. These capabilities depend on the configuration and do not mean the agents can reliably accomplish any task.

For the demonstration I use VS Code, Anaconda and an OpenAI account. I create a project folder and `app.py`, open the terminal and create a conda environment named `autogen` with Python 3.11.4. I activate it and check that the interpreter selected in VS Code matches the environment.

I install the package then shown as `pyautogen` and import `autogen`. Do not treat that historical command as a recommendation to install its latest release: Microsoft says it no longer administers that package and later releases are not from Microsoft. Its migration guide explains supported package choices and major API changes.

02

Configure the model and agents

He sets model and cache parameters, then creates an assistant and user proxy. He explains human input and execution settings.

The legacy configuration list names a model, initially GPT-3.5 Turbo 16k, and an API key. I generate and paste a key in the video, saying I will revoke it before publication. For a real project, keep credentials in an environment variable or secret manager and out of source control and recordings; the key in the footage is not reproduced here.

The `llm_config` includes a request timeout, a seed for the version’s caching behavior, the configuration list and a temperature of zero. I use a low temperature for a coding example. Temperature affects sampling, not a guaranteed measure of creativity or correctness.

Caching can avoid repeated API calls when a matching request is found, saving time and cost. I show a cache associated with seed 42 and clear it to force fresh runs. Cache behavior depends on request matching and version: later AutoGen documentation distinguishes its `cache_seed` from a model provider’s sampling `seed`.

I create an `AssistantAgent` with a name and the model configuration. Multiple assistants can be given distinct roles, such as a CTO and CEO, using system messages. This particular example uses one assistant and one user proxy; naming roles alone does not make them independent experts.

The `UserProxyAgent` acts on the user’s behalf and may send replies or execute generated code. The older tutorial shows three human-input modes: `ALWAYS`, `TERMINATE` and `NEVER`. In the legacy documentation, `TERMINATE` can prompt on a termination message or when the automatic-reply limit is reached, not only when a task is genuinely complete.

Legacy assistant and user proxy
DIAPOSITIVA 1 / 5Legacy assistant and user proxyThe example begins defining the assistant and user proxy in the older AutoGen API.

I set `max_consecutive_auto_reply` to 10 and define a termination-message check. The cap limits an unproductive exchange and its cost, though it is not a guarantee that a task is complete. The `web` working directory holds the demonstration’s generated files.

Input and termination settings
DIAPOSITIVA 2 / 5Input and termination settingsThe displayed proxy configuration includes a human-input mode, an automatic-reply limit and a termination check.

The proxy’s code-execution setting allows generated code to run, which has real consequences for files and the environment. A working directory is not a security boundary. Review generated code and restrict execution; the legacy AutoGen documentation recommends Docker isolation for code execution, or it can be disabled.

03

Run and revise tasks

A first test loops, and subsequent examples generate files with GPT-4. The output reveals how ambiguous instructions can lead to unintended results.

I write a task asking for an article summary, then start the conversation with the user proxy’s `initiate_chat` method, passing in the assistant and the task as the message. The 2023 API shown is an example of the older design; newer AutoGen versions changed the agent and execution interfaces.

An unproductive agent exchange
DIAPOSITIVA 3 / 5An unproductive agent exchangeThe first run loops through polite responses instead of completing the requested task.

The initial GPT-3.5 run does not complete the article task. Instead, the agents exchange unhelpful messages. I point to the limit of 10 automatic replies as a useful guard against an excessively long conversation, and show the cache created by the run.

For a simpler test, I switch to GPT-4, clear the cache and ask for Python to output the numbers 1 through 100 and store the result in a file. The agent produces `numbers.txt` containing the numbers. That works as a file-writing task, but it is not the code file I intended.

Numbers written to a file
DIAPOSITIVA 4 / 5Numbers written to a fileThe working directory contains a text file with generated numbers, exposing a mismatch with the intended code-file request.

After accidentally exiting before giving feedback, I revise the prompt to explicitly ask for the code to be saved in a file. I clear the previous outputs and rerun it. This time the demonstration produces a Python file in the working directory, showing why the exact instruction and the actual artifact both matter.

04

A second task and next steps

Berman asks the agents to modify the first result, then examines the files. He discusses protecting credentials and improving the project structure.

I add a second task asking the agents to change the code from outputting 1–100 to 1–200, and initiate another conversation. For this run I switch human input to `NEVER`. That removes the approval opportunity in the workflow; it does not make automatic code execution risk-free.

The second run does not follow my intended instruction exactly: the existing Python file remains, and the agents create a text file with numbers through 200 and code to update it. I attribute part of the mismatch to an insufficiently precise prompt, while the observed result also shows that generated agents can misunderstand a task.

The second run’s result
DIAPOSITIVA 5 / 5The second run’s resultThe assistant reports a file containing numbers 1–200; Berman notes that this did not exactly match his instruction.

I suggest moving the model and API key into environment variables or a separate configuration file, keeping secrets out of commits, and organizing the agent definitions. The example can be extended with other tasks or agents, but current users should follow version-specific documentation and verify generated code and outputs.

Más de este canal

12 diapositivas34:21EN
Matthew Berman· 27 oct 2026Matthew Berman Examines Anthropic’s IPO Filing, AI Growth and GovernanceMatthew Berman, Sam Altman · Forward FutureThe presenter reviews the S-1’s financial metrics, compute strategy and voting structure while questioning the tension between rapid AI development and safety.AnthropicAI SafetyIA empresarial+2
2 diapositivas0:36EN
Matthew Berman· 25 oct 2026Kimi K3.1 and a Rubik’s Cube Solver DemonstrationMatthew Berman · Forward FutureMatthew Berman shows a scrambled virtual cube being solved and gives the Kimi K3.1 test a favorable assessment.EvaluacionesAgentes de programaciónOpen-weight models
6 diapositivas25:50EN
Matthew Berman· 24 oct 2026Kimi K3.1 Pro Tested: Strong 3D Demos, Uneven Results and Competitive PricingMatthew Berman · Forward FutureMatthew Berman tests the open-weight model on coding, 3D rendering and visual explanations, then compares benchmark results and prices.Open-weight modelsBenchmarksAI cost & performance+1
2 diapositivas32:20EN
Matthew Berman· 23 oct 2026Who Is Local AI For? The Costs, Trade-offs and a Hybrid FutureMatthew Berman · Forward FutureMatthew Berman weighs data control and independence against hardware cost, setup complexity and inference speed.Local inferenceOpen-weight modelsAI cost & performance+1
6 diapositivas1:03:37EN
Matthew Berman· 23 oct 2026Matthew Berman’s Team Tests Kimi K3.1 on Animation, Games, and ChartsMatthew Berman, Alex, Brian · Forward FutureA live team AMA turns into an informal test of Kimi K3.1, from personal-agent workflows to motion graphics, a browser game, and a benchmark chart.Agentes de programaciónGenerative mediaEvaluaciones+2
0:53EN
Matthew Berman· 22 oct 2026Sam Altman on AI and the Discovery of New KnowledgeSam Altman · OpenAIAltman expects progress in mathematical discovery to extend to biology, materials and energy.AI for scienceMathematicsComputational Biology+1