By Sagar Shankaran, Founder of CallSphere
A hands-on guide to migrating AI agent code from LangChain to the OpenAI Agents SDK. Covers concept mapping, code translation, testing strategies, and gradual migration paths.
Key takeaways
LangChain was the first widely adopted framework for building LLM applications, and it earned that position by moving fast. But as production requirements matured, teams encountered pain points: deep abstraction layers that obscured what prompts actually reached the model, rapidly changing APIs with frequent breaking changes, and heavyweight dependency trees.
The OpenAI Agents SDK takes a different approach: minimal abstractions, explicit control flow, and built-in primitives for the patterns that matter most in production — tool calling, agent handoffs, guardrails, and tracing.
Understanding the conceptual mapping is the first step. Here is how the core primitives translate:
flowchart LR
INPUT(["User input"])
AGENT["Agent<br/>name plus instructions"]
HAND{"Handoff to<br/>another agent?"}
SUB["Sub-agent<br/>specialist"]
GUARD{"Guardrail<br/>passed?"}
TOOL["Tool call"]
SDK[("Tracing<br/>OpenAI dashboard")]
OUT(["Final output"])
INPUT --> AGENT --> HAND
HAND -->|Yes| SUB --> GUARD
HAND -->|No| GUARD
GUARD -->|Yes| TOOL --> AGENT
GUARD -->|Block| OUT
AGENT --> OUT
AGENT --> SDK
style AGENT fill:#4f46e5,stroke:#4338ca,color:#fff
style GUARD fill:#f59e0b,stroke:#d97706,color:#1f2937
style SDK fill:#ede9fe,stroke:#7c3aed,color:#1e1b4b
style OUT fill:#059669,stroke:#047857,color:#fff
| LangChain | OpenAI Agents SDK | Notes |
|---|---|---|
ChatOpenAI |
Agent(model="gpt-4o") |
Model config lives on the Agent |
Tool / @tool |
@function_tool |
Decorator-based, type-safe |
AgentExecutor |
Runner.run() |
Manages the agent loop |
ConversationBufferMemory |
Conversation history in input |
Explicit message list |
Chain |
Agent handoffs | Compose via handoffs=[] |
OutputParser |
output_type=MyModel |
Pydantic model on Agent |
Here is a typical LangChain agent that looks up product information:
Hear it before you finish reading
Talk to a live CallSphere AI voice agent in your browser — 60 seconds, no signup.
# ── LangChain version ──
from langchain_openai import ChatOpenAI
from langchain.agents import AgentExecutor, create_openai_tools_agent
from langchain_core.tools import tool
from langchain_core.prompts import ChatPromptTemplate
@tool
def lookup_product(product_id: str) -> str:
"""Look up product details by ID."""
# database call here
return f"Product {product_id}: Widget Pro, $49.99, in stock"
llm = ChatOpenAI(model="gpt-4o", temperature=0)
prompt = ChatPromptTemplate.from_messages([
("system", "You are a product assistant."),
("human", "{input}"),
("placeholder", "{agent_scratchpad}"),
])
agent = create_openai_tools_agent(llm, [lookup_product], prompt)
executor = AgentExecutor(agent=agent, tools=[lookup_product])
result = executor.invoke({"input": "Tell me about product P-1234"})
And here is the equivalent in the OpenAI Agents SDK:
# ── OpenAI Agents SDK version ──
from agents import Agent, Runner, function_tool
@function_tool
def lookup_product(product_id: str) -> str:
"""Look up product details by ID."""
return f"Product {product_id}: Widget Pro, $49.99, in stock"
agent = Agent(
name="Product Assistant",
instructions="You are a product assistant.",
model="gpt-4o",
tools=[lookup_product],
)
result = Runner.run_sync(agent, "Tell me about product P-1234")
print(result.final_output)
The SDK version is roughly half the code. The agent loop, tool execution, and response parsing are handled internally by Runner.
LangChain uses chains to compose multiple steps. The Agents SDK uses handoffs to delegate between specialized agents.
from agents import Agent, Runner
billing_agent = Agent(
name="Billing Agent",
instructions="Handle billing questions. Access account data.",
model="gpt-4o",
)
shipping_agent = Agent(
name="Shipping Agent",
instructions="Handle shipping and delivery questions.",
model="gpt-4o",
)
triage_agent = Agent(
name="Triage Agent",
instructions="Route the user to the right specialist agent.",
model="gpt-4o",
handoffs=[billing_agent, shipping_agent],
)
result = Runner.run_sync(triage_agent, "Where is my order?")
print(result.final_output)
Do not rewrite everything at once. Migrate one agent or chain at a time.
Still reading? Stop comparing — try CallSphere live.
CallSphere ships complete AI voice agents per industry — 14 tools for healthcare, 10 agents for real estate, 4 specialists for salons. See how it actually handles a call before you book a demo.
# Compatibility wrapper: run both and compare
async def migrate_with_comparison(user_input: str):
langchain_result = executor.invoke({"input": user_input})
sdk_result = Runner.run_sync(agent, user_input)
match = langchain_result["output"] == sdk_result.final_output
log_comparison(user_input, langchain_result, sdk_result, match)
# Return SDK result when confidence is high
return sdk_result.final_output
Yes. The Agents SDK supports any model via the LiteLLM integration. Install openai-agents[litellm] and use model strings like litellm/anthropic/claude-sonnet-4-20250514. The tool calling and handoff mechanics work the same regardless of the model provider.
The Agents SDK does not have a built-in memory abstraction. Instead, you pass conversation history explicitly as a list of messages in the input parameter. Extract your existing conversation history from LangChain memory stores and format it as standard message dicts.
Those are data pipeline tools, not agent framework features. You can keep using LangChain's document loaders and vector stores alongside the Agents SDK. Wrap the retrieval logic in a @function_tool and the agent calls it like any other tool.
#LangChain #OpenAIAgentsSDK #Migration #Python #FrameworkMigration #AgenticAI #LearnAI #AIEngineering

Written by
Sagar Shankaran· Founder, CallSphere
LinkedInSagar Shankaran is the founder of CallSphere, where he builds production AI voice and chat agents deployed across healthcare, hospitality, real estate, and home services. He writes about agentic AI, LLM engineering, and shipping voice agents that handle real calls in production.
See how AI voice agents work for your industry. Live demo available -- no signup required.
How we built a fault-tolerant HVAC emergency triage and tech-dispatch platform on Kubernetes — three-tier CQRS, 11 micro-agents on the OpenAI Agents SDK + LangGraph, NATS JetStream, DTMF/SMS/WebSocket acceptance, circuit breakers, and an evaluation pipeline that catches regressions before they wake a tech at 3 AM.
Enterprise CIO Guide perspective on LangGraph's 1.0 release stabilizes the API and adds the production primitives that early adopters had been hand-rolling.
Triage to specialist to return-to-orchestrator pattern explained with code. CallSphere's OpenAI Agents SDK handoffs vs Vapi Squads' linear chain.
AI features evolve fast; users hate breaking changes. The 2026 patterns for clean deprecation, migration windows, and keeping users on board.
SMB Founder Playbook perspective on LangGraph's 1.0 release stabilizes the API and adds the production primitives that early adopters had been hand-rolling.
Healthcare Practice Use Case perspective on LangGraph's 1.0 release stabilizes the API and adds the production primitives that early adopters had been hand-rolling.
© 2026 CallSphere Inc. All rights reserved.
Made within San Francisco