Choosing the Right AI Agent Framework: LangGraph vs CrewAI vs OpenAI Swarm

This edition of Baiyang Compilation Station presents an article by Yi Zhang published on Medium titled “Choosing the Right AI Agent Framework: LangGraph vs CrewAI vs OpenAI Swarm” (Choosing the Right AI Agent Framework: LangGraph vs CrewAI vs OpenAI Swarm).

Autonomous agents powered by large language models (LLMs) have experienced ups and downs. From the viral demonstrations of AutoGPT and BabyAGI in 2023 to now more refined frameworks, the concept of agents capable of autonomously completing end-to-end tasks has sparked imagination and raised many questions.

Why has this concept gained attention again? Over the past nine months, LLMs have undergone significant upgrades: longer context windows, more structured outputs, stronger reasoning capabilities, and simpler tool integrations. These advancements have made it more feasible than ever to build reliable intelligent agent applications.

In this edition of Baiyang Compilation Station, we will explore three popular frameworks for building intelligent agent applications: LangGraph, CrewAI, and OpenAI Swarm. Through a practical case of an “Intelligent Financial Assistant,” we will analyze the advantages, disadvantages, and applicable scenarios of each framework.

(Scan the QR code below to access the original text)

Choosing the Right AI Agent Framework: LangGraph vs CrewAI vs OpenAI Swarm

Original link:

https://medium.com/relari/choosing-the-right-ai-agent-framework-langgraph-vs-crewai-vs-openai-swarm-56f7931b4249

01

What is an “Agent”?

An agent is an advanced system powered by large language models (LLMs) that can independently interact with the environment and make real-time decisions. Unlike traditional LLM applications, which typically operate according to a fixed predefined process (e.g., A → B → C), the workflow of agents introduces a dynamic and adaptive approach. Agents interact with the environment through tools (functions or APIs), determining the next steps based on context and goals. This flexibility allows agents to break out of fixed procedural sequences, completing complex and ever-changing tasks more autonomously and efficiently.

However, this flexibility also brings some challenges:

1. Managing state and memory between tasks for agents

2. Coordinating multiple sub-agents and their communication patterns

3. Ensuring the reliability of tool calls and properly handling complex error scenarios

4. Addressing reasoning and decision-making issues in large-scale scenarios

02

Why Do We Need Agent Frameworks

Building agents from scratch is not an easy task. Frameworks like LangGraph, CrewAI, and OpenAI Swarm simplify this process, allowing developers to focus on application logic rather than redesigning the fundamental functions of state management, task orchestration, and tool integration.

The core functionalities of agent frameworks include:

1. Simple methods for defining agents and tools

2. Task orchestration mechanisms

3. State management

4. Additional tools for building more complex applications, such as persistence layers (memory), interruption handling, etc.

We will explore these topics in detail in the following sections.

03

Overview of Agent Frameworks

Choosing the Right AI Agent Framework: LangGraph vs CrewAI vs OpenAI Swarm

We chose LangGraph, CrewAI, and OpenAI Swarm because they represent the latest ideas in the field of agent development. Here is a brief overview of each:

1. LangGraph

As its name suggests, LangGraph uses a graph structure as the best way to define and orchestrate agent workflows. Unlike earlier versions of LangChain, LangGraph is a well-designed framework with many robust and customizable features suitable for production use. However, its complexity may seem excessive for certain application scenarios, potentially adding extra overhead.

2. CrewAI

Compared to LangGraph, CrewAI is easier to get started with. It provides intuitive abstract tools that help developers focus on task design without needing to write complex orchestration and state management logic. However, this comes at a cost; it is a highly “opinionated” framework, which may encounter more limitations in subsequent customization.

3. OpenAI Swarm

This is a lightweight, minimalist framework that OpenAI describes as “educational” rather than “production-ready.” OpenAI Swarm can almost be seen as a “reverse framework” — many functionalities need to be implemented by the developer or rely on powerful LLMs to handle themselves. We believe it is well-suited for current simple application scenarios or developers looking to flexibly integrate agent workflows into existing LLM pipelines.

Choosing the Right AI Agent Framework: LangGraph vs CrewAI vs OpenAI Swarm

04

Other Frameworks Worth Noticing

1. LlamaIndex Workflow

This is an event-driven framework that conceptually fits many agent workflows. However, as it stands, developers still need to write a lot of template code to get it running properly. The LlamaIndex team is actively improving its Workflow framework, and we look forward to them releasing more advanced tools soon.

2. AutoGen

This is a multi-agent dialogue orchestration framework developed by Microsoft, which has been applied in various agent scenarios. After learning from the lessons of earlier versions and user feedback, the AutoGen team is undergoing a comprehensive rewrite (from v0.2 to v0.4) to transform it into an event-driven orchestration framework.

05

Building an Intelligent Financial Assistant

To benchmark these frameworks, we built the same intelligent financial assistant using each. The complete application code can be viewed at this URL: GitHub – relari-ai/agent-examples: Example Agent Applications by Relari.ai

We hoped the agent could handle the following complex queries:

1. How does Spirit Airlines’ financial health compare to its competitors?

2. What is Apple’s best-performing product line financially? What are they promoting on their official website?

3. Find consumer stocks with a market cap under $5 billion and an annual revenue growth rate over 20%.

Below is an example snippet of the comprehensive response we received from the assistant:

Choosing the Right AI Agent Framework: LangGraph vs CrewAI vs OpenAI Swarm

To achieve these functionalities, we provided the agent system access to financial databases via the FMP API and allowed it to access the internet for content retrieval.

One of the first choices to make when building intelligent agent AI applications is architectural design. Different architectures have their pros and cons. The following diagram summarizes several common architectures proposed by LangGraph.

Choosing the Right AI Agent Framework: LangGraph vs CrewAI vs OpenAI Swarm

We chose the supervisor architecture for this application, mainly for educational purposes. Therefore, we will create a supervisor agent whose task is to decide which sub-agent to assign tasks to, along with three sub-agents with tool access: a financial data agent, a web research agent, and a summarization agent.

Choosing the Right AI Agent Framework: LangGraph vs CrewAI vs OpenAI Swarm

Let’s explore how each framework implements the following aspects: agent creation, tool integration, orchestration, memory, and human-machine interaction.

1. Defining Agents and Tools

First, we will learn how to define general agents in each framework, such as the financial data agent, web research agent, and output summarization agent, and declare the relevant tools for them. The supervisor agent is a special agent responsible for orchestrating roles, so we will discuss it in detail in the orchestration section.

LangGraph

In LangGraph, the easiest way to create a simple tool-calling agent is by using pre-built functions, as shown below. This method allows us to specify the tools and prompts that the agent needs to operate:

Choosing the Right AI Agent Framework: LangGraph vs CrewAI vs OpenAI Swarm

In LangGraph, everything is built in the form of a graph. This utility function creates a simple executable graph with agent nodes and tool nodes.

Choosing the Right AI Agent Framework: LangGraph vs CrewAI vs OpenAI Swarm

The agent acts as a decision-maker, dynamically determining which tools to call and assessing whether it has enough information to transition to the next state.

In the graph, solid lines represent deterministic edges (tool nodes must always return to the agent node), while dashed lines represent conditional edges, which are the paths the LLM-driven agent decides to take next.

Nodes and edges are the fundamental building blocks of a graph. In the subsequent orchestration section, we will see that this graph can be represented as a node in a larger, more complex graph.

CrewAI

The core of agent definition in CrewAI revolves around the relationship between agents and tasks (i.e., the tasks the agent needs to accomplish).

For each agent, we must define its role, objectives, and task descriptions, and specify the tools it can access.

Then, we need to create the tasks that the agent needs to perform. Tasks must include objectives and task descriptions.

This structured approach to building prompts for LLMs provides a clear and consistent framework, ensuring that agent and task definitions are explicit. This approach helps maintain focus and coherence, but can sometimes appear rigid or repetitive, especially when defining roles, objectives, backstories, and task descriptions multiple times.

