Skip to content
BotServBotServ
AutoGenAI AgentMulti-AgentFrameworkWorkflowLocal AICoding

AutoGen

Install and use AutoGen. Multi-agent conversations, coding assistance, and local AI with Ollama.

S

schutzgeist

3 min read
AutoGen

AutoGen

What this article covers

  • What AutoGen is and what you can use it for.
  • How to install AutoGen with Python.
  • How to integrate a local model via Ollama as a backend.
  • A concrete example with two agents having a conversation.
  • Which use cases work particularly well.
  • Common pitfalls and how to avoid them.

Introduction

AutoGen is a Microsoft framework for multi-agent systems. It shines when multiple AI agents need to work together to solve a problem, whether that’s writing code, creating documentation, or debugging. The agents communicate over multiple rounds until you reach an acceptable result. The key advantage: AutoGen can execute suggested code directly, making it a powerful tool for developers.

AutoGen explained

AutoGen centers on agents that communicate with each other. Each agent has a system prompt that describes how it behaves. A typical setup pairs a coder agent with a reviewer agent. The coder writes code, the reviewer checks it, and the process continues until the result is good enough.

Installation

AutoGen runs on Python. To get started, you only need pip:

pip install pyautogen

For code execution, Docker is a worthwhile addition so that code runs in isolation. If you prefer to skip Docker, you can run code in a virtual environment or on a test system instead.

Using a local model with Ollama

For local AI, install Ollama and pull a model:

ollama run llama3.1

AutoGen talks to Ollama via the OpenAI-compatible API at http://localhost:11434/v1. The API key can be any value since Ollama doesn’t require authentication.

When is AutoGen useful?

Use caseWhat AutoGen does
Writing codeWrites and reviews code, executes it, and fixes errors
DebuggingCoder and reviewer discuss potential error sources
DocumentationExplains code and creates appropriate comments
LearningShows step by step why code works the way it does
AutomationBuilds small scripts for recurring tasks

Practical example: coder and reviewer

from autogen import ConversableAgent

# Local model via Ollama
llm_config = {
    "config_list": [
        {"model": "llama3.1", "base_url": "http://localhost:11434/v1", "api_key": "ollama"}
    ]
}

coder = ConversableAgent(
    name="coder",
    system_message="You are an experienced Python developer.",
    llm_config=llm_config,
    human_input_mode="NEVER"
)

reviewer = ConversableAgent(
    name="reviewer",
    system_message="You review code for errors and improvement potential.",
    llm_config=llm_config,
    human_input_mode="NEVER"
)

result = coder.initiate_chat(
    reviewer,
    message="Write a Python function that sorts a list of numbers.",
    max_turns=3
)

print(result)

In this example, the coder and reviewer talk back and forth over multiple rounds. The max_turns parameter limits the number of exchanges to prevent infinite loops. For initial experiments, it’s a helpful safety measure.

Common pitfalls and decision guidance

  • Infinite loops - Without max_turns or clear stopping conditions, agents can keep debating indefinitely.
  • Code execution - AutoGen can run code. Locally, you should do this in a sandbox, container, or with caution.
  • LLM configuration - For Ollama, the OpenAI-compatible API needs the /v1 suffix at the base_url.
  • When to use AutoGen over CrewAI? AutoGen excels at coding and multi-turn conversations. CrewAI is stronger for role-based workflows.
  • AutoGen is designed for multi-agent conversations and coding tasks.
  • Agents communicate via messages over multiple rounds.
  • Code execution is possible but should be secured.
  • Learn more about agents in What is an AI agent? and CrewAI.

FAQ - Common questions about AutoGen

Does AutoGen run locally?

Yes. You can use Ollama as an OpenAI-compatible model backend without sending data to the cloud.

How do I install AutoGen?

With pip install pyautogen. For code execution, Docker is recommended as an additional security layer.

Is AutoGen free?

Yes, the open-source framework is available under the MIT license.

Can AutoGen execute code?

Yes, with a UserProxyAgent or a code execution environment. Locally, you should do this in an isolated environment.

When should I use AutoGen?

Particularly for coding assistance, code reviews, and complex problem-solving where multiple agents should discuss the solution.

How is this different from CrewAI?

CrewAI uses roles and tasks. AutoGen uses conversation-based multi-agent systems with a focus on coding.

Which model do I need locally?

For coding examples, strong 7B or 13B models like Qwen 2.5 Coder or Llama 3.1 work well. More VRAM lets you run larger models.

Can I use AutoGen for content creation?

Yes, especially for technical content, code explanations, and documentation. For pure marketing copy, CrewAI is often a better fit.

Sources

Back to Blog
Share:

Nächster Artikel in AI Agents

Weiterlesen
Camel AI

Related Posts