npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@razroo/agents

v1.0.0

Published

The OpenAI Agents SDK is a lightweight yet powerful framework for building multi-agent workflows.

Readme

OpenAI Agents SDK (JavaScript/TypeScript)

The OpenAI Agents SDK is a lightweight yet powerful framework for building multi-agent workflows in JavaScript/TypeScript. It is provider-agnostic, supporting OpenAI APIs and more.

Core concepts

  1. Agents: LLMs configured with instructions, tools, guardrails, and handoffs.
  2. Handoffs: Specialized tool calls for transferring control between agents.
  3. Guardrails: Configurable safety checks for input and output validation.
  4. Tracing: Built-in tracking of agent runs, allowing you to view, debug, and optimize your workflows.

Explore the examples/ directory to see the SDK in action.

Supported Features

  • [x] Multi-Agent Workflows: Compose and orchestrate multiple agents in a single workflow.
  • [x] Tool Integration: Seamlessly call tools/functions from within agent responses.
  • [x] Handoffs: Transfer control between agents dynamically during a run.
  • [x] Structured Outputs: Support for both plain text and schema-validated structured outputs.
  • [x] Streaming Responses: Stream agent outputs and events in real time.
  • [x] Tracing & Debugging: Built-in tracing for visualizing and debugging agent runs.
  • [x] Guardrails: Input and output validation for safety and reliability.
  • [x] Parallelization: Run agents or tool calls in parallel and aggregate results.
  • [x] Human-in-the-Loop: Integrate human approval or intervention into workflows.
  • [x] Realtime Voice Agents: Build realtime voice agents using WebRTC or Websockets
  • [x] Local MCP Server Support: Give an Agent access to a locally running MCP server to provide tools
  • [x] Separate optimized browser package: Dedicated package meant to run in the browser for Realtime agents.
  • [x] Broader model support: Use non-OpenAI models through the Vercel AI SDK adapter
  • [ ] Long running functions: Suspend an agent loop to execute a long-running function and revive it later
  • [ ] Voice pipeline: Chain text-based agents using speech-to-text and text-to-speech into a voice agent

Get started

Supported environments

  • Node.js 22 or later
  • Deno
  • Bun

Experimental support:

  • Cloudflare Workers with nodejs_compat enabled

Check out the documentation for more detailed information.

Installation

This SDK currently does not work with [email protected] and above. Please install [email protected] (or any older version) explicitly. We will resolve this dependency issue soon. Please check this issue for updates.

npm install @openai/agents 'zod@<=3.25.67'

Hello world example

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 in programming.',
);
console.log(result.finalOutput);
// Code within the code,
// Functions calling themselves,
// Infinite loop's dance.

(If running this, ensure you set the OPENAI_API_KEY environment variable)

Functions example

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

const getWeatherTool = tool({
  name: 'get_weather',
  description: 'Get the weather for a given city',
  parameters: z.object({ city: z.string() }),
  execute: async (input) => {
    return `The weather in ${input.city} is sunny`;
  },
});

const agent = new Agent({
  name: 'Data agent',
  instructions: 'You are a data agent',
  tools: [getWeatherTool],
});

async function main() {
  const result = await run(agent, 'What is the weather in Tokyo?');
  console.log(result.finalOutput);
}

main().catch(console.error);

Handoffs example

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

const getWeatherTool = tool({
  name: 'get_weather',
  description: 'Get the weather for a given city',
  parameters: z.object({ city: z.string() }),
  execute: async (input) => {
    return `The weather in ${input.city} is sunny`;
  },
});

const dataAgent = new Agent({
  name: 'Data agent',
  instructions: 'You are a data agent',
  handoffDescription: 'You know everything about the weather',
  tools: [getWeatherTool],
});

// Use Agent.create method to ensure the finalOutput type considers handoffs
const agent = Agent.create({
  name: 'Basic test agent',
  instructions: 'You are a basic agent',
  handoffs: [dataAgent],
});

async function main() {
  const result = await run(agent, 'What is the weather in San Francisco?');
  console.log(result.finalOutput);
}

main().catch(console.error);

Voice Agent

import { z } from 'zod';
import { RealtimeAgent, RealtimeSession, tool } from '@openai/agents-realtime';

const getWeatherTool = tool({
  name: 'get_weather',
  description: 'Get the weather for a given city',
  parameters: z.object({ city: z.string() }),
  execute: async (input) => {
    return `The weather in ${input.city} is sunny`;
  },
});

const agent = new RealtimeAgent({
  name: 'Data agent',
  instructions: 'You are a data agent',
  tools: [getWeatherTool],
});

// Intended to be run the browser
const { apiKey } = await fetch('/path/to/ephemerial/key/generation').then(
  (resp) => resp.json(),
);
// automatically configures audio input/output so start talking
const session = new RealtimeSession(agent);
await session.connect({ apiKey });

The agent loop

When you call Runner.run(), the SDK executes a loop until a final output is produced.

  1. The agent is invoked with the given input, using the model and settings configured on the agent (or globally).
  2. The LLM returns a response, which may include tool calls or handoff requests.
  3. If the response contains a final output (see below), the loop ends and the result is returned.
  4. If the response contains a handoff, the agent is switched to the new agent and the loop continues.
  5. If there are tool calls, the tools are executed, their results are appended to the message history, and the loop continues.

You can control the maximum number of iterations with the maxTurns parameter.

Final output

The final output is the last thing the agent produces in the loop.

  1. If the agent has an outputType (structured output), the loop ends when the LLM returns a response matching that type.
  2. If there is no outputType (plain text), the first LLM response without tool calls or handoffs is considered the final output.

Summary of the agent loop:

  • If the current agent has an outputType, the loop runs until structured output of that type is produced.
  • If not, the loop runs until a message is produced with no tool calls or handoffs.

Error handling

  • If the maximum number of turns is exceeded, a MaxTurnsExceededError is thrown.
  • If a guardrail is triggered, a GuardrailTripwireTriggered exception is raised.

Documentation

To view the documentation locally:

pnpm docs:dev

Then visit http://localhost:4321 in your browser.

Development

If you want to contribute or edit the SDK/examples:

  1. Install dependencies

    pnpm install
  2. Build the project

    pnpm build
  3. Run tests, linter, etc. (add commands as appropriate for your project)

Acknowledgements

We'd like to acknowledge the excellent work of the open-source community, especially:

We're committed to building the Agents SDK as an open source framework so others in the community can expand on our approach.

For more details, see the documentation or explore the examples/ directory.