OpenAI Agents SDK Explained: Building Agents With the New Toolkit

The OpenAI Agents SDK is a small framework for building agents in Python and TypeScript. Here is how its primitives, tools, handoffs, and guardrails work.

By Galactic News Editorial · Published 2026-11-18T16:43:15+00:00 · Updated 2026-11-18T16:43:15+00:00

OpenAI Agents SDK explained for building agents with the new toolkit

OpenAI Agents SDK Explained: Building Agents With the New Toolkit

The OpenAI Agents SDK is a small open-source framework for building agents in Python and TypeScript. It launched in March 2025. It replaced the experimental Swarm framework. The SDK gives you a handful of primitives: agents, tools, handoffs, guardrails, sessions, and tracing. You define an agent and its tools. The SDK runs the loop.

That is the whole idea. There is no graph to define. There is no callback wiring to learn. You write plain Python or TypeScript, and the model behaves like another function call.

What Is the OpenAI Agents SDK?

An agent in this SDK is a language model with instructions and tools. The Runner executes it. It calls the model, runs any tools the model requests, and feeds the results back in. The loop repeats until the model gives a final answer.

For OpenAI models, the SDK uses the Responses API by default. It also works with other providers through OpenAI-compatible endpoints. The Python package is the reference implementation. It gets new features first. The TypeScript package carries the same primitives to Node and edge runtimes.

The SDK is deliberately minimal. It does not ship a vector store, a memory database, or a deployment platform. You add your own infrastructure where you need it. That keeps the learning curve short and the code easy to read.

The Core Primitives of the OpenAI Agents SDK

PrimitiveWhat it does
AgentA model with instructions, tools, and an optional handoff list
RunnerExecutes the agent loop and returns a run result
ToolsFunctions the model can call, plus built-in server-side tools
HandoffsPasses a task from one agent to a specialist agent
GuardrailsChecks inputs and outputs, and can stop a run
SessionsBuilt-in conversation memory across runs
TracingA record of every step in a run, viewable in the dashboard

Most real workflows need only the first three rows. Add handoffs when one agent should hand work to a specialist. Add guardrails when bad input or output must stop the run. Add sessions when the conversation spans many turns.

Your First Agent in Python

Install the SDK and set your key. You need Python 3.10 or higher.

pip install openai-agents
export OPENAI_API_KEY="your-key"

Define an agent. Give it a name and instructions. Then run it.

import asyncio
from agents import Agent, Runner

agent = Agent(
    name="Assistant",
    instructions="You are a helpful assistant.",
)

async def main() -> None:
    result = await Runner.run(agent, "Write a haiku about recursion.")
    print(result.final_output)

if __name__ == "__main__":
    asyncio.run(main())

That is the hello world. It fits in about twenty lines. No framework boilerplate is needed.

Your First Agent in TypeScript

The TypeScript SDK uses the same shape. Install the package and the zod schema library.

npm install @openai/agents zod
import { Agent, run } from "@openai/agents";

const agent = new Agent({
  name: "Assistant",
  instructions: "You are a helpful assistant.",
});

const result = await run(agent, "Write a haiku about recursion.");
console.log(result.finalOutput);

Use Python when you prototype or when your stack is mixed. Use TypeScript when the agent lives in a web app or an edge worker. Python lands new features first, so check the Python docs when a feature seems missing.

Tools, Handoffs, and Guardrails

Tools turn an agent into something useful. The @function_tool decorator turns any Python function into a tool. The SDK reads the type hints, builds the JSON schema, and runs the function when the model calls it. If the function throws an error, the SDK passes the error message back to the model. The model then decides whether to retry or answer with an error.

Built-in server-side tools are also available. These include web search, file search, code execution, and computer use. You attach them like any other tool.

Handoffs split work across agents. A triage agent can hand a billing question to a billing agent. The handoff is itself a tool call. The receiving agent gets the conversation history. This pattern keeps each agent's instructions short and focused.

Guardrails check the run at two points. Input guardrails run before the agent sees the message. Output guardrails run before the final answer goes out. A tripped guardrail raises an exception and stops the run. Use them for safety checks, format checks, and policy checks.

Sessions, MCP, and Voice

Sessions give the agent memory without manual bookkeeping. A SQLiteSession holds the conversation history across runs. You pass the session to each run call. The SDK remembers the turns for you. A session cannot be combined with the run-level continuation options in the same run.

The SDK also connects to MCP servers as tools. An MCP server exposes tools over a standard protocol. Your agent can use those tools like local functions. This is how one agent gains dozens of tools without custom code for each one. Human approval is supported for sensitive tool calls, so a person can approve an action before it runs.

Voice comes in two forms. A voice pipeline chains speech-to-text, an agent, and text-to-speech. It runs in three steps: transcribe the audio, run the agent, then speak the result. Realtime agents are different. They run low-latency voice over WebSocket with a speech-to-speech model. Start new realtime agents with gpt-realtime-2.1. The Python SDK does not provide a browser WebRTC transport. Use it for server-side sessions, tools, approvals, and telephony.

Python vs TypeScript: Which OpenAI Agents SDK to Pick?

FactorPythonTypeScript
Packageopenai-agents via pip@openai/agents via npm
Entry pointRunner.run()run()
Feature speedReference implementation, new features firstSame primitives, some features later
Best fitPrototyping, data work, mixed stacksWeb apps, edge runtimes, React and Next.js

When to Use It, and When Not To

Use the Agents SDK when your workflow is mostly prompts, tools, and conversation. It fits support agents, research assistants, and internal tools. It fits teams already using OpenAI APIs who want the shortest path to a working agent.

Skip it when you need a visual workflow builder, a managed deployment, or a built-in vector store. Those are separate products. The SDK is a runtime, not a platform. It also offers no built-in memory persistence beyond sessions, so long-term memory is your job.

Keep one more thing in mind. The Python SDK follows a 0.Y.Z release scheme. Minor-version changes may include breaking changes. Pin your version and recheck method names when you upgrade.

Bottom Line

The OpenAI Agents SDK is the smallest useful way to build an agent. Define an agent, give it tools, and run it. Add handoffs when work splits across specialists. Add guardrails and sessions when production demands them. Start in Python, move to TypeScript only if the deployment asks for it.