AutoGen Core Concepts
AutoGen is an open‑source, event‑driven framework for building conversational, tool‑augmented AI agents. It models applications as conversations between agents, where messages, tools, and events flow through a managed runtime. This handbook article focuses strictly on implementation: you’ll learn how AutoGen’s core abstractions—agents, messages, conversations, tools, events, and the runtime—work together, and how to use them to build reliable, production‑ready agent systems.
What Is AutoGen
AutoGen is a conversation‑driven agent framework. Instead of defining a rigid workflow graph, you define agents that respond to messages, invoke tools, and emit events. The runtime orchestrates the conversation, delivering messages, handling tool executions, and providing hooks for observability and human‑in‑the‑loop.
An AutoGen agent is a message handler: it receives a message, reasons (using an LLM or custom logic), optionally calls tools, and returns a response. Agents communicate asynchronously through typed messages. Everything—tool calls, approvals, errors—is modeled as events, giving you fine‑grained control and complete traceability.
A minimal conceptual example:
from autogen_agentchat.agents import AssistantAgent
from autogen_ext.models.openai import OpenAIChatCompletionClient
from autogen_agentchat.messages import TextMessage
# Create an LLM client
model_client = OpenAIChatCompletionClient(model="gpt-4o")
# Define an assistant agent with a tool
assistant = AssistantAgent(
name="assistant",
system_message="You are a helpful assistant.",
model_client=model_client,
tools=[...]
)
# Send a message and get a response
response = await assistant.on_messages(
[TextMessage(content="What's the weather?", source="user")],
cancellation_token=None
)
Under the hood, AutoGen tracks the conversation state, calls the LLM, executes tools, and returns the final response—all as an asynchronous operation.
Why AutoGen Exists
Building complex agent systems from scratch forces developers to solve the same recurring problems: multi‑turn conversation management, tool execution lifecycle, error recovery, and observability. AutoGen provides these out of the box:
- Simplify agent orchestration – Agents communicate via typed messages; the runtime handles delivery, queuing, and concurrency.
- Support conversational workflows – Interactions flow naturally as dialogues, not as a pre‑defined pipeline. Agents can clarify, ask for more information, or delegate to sub‑agents.
- Enable tool‑augmented agents – Tools are first‑class citizens. An agent can call multiple tools, handle their outputs, and retry on failure.
- Improve development productivity – Declare agents and tools, then run them. No need to build custom state machines or message buses.
- Support production deployments – Built‑in support for message persistence, cancellation tokens, telemetry, and human‑in‑the‑loop.
AutoGen is designed for the real world: asynchronous, resilient, and observable by default.
Core Concepts Overview
| Concept | Purpose |
|---|---|
| Agent | The execution unit that processes messages and generates responses |
| Messages | Typed communication payloads (text, tool calls, events) |
| Conversations | Sequences of messages between agents, managed by the runtime |
| Tools | External functions or APIs that extend agent capabilities |
| Events | Runtime‑level signals that drive execution (tool requests, completions, errors) |
| Runtime | The execution environment that schedules agents, delivers messages, and manages state |
| Workflows | Higher‑level orchestration patterns (group chat, handoffs, sequential tasks) |
These building blocks compose to form any agentic application—from a simple question‑answer bot to a multi‑agent research team.
Agent
What Is an Agent
An Agent is an autonomous component that:
- Receives a list of messages (the conversation so far)
- Processes them—typically by calling an LLM—and decides what to do next
- May emit tool call requests
- Returns a final response (or multiple messages) back to the conversation
Agents are defined with a name, a system message (persona), a set of tools, and a model client. They can also have custom logic (e.g., a rule‑based agent that doesn’t use an LLM).
Creating an assistant agent with a tool:
from autogen_agentchat.agents import AssistantAgent
from autogen_ext.models.openai import OpenAIChatCompletionClient
from autogen_core.tools import FunctionTool
def get_temperature(city: str) -> str:
return f"The temperature in {city} is 22°C"
temp_tool = FunctionTool(get_temperature, description="Get temperature for a city")
assistant = AssistantAgent(
name="weather_bot",
system_message="You provide weather information. Use the tool when needed.",
model_client=OpenAIChatCompletionClient(model="gpt-4o"),
tools=[temp_tool]
)
When the agent receives a message, it:
- Appends the new message to the conversation history.
- Sends the history to the LLM.
- If the LLM requests a tool call, AutoGen pauses the agent, emits a tool call request event, and waits for the tool to be executed (the runtime handles this).
- After tool results are injected as messages, the LLM continues reasoning.
- Finally, the agent returns a response.
This lifecycle is fully managed and can be interrupted (e.g., for human approval) via cancellation tokens and custom event handlers.
Messages
Messages are the typed, serializable data structures that flow between agents and the runtime. Every interaction—user input, agent response, tool call, error—is a message.
Key message types include:
TextMessage– Plain text content (user or agent).ToolCallRequestEvent– An agent requests a tool execution.ToolCallExecutionEvent– The result of a tool call.HandoffMessage– An agent delegates to another agent.StopMessage– Indicates the conversation should end.
Creating and sending a message:
from autogen_agentchat.messages import TextMessage
user_message = TextMessage(content="Hello!", source="user")
response = await agent.on_messages([user_message], cancellation_token=None)
Messages are Pydantic models, ensuring structure and enabling serialisation for persistence and cross‑service communication. The runtime uses message sequences to reconstruct conversation state.
Conversations
A conversation is the sequence of messages exchanged among agents. The runtime maintains the full history and provides it to agents so they can produce context‑aware responses.
Important aspects:
- Conversation lifecycle – Starts with an initial user message, proceeds with agent responses and tool interactions, and ends when a
StopMessageis emitted or a termination condition is met. - Context management – The entire message history is available to agents, but you can implement truncation or summarization strategies to stay within token limits.
- Message sequencing – Messages are strictly ordered. The runtime ensures that an agent sees a consistent, immutable snapshot of the conversation.
In a group chat, multiple agents participate in a shared conversation. The GroupChatManager controls which agent speaks next based on a selection strategy (round‑robin, LLM‑driven, etc.).
Tools
Tools allow agents to perform actions beyond pure text generation: search the web, run code, query databases, call APIs. In AutoGen, a tool is a function wrapped in a FunctionTool object that includes a name, description, and a JSON schema of its parameters.
Defining a custom tool:
from autogen_core.tools import FunctionTool
from pydantic import BaseModel
class AddArgs(BaseModel):
a: float
b: float
def add(a: float, b: float) -> float:
return a + b
add_tool = FunctionTool(add, description="Add two numbers", args_type=AddArgs)
When an agent’s LLM requests a tool call, AutoGen:
- Emits a
ToolCallRequestEventcontaining the tool name and arguments. - The runtime dispatches the request to a tool executor (which can run locally or remotely).
- The executor returns a
ToolCallExecutionEventwith the result. - The agent receives the result as a message and resumes reasoning.
Tool execution can be sandboxed, retried, and monitored. Agents can have multiple tools; the LLM chooses which (if any) to use.
Events
Events are the runtime’s coordination mechanism. They are not only internal signals but can also be consumed by developers to hook into the execution flow.
Key events:
ToolCallRequestEvent– emitted when an agent wants to call a tool.ToolCallExecutionEvent– emitted when a tool finishes (success or error).MessageEvent– wraps any message (e.g.,TextMessage) for distribution.GroupChatPause– signals a pause for human input.ConversationTerminated– indicates the conversation ended.
You can intercept events using an event handler. For example, to log every tool call:
async def log_tool_calls(agent, event, context):
if isinstance(event, ToolCallExecutionEvent):
print(f"Tool {event.content[0].name} returned: {event.content[0].content}")
Event handlers are registered on agents or the runtime, enabling custom logic (logging, auditing, human approval) without changing agent code.
Workflows
While individual agents can handle simple tasks, complex applications require multiple agents cooperating. AutoGen provides workflow patterns:
- Group chat – Multiple agents participate in a shared conversation. The
GroupChatManagerselects the next speaker based on a strategy (e.g.,RoundRobinGroupChat,SelectorGroupChat). - Handoffs – An agent can delegate to another agent via a
HandoffMessage. This is ideal for triage: a receptionist agent routes to a specialist. - Sequential task chains – A series of agents run one after another, each processing the output of the previous (achieved through custom orchestration or the new
TaskRunner).
Example: a simple triage and handoff workflow.
# Receptionist agent decides which specialist to hand off to.
# It emits a HandoffMessage with the target agent's name.
Workflows are built by composing agents and configuring group chat managers. The runtime ensures messages are delivered, and all participants see the shared conversation state.
Runtime
The Runtime is the execution environment that:
- Instantiates agents and manages their lifecycle.
- Maintains the message bus and delivers messages.
- Executes tools (via a tool executor).
- Manages conversation state and persistence.
- Handles cancellation and timeouts.
You interact with the runtime through a AgentRuntime instance. In the simplest case, you directly call agent.on_messages(...) and the runtime is implicit. For more complex setups, you deploy an AgentRuntime with registered agents and run it as a service.
from autogen_core import AgentRuntime, SingleThreadedAgentRuntime
from autogen_agentchat.agents import AssistantAgent
runtime = SingleThreadedAgentRuntime()
await AssistantAgent.register(runtime, "assistant", ...)
runtime.start()
The runtime can be persisted (backed by a database), enabling long‑running agents that survive restarts.
Execution Lifecycle
A typical interaction—user asks a question, agent uses a tool, returns an answer—follows this lifecycle:
- Input – The user (or another system) sends a message.
- Agent processing – The agent receives the conversation, invokes the LLM, and decides to use a tool.
- Tool invocation – The runtime intercepts the tool request, executes the function, and returns the result.
- Response – The agent integrates the tool output and generates the final answer.
- Continuation – If the conversation continues, steps 2‑4 repeat.
The runtime records every message and event, enabling full traceability.
Context Management
Agents need to remember previous turns. AutoGen manages context through the message history:
- Each agent maintains a list of messages representing the conversation.
- When
on_messagesis called, the new messages are appended. - The full history (up to a limit) is passed to the LLM on each turn.
- For long conversations, you can implement a message buffer that keeps only the last N messages, or use a summarization middleware that compresses older history.
The runtime can save and load state via save_state() and load_state() methods. This enables persistence across sessions. To keep agents stateless, you can use an external store (database) to persist conversation history and pass it back when resuming.
AutoGen Development Model
Overall, the development model is:
Input (User) → Messages → Agents (LLM + Tools) → Events → Output
You define agents, their tools, and the group chat configuration. The runtime handles the event loop. This model is asynchronous and event‑driven, making it well‑suited for handling concurrent conversations and long‑running workflows.
AutoGen vs Other Frameworks
| Framework | Approach | Strengths | Weaknesses |
|---|---|---|---|
| AutoGen | Conversation‑centric, event‑driven | Asynchronous, scalable, explicit event model, built‑in group chat | Learning curve for event model; less visual graph editor |
| LangGraph | Stateful graph (nodes/edges) | Full control over flow, checkpoints, human‑in‑the‑loop | More boilerplate; steeper learning curve for new users |
| CrewAI | Role‑based task delegation | Simple, declarative, fast prototyping | Limited dynamic routing; less suited for highly adaptive conversations |
| OpenAI Agents SDK | Lightweight agent runner | Tight OpenAI integration, simple | Limited multi‑agent coordination; lacks built‑in persistence/event model |
AutoGen’s key differentiator is its event‑driven, conversation‑first architecture. It treats agent interactions as a real‑time dialog, with tool calls and approvals modeled as events. This makes it ideal for complex, interactive systems where you need fine‑grained control and observability.
Common Beginner Mistakes
- Over‑complicating agent definitions – Starting with too many agents and complex handoffs before a simple flow works.
- Poor message design – Not using the right message types or customizing messages poorly; leads to parsing errors.
- Ignoring event handling – Failing to hook into
ToolCallRequestEventorToolCallExecutionEventfor logging, error recovery, or human‑in‑the‑loop. - Excessive tool usage – Giving agents dozens of tools without proper descriptions or overlap detection, causing LLM confusion.
- Weak context management – Not truncating or summarizing long conversations, leading to token overflow and high cost.
- Misunderstanding the runtime – Trying to use the runtime synchronously in an async context, or not properly handling cancellation tokens.
Best Practices
- Keep agents focused – Each agent should have a single responsibility and a small set of well‑described tools.
- Use structured messages – Leverage the predefined message types and extend them if needed.
- Design predictable workflows – Start with simple group chats (
RoundRobinGroupChat) and add complexity gradually. - Monitor event flows – Subscribe to events in development; you’ll see exactly why an agent took a certain action.
- Limit unnecessary context growth – Implement message trimming or summarization middleware.
- Handle tool errors gracefully – Use
ToolCallExecutionEventto detect failures and provide fallback responses. - Use persistence for production – Enable runtime state saving/loading to recover from crashes.
Practical Example: Research Assistant Workflow
Let’s build a simple research assistant that uses a web search tool. The user asks a question; the assistant decides to call the search tool, receives the results, and synthesizes an answer.
1. Define the tool
from autogen_core.tools import FunctionTool
from pydantic import BaseModel
class SearchArgs(BaseModel):
query: str
def web_search(query: str) -> str:
# Simulated search
return f"Top result for '{query}': ..."
search_tool = FunctionTool(web_search, description="Search the web", args_type=SearchArgs)
2. Create the assistant agent
from autogen_agentchat.agents import AssistantAgent
from autogen_ext.models.openai import OpenAIChatCompletionClient
model_client = OpenAIChatCompletionClient(model="gpt-4o")
assistant = AssistantAgent(
name="research_assistant",
system_message="You are a research assistant. Use the search tool to find information, then answer.",
model_client=model_client,
tools=[search_tool]
)
3. Run a conversation
from autogen_agentchat.messages import TextMessage
history = []
user_msg = TextMessage(content="What is the latest on AI agents?", source="user")
history.append(user_msg)
response = await assistant.on_messages(history, cancellation_token=None)
print(response.chat_message.content) # final answer
Behind the scenes:
- The assistant receives the message and calls the LLM.
- The LLM returns a tool call request for
web_search. - AutoGen’s runtime invokes the tool and returns the result.
- The assistant sees the search result, calls the LLM again, and produces a final
TextMessageanswer. - The entire sequence—messages, tool requests, results—is recorded in the history.
This minimal example illustrates the conversation‑centric model. For multi‑agent research, you’d add a coordinator agent and a group chat manager.
AutoGen and Modern Agent Development
AutoGen integrates naturally with modern agent tooling:
- Tool calling – First‑class support for function tools with schemas, retries, and streaming.
- MCP Integration – Connect to any Model Context Protocol server. Load tools from MCP servers and use them directly in AutoGen agents. (See the MCP Guide).
- Workflow design – Use group chats, handoffs, and the
TaskRunnerfor complex, multi‑step processes. - Observability – Events are traceable; integrate with OpenTelemetry, Azure Monitor, or custom logging for production monitoring.
- Production operations – Persist runtime state, use cancellation tokens for timeouts, and deploy as asynchronous services.
FAQ
1. What is AutoGen?
AutoGen is an open‑source framework by Microsoft for building conversational, tool‑augmented AI agents. It uses an event‑driven, asynchronous runtime to manage agent interactions.
2. What is an Agent in AutoGen?
An agent is a message‑processing component that receives a conversation history, reasons (often via LLM), invokes tools, and returns responses.
3. How do Messages work?
Messages are typed, Pydantic‑based data structures that flow between agents and the runtime. They include text, tool calls, and events.
4. What are Events in AutoGen?
Events are runtime signals that represent actions like tool requests, tool results, or conversation milestones. They can be intercepted for logging, human approval, etc.
5. What is the Runtime?
The runtime manages agent execution, message delivery, tool dispatch, and state persistence. It provides the event loop and lifecycle management.
6. How do Tools work?
Tools are Python functions wrapped with FunctionTool. Agents can request tool calls, and the runtime executes them and returns the results.
7. Is AutoGen production‑ready?
Yes. AutoGen supports persistence, cancellation, telemetry, and can be deployed as asynchronous services.
8. How does AutoGen compare to LangGraph?
LangGraph gives explicit control over a state graph. AutoGen is conversation‑centric, making it easier to model dynamic dialogues, but less prescriptive about the exact flow.
9. Can I use AutoGen with non‑OpenAI models?
Yes, via model clients that implement the ChatCompletionClient interface. AutoGen supports any model that conforms to the interface (OpenAI, Azure, Anthropic, etc.).
10. Does AutoGen support human‑in‑the‑loop?
Yes, you can intercept events (like tool call requests) and pause the conversation until a human provides input.
11. Can I have multiple agents in a conversation?
Yes. Use group chat managers (GroupChatManager) to orchestrate multi‑agent conversations.
12. What is a conversation in AutoGen?
A conversation is the sequence of messages exchanged among agents and users. The runtime maintains the history.
13. How do I persist conversation state?
Use runtime.save_state() and load_state() to store and restore the full conversation.
14. What is the difference between AutoGen v0.2 and v0.4+?
v0.4 introduced a complete rewrite with an event‑driven runtime, asynchronous execution, and improved scalability. This handbook covers the modern v0.4+ API.
15. Where can I learn more about AutoGen workflows?
The next articles in this handbook cover conversation patterns, tools and code execution, workflows, and production deployments. Start with the AutoGen Conversation Patterns guide.
Conclusion
AutoGen Core Concepts provide a conversation‑first, event‑driven model for building AI agents. Agents, messages, tools, and events compose into a flexible, production‑ready framework where every interaction is traceable and controllable.
Key takeaways:
- Agents handle messages, reason, and call tools.
- Messages are the typed communication backbone.
- Tools extend agents into the real world.
- Events give you visibility and control.
- The Runtime orchestrates everything asynchronously.
Now that you understand the foundations, dive deeper:
- AutoGen Conversation Patterns – two‑agent chats, group chats, and handoffs.
- AutoGen Tools & Code Execution – building and securing tools.
- AutoGen Workflows – designing complex, multi‑step processes.
- AutoGen Production – deployment, persistence, and observability.
For cross‑framework comparisons, see the LangGraph, CrewAI, and OpenAI Agents SDK guides, and the comprehensive framework comparison. To standardize your tooling with MCP, visit the MCP Guide.
Build agents that converse, act, and evolve—with AutoGen.