OpenAI Agents SDK (JavaScript/TypeScript)
TL;DR
The OpenAI Agents SDK for JavaScript/TypeScript is OpenAI's MIT-licensed library for agents with tools, guardrails, handoffs and agents-as-tools, plus sessions, tracing, sandbox agents and realtime voice agents. It targets OpenAI models first and reaches others through adapters. It suits Node.js, Deno or Bun developers building OpenAI-centred agent apps.
Key facts
| Type | Framework |
|---|---|
| Languages / SDKs | TypeScript, JavaScript |
| License | MIT |
| Pricing model | Open source, free |
| Orchestration pattern | Handoff |
| GitHub stars | 3,882 (as of 2026-09-30) |
| GitHub forks | 985 |
| Last push | 2026-09-25 |
| Latest release | v0.18.0 |
| Repository | openai/openai-agents-js |
| Website | openai.github.io |
| Documentation | openai.github.io |
| Last verified | 2026-09-30 |
Key features
Agentobjects configured with instructions, tools, guardrails, output types and handoffs, executed byrun()or aRunner. (source)- Handoffs: each target agent becomes a
transfer_to_<name>tool, and the chosen specialist takes over the conversation. (source) - Agents as tools via
agent.asTool(), where a manager agent keeps control and calls specialists like functions. (source) - Input and output guardrails that validate or block content around agent runs. (source)
- Tool approvals with
needsApproval; paused runs surfaceinterruptionsand resume from a serializableRunState. (source) - Sessions that load and save conversation history automatically, with
MemorySession,OpenAIConversationsSessionor a custom store. (source) - Sandbox agents that work inside a filesystem workspace with shell access, using local Unix, Docker or hosted sandbox clients. (source)
- Realtime voice agents (
RealtimeAgent,RealtimeSession) that connect over WebRTC in the browser. (source)
Architecture and orchestration pattern
Pattern: Handoff
The SDK is a runner around a model loop. An Agent holds instructions, tools, guardrails and a list of handoffs; run() calls the model, executes tool calls, and repeats until a final output is produced or control passes to another agent. Tools include local function tools, OpenAI-hosted tools such as web search, MCP servers and sandbox capabilities.
The docs describe two multi-agent patterns. With handoffs, a triage agent transfers the conversation to a specialist, which becomes the active agent. With agents as tools, a manager agent calls specialists through agent.asTool() and stays responsible for the answer. Orchestration in plain code, such as chaining runs or running them in parallel, is also covered. There is no separate graph or workflow engine.
State across turns is handled by sessions, which prepend stored history to each run and persist new items afterwards. The package ships an in-memory session for development and a session backed by OpenAI's Conversations API; other stores implement the Session interface. Within a run, RunState captures progress and can be serialized with toString() and restored with RunState.fromString(). Traces of model calls, tool calls and handoffs go to the OpenAI Traces dashboard by default.
Human in the loop
A function tool, an agent exposed with asTool(), or a hosted MCP tool can require approval through needsApproval, either always or via an async check on the arguments. When a call needs approval, the run ends the turn with result.interruptions instead of executing it. The application calls result.state.approve(item) or result.state.reject(item), optionally with alwaysApprove / alwaysReject so later calls to the same tool follow that decision, and then passes the state back to run().
This works across handoffs and nested agents-as-tools, because interruptions surface on the outer run. For long pauses, result.state.toString() stores the run and RunState.fromString(agent, saved) restores it, so a reviewer can decide later in another process. Guardrails can also stop a run when input or output fails a check.
Harnesses it can drive
- Codex (evidence)
Protocols
| Protocol | Support | Note |
|---|---|---|
| MCP | Yes evidence | Client only: agents use hosted MCP tools through the Responses API or connect to Streamable HTTP and stdio servers with MCPServerStreamableHttp / MCPServerStdio; no MCP server mode is documented. |
| A2A | No evidence | A maintainer replied in issue #171 (closed July 2025) that there are no immediate plans for built-in A2A support and suggested wrapping SDK code inside A2A apps; a repository code search on 2026-09-30 found no A2A implementation. |
| AG-UI | Unknown | Not mentioned in the JS SDK docs, README or repository code; the AG-UI README lists 'OpenAI Agent SDK' (linking the Python docs) as in progress under community integrations. |
Best for
- TypeScript apps built on OpenAI models that need specialists and handoffs
- Support flows where a triage agent hands customers to billing, refund or FAQ agents
- Repository tasks run in a sandbox workspace, or delegated to Codex through the experimental Codex tool
- Browser voice assistants that share tools and handoffs with text agents
Not for
- Python projects, which use the separate openai-agents-python SDK
- Systems that need native A2A endpoints or clients
- Teams that require a stable 1.x API; minor versions in the 0.Y line may break public interfaces
Quickstart
npm install @openai/agents zod import { Agent, run, tool } from '@openai/agents';
import { z } from 'zod';
const refund = tool({
name: 'issue_refund',
description: 'Refund an order',
parameters: z.object({ orderId: z.string() }),
needsApproval: true,
execute: async ({ orderId }) => `Refunded ${orderId}`,
});
const billing = new Agent({ name: 'Billing', instructions: 'Handle refunds.', tools: [refund] });
const triage = new Agent({ name: 'Triage', instructions: 'Send billing questions to Billing.', handoffs: [billing] });
let result = await run(triage, 'Please refund order A-17');
while (result.interruptions?.length) {
for (const item of result.interruptions) result.state.approve(item);
result = await run(triage, result.state);
}
console.log(result.finalOutput);
Common pitfalls
- Supported server runtimes are Node.js 22+, Deno 2.35+ and Bun 1.2.5+; Cloudflare Workers need
nodejs_compatand manual trace flushing. - The SDK uses Zod v4 for tool schemas and structured output.
OPENAI_API_KEYmust be set (orsetDefaultOpenAIKey()called); browser realtime sessions should use a short-lived client token minted on your server.- Tool search and deferred tool loading need the OpenAI Responses API; the AI SDK adapter for other providers does not support them.
- Versions follow
0.Y.Z, and a minor bump can contain breaking changes; v0.18.0, for example, moved Docker sandbox file APIs inside the container.
Pros
- Both delegation styles, handoffs and agents as tools, are built in and documented side by side. (source)
- Approvals raised inside handoffs or nested agent tools surface on the outer run and can be resumed from serialized state. (source)
- MCP servers can be used as hosted tools or connected directly over Streamable HTTP or stdio. (source)
- Text, sandbox and realtime voice agents share one SDK and the same tool and handoff concepts. (source)
- Runs on Node.js, Deno and Bun, with limited support for Cloudflare Workers. (source)
Cons
- Still pre-1.0: the release policy allows breaking changes in any minor version. (source)
- No built-in A2A support; a maintainer said there were no immediate plans for it. (source)
- Only an in-memory session and an OpenAI Conversations API session ship with the SDK; other databases need a custom
Sessionimplementation. (source) - Some tool features, such as tool search and deferred tool loading, only work with OpenAI Responses models. (source)
- The Codex tool is experimental and its API may change. (source)
Alternatives
FAQ
Does the OpenAI Agents SDK for JavaScript support MCP?
Yes, as a client. Agents can use hosted MCP tools through the Responses API or connect to Streamable HTTP and stdio MCP servers. The docs do not describe running an MCP server.
Does it support A2A?
No. A maintainer said in issue #171 that built-in A2A support was not planned at the time, and no A2A code was found in the repository on 2026-09-30.
Is it free?
The SDK is MIT-licensed. Model calls are billed by whichever provider you use, such as the OpenAI API.
Which runtimes does it support?
Node.js 22+, Deno and Bun are supported server runtimes; Cloudflare Workers have limited support, and realtime voice agents run in the browser.
How is it different from the Python OpenAI Agents SDK?
It is a separate repository for JavaScript and TypeScript with the same core ideas (agents, tools, handoffs, guardrails, sessions) and its own release line, currently 0.18.
Sources
- openai-agents-js GitHub repository
- openai-agents-js README
- openai-agents-js LICENSE
- openai-agents-js releases
- Release v0.18.0 notes
- Issue #171: A2A Support
- OpenAI Agents SDK (TypeScript) docs
- Agents guide
- Handoffs guide
- Agent orchestration guide
- Tools guide (incl. experimental Codex tool)
- Guardrails guide
- Human-in-the-loop guide
- MCP guide
- Sessions guide
- Sandbox agents guide
- Voice agents quickstart
- Tracing guide
- Models guide
- Release process
- Quickstart
- Troubleshooting / supported environments
- AG-UI README, supported integrations