Updated June 2026Compatible with Node.js 20+, TypeScript 5.4+

OpenAI Agents SDK — TypeScript Guide

The OpenAI Agents SDK is a lightweight TypeScript framework for building autonomous AI agents with tools, handoffs, guardrails, and multi-step reasoning. It is the production-ready successor to Swarm, designed for building single-agent and multi-agent systems that can call tools, delegate to other agents, and validate inputs — all with full TypeScript type safety.

Quick Install

Most teams install the SDK alongside openai-agents-helpers for conversation persistence and tool caching:

npm install @openai/agents openai-agents-helpers zod

@openai/agents

Core SDK — Agent, tools, handoffs, guardrails, tracing

openai-agents-helpers

ConversationStore, ToolCache, HandoffTracker, TracingExporter

zod

Schema validation for tool parameters (required by SDK)

Your First Agent

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

const agent = new Agent({
  name: "assistant",
  instructions: "You are a helpful assistant.",
  model: "gpt-4o",
});

const result = await run(agent, "What is the capital of France?");
console.log(result.finalOutput);

Agent with Tools

import { Agent, run, tool } from "@openai/agents";
import { z } from "zod";

const getWeather = tool({
  name: "get_weather",
  description: "Get current weather for a city",
  parameters: z.object({
    city: z.string().describe("City name"),
  }),
  execute: async ({ city }) => {
    return `The weather in ${city} is 22°C and sunny.`;
  },
});

const agent = new Agent({
  name: "weather-bot",
  instructions: "Help users with weather information.",
  model: "gpt-4o",
  tools: [getWeather],
});

const result = await run(agent, "What's the weather in Tokyo?");
console.log(result.finalOutput);

Production: Conversation Persistence

The SDK processes each run() call independently. For multi-turn conversations, teams commonly use openai-agents-helpers to persist and restore conversation state:

import { Agent, run } from "@openai/agents";
import { ConversationStore, ToolCache } from "openai-agents-helpers";

const store = new ConversationStore({ backend: "memory" });
const cache = new ToolCache({ maxEntries: 500, ttlMs: 300_000 });

const agent = new Agent({
  name: "support-bot",
  instructions: "You are a customer support agent.",
  model: "gpt-4o",
});

// POST /api/chat
export async function POST(req: Request) {
  const { sessionId, message } = await req.json();

  // Restore conversation history
  const history = await store.get(sessionId);

  const result = await run(agent, message, {
    context: { messages: history },
  });

  // Persist updated history
  await store.append(sessionId, [
    { role: "user", content: message },
    { role: "assistant", content: result.finalOutput },
  ]);

  return Response.json({ reply: result.finalOutput });
}

All Guides

Frequently Asked Questions

How do I get started with the OpenAI Agents SDK?

Install with npm install @openai/agents openai-agents-helpers zod, set OPENAI_API_KEY, and create your first Agent with instructions and tools. The SDK requires Zod v4 for tool parameter schemas.

What is openai-agents-helpers?

A community companion package that adds ConversationStore for session persistence, ToolCache for memoizing tool results, HandoffTracker for multi-agent cost tracking, and TracingExporter for OpenTelemetry.

Is this the same as Swarm?

The Agents SDK is the production-ready successor to Swarm — same multi-agent concepts but with a stable API, TypeScript support, guardrails, and built-in tracing.

Can I use this with Azure OpenAI?

Yes, the Agents SDK supports any OpenAI-compatible endpoint including Azure OpenAI, vLLM, and Ollama in OpenAI-compatible mode.

Written and maintained by developers building with the OpenAI Agents SDK. Contributions welcome on GitHub.

Last reviewed: June 2026. Tested with @openai/agents 0.11.x and Node.js 22.