Comparison and Selection Guide for Mainstream Open Source AI Agent Frameworks
This article provides a comprehensive comparison and selection guide for self-deployable open-source AI agent frameworks. It covers mainstream projects including LangGraph, AutoGen, CrewAI, and OpenHands, detailing their capabilities, architectural layers, context management strategies, and session persistence. Readers will gain insights into workflow orchestration, security boundaries, and practical checklists for choosing the right framework for their enterprise needs.
This article discusses self-deployable and customizable open-source AI agent development frameworks and programming agent projects, excluding closed-source commercial platforms. The following table summarizes these projects based on public documentation and repository designs. Please verify the latest documentation for current capabilities before making a selection.
I. Overview of Mainstream Projects
| Project | Maintainer | Positioning | Orchestration | State Persistence | Sandbox |
|---|---|---|---|---|---|
| LangGraph | LangChain Team | Stateful graph orchestration library | Explicit definition of nodes, edges, and conditional branches | Built-in checkpointing mechanism, can connect to own database | Not provided by the framework itself, requires self-isolation |
| AutoGen | Microsoft initiated open-source project | Multi-agent conversation framework | Multi-agent conversation and group chat collaboration | Requires custom storage to save sessions | Provides Docker code executor |
| CrewAI | CrewAI Team | Role-based multi-agent collaboration | Orchestrated by roles, tasks, and workflows (sequential or hierarchical) | Built-in short-term and long-term memory modules | Not provided by the framework itself, requires self-isolation |
| OpenHands | All Hands AI | Autonomous coding agent for software development | Event-driven agent loop | Sessions and events can be persisted | Execution environment usually runs in Docker containers |
The primary differences among these projects lie in control ownership. LangGraph codifies the workflow, allowing developers to decide the path of each step. AutoGen and CrewAI rely more on dialogues and role divisions among agents. OpenHands separates the agent from the execution runtime, making it suitable for tasks that directly manipulate code repositories.
II. Architectural Layering: The Three-Layer Model
Most frameworks can be divided into three layers. The model access layer handles communication with Large Language Models (LLMs), shields API format differences across vendors, and manages multi-model switching. The logical control layer is the core of the agent, encompassing context management, tool routing, state machines, and workflows. The application and interface layer provides SDKs, command-line interfaces, or web UIs.
Pluggable design is also prevalent. MCP (Model Context Protocol) is an open protocol that allows agents to access external tools and data sources in a unified manner. The benefit of adopting standard protocols is that tools can be reused across different frameworks without rewriting adaptation code for each one.
III. Context Management: Choosing a Compression Strategy
Historical dialogues, reasoning records, and tool return results will continuously grow, eventually exceeding the model’s context window. The three common strategies apply to different scenarios.
| Strategy | Applicable Scenario | Trigger Mechanism | Cost | Main Risk |
|---|---|---|---|---|
| Sliding Window | Short tasks, Q&A interaction | Exceeds fixed rounds or token limit | Low, no extra model calls | Loss of early goals and constraints |
| Summary Extraction | Long tasks, requires retaining decision chains | Exceeds preset threshold | Medium, requires an extra model call | Summary distortion, numbers or constraints rewritten |
| Vector Retrieval (RAG) | Abundant historical data, requires on-demand recall | Similarity retrieval per round | Medium to high, requires vector database and embedding computation | Missing key segments, or injecting irrelevant content |
There is no universal threshold; it must be determined through testing based on the model window size and task length. A common combination is: retain the verbatim text of the most recent rounds, generate summaries for older history, and store user preferences and project constraints as fixed memory to be loaded at the start of each session. This ensures neither short-term details nor long-term constraints are lost.
IV. Session Persistence and Crash Recovery
Long-running tasks inevitably encounter network interruptions, model timeouts, or process crashes. The goal of persistence is to recover from the latest checkpoint rather than executing from scratch. Three things must be determined during implementation.
First, the checkpoint storage location. Relational databases are suitable for scenarios requiring querying and auditing; key-value stores or object storage suit larger intermediate results.
Second, the timing of checkpoints. Typically, a write operation occurs after each model call and tool call completion.
Third, the idempotency of side-effect tools. Operations like sending emails, writing files, or calling payment APIs may be executed repeatedly if retried before results are persisted. Before retrying, you should query whether the operation has already taken effect, or assign a unique identifier to each call to let the downstream system deduplicate.
Retry strategies must also differentiate error types. Rate limits (e.g., HTTP 429), timeouts, and server-side 5xx errors are suitable for exponential backoff with random jitter, with a maximum retry limit. Deterministic errors like parameter errors or insufficient permissions should fail immediately, as retries are meaningless.
V. Tool Calling and Parameter Validation
Tool definitions typically use JSON Schema, including name, functional description, and parameter constraints. The clearer the description, the lower the probability of the model selecting the wrong tool.
Before execution, the framework should validate parameters against the schema. Upon validation failure, specific error information should be returned to the model to allow it to correct and retry, with a retry limit—commonly two to three times.
Tool returns can be very lengthy, such as a complete log or a large file. A safer approach is to truncate the return, keeping the beginning and end while noting the omitted length. The full content can be stored separately and read on demand.
VI. Workflow Orchestration: Plan Mode, Sub-agents, and State Machines
Plan mode is suitable for tasks with many steps or significant impact. The agent first outputs a plan, which is executed after confirmation by the user or rules, and can be adjusted based on results during execution.
Sub-agents are suitable for independent sub-tasks, such as simultaneously reviewing multiple modules. They are not suitable for highly dependent serial steps. Each sub-agent must repeatedly load context, increasing coordination costs and token consumption.
State machines are suitable for fixed workflows requiring auditing. Code determines the flow direction, while the LLM handles judgments within each node. This division of labor is more predictable than relying entirely on the model to determine the flow.
VII. Security Boundaries
Code execution agents carry the highest risk. Sandbox is the first line of defense, commonly in the form of Docker containers or WebAssembly environments. When configuring, limit the following:
- File System: Mount only necessary directories, and set them to read-only where possible.
- Network: Use whitelists, prohibiting access to internal network addresses.
- Resources: Set limits on CPU, memory, and execution time.
- Host Interface: Do not mount the Docker socket into the container, otherwise processes inside the container might gain host control.
Containers share the kernel with the host, resulting in limited isolation strength. For scenarios with high security requirements, consider virtual machines or stronger isolation solutions.
Regarding permissions, tools should be authorized by role (RBAC). High-risk operations such as deleting data, sending external messages, or deploying to production should require manual confirmation.
Audit logs should record the following fields: timestamp, session ID, operating user, tool name, desensitized parameter summary, execution result, and approver. API keys or sensitive personal information should not appear in logs.
VIII. Selection Suggestions and Checklist
- If you need precise control over the workflow and support for breakpoint recovery: Prioritize state graph frameworks like LangGraph.
- If you need multi-role discussions or collaborative division of labor: Evaluate AutoGen or CrewAI.
- For automated fixing and development oriented towards code repositories: Refer to the runtime design of OpenHands.
When making a selection, verify the following questions item by item: Does it have built-in checkpointing, and can checkpoints be written to your own storage? Can code execution be placed in a sandbox? Does the tool protocol support MCP or custom integration? Does the license meet enterprise compliance requirements? How active are the project’s release frequency and community?
During enterprise deployment, you can reuse existing cloud platform object storage, message queues, and container services to build a scalable runtime environment. Regardless of the framework chosen, always validate the recovery process and permission boundaries in a test environment before moving to production.
