Comparisons / LangChain vs OpenAI Agents SDK

LangChain vs OpenAI Agents SDK: Which Agent Framework to Use?

LangChain langchain is the most popular agent framework. 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

LangChain

GitHub Stars

132.3k

Forks

21.8k

Language

Python

License

MIT

Created

2022-10-17

Created by

Harrison Chase

Backed by

Sequoia Capital, Benchmark

Funding

$25M Series A (2023), $25M Series B (2024)

Weekly downloads

3.5M

Cloud/SaaS

LangSmith (observability), LangServe (deployment)

Production ready

Yes

Used by: Notion, Elastic, Instacart

github.com/langchain-ai/langchain

OpenAI Agents SDK

GitHub Stars

20.6k

Forks

3.4k

Language

Python

License

MIT

Created

2025-03-11

Created by

OpenAI

github.com/openai/openai-agents-python

GitHub stats as of April 2026. Stars indicate community interest, not necessarily quality or fit for your use case.

ConceptLangChainOpenAI Agents SDKPlain Python
AgentAgentExecutor with LLMChain, PromptTemplate, OutputParserAgent(name, instructions, model, tools)A function that POSTs to /chat/completions and returns the response
Tools@tool decorator, StructuredTool, BaseTool class hierarchyPython functions with type hints, auto-converted to schemasA dict of callables: tools = {"add": lambda a, b: a + b}
Agent LoopAgentExecutor.invoke() with internal iterationRunner.run() handles the loop internallyA while loop: call LLM, check for tool_calls, execute, repeat
ConversationConversationBufferMemory, ConversationSummaryMemoryA messages list that persists outside the function
StateLangGraph state channels with typed reducersA dict updated inside the loop: state["turns"] += 1
MemoryVectorStoreRetrieverMemory, ConversationEntityMemoryA dict injected into the system prompt, saved via a remember() tool
GuardrailsOutputParser, PydanticOutputParser, custom validatorsInputGuardrail and OutputGuardrail with tripwire patternTwo lists of lambda rules checked before and after the LLM call
HandoffsHandoff between Agent objects for multi-agent routingCall a different agent function based on the LLM's tool choice
ContextTyped context object passed through the agent lifecycleA 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 LangChain 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 LangChain

LangChain adds value when you need production integrations (vector stores, specific LLM providers, deployment tooling). But if you want to understand what's happening — or your use case is straightforward — the plain Python version is easier to debug, modify, and reason about.

What LangChain does

LangChain provides a unifying interface across LLM providers, a class hierarchy for tools and memory, and orchestration via AgentExecutor and LangGraph. The core value proposition is interchangeable components: swap OpenAI for Anthropic by changing one class, plug in a vector store for retrieval, add memory without rewriting your loop. It also ships with dozens of integrations — document loaders, text splitters, embedding models, vector stores — that save you from writing boilerplate HTTP calls. For teams that need to compose many integrations quickly, this catalog is genuinely useful. The tradeoff is that you inherit a large dependency tree and a set of abstractions that sit between you and the actual API calls.

The plain Python equivalent

Every LangChain abstraction maps to a small piece of plain Python. AgentExecutor is a while loop that calls the LLM, checks for tool_calls in the response, executes the matching function from a tools dict, appends the result to a messages array, and repeats. Memory is a dict you inject into the system prompt. Output parsing is a function that validates the LLM's response before returning it. The entire agent — tool dispatch, conversation history, state tracking, guardrails — fits in about 60 lines of Python. No base classes, no decorators, no chain composition. Just a function, a dict, a list, and a loop. When something breaks, you read your 60 lines instead of navigating a class hierarchy.

Full LangChain comparison →

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.

Full OpenAI Agents SDK comparison →

Or build your own in 60 lines

Both LangChain 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 →