Skip to main content

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

AspectOpenAI Agents SDKLangGraph
Execution ModelEvent‑driven loop managed by RunnerGraph traversal with state propagation
Control FlowImplicit: tool calls, guardrails, handoffsExplicit: you define every node and edge
Abstraction LevelHigher‑level; agent‑centricLower‑level; graph‑centric
FlexibilityLimited by runner loop; custom behavior requires subclassingUnlimited; any logic can be a node
DeterminismLess deterministic; handoff logic depends on model choicesHighly deterministic; graph structure is fixed
Developer ExperienceFast to prototype; fewer decisionsSteeper 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

FeatureOpenAI Agents SDKLangGraph
Execution EngineRunner loop: calls model, executes tools, enforces guardrails, handles handoffsStateGraph compiled to a runnable; step‑by‑step node traversal
Workflow OrchestrationLinear with handoff branchesArbitrary graph: sequential, parallel, conditional, cyclic
State ManagementSession‑scoped conversation history; state is transientGlobal State object; all state changes persisted via checkpoints
MemorySession memory provided; external memory via toolsShort‑term (messages in state), long‑term (BaseStore), checkpoint‑based
PlanningImplicit in model reasoning; no built‑in plannerCustom planning nodes; can incorporate LLM‑based plan generation
Tool ExecutionTools run inside the runner loop; synchronous or asyncTools are nodes or functions called by LLM node; parallel execution native
Human‑in‑the‑loopNot a first‑class pattern; can be simulated with toolsinterrupt built‑in: pause graph, wait for human input, resume
ObservabilityBuilt‑in tracing (OpenAI traces); can export to external systemsLangSmith (deep graph traces), OpenTelemetry, custom callbacks
ExtensibilitySubclass Agent, Runner, or add custom tools/guardrailsAny 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

AspectOpenAI Agents SDKLangGraph
Session MemoryAutomatic: conversation history tracked per session IDManual: messages stored in State; checkpointing persists them
Conversation HistorySDK stores list of messages in sessionDeveloper controls what is stored in state (messages list)
Long‑Term MemoryMust be implemented via tools (e.g., database calls)BaseStore abstraction for persistent key‑value storage; integrates with vector DBs
PersistenceSession state is ephemeral (in‑memory) unless externalizedBuilt‑in: every state change saved to checkpoint DB (Postgres, SQLite)
ResumabilityNot natively supported; restarting a session loses context unless explicitly savedDurable execution: resume from any checkpoint after a restart
AdvantagesSimple for short‑lived conversationsSurvive crashes, pause for days, branch from any point
LimitationsNo built‑in durability; state lost on process restartCheckpoint 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.

FeatureOpenAI Agents SDKLangGraph
Function CallingNative via OpenAI APINative via LangChain model binding
MCP SupportMCP tools can be wrapped as custom toolsMCP servers can be exposed as LangChain tools
External APIsInside tool functionsInside tool functions or nodes
RetriesVia guardrails or manual implementationCustom logic in tool nodes; built‑in retry_policy on nodes
Error HandlingGuardrails can catch tool errorsTry/except in tool node; error edges to fallback nodes
Structured OutputsSupported via model configurationSupported via model configuration

Multi‑Agent Capabilities

PatternOpenAI Agents SDKLangGraph
Handoff / DelegationBuilt‑in handoff: agent transfers control, optionally filtering inputSubgraphs or supervisor nodes: explicit dispatch to another agent
RoutingHandoff routing based on model decisionConditional edges based on state analysis
Supervisor PatternNot natively supported; can be built with multiple agentsBuilt‑in: supervisor agent node evaluates state and routes to sub‑agents
Parallel AgentsNot supported directly; must orchestrate outside the SDKSend API fans out to multiple nodes for parallel execution
CollaborationAgent‑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.

FeatureOpenAI Agents SDKLangGraph
Approval WorkflowsSimulate with blocking toolBuilt‑in interrupt + resume
Execution PauseNot natively; blocks the runnerGraph pauses; state saved to checkpointer
Resume After RestartNoYes, load checkpoint and resume
Review SystemsCustom guardrails can review outputNodes 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 State object 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

AreaOpenAI Agents SDKLangGraph
MonitoringBuilt‑in tracing (OpenAI); can forward to observability toolsLangSmith (deep graph tracing); OpenTelemetry
TracingAutomatic trace IDs; see every step in OpenAI dashboardGraph‑level spans; tool call traces; state snapshots
DebuggingTrace viewer; log inspectionTime‑travel debugging: replay from any checkpoint
DeploymentStandard Python container; stateless (scale horizontally)Standard container; external checkpoint DB required for durability
ScalingEasy: stateless runner can be replicatedRequires careful checkpoint DB scaling; graph execution can be resource‑intensive
TestingUnit test tools and guardrails; integration test agent runsUnit test nodes; integration test graph behavior with mocked LLM
ReliabilityRetries left to developer; no built‑in recoveryNode retry policies; checkpoint‑based recovery from failures
LoggingStandard Python loggingStandard 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 Send API 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

AspectOpenAI Agents SDKLangGraph
Initial SetupMinimal: define agent, tools, runMore involved: define state schema, nodes, edges, compile graph
Conceptual ComplexityAgent, Runner, Tools, Guardrails, HandoffsStateGraph, reducers, checkpointers, conditional edges
DocumentationGood; clearly scopedExtensive; many examples, but can be overwhelming
ExamplesPractical, task‑focusedWide variety: from simple to highly complex
DebuggingTrace viewer is helpful; no state inspectionTime‑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

FeatureOpenAI Agents SDKLangGraph
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 OverheadLowMedium (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:

  1. 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_node and tool_node.
  2. 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.
  3. 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.
  4. Externalize state: Move session‑specific data into the LangGraph State. Use checkpointing for persistence instead of manually saving state.
  5. Adapt guardrails: Guardrails become either pre‑/post‑processing nodes or inline validation logic inside nodes. For output validation, add a dedicated review node.
  6. Implement human‑in‑the‑loop: Replace blocking tool calls with interrupt at specific nodes and external resume mechanisms.
  7. 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

  1. 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.

  2. Can the OpenAI Agents SDK replace LangGraph?
    Not for applications that require durable execution, complex branching, or robust human‑in‑the‑loop patterns.

  3. Which framework scales better?
    The SDK scales horizontally more easily due to its stateless design. LangGraph scales too, but requires scaling the checkpoint database.

  4. 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.

  5. Which is easier to learn?
    The OpenAI Agents SDK, especially if you already know the OpenAI API.

  6. 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.

  7. 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.

  8. Can I use LangGraph with OpenAI models only?
    Yes, LangGraph is model‑agnostic; you can use any LLM, including all OpenAI models.

  9. 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.

  10. 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.

  11. Does the SDK have checkpointing like LangGraph?
    No, checkpointing and durable execution are not part of the SDK.

  12. 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_policy directly.
  • 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 TypeRecommended Framework
Internal Q&A bot with toolsOpenAI Agents SDK
Customer support with simple escalationOpenAI Agents SDK
AI‑powered coding assistantOpenAI Agents SDK
Automated loan processing (multi‑step, approval)LangGraph
Research agent (hours‑long exploration)LangGraph
Autonomous operations agent (survive restarts)LangGraph
Rapid prototype → future scaleStart 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: