Exploring OpenAI Agent SDK

Aman KumarAman Kumar
3 min read

In the past few days, we explored RAG patterns, LangChain, and LangGraph. Today, we’ll shift gears to OpenAI’s Agent SDK — a lightweight way to build intelligent, multi-agent workflows directly on top of OpenAI models.


🔹 What is OpenAI Agent SDK?

The Agent SDK is a new experimental package from OpenAI (@openai/agents) that makes it easy to:

  • Define agents with specific personalities and expertise.

  • Equip them with tools like APIs, databases, or functions.

  • Use handoffs to route queries between multiple agents automatically.

It’s like having a team of specialized assistants that know when to step in.


🔹 Code Walkthrough

Here’s an example where we build 3 agents:

  1. Cooking Agent → Handles food, menus, and recipes.

  2. Coding Agent → Specializes in JavaScript help.

  3. Triage Agent (Gateway) → Routes user queries to the right agent.

import 'dotenv/config';
import { Agent, run, tool } from '@openai/agents';
import { z } from 'zod';

// Tool to get current time
const getCurrentTime = tool({
  name: 'get_current_time',
  description: 'This tool returns the current time',
  parameters: z.object({}),
  async execute() {
    return new Date().toString();
  },
});

// Tool to fetch menu items
const getMenuTool = tool({
  name: 'get_menu',
  description: 'Fetches and returns the menu items',
  parameters: z.object({}),
  async execute() {
    return {
      Drinks: { Chai: 'INR 50', Coffee: 'INR 70' },
      Veg: { DalMakhni: 'INR 250', Paneer: 'INR 400' },
    };
  },
});

// Cooking Agent
const cookingAgent = new Agent({
  name: 'Cooking Agent',
  model: 'gpt-4.1-mini',
  tools: [getCurrentTime, getMenuTool],
  instructions: `
    You're a helpful cooking assistant specialized in food.
    You suggest menu items, recipes, and help with cooking tips.
  `,
});

// Coding Agent
const codingAgent = new Agent({
  name: 'Coding Agent',
  instructions: `
    You are an expert coding assistant, especially in JavaScript.
  `,
});

// Gateway Agent that decides who handles the query
const gatewayAgent = Agent.create({
  name: 'Triage Agent',
  instructions: `
    Route food-related queries to Cooking Agent.
    Route coding-related queries to Coding Agent.
  `,
  handoffs: [codingAgent, cookingAgent],
});

// Test it
async function chatWithAgent(query) {
  const result = await run(gatewayAgent, query);
  console.log(`History:`, result.history);
  console.log(`Final Agent:`, result.lastAgent.name);
  console.log(`Response:`, result.finalOutput);
}

chatWithAgent('I want to eat cake');

✅ When you run this, the Triage Agent detects that the query is food-related and hands it off to the Cooking Agent.


🔹 Why is Agent SDK exciting?

Compared to LangChain and LangGraph, OpenAI’s SDK feels:

1. Simplicity

  • LangChain is powerful but has steep learning curve and boilerplate.

  • LangGraph gives you fine-grained control over workflows, but requires state graphs.

  • Agent SDK is much simpler — define agents, add tools, connect them. Done.

2. Native Model Support

  • Since it’s from OpenAI, the SDK integrates tightly with GPT models.

  • You don’t need to manage prompts, memory, or output parsing manually.

3. Handoffs

  • The SDK has built-in routing between agents.

  • In LangChain, you’d have to manually wire logic (Routers, Chains).

  • In LangGraph, you’d build explicit edges between nodes.

  • In Agent SDK, it’s automatic with handoffs.

4. Less Overhead

  • No need for external state managers (like MemorySaver in LangGraph).

  • No heavy dependency on additional orchestration libraries.


🔹 When to Use What?

  • LangChain → Best for complex pipelines (retrieval, multi-modal tools, enterprise apps).

  • LangGraph → Best for stateful, iterative, graph-based workflows.

  • Agent SDK → Best for quick, lightweight multi-agent setups with tool use and routing.

Think of it like this:

  • LangChain = Swiss Army Knife.

  • LangGraph = Workflow Engine.

  • Agent SDK = Lightweight Multi-Agent Playground.


🔹 Final Thoughts

The OpenAI Agent SDK is still experimental but feels like the fastest way to spin up multi-agent assistants without heavy infrastructure. If you want to get started quickly with tool-using agents and automatic routing, this is the way to go.


0
Subscribe to my newsletter

Read articles from Aman Kumar directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Aman Kumar
Aman Kumar