Tools can be integrated using the @tool decorator, similar to LangGraph’s approach. Notably, another option is to extend the BaseTool class, which, due to the use of Pydantic models, can enforce a more rigorous architecture definition for tool inputs, thus making it more robust (this method is also supported by LangGraph).

Choosing the Right AI Agent Framework: LangGraph vs CrewAI vs OpenAI Swarm

OpenAI Swarm Swarm adopts a different approach: The idea proposed by OpenAI is to structure the reasoning process into “routines” in the system prompt, rather than explicitly defining the reasoning process in code. Routines are predefined sets of steps or instructions that agents follow to perform tasks. This approach stems from OpenAI’s desire for developers to rely more on the model’s instruction-following capabilities rather than defining custom logic in code. We found this method to be simple and effective when using a powerful LLM, as it can effectively track and reason through these routines.

That is to say, for tools, we can directly introduce them as tools.

2. Orchestration

Now let’s look at how each framework integrates multiple sub-agents in the core part.

LangGraph

The core of LangGraph is graph-based orchestration. We first create a supervisor agent that acts as a router, whose sole task is to analyze the situation and decide which agent to call next. The executing agents can only return results to the supervisor agent.

LangGraph requires explicit state definitions. The AgentState class helps define a unified state architecture across different agents.

Choosing the Right AI Agent Framework: LangGraph vs CrewAI vs OpenAI Swarm

For each agent, we interact with the state by wrapping it in a node that converts the agent’s output into a consistent message architecture.

After this, we can start defining the agents themselves.

Choosing the Right AI Agent Framework: LangGraph vs CrewAI vs OpenAI Swarm

After defining the supervisor agent, we define the agent workflow as a graph, constructing the graph by treating each agent as a node and all execution logic as edges.

When defining edges, we have two options: regular edges or conditional edges. Regular edges are used for cases requiring deterministic transitions. For example, the financial data agent should always return results to the supervisor agent, which decides the next steps.

Conditional edges are used for situations where we want the LLM to decide which path to take (e.g., the supervisor agent determines whether there is enough data to send directly to the output summarization agent or to return data and ask the web agent for more information).

Choosing the Right AI Agent Framework: LangGraph vs CrewAI vs OpenAI Swarm

The generated graph is as follows.

Choosing the Right AI Agent Framework: LangGraph vs CrewAI vs OpenAI Swarm

CrewAI

Compared to LangGraph, CrewAI abstracts most of the orchestration tasks.

Similar to LangGraph, we first create a supervisor agent. This code flag allows the agent to delegate tasks to other agents: allow_delegation.

Next, we use CrewProcess to gather the agents together. Here, it is important to choose hierarchicalProcess to allow the supervisor agent to delegate tasks. Behind the scenes, the supervisor agent converts user queries into tasks and then finds the corresponding agents to execute these tasks. An alternative is to not use a managing agent and instead choose sequential if we want to create a more deterministic process where tasks execute in order.

Choosing the Right AI Agent Framework: LangGraph vs CrewAI vs OpenAI Swarm

OpenAI SwarmSwarm adopts a very simple strategy for orchestration — handoffs. The core idea is to create a transfer function that uses another agent as a tool.

This method is undoubtedly the most concise. The relationships between agents are implicit in the transfer function.

One drawback of this approach is that as applications grow, the dependencies between agents become increasingly difficult to track.

3. Memory

Memory is a key component of stateful agent systems. We can distinguish two levels of memory:

1. Short-term memory: allows agents to maintain multi-turn/multi-step executions.

2. Long-term memory: allows agents to learn across sessions and remember preferences.

This topic can be quite complex, so let’s take a look at the simplest memory orchestration methods in each framework.

LangGraph

LangGraph divides memory into in-thread memory (memory within a single dialogue thread) and cross-thread memory (memory across dialogues).

To save in-thread memory, LangGraph provides the MemorySaver() class, which can save the state of the graph or dialogue history to the .checkpointer.

Choosing the Right AI Agent Framework: LangGraph vs CrewAI vs OpenAI Swarm

