OpenAI Agents SDK vs LangGraph
OpenAI Agents SDK and LangGraph are two of the most prominent frameworks for building AI agent systems, yet they embody fundamentally different design philosophies. The OpenAI Agents SDK provides a streamlined, opinionated way to create agents that can use tools, delegate to other agents, and enforce guardrails—all within a Python-native, OpenAI-centric ecosystem. LangGraph, built on the LangChain ecosystem, offers a low‑level graph‑based state machine that gives engineers full control over every node, edge, and state transition.
Engineers compare them because both address the challenge of moving from single‑shot LLM calls to multi‑step, tool‑using, stateful agent workflows. The choice between them has direct consequences for production architecture: how you handle long‑running processes, human approvals, complex branching, and system reliability.
This guide provides a neutral, engineering‑focused comparison. We examine architecture, memory, tool calling, multi‑agent patterns, production readiness, and the trade‑offs that matter when building real‑world systems.
What is OpenAI Agents SDK?
The OpenAI Agents SDK is a lightweight, Python‑only framework for building agents that run on OpenAI models. It centers on a Runner that executes an Agent with a set of Tools and optional Guardrails. Agents can handoff control to other agents, creating simple multi‑agent flows without explicit graph definitions.
Its philosophy is batteries‑included but open‑ended: it provides sensible defaults for tracing, streaming, and session management while leaving the developer in control of the agent loop logic.
Key components:
- Agent: Defines the model, instructions, tools, handoffs, and guardrails.
- Runner: Executes the agent loop—calls the LLM, invokes tools, evaluates guardrails, and manages handoffs.
- Tools: Functions with schemas that the model can invoke. Includes built‑in tool classes and support for custom Python functions.
- Guardrails: Input and output validation checks that can raise errors or modify behavior before/after agent steps.
- Handoffs: Agent‑to‑agent delegation where one agent transfers control to another with optional input filtering.
- Session: Groups conversations under an ID; enables tracing and stateful interactions across multiple turns.
Execution is managed by the runner in a straightforward loop: model response → tool execution → guardrail check → (optional handoff) → repeat until a final output is produced. This loop is not exposed as a graph; flow control is largely linear with handoffs as the primary branching mechanism.
What is LangGraph?
LangGraph is a graph‑based orchestration framework where agent logic is explicitly modeled as a StateGraph. Every step—LLM calls, tool executions, condition checks—is a node. Transitions between nodes are defined by edges, which can be conditional. A shared State object flows through the graph, and every state change is automatically persisted via checkpointing.
Its philosophy is maximum control and durability. The graph is your program; you decide exactly what happens at each step, including error recovery, parallel execution, and pause‑for‑human loops.
Key concepts:
- StateGraph: A directed graph that defines the agent’s workflow. Nodes are Python functions; edges connect them.
- State: A typed dictionary that holds all the data flowing through the graph (messages, plans, memory). Updated by reducers that merge concurrent writes.
- Nodes: Computational steps—call an LLM, run a tool, transform state.
- Edges: Conditional or unconditional transitions. Conditional edges evaluate a function on the state to determine the next node.
- Checkpointing: After every node execution, the full state is saved. Enables pausing, resuming, branching, time‑travel debugging, and surviving restarts.
- Cycles: Supported natively; the graph can loop back to previous nodes for iterative reasoning or tool‑use loops.
The execution model is deterministic: given the same starting state and LLM outputs, the graph traversal is exactly reproducible. This makes LangGraph uniquely suited for auditable workflows and complex error handling.
Core Design Philosophy
| Aspect | OpenAI Agents SDK | LangGraph |
|---|---|---|
| Execution Model | Event‑driven loop managed by Runner | Graph traversal with state propagation |
| Control Flow | Implicit: tool calls, guardrails, handoffs | Explicit: you define every node and edge |
| Abstraction Level | Higher‑level; agent‑centric | Lower‑level; graph‑centric |
| Flexibility | Limited by runner loop; custom behavior requires subclassing | Unlimited; any logic can be a node |
| Determinism | Less deterministic; handoff logic depends on model choices | Highly deterministic; graph structure is fixed |
| Developer Experience | Fast to prototype; fewer decisions | Steeper learning curve; more design upfront |
The OpenAI Agents SDK reduces time‑to‑first‑agent by handling the orchestration loop for you. LangGraph asks you to build that loop yourself but rewards you with complete control over the edges—including parallel execution, retry policies, and human‑in‑the‑loop pause points.
Architecture Comparison
| Feature | OpenAI Agents SDK | LangGraph |
|---|---|---|
| Execution Engine | Runner loop: calls model, executes tools, enforces guardrails, handles handoffs | StateGraph compiled to a runnable; step‑by‑step node traversal |
| Workflow Orchestration | Linear with handoff branches | Arbitrary graph: sequential, parallel, conditional, cyclic |
| State Management | Session‑scoped conversation history; state is transient | Global State object; all state changes persisted via checkpoints |
| Memory | Session memory provided; external memory via tools | Short‑term (messages in state), long‑term (BaseStore), checkpoint‑based |
| Planning | Implicit in model reasoning; no built‑in planner | Custom planning nodes; can incorporate LLM‑based plan generation |
| Tool Execution | Tools run inside the runner loop; synchronous or async | Tools are nodes or functions called by LLM node; parallel execution native |
| Human‑in‑the‑loop | Not a first‑class pattern; can be simulated with tools | interrupt built‑in: pause graph, wait for human input, resume |
| Observability | Built‑in tracing (OpenAI traces); can export to external systems | LangSmith (deep graph traces), OpenTelemetry, custom callbacks |
| Extensibility | Subclass Agent, Runner, or add custom tools/guardrails | Any Python function can be a node; graph structure fully modifiable |
Agent Workflow Comparison
Both frameworks orchestrate the same fundamental loop—user input → plan/reason → tool call → response—but the orchestration mechanics differ significantly.
OpenAI Agents SDK workflow:
User Input → Runner executes Agent
├── Model generates response (may include tool calls)
├── Runner executes tools & feeds results back to model
├── Guardrails check output at each step
└── Optional handoff to another Agent
→ Final response returned
The runner handles the loop; the developer’s main responsibility is defining tools, guardrails, and handoff targets.
LangGraph workflow:
User Input → Enter Graph
├── Node: Agent (LLM) generates plan or tool calls
├── Conditional Edge: if tool calls → Tool Node; else → End
├── Tool Node executes tools, updates state
├── Loop back to Agent Node
└── Node: Response Generator (optional)
→ Exit Graph
The developer defines every node and transition. A common pattern is a ReAct‑style loop: the agent node decides what to do next based on the state, and edges route to tools or end.
Memory Comparison
| Aspect | OpenAI Agents SDK | LangGraph |
|---|---|---|
| Session Memory | Automatic: conversation history tracked per session ID | Manual: messages stored in State; checkpointing persists them |
| Conversation History | SDK stores list of messages in session | Developer controls what is stored in state (messages list) |
| Long‑Term Memory | Must be implemented via tools (e.g., database calls) | BaseStore abstraction for persistent key‑value storage; integrates with vector DBs |
| Persistence | Session state is ephemeral (in‑memory) unless externalized | Built‑in: every state change saved to checkpoint DB (Postgres, SQLite) |
| Resumability | Not natively supported; restarting a session loses context unless explicitly saved | Durable execution: resume from any checkpoint after a restart |
| Advantages | Simple for short‑lived conversations | Survive crashes, pause for days, branch from any point |
| Limitations | No built‑in durability; state lost on process restart | Checkpoint storage can become large; must manage state size |
LangGraph’s checkpoint‑based memory is a differentiator for agents that must run for hours or days, or that need to pause and wait for external events (human approval, system signals). The OpenAI SDK is simpler but assumes that the agent runtime is reliable and that long‑term state can be offloaded to a database.
Tool Calling Comparison
Both frameworks support the OpenAI function‑calling interface, but the surrounding infrastructure differs.
OpenAI Agents SDK:
from agents import Agent, function_tool
@function_tool
def search(query: str) -> str:
"""Search for information."""
return f"Results for {query}"
agent = Agent(
name="Assistant",
instructions="Help the user.",
tools=[search],
)
Tools are decorated with @function_tool. The SDK automatically generates schemas, handles execution, and feeds results back to the model. Retries and error handling can be added via custom guardrails.
LangGraph:
from langchain_core.tools import tool
from langgraph.graph import StateGraph, MessagesState
@tool
def search(query: str) -> str:
"""Search for information."""
return f"Results for {query}"
tools = [search]
llm_with_tools = llm.bind_tools(tools)
def agent_node(state: MessagesState):
response = llm_with_tools.invoke(state["messages"])
return {"messages": [response]}
def tool_node(state: MessagesState):
# Execute the most recent tool call
tool_call = state["messages"][-1].tool_calls[0]
result = search.invoke(tool_call["args"])
return {"messages": [result]}
LangGraph gives more control over when tools are called and how results are processed. You can implement custom retry logic in the tool node, add parallel tool calls via Send, or conditionally skip tool execution based on state.
| Feature | OpenAI Agents SDK | LangGraph |
|---|---|---|
| Function Calling | Native via OpenAI API | Native via LangChain model binding |
| MCP Support | MCP tools can be wrapped as custom tools | MCP servers can be exposed as LangChain tools |
| External APIs | Inside tool functions | Inside tool functions or nodes |
| Retries | Via guardrails or manual implementation | Custom logic in tool nodes; built‑in retry_policy on nodes |
| Error Handling | Guardrails can catch tool errors | Try/except in tool node; error edges to fallback nodes |
| Structured Outputs | Supported via model configuration | Supported via model configuration |
Multi‑Agent Capabilities
| Pattern | OpenAI Agents SDK | LangGraph |
|---|---|---|
| Handoff / Delegation | Built‑in handoff: agent transfers control, optionally filtering input | Subgraphs or supervisor nodes: explicit dispatch to another agent |
| Routing | Handoff routing based on model decision | Conditional edges based on state analysis |
| Supervisor Pattern | Not natively supported; can be built with multiple agents | Built‑in: supervisor agent node evaluates state and routes to sub‑agents |
| Parallel Agents | Not supported directly; must orchestrate outside the SDK | Send API fans out to multiple nodes for parallel execution |
| Collaboration | Agent‑to‑agent handoffs (sequential) | Nodes can read/write shared state; any collaboration topology possible |
The SDK’s handoff is simple: agent1 can delegate to agent2 with an optional filter on the input. But the pattern is one‑to‑one and sequential. LangGraph can implement any multi‑agent topology—supervisor, hierarchical, map‑reduce—because agents are just nodes in a graph.
Human‑in‑the‑Loop Support
The OpenAI Agents SDK does not have a native pause‑and‑wait mechanism for human approval. You can simulate it by having a tool that blocks (e.g., calling a human approval service), but the runner loop will wait in‑process, which is fragile.
LangGraph provides interrupt, which suspends graph execution at a specific node and returns control to the caller. The graph state is checkpointed. Later, an external system can resume the graph with human input, picking up exactly where it left off. This pattern is robust for long‑running approval flows, as the process can be restarted without losing state.
| Feature | OpenAI Agents SDK | LangGraph |
|---|---|---|
| Approval Workflows | Simulate with blocking tool | Built‑in interrupt + resume |
| Execution Pause | Not natively; blocks the runner | Graph pauses; state saved to checkpointer |
| Resume After Restart | No | Yes, load checkpoint and resume |
| Review Systems | Custom guardrails can review output | Nodes dedicated to review; can branch on approval |
State Management
- OpenAI Agents SDK: Stateless between runs unless you persist data externally. Each
Runner.run()call starts fresh; the session history is maintained by the runner in memory but is lost on restart. You are responsible for saving and restoring context. - LangGraph: State is a first‑class citizen. The
Stateobject is passed through every node, updated with reducers, and persisted at each step. The graph can be halted at any node and resumed later. This model is especially suited for workflows with many steps where you want to ensure exactly‑once processing and auditability.
Production Readiness
| Area | OpenAI Agents SDK | LangGraph |
|---|---|---|
| Monitoring | Built‑in tracing (OpenAI); can forward to observability tools | LangSmith (deep graph tracing); OpenTelemetry |
| Tracing | Automatic trace IDs; see every step in OpenAI dashboard | Graph‑level spans; tool call traces; state snapshots |
| Debugging | Trace viewer; log inspection | Time‑travel debugging: replay from any checkpoint |
| Deployment | Standard Python container; stateless (scale horizontally) | Standard container; external checkpoint DB required for durability |
| Scaling | Easy: stateless runner can be replicated | Requires careful checkpoint DB scaling; graph execution can be resource‑intensive |
| Testing | Unit test tools and guardrails; integration test agent runs | Unit test nodes; integration test graph behavior with mocked LLM |
| Reliability | Retries left to developer; no built‑in recovery | Node retry policies; checkpoint‑based recovery from failures |
| Logging | Standard Python logging | Standard Python logging |
LangGraph’s durability and recovery features make it more suitable for mission‑critical agents where a crash mid‑workflow is unacceptable. The SDK is simpler to deploy if you can tolerate occasional restarts and rely on external persistence for state.
Performance Comparison
- Latency: Both add minimal overhead relative to LLM latency. LangGraph’s checkpoint I/O may add a few milliseconds per node, but this is negligible compared to model inference time.
- Execution Overhead: The SDK’s runner loop is lightweight. LangGraph’s graph traversal and state management add minor CPU overhead, which becomes noticeable only in extremely high‑throughput scenarios with many tiny nodes.
- Scalability: The SDK’s stateless runner scales horizontally with ease. LangGraph’s checkpointing requires a scalable database; Postgres with connection pooling works well, but it is an additional infrastructure component.
- Concurrent Agents: LangGraph’s
SendAPI allows parallel execution of multiple nodes, which can reduce total latency when making independent tool calls. The SDK executes tool calls sequentially within a single agent run.
Learning Curve
| Aspect | OpenAI Agents SDK | LangGraph |
|---|---|---|
| Initial Setup | Minimal: define agent, tools, run | More involved: define state schema, nodes, edges, compile graph |
| Conceptual Complexity | Agent, Runner, Tools, Guardrails, Handoffs | StateGraph, reducers, checkpointers, conditional edges |
| Documentation | Good; clearly scoped | Extensive; many examples, but can be overwhelming |
| Examples | Practical, task‑focused | Wide variety: from simple to highly complex |
| Debugging | Trace viewer is helpful; no state inspection | Time‑travel debugging is powerful but requires learning checkpoint concepts |
Teams familiar with OpenAI’s API will find the SDK immediately productive. LangGraph requires more upfront learning but pays dividends when workflows become complex.
Enterprise Use Cases
OpenAI Agents SDK is suitable for:
- Internal Q&A assistants with tool access.
- Customer support bots with predefined escalation handoffs.
- AI copilots that augment user workflows in real time (e.g., coding assistants).
- Enterprise chat applications where sessions are short‑lived and failures are acceptable.
- Rapid prototyping of agent concepts before graduating to a more robust framework.
LangGraph is suitable for:
- Complex, multi‑step business process automation (e.g., loan approval with document checks).
- Research agents that require iterative exploration and data gathering.
- Autonomous agents that run for extended periods, possibly without user supervision.
- Systems requiring strict audit trails and the ability to replay past executions.
- Any scenario where human‑in‑the‑loop approval is a core part of the workflow and must survive system restarts.
Strengths and Weaknesses
| Feature | OpenAI Agents SDK | LangGraph |
|---|---|---|
| Ease of Use | ✅ Very easy to get started | ❌ Steeper learning curve |
| Flexibility | ❌ Limited to linear/handoff patterns | ✅ Unlimited graph topologies |
| Multi‑Agent Support | ⚠️ Handoff only | ✅ Any topology (supervisor, parallel, etc.) |
| State Persistence | ❌ Ephemeral; must implement yourself | ✅ Built‑in checkpointing |
| Human‑in‑the‑Loop | ❌ Not native; fragile workarounds | ✅ Robust interrupt/resume |
| Determinism & Auditing | ❌ Hard to reproduce exact runs | ✅ Deterministic replay from checkpoints |
| Ecosystem Integration | ✅ Tight OpenAI integration | ✅ Large LangChain ecosystem |
| Production Maturity | ⚠️ Newer; rapidly evolving | ✅ Battle‑tested at scale |
| Cloud Provider Lock‑in | ⚠️ OpenAI‑centric (model provider) | ✅ Model‑agnostic |
| Maintenance Overhead | Low | Medium (managing checkpoints, state size) |
When Should You Choose OpenAI Agents SDK?
Choose the SDK when:
- You are building simple to moderately complex agents that primarily need tool calling and occasional delegation.
- Your team wants to minimize boilerplate and get to a working agent quickly.
- You are already using OpenAI models and value the integrated tracing and tooling.
- Your workflows are short‑lived (seconds to minutes) and do not require durability across restarts.
- You plan to handle long‑term state and human approvals through external services rather than the orchestration framework itself.
When Should You Choose LangGraph?
Choose LangGraph when:
- Your agent’s workflow is complex—many steps, conditional branches, parallel tool calls.
- You need the agent to run for a long time, possibly pausing for hours or days, and must survive crashes.
- Human‑in‑the‑loop approval is a core requirement, and the system must wait asynchronously.
- Auditability, replay, and deterministic execution are important for compliance or debugging.
- You want a model‑agnostic framework that can switch between LLM providers without changing orchestration logic.
Migration Guide: OpenAI Agents SDK → LangGraph
If you start with the SDK and later need LangGraph’s capabilities, a migration involves several steps:
- Identify the core workflow: Map the agent’s tool calling loop and handoff logic to a graph structure. A typical ReAct pattern (reasoning ↔ tools) becomes a cycle of
agent_nodeandtool_node. - Convert agents to nodes: Each agent in the SDK becomes one or more nodes in LangGraph. If an agent had tools, those become a tool‑calling node.
- Replace handoffs with edges: Handoff targets become separate subgraphs or nodes connected by conditional edges. The routing logic (previously decided by the model) is now expressed as a conditional edge function.
- Externalize state: Move session‑specific data into the LangGraph
State. Use checkpointing for persistence instead of manually saving state. - Adapt guardrails: Guardrails become either pre‑/post‑processing nodes or inline validation logic inside nodes. For output validation, add a dedicated review node.
- Implement human‑in‑the‑loop: Replace blocking tool calls with
interruptat specific nodes and external resume mechanisms. - Test and replay: Leverage checkpointing to replay past traces and ensure behavior consistency after migration.
The migration requires effort but results in a more robust, maintainable system for complex agents.
Frequently Asked Questions
-
Is LangGraph more powerful than the OpenAI Agents SDK?
Yes, in terms of workflow expressiveness and durability. But “power” comes with complexity. The SDK is “powerful enough” for many use cases. -
Can the OpenAI Agents SDK replace LangGraph?
Not for applications that require durable execution, complex branching, or robust human‑in‑the‑loop patterns. -
Which framework scales better?
The SDK scales horizontally more easily due to its stateless design. LangGraph scales too, but requires scaling the checkpoint database. -
Which supports long‑running workflows?
LangGraph, natively. The SDK can be used for long workflows if you externalize state, but it does not provide built‑in durability. -
Which is easier to learn?
The OpenAI Agents SDK, especially if you already know the OpenAI API. -
Does the OpenAI Agents SDK support MCP?
Yes, you can integrate MCP tools by wrapping them in SDK tool functions, though it requires manual client session management. -
Which is better for enterprise systems?
LangGraph, for its reliability, auditability, and vendor‑neutral model support. The SDK is often a good starting point for prototypes that may evolve. -
Can I use LangGraph with OpenAI models only?
Yes, LangGraph is model‑agnostic; you can use any LLM, including all OpenAI models. -
Do I need to know LangChain to use LangGraph?
Familiarity helps, but LangGraph can be used with minimal LangChain knowledge. The graph concepts are independent. -
Can I mix the two in a single project?
Technically yes, but it’s not recommended because it introduces two orchestration paradigms. Choose one as your main agent framework. -
Does the SDK have checkpointing like LangGraph?
No, checkpointing and durable execution are not part of the SDK. -
Which framework has better observability?
Both are well‑instrumented. LangGraph’s state snapshots and time‑travel debugging provide deeper introspection for debugging; the SDK’s tracing is straightforward and integrated with the OpenAI ecosystem.
Best Practices
- Separate orchestration from business logic: Keep tool implementations pure and framework‑agnostic so you can switch orchestration layers later if needed.
- Use structured tool interfaces: Define clear schemas; this benefits both frameworks and improves model reliability.
- Avoid oversized agent prompts: Streamline instructions; in LangGraph, consider summarization nodes for long conversations to manage state size.
- Design for deterministic workflows where possible: In LangGraph, leverage conditional edges rather than relying solely on model decisions.
- Implement retries and timeouts on all external calls: Both frameworks allow this; LangGraph nodes support
retry_policydirectly. - Monitor tool latency: Long‑running tools affect both frameworks; use timeouts and async patterns.
- Isolate external dependencies: Use the dependency inversion principle so that swapping frameworks does not force rewriting integrations.
- Use persistent state only when required: In LangGraph, be mindful of checkpoint size; trim state regularly.
Conclusion
OpenAI Agents SDK is generally the better choice when you need rapid development, are building OpenAI‑native applications, and your workflows are linear with occasional handoffs. Its simplicity and tight integration accelerate time‑to‑value for lightweight assistants and enterprise chat scenarios.
LangGraph is the better choice for complex orchestration, long‑running workflows, production‑grade stateful agents, and any system that must guarantee durability and auditability. Its graph‑based model, checkpointing, and human‑in‑the‑loop primitives make it the foundation for mission‑critical enterprise AI systems.
Recommendation matrix:
| Project Type | Recommended Framework |
|---|---|
| Internal Q&A bot with tools | OpenAI Agents SDK |
| Customer support with simple escalation | OpenAI Agents SDK |
| AI‑powered coding assistant | OpenAI Agents SDK |
| Automated loan processing (multi‑step, approval) | LangGraph |
| Research agent (hours‑long exploration) | LangGraph |
| Autonomous operations agent (survive restarts) | LangGraph |
| Rapid prototype → future scale | Start with SDK; plan migration path to LangGraph |
As the AI agent ecosystem evolves, expect these frameworks to converge on features—the SDK may gain more advanced orchestration, and LangGraph will simplify its developer experience. Your choice today should align with your current complexity needs, not just feature lists.
Further reading: