Comparisons / CrewAI vs OpenAI Agents SDK
CrewAI vs OpenAI Agents SDK: Which Agent Framework to Use?
CrewAI crewai organizes work into agents, tasks, and crews. OpenAI Agents SDK openai's agents sdk (evolved from swarm) provides agent, runner, handoffs, and guardrails. Here is how they compare — and what the same patterns look like in plain Python.
By the numbers
CrewAI
48.0k
6.5k
Python
MIT
2023-10-27
João Moura
OpenAI Agents SDK
20.6k
3.4k
Python
MIT
2025-03-11
OpenAI
GitHub stats as of April 2026. Stars indicate community interest, not necessarily quality or fit for your use case.
| Concept | CrewAI | OpenAI Agents SDK | Plain Python |
|---|---|---|---|
| Agent | Agent(role, goal, backstory, tools, llm) | Agent(name, instructions, model, tools) | A function with a system prompt and a tools dict |
| Tools | Tool registration with @tool decorator, custom Tool classes | Python functions with type hints, auto-converted to schemas | A dict: tools[name](**args) |
| Agent Loop | Internal to Agent execution, hidden from user | Runner.run() handles the loop internally | A while loop over messages with tool_calls check |
| Task Delegation | Crew(agents, tasks, process=sequential/hierarchical) | — | A task queue processed in a while loop with a budget cap |
| Memory | ShortTermMemory, LongTermMemory, EntityMemory | — | A dict injected into the system prompt |
| State | Task output passed between agents via Crew orchestration | — | A dict tracking tool calls and results |
| Handoffs | — | Handoff between Agent objects for multi-agent routing | Call a different agent function based on the LLM's tool choice |
| Guardrails | — | InputGuardrail and OutputGuardrail with tripwire pattern | Two lists of rule functions checked before and after the LLM |
| Context | — | Typed context object passed through the agent lifecycle | A state dict updated inside the loop |
What both do in plain Python
Every concept in the table above — agent, tools, loop, memory, state — maps to a handful of Python primitives: a function, a dict, a list, and a while loop. Both CrewAI and OpenAI Agents SDK wrap these primitives in their own class hierarchies and APIs. The underlying pattern is the same ~60 lines of code. The difference is how much ceremony each framework adds on top.
When to use CrewAI
CrewAI shines for multi-agent setups where you want named roles ("researcher", "writer"). But the core mechanics — tool dispatch, the agent loop, task scheduling — are the same patterns you can build in plain Python.
What CrewAI does
CrewAI models multi-agent systems as a crew of specialists. Each Agent has a role ("Senior Researcher"), a goal ("Find the best data sources"), a backstory that shapes its behavior, and a set of tools it can use. Tasks define discrete units of work with expected outputs. The Crew orchestrates execution — sequentially, hierarchically, or with a custom process. CrewAI also provides memory systems (short-term, long-term, entity) and delegation, where one agent can hand off subtasks to another. The mental model is a team of people collaborating on a project. For prototyping multi-agent workflows where you want to reason about roles and responsibilities, it provides a clean vocabulary.
The plain Python equivalent
An Agent in CrewAI is a function with a system prompt that includes the role, goal, and backstory. The tools dict maps names to callables. Task delegation is a list of tasks processed in order — each task calls the assigned agent function with the task description appended to the messages. Hierarchical execution is a manager agent that decides which sub-agent to call next (just another tool choice). Memory is a dict injected into the system prompt. The entire crew pattern — multiple agents, task queue, delegation — is a for-loop over tasks, where each iteration calls the right agent function. No Crew class, no process kwarg. Just functions calling functions with a shared state dict passed between them.
When to use OpenAI Agents SDK
The Agents SDK is the thinnest framework on this list — it barely abstracts beyond what you'd write yourself. Use it when you want OpenAI's conventions and auto-schema generation. Skip it when you want full control or use non-OpenAI models.
What the OpenAI Agents SDK does
The Agents SDK (formerly Swarm) is OpenAI's opinionated take on agent architecture. It provides four primitives: Agent (system prompt + tools + model), Runner (the agent loop), handoffs (routing between agents), and guardrails (input/output validation). The key feature is auto-schema generation — write a Python function with type hints and the SDK converts it to a JSON tool schema automatically. Runner.run() handles the loop: call the model, check for tool calls, execute them, repeat. Handoffs let one agent transfer control to another by returning a special tool call. It's deliberately thin. OpenAI designed it as a reference implementation showing how agents should work with their API, not as a batteries-included framework.
The plain Python equivalent
The Agents SDK is already close to plain Python, which says something. Agent is a function that takes messages and returns a completion — the system prompt is the first message, tools are a dict. Runner.run() is a while loop: call openai.chat.completions.create(), check if the response has tool_calls, execute the matching functions from your tools dict, append results to messages, repeat until the model responds without tool_calls. Handoffs are an if-statement: if the model calls a "transfer_to_research" tool, call the research agent function instead. Guardrails are two lists of validation functions — run the input rules before calling the LLM, run the output rules after. The auto-schema generation is the only piece that takes more than a few lines to replicate.
Or build your own in 60 lines
Both CrewAI and OpenAI Agents SDK implement the same 8 patterns. An agent is a function. Tools are a dict. The loop is a while loop. The whole thing composes in ~60 lines of Python.
No framework. No dependencies. No opinions. Just the code.
Build it from scratch →