To associate agent execution with memory threads, pass a parameter containing thread_id configuration. This tells the agent which thread’s memory checkpoint to use.

Choosing the Right AI Agent Framework: LangGraph vs CrewAI vs OpenAI Swarm

To save cross-thread memory, LangGraph saves the memory to a JSON document store.

Choosing the Right AI Agent Framework: LangGraph vs CrewAI vs OpenAI Swarm

CrewAI CrewAI takes a simpler but stricter approach. On the developer side, you only need to set memory to true.

What it does behind the scenes is quite complex, as it creates several different memory stores:

1. Short-term memory: saves the agent execution history using OpenAI embedded ChromaDB vector storage.

2. Recent memory: saves recent task execution results using an SQLite3 database.

3. Long-term memory: saves task results using an SQLite3 database, noting that task descriptions must match exactly (strict requirements) to retrieve long-term memory.

4. Entity memory: extracts key entities and stores entity relationships in another ChromaDB vector storage.

Choosing the Right AI Agent Framework: LangGraph vs CrewAI vs OpenAI Swarm

OpenAI Swarm Swarm uses a simple stateless design and does not have built-in memory functions. OpenAI’s approach to memory can be referenced through its stateful assistant API. Each dialogue has a thread_id for short-term memory, while each assistant has an assistant_id that can be associated with long-term memory.

Additionally, third-party memory layer providers, such as mem0, can be integrated, or we can implement our own short-term and long-term memory.

4. Human-Machine Collaboration

While we want agents to autonomously perform tasks, many agents are designed to interact with humans.

For example, a customer support agent may ask users for information during execution. Humans can also act as auditors or guides to achieve more seamless human-machine collaboration.

LangGraph

LangGraph allows us to set breakpoints in the graph, such as if we want to add a human checkpoint before the summarizer generates the final output.

For example:

workflow.compile(checkpointer=checkpointer, interrupt_before=[“Output_Summarizing_Agent”])

The code will execute until it reaches the breakpoint. We can then implement a step to get user input and continue executing the rest.

Choosing the Right AI Agent Framework: LangGraph vs CrewAI vs OpenAI Swarm

CrewAI CrewAI allows human feedback to be provided to the agent by setting human_input=True during agent initialization.

Choosing the Right AI Agent Framework: LangGraph vs CrewAI vs OpenAI Swarm

The agent pauses after execution and requests users to provide natural language feedback on its actions and results.

Clearly, it does not support more customized human-machine collaborative interactions.

OpenAI Swarm

Swarm has no built-in human-machine collaboration features. However, the simplest way to add human input during execution is to use humans as tools or agents for the AI agent to hand off.

06

Summary of Functional Differences

Summarizing our findings from building the same application across these three frameworks.

Choosing the Right AI Agent Framework: LangGraph vs CrewAI vs OpenAI Swarm

07

Author’s Recommendations

We summarized our recommendations into a flowchart to help you decide which framework to start with.

Choosing the Right AI Agent Framework: LangGraph vs CrewAI vs OpenAI Swarm

Want more? Click the link below to read more past excellent works

Baiyang Compilation Station|CEST-LA-VIZ Conference: Dialogue, Breakthroughs, and Reshaping Boundaries

Baiyang Compilation Station | From Data to Art: Producing “The Mouse Tide Revolution”

Baiyang Compilation Station | How China Became the World’s Largest Car Exporter

If you have any questions or suggestions, please leave a message in the comment area or the public account backend.

What else would you like to know about cutting-edge topics in data journalism? Shuxin Xiaobaiyang welcomes your messages!

We look forward to your attention, “likes,” and shares.

Author | Wu Ji

Reviewed by | Zeng Xilei

Choosing the Right AI Agent Framework: LangGraph vs CrewAI vs OpenAI Swarm
Choosing the Right AI Agent Framework: LangGraph vs CrewAI vs OpenAI Swarm
Choosing the Right AI Agent Framework: LangGraph vs CrewAI vs OpenAI Swarm

Leave a Comment