This is the full developer documentation for OpenAI Agents SDK (TypeScript) # OpenAI Agents SDK TypeScript > The OpenAI Agents SDK for TypeScript enables you to build agentic AI apps in a lightweight, easy-to-use package with very few abstractions. ## OpenAI Agents SDK Build sandbox, text, and voice agents with a small set of primitives. [Let’s build](/openai-agents-js/llms-full.txt/guides/sandbox-agents) * Sandbox Agent ```typescript import { run } from '@openai/agents'; import { gitRepo, SandboxAgent } from '@openai/agents/sandbox'; import { UnixLocalSandboxClient } from '@openai/agents/sandbox/local'; const agent = new SandboxAgent({ name: 'Workspace Assistant', model: 'gpt-5.5', instructions: 'Inspect the repo before changing files.', defaultManifest: { entries: { repo: gitRepo({ repo: 'openai/openai-agents-js' }) }, }, }); const result = await run( agent, 'Inspect the repo README and summarize what this project does.', { sandbox: { client: new UnixLocalSandboxClient() } }, ); console.log(result.finalOutput); ``` * Text Agent ```typescript 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); ``` * Voice Agent ```typescript import { RealtimeAgent, RealtimeSession } from '@openai/agents/realtime'; const agent = new RealtimeAgent({ name: 'Assistant', instructions: 'You are a helpful assistant.', }); // Automatically connects your microphone and audio output in the browser via WebRTC. const session = new RealtimeSession(agent); await session.connect({ apiKey: '', }); ``` ## Overview [Section titled “Overview”](#overview) The [OpenAI Agents SDK for TypeScript](https://github.com/openai/openai-agents-js) enables you to build agentic AI apps in a lightweight, easy-to-use package with very few abstractions. It’s a production-ready upgrade of our previous experimentation for agents, [Swarm](https://github.com/openai/swarm/tree/main), that’s also [available in Python](https://github.com/openai/openai-agents-python). The Agents SDK has a very small set of primitives: * **Agents**, which are LLMs equipped with instructions and tools * **Sandbox agents**, which pair agents with isolated filesystem workspaces, shell commands, file editing, snapshots, and sandbox session state * **Agents as tools / Handoffs**, which allow agents to delegate to other agents for specific tasks * **Guardrails**, which enable the inputs to agents to be validated In combination with TypeScript, these primitives are powerful enough to express complex relationships between tools and agents, give agents a real workspace when they need one, and allow you to build real-world applications without a steep learning curve. In addition, the SDK comes with built-in **tracing** that lets you visualize and debug your agentic flows, as well as evaluate them and even fine-tune models for your application. ## Why use the Agents SDK [Section titled “Why use the Agents SDK”](#why-use-the-agents-sdk) The SDK has two driving design principles: 1. Enough features to be worth using, but few enough primitives to make it quick to learn. 2. Works great out of the box, but you can customize exactly what happens. Here are the main features of the SDK: * **Agent loop**: A built-in agent loop that handles tool invocation, sends results back to the LLM, and continues until the task is complete. * **Sandbox execution**: Run agents with isolated filesystem workspaces, shell commands, file editing, snapshots, and sandbox session state when the work needs a workspace. * **TypeScript-first**: Orchestrate and chain agents using native TypeScript language features, without needing to learn new abstractions. * **Agents as tools / Handoffs**: A powerful mechanism for coordinating and delegating work across multiple agents. * **Guardrails**: Run input validation and safety checks in parallel with agent execution, and fail fast when checks do not pass. * **Function tools**: Turn any TypeScript function into a tool with automatic schema generation and Zod-powered validation. * **MCP server tool calling**: Built-in MCP server tool integration that works the same way as function tools. * **Sessions**: A persistent memory layer for maintaining working context within an agent loop. * **Human in the loop**: Built-in mechanisms for involving humans across agent runs. * **Tracing**: Built-in tracing for visualizing, debugging, and monitoring workflows, with support for the OpenAI suite of evaluation, fine-tuning, and distillation tools. * **Realtime Agents**: Build powerful voice agents with features such as automatic interruption detection, context management, guardrails, and more. ## Installation [Section titled “Installation”](#installation) ```bash npm install @openai/agents zod ``` The SDK requires Zod v4; installing `zod` via npm will fetch the latest v4 release. ## Choose your starting point [Section titled “Choose your starting point”](#choose-your-starting-point) Most first-time users only need one of these entry points: | Start with | Use it when | Notes | | -------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `@openai/agents` | You are building most text, sandbox, or voice applications. | Recommended default. It includes the OpenAI provider setup, sandbox agent APIs under `@openai/agents/sandbox`, and voice APIs under `@openai/agents/realtime`. | | `@openai/agents-realtime` | You only need the standalone Realtime package. | Useful for browser-only voice apps or when you want a narrower package boundary. | | Lower-level packages (`@openai/agents-core`, `@openai/agents-openai`, `@openai/agents-extensions`) | You need lower-level composition, custom provider wiring, or specific integrations. | Most new users can ignore these until they have a concrete need. | ## Hello world examples [Section titled “Hello world examples”](#hello-world-examples) Start with a sandbox agent when the agent should work in a filesystem. You can still use a regular `Agent` when your workflow does not need a sandbox workspace or sandbox lifecycle. * Sandbox Agent Hello World with a sandbox ```typescript import { run } from '@openai/agents'; import { gitRepo, SandboxAgent } from '@openai/agents/sandbox'; import { UnixLocalSandboxClient } from '@openai/agents/sandbox/local'; const agent = new SandboxAgent({ name: 'Workspace Assistant', model: 'gpt-5.5', instructions: 'Inspect the repo before changing files.', defaultManifest: { entries: { repo: gitRepo({ repo: 'openai/openai-agents-js' }) }, }, }); const result = await run( agent, 'Inspect the repo README and summarize what this project does.', { sandbox: { client: new UnixLocalSandboxClient() } }, ); console.log(result.finalOutput); ``` * Without Sandbox Hello World without a sandbox ```typescript 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*) ```bash export OPENAI_API_KEY=sk-... ``` ## Start here [Section titled “Start here”](#start-here) Pick one path first, get it working end to end, then come back for the deeper guides. [Quickstart ](/openai-agents-js/guides/quickstart)Build your first text-based agent and learn the core SDK workflow. [Voice Agents Quickstart ](/openai-agents-js/guides/voice-agents/quickstart)Start with the Realtime voice path when you are building spoken interactions. [Sandbox agents ](/openai-agents-js/guides/sandbox-agents)Start a sandbox agent when the agent needs files, shell commands, patches, or resumable sandbox state. ## Choose your path [Section titled “Choose your path”](#choose-your-path) Use this table when you know the job you want to do, but not which page explains it. | Goal | Start here | | --------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------- | | Build the first text agent and see one complete run | [Quickstart](/openai-agents-js/guides/quickstart) | | Add function tools, hosted tools, or agents as tools | [Tools](/openai-agents-js/guides/tools) | | Give an agent an isolated filesystem and shell workspace | [Sandbox agents](/openai-agents-js/guides/sandbox-agents) | | Decide between handoffs and manager-style orchestration | [Agent orchestration](/openai-agents-js/guides/multi-agent) | | Keep memory across turns | [Running agents](/openai-agents-js/guides/running-agents) and [Sessions](/openai-agents-js/guides/sessions) | | Use OpenAI models, websocket transport, or non-OpenAI providers | [Models](/openai-agents-js/guides/models) | | Review outputs, run items, interruptions, and resume state | [Results](/openai-agents-js/guides/results) | | Build a low-latency voice agent | [Voice Agents Quickstart](/openai-agents-js/guides/voice-agents/quickstart) | # AI SDK Integration > Connect your Agents SDK agents to any model through Vercel's AI SDK Out of the box the Agents SDK works with OpenAI models through the Responses API or Chat Completions API. However, if you would like to use another model, the [Vercel AI SDK](https://sdk.vercel.ai/) offers a range of supported models that can be brought into the Agents SDK through this adapter. ## Setup [Section titled “Setup”](#setup) 1. Install the AI SDK adapter by installing the extensions package: ```bash npm install @openai/agents-extensions ``` 2. Choose your desired model package from the [Vercel’s AI SDK](https://ai-sdk.dev/docs/foundations/providers-and-models) and install it: ```bash npm install @ai-sdk/openai ``` 3. Import the adapter and model to connect to your agent: Import the adapter ```typescript import { openai } from '@ai-sdk/openai'; import { aisdk } from '@openai/agents-extensions/ai-sdk'; ``` 4. Initialize an instance of the model to be used by the agent: Create the model ```typescript import { openai } from '@ai-sdk/openai'; import { aisdk } from '@openai/agents-extensions/ai-sdk'; const model = aisdk(openai('gpt-5.4')); ``` ## Code examples [Section titled “Code examples”](#code-examples) AI SDK Setup ```typescript import { Agent, run } from '@openai/agents'; // Import the model package you installed import { openai } from '@ai-sdk/openai'; // Import the adapter import { aisdk } from '@openai/agents-extensions/ai-sdk'; // Create a model instance to be used by the agent const model = aisdk(openai('gpt-5.4')); // Create an agent with the model const agent = new Agent({ name: 'My Agent', instructions: 'You are a helpful assistant.', model, }); // Run the agent with the new model run(agent, 'What is the capital of Germany?'); ``` ## Passing provider metadata [Section titled “Passing provider metadata”](#passing-provider-metadata) If you need to send provider-specific options with a message, pass them through `providerMetadata`. The values are forwarded directly to the underlying AI SDK model. For example, the following `providerData` in the Agents SDK Agents SDK providerData ```typescript const providerData = { anthropic: { cacheControl: { type: 'ephemeral', }, }, }; ``` would become AI SDK providerMetadata ```typescript const providerMetadata = { anthropic: { cacheControl: { type: 'ephemeral', }, }, }; ``` when using the AI SDK integration. ## Normalizing finalized output text [Section titled “Normalizing finalized output text”](#normalizing-finalized-output-text) Some providers return structured output as plain text with extra wrapping, such as JSON code fences. If you need provider-specific cleanup before the Agents runtime validates the final output, pass `transformOutputText` when creating the adapter: Normalize finalized output text ````typescript import { openai } from '@ai-sdk/openai'; import { aisdk } from '@openai/agents-extensions/ai-sdk'; const model = aisdk(openai('gpt-5.4'), { transformOutputText(text) { return text.match(/```(?:json)?\s*([\s\S]*?)\s*```/)?.[1]?.trim() ?? text; }, }); ```` `transformOutputText` runs on finalized assistant text for non-streamed responses and on the final `response_done` event for streamed responses. It does not modify incremental `output_text_delta` events. ## Retries [Section titled “Retries”](#retries) `modelSettings.retry` works with AI SDK-backed models too, because retries are implemented by the Agents runtime rather than only by the default OpenAI provider. That means you can attach the same retry configuration you would use elsewhere: * Set `modelSettings.retry` on the `Agent`, `Runner`, or both. * Compose `retryPolicies` such as `networkError()`, `httpStatus([...])`, or `providerSuggested()`. * Keep in mind that `providerSuggested()` only helps when the wrapped AI SDK model can surface retry advice through the adapter. For a complete example using `aisdk(openai(...))`, see [`examples/ai-sdk/retry.ts`](https://github.com/openai/openai-agents-js/tree/main/examples/ai-sdk/retry.ts). For the retry API itself, including safety boundaries for streaming and stateful follow-up requests, see the [Models guide](/openai-agents-js/guides/models#model-retries). ## Picking the right integration [Section titled “Picking the right integration”](#picking-the-right-integration) There are two related integrations in `@openai/agents-extensions`: * `@openai/agents-extensions/ai-sdk` adapts an AI SDK model so an `Agent` can run on it. * `@openai/agents-extensions/ai-sdk-ui` adapts a streamed Agents SDK run so AI SDK UI routes can return a standard streaming `Response`. ### Notes for AI SDK models [Section titled “Notes for AI SDK models”](#notes-for-ai-sdk-models) * The `@openai/agents-extensions/ai-sdk` adapter is still in beta, so it is worth testing carefully with your chosen provider, especially smaller ones. * If you are using OpenAI models, prefer the default OpenAI model provider instead of this adapter. * Supported AI SDK providers must expose `specificationVersion` `v2` or `v3`. If you need the older v1 provider style, copy the module from [examples/ai-sdk-v1](https://github.com/openai/openai-agents-js/tree/main/examples/ai-sdk-v1) into your project. * Computer tools require display metadata when used through this adapter. Make sure the tool includes both `environment` and `dimensions` metadata. * Deferred Responses tool-loading flows are not supported here. That includes `toolNamespace()`, function tools with `deferLoading: true`, and `toolSearchTool()`. If you need tool search, use an OpenAI Responses model directly. See the [Tools guide](/openai-agents-js/guides/tools#deferred-tool-loading-with-tool-search) and [Models guide](/openai-agents-js/guides/models#responses-only-deferred-tool-loading). ## AI SDK UI stream helpers [Section titled “AI SDK UI stream helpers”](#ai-sdk-ui-stream-helpers) `@openai/agents-extensions/ai-sdk-ui` provides response helpers for wiring Agents SDK streams into AI SDK UI routes: * `createAiSdkTextStreamResponse(source, options?)` for plain text streaming responses. * `createAiSdkUiMessageStream(source)` for a lower-level `ReadableStream`. * `createAiSdkUiMessageStreamResponse(source, options?)` for `UIMessageChunk` streaming responses. These helpers accept a `StreamedRunResult`, stream-like source, or compatible wrapper object. The response helpers return a `Response` with streaming-friendly headers. Use `createAiSdkUiMessageStreamResponse(...)` when your route should return the AI SDK response directly. Use `createAiSdkUiMessageStream(...)` when you want to own the response or rendering layer while still using the maintained Agents SDK to AI SDK `UIMessageChunk` translation. Use `createAiSdkTextStreamResponse(...)` when you only want plain text. The response helpers also accept optional response settings through `options`: * `headers`: additional response headers to merge into the streaming response. * `status`: the HTTP status code for the returned `Response`. * `statusText`: the HTTP status text for the returned `Response`. Example lower-level UI message stream: UI message stream ```typescript import { Agent, run } from '@openai/agents'; import { createAiSdkUiMessageStream } from '@openai/agents-extensions/ai-sdk-ui'; const agent = new Agent({ name: 'Assistant', instructions: 'Reply with a short answer.', }); export async function createStream() { const stream = await run(agent, 'Hello there.', { stream: true }); return createAiSdkUiMessageStream(stream); } ``` Example Next.js route for UI message streaming: UI message stream response ```typescript import { Agent, run } from '@openai/agents'; import { createAiSdkUiMessageStreamResponse } from '@openai/agents-extensions/ai-sdk-ui'; const agent = new Agent({ name: 'Assistant', instructions: 'Reply with a short answer.', }); export async function POST() { const stream = await run(agent, 'Hello there.', { stream: true }); return createAiSdkUiMessageStreamResponse(stream); } ``` Example Next.js route for text-only streaming: Text stream response ```typescript import { Agent, run } from '@openai/agents'; import { createAiSdkTextStreamResponse } from '@openai/agents-extensions/ai-sdk-ui'; const agent = new Agent({ name: 'Assistant', instructions: 'Reply with a short answer.', }); export async function POST() { const stream = await run(agent, 'Hello there.', { stream: true }); return createAiSdkTextStreamResponse(stream); } ``` For end-to-end usage, see the `examples/ai-sdk-ui` app in this repository. # Realtime Agents on Cloudflare > Connect your Agents SDK agents from Cloudflare Workers/workerd using a dedicated transport. Cloudflare Workers and other workerd runtimes cannot open outbound WebSockets using the global `WebSocket` constructor. To simplify connecting Realtime Agents from these environments, the extensions package provides a dedicated transport that performs the `fetch()`-based upgrade internally. Caution This adapter is still in beta. You may run into edge case issues or bugs. Please report any issues via [GitHub issues](https://github.com/openai/openai-agents-js/issues) and we’ll fix quickly. For Node.js-style APIs in Workers, consider enabling `nodejs_compat`. ## Setup [Section titled “Setup”](#setup) 1. **Install the extensions package.** ```bash npm install @openai/agents-extensions ``` 2. **Create a transport and attach it to your session.** ```typescript import { CloudflareRealtimeTransportLayer } from '@openai/agents-extensions'; import { RealtimeAgent, RealtimeSession } from '@openai/agents/realtime'; const agent = new RealtimeAgent({ name: 'My Agent', }); // Create a transport that connects to OpenAI Realtime via Cloudflare/workerd's fetch-based upgrade. const cfTransport = new CloudflareRealtimeTransportLayer({ url: 'wss://api.openai.com/v1/realtime?model=gpt-realtime-2', }); const session = new RealtimeSession(agent, { // Set your own transport. transport: cfTransport, }); ``` 3. **Connect your `RealtimeSession`.** ```typescript await session.connect({ apiKey: 'your-openai-ephemeral-or-server-key' }); ``` ## Notes [Section titled “Notes”](#notes) * The Cloudflare transport uses `fetch()` with `Upgrade: websocket` under the hood and skips waiting for a socket `open` event, matching the workerd APIs. * All `RealtimeSession` features (tools, guardrails, etc.) work as usual when using this transport. * Use `DEBUG=openai-agents*` to inspect detailed logs during development. # Realtime Agents on Twilio > Run Agents SDK voice agents over Twilio phone calls Twilio offers a [Media Streams API](https://www.twilio.com/docs/voice/media-streams) that sends the raw audio from a phone call to a WebSocket server. This setup can be used to connect your [voice agents](/openai-agents-js/guides/voice-agents) to Twilio. You can use the default Realtime Session transport in `websocket` mode to connect the events coming from Twilio to your Realtime Session. However, this requires you to set the right audio format and adjust your own interruption timing as phone calls will naturally introduce more latency than a web-based conversation. To improve the setup experience, we’ve created a dedicated transport layer that handles the connection to Twilio, including interruption handling and audio forwarding. Caution This adapter is still in beta. You may run into edge case issues or bugs. Please report any issues via [GitHub issues](https://github.com/openai/openai-agents-js/issues) and we’ll fix quickly. ## Setup [Section titled “Setup”](#setup) 1. **Make sure you have a Twilio account and a Twilio phone number.** 2. **Set up a WebSocket server that can receive events from Twilio.** If you are developing locally, you will need to configure a local tunnel like [`ngrok`](https://ngrok.io/) or [Cloudflare Tunnel](https://developers.cloudflare.com/pages/how-to/preview-with-cloudflare-tunnel/) to make your local server accessible to Twilio. You can use the `TwilioRealtimeTransportLayer` to connect to Twilio. 3. **Install the Twilio adapter by installing the extensions package:** ```bash npm install @openai/agents-extensions ``` 4. **Import the adapter and model to connect to your `RealtimeSession`:** ```typescript import { TwilioRealtimeTransportLayer } from '@openai/agents-extensions'; import { RealtimeAgent, RealtimeSession } from '@openai/agents/realtime'; const agent = new RealtimeAgent({ name: 'My Agent', }); // Create a new transport mechanism that will bridge the connection between Twilio and // the OpenAI Realtime API. const twilioTransport = new TwilioRealtimeTransportLayer({ twilioWebSocket: websocketConnection, }); const session = new RealtimeSession(agent, { // set your own transport transport: twilioTransport, }); ``` 5. **Connect your `RealtimeSession` to Twilio:** ```typescript session.connect({ apiKey: 'your-openai-api-key' }); ``` Any event and behavior that you would expect from a `RealtimeSession` will work as expected including tool calls, guardrails, and more. Read the [voice agents guide](/openai-agents-js/guides/voice-agents) for more information on how to use the `RealtimeSession` with voice agents. ## Tips and considerations [Section titled “Tips and considerations”](#tips-and-considerations) 1. **Speed is the name of the game.** In order to receive all the necessary events and audio from Twilio, you should create your `TwilioRealtimeTransportLayer` instance as soon as you have a reference to the WebSocket connection and immediately call `session.connect()` afterwards. 2. **Access the raw Twilio events.** If you want to access the raw events that are being sent by Twilio, you can listen to the `transport_event` event on your `RealtimeSession` instance. Every event from Twilio will have a type of `twilio_message` and a `message` property that contains the raw event data. 3. **Watch debug logs.** Sometimes you may run into issues where you want more information on what’s going on. Using a `DEBUG=openai-agents*` environment variable will show all the debug logs from the Agents SDK. Alternatively, you can enable just debug logs for the Twilio adapter using `DEBUG=openai-agents:extensions:twilio*`. ## Full example server [Section titled “Full example server”](#full-example-server) Below is an example of a full end-to-end example of a WebSocket server that receives requests from Twilio and forwards them to a `RealtimeSession`. Example server using Fastify ```typescript import Fastify from 'fastify'; import type { FastifyInstance, FastifyReply, FastifyRequest } from 'fastify'; import dotenv from 'dotenv'; import fastifyFormBody from '@fastify/formbody'; import fastifyWs from '@fastify/websocket'; import { RealtimeAgent, RealtimeSession, backgroundResult, tool, } from '@openai/agents/realtime'; import { TwilioRealtimeTransportLayer } from '@openai/agents-extensions'; import { hostedMcpTool } from '@openai/agents'; import { z } from 'zod'; import process from 'node:process'; // Load environment variables from .env file dotenv.config(); // Retrieve the OpenAI API key from environment variables. You must have OpenAI Realtime API access. const { OPENAI_API_KEY } = process.env; if (!OPENAI_API_KEY) { console.error('Missing OpenAI API key. Please set it in the .env file.'); process.exit(1); } const PORT = +(process.env.PORT || 5050); // Initialize Fastify const fastify = Fastify(); fastify.register(fastifyFormBody); fastify.register(fastifyWs); const weatherTool = tool({ name: 'weather', description: 'Get the weather in a given location.', parameters: z.object({ location: z.string(), }), execute: async ({ location }: { location: string }) => { return backgroundResult(`The weather in ${location} is sunny.`); }, }); const secretTool = tool({ name: 'secret', description: 'A secret tool to tell the special number.', parameters: z.object({ question: z .string() .describe( 'The question to ask the secret tool; mainly about the special number.', ), }), execute: async ({ question }: { question: string }) => { return `The answer to ${question} is 42.`; }, needsApproval: true, }); const agent = new RealtimeAgent({ name: 'Greeter', instructions: 'You are a friendly assistant. When you use a tool always first say what you are about to do.', tools: [ hostedMcpTool({ serverLabel: 'deepwiki', serverUrl: 'https://mcp.deepwiki.com/mcp', }), secretTool, weatherTool, ], }); // Root Route fastify.get('/', async (_request: FastifyRequest, reply: FastifyReply) => { reply.send({ message: 'Twilio Media Stream Server is running!' }); }); // Route for Twilio to handle incoming and outgoing calls // punctuation to improve text-to-speech translation fastify.all( '/incoming-call', async (request: FastifyRequest, reply: FastifyReply) => { const twimlResponse = ` O.K. you can start talking! `.trim(); reply.type('text/xml').send(twimlResponse); }, ); // WebSocket route for media-stream fastify.register(async (scopedFastify: FastifyInstance) => { scopedFastify.get( '/media-stream', { websocket: true }, async (connection: any) => { const twilioTransportLayer = new TwilioRealtimeTransportLayer({ twilioWebSocket: connection, }); const session = new RealtimeSession(agent, { transport: twilioTransportLayer, model: 'gpt-realtime-2', config: { audio: { output: { voice: 'verse', }, }, }, }); session.on('mcp_tools_changed', (tools: { name: string }[]) => { const toolNames = tools.map((tool) => tool.name).join(', '); console.log(`Available MCP tools: ${toolNames || 'None'}`); }); session.on( 'tool_approval_requested', (_context: unknown, _agent: unknown, approvalRequest: any) => { console.log( `Approving tool call for ${approvalRequest.approvalItem.rawItem.name}.`, ); session .approve(approvalRequest.approvalItem) .catch((error: unknown) => console.error('Failed to approve tool call.', error), ); }, ); session.on( 'mcp_tool_call_completed', (_context: unknown, _agent: unknown, toolCall: unknown) => { console.log('MCP tool call completed.', toolCall); }, ); await session.connect({ apiKey: OPENAI_API_KEY, }); console.log('Connected to the OpenAI Realtime API'); }, ); }); fastify.listen({ port: PORT }, (err: Error | null) => { if (err) { console.error(err); process.exit(1); } console.log(`Server is listening on port ${PORT}`); }); process.on('SIGINT', () => { fastify.close(); process.exit(0); }); ``` # Agents > Learn more about how to define agents in the OpenAI Agents SDK for JavaScript / TypeScript Agents are the main building‑block of the OpenAI Agents SDK. An **Agent** is a Large Language Model (LLM) that has been configured with: * **Instructions** – the system prompt that tells the model *who it is* and *how it should respond*. * **Model** – which OpenAI model to call, plus any optional model tuning parameters. * **Tools** – a list of functions or APIs the LLM can invoke to accomplish a task. Basic Agent definition ```typescript import { Agent } from '@openai/agents'; const agent = new Agent({ name: 'Haiku Agent', instructions: 'Always respond in haiku form.', model: 'gpt-5.4', // optional – falls back to the default model }); ``` > Use this page when you want to define or customize a single `Agent`. If you are deciding how several agents should collaborate, read [Agent orchestration](/openai-agents-js/guides/multi-agent). ### Choose the next guide [Section titled “Choose the next guide”](#choose-the-next-guide) Use this page as the hub for agent definition. Jump out to the adjacent guide that matches the next decision you need to make. | If you want to… | Read next | | ----------------------------------------------- | ------------------------------------------------------------------ | | Choose a model or configure stored prompts | [Models](/openai-agents-js/guides/models) | | Add capabilities to the agent | [Tools](/openai-agents-js/guides/tools) | | Give the agent an isolated filesystem workspace | [Sandbox agents](/openai-agents-js/guides/sandbox-agents/concepts) | | Decide between managers and handoffs | [Agent orchestration](/openai-agents-js/guides/multi-agent) | | Configure handoff behavior | [Handoffs](/openai-agents-js/guides/handoffs) | | Run turns, stream events, or manage state | [Running agents](/openai-agents-js/guides/running-agents) | | Inspect final output, run items, or resume | [Results](/openai-agents-js/guides/results) | The rest of this page walks through every Agent feature in more detail. *** ## Agent fundamentals [Section titled “Agent fundamentals”](#agent-fundamentals) ### Basic configuration [Section titled “Basic configuration”](#basic-configuration) The `Agent` constructor takes a single configuration object. The most commonly‑used properties are shown below. | Property | Required | Description | | --------------------------------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `name` | yes | A short human‑readable identifier. | | `instructions` | yes | System prompt (string **or** function – see [Dynamic instructions](#dynamic-instructions)). | | `prompt` | no | OpenAI Responses API prompt configuration. Accepts a static prompt object or a function. See [Prompt](/openai-agents-js/guides/models#prompt). | | `handoffDescription` | no | Short description used when this agent is offered as a handoff tool. | | `handoffs` | no | Delegate the conversation to specialist agents. See [Composition patterns](#composition-patterns) and the [Handoffs guide](/openai-agents-js/guides/handoffs). | | `model` | no | Model name **or** a custom [`Model`](/openai-agents-js/openai/agents/interfaces/model/) implementation. | | `modelSettings` | no | Tuning parameters (temperature, top\_p, etc.). See [Models](/openai-agents-js/guides/models#modelsettings). If the properties you need aren’t at the top level, you can include them under `providerData`. | | `tools` | no | Array of [`Tool`](/openai-agents-js/openai/agents/type-aliases/tool/) instances the model can call. See [Tools](/openai-agents-js/guides/tools). | | `mcpServers` | no | MCP-backed tools for the agent. See the [MCP guide](/openai-agents-js/guides/mcp). | | `mcpConfig` | no | Options for local MCP tools, such as strict schemas, error handling, and server-prefixed tool names. See [Agent-level MCP configuration](/openai-agents-js/guides/mcp#agent-level-mcp-configuration). | | `inputGuardrails` | no | Guardrails applied to the first user input for this agent chain. See [Guardrails](/openai-agents-js/guides/guardrails). | | `outputGuardrails` | no | Guardrails applied to the final output for this agent. See [Guardrails](/openai-agents-js/guides/guardrails). | | `outputType` | no | Return structured output instead of plain text. See [Output types](#output-types) and [Results](/openai-agents-js/guides/results#final-output). | | `toolUseBehavior` | no | Control whether function-tool results loop back to the model or finish the run. See [Forcing tool use](#forcing-tool-use). | | `resetToolChoice` | no | Reset `toolChoice` to the default after a tool call (default: `true`) to prevent tool-use loops. See [Forcing tool use](#forcing-tool-use). | | `handoffOutputTypeWarningEnabled` | no | Emit a warning when handoff output types differ (default: `true`). See [Results](/openai-agents-js/guides/results#final-output). | Agent with tools ```typescript import { Agent, tool } from '@openai/agents'; import { z } from 'zod'; const getWeather = tool({ name: 'get_weather', description: 'Return the weather for a given city.', parameters: z.object({ city: z.string() }), async execute({ city }) { return `The weather in ${city} is sunny.`; }, }); const agent = new Agent({ name: 'Weather bot', instructions: 'You are a helpful weather bot.', model: 'gpt-4.1', tools: [getWeather], }); ``` *** ### Context [Section titled “Context”](#context) Agents are **generic on their context type** – i.e. `Agent`. The *context* is a dependency‑injection object that you create and pass to `Runner.run()`. It is forwarded to every tool, guardrail, handoff, etc. and is useful for storing state or providing shared services (database connections, user metadata, feature flags, …). Agent with context ```typescript import { Agent } from '@openai/agents'; interface Purchase { id: string; uid: string; deliveryStatus: string; } interface UserContext { uid: string; isProUser: boolean; // this function can be used within tools fetchPurchases(): Promise; } const agent = new Agent({ name: 'Personal shopper', instructions: 'Recommend products the user will love.', }); // Later import { run } from '@openai/agents'; const result = await run(agent, 'Find me a new pair of running shoes', { context: { uid: 'abc', isProUser: true, fetchPurchases: async () => [] }, }); ``` *** ### Output types [Section titled “Output types”](#output-types) By default, an Agent returns **plain text** (`string`). If you want the model to return a structured object you can specify the `outputType` property. The SDK accepts: 1. A [Zod](https://github.com/colinhacks/zod) schema (`z.object({...})`). 2. Any JSON‑schema‑compatible object. Structured output with Zod ```typescript import { Agent } from '@openai/agents'; import { z } from 'zod'; const CalendarEvent = z.object({ name: z.string(), date: z.string(), participants: z.array(z.string()), }); const extractor = new Agent({ name: 'Calendar extractor', instructions: 'Extract calendar events from the supplied text.', outputType: CalendarEvent, }); ``` When `outputType` is provided, the SDK automatically uses [structured outputs](https://developers.openai.com/api/docs/guides/structured-outputs) instead of plain text. *** ### OpenAI platform mapping [Section titled “OpenAI platform mapping”](#openai-platform-mapping) Some agent concepts map directly to OpenAI platform concepts, while others are configured when you run the agent rather than when you define it. | SDK concept | OpenAI guide | When it matters | | --------------------------------------- | -------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------ | | `outputType` | [Structured Outputs](https://developers.openai.com/api/docs/guides/structured-outputs) | The agent should return typed JSON or a Zod-validated object instead of text. | | `tools` / hosted tools | [Tools guide](https://developers.openai.com/api/docs/guides/tools) | The model should search, retrieve, execute code, or call your functions/tools. | | `conversationId` / `previousResponseId` | [Conversation state](https://developers.openai.com/api/docs/guides/conversation-state) | You want OpenAI to persist or chain conversation state between turns. | `conversationId` and `previousResponseId` are run-time controls, not `Agent` constructor fields. Use [Running agents](/openai-agents-js/guides/running-agents) when you need those SDK entry points. *** ## Composition patterns [Section titled “Composition patterns”](#composition-patterns) Two SDK entry points show up most often when an agent participates in a larger workflow: 1. **Manager (agents as tools)** – a central agent owns the conversation and invokes specialized agents that are exposed as tools. 2. **Handoffs** – the initial agent delegates the entire conversation to a specialist once it has identified the user’s request. These approaches are complementary. Managers give you a single place to enforce guardrails or rate limits, while handoffs let each agent focus on a single task without retaining control of the conversation. For the design tradeoffs and when to choose each pattern, see [Agent orchestration](/openai-agents-js/guides/multi-agent). #### Manager (agents as tools) [Section titled “Manager (agents as tools)”](#manager-agents-as-tools) In this pattern the manager never hands over control—the LLM uses the tools and the manager summarizes the final answer. Read more in the [tools guide](/openai-agents-js/guides/tools#agents-as-tools). Agents as tools ```typescript import { Agent } from '@openai/agents'; const bookingAgent = new Agent({ name: 'Booking expert', instructions: 'Answer booking questions and modify reservations.', }); const refundAgent = new Agent({ name: 'Refund expert', instructions: 'Help customers process refunds and credits.', }); const customerFacingAgent = new Agent({ name: 'Customer-facing agent', instructions: 'Talk to the user directly. When they need booking or refund help, call the matching tool.', tools: [ bookingAgent.asTool({ toolName: 'booking_expert', toolDescription: 'Handles booking questions and requests.', }), refundAgent.asTool({ toolName: 'refund_expert', toolDescription: 'Handles refund questions and requests.', }), ], }); ``` #### Handoffs [Section titled “Handoffs”](#handoffs) With handoffs the triage agent routes requests, but once a handoff occurs the specialist agent owns the conversation until it produces a final output. This keeps prompts short and lets you reason about each agent independently. Learn more in the [handoffs guide](/openai-agents-js/guides/handoffs). Agent with handoffs ```typescript import { Agent } from '@openai/agents'; const bookingAgent = new Agent({ name: 'Booking Agent', instructions: 'Help users with booking requests.', }); const refundAgent = new Agent({ name: 'Refund Agent', instructions: 'Process refund requests politely and efficiently.', }); // Use Agent.create method to ensure the finalOutput type considers handoffs const triageAgent = Agent.create({ name: 'Triage Agent', instructions: `Help the user with their questions. If the user asks about booking, hand off to the booking agent. If the user asks about refunds, hand off to the refund agent.`.trimStart(), handoffs: [bookingAgent, refundAgent], }); ``` If your handoff targets can return different output types, prefer `Agent.create(...)` over `new Agent(...)`. That lets TypeScript infer the union of possible `finalOutput` shapes across the handoff graph and avoids the runtime warning controlled by `handoffOutputTypeWarningEnabled`. See the [results guide](/openai-agents-js/guides/results#final-output) for an end-to-end example. *** ## Advanced configuration and runtime controls [Section titled “Advanced configuration and runtime controls”](#advanced-configuration-and-runtime-controls) ### Dynamic instructions [Section titled “Dynamic instructions”](#dynamic-instructions) `instructions` can be a **function** instead of a string. The function receives the current `RunContext` and the Agent instance and can return a string *or* a `Promise`. Agent with dynamic instructions ```typescript import { Agent, RunContext } from '@openai/agents'; interface UserContext { name: string; } function buildInstructions(runContext: RunContext) { return `The user's name is ${runContext.context.name}. Be extra friendly!`; } const agent = new Agent({ name: 'Personalized helper', instructions: buildInstructions, }); ``` Both synchronous and `async` functions are supported. *** ### Dynamic prompts [Section titled “Dynamic prompts”](#dynamic-prompts) `prompt` supports the same callback shape as `instructions`, but returns a prompt configuration object instead of a string. This is useful when the prompt ID, version, or variables depend on the current run context. Agent with dynamic prompt ```typescript import { Agent, RunContext } from '@openai/agents'; interface PromptContext { customerTier: 'free' | 'pro'; } function buildPrompt(runContext: RunContext) { return { promptId: 'pmpt_support_agent', version: '7', variables: { customer_tier: runContext.context.customerTier, }, }; } const agent = new Agent({ name: 'Prompt-backed helper', prompt: buildPrompt, }); ``` This is only supported when you use the OpenAI Responses API. Both synchronous and `async` functions are supported. *** ### Lifecycle hooks [Section titled “Lifecycle hooks”](#lifecycle-hooks) For advanced use‑cases you can observe the Agent lifecycle by listening on events. `Agent` instances emit lifecycle events for that specific agent instance, while `Runner` emits the same event names as a single stream across the whole run. This is useful for multi-agent workflows where you want one place to observe handoffs and tool calls. The shared event names are: | Event | Agent hook arguments | Runner hook arguments | | ------------------ | --------------------------------------- | ---------------------------------------------- | | `agent_start` | `(context, agent, turnInput?)` | `(context, agent, turnInput?)` | | `agent_end` | `(context, output)` | `(context, agent, output)` | | `agent_handoff` | `(context, nextAgent)` | `(context, fromAgent, toAgent)` | | `agent_tool_start` | `(context, tool, { toolCall })` | `(context, agent, tool, { toolCall })` | | `agent_tool_end` | `(context, tool, result, { toolCall })` | `(context, agent, tool, result, { toolCall })` | Agent with lifecycle hooks ```typescript import { Agent } from '@openai/agents'; const agent = new Agent({ name: 'Verbose agent', instructions: 'Explain things thoroughly.', }); agent.on('agent_start', (ctx, agent) => { console.log(`[${agent.name}] started`); }); agent.on('agent_end', (ctx, output) => { console.log(`[agent] produced:`, output); }); ``` *** ### Guardrails [Section titled “Guardrails”](#guardrails) Guardrails allow you to validate or transform user input and agent output. They are configured via the `inputGuardrails` and `outputGuardrails` arrays. See the [guardrails guide](/openai-agents-js/guides/guardrails) for details. *** ### Cloning / copying agents [Section titled “Cloning / copying agents”](#cloning--copying-agents) Need a slightly modified version of an existing agent? Use the `clone()` method, which returns an entirely new `Agent` instance. Cloning Agents ```typescript import { Agent } from '@openai/agents'; const pirateAgent = new Agent({ name: 'Pirate', instructions: 'Respond like a pirate – lots of “Arrr!”', model: 'gpt-5.4', }); const robotAgent = pirateAgent.clone({ name: 'Robot', instructions: 'Respond like a robot – be precise and factual.', }); ``` *** ### Forcing tool use [Section titled “Forcing tool use”](#forcing-tool-use) Supplying tools doesn’t guarantee the LLM will call one. You can **force** tool use with `modelSettings.toolChoice`: 1. `'auto'` (default) – the LLM decides whether to use a tool. 2. `'required'` – the LLM *must* call a tool (it can choose which one). 3. `'none'` – the LLM must **not** call a tool. 4. A specific tool name, e.g. `'calculator'` – the LLM must call that particular tool. When the available tool is `computerTool()` on OpenAI Responses, `toolChoice: 'computer'` is special: it forces the GA built-in computer tool instead of treating `'computer'` as a plain function name. The SDK also accepts preview-compatible computer selectors for older integrations, but new code should prefer `'computer'`. If no computer tool is available, the string behaves like any other function tool name. Forcing tool use ```typescript import { Agent, tool } from '@openai/agents'; import { z } from 'zod'; const calculatorTool = tool({ name: 'Calculator', description: 'Use this tool to answer questions about math problems.', parameters: z.object({ question: z.string() }), execute: async (input) => { throw new Error('TODO: implement this'); }, }); const agent = new Agent({ name: 'Strict tool user', instructions: 'Always answer using the calculator tool.', tools: [calculatorTool], modelSettings: { toolChoice: 'required' }, }); ``` When you use deferred Responses tools such as `toolNamespace()`, function tools with `deferLoading: true`, or hosted MCP tools with `deferLoading: true`, keep `modelSettings.toolChoice` on `'auto'`. The SDK rejects forcing a deferred tool or the built-in `tool_search` helper by name because the model needs to decide when to load those definitions. See the [Tools guide](/openai-agents-js/guides/tools#deferred-tool-loading-with-tool-search) for the full tool-search setup. #### Preventing infinite loops [Section titled “Preventing infinite loops”](#preventing-infinite-loops) After a tool call the SDK automatically resets `toolChoice` back to `'auto'`. This prevents the model from entering an infinite loop where it repeatedly tries to call the tool. You can override this behavior via the `resetToolChoice` flag or by configuring `toolUseBehavior`: * `'run_llm_again'` (default) – run the LLM again with the tool result. * `'stop_on_first_tool'` – treat the first tool result as the final answer. * `{ stopAtToolNames: ['my_tool'] }` – stop when any of the listed tools is called. * `(context, toolResults) => ...` – custom function returning whether the run should finish. ```typescript const agent = new Agent({ ..., toolUseBehavior: 'stop_on_first_tool', }); ``` Note: `toolUseBehavior` only applies to **function tools**. Hosted tools always return to the model for processing. *** ## Related guides [Section titled “Related guides”](#related-guides) * [Models](/openai-agents-js/guides/models) for model selection, stored prompts, and provider configuration. * [Tools](/openai-agents-js/guides/tools) for function tools, hosted tools, MCP, and `agent.asTool()`. * [Agent orchestration](/openai-agents-js/guides/multi-agent) for choosing between managers, handoffs, and code-driven orchestration. * [Handoffs](/openai-agents-js/guides/handoffs) for configuring specialist delegation. * [Running agents](/openai-agents-js/guides/running-agents) for executing turns, streaming, and conversation state. * [Results](/openai-agents-js/guides/results) for `finalOutput`, run items, and resume state. * Explore the full TypeDoc reference under **@openai/agents** in the sidebar. # Configuration > Configure process-wide OpenAI client, transport, tracing, and logging defaults This page covers **SDK-wide defaults** that you usually set once during app startup, such as the default OpenAI client, transport, tracing export key, and debug logging behavior. These settings apply process-wide by default, so this is the right place for universal configuration rather than per-agent or per-run tuning. If you need to configure a specific `Agent`, `Runner`, or `run()` call instead, see: * [Running Agents](/openai-agents-js/guides/running-agents) for `Runner` and per-run options. * [Models](/openai-agents-js/guides/models) for agent-level and runner-level model settings. * [Tracing](/openai-agents-js/guides/tracing) for run-specific tracing configuration and exporter behavior. ## OpenAI client and transport [Section titled “OpenAI client and transport”](#openai-client-and-transport) ### API keys and clients [Section titled “API keys and clients”](#api-keys-and-clients) By default the SDK resolves `OPENAI_API_KEY` lazily when it needs to create an OpenAI client. If setting the environment variable is not possible, call `setDefaultOpenAIKey()` manually. Set default OpenAI key ```typescript import { setDefaultOpenAIKey } from '@openai/agents'; setDefaultOpenAIKey(process.env.OPENAI_API_KEY!); // sk-... ``` You may also pass your own `OpenAI` client instance. The SDK will otherwise create one automatically using the default key. Set default OpenAI client ```typescript import { OpenAI } from 'openai'; import { setDefaultOpenAIClient } from '@openai/agents'; const customClient = new OpenAI({ baseURL: '...', apiKey: '...' }); setDefaultOpenAIClient(customClient); ``` ### API selection [Section titled “API selection”](#api-selection) Finally you can switch between the Responses API and the Chat Completions API. Set OpenAI API ```typescript import { setOpenAIAPI } from '@openai/agents'; setOpenAIAPI('chat_completions'); ``` ### Responses transport [Section titled “Responses transport”](#responses-transport) If you are using the Responses API, you can also choose the OpenAI provider transport. The default is HTTP. Set Responses transport ```typescript import { setOpenAIAPI, setOpenAIResponsesTransport } from '@openai/agents'; setOpenAIAPI('responses'); setOpenAIResponsesTransport('websocket'); ``` Use `setOpenAIResponsesTransport('websocket')` to enable the WebSocket transport and `setOpenAIResponsesTransport('http')` to switch back. If you route websocket traffic through a proxy or gateway, set `OPENAI_WEBSOCKET_BASE_URL` (or configure `websocketBaseURL` on your `OpenAIProvider`). This process-wide default only affects models that are later resolved through the default OpenAI provider. If you pass a concrete `Model` instance or a custom `modelProvider`, configure the transport there instead. See the [Models guide](/openai-agents-js/guides/models#responses-websocket-transport). ## Observability and debugging [Section titled “Observability and debugging”](#observability-and-debugging) ### Tracing [Section titled “Tracing”](#tracing) Tracing is enabled by default in supported server runtimes. It is disabled by default in browsers and when `NODE_ENV=test`. By default trace export uses the same OpenAI key from the section above. A separate key may be set via `setTracingExportApiKey()`: Set tracing export API key ```typescript import { setTracingExportApiKey } from '@openai/agents'; setTracingExportApiKey('sk-...'); ``` Tracing can also be disabled entirely: Disable tracing ```typescript import { setTracingDisabled } from '@openai/agents'; setTracingDisabled(true); ``` If you’d like to learn more about the tracing feature, please check out [Tracing guide](/openai-agents-js/guides/tracing). ### Debug logging [Section titled “Debug logging”](#debug-logging) The SDK uses the [`debug`](https://www.npmjs.com/package/debug) package for debug logging. Set the `DEBUG` environment variable to `openai-agents*` to see verbose logs. ```bash export DEBUG=openai-agents* ``` To log session persistence activity, set `OPENAI_AGENTS__DEBUG_SAVE_SESSION=1`. You can obtain a namespaced logger for your own modules using `getLogger(namespace)` from `@openai/agents`. Get logger ```typescript import { getLogger } from '@openai/agents'; const logger = getLogger('my-app'); logger.debug('something happened'); ``` #### Sensitive data in logs [Section titled “Sensitive data in logs”](#sensitive-data-in-logs) Certain logs may contain user data. Disable them by setting these environment variables. To disable logging LLM inputs and outputs: ```bash export OPENAI_AGENTS_DONT_LOG_MODEL_DATA=1 ``` To disable logging tool inputs and outputs: ```bash export OPENAI_AGENTS_DONT_LOG_TOOL_DATA=1 ``` # Context Management > Learn how to provide local data via RunContext and expose context to the LLM Context is an overloaded term. There are two main classes of context you might care about: 1. **Local context** that your code can access during a run: dependencies or data needed by tools, callbacks like `onHandoff`, and lifecycle hooks. 2. **Agent/LLM context** that the language model can see when generating a response. ## Local context [Section titled “Local context”](#local-context) Local context is represented by the `RunContext` type. You create any object to hold your state or dependencies and pass it to `Runner.run()`. All tool calls and hooks receive a `RunContext` wrapper so they can read from or modify that object. Local context example ```typescript import { Agent, run, RunContext, tool } from '@openai/agents'; import { z } from 'zod'; interface UserInfo { name: string; uid: number; } const fetchUserAge = tool({ name: 'fetch_user_age', description: 'Return the age of the current user', parameters: z.object({}), execute: async ( _args, runContext?: RunContext, ): Promise => { return `User ${runContext?.context.name} is 47 years old`; }, }); async function main() { const userInfo: UserInfo = { name: 'John', uid: 123 }; const agent = new Agent({ name: 'Assistant', tools: [fetchUserAge], }); const result = await run(agent, 'What is the age of the user?', { context: userInfo, }); console.log(result.finalOutput); // The user John is 47 years old. } main().catch((error) => { console.error(error); process.exit(1); }); ``` Every agent, tool and hook participating in a single run must use the same **type** of context. Use local context for things like: * Data about the run (user name, IDs, etc.) * Dependencies such as loggers or data fetchers * Helper functions Note The context object is **not** sent to the LLM. It is purely local and you can read from or write to it freely. Within a single run, derived contexts share the same underlying app context, approvals, and usage tracking. Nested `agent.asTool()` runs may attach a different `toolInput`, but they do not get an isolated copy of your app state by default. ### What `RunContext` exposes [Section titled “What RunContext exposes”](#what-runcontext-exposes) `RunContext` is a wrapper around your app-defined context object. In practice you will most often use: * `runContext.context` for your own mutable app state and dependencies. * `runContext.usage` for the aggregated token/request usage of the current run. * `runContext.toolInput` for structured input when the current run is executing inside `agent.asTool()`. * `runContext.approveTool(...)` / `runContext.rejectTool(...)` when you need to update approval state programmatically. Only `runContext.context` is your app-defined object. The other fields are runtime metadata managed by the SDK. If you later serialize a [`RunState`](/openai-agents-js/guides/results#state) for [human-in-the-loop](/openai-agents-js/guides/human-in-the-loop), that runtime metadata is saved with the state. Avoid putting secrets in `runContext.context` if you intend to persist or transmit serialized state. Note `RunContext` is about local app state for the current run. Conversation state is a separate concern: use `result.history`, `session`, `conversationId`, or `previousResponseId` depending on how you want to carry turns forward. See [Running agents](/openai-agents-js/guides/running-agents#state-and-conversation-management) for that decision. If you subclass `RunContext`, verify that nested or derived runs still preserve any subclass-specific instance state you rely on. The SDK creates forked contexts internally during nested runs. ## Agent/LLM context [Section titled “Agent/LLM context”](#agentllm-context) When the LLM is called, the only data it can see comes from the conversation history. To make additional information available you have a few options: 1. Add it to the Agent `instructions` – also known as a system or developer message. This can be a static string or a function that receives the context and returns a string. 2. Include it in the `input` when calling `Runner.run()`. This is similar to the instructions technique but lets you place the message lower in the [chain of command](https://cdn.openai.com/spec/model-spec-2024-05-08.html#follow-the-chain-of-command). 3. Expose it via function tools so the LLM can fetch data on demand. 4. Use retrieval or web search tools to ground responses in relevant data from files, databases, or the web. # Guardrails > Validate or transform agent input and output Guardrails can run alongside your agents or block execution until they complete, allowing you to perform checks and validations on user input or agent output. For example, you may run a lightweight model as a guardrail before invoking an expensive model. If the guardrail detects malicious usage, it can trigger an error and stop the costly model from running. There are two kinds of guardrails: 1. **Input guardrails** run on the initial user input. 2. **Output guardrails** run on the final agent output. ## Workflow boundaries [Section titled “Workflow boundaries”](#workflow-boundaries) Guardrails are attached to agents, but they do not necessarily run on every agent in a workflow: * **Input guardrails** run only for the first agent in the chain. * **Output guardrails** run only for the agent that produces the final output. * **Tool guardrails** run on every function-tool invocation, with input guardrails before execution and output guardrails after execution. If you need checks around each custom function-tool call in a workflow that includes managers or handoffs, use **tool guardrails** instead of agent-level input/output guardrails. ## Input guardrails [Section titled “Input guardrails”](#input-guardrails) Input guardrails run in three steps: 1. The guardrail receives the same input passed to the agent. 2. The guardrail function executes and returns a [`GuardrailFunctionOutput`](/openai-agents-js/openai/agents/interfaces/guardrailfunctionoutput) wrapped inside an [`InputGuardrailResult`](/openai-agents-js/openai/agents/interfaces/inputguardrailresult). 3. If `tripwireTriggered` is `true`, an [`InputGuardrailTripwireTriggered`](/openai-agents-js/openai/agents/classes/inputguardrailtripwiretriggered) error is thrown. > **Note** Input guardrails are intended for user input, so they only run if the agent is the *first* agent in the workflow. Guardrails are configured on the agent itself because different agents often require different guardrails. ### Execution modes [Section titled “Execution modes”](#execution-modes) * `runInParallel: true` (default) starts guardrails alongside the LLM/tool calls. This minimizes latency but the model may already have consumed tokens or run tools if the guardrail later triggers. * `runInParallel: false` runs the guardrail **before** calling the model, preventing token spend and tool execution when the guardrail blocks the request. Use this when you prefer safety and cost over latency. ## Output guardrails [Section titled “Output guardrails”](#output-guardrails) Output guardrails run in 3 steps: 1. The guardrail receives the output produced by the agent. 2. The guardrail function executes and returns a [`GuardrailFunctionOutput`](/openai-agents-js/openai/agents/interfaces/guardrailfunctionoutput) wrapped inside an [`OutputGuardrailResult`](/openai-agents-js/openai/agents/interfaces/outputguardrailresult). 3. If `tripwireTriggered` is `true`, an [`OutputGuardrailTripwireTriggered`](/openai-agents-js/openai/agents/classes/outputguardrailtripwiretriggered) error is thrown. > **Note** Output guardrails only run if the agent is the *last* agent in the workflow. For realtime voice interactions see [the voice agents guide](/openai-agents-js/guides/voice-agents/build#guardrails). Output guardrail functions also receive an optional `details` object with the underlying `modelResponse` and the generated output items for the turn. Use this when the final output alone is not enough to decide whether the response should pass, for example when you want to inspect the full generated item list or provider response metadata before tripping the guardrail. ## Tool guardrails [Section titled “Tool guardrails”](#tool-guardrails) Tool guardrails wrap **function tools** and let you validate or block tool calls before and after execution. They are configured on the tool itself (via `tool()` options) and run for every invocation of that tool. In practice, this means custom function tools where you set `inputGuardrails` and/or `outputGuardrails` on `tool({...})`. * **Input tool guardrails** run before the tool executes and can reject the call with a message or throw a tripwire. * **Output tool guardrails** run after the tool executes and can replace the output with a rejection message or throw a tripwire. Tool guardrails return a `behavior`: * `allow` — continue to the next guardrail or tool execution. * `rejectContent` — short‑circuit with a message (tool call is skipped or output is replaced). * `throwException` — throw a tripwire error immediately. Tool guardrails apply to function tools you define with `tool()`. Handoffs are presented to the model as function-like tools, but they run through the SDK’s handoff path rather than the normal function-tool pipeline, so tool guardrails do not apply to the handoff call itself. Hosted tools and built-in execution tools (`computerTool`, `shellTool`, `applyPatchTool`) also do not use this guardrail pipeline, and `agent.asTool()` does not currently expose tool-guardrail options directly. ## Tripwires [Section titled “Tripwires”](#tripwires) When a guardrail fails, it signals this via a tripwire. As soon as a tripwire is triggered, the runner throws the corresponding error and halts execution. ## Implementing a guardrail [Section titled “Implementing a guardrail”](#implementing-a-guardrail) A guardrail is simply a function that returns a `GuardrailFunctionOutput`. Below is a minimal example that checks whether the user is asking for math homework help by running another agent under the hood. Input guardrail example ```typescript import { Agent, run, InputGuardrailTripwireTriggered, InputGuardrail, } from '@openai/agents'; import { z } from 'zod'; const guardrailAgent = new Agent({ name: 'Guardrail check', instructions: 'Check if the user is asking you to do their math homework.', outputType: z.object({ isMathHomework: z.boolean(), reasoning: z.string(), }), }); const mathGuardrail: InputGuardrail = { name: 'Math Homework Guardrail', // Set runInParallel to false to block the model until the guardrail completes. runInParallel: false, execute: async ({ input, context }) => { const result = await run(guardrailAgent, input, { context }); return { outputInfo: result.finalOutput, tripwireTriggered: result.finalOutput?.isMathHomework === false, }; }, }; const agent = new Agent({ name: 'Customer support agent', instructions: 'You are a customer support agent. You help customers with their questions.', inputGuardrails: [mathGuardrail], }); async function main() { try { await run(agent, 'Hello, can you help me solve for x: 2x + 3 = 11?'); console.log("Guardrail didn't trip - this is unexpected"); } catch (e) { if (e instanceof InputGuardrailTripwireTriggered) { console.log('Math homework guardrail tripped'); } } } main().catch(console.error); ``` Output guardrails work the same way. Output guardrail example ```typescript import { Agent, run, OutputGuardrailTripwireTriggered, OutputGuardrail, } from '@openai/agents'; import { z } from 'zod'; // The output by the main agent const MessageOutput = z.object({ response: z.string() }); type MessageOutput = z.infer; // The output by the math guardrail agent const MathOutput = z.object({ reasoning: z.string(), isMath: z.boolean() }); // The guardrail agent const guardrailAgent = new Agent({ name: 'Guardrail check', instructions: 'Check if the output includes any math.', outputType: MathOutput, }); // An output guardrail using an agent internally const mathGuardrail: OutputGuardrail = { name: 'Math Guardrail', async execute({ agentOutput, context }) { const result = await run(guardrailAgent, agentOutput.response, { context, }); return { outputInfo: result.finalOutput, tripwireTriggered: result.finalOutput?.isMath ?? false, }; }, }; const agent = new Agent({ name: 'Support agent', instructions: 'You are a user support agent. You help users with their questions.', outputGuardrails: [mathGuardrail], outputType: MessageOutput, }); async function main() { try { const input = 'Hello, can you help me solve for x: 2x + 3 = 11?'; await run(agent, input); console.log("Guardrail didn't trip - this is unexpected"); } catch (e) { if (e instanceof OutputGuardrailTripwireTriggered) { console.log('Math output guardrail tripped'); } } } main().catch(console.error); ``` Tool input/output guardrails look like this: Tool guardrails ```typescript import { Agent, ToolGuardrailFunctionOutputFactory, defineToolInputGuardrail, defineToolOutputGuardrail, tool, } from '@openai/agents'; import { z } from 'zod'; const blockSecrets = defineToolInputGuardrail({ name: 'block_secrets', run: async ({ toolCall }) => { const args = JSON.parse(toolCall.arguments) as { text?: string }; if (args.text?.includes('sk-')) { return ToolGuardrailFunctionOutputFactory.rejectContent( 'Remove secrets before calling this tool.', ); } return ToolGuardrailFunctionOutputFactory.allow(); }, }); const redactOutput = defineToolOutputGuardrail({ name: 'redact_output', run: async ({ output }) => { const text = String(output ?? ''); if (text.includes('sk-')) { return ToolGuardrailFunctionOutputFactory.rejectContent( 'Output contained sensitive data.', ); } return ToolGuardrailFunctionOutputFactory.allow(); }, }); const classifyTool = tool({ name: 'classify_text', description: 'Classify text for internal routing.', parameters: z.object({ text: z.string(), }), inputGuardrails: [blockSecrets], outputGuardrails: [redactOutput], execute: ({ text }) => `length:${text.length}`, }); const agent = new Agent({ name: 'Classifier', instructions: 'Classify incoming text.', tools: [classifyTool], }); ``` 1. `guardrailAgent` is used inside the guardrail functions. 2. The guardrail function receives the agent input or output and returns the result. 3. Extra information can be included in the guardrail result. 4. `agent` defines the actual workflow where guardrails are applied. # Handoffs > Delegate tasks from one agent to another Handoffs let an agent delegate part of a conversation to another agent. This is useful when different agents specialise in specific areas. In a customer support app for example, you might have agents that handle bookings, refunds or FAQs. Handoffs are represented as tools to the LLM. If you hand off to an agent called `Refund Agent`, the tool name would be `transfer_to_refund_agent`. > Read this page after [Agents](/openai-agents-js/guides/agents#composition-patterns) once you know the specialist should take over the conversation. If the specialist should stay behind the original agent, use [agents as tools](/openai-agents-js/guides/tools#4-agents-as-tools) instead. ## Creating a handoff [Section titled “Creating a handoff”](#creating-a-handoff) Every agent accepts a `handoffs` option. It can contain other `Agent` instances or `Handoff` objects returned by the `handoff()` helper. If you pass plain `Agent` instances, their `handoffDescription` (if provided) is appended to the default tool description. Use it to clarify when the model should pick that handoff. ### Basic usage [Section titled “Basic usage”](#basic-usage) Basic handoffs ```typescript import { Agent, handoff } from '@openai/agents'; const billingAgent = new Agent({ name: 'Billing agent' }); const refundAgent = new Agent({ name: 'Refund agent' }); // Use Agent.create method to ensure the finalOutput type considers handoffs const triageAgent = Agent.create({ name: 'Triage agent', handoffs: [billingAgent, handoff(refundAgent)], }); ``` ### Customising handoffs via `handoff()` [Section titled “Customising handoffs via handoff()”](#customising-handoffs-via-handoff) The `handoff()` function lets you tweak the generated tool. * `agent` – the agent to hand off to. * `toolNameOverride` – override the default `transfer_to_` tool name. * `toolDescriptionOverride` – override the default tool description. * `onHandoff` – callback when the handoff occurs. Receives a `RunContext` and, when `inputType` is configured, the parsed handoff payload. * `inputType` – schema for the handoff tool-call arguments. * `inputFilter` – filter the history passed to the next agent. * `isEnabled` – boolean or predicate that exposes the handoff only for matching runs. The `handoff()` helper always transfers control to the specific `agent` you passed in. If you have multiple possible destinations, register one handoff per destination and let the model choose among them. Use a custom `Handoff` when your own handoff code must decide which agent to return at invocation time. Customized handoffs ```typescript import { z } from 'zod'; import { Agent, handoff, RunContext } from '@openai/agents'; const FooSchema = z.object({ foo: z.string() }); function onHandoff(ctx: RunContext, input?: { foo: string }) { console.log('Handoff called with:', input?.foo); } const agent = new Agent({ name: 'My agent' }); const handoffObj = handoff(agent, { onHandoff, inputType: FooSchema, toolNameOverride: 'custom_handoff_tool', toolDescriptionOverride: 'Custom description', }); ``` ## Handoff inputs [Section titled “Handoff inputs”](#handoff-inputs) Sometimes you want the model to attach a small structured payload when it chooses a handoff. Define `inputType` and `onHandoff` together for that case. Handoff inputs ```typescript import { z } from 'zod'; import { Agent, handoff, RunContext } from '@openai/agents'; const EscalationData = z.object({ reason: z.string() }); type EscalationData = z.infer; async function onHandoff( ctx: RunContext, input: EscalationData | undefined, ) { console.log(`Escalation agent called with reason: ${input?.reason}`); } const agent = new Agent({ name: 'Escalation agent' }); const handoffObj = handoff(agent, { onHandoff, inputType: EscalationData, }); ``` `inputType` describes the arguments for the handoff tool call itself. The SDK exposes that schema to the model as the handoff tool’s `parameters`, parses the returned arguments locally, and passes the parsed value to `onHandoff`. It does not replace the next agent’s main input, and it does not choose a different destination. The `handoff()` helper still transfers to the specific agent you wrapped, and the receiving agent still sees the conversation history unless you change it with an `inputFilter`. `inputType` is also separate from `RunContext`. Use it for metadata the model decides at handoff time, not for application state or dependencies you already have locally. ### When to use `inputType` [Section titled “When to use inputType”](#when-to-use-inputtype) Use `inputType` when the handoff needs a small piece of model-generated routing metadata such as `reason`, `language`, `priority`, or `summary`. For example, a triage agent can hand off to a refund agent with `{ reason: 'duplicate_charge', priority: 'high' }`, and `onHandoff` can log or persist that metadata before the refund agent takes over. Choose a different mechanism when the goal is different: * Put existing application state in `RunContext`. * Use `inputFilter` if you want to change what history the receiving agent sees. * Register one handoff per destination if there are multiple possible specialists. `inputType` can add metadata to the chosen handoff, but it does not dispatch between destinations. * Prefer a Zod schema when you want the SDK to validate the parsed payload before `onHandoff` runs; a raw JSON Schema only defines the tool contract sent to the model. ## Input filters [Section titled “Input filters”](#input-filters) By default a handoff receives the entire conversation history. To modify what gets passed to the next agent, provide an `inputFilter`. Common helpers live in `@openai/agents-core/extensions`. Input filters ```typescript import { Agent, handoff } from '@openai/agents'; import { removeAllTools } from '@openai/agents-core/extensions'; const agent = new Agent({ name: 'FAQ agent' }); const handoffObj = handoff(agent, { inputFilter: removeAllTools, }); ``` An `inputFilter` receives and returns a `HandoffInputData` object: * `inputHistory` – the input history before the run started. * `preHandoffItems` – items generated before the turn where the handoff happened. * `newItems` – items generated during the current turn, including the handoff call/output items. * `runContext` – the active run context. If you also configure `handoffInputFilter` on the `Runner`, the per-handoff `inputFilter` takes precedence for that specific handoff. Note Handoffs stay within a single run. Input guardrails still apply only to the first agent in the chain, and output guardrails only to the agent that produces the final output. Use tool guardrails when you need checks around each custom function-tool call inside the workflow. ## Recommended prompts [Section titled “Recommended prompts”](#recommended-prompts) LLMs respond more reliably when your prompts mention handoffs. The SDK exposes a recommended prefix via `RECOMMENDED_PROMPT_PREFIX`. Recommended prompts ```typescript import { Agent } from '@openai/agents'; import { RECOMMENDED_PROMPT_PREFIX } from '@openai/agents-core/extensions'; const billingAgent = new Agent({ name: 'Billing agent', instructions: `${RECOMMENDED_PROMPT_PREFIX} Fill in the rest of your prompt here.`, }); ``` ## Related guides [Section titled “Related guides”](#related-guides) * [Agents](/openai-agents-js/guides/agents#composition-patterns) for choosing between managers and handoffs. * [Agent orchestration](/openai-agents-js/guides/multi-agent) for the broader workflow tradeoffs. * [Tools](/openai-agents-js/guides/tools#4-agents-as-tools) for the manager-style alternative using `agent.asTool()`. * [Running agents](/openai-agents-js/guides/running-agents) for how handoffs behave at run time. * [Results](/openai-agents-js/guides/results#final-output) for typed `finalOutput` across handoff graphs. # Human-in-the-loop > Add a human in the loop check for your agent executions This guide covers the SDK’s approval-based human-in-the-loop flow. When a tool call requires approval, the SDK pauses the run, returns `interruptions`, and lets you resume later from the same `RunState`. That approval surface is run-wide, not limited to the current top-level agent. The same pattern applies when the tool belongs to the current agent, to an agent reached through a handoff, or to a nested `agent.asTool()` execution. In the nested `agent.asTool()` case, the interruption still surfaces on the outer run, so you approve or reject it on the outer `result.state` and resume the original root run. With `agent.asTool()`, approvals can happen at two different layers: the agent tool itself can require approval via `asTool({ needsApproval })`, and tools inside the nested agent can later raise their own approvals after the nested run starts. Both are handled through the same outer-run interruption flow. This page focuses on the manual approval flow via `interruptions`. If your app can decide in code, some tool types also support programmatic approval callbacks so the run can continue without pausing. If you are setting up `agent.asTool()` itself, see the [tools guide](/openai-agents-js/guides/tools#4-agents-as-tools); this page covers what happens once any tool in that run hierarchy needs approval. ## Approval flow [Section titled “Approval flow”](#approval-flow) You can define a tool that requires approval by setting the `needsApproval` option to `true` or to an async function that returns a boolean. Tool approval definition ```typescript import { tool } from '@openai/agents'; import z from 'zod'; const sensitiveTool = tool({ name: 'cancelOrder', description: 'Cancel order', parameters: z.object({ orderId: z.number(), }), // always requires approval needsApproval: true, execute: async ({ orderId }, args) => { // prepare order return }, }); const sendEmail = tool({ name: 'sendEmail', description: 'Send an email', parameters: z.object({ to: z.string(), subject: z.string(), body: z.string(), }), needsApproval: async (_context, { subject }) => { // check if the email is spam return subject.includes('spam'); }, execute: async ({ to, subject, body }, args) => { // send email }, }); ``` ### Flow [Section titled “Flow”](#flow) 1. When a tool invocation is about to execute, the SDK evaluates its approval rule (`needsApproval` or the hosted MCP equivalent). 2. If approval is required and no decision is stored yet, the tool call does not execute. Instead, the run records a [`RunToolApprovalItem`](/openai-agents-js/openai/agents/classes/runtoolapprovalitem). 3. At the end of that turn, the run pauses and returns all pending approvals in the [result](/openai-agents-js/guides/results) `interruptions` array. This includes approvals raised inside nested `agent.asTool()` runs. 4. Resolve each pending item with `result.state.approve(interruption)` or `result.state.reject(interruption)`. Pass `{ alwaysApprove: true }` or `{ alwaysReject: true }` if the same tool should stay approved or rejected for the rest of the run. When rejecting, you can also pass `{ message: '...' }` to control the rejection text that is sent back to the model for that specific tool call. 5. Resume by passing the updated `result.state` back into `runner.run(agent, state)`, where `agent` is the original top-level agent for the run. The SDK continues from the interrupted point, including nested agent-tool executions. Sticky decisions created with `{ alwaysApprove: true }` or `{ alwaysReject: true }` are stored in the run state, so they survive `toString()` / `fromString()` when you resume the same paused run later. Computer tool interruptions can represent a batch of actions in one `computer_call` on GA models. The SDK evaluates `needsApproval` per action before execution, so one pending approval can cover a sequence such as move + click. If you inspect `interruption.rawItem` to render a UI, handle both the GA `actions` array and the legacy single `action` field. Serialized `RunState` also preserves computer approvals across both the current `computer` tool name and the legacy `computer_use_preview` name, so paused runs can resume cleanly during preview-to-GA migrations. If you do not provide `message`, the SDK falls back to the configured `toolErrorFormatter` (if any) and then to the default rejection text. You do not need to resolve every pending approval in the same pass. If you rerun after approving or rejecting only some items, those resolved calls can continue while unresolved ones remain in `interruptions` and pause the run again. ### Automatic approval decisions [Section titled “Automatic approval decisions”](#automatic-approval-decisions) Manual `interruptions` are the most general pattern, but they are not the only one: * Local `shellTool()` and `applyPatchTool()` can use `onApproval` to approve or reject immediately in code. * Hosted MCP tools can use `requireApproval` together with `onApproval` for the same kind of programmatic decision. * Plain function tools use the manual interruption flow on this page. When these callbacks return a decision, the run continues without pausing for a human response. For Realtime / voice session APIs, see the approval flow in the [voice agents build guide](/openai-agents-js/guides/voice-agents/build#approval-requests). ### Streaming and sessions [Section titled “Streaming and sessions”](#streaming-and-sessions) The same interruption flow works in streaming runs. After a streamed run pauses, wait for `stream.completed`, read `stream.interruptions`, resolve them, and call `run()` again with `{ stream: true }` if you want the resumed output to keep streaming. See [Human in the loop while streaming](/openai-agents-js/guides/streaming#human-in-the-loop-while-streaming) for the streamed version of this pattern. If you are also using a `session`, keep passing the same `session` when you resume from `RunState`. The resumed turn is then appended to session memory without re-preparing the input. See the [sessions guide](/openai-agents-js/guides/sessions) for the session lifecycle details. ## Example [Section titled “Example”](#example) Below is a more complete example of a human-in-the-loop flow that prompts for approval in the terminal and temporarily stores the state in a file. Human in the loop ```typescript import { z } from 'zod'; import readline from 'node:readline/promises'; import fs from 'node:fs/promises'; import { Agent, run, tool, RunState, RunResult } from '@openai/agents'; const getWeatherTool = tool({ name: 'get_weather', description: 'Get the weather for a given city', parameters: z.object({ location: z.string(), }), needsApproval: async (_context, { location }) => { // forces approval to look up the weather in San Francisco return location === 'San Francisco'; }, execute: async ({ location }) => { return `The weather in ${location} is sunny`; }, }); const dataAgentTwo = new Agent({ name: 'Data agent', instructions: 'You are a data agent', handoffDescription: 'You know everything about the weather', tools: [getWeatherTool], }); const agent = new Agent({ name: 'Basic test agent', instructions: 'You are a basic agent', handoffs: [dataAgentTwo], }); async function confirm(question: string) { const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); const answer = await rl.question(`${question} (y/n): `); const normalizedAnswer = answer.toLowerCase(); rl.close(); return normalizedAnswer === 'y' || normalizedAnswer === 'yes'; } async function main() { let result: RunResult> = await run( agent, 'What is the weather in Oakland and San Francisco?', ); let hasInterruptions = result.interruptions?.length > 0; while (hasInterruptions) { // storing await fs.writeFile( 'result.json', JSON.stringify(result.state, null, 2), 'utf-8', ); // from here on you could run things on a different thread/process // reading later on const storedState = await fs.readFile('result.json', 'utf-8'); const state = await RunState.fromString(agent, storedState); for (const interruption of result.interruptions) { const confirmed = await confirm( `Agent ${interruption.agent.name} would like to use the tool ${interruption.name} with "${interruption.arguments}". Do you approve?`, ); if (confirmed) { state.approve(interruption); } else { state.reject(interruption); } } // resume execution of the current state result = await run(agent, state); hasInterruptions = result.interruptions?.length > 0; } console.log(result.finalOutput); } main().catch((error) => { console.dir(error, { depth: null }); }); ``` See [the full example script](https://github.com/openai/openai-agents-js/tree/main/examples/agent-patterns/human-in-the-loop.ts) for a working end-to-end version. ## Dealing with longer approval times [Section titled “Dealing with longer approval times”](#dealing-with-longer-approval-times) The human-in-the-loop flow is designed to be interruptible for longer periods of time without keeping your server running. If you need to shut down the request and continue later on you can serialize the state and resume later. You can serialize the state using `result.state.toString()` (or `JSON.stringify(result.state)`) and resume later on by passing the serialized state into `RunState.fromString(agent, serializedState)` where `agent` is the instance of the agent that triggered the overall run. When `RunState` is serialized, the SDK records stable agent identities for the handoff and `Agent.asTool()` graph. This lets paused runs resume even when distinct agents share the same `name`, as long as the process that resumes the run rebuilds the same agent graph. If the resumed process needs to inject a fresh context object, use `RunState.fromStringWithContext(agent, serializedState, context, { contextStrategy })` instead. * `contextStrategy: 'merge'` (default) keeps the provided `RunContext`, merges in the serialized approval state, and restores serialized `toolInput` when the new context does not already define one. * `contextStrategy: 'replace'` rebuilds the run using the provided `RunContext` as-is. Serialized run state includes your app context plus SDK-managed runtime metadata such as approvals, usage, nested `toolInput`, and pending nested agent-tool resumptions. If you plan to store or transmit serialized state, treat `runContext.context` as persisted data and avoid placing secrets there unless you intentionally want them to travel with the state. By default tracing API keys are omitted from serialized state so you do not accidentally persist secrets. Pass `result.state.toString({ includeTracingApiKey: true })` only when you intentionally need to move tracing credentials with the state. That way you can store your serialized state in a database, or along with your request. ### Versioning pending tasks [Section titled “Versioning pending tasks”](#versioning-pending-tasks) Note This primarily applies if you are trying to store your serialized state for a longer time while doing changes to your agents. If your approval requests take a longer time and you intend to version your agent definitions in a meaningful way or bump your Agents SDK version, we currently recommend for you to implement your own branching logic by installing two versions of the Agents SDK in parallel using package aliases. In practice this means assigning your own code a version number and storing it along with the serialized state and guiding the deserialization to the correct version of your code. # Model Context Protocol (MCP) > Learn how to utilize MCP servers as tools The [**Model Context Protocol (MCP)**](https://modelcontextprotocol.io) is an open protocol that standardizes how applications provide tools and context to LLMs. From the MCP docs: > MCP is an open protocol that standardizes how applications provide context to LLMs. Think of MCP like a USB-C port for AI applications. Just as USB-C provides a standardized way to connect your devices to various peripherals and accessories, MCP provides a standardized way to connect AI models to different data sources and tools. There are three types of MCP servers this SDK supports: 1. **Hosted MCP server tools** – remote MCP servers used as tools by the [OpenAI Responses API](https://platform.openai.com/docs/guides/tools-remote-mcp) 2. **Streamable HTTP MCP servers** – local or remote servers that implement the [Streamable HTTP transport](https://modelcontextprotocol.io/docs/concepts/transports#streamable-http) 3. **Stdio MCP servers** – servers accessed via standard input/output (the simplest option) > Note: The SDK also includes `MCPServerSSE` for legacy Server‑Sent Events transports, but SSE has been deprecated by the MCP project. Prefer Streamable HTTP or stdio for new integrations. Choose a server type based on your use‑case: | What you need | Recommended option | | -------------------------------------------------------------------------------- | ----------------------- | | Call publicly accessible remote servers with default OpenAI responses models | **1. Hosted MCP tools** | | Use publicly accessible remote servers but have the tool calls triggered locally | **2. Streamable HTTP** | | Use locally running Streamable HTTP servers | **2. Streamable HTTP** | | Use any Streamable HTTP servers with non-OpenAI-Responses models | **2. Streamable HTTP** | | Work with local MCP servers that only support the standard-I/O protocol | **3. Stdio** | ## 1. Hosted MCP server tools [Section titled “1. Hosted MCP server tools”](#1-hosted-mcp-server-tools) Hosted tools push the entire round‑trip into the model. Instead of your code calling an MCP server, the OpenAI Responses API invokes the remote tool endpoint and streams the result back to the model. Here is the simplest example of using hosted MCP tools. You can pass the remote MCP server’s label and URL to the `hostedMcpTool` utility function, which is helpful for creating hosted MCP server tools. hostedAgent.ts ```typescript import { Agent, hostedMcpTool } from '@openai/agents'; export const agent = new Agent({ name: 'MCP Assistant', instructions: 'You must always use the MCP tools to answer questions.', tools: [ hostedMcpTool({ serverLabel: 'deepwiki', serverUrl: 'https://mcp.deepwiki.com/mcp', }), ], }); ``` Then, you can run the Agent with the `run` function (or your own customized `Runner` instance’s `run` method): Run with hosted MCP tools ```typescript import { run } from '@openai/agents'; import { agent } from './hostedAgent'; async function main() { const result = await run( agent, 'Which language is the repo I pointed in the MCP tool settings written in?', ); console.log(result.finalOutput); } main().catch(console.error); ``` To stream incremental MCP results, pass `stream: true` when you run the `Agent`: Run with hosted MCP tools (streaming) ```typescript import { isOpenAIResponsesRawModelStreamEvent, run } from '@openai/agents'; import { agent } from './hostedAgent'; async function main() { const result = await run( agent, 'Which language is the repo I pointed in the MCP tool settings written in?', { stream: true }, ); for await (const event of result) { if ( isOpenAIResponsesRawModelStreamEvent(event) && event.data.event.type !== 'response.mcp_call_arguments.delta' && event.data.event.type !== 'response.output_text.delta' ) { console.log(`Got event of type ${JSON.stringify(event.data)}`); } } console.log(`Done streaming; final result: ${result.finalOutput}`); } main().catch(console.error); ``` ### Optional approval flow [Section titled “Optional approval flow”](#optional-approval-flow) For sensitive operations you can require human approval of individual tool calls. Pass either `requireApproval: 'always'` or a fine‑grained object mapping tool names to `'never'`/`'always'`. If you can programmatically determine whether a tool call is safe, you can use the [`onApproval` callback](https://github.com/openai/openai-agents-js/blob/main/examples/mcp/hosted-mcp-on-approval.ts) to approve or reject the tool call. If you require human approval, you can use the same [human-in-the-loop (HITL) approach](/openai-agents-js/guides/human-in-the-loop/) using `interruptions` as for local function tools. Human in the loop with hosted MCP tools ```typescript import { Agent, run, hostedMcpTool, RunToolApprovalItem } from '@openai/agents'; async function main(): Promise { const agent = new Agent({ name: 'MCP Assistant', instructions: 'You must always use the MCP tools to answer questions.', tools: [ hostedMcpTool({ serverLabel: 'deepwiki', serverUrl: 'https://mcp.deepwiki.com/mcp', // 'always' | 'never' | { never, always } requireApproval: { never: { toolNames: ['read_wiki_structure', 'read_wiki_contents'], }, always: { toolNames: ['ask_question'], }, }, }), ], }); let result = await run( agent, 'For the repository openai/codex, tell me the primary programming language.', ); while (result.interruptions && result.interruptions.length) { for (const interruption of result.interruptions) { // Human in the loop here const approval = await confirm(interruption); if (approval) { result.state.approve(interruption); } else { result.state.reject(interruption); } } result = await run(agent, result.state); } console.log(result.finalOutput); } import { stdin, stdout } from 'node:process'; import * as readline from 'node:readline/promises'; async function confirm(item: RunToolApprovalItem): Promise { const rl = readline.createInterface({ input: stdin, output: stdout }); const name = item.name; const params = item.arguments; const answer = await rl.question( `Approve running tool (mcp: ${name}, params: ${params})? (y/n) `, ); rl.close(); return answer.toLowerCase().trim() === 'y'; } main().catch(console.error); ``` ### Hosted MCP options reference [Section titled “Hosted MCP options reference”](#hosted-mcp-options-reference) `hostedMcpTool(...)` supports both MCP server URLs and connector-backed servers: | Option | Type | Notes | | ----------------- | ------------------------------- | ------------------------------------------------------------------------------------------------------------- | | `serverLabel` | `string` | Required label that identifies the hosted MCP server in events and traces. | | `serverUrl` | `string` | Remote MCP server URL (use this for regular hosted MCP servers). | | `connectorId` | `string` | OpenAI connector id (use this instead of `serverUrl` for connector-backed hosted servers). | | `authorization` | `string` | Optional authorization token sent to the hosted MCP backend. | | `headers` | `Record` | Optional extra request headers. | | `allowedTools` | `string[] \| object` | Allowlist of tool names exposed to the model. Pass `string[]` or `{ toolNames?: string[] }`. | | `deferLoading` | `boolean` | Responses-only deferred loading for hosted MCP tools. Requires `toolSearchTool()` in the same agent. | | `requireApproval` | `'never' \| 'always' \| object` | Approval policy for hosted MCP tool calls. Use the object form for per-tool overrides. Defaults to `'never'`. | | `onApproval` | Approval callback | Optional callback for programmatic approval/rejection when `requireApproval` requires approval handling. | Set `deferLoading: true` when you want the model to load a hosted MCP server’s tool definitions on demand via tool search instead of exposing them up front. This only works with the OpenAI Responses API, requires `toolSearchTool()` in the same request, and should be used with GPT-5.4 and newer supported model releases. See the [Tools guide](/openai-agents-js/guides/tools#deferred-tool-loading-with-tool-search) for the full deferred-loading setup. `requireApproval` object form: ```ts { always?: { toolNames: string[] }; never?: { toolNames: string[] }; } ``` `onApproval` signature: ```ts async function onApproval( context, item, ): Promise<{ approve: boolean; reason?: string; }> {} ``` ### Connector-backed hosted servers [Section titled “Connector-backed hosted servers”](#connector-backed-hosted-servers) Hosted MCP also supports OpenAI connectors. Instead of providing a `serverUrl`, pass the connector’s `connectorId` and an `authorization` token. The Responses API then handles authentication and exposes the connector’s tools through the hosted MCP interface. Connector-backed hosted MCP tool ```typescript import { Agent, hostedMcpTool } from '@openai/agents'; const authorization = process.env.GOOGLE_CALENDAR_AUTHORIZATION!; export const connectorAgent = new Agent({ name: 'Calendar Assistant', instructions: "You are a helpful assistant that can answer questions about the user's calendar.", tools: [ hostedMcpTool({ serverLabel: 'google_calendar', connectorId: 'connector_googlecalendar', authorization, requireApproval: 'never', }), ], }); ``` In this example the `GOOGLE_CALENDAR_AUTHORIZATION` environment variable holds an OAuth token obtained from the Google OAuth Playground, which authorizes the connector-backed server to call the Calendar API. For a runnable sample that also demonstrates streaming, see [`examples/connectors`](https://github.com/openai/openai-agents-js/tree/main/examples/connectors). Fully working samples (Hosted tools/Streamable HTTP/stdio + Streaming, HITL, onApproval) are [examples/mcp](https://github.com/openai/openai-agents-js/tree/main/examples/mcp) in our GitHub repository. ## Agent-level MCP configuration [Section titled “Agent-level MCP configuration”](#agent-level-mcp-configuration) In addition to choosing a transport, you can tune how local MCP tools are prepared by setting `Agent.mcpConfig`. ```ts const agent = new Agent({ name: 'Assistant', mcpServers: [server], mcpConfig: { // Try to convert MCP tool schemas to strict JSON schema. convertSchemasToStrict: true, // Set to null to raise MCP tool failures instead of returning model-visible error text. errorFunction: null, // Prefix local MCP tool names with their server name. includeServerInToolNames: true, }, }); ``` Notes: * `convertSchemasToStrict` is best-effort. If a schema cannot be converted, the original schema is used. * `errorFunction` controls how MCP tool call failures are surfaced to the model. * When `errorFunction` is unset, the SDK uses the default tool error formatter. * Server-level `errorFunction` values override `Agent.mcpConfig.errorFunction` for that server. * `includeServerInToolNames` is opt-in. When enabled, each local MCP tool is exposed to the model with a deterministic server-prefixed name, which helps avoid collisions when multiple MCP servers publish tools with the same name. ## 2. Streamable HTTP MCP servers [Section titled “2. Streamable HTTP MCP servers”](#2-streamable-http-mcp-servers) When your Agent talks directly to a Streamable HTTP MCP server—local or remote—instantiate `MCPServerStreamableHttp` with the server `url`, `name`, and any optional settings: Run with Streamable HTTP MCP servers ```typescript import { Agent, run, MCPServerStreamableHttp } from '@openai/agents'; async function main() { const mcpServer = new MCPServerStreamableHttp({ url: 'https://mcp.deepwiki.com/mcp', name: 'DeepWiki MCP Server', }); const agent = new Agent({ name: 'DeepWiki Assistant', instructions: 'Use the tools to respond to user requests.', mcpServers: [mcpServer], }); try { await mcpServer.connect(); const result = await run( agent, 'For the repository openai/codex, tell me the primary programming language.', ); console.log(result.finalOutput); } finally { await mcpServer.close(); } } main().catch(console.error); ``` Constructor options: | Option | Type | Notes | | ----------------------------- | ---------------------------------------------- | -------------------------------------------- | | `url` | `string` | Streamable HTTP server URL. | | `name` | `string` | Optional label for the server. | | `cacheToolsList` | `boolean` | Cache tools list to reduce latency. | | `clientSessionTimeoutSeconds` | `number` | Timeout for MCP client sessions. | | `toolFilter` | `MCPToolFilterCallable \| MCPToolFilterStatic` | Filter available tools. | | `toolMetaResolver` | `MCPToolMetaResolver` | Inject per-call MCP `_meta` request fields. | | `errorFunction` | `MCPToolErrorFunction \| null` | Map MCP call failures to model-visible text. | | `timeout` | `number` | Per-request timeout (milliseconds). | | `logger` | `Logger` | Custom logger. | | `authProvider` | `OAuthClientProvider` | OAuth provider from the MCP TypeScript SDK. | | `requestInit` | `RequestInit` | Fetch init options for requests. | | `fetch` | `FetchLike` | Custom fetch implementation. | | `reconnectionOptions` | `StreamableHTTPReconnectionOptions` | Reconnection tuning options. | | `sessionId` | `string` | Explicit session id for MCP connections. | The constructor also accepts additional MCP TypeScript‑SDK options such as `authProvider`, `requestInit`, `fetch`, `reconnectionOptions`, and `sessionId`. See the [MCP TypeScript SDK repository](https://github.com/modelcontextprotocol/typescript-sdk) and its documents for details. ## 3. Stdio MCP servers [Section titled “3. Stdio MCP servers”](#3-stdio-mcp-servers) For servers that expose only standard I/O, instantiate `MCPServerStdio` with a `fullCommand`: Run with Stdio MCP servers ```typescript import { Agent, run, MCPServerStdio } from '@openai/agents'; import * as path from 'node:path'; async function main() { const samplesDir = path.join(__dirname, 'sample_files'); const mcpServer = new MCPServerStdio({ name: 'Filesystem MCP Server, via local package', fullCommand: `pnpm exec mcp-server-filesystem ${samplesDir}`, }); await mcpServer.connect(); try { const agent = new Agent({ name: 'FS MCP Assistant', instructions: 'Use the tools to read the filesystem and answer questions based on those files. If you are unable to find any files, you can say so instead of assuming they exist.', mcpServers: [mcpServer], }); const result = await run(agent, 'Read the files and list them.'); console.log(result.finalOutput); } finally { await mcpServer.close(); } } main().catch(console.error); ``` Constructor options: | Option | Type | Notes | | ----------------------------- | ---------------------------------------------- | ------------------------------------------------------ | | `command` / `args` | `string` / `string[]` | Command + args for stdio servers. | | `fullCommand` | `string` | Full command string alternative to `command` + `args`. | | `env` | `Record` | Environment variables for the server process. | | `cwd` | `string` | Working directory for the server process. | | `cacheToolsList` | `boolean` | Cache tools list to reduce latency. | | `clientSessionTimeoutSeconds` | `number` | Timeout for MCP client sessions. | | `name` | `string` | Optional label for the server. | | `encoding` | `string` | Encoding for stdio streams. | | `encodingErrorHandler` | `'strict' \| 'ignore' \| 'replace'` | Encoding error strategy. | | `toolFilter` | `MCPToolFilterCallable \| MCPToolFilterStatic` | Filter available tools. | | `toolMetaResolver` | `MCPToolMetaResolver` | Inject per-call MCP `_meta` request fields. | | `errorFunction` | `MCPToolErrorFunction \| null` | Map MCP call failures to model-visible text. | | `timeout` | `number` | Per-request timeout (milliseconds). | | `logger` | `Logger` | Custom logger. | ## Managing MCP server lifecycle [Section titled “Managing MCP server lifecycle”](#managing-mcp-server-lifecycle) When you work with multiple MCP servers, you can use `connectMcpServers` to connect them together, track failures, and close them in one place. The helper returns an `MCPServers` instance with `active`, `failed`, and `errors` collections so you can pass only healthy servers to your agent. Manage multiple MCP servers ```typescript import { Agent, MCPServerStreamableHttp, connectMcpServers, run, } from '@openai/agents'; async function main() { const servers = [ new MCPServerStreamableHttp({ url: 'https://mcp.deepwiki.com/mcp', name: 'DeepWiki MCP Server', }), new MCPServerStreamableHttp({ url: 'http://localhost:8001/mcp', name: 'Local MCP Server', }), ]; const mcpServers = await connectMcpServers(servers, { connectInParallel: true, }); try { console.log(`Active servers: ${mcpServers.active.length}`); console.log(`Failed servers: ${mcpServers.failed.length}`); for (const [server, error] of mcpServers.errors) { console.warn(`${server.name} failed to connect: ${error.message}`); } const agent = new Agent({ name: 'MCP lifecycle agent', instructions: 'Use MCP tools to answer user questions.', mcpServers: mcpServers.active, }); const result = await run( agent, 'Which language is the openai/codex repository written in?', ); console.log(result.finalOutput); } finally { await mcpServers.close(); } } main().catch(console.error); ``` Use cases: * **Multiple servers at once**: connect everything in parallel and use `mcpServers.active` for the agent. * **Partial failure handling**: inspect `failed` + `errors` and decide whether to continue or retry. * **Retry failed servers**: call `mcpServers.reconnect()` (defaults to retrying failed servers only). If you want a strict “all or nothing” connection or different timeouts, use `connectMcpServers(servers, options)` and tune the options for your environment. `connectMcpServers` options: | Option | Type | Default | Notes | | -------------------- | ---------------- | ------- | ------------------------------------------------------------- | | `connectTimeoutMs` | `number \| null` | `10000` | Timeout for each server `connect()`. Use `null` to disable. | | `closeTimeoutMs` | `number \| null` | `10000` | Timeout for each server `close()`. Use `null` to disable. | | `dropFailed` | `boolean` | `true` | Exclude failed servers from `active`. | | `strict` | `boolean` | `false` | Throw if any server fails to connect. | | `suppressAbortError` | `boolean` | `true` | Ignore abort-like errors while still tracking failed servers. | | `connectInParallel` | `boolean` | `false` | Connect all servers concurrently instead of sequentially. | `mcpServers.reconnect(options)` supports: | Option | Type | Default | Notes | | ------------ | --------- | ------- | ---------------------------------------------------------------------- | | `failedOnly` | `boolean` | `true` | Retry only failed servers (`true`) or reconnect all servers (`false`). | ### Async disposal (optional) [Section titled “Async disposal (optional)”](#async-disposal-optional) If your runtime supports `Symbol.asyncDispose`, `MCPServers` also supports the `await using` pattern. In TypeScript, enable `esnext.disposable` in `tsconfig.json`: ```json { "compilerOptions": { "lib": ["ES2018", "DOM", "esnext.disposable"] } } ``` Then you can write: ```ts await using mcpServers = await connectMcpServers(servers); ``` ## Other things to know [Section titled “Other things to know”](#other-things-to-know) For **Streamable HTTP** and **Stdio** servers, each time an `Agent` runs it may call `list_tools()` to discover available tools. Because that round‑trip can add latency—especially to remote servers—you can cache the results in memory by passing `cacheToolsList: true` to `MCPServerStdio` or `MCPServerStreamableHttp`. Only enable this if you’re confident the tool list won’t change. To invalidate the cache later, call `invalidateToolsCache()` on the server instance. If you are using shared MCP tool caching via `getAllMcpTools(...)`, you can also invalidate by server name with `invalidateServerToolsCache(serverName)`. For advanced cases, `getAllMcpTools({ generateMCPToolCacheKey })` lets you customize cache partitioning (for example, by server + agent + run context). ### Server-prefixed tool names [Section titled “Server-prefixed tool names”](#server-prefixed-tool-names) By default, local MCP tools keep the tool name reported by the MCP server. If two local MCP servers expose the same tool name, the SDK raises a duplicate tool name error because the model cannot safely choose between them. To opt in to deterministic server-prefixed names, set `mcpConfig.includeServerInToolNames: true` on the agent: ```ts const agent = new Agent({ name: 'Assistant', mcpServers: [docsServer, calendarServer], mcpConfig: { includeServerInToolNames: true, }, }); ``` With this setting, a `search` tool from a `docs` server is exposed to the model as `mcp_docs__search`, while a `search` tool from a `calendar` server is exposed as `mcp_calendar__search`. The SDK still invokes the original MCP tool name on the original server. Generated names are ASCII-safe, stay within the function-tool name limit, and avoid local function tool names and enabled handoff names on the same agent. The setting only affects local Streamable HTTP and stdio MCP tools; hosted MCP tools keep their hosted server labels and tool metadata. ### Tool filtering [Section titled “Tool filtering”](#tool-filtering) You can restrict which tools are exposed from each server by passing either a static filter via `createMCPToolStaticFilter` or a custom function. Here’s a combined example showing both approaches: Tool filtering ```typescript import { MCPServerStdio, MCPServerStreamableHttp, createMCPToolStaticFilter, MCPToolFilterContext, } from '@openai/agents'; interface ToolFilterContext { allowAll: boolean; } const server = new MCPServerStdio({ fullCommand: 'my-server', toolFilter: createMCPToolStaticFilter({ allowed: ['safe_tool'], blocked: ['danger_tool'], }), }); const dynamicServer = new MCPServerStreamableHttp({ url: 'http://localhost:3000', toolFilter: async ({ runContext }: MCPToolFilterContext, tool) => (runContext.context as ToolFilterContext).allowAll || tool.name !== 'admin', }); ``` ## Further reading [Section titled “Further reading”](#further-reading) * [Model Context Protocol](https://modelcontextprotocol.io/) – official specification. * [examples/mcp](https://github.com/openai/openai-agents-js/tree/main/examples/mcp) – runnable demos referenced above. # Models > Choose and configure language models for your agents Every Agent ultimately calls an LLM. The SDK abstracts models behind two lightweight interfaces: * [`Model`](/openai-agents-js/openai/agents/interfaces/model) – knows how to make *one* request against a specific API. * [`ModelProvider`](/openai-agents-js/openai/agents/interfaces/modelprovider) – resolves human‑readable model **names** (e.g. `'gpt‑5.4'`) to `Model` instances. In day‑to‑day work you normally only interact with model **names** and occasionally `ModelSettings`. Specifying a model per‑agent ```typescript import { Agent } from '@openai/agents'; const agent = new Agent({ name: 'Creative writer', model: 'gpt-5.4', }); ``` ## Choosing models [Section titled “Choosing models”](#choosing-models) ### Default model [Section titled “Default model”](#default-model) When you don’t specify a model when initializing an `Agent`, the default model will be used. The default is currently [`gpt-5.4-mini`](https://developers.openai.com/api/docs/models/gpt-5.4-mini) with `reasoning.effort: "none"` and `text.verbosity: "low"` for a balance of quality and latency. If you want to switch to another model like [`gpt-5.5`](https://developers.openai.com/api/docs/models/gpt-5.5), there are two ways to configure your agents. First, if you want to consistently use a specific model for all agents that do not set a custom model, set the `OPENAI_DEFAULT_MODEL` environment variable before running your agents. ```bash export OPENAI_DEFAULT_MODEL=gpt-5.5 node my-awesome-agent.js ``` Second, you can set a default model for a `Runner` instance. If you don’t set a model for an agent, this `Runner`’s default model will be used. Set a default model for a Runner ```typescript import { Runner } from '@openai/agents'; const runner = new Runner({ model: 'gpt‑4.1-mini' }); ``` #### GPT-5.x models [Section titled “GPT-5.x models”](#gpt-5x-models) When you use any GPT-5.x model such as [`gpt-5.4`](https://developers.openai.com/api/docs/models/gpt-5.4) in this way, the SDK applies default `modelSettings`. It sets the ones that work the best for most use cases. To adjust the reasoning effort for the default model, pass your own `modelSettings`: Customize GPT-5 default settings ```typescript import { Agent } from '@openai/agents'; const myAgent = new Agent({ name: 'My Agent', instructions: "You're a helpful agent.", // If OPENAI_DEFAULT_MODEL=gpt-5.4 is set, passing only modelSettings works. // It's also fine to pass a GPT-5.x model name explicitly: model: 'gpt-5.4', modelSettings: { reasoning: { effort: 'high' }, text: { verbosity: 'low' }, }, }); ``` If latency matters, start with the default `gpt-5.4-mini` configuration or use `reasoning.effort: "none"` on another GPT-5.x model, then increase reasoning effort only if your task needs more deliberate reasoning. #### Non-GPT-5 models [Section titled “Non-GPT-5 models”](#non-gpt-5-models) If you pass a non–GPT-5 model name without custom `modelSettings`, the SDK reverts to generic `modelSettings` compatible with any model. *** ## OpenAI provider configuration [Section titled “OpenAI provider configuration”](#openai-provider-configuration) ### The OpenAI provider [Section titled “The OpenAI provider”](#the-openai-provider) The default `ModelProvider` resolves names using the OpenAI APIs. It supports two distinct endpoints: | API | Usage | Call `setOpenAIAPI()` | | ---------------- | ----------------------------------------------------------------- | --------------------------------------- | | Chat Completions | Standard chat & function calls | `setOpenAIAPI('chat_completions')` | | Responses | New streaming‑first generative API (tool calls, flexible outputs) | `setOpenAIAPI('responses')` *(default)* | #### Authentication [Section titled “Authentication”](#authentication) Set default OpenAI key ```typescript import { setDefaultOpenAIKey } from '@openai/agents'; setDefaultOpenAIKey(process.env.OPENAI_API_KEY!); // sk-... ``` You can also plug your own `OpenAI` client via `setDefaultOpenAIClient(client)` if you need custom networking settings. #### Responses WebSocket transport [Section titled “Responses WebSocket transport”](#responses-websocket-transport) When you use the OpenAI provider with the Responses API, you can send requests over a WebSocket transport instead of the default HTTP transport. Enable it globally with `setOpenAIResponsesTransport('websocket')`, or enable it per provider with `new OpenAIProvider({ useResponses: true, useResponsesWebSocket: true })`. You do not need `withResponsesWebSocketSession(...)` or a custom `OpenAIProvider` just to use the WebSocket transport. If reconnecting for each run/request is acceptable, your existing `run()` / `Runner.run()` usage will continue to work after enabling `setOpenAIResponsesTransport('websocket')`. Transport selection follows model resolution: * `setOpenAIResponsesTransport('websocket')` only affects string model names that are later resolved through the OpenAI provider while using the Responses API. * If you pass a concrete `Model` instance to an `Agent` or `Runner`, that instance is used as-is. `OpenAIResponsesWSModel` stays on WebSocket, `OpenAIResponsesModel` stays on HTTP, and `OpenAIChatCompletionsModel` stays on Chat Completions. * If you provide your own `modelProvider`, that provider controls model resolution. Enable WebSocket there instead of relying on the global setter. * If you route through a proxy, gateway, or other OpenAI-compatible endpoint, the target must support the WebSocket `/responses` endpoint. You may also need to set `websocketBaseURL` explicitly. Use `withResponsesWebSocketSession(...)` or a custom `OpenAIProvider` / `Runner` only when you want to optimize connection reuse and manage the websocket provider lifecycle more explicitly: * `withResponsesWebSocketSession(...)`: convenient scoped lifecycle with automatic cleanup after the callback. * Custom `OpenAIProvider` / `Runner`: explicit lifecycle control (including shutdown cleanup) in your own app architecture. Despite the name, `withResponsesWebSocketSession(...)` is a transport lifecycle helper and is unrelated to the memory `Session` interface described in the [sessions guide](/openai-agents-js/guides/sessions). If you use a websocket proxy or gateway, configure `websocketBaseURL` on `OpenAIProvider` or set `OPENAI_WEBSOCKET_BASE_URL`. If you instantiate `OpenAIProvider` yourself, remember that websocket-backed Responses model wrappers are cached by default for connection reuse. Call `await provider.close()` during shutdown to release those cached connections. `withResponsesWebSocketSession(...)` exists largely to manage that lifecycle for you: it creates a websocket-enabled provider and runner, passes them to your callback, and always closes the provider afterward. Use `providerOptions` for the temporary provider and `runnerConfig` for callback-scoped runner defaults. See [`examples/basic/stream-ws.ts`](https://github.com/openai/openai-agents-js/tree/main/examples/basic/stream-ws.ts) for a full streaming + HITL example using the Responses WebSocket transport. #### Responses-only deferred tool loading [Section titled “Responses-only deferred tool loading”](#responses-only-deferred-tool-loading) `toolSearchTool()`, `toolNamespace()`, and function tools or hosted MCP tools that set `deferLoading: true` require the OpenAI Responses API. The Chat Completions provider rejects namespaced or deferred function tools, and the AI SDK adapter does not support deferred Responses tool-loading flows. Use a Responses model directly when you need tool search. Tool search is supported only on GPT-5.4 and newer model releases that support it in the Responses API. When a run includes deferred tools, add `toolSearchTool()` to the same agent and keep `modelSettings.toolChoice` on `'auto'`. The SDK does not let you force the built-in `tool_search` tool or a deferred function tool by name because the model needs to decide when to load those definitions. See the [Tools guide](/openai-agents-js/guides/tools#deferred-tool-loading-with-tool-search) and the official [OpenAI tool search guide](https://developers.openai.com/api/docs/guides/tools-tool-search) for the full setup. *** ## Model behavior and prompts [Section titled “Model behavior and prompts”](#model-behavior-and-prompts) ### ModelSettings [Section titled “ModelSettings”](#modelsettings) `ModelSettings` mirrors the OpenAI parameters but is provider‑agnostic. | Field | Type | Notes | | ---------------------- | --------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `temperature` | `number` | Creativity vs. determinism. | | `topP` | `number` | Nucleus sampling. | | `frequencyPenalty` | `number` | Penalise repeated tokens. | | `presencePenalty` | `number` | Encourage new tokens. | | `toolChoice` | `'auto' \| 'required' \| 'none' \| string` | See [forcing tool use](/openai-agents-js/guides/agents#forcing-tool-use). On OpenAI Responses, `toolChoice: 'computer'` forces the GA built-in computer tool when available. | | `parallelToolCalls` | `boolean` | Allow parallel function calls where supported. | | `truncation` | `'auto' \| 'disabled'` | Token truncation strategy. | | `maxTokens` | `number` | Maximum tokens in the response. | | `store` | `boolean` | Persist the response for retrieval / RAG workflows. | | `promptCacheRetention` | `'in-memory' \| '24h' \| null` | Controls provider prompt-cache retention when supported. | | `contextManagement` | `ModelSettingsContextManagement` | Controls provider context management, such as server-side compaction. | | `reasoning.effort` | `'none' \| 'minimal' \| 'low' \| 'medium' \| 'high' \| 'xhigh'` | Reasoning effort for gpt-5.x models. | | `reasoning.summary` | `'auto' \| 'concise' \| 'detailed'` | Controls how much reasoning summary the model returns. | | `text.verbosity` | `'low' \| 'medium' \| 'high'` | Text verbosity for gpt-5.x etc. | | `providerData` | `Record` | Provider-specific passthrough options forwarded to the underlying model. | | `retry` | `ModelRetrySettings` | Runtime-only opt-in retry config. See [Model retries](#model-retries). | Attach settings at either level: Model settings ```typescript import { Runner, Agent } from '@openai/agents'; const agent = new Agent({ name: 'Creative writer', // ... modelSettings: { temperature: 0.7, toolChoice: 'auto' }, }); // or globally new Runner({ modelSettings: { temperature: 0.3 } }); ``` `Runner`‑level settings override any conflicting per‑agent settings. `retry` is the notable exception: its nested fields are merged across runner and agent settings unless you explicitly clear inherited values with `undefined`. ### Model retries [Section titled “Model retries”](#model-retries) Retries are runtime-only and opt-in. The SDK does not retry model requests unless you configure `modelSettings.retry` and your policy returns a retry decision. Opt in to model retries ```typescript import { Agent, Runner, retryPolicies } from '@openai/agents'; const sharedRetry = { maxRetries: 4, backoff: { initialDelayMs: 500, maxDelayMs: 5_000, multiplier: 2, jitter: true, }, policy: retryPolicies.any( retryPolicies.providerSuggested(), retryPolicies.retryAfter(), retryPolicies.networkError(), retryPolicies.httpStatus([408, 409, 429, 500, 502, 503, 504]), ), }; const runner = new Runner({ modelSettings: { retry: sharedRetry, }, }); const agent = new Agent({ name: 'Assistant', instructions: 'You are a concise assistant.', modelSettings: { retry: { maxRetries: 2, backoff: { maxDelayMs: 2_000, }, }, }, }); await runner.run(agent, 'Summarize exponential backoff in plain English.'); ``` `ModelRetrySettings` has three fields: | Field | Type | Notes | | ------------ | -------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `maxRetries` | `number` | Number of retry attempts allowed after the initial request. | | `backoff` | `{ initialDelayMs?, maxDelayMs?, multiplier?, jitter? }` | Default delay strategy when the policy retries without returning `delayMs`. `backoff.maxDelayMs` caps this computed backoff delay only; it does not cap explicit `delayMs` values returned by a policy or retry-after hints. | | `policy` | `RetryPolicy` | Callback that decides whether to retry. This function is runtime-only and is not serialized into persisted run state. | A retry policy receives a `RetryPolicyContext` with: * `attempt` and `maxRetries` so you can make attempt-aware decisions. * `stream` so you can branch between streamed and non-streamed behavior. * `error` for raw inspection. * `normalized` facts such as `statusCode`, `retryAfterMs`, `errorCode`, `isNetworkError`, and `isAbort`. * `providerAdvice` when the underlying model/provider can supply retry guidance. The policy can return either: * `true` / `false` for a simple retry decision. * `{ retry, delayMs?, reason? }` when you want to override the delay or attach a diagnostic reason for logging. The SDK exports ready-made helpers on `retryPolicies`: | Helper | Behavior | | ----------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------- | | `retryPolicies.never()` | Always opts out. | | `retryPolicies.providerSuggested()` | Follows provider retry advice when available. | | `retryPolicies.networkError()` | Matches transient transport/connectivity failures. | | `retryPolicies.httpStatus([..])` | Matches selected HTTP status codes. | | `retryPolicies.retryAfter()` | Retries only when a retry-after hint is available, using that hint as an explicit delay that is not capped by `backoff.maxDelayMs`. | | `retryPolicies.any(...)` | Retries when any nested policy opts in. | | `retryPolicies.all(...)` | Retries only when every nested policy opts in. | When you compose policies, `providerSuggested()` is the safest first building block because it preserves provider vetoes and replay-safety approvals when the provider can distinguish them. #### Safety boundaries [Section titled “Safety boundaries”](#safety-boundaries) Some failures are never retried automatically: * Abort errors. * Streamed runs after any visible event or raw model event has already been emitted. * Provider advice that marks replay as unsafe. Stateful follow-up requests using `previousResponseId` or `conversationId` are also treated more conservatively. For those requests, non-provider predicates such as `networkError()` or `httpStatus([500])` are not enough by themselves. The retry policy must include a replay-safe approval from the provider, typically via `retryPolicies.providerSuggested()`. #### Runner and agent merge behavior [Section titled “Runner and agent merge behavior”](#runner-and-agent-merge-behavior) `retry` is deep-merged between runner-level and agent-level `modelSettings`: * An agent can override only `retry.maxRetries` and still inherit the runner’s `policy`. * An agent can override only part of `retry.backoff` and keep sibling backoff fields from the runner. * If you need to remove an inherited `policy` or `backoff`, set that field to `undefined` explicitly. See [`examples/basic/retry.ts`](https://github.com/openai/openai-agents-js/tree/main/examples/basic/retry.ts) and [`examples/ai-sdk/retry.ts`](https://github.com/openai/openai-agents-js/tree/main/examples/ai-sdk/retry.ts) for fuller examples with logging. *** ### Prompt [Section titled “Prompt”](#prompt) Agents can be configured with a `prompt` parameter, indicating a server-stored prompt configuration that should be used to control the Agent’s behavior. Currently, this option is only supported when you use the OpenAI [Responses API](https://platform.openai.com/docs/api-reference/responses). `prompt` can be either a static object or a function that returns one at runtime. For the callback shape, see [Dynamic prompts](/openai-agents-js/guides/agents#dynamic-prompts). | Field | Type | Notes | | ----------- | -------- | -------------------------------------------------------------------------------------------------------------------------------------- | | `promptId` | `string` | Unique identifier for a prompt. | | `version` | `string` | Version of the prompt you wish to use. | | `variables` | `object` | A key/value pair of variables to substitute into the prompt. Values can be strings or content input types like text, images, or files. | Agent with prompt ```typescript import { parseArgs } from 'node:util'; import { Agent, run } from '@openai/agents'; /* NOTE: This example will not work out of the box, because the default prompt ID will not be available in your project. To use it, please: 1. Go to https://platform.openai.com/chat/edit 2. Create a new prompt variable, `poem_style`. 3. Create a system prompt with the content: Write a poem in {{poem_style}} 4. Run the example with the `--prompt-id` flag. */ const DEFAULT_PROMPT_ID = 'pmpt_6965a984c7ac8194a8f4e79b00f838840118c1e58beb3332'; const POEM_STYLES = ['limerick', 'haiku', 'ballad']; function pickPoemStyle(): string { return POEM_STYLES[Math.floor(Math.random() * POEM_STYLES.length)]; } async function runDynamic(promptId: string) { const poemStyle = pickPoemStyle(); console.log(`[debug] Dynamic poem_style: ${poemStyle}`); const agent = new Agent({ name: 'Assistant', prompt: { promptId, version: '1', variables: { poem_style: poemStyle }, }, }); const result = await run(agent, 'Tell me about recursion in programming.'); console.log(result.finalOutput); } async function runStatic(promptId: string) { const agent = new Agent({ name: 'Assistant', prompt: { promptId, version: '1', variables: { poem_style: 'limerick' }, }, }); const result = await run(agent, 'Tell me about recursion in programming.'); console.log(result.finalOutput); } async function main() { const args = parseArgs({ options: { dynamic: { type: 'boolean', default: false }, 'prompt-id': { type: 'string', default: DEFAULT_PROMPT_ID }, }, }); const promptId = args.values['prompt-id']; if (!promptId) { console.error('Please provide a prompt ID via --prompt-id.'); process.exit(1); } if (args.values.dynamic) { await runDynamic(promptId); } else { await runStatic(promptId); } } main().catch((error) => { console.error(error); process.exit(1); }); ``` Any additional agent configuration, like tools or instructions, will override the values you may have configured in your stored prompt. When a stored prompt already defines the model, the SDK does not send the agent’s default model unless you explicitly override it. That matters for `computerTool()`: prompt-managed runs keep the legacy preview wire shape by default for compatibility. To opt into the GA Responses computer tool on a prompt-managed run, explicitly set `modelSettings.toolChoice: 'computer'` or send an explicit model such as [`gpt-5.4`](https://developers.openai.com/api/docs/models/gpt-5.4). See [Tools](/openai-agents-js/guides/tools#computer-tool-specifics) for the surrounding computer-use details. *** ## Advanced providers and observability [Section titled “Advanced providers and observability”](#advanced-providers-and-observability) ### Custom model providers [Section titled “Custom model providers”](#custom-model-providers) Implementing your own provider is straightforward – implement `ModelProvider` and `Model` and pass the provider to the `Runner` constructor: Minimal custom provider ```typescript import { ModelProvider, Model, ModelRequest, ModelResponse, ResponseStreamEvent, } from '@openai/agents-core'; import { Agent, Runner } from '@openai/agents'; class EchoModel implements Model { name: string; constructor() { this.name = 'Echo'; } async getResponse(request: ModelRequest): Promise { return { usage: {}, output: [{ role: 'assistant', content: request.input as string }], } as any; } async *getStreamedResponse( _request: ModelRequest, ): AsyncIterable { yield { type: 'response.completed', response: { output: [], usage: {} }, } as any; } } class EchoProvider implements ModelProvider { getModel(_modelName?: string): Promise | Model { return new EchoModel(); } } const runner = new Runner({ modelProvider: new EchoProvider() }); console.log(runner.config.modelProvider.getModel()); const agent = new Agent({ name: 'Test Agent', instructions: 'You are a helpful assistant.', model: new EchoModel(), modelSettings: { temperature: 0.7, toolChoice: 'auto' }, }); console.log(agent.model); ``` If you want every `run()` call and every newly constructed `Runner` to use the same provider by default, set it once during app startup: Set a default model provider ```typescript import { setDefaultModelProvider } from '@openai/agents'; setDefaultModelProvider({ async getModel() { // Return any Model implementation here. throw new Error('Provide your own model implementation.'); }, }); ``` This is useful when your app standardizes on a non-OpenAI provider and you do not want to pass a custom `Runner` everywhere. #### AI SDK integration [Section titled “AI SDK integration”](#ai-sdk-integration) If you want to use non-OpenAI models without implementing `ModelProvider` yourself, see [Using any model with Vercel’s AI SDK](/openai-agents-js/extensions/ai-sdk). That adapter lets you plug an AI SDK model into the Agents runtime directly, which is useful when your app already standardizes on AI SDK providers or you want access to the wider provider ecosystem. It also documents how Agents SDK `providerData` maps to AI SDK `providerMetadata`, plus the stream helpers available for AI SDK UI routes. *** ### Tracing credentials [Section titled “Tracing credentials”](#tracing-credentials) Tracing is already enabled by default in supported server runtimes. Use `setTracingExportApiKey()` only when trace export should use a different credential than the default OpenAI API key: Set tracing export API key ```typescript import { setTracingExportApiKey } from '@openai/agents'; setTracingExportApiKey('sk-...'); ``` This sends traces to the [OpenAI dashboard](https://platform.openai.com/traces) using that credential. For exporter customization such as custom ingest endpoints or retry tuning, see the [Tracing guide](/openai-agents-js/guides/tracing#openai-tracing-exporter). *** ## Next steps [Section titled “Next steps”](#next-steps) * Explore [running agents](/openai-agents-js/guides/running-agents). * Give your models super‑powers with [tools](/openai-agents-js/guides/tools). * Add [guardrails](/openai-agents-js/guides/guardrails) or [tracing](/openai-agents-js/guides/tracing) as needed. # Agent Orchestration > Coordinate the flow between several agents Orchestration refers to the flow of agents in your app. Which agents run, in what order, and how do they decide what happens next? There are two main ways to orchestrate agents: > Read this page after the [Quickstart](/openai-agents-js/guides/quickstart) or the [Agents guide](/openai-agents-js/guides/agents#composition-patterns). This page is about workflow design across multiple agents, not the `Agent` constructor itself. 1. Allowing the LLM to make decisions: this uses the intelligence of an LLM to plan, reason, and decide on what steps to take based on that. 2. Orchestrating via code: determining the flow of agents via your code. You can mix and match these patterns. Each has their own tradeoffs, described below. ## Orchestrating via LLM [Section titled “Orchestrating via LLM”](#orchestrating-via-llm) An agent is an LLM equipped with instructions, tools and handoffs. This means that given an open-ended task, the LLM can autonomously plan how it will tackle the task, using tools to take actions and acquire data, and using handoffs to delegate tasks to sub-agents. For example, a research agent could be equipped with tools like: * Web search to find information online * File search and retrieval to search through proprietary data and connections * Computer use to take actions on a computer * Code execution to do data analysis * Handoffs to specialized agents that are great at planning, report writing and more. ### Core SDK patterns [Section titled “Core SDK patterns”](#core-sdk-patterns) In the Agents SDK, two orchestration patterns come up most often: | Pattern | How it works | Best when | | --------------- | ------------------------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------- | | Agents as tools | A manager agent keeps control of the conversation and calls specialist agents through `agent.asTool()`. | You want one agent to own the final answer, combine outputs from multiple specialists, or enforce shared guardrails in one place. | | Handoffs | A triage agent routes the conversation to a specialist, and that specialist becomes the active agent for the rest of the turn. | You want the specialist to speak directly to the user, keep prompts focused, or use different instructions/models per specialist. | Use **agents as tools** when the specialist should help with a subtask but should not take over the user-facing conversation. The manager stays responsible for deciding which tools to call and how to present the final response. See the [tools guide](/openai-agents-js/guides/tools#agents-as-tools) for the API details, and the [agents guide](/openai-agents-js/guides/agents#composition-patterns) for a side-by-side example. Use **handoffs** when routing itself is part of the workflow and you want the selected specialist to own the next part of the conversation. The handoff preserves the conversation context while narrowing the active instructions to the specialist. See the [handoffs guide](/openai-agents-js/guides/handoffs) for the API, and the [quickstart](/openai-agents-js/guides/quickstart#define-your-handoffs) for the smallest end-to-end example. You can combine the two patterns. A triage agent might hand off to a specialist, and that specialist can still use other agents as tools for bounded subtasks. This pattern is great when the task is open-ended and you want to rely on the intelligence of an LLM. The most important tactics here are: 1. Invest in good prompts. Make it clear what tools are available, how to use them, and what parameters it must operate within. 2. Monitor your app and iterate on it. See where things go wrong, and iterate on your prompts. 3. Allow the agent to introspect and improve. For example, run it in a loop, and let it critique itself; or, provide error messages and let it improve. 4. Have specialized agents that excel in one task, rather than having a general purpose agent that is expected to be good at anything. 5. Invest in [evals](https://platform.openai.com/docs/guides/evals). This lets you train your agents to improve and get better at tasks. If you want the SDK primitives behind this style of orchestration, start with [tools](/openai-agents-js/guides/tools), [handoffs](/openai-agents-js/guides/handoffs), and [running agents](/openai-agents-js/guides/running-agents). ## Orchestrating via code [Section titled “Orchestrating via code”](#orchestrating-via-code) While orchestrating via LLM is powerful, orchestrating via code makes tasks more deterministic and predictable, in terms of speed, cost and performance. Common patterns here are: * Using [structured outputs](https://developers.openai.com/api/docs/guides/structured-outputs) to generate well formed data that you can inspect with your code. For example, you might ask an agent to classify the task into a few categories, and then pick the next agent based on the category. * Chaining multiple agents by transforming the output of one into the input of the next. You can decompose a task like writing a blog post into a series of steps - do research, write an outline, write the blog post, critique it, and then improve it. * Running the agent that performs the task in a `while` loop with an agent that evaluates and provides feedback, until the evaluator says the output passes certain criteria. * Running multiple agents in parallel, e.g. via JavaScript primitives like `Promise.all`. This is useful for speed when you have multiple tasks that don’t depend on each other. We have a number of examples in [`examples/agent-patterns`](https://github.com/openai/openai-agents-js/tree/main/examples/agent-patterns). ## Related guides [Section titled “Related guides”](#related-guides) * [Agents](/openai-agents-js/guides/agents) for composition patterns and agent configuration. * [Tools](/openai-agents-js/guides/tools#agents-as-tools) for `agent.asTool()` and manager-style orchestration. * [Handoffs](/openai-agents-js/guides/handoffs) for delegation between specialist agents. * [Running Agents](/openai-agents-js/guides/running-agents) for `Runner` and per-run orchestration controls. * [Quickstart](/openai-agents-js/guides/quickstart) for a minimal end-to-end handoff example. # Quickstart > Create your first AI Agent from scratch Looking for sandbox agents? This quickstart builds a text agent that runs in your app process. If you want an agent with an isolated filesystem workspace, shell commands, and sandbox session state, start with the [Sandbox agents quickstart](/openai-agents-js/guides/sandbox-agents). ## Project Setup [Section titled “Project Setup”](#project-setup) 1. Create a project and initialize npm. You’ll only need to do this once. ```bash mkdir my_project cd my_project npm init -y ``` 2. Install the Agents SDK and Zod. The SDK uses Zod v4 for tool schemas and structured outputs. ```bash npm install @openai/agents zod ``` 3. Set an OpenAI API key. If you don’t have one, follow [these instructions](https://platform.openai.com/docs/quickstart#create-and-export-an-api-key) to create an OpenAI API key. ```bash export OPENAI_API_KEY=sk-... ``` Alternatively you can call `setDefaultOpenAIKey('')` to set the key programmatically and use `setTracingExportApiKey('')` for tracing. See [the config guide](/openai-agents-js/guides/config) for more details. ## Create your first agent [Section titled “Create your first agent”](#create-your-first-agent) Agents are defined with instructions and a name. Create an agent ```typescript import { Agent } from '@openai/agents'; const agent = new Agent({ name: 'History Tutor', instructions: 'You provide assistance with historical queries. Explain important events and context clearly.', }); ``` ## Run your first agent [Section titled “Run your first agent”](#run-your-first-agent) You can use the `run` method to run your agent. You trigger a run by passing both the agent you want to start on and the input you want to pass in. This will return a result that contains the final output and any actions that were performed during that run. Run an agent ```typescript import { Agent, run } from '@openai/agents'; const agent = new Agent({ name: 'History Tutor', instructions: 'You provide assistance with historical queries. Explain important events and context clearly.', }); const result = await run(agent, 'When did sharks first appear?'); console.log(result.finalOutput); ``` For a second turn, you can either pass `result.history` back into `run()`, attach a [session](/openai-agents-js/guides/sessions), or reuse OpenAI server-managed state with `conversationId` / `previousResponseId`. The [running agents](/openai-agents-js/guides/running-agents) guide compares these approaches. ## Give your agent tools [Section titled “Give your agent tools”](#give-your-agent-tools) You can give an agent tools to use to look up information or perform actions. Add a tool ```typescript import { Agent, tool } from '@openai/agents'; import { z } from 'zod'; const historyFunFact = tool({ // The name of the tool will be used by the agent to tell what tool to use. name: 'history_fun_fact', // The description is used to describe when to use the tool by telling it what it does. description: 'Give a fun fact about a historical event', // This tool takes no parameters, so we provide an empty Zod object. parameters: z.object({}), execute: async () => { // The output will be returned back to the agent to use. return 'Sharks are older than trees.'; }, }); const agent = new Agent({ name: 'History Tutor', instructions: 'You provide assistance with historical queries. Explain important events and context clearly.', // Add the tool to the agent. tools: [historyFunFact], }); ``` ## Add a few more agents [Section titled “Add a few more agents”](#add-a-few-more-agents) Additional agents can be defined similarly to break down problems into smaller parts and have your agent be more focused on the task at hand. It also allows you to use different models for different problems by defining the model on the agent. Create specialist agents ```typescript import { Agent } from '@openai/agents'; const historyTutorAgent = new Agent({ name: 'History Tutor', instructions: 'You provide assistance with historical queries. Explain important events and context clearly.', }); const mathTutorAgent = new Agent({ name: 'Math Tutor', instructions: 'You provide help with math problems. Explain your reasoning at each step and include examples', }); ``` ## Define your handoffs [Section titled “Define your handoffs”](#define-your-handoffs) In order to orchestrate between multiple agents, you can define `handoffs` for an agent. This will enable the agent to pass the conversation on to the next agent. This will happen automatically during the course of a run. Define handoffs ```typescript import { Agent } from '@openai/agents'; const historyTutorAgent = new Agent({ name: 'History Tutor', instructions: 'You provide assistance with historical queries. Explain important events and context clearly.', }); const mathTutorAgent = new Agent({ name: 'Math Tutor', instructions: 'You provide help with math problems. Explain your reasoning at each step and include examples', }); // Use Agent.create() to keep handoff output types aligned. const triageAgent = Agent.create({ name: 'Triage Agent', instructions: "You determine which agent to use based on the user's homework question", handoffs: [historyTutorAgent, mathTutorAgent], }); ``` After your run you can see which agent generated the final response by looking at the `lastAgent` property on the result. ## Run the agent orchestration [Section titled “Run the agent orchestration”](#run-the-agent-orchestration) The runner handles executing individual agents, any handoffs, and any tool calls. Run agent orchestration ```typescript import { Agent, run } from '@openai/agents'; const historyTutorAgent = new Agent({ name: 'History Tutor', instructions: 'You provide assistance with historical queries. Explain important events and context clearly.', }); const mathTutorAgent = new Agent({ name: 'Math Tutor', instructions: 'You provide help with math problems. Explain your reasoning at each step and include examples', }); const triageAgent = Agent.create({ name: 'Triage Agent', instructions: "You determine which agent to use based on the user's homework question", handoffs: [historyTutorAgent, mathTutorAgent], }); async function main() { const result = await run(triageAgent, 'What is the capital of France?'); console.log(result.finalOutput); } main().catch((err) => console.error(err)); ``` ## Putting it all together [Section titled “Putting it all together”](#putting-it-all-together) Let’s put it all together into one full example. Place this into your `index.js` file and run it. If your app is already set up for TypeScript, you can use `index.ts` instead. Quickstart ```typescript import { Agent, run } from '@openai/agents'; const historyTutorAgent = new Agent({ name: 'History Tutor', instructions: 'You provide assistance with historical queries. Explain important events and context clearly.', }); const mathTutorAgent = new Agent({ name: 'Math Tutor', instructions: 'You provide help with math problems. Explain your reasoning at each step and include examples', }); const triageAgent = Agent.create({ name: 'Triage Agent', instructions: "You determine which agent to use based on the user's homework question", handoffs: [historyTutorAgent, mathTutorAgent], }); async function main() { const result = await run(triageAgent, 'What is the capital of France?'); console.log(result.finalOutput); } main().catch((err) => console.error(err)); ``` ## View your traces [Section titled “View your traces”](#view-your-traces) The Agents SDK will automatically generate traces for you. This allows you to review how your agents are operating, what tools they called or which agent they handed off to. To review what happened during your agent run, navigate to the [Trace viewer in the OpenAI Dashboard](https://platform.openai.com/traces). ## Next steps [Section titled “Next steps”](#next-steps) Learn how to build more complex agentic flows: * Learn about configuring [Agents](/openai-agents-js/guides/agents). * Learn about [running agents](/openai-agents-js/guides/running-agents) and [sessions](/openai-agents-js/guides/sessions). * Learn about [tools](/openai-agents-js/guides/tools), [guardrails](/openai-agents-js/guides/guardrails), and [models](/openai-agents-js/guides/models). # Release process > Learn how we version and release the SDK and recent changes. ## Versioning [Section titled “Versioning”](#versioning) The project follows a slightly modified version of semantic versioning using the form `0.Y.Z`. The leading `0` indicates the SDK is still evolving rapidly. Increment the components as follows: ## Minor (`Y`) versions [Section titled “Minor (Y) versions”](#minor-y-versions) We will increase minor versions `Y` for **breaking changes** to any public interfaces that are not marked as beta. For example, going from `0.0.x` to `0.1.x` might include breaking changes. If you don’t want breaking changes, we recommend pinning to `0.0.x` versions in your project. ## Patch (`Z`) versions [Section titled “Patch (Z) versions”](#patch-z-versions) We will increment `Z` for non-breaking changes: * Bug fixes * New features * Changes to private interfaces * Updates to beta features ## Versioning sub-packages [Section titled “Versioning sub-packages”](#versioning-sub-packages) The main `@openai/agents` package is comprised of multiple sub-packages that can be used independently. At the moment the versions of the packages are linked, meaning if one package receives a version increase, so do the others. We might change this strategy as we move to `1.0.0`. ## Changelogs [Section titled “Changelogs”](#changelogs) We generate changelogs for each of the sub-packages to help understand what has changed. As the changes might have happened in a sub-package, you might have to look in that respective changelog for details on the change. * [`@openai/agents`](https://github.com/openai/openai-agents-js/blob/main/packages/agents/CHANGELOG.md) * [`@openai/agents-core`](https://github.com/openai/openai-agents-js/blob/main/packages/agents-core/CHANGELOG.md) * [`@openai/agents-extensions`](https://github.com/openai/openai-agents-js/blob/main/packages/agents-extensions/CHANGELOG.md) * [`@openai/agents-openai`](https://github.com/openai/openai-agents-js/blob/main/packages/agents-openai/CHANGELOG.md) * [`@openai/agents-realtime`](https://github.com/openai/openai-agents-js/blob/main/packages/agents-realtime/CHANGELOG.md) # Results > Learn how to access the results and output from your agent run When you [run your agent](/openai-agents-js/guides/running-agents), you will either receive a: * [`RunResult`](/openai-agents-js/openai/agents/classes/runresult) if you call `run` without `stream: true` * [`StreamedRunResult`](/openai-agents-js/openai/agents/classes/streamedrunresult) if you call `run` with `stream: true`. For details on streaming, also check the [streaming guide](/openai-agents-js/guides/streaming). Both result types expose the same core result surfaces such as `finalOutput`, `newItems`, `interruptions`, and `state`. `StreamedRunResult` adds streaming controls like `completed`, `toStream()`, `toTextStream()`, and `currentAgent`. ## Choose the right result surface [Section titled “Choose the right result surface”](#choose-the-right-result-surface) Most applications only need a few properties: | If you need… | Use | | --------------------------------------------------------------------------------------------------------- | ---------------------------------------------- | | The final answer to show the user | `finalOutput` | | A replay-ready next-turn input with the full local transcript | `history` | | Only the newly generated model-shaped items from this run | `output` | | Rich run items with agent/tool/handoff metadata | `newItems` | | The agent that should usually handle the next user turn | `lastAgent` or `activeAgent` | | OpenAI Responses API chaining with `previousResponseId` | `lastResponseId` | | Pending approvals and a resumable snapshot | `interruptions` and `state` | | App context, approvals, usage, and nested agent-tool input | `runContext` | | Metadata about the current nested `Agent.asTool()` invocation, for example inside `customOutputExtractor` | `agentToolInvocation` | | Raw model calls or guardrail diagnostics | `rawResponses` and the guardrail result arrays | ## Final output [Section titled “Final output”](#final-output) The `finalOutput` property contains the final output of the last agent that ran. This result is either: * `string` — default for any agent that has no `outputType` defined * `unknown` — if the agent has a JSON schema defined as output type. In this case the JSON was parsed but you still have to verify its type manually. * `z.infer` — if the agent has a Zod schema defined as output type. The output will automatically be parsed against this schema. * `undefined` — if the agent did not produce an output (for example stopped before it could produce an output) `finalOutput` is also `undefined` while a streamed run is still in progress or when the run paused on an approval interruption before reaching a final output. If you are using handoffs with different output types, you should use the `Agent.create()` method instead of the `new Agent()` constructor to create your agents. This will enable the SDK to infer the output types across all possible handoffs and provide a union type for the `finalOutput` property. For example: Handoff final output types ```typescript import { Agent, run } from '@openai/agents'; import { z } from 'zod'; const refundAgent = new Agent({ name: 'Refund Agent', instructions: 'You are a refund agent. You are responsible for refunding customers.', outputType: z.object({ refundApproved: z.boolean(), }), }); const orderAgent = new Agent({ name: 'Order Agent', instructions: 'You are an order agent. You are responsible for processing orders.', outputType: z.object({ orderId: z.string(), }), }); const triageAgent = Agent.create({ name: 'Triage Agent', instructions: 'You are a triage agent. You are responsible for triaging customer issues.', handoffs: [refundAgent, orderAgent], }); const result = await run(triageAgent, 'I need to a refund for my order'); const output = result.finalOutput; // ^? { refundApproved: boolean } | { orderId: string } | string | undefined ``` ## Input and output surfaces [Section titled “Input and output surfaces”](#input-and-output-surfaces) These properties answer different questions: | Property | What it contains | Best for | | ---------- | ------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------- | | `input` | The base input for this run. If a handoff input filter rewrote the history, this reflects the filtered input the run continued with. | Auditing what this run actually used as input | | `output` | Only the model-shaped items generated in this run, without agent metadata. | Storing or replaying just the new model delta | | `newItems` | Rich [`RunItem`](/openai-agents-js/openai/agents/type-aliases/runitem) wrappers with agent/tool/handoff metadata. | Logs, UIs, audits, and debugging | | `history` | A replay-ready next-turn input built from `input + newItems`. | Manual chat loops and client-managed conversation state | In practice: * Use `history` when you are manually carrying the whole conversation in your application. * Use `output` when you already store prior history elsewhere and only want the new generated items from this run. * Use `newItems` when you need agent associations, tool outputs, handoff boundaries, or approval items. * If you are using `conversationId` or `previousResponseId`, you usually do not pass `history` back into `run()`. Instead, pass only the new user input and reuse the server-managed ID. See [Running agents](/openai-agents-js/guides/running-agents#state-and-conversation-management) for the full comparison. `history` is a convenient way to maintain a full history in a chat-like use case: History loop ```typescript import { Agent, user, run } from '@openai/agents'; import type { AgentInputItem } from '@openai/agents'; const agent = new Agent({ name: 'Assistant', instructions: 'You are a helpful assistant knowledgeable about recent AGI research.', }); let history: AgentInputItem[] = [ // initial message user('Are we there yet?'), ]; for (let i = 0; i < 10; i++) { // run 10 times const result = await run(agent, history); // update the history to the new output history = result.history; history.push(user('How about now?')); } ``` ## New items [Section titled “New items”](#new-items) `newItems` gives you the richest view of what happened during the run. Common item types are: * [`RunMessageOutputItem`](/openai-agents-js/openai/agents/classes/runmessageoutputitem) for assistant messages. * [`RunReasoningItem`](/openai-agents-js/openai/agents/classes/runreasoningitem) for reasoning items. * [`RunToolSearchCallItem`](/openai-agents-js/openai/agents/classes/runtoolsearchcallitem) and [`RunToolSearchOutputItem`](/openai-agents-js/openai/agents/classes/runtoolsearchoutputitem) for Responses tool-search requests and the loaded tool definitions they return. * [`RunToolCallItem`](/openai-agents-js/openai/agents/classes/runtoolcallitem) and [`RunToolCallOutputItem`](/openai-agents-js/openai/agents/classes/runtoolcalloutputitem) for tool calls and their results. * [`RunToolApprovalItem`](/openai-agents-js/openai/agents/classes/runtoolapprovalitem) for tool calls that paused for approval. * [`RunHandoffCallItem`](/openai-agents-js/openai/agents/classes/runhandoffcallitem) and [`RunHandoffOutputItem`](/openai-agents-js/openai/agents/classes/runhandoffoutputitem) for handoff requests and completed transfers. Choose `newItems` over `output` whenever you need to know which agent produced an item or whether it marks a tool, tool-search, handoff, or approval boundary. When you use `toolSearchTool()`, these tool-search items are the easiest way to inspect which deferred tools or namespaces were loaded before the normal tool call happened. ## Continue or resume the conversation [Section titled “Continue or resume the conversation”](#continue-or-resume-the-conversation) ### Active agent [Section titled “Active agent”](#active-agent) The `lastAgent` property contains the last agent that ran. This is often the best agent to reuse for the next user turn after handoffs. `activeAgent` is an alias for the same value. In streaming mode, `currentAgent` tells you which agent is currently active while the run is still in progress. ### Interruptions and resumable state [Section titled “Interruptions and resumable state”](#interruptions-and-resumable-state) If a tool needs approval, the run pauses and `interruptions` contains the pending [`RunToolApprovalItem`](/openai-agents-js/openai/agents/classes/runtoolapprovalitem)s. This can include approvals raised by direct tools, by tools reached after a handoff, or by nested `agent.asTool()` runs. Resolve approvals through `result.state.approve(...)` / `result.state.reject(...)`, then pass the same `state` back into `run()` to resume. You do not need to resolve every interruption at once. If you rerun after handling only some items, resolved calls can continue while unresolved ones stay pending and pause the run again. The `state` property is the serializable snapshot behind the result. Use it for [human-in-the-loop](/openai-agents-js/guides/human-in-the-loop), retry flows, or any case where you need to resume a paused run later. ### Server-managed continuation [Section titled “Server-managed continuation”](#server-managed-continuation) `lastResponseId` is the value to pass as `previousResponseId` on the next turn when you are using OpenAI Responses API chaining. If you are already continuing the conversation with `history`, `session`, or `conversationId`, you usually do not need `lastResponseId`. If you need every raw model response from a multi-step run, inspect `rawResponses` instead. ## Nested agent-tool metadata [Section titled “Nested agent-tool metadata”](#nested-agent-tool-metadata) `agentToolInvocation` is for nested `Agent.asTool()` results, especially when you are inside `customOutputExtractor` and want metadata about the current tool invocation. It is not a general “the whole run has finished” summary field. In that nested context, `agentToolInvocation` exposes: * `toolName` * `toolCallId` * `toolArguments` Pair it with `result.runContext.toolInput` when you also need the structured input passed into that nested agent-tool run. On normal top-level `run()` results this is usually `undefined`. The metadata is runtime-only and is not serialized into `RunState`. See [Agents as tools](/openai-agents-js/guides/tools#4-agents-as-tools) for the surrounding pattern. ## Streamed results [Section titled “Streamed results”](#streamed-results) `StreamedRunResult` inherits the same result surfaces above, but adds streaming-specific controls: * `toTextStream()` for assistant text only. * `toStream()` or `for await ... of stream` for the full event stream. * `completed` to wait until the run and all post-processing callbacks finish. * `error` and `cancelled` to inspect the terminal streaming state. * `currentAgent` to track the active agent mid-run. If you need the settled final state of a streamed run, wait for `completed` before reading `finalOutput`, `history`, `interruptions`, or other summary properties. For event-by-event handling, see the [streaming guide](/openai-agents-js/guides/streaming). If a streamed run is cancelled, `completed` still resolves after cleanup and `cancelled` becomes `true`, but turn-end fields such as `finalOutput` can remain unset because the current turn never finished. Resume that unfinished turn with `result.state` (and the same `session`, if you use one) instead of appending a fresh user message. ## Diagnostics and advanced fields [Section titled “Diagnostics and advanced fields”](#diagnostics-and-advanced-fields) ### Run context [Section titled “Run context”](#run-context) The `runContext` property is the supported public view of the run context on the result. `result.runContext.context` is your app context, and the same object also carries SDK-managed runtime metadata such as approvals, usage, and nested `toolInput`. See [Context](/openai-agents-js/guides/context) for the full shape. ### Raw responses [Section titled “Raw responses”](#raw-responses) `rawResponses` contains the raw model responses collected during the run. Multi-step runs can produce more than one response, for example across handoffs or repeated tool/model cycles. ### Guardrail results [Section titled “Guardrail results”](#guardrail-results) The `inputGuardrailResults` and `outputGuardrailResults` properties contain agent-level guardrail results. Tool guardrail results are exposed separately via `toolInputGuardrailResults` and `toolOutputGuardrailResults`. Use these arrays when you want to log guardrail decisions, inspect extra metadata returned by guardrail functions, or debug why a run was blocked. ### Usage [Section titled “Usage”](#usage) Token usage is aggregated in `result.state.usage`, which tracks request counts and token totals for the run. The same usage object is also available through `result.runContext.usage`. For streaming runs this data updates as responses arrive. Read usage from RunState ```typescript import { Agent, run } from '@openai/agents'; const agent = new Agent({ name: 'Usage Tracker', instructions: 'Summarize the latest project update in one sentence.', }); const result = await run( agent, 'Summarize this: key customer feedback themes and the next product iteration.', ); const usage = result.state.usage; console.log({ requests: usage.requests, inputTokens: usage.inputTokens, outputTokens: usage.outputTokens, totalTokens: usage.totalTokens, }); if (usage.requestUsageEntries) { for (const entry of usage.requestUsageEntries) { console.log('request', { endpoint: entry.endpoint, inputTokens: entry.inputTokens, outputTokens: entry.outputTokens, totalTokens: entry.totalTokens, }); } } ``` # Running Agents > Configure and execute agent workflows with the Runner class Agents do nothing by themselves – you **run** them with the `Runner` class or the `run()` utility. > Read this page after [Agents](/openai-agents-js/guides/agents) once you want to execute turns, stream events, or manage conversation state. If you are still deciding how the agent should be defined, start with [Agents](/openai-agents-js/guides/agents) first. Simple run ```typescript 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. ``` When you don’t need a custom runner, you can also use the `run()` utility, which runs a singleton default `Runner` instance. Alternatively, you can create your own runner instance: Simple run ```typescript import { Agent, Runner } from '@openai/agents'; const agent = new Agent({ name: 'Assistant', instructions: 'You are a helpful assistant', }); // You can pass custom configuration to the runner const runner = new Runner(); const result = await runner.run( agent, 'Write a haiku about recursion in programming.', ); console.log(result.finalOutput); // Code within the code, // Functions calling themselves, // Infinite loop's dance. ``` After running your agent, you will receive a [result](/openai-agents-js/guides/results) object that contains the final output and the full history of the run. ## Runner lifecycle and configuration [Section titled “Runner lifecycle and configuration”](#runner-lifecycle-and-configuration) ### The agent loop [Section titled “The agent loop”](#the-agent-loop) When you use the run method in Runner, you pass in a starting agent and input. The input can either be a string (which is considered a user message), or a list of input items, which are the items in the OpenAI Responses API. The runner then runs a loop: 1. Call the current agent’s model with the current input. 2. Inspect the LLM response. * **Final output** → return. * **Handoff** → switch to the new agent, keep the accumulated conversation history, go to 1. * **Tool calls** → execute tools, append their results to the conversation, go to 1. 3. Throw [`MaxTurnsExceededError`](/openai-agents-js/openai/agents-core/classes/maxturnsexceedederror) once `maxTurns` is reached, unless `maxTurns` is `null`. Note The rule for whether the LLM output is considered as a “final output” is that it produces text output with the desired type, and there are no tool calls. #### Runner lifecycle [Section titled “Runner lifecycle”](#runner-lifecycle) Create a `Runner` when your app starts and reuse it across requests. The instance stores global configuration such as model provider and tracing options. Only create another `Runner` if you need a completely different setup. For simple scripts you can also call `run()` which uses a default runner internally. ### Run arguments [Section titled “Run arguments”](#run-arguments) The input to the `run()` method is an initial agent to start the run on, input for the run and a set of options. The input can either be a string (which is considered a user message), or a list of [input items](/openai-agents-js/openai/agents-core/type-aliases/agentinputitem), or a [`RunState`](/openai-agents-js/openai/agents-core/classes/runstate) object in case you are building a [human-in-the-loop](/openai-agents-js/guides/human-in-the-loop) agent. The additional options are: | Option | Default | Description | | ----------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | `stream` | `false` | If `true` the call returns a `StreamedRunResult` and emits events as they arrive from the model. | | `context` | – | Context object forwarded to every tool / guardrail / handoff. Learn more in the [context guide](/openai-agents-js/guides/context). | | `maxTurns` | `10` | Safety limit – throws [`MaxTurnsExceededError`](/openai-agents-js/openai/agents-core/classes/maxturnsexceedederror) when reached. Pass `null` to disable the limit. | | `signal` | – | `AbortSignal` for cancellation. | | `session` | – | Session persistence implementation. See the [sessions guide](/openai-agents-js/guides/sessions). | | `sessionInputCallback` | – | Custom merge logic for session history and new input; runs before the model call. See [sessions](/openai-agents-js/guides/sessions). | | `callModelInputFilter` | – | Hook to edit the model input (items + optional instructions) just before calling the model. See [Call model input filter](#call-model-input-filter). | | `toolErrorFormatter` | – | Hook to customize tool approval rejection messages returned to the model. See [Tool error formatter](#tool-error-formatter). | | `reasoningItemIdPolicy` | – | Controls whether reasoning-item `id`s are preserved or omitted when prior run items are turned back into model input. See [Reasoning item ID policy](#reasoning-item-id-policy). | | `tracing` | – | Per-run tracing configuration overrides (for example, export API key). | | `sandbox` | – | Sandbox client, live session, session state, snapshot, manifest override, or concurrency limits for `SandboxAgent` runs. See [Sandbox agents](/openai-agents-js/guides/sandbox-agents/concepts). | | `toolExecution` | – | SDK-side execution settings for local tool calls. Use `toolExecution.maxFunctionToolConcurrency` to limit how many function tools run at once. | | `errorHandlers` | – | Handlers for supported runtime errors (currently `maxTurns`). See [Error handlers](#error-handlers). | | `conversationId` | – | Reuse a server-side conversation (OpenAI Responses API + Conversations API only). | | `previousResponseId` | – | Continue from the previous Responses API call without creating a conversation (OpenAI Responses API only). | ### Streaming [Section titled “Streaming”](#streaming) Streaming allows you to additionally receive streaming events as the LLM runs. Once the stream is started, the `StreamedRunResult` will contain the complete information about the run, including all the new outputs produces. You can iterate over the streaming events using a `for await` loop. Read more in the [streaming guide](/openai-agents-js/guides/streaming). ### Run config [Section titled “Run config”](#run-config) If you are creating your own `Runner` instance, you can pass in a `RunConfig` object to configure the runner. | Field | Type | Purpose | | --------------------------- | ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | `model` | `string \| Model` | Force a specific model for **all** agents in the run. | | `modelProvider` | `ModelProvider` | Resolves model names – defaults to the OpenAI provider. | | `modelSettings` | `ModelSettings` | Global tuning parameters that override per‑agent settings. See the [models guide](/openai-agents-js/guides/models#modelsettings) for details, including opt-in retry configuration. | | `handoffInputFilter` | `HandoffInputFilter` | Mutates input items when performing handoffs (if the handoff itself doesn’t already define one). | | `inputGuardrails` | `InputGuardrail[]` | Guardrails applied to the *initial* user input. | | `outputGuardrails` | `OutputGuardrail[]` | Guardrails applied to the *final* output. | | `tracingDisabled` | `boolean` | Disable OpenAI Tracing completely. | | `traceIncludeSensitiveData` | `boolean` | Exclude LLM/tool inputs & outputs from traces while still emitting spans. | | `workflowName` | `string` | Appears in the Traces dashboard – helps group related runs. | | `traceId` / `groupId` | `string` | Manually specify the trace or group ID instead of letting the SDK generate one. | | `traceMetadata` | `Record` | Arbitrary metadata to attach to every span. | | `tracing` | `TracingConfig` | Per-run tracing overrides (for example, export API key). | | `sessionInputCallback` | `SessionInputCallback` | Default history merge strategy for all runs on this runner. | | `callModelInputFilter` | `CallModelInputFilter` | Global hook to edit model inputs before each model call. | | `toolErrorFormatter` | `ToolErrorFormatter` | Global hook to customize tool approval rejection messages returned to the model. | | `reasoningItemIdPolicy` | `ReasoningItemIdPolicy` | Default policy for preserving or omitting reasoning-item `id`s when replaying generated items into later model calls. | | `sandbox` | `SandboxRunConfig` | Default sandbox runtime configuration for `SandboxAgent` runs. | | `toolExecution` | `ToolExecutionConfig` | Default SDK-side execution settings for local tool calls. `maxFunctionToolConcurrency` caps local function tool concurrency for each turn; unset or `null` starts all function tool calls emitted in a turn. | `toolExecution.maxFunctionToolConcurrency` must be an integer greater than or equal to `1`. This setting only limits SDK-side execution of local function tools. It does not change provider-side `modelSettings.parallelToolCalls`. ## State and conversation management [Section titled “State and conversation management”](#state-and-conversation-management) ### Choose one memory strategy [Section titled “Choose one memory strategy”](#choose-one-memory-strategy) There are four common ways to carry state into the next turn: | Strategy | Where state lives | Best for | What you pass on the next turn | | -------------------- | ------------------------- | ------------------------------------------------------------------------ | ----------------------------------------------------- | | `result.history` | Your app memory | Small chat loops, full manual control, any provider | `result.history` | | `session` | Your storage + the SDK | Persistent chat state, resumable runs, custom stores | The same `session` instance (or a store-backed one) | | `conversationId` | OpenAI Conversations API | Shared server-side state across workers/services | The same `conversationId` plus only the new user turn | | `previousResponseId` | OpenAI Responses API only | The simplest server-managed continuation without creating a conversation | `result.lastResponseId` plus only the new user turn | `result.history` and `session` are client-managed. `conversationId` and `previousResponseId` are OpenAI-managed and only apply when you are using the OpenAI Responses API. In most applications, pick one persistence strategy per conversation. Mixing client-managed history with server-managed state can duplicate context unless you are deliberately reconciling both layers. Sandbox agents add another state layer: the live sandbox workspace. Use the regular SDK `session`, `conversationId`, or `previousResponseId` for conversation history, and use `sandbox.session`, `sandbox.sessionState`, `RunState`, or snapshots for sandbox filesystem state. See [Sandbox agents](/openai-agents-js/guides/sandbox-agents/concepts) for the workspace lifecycle. ### Conversations / chat threads [Section titled “Conversations / chat threads”](#conversations--chat-threads) Each call to `runner.run()` (or `run()` utility) represents one **turn** in your application-level conversation. You choose how much of the `RunResult` you show the end‑user – sometimes only `finalOutput`, other times every generated item. Example of carrying over the conversation history ```typescript import { Agent, run } from '@openai/agents'; import type { AgentInputItem } from '@openai/agents'; let thread: AgentInputItem[] = []; const agent = new Agent({ name: 'Assistant', }); async function userSays(text: string) { const result = await run( agent, thread.concat({ role: 'user', content: text }), ); thread = result.history; // Carry over history + newly generated items return result.finalOutput; } await userSays('What city is the Golden Gate Bridge in?'); // -> "San Francisco" await userSays('What state is it in?'); // -> "California" ``` See [the chat example](https://github.com/openai/openai-agents-js/tree/main/examples/basic/chat.ts) for an interactive version. #### Server-managed conversations [Section titled “Server-managed conversations”](#server-managed-conversations) You can let the OpenAI Responses API persist conversation history for you instead of sending your entire local conversation history on every turn. This is useful when you are coordinating long conversations or multiple services. With either server-managed approach below, pass only the new turn’s input on each request. The API reuses prior state for you. See the [Conversation state guide](https://developers.openai.com/api/docs/guides/conversation-state) for details. OpenAI exposes two ways to reuse server-side state: ##### 1. `conversationId` for an entire conversation [Section titled “1. conversationId for an entire conversation”](#1-conversationid-for-an-entire-conversation) You can create a conversation once using [Conversations API](https://platform.openai.com/docs/api-reference/conversations/create) and then reuse its ID for every turn. The SDK automatically includes only the newly generated items. Reusing a server conversation ```typescript import { Agent, run } from '@openai/agents'; import { OpenAI } from 'openai'; const agent = new Agent({ name: 'Assistant', instructions: 'Reply very concisely.', }); async function main() { // Create a server-managed conversation: const client = new OpenAI(); const { id: conversationId } = await client.conversations.create({}); const first = await run(agent, 'What city is the Golden Gate Bridge in?', { conversationId, }); console.log(first.finalOutput); // -> "San Francisco" const second = await run(agent, 'What state is it in?', { conversationId }); console.log(second.finalOutput); // -> "California" } main().catch(console.error); ``` ##### 2. `previousResponseId` to continue from the last turn [Section titled “2. previousResponseId to continue from the last turn”](#2-previousresponseid-to-continue-from-the-last-turn) If you want to start only with Responses API anyway, you can chain each request using the ID returned from the previous response. This keeps the context alive across turns without creating a full conversation resource. Chaining with previousResponseId ```typescript import { Agent, run } from '@openai/agents'; const agent = new Agent({ name: 'Assistant', instructions: 'Reply very concisely.', }); async function main() { const first = await run(agent, 'What city is the Golden Gate Bridge in?'); console.log(first.finalOutput); // -> "San Francisco" const previousResponseId = first.lastResponseId; const second = await run(agent, 'What state is it in?', { previousResponseId, }); console.log(second.finalOutput); // -> "California" } main().catch(console.error); ``` `conversationId` and `previousResponseId` are mutually exclusive. Use `conversationId` when you want a named conversation resource you can share across systems, and `previousResponseId` when you just want the cheapest SDK-level continuation primitive from one response to the next. ## Hooks and customization [Section titled “Hooks and customization”](#hooks-and-customization) ### Call model input filter [Section titled “Call model input filter”](#call-model-input-filter) Use `callModelInputFilter` to edit the model input *right before* the model is called. This hook receives the current agent, context, and the combined input items (including session history when present). Return the updated `input` array and optional `instructions` to redact sensitive data, drop old messages, or inject additional system guidance. Set it per run in `runner.run(..., { callModelInputFilter })` or as a default in the `Runner` config (`callModelInputFilter` in `RunConfig`). The return value must be a `ModelInputData` object: `{ input: AgentInputItem[], instructions? }`. The `input` field is required and must be an array. Returning any other shape throws a `UserError`. The SDK clones the prepared turn input before invoking the filter. If you are also using a `session`, the filtered clones are what get persisted, so redaction or truncation applied here is reflected in stored session history as well. With `conversationId` or `previousResponseId`, the hook runs on the prepared payload for the next Responses API call. Prior server-managed context is recovered by the API, so the filtered array for that call may already represent only the new turn delta rather than a full replay of earlier history. If you need to change how stored history and the current turn are merged before this final filter step, use `sessionInputCallback`. ### Tool error formatter [Section titled “Tool error formatter”](#tool-error-formatter) Use `toolErrorFormatter` to customize approval-rejection messages that are sent back to the model when a tool call is rejected. This lets you return domain-specific wording (for example, compliance guidance) instead of the SDK default message. The formatter can be set per-run (`runner.run(..., { toolErrorFormatter })`) or globally in `RunConfig` (`toolErrorFormatter` in `new Runner(...)`). This formatter is the global fallback for approval rejections. If you reject a specific interruption with `result.state.reject(interruption, { message: '...' })`, that per-call `message` takes precedence over `toolErrorFormatter`. If neither is provided, the SDK falls back to the default rejection text: `Tool execution was not approved.` The formatter currently runs for `approval_rejected` events and receives: * `kind` (currently always `'approval_rejected'`) * `toolType` (`'function'`, `'computer'`, `'shell'`, or `'apply_patch'`) * `toolName` * `callId` * `defaultMessage` (the SDK fallback message, currently `Tool execution was not approved.`) * `runContext` Return a string to override the message, or return `undefined` to keep the SDK default. If the formatter throws (or returns a non-string value), the SDK logs a warning and falls back to the default approval-rejection message. ### Reasoning item ID policy [Section titled “Reasoning item ID policy”](#reasoning-item-id-policy) Use `reasoningItemIdPolicy` to control whether reasoning items keep their `id` fields when the SDK converts previously generated run items back into `AgentInputItem[]` for later model input. This affects places where the SDK replays generated model items as input, such as: * follow-up model calls inside the same run (for example, after tool execution), * subsequent turns that reuse generated items as input/history, * resumed runs from a saved `RunState`, * derived result views like `result.history` / `result.output` (which are model-input-shaped arrays). * `'preserve'` (default) keeps reasoning-item IDs. * `'omit'` strips the `id` field from reasoning items before they are sent back as input. * Non-reasoning items are unaffected. What this does **not** change: * raw model responses (`result.rawResponses`), * run items (`result.newItems`), * the model’s current-turn output as returned by the provider. In other words, the policy applies when the SDK builds the **next input** from prior generated items. You can set the policy per run (`runner.run(..., { reasoningItemIdPolicy: 'omit' })`) or as the runner default (`new Runner({ reasoningItemIdPolicy: 'omit', ... })`). When resuming from a saved `RunState`, the previously resolved policy is reused unless you override it. #### Interaction with `callModelInputFilter` [Section titled “Interaction with callModelInputFilter”](#interaction-with-callmodelinputfilter) `reasoningItemIdPolicy` is applied before `callModelInputFilter`. If you need custom behavior, `callModelInputFilter` can still inspect the prepared input and re-introduce or remove reasoning IDs manually before the model call. #### When to use `'omit'` [Section titled “When to use 'omit'”](#when-to-use-omit) Use `'omit'` when you want replayed reasoning items to be normalized without IDs (for example, to keep forwarded/replayed model inputs simpler or to match integration requirements in your app pipeline). It is also a useful troubleshooting option if your backend/provider rejects replayed reasoning items with request validation errors (for example, HTTP `400` errors related to reasoning item IDs in follow-up inputs). In those cases, stripping replayed reasoning IDs with `'omit'` can avoid sending IDs that the backend treats as invalid for a new request. Keep `'preserve'` if you want the SDK to carry reasoning-item IDs through replayed inputs and your integration accepts them. ## Errors and recovery [Section titled “Errors and recovery”](#errors-and-recovery) ### Error handlers [Section titled “Error handlers”](#error-handlers) Use `errorHandlers` to convert supported runtime errors into a final output instead of throwing. The supported keys are `maxTurns` and `modelRefusal`. * `errorHandlers.maxTurns` handles only max-turn errors. * `errorHandlers.modelRefusal` handles model refusals surfaced as [`ModelRefusalError`](/openai-agents-js/openai/agents-core/classes/modelrefusalerror). * `errorHandlers.default` is used as a fallback for supported kinds. * Handlers receive `{ error, context, runData }` and can return `{ finalOutput, includeInHistory? }`. ### Exceptions [Section titled “Exceptions”](#exceptions) The SDK throws a small set of errors you can catch: * [`MaxTurnsExceededError`](/openai-agents-js/openai/agents-core/classes/maxturnsexceedederror) – `maxTurns` reached. * [`ModelBehaviorError`](/openai-agents-js/openai/agents-core/classes/modelbehaviorerror) – model produced invalid output (e.g. malformed JSON, unknown tool). * [`ModelRefusalError`](/openai-agents-js/openai/agents-core/classes/modelrefusalerror) – model refused to produce the requested output. * [`InputGuardrailTripwireTriggered`](/openai-agents-js/openai/agents-core/classes/inputguardrailtripwiretriggered) / [`OutputGuardrailTripwireTriggered`](/openai-agents-js/openai/agents-core/classes/outputguardrailtripwiretriggered) – guardrail violations. * [`ToolInputGuardrailTripwireTriggered`](/openai-agents-js/openai/agents-core/classes/toolinputguardrailtripwiretriggered) / [`ToolOutputGuardrailTripwireTriggered`](/openai-agents-js/openai/agents-core/classes/tooloutputguardrailtripwiretriggered) – tool guardrail violations. * [`GuardrailExecutionError`](/openai-agents-js/openai/agents-core/classes/guardrailexecutionerror) – guardrails failed to complete. * [`ToolTimeoutError`](/openai-agents-js/openai/agents-core/classes/tooltimeouterror) – a function tool exceeded `timeoutMs` and used `timeoutBehavior: 'raise_exception'`. * [`ToolCallError`](/openai-agents-js/openai/agents-core/classes/toolcallerror) – function tool execution failed for non-timeout errors. * [`UserError`](/openai-agents-js/openai/agents-core/classes/usererror) – any error thrown based on configuration or user input. All extend the base `AgentsError` class, which could provide the `state` property to access the current run state. Here is an example code that handles `GuardrailExecutionError`. Because input guardrails only run on the first user input, the example restarts the run with the original input and context. It also shows reusing the saved state to retry output guardrails without calling the model again: Guardrail execution error ```typescript import { Agent, GuardrailExecutionError, InputGuardrail, InputGuardrailTripwireTriggered, OutputGuardrail, OutputGuardrailTripwireTriggered, run, } from '@openai/agents'; import { z } from 'zod'; // Shared guardrail agent to avoid re-creating it on every fallback run. const guardrailAgent = new Agent({ name: 'Guardrail check', instructions: 'Check if the user is asking you to do their math homework.', outputType: z.object({ isMathHomework: z.boolean(), reasoning: z.string(), }), }); async function main() { const input = 'Hello, can you help me solve for x: 2x + 3 = 11?'; const context = { customerId: '12345' }; // Input guardrail example const unstableInputGuardrail: InputGuardrail = { name: 'Math Homework Guardrail (unstable)', execute: async () => { throw new Error('Something is wrong!'); }, }; const fallbackInputGuardrail: InputGuardrail = { name: 'Math Homework Guardrail (fallback)', execute: async ({ input, context }) => { const result = await run(guardrailAgent, input, { context }); const isMathHomework = result.finalOutput?.isMathHomework ?? /solve for x|math homework/i.test(JSON.stringify(input)); return { outputInfo: result.finalOutput, tripwireTriggered: isMathHomework, }; }, }; const agent = new Agent({ name: 'Customer support agent', instructions: 'You are a customer support agent. You help customers with their questions.', inputGuardrails: [unstableInputGuardrail], }); try { // Input guardrails only run on the first turn of a run, so retries must start a fresh run. await run(agent, input, { context }); } catch (e) { if (e instanceof GuardrailExecutionError) { console.error(`Guardrail execution failed (input): ${e}`); try { agent.inputGuardrails = [fallbackInputGuardrail]; // Retry from scratch with the original input and context. await run(agent, input, { context }); } catch (ee) { if (ee instanceof InputGuardrailTripwireTriggered) { console.log('Math homework input guardrail tripped on retry'); } else { throw ee; } } } else { throw e; } } // Output guardrail example const replyOutputSchema = z.object({ reply: z.string() }); const unstableOutputGuardrail: OutputGuardrail = { name: 'Answer review (unstable)', execute: async () => { throw new Error('Output guardrail crashed.'); }, }; const fallbackOutputGuardrail: OutputGuardrail = { name: 'Answer review (fallback)', execute: async ({ agentOutput }) => { const outputText = typeof agentOutput === 'string' ? agentOutput : (agentOutput?.reply ?? JSON.stringify(agentOutput)); const flagged = /math homework|solve for x|x =/i.test(outputText); return { outputInfo: { flaggedOutput: outputText }, tripwireTriggered: flagged, }; }, }; const agent2 = new Agent({ name: 'Customer support agent (output check)', instructions: 'You are a customer support agent. Answer briefly.', outputType: replyOutputSchema, outputGuardrails: [unstableOutputGuardrail], }); try { await run(agent2, input, { context }); } catch (e) { if (e instanceof GuardrailExecutionError && e.state) { console.error(`Guardrail execution failed (output): ${e}`); try { agent2.outputGuardrails = [fallbackOutputGuardrail]; // Output guardrails can be retried using the saved state without another model call. await run(agent2, e.state); } catch (ee) { if (ee instanceof OutputGuardrailTripwireTriggered) { console.log('Output guardrail tripped after retry with saved state'); } else { throw ee; } } } else { throw e; } } } main().catch(console.error); ``` Input vs. output retries: * Input guardrails run only on the very first user input of a run, so you must start a fresh run with the same input/context to retry them—passing a saved `state` will not re-trigger input guardrails. * Output guardrails run after the model response, so you can reuse the saved `state` from a `GuardrailExecutionError` to rerun output guardrails without another model call. When you run the above example, you will see the following output: ```plaintext Guardrail execution failed (input): Error: Input guardrail failed to complete: Error: Something is wrong! Math homework input guardrail tripped on retry Guardrail execution failed (output): Error: Output guardrail failed to complete: Error: Output guardrail crashed. Output guardrail tripped after retry with saved state ``` *** ## Related guides [Section titled “Related guides”](#related-guides) * [Agents](/openai-agents-js/guides/agents) for defining the agent before you run it. * [Results](/openai-agents-js/guides/results) for `finalOutput`, run items, interruptions, and resume state. * [Sessions](/openai-agents-js/guides/sessions) for persistent SDK-managed memory. * [Tools](/openai-agents-js/guides/tools) for the capabilities used during the run loop. * [Models](/openai-agents-js/guides/models) for provider configuration and Responses transport. * Add [guardrails](/openai-agents-js/guides/guardrails) or [tracing](/openai-agents-js/guides/tracing) for production readiness. # Quickstart > Create your first sandbox agent with an isolated workspace, filesystem tools, shell commands, and sandbox session state. Beta feature Sandbox agents are in beta. API details, defaults, and supported capabilities may change before general availability, and more advanced features are expected over time. Modern agents work best when they can operate on real files in a filesystem. **Sandbox Agents** in the Agents SDK give the model a persistent workspace where it can search large document sets, edit files, run commands, generate artifacts, and pick work back up from saved sandbox state. The SDK gives you that execution harness without making you wire together file staging, filesystem tools, shell access, sandbox lifecycle, snapshots, and provider-specific glue yourself. You keep the normal `Agent` and `Runner` flow, then add a `Manifest` for the workspace, capabilities for sandbox-native tools, and the `sandbox` run option for where the work runs. ## Prerequisites [Section titled “Prerequisites”](#prerequisites) * Node.js 22 or higher. * Basic familiarity with the OpenAI Agents SDK. * A sandbox client. For local development, start with `UnixLocalSandboxClient`. This quickstart uses Node.js and npm commands, but the SDK is not limited to Node.js. Sandbox agents can also run on Deno and Bun when your project uses compatible package resolution and runtime APIs. ## Installation [Section titled “Installation”](#installation) If you have not already installed the SDK: ```bash npm install @openai/agents ``` For Docker-backed sandboxes, install Docker locally and use `DockerSandboxClient` from `@openai/agents/sandbox/local`. If you use interactive local PTY sessions with `tty: true`, the process running the SDK also needs Python 3 available as `python3`, or through `OPENAI_AGENTS_PYTHON`. Non-PTY shell commands do not require Python. ## Create a local sandbox agent [Section titled “Create a local sandbox agent”](#create-a-local-sandbox-agent) This example stages a local repo under `repo/`, loads local skills lazily, and lets the runner create a Unix-local sandbox session for the run. The agent definition owns the manifest and capabilities, while the run config only chooses the sandbox client for this run. Create a local sandbox agent ```typescript import { run } from '@openai/agents'; import { Capabilities, Manifest, SandboxAgent, localDir, skills, } from '@openai/agents/sandbox'; import { UnixLocalSandboxClient, localDirLazySkillSource, } from '@openai/agents/sandbox/local'; import { dirname, join } from 'node:path'; import { fileURLToPath } from 'node:url'; const exampleDir = dirname(fileURLToPath(import.meta.url)); const hostRepoDir = join(exampleDir, 'repo'); const hostSkillsDir = join(exampleDir, 'skills'); const manifest = new Manifest({ entries: { repo: localDir({ src: hostRepoDir }), }, }); const agent = new SandboxAgent({ name: 'Sandbox engineer', model: 'gpt-5.5', instructions: 'Read `repo/task.md` before editing files. Load the `$invoice-total-fixer` skill before changing code. Stay grounded in the repository, preserve existing behavior, and mention the exact verification command you ran. If you edit files with apply_patch, paths are relative to the sandbox workspace root.', defaultManifest: manifest, capabilities: [ ...Capabilities.default(), skills({ lazyFrom: localDirLazySkillSource({ src: hostSkillsDir, }), }), ], }); const result = await run( agent, 'Open `repo/task.md`, fix the issue, run the targeted test, and summarize the change.', { sandbox: { client: new UnixLocalSandboxClient(), }, }, ); console.log(result.finalOutput); ``` ## Key choices [Section titled “Key choices”](#key-choices) Once the basic run works, the choices most people reach for next are: * `defaultManifest`: the files, repos, directories, and mounts for fresh sandbox sessions. * `instructions`: short workflow rules that should apply across prompts. * `baseInstructions`: an advanced escape hatch for replacing the SDK sandbox prompt. * `capabilities`: sandbox-native tools such as filesystem editing/image inspection, shell, skills, memory, and compaction. * `runAs`: the sandbox user identity for model-facing tools. * `sandbox.client`: the sandbox backend. * `sandbox.session`, `sandbox.sessionState`, or `sandbox.snapshot`: how later runs reconnect to prior work. ## Where to go next [Section titled “Where to go next”](#where-to-go-next) * [Concepts](/openai-agents-js/guides/sandbox-agents/concepts): understand manifests, capabilities, permissions, snapshots, run config, and composition patterns. * [Sandbox clients](/openai-agents-js/guides/sandbox-agents/clients): choose Unix-local, Docker, hosted providers, and mount strategies. * [Agent memory](/openai-agents-js/guides/sandbox-agents/memory): preserve and reuse lessons from previous sandbox runs. If shell access is only one occasional tool, start with hosted shell in the [Tools guide](/openai-agents-js/guides/tools). Reach for sandbox agents when workspace isolation, sandbox client choice, or sandbox-session resume behavior are part of the design. # Sandbox clients > Choose where sandbox work should run and how sessions, snapshots, mounts, and ports behave. Use this page to choose where sandbox work should run. In most cases, the `SandboxAgent` definition stays the same while the sandbox client and client-specific options change in the `sandbox` run option. Beta feature Sandbox agents are in beta. API details, defaults, and supported capabilities may change before general availability, and more advanced features are expected over time. ## Decision guide [Section titled “Decision guide”](#decision-guide) | Goal | Start with | Why | | ---------------------------------------------- | ------------------------ | ------------------------------------------------------------------- | | Fastest local iteration on macOS or Linux | `UnixLocalSandboxClient` | No extra service dependency and a simple local filesystem workflow. | | Basic container isolation | `DockerSandboxClient` | Runs work inside Docker with a specific image. | | Hosted execution or production-style isolation | A hosted sandbox client | Moves the workspace boundary to a provider-managed environment. | ## Local clients [Section titled “Local clients”](#local-clients) For most users, start with one of these two sandbox clients: | Client | Install | Choose it when | | ------------------------ | ---------------------------- | ------------------------------------------------------------------------------ | | `UnixLocalSandboxClient` | none | Fastest local iteration on macOS or Linux. Good default for local development. | | `DockerSandboxClient` | Docker CLI available locally | You want container isolation or a specific image for local parity. | Unix-local is the easiest way to start developing against a local filesystem. Move to Docker or a hosted provider when you need stronger environment isolation or production-style parity. To switch from Unix-local to Docker, keep the agent definition the same and change only the client: Use Docker ```typescript import { run } from '@openai/agents'; import { SandboxAgent } from '@openai/agents/sandbox'; import { DockerSandboxClient } from '@openai/agents/sandbox/local'; const agent = new SandboxAgent({ name: 'Workspace reviewer', model: 'gpt-5.5', instructions: 'Inspect the sandbox workspace before answering.', }); const result = await run(agent, 'Inspect the workspace.', { sandbox: { client: new DockerSandboxClient({ image: 'node:22-bookworm-slim' }), }, }); console.log(result.finalOutput); ``` The same agent can usually run with either local client: Switch between local clients ```typescript import { DockerSandboxClient, UnixLocalSandboxClient, } from '@openai/agents/sandbox/local'; const client = process.env.USE_DOCKER ? new DockerSandboxClient({ image: 'node:22-bookworm-slim' }) : new UnixLocalSandboxClient(); ``` ### Session ownership [Section titled “Session ownership”](#session-ownership) There are two lifecycle styles. | Style | What you pass | Who closes the session | Use it when | | --------------- | ---------------------- | ---------------------- | ---------------------------------------------------------------------------------------------- | | SDK-owned | `sandbox: { client }` | The runner | The sandbox only needs to live for one run. | | Developer-owned | `sandbox: { session }` | Your code | You need to inspect files afterward, reuse the same live session, or coordinate multiple runs. | When you create a session yourself, close it yourself: Own the sandbox session lifecycle ```typescript import { run } from '@openai/agents'; import { Manifest, SandboxAgent } from '@openai/agents/sandbox'; import { UnixLocalSandboxClient } from '@openai/agents/sandbox/local'; const manifest = new Manifest(); const agent = new SandboxAgent({ name: 'Workspace reviewer', model: 'gpt-5.5', instructions: 'Inspect the sandbox workspace before answering.', }); const client = new UnixLocalSandboxClient(); const session = await client.create({ manifest }); try { await run(agent, 'First pass.', { sandbox: { session } }); await run(agent, 'Follow-up pass.', { sandbox: { session } }); } finally { await session.close?.(); } ``` ### Resume and snapshots [Section titled “Resume and snapshots”](#resume-and-snapshots) Sandbox state and conversation state are separate: * SDK conversation state lives in `result.history`, an SDK `Session`, `conversationId`, or `previousResponseId`. * Sandbox state lives in the live sandbox session, serialized `sessionState`, `RunState` sandbox payloads, or snapshots. Use `sessionState` when you want to reconnect to the same backend session through a sandbox client. Use a snapshot when you want a fresh session seeded from saved workspace contents. Serialize and resume sandbox state ```typescript import { Manifest } from '@openai/agents/sandbox'; import { UnixLocalSandboxClient } from '@openai/agents/sandbox/local'; const manifest = new Manifest(); const client = new UnixLocalSandboxClient({ snapshot: { type: 'local', baseDir: '/tmp/my-sandbox-snapshots' }, }); const session = await client.create({ manifest }); const state = await client.serializeSessionState?.(session.state); await session.close?.(); if (state) { const restored = await client.resume?.( await client.deserializeSessionState!(state), ); await restored?.close?.(); } ``` `RunState` can also preserve runner-managed sandbox state when you pause or resume a larger workflow. Use explicit `sessionState` when the sandbox lifecycle is managed outside a serialized run. ### Manifest materialization [Section titled “Manifest materialization”](#manifest-materialization) Manifest entries are prepared before the agent runs. You can tune materialization concurrency per run or per client create call: Tune manifest materialization concurrency ```typescript import { run } from '@openai/agents'; import { SandboxAgent } from '@openai/agents/sandbox'; import { UnixLocalSandboxClient } from '@openai/agents/sandbox/local'; const agent = new SandboxAgent({ name: 'Repository inspector', model: 'gpt-5.5', instructions: 'Inspect the repository before answering.', }); await run(agent, 'Inspect the repo.', { sandbox: { client: new UnixLocalSandboxClient(), concurrencyLimits: { manifestEntries: 4, localDirFiles: 16, }, }, }); ``` `manifestEntries` limits parallel top-level entry work. `localDirFiles` limits file copy concurrency inside `localDir()` entries. ## Mounts and remote storage [Section titled “Mounts and remote storage”](#mounts-and-remote-storage) Mount entries describe what storage to expose; mount strategies describe how a sandbox backend attaches that storage. Import the built-in mount entries and generic strategies from `@openai/agents/sandbox`. Common mount options: * `mountPath`: where the storage appears in the sandbox. Relative paths are resolved under the manifest root; absolute paths are used as-is. * `readOnly`: set this when the sandbox should not write back to the mounted storage. * `mountStrategy`: use a strategy that matches both the mount entry and the sandbox backend. Mounts are treated as ephemeral workspace entries. Snapshot and persistence flows detach or skip mounted paths instead of copying mounted remote storage into the saved workspace. Generic local/container strategies: | Strategy or pattern | Use it when | Notes | | -------------------------------- | --------------------------------------------------------------------------------------- | ---------------------------------------------------------------- | | `inContainerMountStrategy(...)` | The sandbox image can run a mount command such as `rclone`, `mount-s3`, or `blobfuse2`. | Available as a generic strategy; support depends on the backend. | | `dockerVolumeMountStrategy(...)` | Docker should attach a volume-driver-backed mount before the container starts. | Docker-only. | | `localBindMountStrategy()` | A local backend should bind an absolute local path into the workspace. | Supported by local workspace materialization where allowed. | Backend support is intentionally explicit: | Backend | Mount notes | | ------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------- | | `UnixLocalSandboxClient` | Supports local bind-style mounts through the local workspace model. | | `DockerSandboxClient` | Supports local bind mounts and Docker volume-style strategies where Docker can attach the storage. | | Hosted providers | Provider-specific strategies live with each provider implementation. Check that provider’s docs for supported mounts and required setup. | Do not assume a mount entry works on every backend. If a client cannot enforce manifest metadata, identity, or mount behavior, it should fail early instead of silently ignoring that part of the manifest. ## Supported hosted platforms [Section titled “Supported hosted platforms”](#supported-hosted-platforms) When you need a hosted environment, the same `SandboxAgent` definition usually carries over and only the sandbox client changes in the `sandbox` run option. Hosted provider implementations are available from `@openai/agents-extensions` provider subpaths. Check the provider’s docs for exact environment variables, runnable examples, port behavior, PTY support, snapshot behavior, and cleanup behavior. Install `@openai/agents-extensions` and satisfy its package-level peers. Each provider may also require a provider SDK package or backend setup: | Client | Import path | Provider requirement | | ------------------------- | ---------------------------------------------- | ---------------------------------------------------- | | `BlaxelSandboxClient` | `@openai/agents-extensions/sandbox/blaxel` | npm peer: `@blaxel/core` | | `CloudflareSandboxClient` | `@openai/agents-extensions/sandbox/cloudflare` | Cloudflare Sandbox bridge Worker URL and Worker auth | | `DaytonaSandboxClient` | `@openai/agents-extensions/sandbox/daytona` | npm peer: `@daytonaio/sdk` | | `E2BSandboxClient` | `@openai/agents-extensions/sandbox/e2b` | npm peer: `e2b` or `@e2b/code-interpreter` | | `ModalSandboxClient` | `@openai/agents-extensions/sandbox/modal` | npm peer: `modal` | | `RunloopSandboxClient` | `@openai/agents-extensions/sandbox/runloop` | npm peer: `@runloop/api-client` | | `VercelSandboxClient` | `@openai/agents-extensions/sandbox/vercel` | npm peer: `@vercel/sandbox` | `CloudflareSandboxClient` does not import a Cloudflare npm SDK. It talks to a deployed Cloudflare Sandbox bridge Worker over HTTP instead. Hosted sandbox clients expose provider-specific mount strategies. Choose the backend and mount strategy that best fit your storage provider: | Backend | Mount notes | | ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | Docker | Supports `s3Mount()`, `gcsMount()`, `r2Mount()`, `azureBlobMount()`, `boxMount()`, and `s3FilesMount()` with local strategies such as `inContainerMountStrategy()` and `dockerVolumeMountStrategy()`. | | `ModalSandboxClient` | Supports cloud bucket mounts with `ModalCloudBucketMountStrategy` on S3, R2, and HMAC-authenticated GCS mount entries. | | `CloudflareSandboxClient` | Supports Cloudflare bucket mounts with `CloudflareBucketMountStrategy` on S3, R2, and HMAC-authenticated GCS mount entries. | | `BlaxelSandboxClient` | Supports cloud bucket mounts with `BlaxelCloudBucketMountStrategy` on S3, R2, and GCS mount entries. It also supports persistent Blaxel Drives with `BlaxelDriveMount` and `BlaxelDriveMountStrategy`. | | `DaytonaSandboxClient` | Supports rclone-backed mounts with `DaytonaCloudBucketMountStrategy` on S3, GCS, R2, Azure Blob, and Box mount entries. | | `E2BSandboxClient` | Supports rclone-backed mounts with `E2BCloudBucketMountStrategy` on S3, GCS, R2, Azure Blob, and Box mount entries. | | `RunloopSandboxClient` | Supports rclone-backed mounts with `RunloopCloudBucketMountStrategy` on S3, GCS, R2, Azure Blob, and Box mount entries. | | `VercelSandboxClient` | No hosted-specific mount strategy is currently exposed. Use manifest files, repos, snapshots, or other workspace inputs instead. | The table below summarizes which remote storage entries each backend can mount directly: | Backend | AWS S3 | Cloudflare R2 | GCS | Azure Blob Storage | Box | S3 Files | | ------------------------- | ------ | ------------- | --- | ------------------ | --- | -------- | | Docker | yes | yes | yes | yes | yes | yes | | `ModalSandboxClient` | yes | yes | yes | no | no | no | | `CloudflareSandboxClient` | yes | yes | yes | no | no | no | | `BlaxelSandboxClient` | yes | yes | yes | no | no | no | | `DaytonaSandboxClient` | yes | yes | yes | yes | yes | no | | `E2BSandboxClient` | yes | yes | yes | yes | yes | no | | `RunloopSandboxClient` | yes | yes | yes | yes | yes | no | | `VercelSandboxClient` | no | no | no | no | no | no | ### Exposed ports [Section titled “Exposed ports”](#exposed-ports) Sandbox clients can expose endpoints through `resolveExposedPort(port)` when the backend supports it. | Client | Behavior | | ------------------------ | ----------------------------------------------------------------------- | | `UnixLocalSandboxClient` | Resolves configured ports to `127.0.0.1`. | | `DockerSandboxClient` | Publishes configured container ports and resolves their host endpoints. | Declare the ports in the client options when you need a backend to enforce an allowlist: Expose a port ```typescript import { DockerSandboxClient } from '@openai/agents/sandbox/local'; const client = new DockerSandboxClient({ image: 'node:22-bookworm-slim', exposedPorts: [3000], }); ``` ### Capability support matrix [Section titled “Capability support matrix”](#capability-support-matrix) | Capability | Unix-local | Docker | | -------------------- | ---------------------------------------------------------- | ------------------------------------- | | `exec_command` | Supported | Supported | | PTY `write_stdin` | Supported | Supported | | `apply_patch` | Supported | Supported through workspace file APIs | | `view_image` | Supported | Supported through workspace file APIs | | `runAs` for commands | Supported when the host can resolve and switch to the user | Limited by container/user setup | | Local snapshots | Supported | Supported | | Local/Docker mounts | Local bind-style support | Bind and Docker volume-style support | Local PTY support uses a small Python 3 bridge in the SDK process. The bridge is only used for `tty: true` sessions, where Node.js does not provide a built-in PTY API and the SDK needs standard POSIX PTY behavior for interactive stdin, signal handling, and exit status reporting. Install `python3` in the environment that runs your SDK code, or set `OPENAI_AGENTS_PYTHON` to a Python 3 executable. This is separate from the Python version, if any, installed inside a Docker sandbox image. Hosted provider support varies by provider. Check the provider-specific docs for exact options, environment variables, port behavior, PTY support, snapshot behavior, and cleanup behavior. # Concepts > Understand manifests, capabilities, permissions, snapshots, sandbox lifecycle, run config, and composition patterns. Beta feature Sandbox agents are in beta. API details, defaults, and supported capabilities may change before general availability, and more advanced features are expected over time. Modern agents work best when they can operate on real files in a filesystem. **Sandbox Agents** can make use of specialized tools and shell commands to search over and manipulate large document sets, edit files, generate artifacts, and run commands. The sandbox provides the model with a persistent workspace that the agent can use to do work on your behalf. Sandbox Agents in the Agents SDK help you run agents paired with a sandbox environment, making it easy to get the right files on the filesystem and orchestrate sandboxes to start, stop, and resume tasks at scale. You define the workspace around the data the agent needs. It can start from GitHub repos, local files and directories, synthetic task files, remote filesystems such as S3 or Azure Blob Storage, and other sandbox inputs you provide. ![Sandbox agent harness with compute](/openai-agents-js/_astro/harness_with_compute.B0kxm8VC.png) `SandboxAgent` extends `Agent`, so it is still an `Agent`. It keeps the usual agent surface such as `instructions`, `tools`, `handoffs`, `mcpServers`, `modelSettings`, output types, guardrails, and hooks, and it still runs through the normal `run()` and `Runner` APIs. What changes is the execution boundary: * `SandboxAgent` defines the agent itself: the usual agent configuration plus sandbox-specific defaults like `defaultManifest`, `baseInstructions`, `runAs`, and capabilities such as filesystem tools, shell access, skills, memory, or compaction. * `Manifest` declares the desired starting contents and layout for a fresh sandbox workspace, including files, repos, mounts, and environment. * A sandbox session is the live execution environment where commands run and files change. * The `sandbox` run option decides how the run gets that sandbox session, for example by injecting one directly, reconnecting from serialized sandbox session state, or creating a fresh sandbox session through a sandbox client. * Saved sandbox state and snapshots let later runs reconnect to prior work or seed a fresh sandbox session from saved contents. `Manifest` defines the starting contents for a new sandbox workspace. It does not describe the current files in every live sandbox, because reused sessions, serialized session state, and snapshots can all provide or change the workspace at run time. Throughout this page, “sandbox session” means the live execution environment managed by a sandbox client. The exact boundary depends on the client: Unix-local sessions run in a local workspace on the host, while Docker and hosted clients provide stronger environment isolation. This is different from the SDK’s conversational `Session` interfaces described in [Sessions](/openai-agents-js/guides/sessions). The outer runtime still owns approvals, tracing, handoffs, and resume bookkeeping. The sandbox session owns commands, file changes, and environment isolation. That split is a core part of the model. ### How the pieces fit together [Section titled “How the pieces fit together”](#how-the-pieces-fit-together) A sandbox run combines an agent definition with per-run sandbox configuration. The runner prepares the agent, binds it to a live sandbox session, and can save state for later runs. **SandboxAgent**Agent plus sandbox defaults → **Runner**Prepare instructions and bind capability tools → **Sandbox session**Workspace where commands run and files change → **Saved state**Resume later or seed a fresh workspace Sandbox-specific defaults stay on `SandboxAgent`. Per-run sandbox-session choices stay in the `sandbox` run option. Think about the lifecycle in three phases: 1. Define the agent and starting workspace contents with `SandboxAgent`, `Manifest`, and capabilities. 2. Execute a run by giving `run()` or `Runner` a `sandbox` run option that injects, resumes, or creates the sandbox session. 3. Continue later from runner-managed `RunState`, explicit sandbox `sessionState`, or a saved workspace snapshot. If shell access is only one occasional tool, start with hosted shell in the [Tools guide](/openai-agents-js/guides/tools). Reach for sandbox agents when workspace isolation, sandbox client choice, or sandbox-session resume behavior are part of the design. ## When to use them [Section titled “When to use them”](#when-to-use-them) Sandbox agents are a good fit for workspace-centric workflows, for example: * **Coding and debugging**: orchestrate automated fixes for issue reports in a GitHub repo and run targeted tests. * **Document processing and editing**: extract information from a user’s financial documents and create a completed tax-form draft. * **File-grounded review or analysis**: check onboarding packets, generated reports, or artifact bundles before answering. * **Isolated multi-agent patterns**: give each reviewer or coding sub-agent its own workspace. * **Multi-step workspace tasks**: fix a bug in one run and add a regression test later, or resume from snapshot or sandbox session state. If you do not need access to files or a living filesystem, keep using `Agent`. If shell access is just one occasional capability, add hosted shell; if the workspace boundary itself is part of the feature, use sandbox agents. ## Choose a sandbox client [Section titled “Choose a sandbox client”](#choose-a-sandbox-client) Start with `UnixLocalSandboxClient` for local development. Move to `DockerSandboxClient` when you need container isolation or image parity. Move to a hosted provider when you need provider-managed execution. In most cases, the `SandboxAgent` definition stays the same while the sandbox client and its options change in the `sandbox` run option. See [Sandbox clients](/openai-agents-js/guides/sandbox-agents/clients) for local, Docker, hosted, and remote-mount options. ## Core pieces [Section titled “Core pieces”](#core-pieces) | Layer | Main SDK pieces | What it answers | | ------------------- | ---------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------- | | Agent definition | `SandboxAgent`, `Manifest`, capabilities | What agent will run, and what fresh-session workspace contract should it start from? | | Sandbox execution | `sandbox` run option, the sandbox client, and the live sandbox session | How does this run get a live sandbox session, and where does the work execute? | | Saved sandbox state | `RunState` sandbox payload, `sessionState`, and snapshots | How does this workflow reconnect to prior sandbox work or seed a fresh sandbox session from saved contents? | The main SDK pieces map onto those layers like this: | Piece | What it owns | Ask this question | | ---------------------- | --------------------------------------------------- | --------------------------------------------------------------------------------------------------- | | `SandboxAgent` | The agent definition | What should this agent do, and which defaults should travel with it? | | `Manifest` | Fresh-session workspace files and folders | What files and folders should be present on the filesystem when the run starts? | | `Capability` | Sandbox-native behavior | Which tools, instruction fragments, or runtime behavior should attach to this agent? | | `sandbox` run option | Per-run sandbox client and sandbox-session source | Should this run inject, resume, or create a sandbox session? | | `RunState` | Runner-managed saved sandbox state | Am I resuming a prior runner-managed workflow and carrying its sandbox state forward automatically? | | `sandbox.sessionState` | Explicit serialized sandbox session state | Do I want to resume from sandbox state I already serialized outside `RunState`? | | `sandbox.snapshot` | Saved workspace contents for fresh sandbox sessions | Should a new sandbox session start from saved files and artifacts? | A practical design order is: 1. Define the fresh-session workspace contract with a `Manifest` or manifest init object. 2. Define the agent with `SandboxAgent`. 3. Add built-in or custom capabilities. 4. Decide how each run should obtain its sandbox session in `run(agent, input, { sandbox: ... })` or `new Runner({ sandbox: ... })`. ## How a sandbox run is prepared [Section titled “How a sandbox run is prepared”](#how-a-sandbox-run-is-prepared) At run time, the runner turns that definition into a concrete sandbox-backed run: 1. It resolves the sandbox session from the `sandbox` run option. 2. It determines the effective workspace inputs for the run. 3. It lets capabilities process the resulting manifest. 4. It builds the final instructions in a fixed order: the SDK’s default sandbox prompt, or `baseInstructions` if you explicitly override it, then `instructions`, then capability instruction fragments, then any remote-mount policy text, then a rendered filesystem tree. 5. It binds capability tools to the live sandbox session and runs the prepared agent through the normal `run()` and `Runner` APIs. Sandboxing does not change what a turn means. A turn is still a model step, not a single shell command or sandbox action. There is no fixed 1:1 mapping between sandbox-side operations and turns. As a practical rule, another turn is consumed only when the agent runtime needs another model response after sandbox work has happened. ## `SandboxAgent` options [Section titled “SandboxAgent options”](#sandboxagent-options) These are the sandbox-specific options on top of the usual `Agent` fields: | Option | Best use | | ------------------ | --------------------------------------------------------------------------------------------- | | `defaultManifest` | The default workspace for fresh sandbox sessions created by the runner. | | `instructions` | Additional role, workflow, and success criteria appended after the SDK sandbox prompt. | | `baseInstructions` | Advanced escape hatch that replaces the SDK sandbox prompt. | | `capabilities` | Sandbox-native tools and behavior that should travel with this agent. | | `runAs` | User identity for model-facing sandbox tools such as shell commands, file reads, and patches. | Sandbox client choice, sandbox-session reuse, manifest override, and snapshot selection belong in the `sandbox` run option, not on the agent. ### `defaultManifest` [Section titled “defaultManifest”](#defaultmanifest) `defaultManifest` is the default workspace used when the runner creates a fresh sandbox session for this agent. Pass either a `Manifest` instance or the same init object you would pass to `new Manifest(...)`. Use it for the files, repos, helper material, output directories, and mounts the agent should usually start with. This is only the default. A run can override it with `sandbox.manifest`, and a reused or resumed sandbox session keeps its existing workspace state. Define a manifest ```typescript import { file, gitRepo, Manifest } from '@openai/agents/sandbox'; const manifest = new Manifest({ root: '/workspace', entries: { 'task.md': file({ content: 'Fix the failing test and summarize the change.', }), repo: gitRepo({ repo: 'openai/openai-agents-js', ref: 'main', }), }, environment: { NODE_ENV: 'test', }, }); ``` ### `instructions` and `baseInstructions` [Section titled “instructions and baseInstructions”](#instructions-and-baseinstructions) Use `instructions` for short rules that should survive different prompts. In a `SandboxAgent`, these instructions are appended after the SDK’s sandbox base prompt, so you keep the built-in sandbox guidance and add your own role, workflow, and success criteria. Use `baseInstructions` only when you want to replace the SDK sandbox base prompt. Most agents should not set it. | Put it in… | Use it for | Examples | | ------------------------------- | -------------------------------------------------------------------------- | ----------------------------------------------------------------------------------- | | `instructions` | Stable role, workflow rules, and success criteria for the agent. | ”Inspect onboarding documents, then hand off.”, “Write final files into `output/`.” | | `baseInstructions` | A full replacement for the SDK sandbox base prompt. | Custom low-level sandbox wrapper prompts. | | the user prompt | The one-off request for this run. | ”Summarize this workspace.” | | workspace files in the manifest | Longer task specs, repo-local instructions, or bounded reference material. | `repo/task.md`, document bundles, sample packets. | Avoid copying the user’s one-off task into `instructions`, embedding long reference material that belongs in the manifest, restating tool docs that built-in capabilities already inject, or mixing in local installation notes the model does not need at run time. ### `capabilities` [Section titled “capabilities”](#capabilities) Capabilities attach sandbox-native behavior to a `SandboxAgent`. They can shape the workspace before a run starts, append sandbox-specific instructions, expose tools that bind to the live sandbox session, and adjust model behavior or input handling for that agent. Built-in capabilities include: | Capability | Add it when | Notes | | -------------- | ---------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------- | | `shell()` | The agent needs shell access. | Adds `exec_command`, plus `write_stdin` when the sandbox client supports PTY interaction. | | `filesystem()` | The agent needs to edit files or inspect local images. | Adds `apply_patch` and `view_image`; patch paths are workspace-root-relative. | | `skills()` | You want skill discovery and materialization in the sandbox. | Prefer this over mounting `.agents` or `.agents/skills` manually for sandbox-local `SKILL.md` skills. | | `memory()` | Follow-on runs should read or generate memory artifacts. | Requires `shell()`; live updates also require `filesystem()`. | | `compaction()` | Long-running flows need context trimming after compaction items. | Adjusts model sampling and input handling. | By default, `SandboxAgent.capabilities` uses `Capabilities.default()`, which includes `filesystem()`, `shell()`, and `compaction()`. If you pass `capabilities: [...]`, that list replaces the default, so include any default capabilities you still want. ## Concepts [Section titled “Concepts”](#concepts) ### Manifest [Section titled “Manifest”](#manifest) A `Manifest` describes the workspace for a fresh sandbox session. It can set the workspace `root`, declare files and directories, copy in local files, clone Git repos, attach remote storage mounts, set environment variables, define users or groups, and grant access to specific absolute paths outside the workspace. Manifest environment values are persisted by default. Use ephemeral entries such as `{ value: "...", ephemeral: true }` for API keys, access tokens, or other short-lived credentials that should not be saved with sandbox state. Manifest entry paths are workspace-relative. They cannot be absolute paths or escape the workspace with `..`, which keeps the workspace contract portable across local, Docker, and hosted clients. Use manifest entries for the material the agent needs before work begins: | Manifest entry | Use it for | | ------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------- | | `file()`, `dir()` | Small synthetic inputs, helper files, or output directories. | | `localFile()`, `localDir()` | Host files or directories that should be materialized into the sandbox. | | `gitRepo()` | A repository that should be fetched into the workspace. | | mounts such as `s3Mount()`, `gcsMount()`, `r2Mount()`, `azureBlobMount()`, `s3FilesMount()` | External storage that should appear inside the sandbox. | For local materialization, `localFile()` and `localDir()` source paths must stay inside the local source base directory. The default base is the current working directory of your Node process, and local sandbox clients may provide a client-specific base when they materialize entries. If a source must come from another absolute host directory, add the smallest necessary `Manifest.extraPathGrants` entry. `extraPathGrants` is also used by local lazy skill discovery. A `localDirLazySkillSource()` that points outside the source base directory is ignored unless the manifest grants that directory. Prefer `readOnly: true` for input bundles such as shared skills, datasets, and reference repositories. Grant a shared local source ```typescript import { Manifest, localDir, skills } from '@openai/agents/sandbox'; import { localDirLazySkillSource } from '@openai/agents/sandbox/local'; import { dirname, join } from 'node:path'; import { fileURLToPath } from 'node:url'; const appRoot = dirname(fileURLToPath(import.meta.url)); const repoDir = join(appRoot, 'repo'); const sharedSkillsDir = '/opt/company/agent-skills'; const manifest = new Manifest({ extraPathGrants: [ { path: sharedSkillsDir, readOnly: true, description: 'Shared skill bundle.', }, ], entries: { repo: localDir({ src: repoDir }), }, }); const skillCapability = skills({ lazyFrom: localDirLazySkillSource({ src: sharedSkillsDir, }), }); ``` Mount entries describe what storage to expose; mount strategies describe how a sandbox backend attaches that storage. See [Sandbox clients](/openai-agents-js/guides/sandbox-agents/clients#mounts-and-remote-storage) for mount options and provider support. ### Permissions [Section titled “Permissions”](#permissions) `Permissions` controls filesystem permissions for manifest entries. It is about the files the sandbox materializes, not model permissions, approval policy, or API credentials. Users are the sandbox identities that can execute work. Add a user to the manifest when you want that identity to exist in the sandbox, then set `SandboxAgent.runAs` when model-facing sandbox tools such as shell commands, file reads, and patches should run as that user. If you also need file-level sharing rules, combine users with manifest groups and entry `group` metadata. The `runAs` user controls who executes sandbox-native actions; `Permissions` controls which files that user can read, write, or execute once the sandbox has materialized the workspace. ### SnapshotSpec [Section titled “SnapshotSpec”](#snapshotspec) `SnapshotSpec` tells a fresh sandbox session where saved workspace contents should be restored from and persisted back to. It is the snapshot policy for the sandbox workspace, while `sessionState` is the serialized connection state for resuming a specific sandbox backend. Use local snapshots for local durable snapshots and remote snapshots when your app provides a remote snapshot client. Mounted and ephemeral paths are not copied into snapshots as durable workspace contents. ### Sandbox lifecycle [Section titled “Sandbox lifecycle”](#sandbox-lifecycle) There are two lifecycle modes: **SDK-owned** and **developer-owned**. **SDK-owned**Runner owns the live sandbox. 1. 1 Pass `sandbox.client`. 2. 2 Runner creates or resumes a sandbox session. 3. 3 Agent runs and snapshot-backed workspace state can persist. 4. 4 Runner closes runner-owned resources. **Developer-owned**Your application owns the live sandbox. 1. 1 Create a `session`. 2. 2 Pass `sandbox.session` into the run. 3. 3 Agent uses the existing workspace. 4. 4 Inspect, reuse, then close the session yourself. Use SDK-owned lifecycle when the sandbox only needs to live for one run. Pass a `client`, optional `manifest`, optional `snapshot`, and client `options`; the runner creates or resumes the sandbox, runs the agent, persists snapshot-backed workspace state, and lets the client clean up runner-owned resources. Let the runner manage the sandbox session ```typescript import { run } from '@openai/agents'; import { SandboxAgent } from '@openai/agents/sandbox'; import { UnixLocalSandboxClient } from '@openai/agents/sandbox/local'; const agent = new SandboxAgent({ name: 'Workspace reviewer', model: 'gpt-5.5', instructions: 'Inspect the sandbox workspace before answering.', }); const result = await run(agent, 'Inspect the workspace.', { sandbox: { client: new UnixLocalSandboxClient(), }, }); console.log(result.finalOutput); ``` Use developer-owned lifecycle when you want to eagerly create a sandbox, reuse one live sandbox across multiple runs, inspect files after a run, stream over a sandbox you created yourself, or decide exactly when cleanup happens. Passing `session` tells the runner to use that live sandbox, but not to close it for you. Manage the sandbox session yourself ```typescript import { run } from '@openai/agents'; import { Manifest, SandboxAgent } from '@openai/agents/sandbox'; import { UnixLocalSandboxClient } from '@openai/agents/sandbox/local'; const manifest = new Manifest(); const agent = new SandboxAgent({ name: 'Workspace reviewer', model: 'gpt-5.5', instructions: 'Inspect the sandbox workspace before answering.', }); const client = new UnixLocalSandboxClient(); const session = await client.create({ manifest }); try { await run(agent, 'First task.', { sandbox: { session } }); await run(agent, 'Follow-up task.', { sandbox: { session } }); } finally { await session.close?.(); } ``` ## `sandbox` run options [Section titled “sandbox run options”](#sandbox-run-options) The `sandbox` run option holds the per-run options that decide where the sandbox session comes from and how a fresh session should be initialized. ### Sandbox source [Section titled “Sandbox source”](#sandbox-source) These options decide whether the runner should reuse, resume, or create the sandbox session: | Option | Use it when | Notes | | -------------- | -------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------ | | `client` | You want the runner to create, resume, and clean up sandbox sessions for you. | Required unless you provide a live sandbox `session`. | | `session` | You already created a live sandbox session yourself. | The caller owns lifecycle; the runner reuses that live sandbox session. | | `sessionState` | You have serialized sandbox session state but not a live sandbox session object. | Requires `client`; the runner resumes from that explicit state as an owning session. | ### Fresh-session inputs [Section titled “Fresh-session inputs”](#fresh-session-inputs) These options only matter when the runner is creating a fresh sandbox session: | Option | Use it when | Notes | | ---------- | --------------------------------------------------------- | ------------------------------------------------------------------------------------------------- | | `manifest` | You want a one-off fresh-session workspace override. | Accepts a `Manifest` or manifest init object. Falls back to `agent.defaultManifest` when omitted. | | `snapshot` | A fresh sandbox session should be seeded from a snapshot. | Useful for resume-like flows or remote snapshot clients. | | `options` | The sandbox client needs creation-time options. | Common for Docker images, provider timeouts, and similar client-specific settings. | `concurrencyLimits` controls how much sandbox materialization work can run in parallel. Use `manifestEntries` and `localDirFiles` when large manifests or local directory copies need tighter resource control. ### Materialization controls [Section titled “Materialization controls”](#materialization-controls) Materialization controls are intentionally per-run. Keep them near the `sandbox` run option so the same `SandboxAgent` can use conservative limits for large local directory copies and looser limits for small manifests. Use `concurrencyLimits.manifestEntries` when a manifest has many independent entries such as files, directories, repos, and mounts. Use `concurrencyLimits.localDirFiles` when `localDir()` entries contain many files and local copy pressure needs to be capped. ## Full example: coding task [Section titled “Full example: coding task”](#full-example-coding-task) This coding-style example is a good default starting point: Sandbox coding task ```typescript import { run } from '@openai/agents'; import { Capabilities, Manifest, SandboxAgent, localDir, skills, } from '@openai/agents/sandbox'; import { UnixLocalSandboxClient, localDirLazySkillSource, } from '@openai/agents/sandbox/local'; import { dirname, join } from 'node:path'; import { fileURLToPath } from 'node:url'; const exampleDir = dirname(fileURLToPath(import.meta.url)); const hostRepoDir = join(exampleDir, 'repo'); const hostSkillsDir = join(exampleDir, 'skills'); const manifest = new Manifest({ entries: { repo: localDir({ src: hostRepoDir }), }, }); const agent = new SandboxAgent({ name: 'Sandbox engineer', model: 'gpt-5.5', instructions: 'Read `repo/task.md` before editing files. Load the `$invoice-total-fixer` skill before changing code. Stay grounded in the repository, preserve existing behavior, and mention the exact verification command you ran. If you edit files with apply_patch, paths are relative to the sandbox workspace root.', defaultManifest: manifest, capabilities: [ ...Capabilities.default(), skills({ lazyFrom: localDirLazySkillSource({ src: hostSkillsDir, }), }), ], }); const result = await run( agent, 'Open `repo/task.md`, fix the issue, run the targeted test, and summarize the change.', { sandbox: { client: new UnixLocalSandboxClient(), }, }, ); console.log(result.finalOutput); ``` ## Common patterns [Section titled “Common patterns”](#common-patterns) Start from the full example above. In many cases, the same `SandboxAgent` can stay intact while only the sandbox client, sandbox-session source, or workspace source changes. ### Switch sandbox clients [Section titled “Switch sandbox clients”](#switch-sandbox-clients) Keep the agent definition the same and change only the run config. Use Docker when you want container isolation or image parity, or a hosted provider when you want provider-managed execution. See [Sandbox clients](/openai-agents-js/guides/sandbox-agents/clients) for examples and provider options. ### Override the workspace [Section titled “Override the workspace”](#override-the-workspace) Keep the agent definition the same and swap only the fresh-session manifest with `sandbox: { client, manifest }`. Use this when the same agent role should run against different repos, packets, or task bundles without rebuilding the agent. ### Inject a sandbox session [Section titled “Inject a sandbox session”](#inject-a-sandbox-session) Inject a live sandbox session when you need explicit lifecycle control, post-run inspection, or output copying. Use `sandbox: { session }` for that run, and close the session in your application code. ### Resume from session state [Section titled “Resume from session state”](#resume-from-session-state) If you already serialized sandbox state outside `RunState`, let the runner reconnect from that state with `sandbox: { client, sessionState }`. Use this when sandbox state lives in your own storage or job system and you want `Runner` to resume from it directly. ### Start from a snapshot [Section titled “Start from a snapshot”](#start-from-a-snapshot) Seed a new sandbox from saved files and artifacts with `sandbox: { client, snapshot }`. Use this when a fresh run should start from saved workspace contents rather than only `agent.defaultManifest`. ### Load skills from Git [Section titled “Load skills from Git”](#load-skills-from-git) Swap the local skill source for a repository-backed one with `skills({ from: gitRepo(...) })`. Use this when the skills bundle has its own release cadence or should be shared across sandboxes. ### Expose as tools [Section titled “Expose as tools”](#expose-as-tools) Tool-agents can either get their own sandbox boundary or reuse a live sandbox from the parent run. Reuse is useful for a fast read-only explorer agent: it can inspect the exact workspace the parent is using without paying to create, hydrate, or snapshot another sandbox. When a tool-agent needs real isolation instead, give it its own `runConfig` through `sandboxAgent.asTool(...)`. Use a separate sandbox when the tool-agent should mutate freely, run untrusted commands, or use a different backend or image. ### Combine with local tools and MCP [Section titled “Combine with local tools and MCP”](#combine-with-local-tools-and-mcp) Keep the sandbox workspace while still using ordinary tools on the same agent. Sandbox capabilities can coexist with `tools`, `mcpServers`, handoffs, model settings, and output configuration. ## Memory [Section titled “Memory”](#memory) Use the `memory()` capability when future sandbox-agent runs should learn from prior runs. Memory is separate from the SDK’s conversational `Session` memory: it distills lessons into files inside the sandbox workspace, then later runs can read those files. See [Agent memory](/openai-agents-js/guides/sandbox-agents/memory) for setup, read/generate behavior, multi-turn conversations, and layout isolation. ## Composition patterns [Section titled “Composition patterns”](#composition-patterns) Once the single-agent pattern is clear, the next design question is where the sandbox boundary belongs in a larger system. Sandbox agents still compose with the rest of the SDK: * [Handoffs](/openai-agents-js/guides/handoffs): hand document-heavy work from a non-sandbox intake agent into a sandbox reviewer. * [Agents as tools](/openai-agents-js/guides/tools#agents-as-tools): expose multiple sandbox agents as tools, usually by passing a sandbox run config on each `asTool(...)` call so each tool gets its own sandbox boundary. * [MCP](/openai-agents-js/guides/mcp) and normal function tools: sandbox capabilities can coexist with `mcpServers` and ordinary tools. * [Running agents](/openai-agents-js/guides/running-agents): sandbox runs still use the normal `run()` and `Runner` APIs. With a handoff, there is still one top-level run and one top-level turn loop. The active agent changes, but the run does not become nested. With `asTool(...)`, the relationship is different. The outer orchestrator uses one outer turn to decide to call the tool, and that tool call starts a nested run for the sandbox agent. The nested run has its own turn loop, `maxTurns`, approvals, and usually its own sandbox run config. From the outer orchestrator’s point of view, all of that work still sits behind one tool invocation, so the nested turns do not increment the outer run’s turn counter. ## Further reading [Section titled “Further reading”](#further-reading) * [Quickstart](/openai-agents-js/guides/sandbox-agents): get one sandbox agent running. * [Sandbox clients](/openai-agents-js/guides/sandbox-agents/clients): choose local, Docker, hosted, and mount options. * [Agent memory](/openai-agents-js/guides/sandbox-agents/memory): preserve and reuse lessons from prior sandbox runs. # Agent memory > Preserve and reuse lessons from previous sandbox-agent runs. Memory lets future sandbox-agent runs learn from prior runs. It is separate from the SDK’s conversational [Session](/openai-agents-js/guides/sessions) memory, which stores message history. Memory distills lessons from prior runs into files in the sandbox workspace, so treat generated memory artifacts as retained data and apply the same sensitivity and retention policy you use for the workspace. Beta feature Sandbox agents are in beta. API details, defaults, and supported capabilities may change before general availability, and more advanced features are expected over time. Memory can reduce three kinds of cost for future runs: 1. Agent cost: If the agent took a long time to complete a workflow, the next run should need less exploration. This can reduce token usage and time to completion. 2. User cost: If the user corrected the agent or expressed a preference, future runs can remember that feedback. This can reduce human intervention. 3. Context cost: If the agent completed a task before, and the user wants to build on that task, the user should not need to find the previous thread or re-type all the context. This makes task descriptions shorter. ## Enable memory [Section titled “Enable memory”](#enable-memory) Add `memory()` as a capability to the sandbox agent. Enable memory ```typescript import { filesystem, Manifest, memory, SandboxAgent, shell, } from '@openai/agents/sandbox'; const manifest = new Manifest({ entries: { 'README.md': { type: 'file', content: '# Memory demo\n\nA workspace for follow-up runs.\n', }, }, }); const agent = new SandboxAgent({ name: 'Memory-enabled reviewer', model: 'gpt-5.5', instructions: 'Inspect the workspace, verify important claims, and preserve useful lessons for follow-up runs.', defaultManifest: manifest, capabilities: [filesystem(), shell(), memory()], }); ``` If read is enabled, `memory()` requires `shell()`, which lets the agent read and search memory files when the injected summary is not enough. When live memory update is enabled by default, it also requires `filesystem()`, which lets the agent update `memories/MEMORY.md` if the agent discovers stale memory or the user asks it to update memory. By default, memory artifacts are stored in the sandbox workspace under `memories/`. To reuse them in a later run, preserve and reuse the whole configured memories directory by keeping the same live sandbox session or resuming from a persisted session state or snapshot; a fresh empty sandbox starts with empty memory. `memory()` enables both reading and generating memories. Use `memory({ generate: false })` for agents that should read memory but should not generate new memories: for example, an internal agent, subagent, checker, or one-off tool agent whose run does not add much signal. Use `memory({ read: null })` when the run should generate memory for later, but the user does not want the run to be influenced by existing memory. Configure read-only memory ```typescript import { memory } from '@openai/agents/sandbox'; const readOnlyMemory = memory({ read: { liveUpdate: false }, generate: false, }); ``` ## Read memory [Section titled “Read memory”](#read-memory) Memory reads use progressive disclosure. At the start of a run, the SDK injects a small summary (`memory_summary.md`) of generally useful tips, user preferences, and available memories into the agent’s developer prompt. This gives the agent enough context to decide whether prior work may be relevant. When prior work looks relevant, the agent searches the configured memory index (`MEMORY.md` under `memoriesDir`) for keywords from the current task. It opens the corresponding prior rollout summaries under the configured `rollout_summaries/` directory only when the task needs more detail. Memory can become stale. Agents are instructed to treat memories as guidance only and trust the current environment. By default, memory reads have `liveUpdate` enabled, so if the agent discovers stale memory, it can update the configured `MEMORY.md` in the same run. Disable live updates when the agent should read memory but not modify it during the run, for example if the run is latency sensitive. ## Generate memory [Section titled “Generate memory”](#generate-memory) After a run finishes, the sandbox runtime appends that run segment to a conversation file. Accumulated conversation files are processed when the sandbox session closes. These conversation files can include user input, assistant and tool items, interruptions, and final outputs, so use an appropriate memory store and retention policy for sensitive workloads. Memory generation has two phases: 1. Phase 1: conversation extraction. A memory-generating model processes one accumulated conversation file and generates a conversation summary. System, developer, and reasoning content are omitted. If the conversation is too long, it is truncated to fit within the context window, with the beginning and end preserved. It also generates a raw memory extract: compact notes from the conversation that Phase 2 can consolidate. 2. Phase 2: layout consolidation. A consolidation agent reads raw memories for one memory layout, opens conversation summaries when more evidence is needed, and extracts patterns into `MEMORY.md` and `memory_summary.md`. The default workspace layout is: ```text workspace/ ├── sessions/ │ └── .jsonl └── memories/ ├── memory_summary.md ├── MEMORY.md ├── raw_memories.md ├── raw_memories/ └── rollout_summaries/ ``` You can configure memory generation with `memory({ generate: ... })`: Configure memory generation ```typescript import { memory } from '@openai/agents/sandbox'; const memoryCapability = memory({ generate: { maxRawMemoriesForConsolidation: 128, phaseOneModel: 'gpt-5.4-mini', phaseTwoModel: 'gpt-5.4', extraPrompt: 'Prioritize workflow corrections, verification commands, and user preferences.', }, }); ``` Use `extraPrompt` to tell the memory generator which signals matter most for your use case, such as customer and company details for a GTM agent. If recent raw memories exceed `maxRawMemoriesForConsolidation`, Phase 2 keeps only memories from the newest conversations and removes older ones. Recency is based on the last time the conversation is updated. This forgetting mechanism helps memories reflect the newest environment. ## Multi-turn conversations [Section titled “Multi-turn conversations”](#multi-turn-conversations) For multi-turn sandbox chats, use the normal SDK `Session` together with the same live sandbox session: Use one SDK session with one sandbox session ```typescript import { MemorySession, run } from '@openai/agents'; import { filesystem, Manifest, memory, SandboxAgent, shell, } from '@openai/agents/sandbox'; import { UnixLocalSandboxClient } from '@openai/agents/sandbox/local'; const manifest = new Manifest(); const agent = new SandboxAgent({ name: 'Memory-enabled reviewer', model: 'gpt-5.5', instructions: 'Inspect the workspace before answering.', capabilities: [filesystem(), shell(), memory()], }); const conversation = new MemorySession({ sessionId: 'workspace-review' }); const sandbox = await new UnixLocalSandboxClient().create({ manifest }); try { await run(agent, 'Analyze data/leads.csv.', { session: conversation, sandbox: { session: sandbox }, }); await run(agent, 'Write a follow-up recommendation.', { session: conversation, sandbox: { session: sandbox }, }); } finally { await sandbox.close?.(); } ``` Both runs append to one memory conversation file because they pass the same SDK conversation session and therefore share the same session id. This is different from the sandbox, which identifies the live workspace and is not used as the memory conversation ID. Phase 1 sees the accumulated conversation when the sandbox session closes, so it can extract memory from the whole exchange instead of two isolated turns. If you want multiple `run(...)` calls to become one memory conversation, pass a stable identifier across those calls. When memory associates a run with a conversation, it resolves in this order: 1. `conversationId`, when you pass one to `run(...)`. 2. the SDK `session` id, when you pass an SDK `Session`. 3. `groupId`, when neither of the above is present. 4. a generated per-run ID, when no stable identifier is present. ## Use different layouts to isolate memory for different agents [Section titled “Use different layouts to isolate memory for different agents”](#use-different-layouts-to-isolate-memory-for-different-agents) Memory isolation is based on `MemoryLayoutConfig`, not on agent name. Agents with the same layout and the same memory conversation ID share one memory conversation and one consolidated memory. Agents with different layouts keep separate rollout files, raw memories, `MEMORY.md`, and `memory_summary.md`, even when they share the same sandbox workspace. Use separate layouts when multiple agents share one sandbox but should not share memory: Use separate memory layouts ```typescript import { memory } from '@openai/agents/sandbox'; const engineeringMemory = memory({ layout: { memoriesDir: 'memories/engineering', sessionsDir: 'sessions/engineering', }, }); const financeMemory = memory({ layout: { memoriesDir: 'memories/finance', sessionsDir: 'sessions/finance', }, }); ``` This prevents one domain’s analysis from being consolidated into another domain’s memory, and vice versa. # Sessions > Persist multi-turn conversation history so agents can resume context across runs. Sessions give the Agents SDK a **persistent memory layer**. Provide any object that implements the `Session` interface to `Runner.run`, and the SDK handles the rest. When a session is present, the runner automatically: 1. Fetches previously stored conversation items and prepends them to the next turn. 2. Persists new user input and assistant output after each run completes. 3. Keeps the session available for future turns, whether you call the runner with new user text or resume from an interrupted `RunState`. This removes the need to manually call `toInputList()` or stitch history between turns. The TypeScript SDK ships with two implementations: `OpenAIConversationsSession` for the Conversations API and `MemorySession`, which is intended for local development. Because they share the `Session` interface, you can plug in your own storage backend. For inspiration beyond the Conversations API, explore the sample session backends under `examples/memory/` (Prisma, file-backed, and more). When you use an OpenAI Responses model, wrap any session with `OpenAIResponsesCompactionSession` to automatically shrink stored conversation history via [`responses.compact`](https://platform.openai.com/docs/api-reference/responses/compact). > Tip: To run the `OpenAIConversationsSession` examples on this page, set the `OPENAI_API_KEY` environment variable (or provide an `apiKey` when constructing the session) so the SDK can call the Conversations API. Use sessions when you want the SDK to manage client-side memory for you. If you are already using OpenAI server-managed state with `conversationId` or `previousResponseId`, you usually do not also need a session for the same conversation history. *** ## Getting started [Section titled “Getting started”](#getting-started) ### Quick start [Section titled “Quick start”](#quick-start) Use `OpenAIConversationsSession` to sync memory with the [Conversations API](https://platform.openai.com/docs/api-reference/conversations), or swap in any other `Session` implementation. Use the Conversations API as session memory ```typescript import { Agent, OpenAIConversationsSession, run } from '@openai/agents'; const agent = new Agent({ name: 'TourGuide', instructions: 'Answer with compact travel facts.', }); // Any object that implements the Session interface works here. This example uses // the built-in OpenAIConversationsSession, but you can swap in a custom Session. const session = new OpenAIConversationsSession(); const firstTurn = await run(agent, 'What city is the Golden Gate Bridge in?', { session, }); console.log(firstTurn.finalOutput); // "San Francisco" const secondTurn = await run(agent, 'What state is it in?', { session }); console.log(secondTurn.finalOutput); // "California" ``` Reusing the same session instance ensures the agent receives the full conversation history before every turn and automatically persists new items. Switching to a different `Session` implementation requires no other code changes. For local demos, tests, or process-local chat state, `MemorySession` provides the same interface without talking to OpenAI: Use MemorySession for local state ```typescript import { Agent, MemorySession, run } from '@openai/agents'; const agent = new Agent({ name: 'TourGuide', instructions: 'Answer with compact travel facts.', }); const session = new MemorySession(); const result = await run(agent, 'What city is the Golden Gate Bridge in?', { session, }); console.log(result.finalOutput); ``` `OpenAIConversationsSession` constructor options: | Option | Type | Notes | | ---------------- | -------- | -------------------------------------------------------------- | | `conversationId` | `string` | Reuse an existing conversation instead of creating one lazily. | | `client` | `OpenAI` | Pass a preconfigured OpenAI client. | | `apiKey` | `string` | API key used when creating an internal OpenAI client. | | `baseURL` | `string` | Base URL for OpenAI-compatible endpoints. | | `organization` | `string` | OpenAI organization ID for requests. | | `project` | `string` | OpenAI project ID for requests. | `MemorySession` constructor options: | Option | Type | Notes | | -------------- | ------------------ | ------------------------------------------------------------------------ | | `sessionId` | `string` | Stable identifier for logs or tests. Generated automatically by default. | | `initialItems` | `AgentInputItem[]` | Seed the session with existing history. | | `logger` | `Logger` | Override the logger used for debug output. | `MemorySession` stores everything in local process memory, so it is reset when your process exits. If you need to pre-create a conversation ID before constructing the session, use `startOpenAIConversationsSession(client?)` and pass the returned ID as `conversationId`. *** ## Core session behavior [Section titled “Core session behavior”](#core-session-behavior) ### How the runner uses sessions [Section titled “How the runner uses sessions”](#how-the-runner-uses-sessions) * **Before each run** it retrieves the session history, merges it with the new turn’s input, and passes the combined list to your agent. * **After a non-streaming run** one call to `session.addItems()` persists both the original user input and the model outputs from the latest turn. * **For streaming runs** it writes the user input first and appends streamed outputs once the turn completes. * **When resuming from `RunResult.state`** (for approvals or other interruptions) keep passing the same `session`. The resumed turn is added to memory without re-preparing the input. *** ### Inspecting and editing history [Section titled “Inspecting and editing history”](#inspecting-and-editing-history) Sessions expose simple CRUD helpers so you can build “undo”, “clear chat”, or audit features. Read and edit stored items ```typescript import { OpenAIConversationsSession } from '@openai/agents'; import type { AgentInputItem } from '@openai/agents-core'; // Replace OpenAIConversationsSession with any other Session implementation that // supports get/add/pop/clear if you store history elsewhere. const session = new OpenAIConversationsSession({ conversationId: 'conv_123', // Resume an existing conversation if you have one. }); const history = await session.getItems(); console.log(`Loaded ${history.length} prior items.`); const followUp: AgentInputItem[] = [ { type: 'message', role: 'user', content: [{ type: 'input_text', text: 'Let’s continue later.' }], }, ]; await session.addItems(followUp); const undone = await session.popItem(); if (undone?.type === 'message') { console.log(undone.role); // "user" } await session.clearSession(); ``` `session.getItems()` returns the stored `AgentInputItem[]`. Call `popItem()` to remove the last entry—useful for user corrections before you rerun the agent. *** ## Custom storage and merge behavior [Section titled “Custom storage and merge behavior”](#custom-storage-and-merge-behavior) ### Bring your own storage [Section titled “Bring your own storage”](#bring-your-own-storage) Implement the `Session` interface to back memory with Redis, DynamoDB, SQLite, or another datastore. Only five asynchronous methods are required. Custom in-memory session implementation ```typescript import { Agent, run } from '@openai/agents'; import { randomUUID } from '@openai/agents-core/_shims'; import { getLogger } from '@openai/agents-core'; import type { AgentInputItem, Session } from '@openai/agents-core'; /** * Minimal example of a Session implementation; swap this class for any storage-backed version. */ export class CustomMemorySession implements Session { private readonly sessionId: string; private readonly logger: ReturnType; private items: AgentInputItem[]; constructor( options: { sessionId?: string; initialItems?: AgentInputItem[]; logger?: ReturnType; } = {}, ) { this.sessionId = options.sessionId ?? randomUUID(); this.items = options.initialItems ? options.initialItems.map(cloneAgentItem) : []; this.logger = options.logger ?? getLogger('openai-agents:memory-session'); } async getSessionId(): Promise { return this.sessionId; } async getItems(limit?: number): Promise { if (limit === undefined) { const cloned = this.items.map(cloneAgentItem); this.logger.debug( `Getting items from memory session (${this.sessionId}): ${JSON.stringify(cloned)}`, ); return cloned; } if (limit <= 0) { return []; } const start = Math.max(this.items.length - limit, 0); const items = this.items.slice(start).map(cloneAgentItem); this.logger.debug( `Getting items from memory session (${this.sessionId}): ${JSON.stringify(items)}`, ); return items; } async addItems(items: AgentInputItem[]): Promise { if (items.length === 0) { return; } const cloned = items.map(cloneAgentItem); this.logger.debug( `Adding items to memory session (${this.sessionId}): ${JSON.stringify(cloned)}`, ); this.items = [...this.items, ...cloned]; } async popItem(): Promise { if (this.items.length === 0) { return undefined; } const item = this.items[this.items.length - 1]; const cloned = cloneAgentItem(item); this.logger.debug( `Popping item from memory session (${this.sessionId}): ${JSON.stringify(cloned)}`, ); this.items = this.items.slice(0, -1); return cloned; } async clearSession(): Promise { this.logger.debug(`Clearing memory session (${this.sessionId})`); this.items = []; } } function cloneAgentItem(item: T): T { return structuredClone(item); } const agent = new Agent({ name: 'MemoryDemo', instructions: 'Remember the running total.', }); // Using the above custom memory session implementation here const session = new CustomMemorySession({ sessionId: 'session-123-4567', }); const first = await run(agent, 'Add 3 to the total.', { session }); console.log(first.finalOutput); const second = await run(agent, 'Add 4 more.', { session }); console.log(second.finalOutput); ``` Custom sessions let you enforce retention policies, add encryption, or attach metadata to each conversation turn before persisting it. *** ### Control how history and new items merge [Section titled “Control how history and new items merge”](#control-how-history-and-new-items-merge) When you pass an array of `AgentInputItem`s as the run input, provide a `sessionInputCallback` to merge them with stored history deterministically. The runner loads the existing history, calls your callback **before the model invocation**, and hands the returned array to the model as the turn’s complete input. This hook is ideal for trimming old items, deduplicating tool results, or highlighting only the context you want the model to see. Truncate history with sessionInputCallback ```typescript import { Agent, OpenAIConversationsSession, run } from '@openai/agents'; import type { AgentInputItem } from '@openai/agents-core'; const agent = new Agent({ name: 'Planner', instructions: 'Track outstanding tasks before responding.', }); // Any Session implementation can be passed here; customize storage as needed. const session = new OpenAIConversationsSession(); const todoUpdate: AgentInputItem[] = [ { type: 'message', role: 'user', content: [ { type: 'input_text', text: 'Add booking a hotel to my todo list.' }, ], }, ]; await run(agent, todoUpdate, { session, // function that combines session history with new input items before the model call sessionInputCallback: (history, newItems) => { const recentHistory = history.slice(-8); return [...recentHistory, ...newItems]; }, }); ``` For string inputs the runner merges history automatically, so the callback is optional. The callback only runs when your turn input is already an item array. If you are also using `conversationId` or `previousResponseId`, keep at least one new item from the current turn in the callback result. Those server-managed APIs depend on the current-turn delta. If the callback drops every new item, the SDK restores the original new inputs and logs a warning instead of sending an empty delta. *** ## Resumable runs [Section titled “Resumable runs”](#resumable-runs) ### Handling approvals and resumable runs [Section titled “Handling approvals and resumable runs”](#handling-approvals-and-resumable-runs) Human-in-the-loop flows often pause a run to wait for approval: Resume a run with the same session ```typescript import { Agent, MemorySession, Runner } from '@openai/agents'; const agent = new Agent({ name: 'Trip Planner', instructions: 'Plan trips and ask for approval before booking anything.', }); const runner = new Runner(); const session = new MemorySession(); const result = await runner.run(agent, 'Search the itinerary', { session, }); if (result.interruptions?.length) { // ... collect user feedback, then resume the agent in a later turn. for (const interruption of result.interruptions) { result.state.approve(interruption); } const continuation = await runner.run(agent, result.state, { session }); console.log(continuation.finalOutput); } ``` When you resume from a previous `RunState`, the new turn is appended to the same memory record to preserve a single conversation history. Human-in-the-loop (HITL) flows stay fully compatible—approval checkpoints still round-trip through `RunState` while the session keeps the conversation history complete. *** ## Advanced: history compaction [Section titled “Advanced: history compaction”](#advanced-history-compaction) ### Compact OpenAI Responses history automatically [Section titled “Compact OpenAI Responses history automatically”](#compact-openai-responses-history-automatically) `OpenAIResponsesCompactionSession` decorates any `Session` and uses the OpenAI Responses API to replace a long stored history with a shorter equivalent list of conversation items. After each persisted turn the runner passes the latest `responseId` into `runCompaction`, which calls `responses.compact` when your decision hook returns true. Depending on `compactionMode`, the request is built either from the latest Responses API chain or from the session’s current items. The default trigger compacts once at least 10 non-user items have accumulated; override `shouldTriggerCompaction` to base the decision on token counts or custom heuristics. After compaction returns, the decorator clears the underlying session and rewrites it with the reduced item list, so avoid pairing it with `OpenAIConversationsSession`, which uses a different server-managed history flow. Decorate a session with OpenAIResponsesCompactionSession ```typescript import { Agent, MemorySession, OpenAIResponsesCompactionSession, run, } from '@openai/agents'; const agent = new Agent({ name: 'Support', instructions: 'Answer briefly and keep track of prior context.', model: 'gpt-5.4', }); // Wrap any Session to trigger responses.compact once history grows beyond your threshold. const session = new OpenAIResponsesCompactionSession({ // You can pass any Session implementation except OpenAIConversationsSession underlyingSession: new MemorySession(), // (optional) The model used for calling responses.compact API model: 'gpt-5.4', // (optional) your custom logic here shouldTriggerCompaction: ({ compactionCandidateItems }) => { return compactionCandidateItems.length >= 12; }, }); await run(agent, 'Summarize order #8472 in one sentence.', { session }); await run(agent, 'Remind me of the shipping address.', { session }); // Compaction runs automatically after each persisted turn. You can also force it manually. await session.runCompaction({ force: true }); ``` `OpenAIResponsesCompactionSession` constructor options: | Option | Type | Notes | | ------------------------- | --------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `client` | `OpenAI` | OpenAI client used for `responses.compact`. | | `underlyingSession` | `Session` | Backing session store to clear/rewrite with compacted items. Defaults to an in-memory session for demos and must not be `OpenAIConversationsSession`. | | `model` | `OpenAI.ResponsesModel` | Model used for compaction requests. Defaults to the SDK’s current default OpenAI model. | | `compactionMode` | `'auto' \| 'previous_response_id' \| 'input'` | Controls whether compaction uses server response chaining or local input items. | | `shouldTriggerCompaction` | `(context) => boolean \| Promise` | Custom trigger hook based on `responseId`, `compactionMode`, candidate items, and current session items. | `compactionMode: 'previous_response_id'` is useful when you are already chaining turns with Responses API response IDs. `compactionMode: 'input'` rebuilds compaction requests from the current session items instead, which is helpful when the response chain is unavailable or you want the underlying session contents to be the source of truth. `runCompaction(args)` options: | Option | Type | Notes | | ---------------- | --------------------------------------------- | ----------------------------------------------------------------- | | `responseId` | `string` | Latest Responses API response id for `previous_response_id` mode. | | `compactionMode` | `'auto' \| 'previous_response_id' \| 'input'` | Optional per-call override of the configured mode. | | `store` | `boolean` | Indicates whether the last run stored server state. | | `force` | `boolean` | Bypass `shouldTriggerCompaction` and compact immediately. | #### Manual compaction for low-latency streaming [Section titled “Manual compaction for low-latency streaming”](#manual-compaction-for-low-latency-streaming) Compaction clears and rewrites the underlying session, so the SDK waits for it before resolving a streaming run. If compaction is heavy, `result.completed` can stay pending for a few seconds after the last output token. For low-latency streaming or faster turn-taking, disable auto-compaction and call `runCompaction` yourself between turns (or during idle time). Disable auto-compaction and compact between turns ```typescript import { Agent, MemorySession, OpenAIResponsesCompactionSession, run, } from '@openai/agents'; const agent = new Agent({ name: 'Support', instructions: 'Answer briefly and keep track of prior context.', model: 'gpt-5.4', }); // Disable auto-compaction to avoid delaying stream completion. const session = new OpenAIResponsesCompactionSession({ underlyingSession: new MemorySession(), shouldTriggerCompaction: () => false, }); const result = await run(agent, 'Share the latest ticket update.', { session, stream: true, }); // Wait for the streaming run to finish before compacting. await result.completed; // Choose force based on your own thresholds or heuristics, between turns or during idle time. await session.runCompaction({ force: true }); ``` You can call `runCompaction({ force: true })` at any time to shrink history before archiving or handoff. Enable debug logs with `DEBUG=openai-agents:openai:compaction` to trace compaction decisions. # Streaming > Stream agent output in real time using the Runner The Agents SDK can deliver output from the model and other execution steps incrementally. Streaming keeps your UI responsive and avoids waiting for the entire final result before updating the user. ## Enabling streaming [Section titled “Enabling streaming”](#enabling-streaming) Pass a `{ stream: true }` option to `Runner.run()` to obtain a streaming object rather than a full result: Enabling streaming ```typescript import { Agent, run } from '@openai/agents'; const agent = new Agent({ name: 'Storyteller', instructions: 'You are a storyteller. You will be given a topic and you will tell a story about it.', }); const result = await run(agent, 'Tell me a story about a cat.', { stream: true, }); ``` When streaming is enabled the returned `stream` implements the `AsyncIterable` interface. Each yielded event is an object describing what happened within the run. The stream yields one of three event types, each describing a different part of the agent’s execution. Most applications only want the model’s text though, so the stream provides helpers. ### Get the text output [Section titled “Get the text output”](#get-the-text-output) Call `stream.toTextStream()` to obtain a stream of the emitted text. When `compatibleWithNodeStreams` is `true` the return value is a regular Node.js `Readable`. We can pipe it directly into `process.stdout` or another destination. Logging out the text as it arrives ```typescript import { Agent, run } from '@openai/agents'; const agent = new Agent({ name: 'Storyteller', instructions: 'You are a storyteller. You will be given a topic and you will tell a story about it.', }); const result = await run(agent, 'Tell me a story about a cat.', { stream: true, }); result .toTextStream({ compatibleWithNodeStreams: true, }) .pipe(process.stdout); ``` The promise `stream.completed` resolves once the run and all pending callbacks are completed. Always await it if you want to ensure there is no more output. This includes post-processing work such as session persistence or history compaction hooks that finish after the last text token arrives. `toTextStream()` only emits assistant text. Tool calls, handoffs, approvals, and other runtime events are available from the full event stream. ### Listen to all events [Section titled “Listen to all events”](#listen-to-all-events) You can use a `for await` loop to inspect each event as it arrives. Useful information includes low level model events, any agent switches and SDK specific run information: Listening to all events ```typescript import { Agent, run } from '@openai/agents'; const agent = new Agent({ name: 'Storyteller', instructions: 'You are a storyteller. You will be given a topic and you will tell a story about it.', }); const result = await run(agent, 'Tell me a story about a cat.', { stream: true, }); for await (const event of result) { // these are the raw events from the model if (event.type === 'raw_model_stream_event') { console.log(`${event.type} %o`, event.data); } // agent updated events if (event.type === 'agent_updated_stream_event') { console.log(`${event.type} %s`, event.agent.name); } // Agent SDK specific events if (event.type === 'run_item_stream_event') { console.log(`${event.type} %o`, event.item); } } ``` See [the streamed example](https://github.com/openai/openai-agents-js/tree/main/examples/agent-patterns/streamed.ts) for a fully worked script that prints both the plain text stream and the raw event stream. ### Responses WebSocket transport (optional) [Section titled “Responses WebSocket transport (optional)”](#responses-websocket-transport-optional) The streaming APIs on this page also work with the OpenAI Responses WebSocket transport. Enable it globally with `setOpenAIResponsesTransport('websocket')`, or use your own `OpenAIProvider` with `useResponsesWebSocket: true`. You do not need `withResponsesWebSocketSession(...)` or a custom `OpenAIProvider` just to stream over WebSocket. If reconnecting between runs is acceptable, `run()` / `Runner.run(..., { stream: true })` still works after enabling the transport. Use `withResponsesWebSocketSession(...)` or a custom `OpenAIProvider` / `Runner` when you want connection reuse and more explicit provider lifecycle control. Continuation with `previousResponseId` uses the same semantics as the HTTP transport. The difference is just the transport and connection lifecycle. If you build the provider yourself, remember to call `await provider.close()` when shutting down. Websocket-backed model wrappers are cached for reuse by default, and closing the provider releases those connections. `withResponsesWebSocketSession(...)` gives you the same reuse but scopes cleanup to a single callback automatically. See [`examples/basic/stream-ws.ts`](https://github.com/openai/openai-agents-js/tree/main/examples/basic/stream-ws.ts) for a complete example with streaming, tool calls, approvals, and `previousResponseId`. ## Event types [Section titled “Event types”](#event-types) The stream yields three different event types: ### raw\_model\_stream\_event [Section titled “raw\_model\_stream\_event”](#raw_model_stream_event) RunRawModelStreamEvent ```typescript import { isOpenAIChatCompletionsRawModelStreamEvent, isOpenAIResponsesRawModelStreamEvent, type RunStreamEvent, } from '@openai/agents'; export function logOpenAIRawModelEvent(event: RunStreamEvent) { if (isOpenAIResponsesRawModelStreamEvent(event)) { console.log(event.source); console.log(event.data.event.type); return; } if (isOpenAIChatCompletionsRawModelStreamEvent(event)) { console.log(event.source); console.log(event.data.event.object); } } ``` Example: ```json { "type": "raw_model_stream_event", "data": { "type": "output_text_delta", "delta": "Hello" } } ``` If you are using the OpenAI provider, `@openai/agents-openai` and `@openai/agents` both export helpers that narrow raw OpenAI payloads without changing the generic `RunRawModelStreamEvent` contract in `agents-core`. Narrow OpenAI raw model events ```typescript import type { RunStreamEvent } from '@openai/agents'; import { isOpenAIResponsesRawModelStreamEvent } from '@openai/agents'; export function isOpenAIResponsesTextDelta(event: RunStreamEvent): boolean { return ( isOpenAIResponsesRawModelStreamEvent(event) && event.data.event.type === 'response.output_text.delta' ); } ``` When you only need transport-agnostic streaming code, checking `event.type === 'raw_model_stream_event'` is still enough. If you are using OpenAI models and want to inspect provider-specific payloads without manual casts, the SDK also exports narrowing helpers: * `isOpenAIResponsesRawModelStreamEvent(event)` for Responses raw events. * `isOpenAIChatCompletionsRawModelStreamEvent(event)` for Chat Completions chunks. For these OpenAI model events, `RunRawModelStreamEvent.source` is also populated with either `'openai-responses'` or `'openai-chat-completions'`. This is especially useful when you want to inspect Responses-only events such as `response.reasoning_summary_text.delta`, `response.output_item.done`, or MCP argument deltas while keeping TypeScript aware of the underlying event shape. See [`examples/basic/stream-ws.ts`](https://github.com/openai/openai-agents-js/tree/main/examples/basic/stream-ws.ts), [`examples/tools/code-interpreter.ts`](https://github.com/openai/openai-agents-js/tree/main/examples/tools/code-interpreter.ts), and [`examples/connectors/index.ts`](https://github.com/openai/openai-agents-js/tree/main/examples/connectors) for fuller OpenAI-specific streaming patterns. ### run\_item\_stream\_event [Section titled “run\_item\_stream\_event”](#run_item_stream_event) RunItemStreamEvent ```typescript import type { RunItemStreamEvent, RunStreamEvent } from '@openai/agents'; export function isRunItemStreamEvent( event: RunStreamEvent, ): event is RunItemStreamEvent { return event.type === 'run_item_stream_event'; } ``` `name` identifies which kind of item was produced: | `name` | Meaning | | ---------------------------- | --------------------------------------------------------------------- | | `message_output_created` | A message output item was created. | | `handoff_requested` | The model requested a handoff. | | `handoff_occurred` | The runtime completed a handoff to another agent. | | `tool_search_called` | A `tool_search_call` item was emitted. | | `tool_search_output_created` | A `tool_search_output` item with loaded tool definitions was emitted. | | `tool_called` | A tool call item was emitted. | | `tool_output` | A tool result item was emitted. | | `reasoning_item_created` | A reasoning item was emitted. | | `tool_approval_requested` | A tool call paused for human approval. | The `tool_search_*` events only appear on Responses runs that use `toolSearchTool()` to load deferred tools during the run. Example handoff payload: ```json { "type": "run_item_stream_event", "name": "handoff_occurred", "item": { "type": "handoff_call", "id": "h1", "status": "completed", "name": "transfer_to_refund_agent" } } ``` ### agent\_updated\_stream\_event [Section titled “agent\_updated\_stream\_event”](#agent_updated_stream_event) RunAgentUpdatedStreamEvent ```typescript import type { RunAgentUpdatedStreamEvent, RunStreamEvent, } from '@openai/agents'; export function isRunAgentUpdatedStreamEvent( event: RunStreamEvent, ): event is RunAgentUpdatedStreamEvent { return event.type === 'agent_updated_stream_event'; } ``` Example: ```json { "type": "agent_updated_stream_event", "agent": { "name": "Refund Agent" } } ``` ## Human in the loop while streaming [Section titled “Human in the loop while streaming”](#human-in-the-loop-while-streaming) Streaming is compatible with handoffs that pause execution (for example when a tool requires approval). The `interruptions` field on the stream object exposes the pending approvals, and you can continue execution by calling `state.approve()` or `state.reject()` for each of them. After the stream pauses, `stream.completed` resolves and `stream.interruptions` contains the approvals to handle. Executing again with `{ stream: true }` resumes streaming output. Handling human approval while streaming ```typescript import { Agent, run } from '@openai/agents'; const agent = new Agent({ name: 'Storyteller', instructions: 'You are a storyteller. You will be given a topic and you will tell a story about it.', }); let stream = await run( agent, 'What is the weather in San Francisco and Oakland?', { stream: true }, ); stream.toTextStream({ compatibleWithNodeStreams: true }).pipe(process.stdout); await stream.completed; while (stream.interruptions?.length) { console.log( 'Human-in-the-loop: approval required for the following tool calls:', ); const state = stream.state; for (const interruption of stream.interruptions) { const approved = confirm( `Agent ${interruption.agent.name} would like to use the tool ${interruption.name} with "${interruption.arguments}". Do you approve?`, ); if (approved) { state.approve(interruption); } else { state.reject(interruption); } } // Resume execution with streaming output stream = await run(agent, state, { stream: true }); const textStream = stream.toTextStream({ compatibleWithNodeStreams: true }); textStream.pipe(process.stdout); await stream.completed; } ``` A fuller example that interacts with the user is [`human-in-the-loop-stream.ts`](https://github.com/openai/openai-agents-js/tree/main/examples/agent-patterns/human-in-the-loop-stream.ts). ## Stop a stream and continue the same turn [Section titled “Stop a stream and continue the same turn”](#stop-a-stream-and-continue-the-same-turn) To stop a streaming run early, abort the `signal` you passed to `run()` or cancel a reader created from `stream.toStream()`. Either way, still await `stream.completed` before treating the run as settled. The SDK may still be persisting the current turn input or finishing other cleanup after your code stops consuming events. When a stream is cancelled, `stream.cancelled` becomes `true`, and `stream.finalOutput` often remains `undefined` because the current turn never finished. If you want to continue that unfinished turn later, rerun the same agent with `stream.state` instead of appending a fresh user message. That keeps turn counting correct and reuses any `conversationId` or `previousResponseId` already stored in the `RunState`. If you are also using session persistence, pass the same `session` again on the resumed `run()` call so the conversation keeps writing to the same backing store. Approval pauses follow the same rule: resolve `stream.interruptions`, then resume from `stream.state` rather than starting a new turn. ## Tips [Section titled “Tips”](#tips) * Remember to wait for `stream.completed` before exiting to ensure all output has been flushed. * The initial `{ stream: true }` option only applies to the call where it is provided. If you re-run with a `RunState` you must specify the option again. * If your application only cares about the textual result prefer `toTextStream()` to avoid dealing with individual event objects. With streaming and the event system you can integrate an agent into a chat interface, terminal application or any place where users benefit from incremental updates. # Tools > Provide your agents with capabilities via hosted tools or custom function tools Tools let an Agent **take actions** – fetch data, call external APIs, execute code, or even use a computer. The JavaScript/TypeScript SDK supports seven categories: > Read this page after [Agents](/openai-agents-js/guides/agents) once you know which agent should own the task and you want to give it capabilities. If you are still deciding between delegation patterns, see [Agent orchestration](/openai-agents-js/guides/multi-agent). 1. **Hosted OpenAI tools** – run alongside the model on OpenAI servers. *(web search, file search, code interpreter, image generation, tool search)* 2. **Built-in execution tools** – SDK-provided tools that execute outside the model. *(computer use and apply\_patch run locally; shell can run locally or in hosted containers)* 3. **Function tools** – wrap any local function with a JSON schema so the LLM can call it. 4. **Agents as tools** – expose an entire Agent as a callable tool. 5. **MCP servers** – attach a Model Context Protocol server (local or remote). 6. **Sandbox capabilities** – attach workspace-scoped shell, filesystem, skills, memory, or compaction tools to a `SandboxAgent`. 7. **Experimental: Codex tool** – wrap the Codex SDK as a function tool to run workspace-aware tasks. *** ## Tool categories [Section titled “Tool categories”](#tool-categories) The rest of this guide first covers each tool category, then summarizes cross-cutting tool selection and prompting guidance. ### 1. Hosted tools (OpenAI Responses API) [Section titled “1. Hosted tools (OpenAI Responses API)”](#1-hosted-tools-openai-responses-api) When you use the `OpenAIResponsesModel` you can add the following built‑in tools: | Tool | Type string | Purpose | | ----------------------- | -------------------- | ----------------------------------------------------------------------------- | | Web search | `'web_search'` | Internet search. | | File / retrieval search | `'file_search'` | Query vector stores hosted on OpenAI. | | Code Interpreter | `'code_interpreter'` | Run code in a sandboxed environment. | | Image generation | `'image_generation'` | Generate images based on text. | | Tool search | `'tool_search'` | Load deferred function tools, namespaces, or searchable MCP tools at runtime. | Hosted tools ```typescript import { Agent, codeInterpreterTool, fileSearchTool, imageGenerationTool, webSearchTool, } from '@openai/agents'; const agent = new Agent({ name: 'Travel assistant', tools: [ webSearchTool({ searchContextSize: 'medium' }), fileSearchTool('VS_ID', { maxNumResults: 3 }), codeInterpreterTool(), imageGenerationTool({ size: '1024x1024' }), ], }); ``` The SDK provides helper functions that return hosted tool definitions: | Helper function | Notes | | ------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `webSearchTool(options?)` | JS-friendly options such as `searchContextSize`, `userLocation`, and `filters.allowedDomains`. | | `fileSearchTool(ids, options?)` | Accepts one or more vector store IDs as the first argument, plus options like `maxNumResults`, `includeSearchResults`, `rankingOptions`, and filters. | | `codeInterpreterTool(options?)` | Defaults to an auto-managed container when no `container` is provided. | | `imageGenerationTool(options?)` | Supports image generation configuration such as `model`, `size`, `quality`, `background`, `inputFidelity`, `inputImageMask`, `moderation`, `outputCompression`, `partialImages`, and output format. | | `toolSearchTool(options?)` | Adds the built-in `tool_search` helper. Pair it with deferred function tools or hosted MCP tools that set `deferLoading: true`. Supports hosted execution by default or client execution with `execution: 'client'` plus `execute`. | These helpers map JavaScript/TypeScript-friendly option names to the underlying OpenAI Responses API tool payloads. Refer to the official [OpenAI tools guide](https://developers.openai.com/api/docs/guides/tools) for the full tool schemas and advanced options like ranking options or semantic filters, and the official [Tool search guide](https://developers.openai.com/api/docs/guides/tools-tool-search) for the current built-in tool-search flow and model availability. *** ### 2. Built-in execution tools [Section titled “2. Built-in execution tools”](#2-built-in-execution-tools) These tools are built into the SDK, but execution happens outside the model response itself: * **Computer use** – implement the `Computer` interface and pass it to `computerTool()`. This always runs against a local `Computer` implementation that you provide. * **Shell** – either provide a local `Shell` implementation, or configure a hosted container environment with `shellTool({ environment })`. * **Apply patch** – implement the `Editor` interface and pass it to `applyPatchTool()`. This always runs against a local `Editor` implementation that you provide. * **Sandbox shell and filesystem tools** – use `shell()`, `filesystem()`, `skills()`, `memory()`, or `compaction()` on a `SandboxAgent` when those actions should run inside a sandbox workspace. The tool calls are still requested by the model, but your application or configured execution environment performs the work. Sandbox capability tools are different from process-wide built-in tools: they are bound to the live sandbox session for the current `SandboxAgent` run. Use [Sandbox agents](/openai-agents-js/guides/sandbox-agents) when the tool should operate on the agent’s isolated workspace instead of your application process. Built-in execution tools ```typescript import { Agent, applyPatchTool, computerTool, shellTool, Computer, Editor, Shell, } from '@openai/agents'; const computer: Computer = { environment: 'browser', dimensions: [1024, 768], screenshot: async () => '', click: async () => {}, doubleClick: async () => {}, scroll: async () => {}, type: async () => {}, wait: async () => {}, move: async () => {}, keypress: async () => {}, drag: async () => {}, }; const shell: Shell = { run: async () => ({ output: [ { stdout: '', stderr: '', outcome: { type: 'exit', exitCode: 0 }, }, ], }), }; const editor: Editor = { createFile: async () => ({ status: 'completed' }), updateFile: async () => ({ status: 'completed' }), deleteFile: async () => ({ status: 'completed' }), }; const agent = new Agent({ name: 'Local tools agent', model: 'gpt-5.4', tools: [ computerTool({ computer }), shellTool({ shell, needsApproval: true }), applyPatchTool({ editor, needsApproval: true }), ], }); ``` #### Computer tool specifics [Section titled “Computer tool specifics”](#computer-tool-specifics) `computerTool()` accepts either: * A concrete `Computer` instance. * An initializer function that creates a `Computer` per run. * A provider object with `{ create, dispose }` when you need run-scoped setup and teardown. To use OpenAI’s current computer-use path, set a computer-capable model such as [`gpt-5.4`](https://developers.openai.com/api/docs/models/gpt-5.4). When the request model is explicit, the SDK sends the GA built-in `computer` tool shape. If the effective model still comes from a stored prompt or another older integration, the SDK keeps the legacy `computer_use_preview` wire shape for compatibility unless you explicitly opt into the GA path with `modelSettings.toolChoice: 'computer'`. GA computer calls can contain batched `actions[]` in a single `computer_call`. The SDK executes them in order, evaluates `needsApproval` against each action, and returns the final screenshot as the tool output. If you build an approval UI from `interruption.rawItem`, read `actions` when present and fall back to `action` for legacy preview items. Use `needsApproval` when high-impact computer actions should pause for user review, and `onSafetyCheck` when you want to acknowledge or reject the pending safety checks reported for a computer call. For model-side guidance and migration details, see the official [OpenAI computer use guide](https://developers.openai.com/api/docs/guides/tools-computer-use/) and its [migration note](https://developers.openai.com/api/docs/guides/tools-computer-use/#migration-from-computer-use-preview). #### Shell tool specifics [Section titled “Shell tool specifics”](#shell-tool-specifics) `shellTool()` has two modes: * Local mode: provide `shell`, and optionally `environment: { type: 'local', skills }` plus `needsApproval` and `onApproval` for automatic approval handling. * Hosted container mode: provide `environment` with `type: 'container_auto'` or `type: 'container_reference'`. In local mode, `environment.skills` lets you mount local skills by `name`, `description`, and filesystem `path`. In hosted container mode, configure `shellTool({ environment })` with either: * `type: 'container_auto'` to create a managed container for the run. * `type: 'container_reference'` to reuse an existing container by `containerId`. Hosted `container_auto` environments support: * `networkPolicy`, including allowlists with `domainSecrets`. * `fileIds` for mounting uploaded files. * `memoryLimit` for container sizing. * `skills`, either by `skill_reference` or inline zip bundles. Hosted shell environments do not accept `shell`, `needsApproval`, or `onApproval`, because the execution happens in the hosted container environment instead of your local process. See `examples/tools/local-shell.ts`, `examples/tools/container-shell-skill-ref.ts`, and `examples/tools/container-shell-inline-skill.ts` for end-to-end usage. #### Apply-patch tool specifics [Section titled “Apply-patch tool specifics”](#apply-patch-tool-specifics) `applyPatchTool()` mirrors the local approval flow from `shellTool()`: use `needsApproval` to pause before file edits and `onApproval` when you want an app-level callback to auto-approve or reject. *** ### 3. Function tools [Section titled “3. Function tools”](#3-function-tools) You can turn **any** function into a tool with the `tool()` helper. Function tool with Zod parameters ```typescript import { tool } from '@openai/agents'; import { z } from 'zod'; const getWeatherTool = tool({ name: 'get_weather', description: 'Get the weather for a given city', parameters: z.object({ city: z.string() }), async execute({ city }) { return `The weather in ${city} is sunny.`; }, }); ``` #### Options reference [Section titled “Options reference”](#options-reference) | Field | Required | Description | | ---------------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `name` | No | Defaults to the function name (e.g., `get_weather`). | | `description` | Yes | Clear, human-readable description shown to the LLM. | | `parameters` | Yes | Either a Zod schema or a raw JSON schema object. Zod parameters automatically enable **strict** mode. | | `strict` | No | When `true` (default), the SDK returns a model error if the arguments don’t validate. Set to `false` for fuzzy matching. | | `execute` | Yes | `(args, context, details) => string \| unknown \| Promise<...>` – your business logic. Non-string outputs are serialized for the model. `context` is optional `RunContext`; `details` includes metadata like `toolCall`, `resumeState`, and `signal`. | | `errorFunction` | No | Custom handler `(context, error) => string` for transforming internal errors into a user-visible string. | | `timeoutMs` | No | Per-call timeout in milliseconds. Must be greater than 0 and less than or equal to `2147483647`. | | `timeoutBehavior` | No | Timeout mode: `error_as_result` (default) returns a model-visible timeout message, and `raise_exception` throws `ToolTimeoutError`. | | `timeoutErrorFunction` | No | Custom handler `(context, timeoutError) => string` for timeout output when `timeoutBehavior` is `error_as_result`. | | `needsApproval` | No | Require human approval before execution. See the [human-in-the-loop guide](/openai-agents-js/guides/human-in-the-loop). | | `isEnabled` | No | Conditionally expose the tool per run; accepts a boolean or predicate. | | `inputGuardrails` | No | Guardrails that run before the tool executes; can reject or throw. See [Guardrails](/openai-agents-js/guides/guardrails#tool-guardrails). | | `outputGuardrails` | No | Guardrails that run after the tool executes; can reject or throw. See [Guardrails](/openai-agents-js/guides/guardrails#tool-guardrails). | #### Function tool timeouts [Section titled “Function tool timeouts”](#function-tool-timeouts) Use `timeoutMs` to bound each function tool invocation. * `timeoutBehavior: 'error_as_result'` (default) returns `Tool '' timed out after ms.` to the model. * `timeoutBehavior: 'raise_exception'` throws [`ToolTimeoutError`](/openai-agents-js/openai/agents-core/classes/tooltimeouterror), which you can catch as part of [run exceptions](/openai-agents-js/guides/running-agents#exceptions). * `timeoutErrorFunction` lets you customize timeout text in `error_as_result` mode. * Timeouts abort `details.signal`, so long-running tools can stop promptly when they listen for cancellation. If you invoke a function tool directly, use [`invokeFunctionTool`](/openai-agents-js/openai/agents/functions/invokefunctiontool) to enforce the same timeout behavior as normal agent runs. #### Non‑strict JSON‑schema tools [Section titled “Non‑strict JSON‑schema tools”](#nonstrict-jsonschema-tools) If you need the model to *guess* invalid or partial input you can disable strict mode when using raw JSON schema: Non-strict JSON schema tools ```typescript import { tool } from '@openai/agents'; interface LooseToolInput { text: string; } const looseTool = tool({ description: 'Echo input; be forgiving about typos', strict: false, parameters: { type: 'object', properties: { text: { type: 'string' } }, required: ['text'], additionalProperties: true, }, execute: async (input) => { // because strict is false we need to do our own verification if (typeof input !== 'object' || input === null || !('text' in input)) { return 'Invalid input. Please try again'; } return (input as LooseToolInput).text; }, }); ``` #### Deferred tool loading with tool search [Section titled “Deferred tool loading with tool search”](#deferred-tool-loading-with-tool-search) Tool search lets the model load only the tool definitions it needs at runtime instead of sending every schema up front. In the SDK, this is how you work with deferred top-level function tools, `toolNamespace()` groups, and hosted MCP tools configured with `deferLoading: true`. Use Tool search only with GPT-5.4 and newer model releases that support it in the Responses API. Deferred tool loading with tool search ```typescript import { Agent, tool, toolNamespace, toolSearchTool } from '@openai/agents'; import { z } from 'zod'; const customerIdParams = z.object({ customerId: z.string().describe('The customer identifier to look up.'), }); // Keep a standalone deferred tool at the top level when it represents a // single searchable capability that does not need a shared namespace. const shippingLookup = tool({ name: 'get_shipping_eta', description: 'Look up a shipment ETA by customer identifier.', parameters: customerIdParams, deferLoading: true, async execute({ customerId }) { return { customerId, eta: '2026-03-07', carrier: 'Priority Express', }; }, }); // Group related tools into a namespace when one domain description should // cover several deferred tools and let tool search load them together. const crmTools = toolNamespace({ name: 'crm', description: 'CRM tools for customer profile lookups.', tools: [ tool({ name: 'get_customer_profile', description: 'Fetch a basic customer profile.', parameters: customerIdParams, deferLoading: true, async execute({ customerId }) { return { customerId, tier: 'enterprise', }; }, }), ], }); const agent = new Agent({ name: 'Operations assistant', model: 'gpt-5.4', // Mixing namespaced and top-level deferred tools in one request is supported. tools: [shippingLookup, ...crmTools, toolSearchTool()], }); ``` The example intentionally mixes both styles: * `shippingLookup` stays top-level because it is one standalone searchable capability. * `crmTools` uses `toolNamespace()` because related CRM tools share one high-level label and description. * Mixing namespaced and top-level deferred tools in the same request is supported; tool search can load both namespace paths such as `crm` and top-level paths such as `get_shipping_eta`. When you use tool search: * Mark each deferred function tool with `deferLoading: true`. * Use `toolNamespace({ name, description, tools })` when multiple related tools should share one domain description and be loaded as a group. * Keep a tool top-level when it is a single independent capability and the tool name itself is a good search target. * Add `toolSearchTool()` to the same `tools` array whenever any deferred function tool or hosted MCP tool uses `deferLoading: true`. * Leave `modelSettings.toolChoice` on `'auto'`. The SDK rejects forcing the built-in `tool_search` tool or a deferred function tool by name. * Hosted execution is the default. If you set `toolSearchTool({ execution: 'client', execute })`, the standard `run()` loop only supports the built-in `{ paths: string[] }` client query shape; custom client-side schemas require your own Responses loop. * A namespace can mix immediate and deferred members. Immediate members stay callable without tool search, while deferred members in the same namespace are loaded on demand. * Deferred function tools and `toolNamespace()` are Responses-only. Chat Completions rejects them, and the AI SDK adapter does not support deferred Responses tool-loading flows. *** ### 4. Agents as tools [Section titled “4. Agents as tools”](#4-agents-as-tools) Sometimes you want an Agent to *assist* another Agent without fully handing off the conversation. Use `agent.asTool()`: If you are still choosing between `agent.asTool()` and `handoff()`, compare the patterns in the [Agents guide](/openai-agents-js/guides/agents#composition-patterns) and [Agent orchestration](/openai-agents-js/guides/multi-agent). Agents as tools ```typescript import { Agent } from '@openai/agents'; const summarizer = new Agent({ name: 'Summarizer', instructions: 'Generate a concise summary of the supplied text.', }); const summarizerTool = summarizer.asTool({ toolName: 'summarize_text', toolDescription: 'Generate a concise summary of the supplied text.', }); const mainAgent = new Agent({ name: 'Research assistant', tools: [summarizerTool], }); ``` Under the hood the SDK: * Creates a function tool with a single `input` parameter. * Runs the sub‑agent with that input when the tool is called. * Returns either the last message or the output extracted by `customOutputExtractor`. When you run an agent as a tool, Agents SDK creates a runner with the default settings and run the agent with it within the function execution. If you want to provide any properties of `runConfig` or `runOptions`, you can pass them to the `asTool()` method to customize the runner’s behavior. You can also set `needsApproval` and `isEnabled` on the agent tool via `asTool()` options to integrate with human‑in‑the‑loop flows and conditional tool availability. Inside `customOutputExtractor`, use `result.agentToolInvocation` to inspect the current `Agent.asTool()` invocation. In that callback the result always comes from `Agent.asTool()`, so `agentToolInvocation` is always defined and exposes `toolName`, `toolCallId`, and `toolArguments`. Use `result.runContext` for the regular app context and `toolInput`. This metadata is scoped to the current nested invocation and is not serialized into `RunState`. Read agent tool invocation metadata ```typescript import { Agent } from '@openai/agents'; const billingAgent = new Agent({ name: 'Billing Agent', instructions: 'Handle billing questions and subscription changes.', }); const billingTool = billingAgent.asTool({ toolName: 'billing_agent', toolDescription: 'Handles customer billing questions.', customOutputExtractor(result) { console.log('tool', result.agentToolInvocation.toolName); // Direct invoke() calls may not have a model-generated tool call id. console.log('call', result.agentToolInvocation.toolCallId); console.log('args', result.agentToolInvocation.toolArguments); return String(result.finalOutput ?? ''); }, }); const orchestrator = new Agent({ name: 'Support Orchestrator', instructions: 'Delegate billing questions to the billing agent tool.', tools: [billingTool], }); ``` Advanced structured-input options for `agent.asTool()`: * `inputBuilder`: maps structured tool args to the nested agent input payload. * `includeInputSchema`: includes the input JSON schema in the nested run for stronger schema-aware behavior. * `resumeState`: controls context reconciliation strategy when resuming nested serialized `RunState`: `'merge'` (default) merges live approval/context state into the serialized state, `'replace'` uses the current run context instead, and `'preferSerialized'` resumes with the serialized context unchanged. #### Streaming events from agent tools [Section titled “Streaming events from agent tools”](#streaming-events-from-agent-tools) Agent tools can stream all nested run events back to your app. Choose the hook style that fits how you construct the tool: Streaming agent tools ```typescript import { Agent } from '@openai/agents'; const billingAgent = new Agent({ name: 'Billing Agent', instructions: 'Answer billing questions and compute simple charges.', }); const billingTool = billingAgent.asTool({ toolName: 'billing_agent', toolDescription: 'Handles customer billing questions.', // onStream: simplest catch-all when you define the tool inline. onStream: (event) => { console.log(`[onStream] ${event.event.type}`, event); }, }); // on(eventName) lets you subscribe selectively (or use '*' for all). billingTool.on('run_item_stream_event', (event) => { console.log('[on run_item_stream_event]', event); }); billingTool.on('raw_model_stream_event', (event) => { console.log('[on raw_model_stream_event]', event); }); const orchestrator = new Agent({ name: 'Support Orchestrator', instructions: 'Delegate billing questions to the billing agent tool.', tools: [billingTool], }); ``` * Event types match `RunStreamEvent['type']`: `raw_model_stream_event`, `run_item_stream_event`, `agent_updated_stream_event`. * `onStream` is the simplest “catch-all” and works well when you declare the tool inline (`tools: [agent.asTool({ onStream })]`). Use it if you do not need per-event routing. * `on(eventName, handler)` lets you subscribe selectively (or with `'*'`) and is best when you need finer-grained handling or want to attach listeners after creation. * If you provide either `onStream` or any `on(...)` handler, the agent-as-tool will run in streaming mode automatically; without them it stays on the non-streaming path. * Handlers are invoked in parallel so a slow `onStream` callback will not block `on(...)` handlers (and vice versa). * `toolCallId` is provided when the tool was invoked via a model tool call; direct `invoke()` calls or provider quirks may omit it. *** ### 5. MCP servers [Section titled “5. MCP servers”](#5-mcp-servers) You can expose tools via [Model Context Protocol (MCP)](https://modelcontextprotocol.io/) servers and attach them to an agent. For instance, you can use `MCPServerStdio` to spawn and connect to the stdio MCP server: Local MCP server ```typescript import { Agent, MCPServerStdio } from '@openai/agents'; const server = new MCPServerStdio({ fullCommand: 'pnpm exec mcp-server-filesystem ./sample_files', }); await server.connect(); const agent = new Agent({ name: 'Assistant', mcpServers: [server], }); ``` See [`filesystem-example.ts`](https://github.com/openai/openai-agents-js/tree/main/examples/mcp/filesystem-example.ts) for a complete example. Also, if you’re looking for a comprehensitve guide for MCP server tool integration, refer to [MCP guide](/openai-agents-js/guides/mcp) for details. When managing multiple servers (or partial failures), use `connectMcpServers` and the lifecycle guidance in the [MCP guide](/openai-agents-js/guides/mcp#managing-mcp-server-lifecycle). *** ### 6. Experimental: Codex tool [Section titled “6. Experimental: Codex tool”](#6-experimental-codex-tool) `@openai/agents-extensions/experimental/codex` provides `codexTool()`, a function tool that routes model tool calls to the Codex SDK so the agent can run workspace-scoped tasks (shell, file edits, MCP tools) autonomously. This surface is experimental and may change. Install dependencies first: ```bash npm install @openai/agents-extensions @openai/codex-sdk ``` Quick start: Experimental Codex tool ```typescript import { Agent } from '@openai/agents'; import { codexTool } from '@openai/agents-extensions/experimental/codex'; export const codexAgent = new Agent({ name: 'Codex Agent', instructions: 'Use the codex tool to inspect the workspace and answer the question. When skill names, which usually start with `$`, are mentioned, you must rely on the codex tool to use the skill and answer the question.', tools: [ codexTool({ sandboxMode: 'workspace-write', workingDirectory: '/path/to/repo', defaultThreadOptions: { model: 'gpt-5.4', networkAccessEnabled: true, webSearchEnabled: false, }, }), ], }); ``` What to know: * Auth: supply `CODEX_API_KEY` (preferred) or `OPENAI_API_KEY`, or pass `codexOptions.apiKey`. * Inputs: strict schema—`inputs` must contain at least one `{ type: 'text', text }` or `{ type: 'local_image', path }`. * Safety: pair `sandboxMode` with `workingDirectory`; set `skipGitRepoCheck` if the directory is not a Git repo. * Threading: `useRunContextThreadId: true` reads/stores the latest thread id in `runContext.context`, which is useful for cross-turn reuse in your app state. * Thread ID precedence: tool call `threadId` (if your schema includes it) takes priority, then run-context thread id, then `codexTool({ threadId })`. * Run context key: defaults to `codexThreadId` for `name: 'codex'`, or `codexThreadId_` for names like `name: 'engineer'` (`codex_engineer` after normalization). * Mutable context requirement: when `useRunContextThreadId` is enabled, pass a mutable object or `Map` as `run(..., { context })`. * Naming: tool names are normalized into the `codex` namespace (`engineer` becomes `codex_engineer`), and duplicate Codex tool names in an agent are rejected. * Streaming: `onStream` mirrors Codex events (reasoning, command execution, MCP tool calls, file changes, web search) so you can log or trace progress. * Outputs: tool result includes `response`, `usage`, and `threadId`, and Codex token usage is recorded in `RunContext`. * Structure: `outputSchema` can be a descriptor, JSON schema object, or Zod object. For JSON object schemas, `additionalProperties` must be `false`. Run-context thread reuse example: Codex run-context thread reuse ```typescript import { Agent, run } from '@openai/agents'; import { codexTool } from '@openai/agents-extensions/experimental/codex'; // Derived from codexTool({ name: 'engineer' }) when runContextThreadIdKey is omitted. type ExampleContext = { codexThreadId_engineer?: string; }; const agent = new Agent({ name: 'Codex assistant', instructions: 'Use the codex tool for workspace tasks.', tools: [ codexTool({ // `name` is optional for a single Codex tool. // We set it so the run-context key is tool-specific and to avoid collisions when adding more Codex tools. name: 'engineer', // Reuse the same Codex thread across runs that share this context object. useRunContextThreadId: true, sandboxMode: 'workspace-write', workingDirectory: '/path/to/repo', defaultThreadOptions: { model: 'gpt-5.4', approvalPolicy: 'never', }, }), ], }); // The default key for useRunContextThreadId with name=engineer is codexThreadId_engineer. const context: ExampleContext = {}; // First turn creates (or resumes) a Codex thread and stores the thread ID in context. await run(agent, 'Inspect src/tool.ts and summarize it.', { context }); // Second turn reuses the same thread because it shares the same context object. await run(agent, 'Now list refactoring opportunities.', { context }); const threadId = context.codexThreadId_engineer; ``` *** ## Tool strategy and best practices [Section titled “Tool strategy and best practices”](#tool-strategy-and-best-practices) ### Tool use behavior [Section titled “Tool use behavior”](#tool-use-behavior) Refer to the [Agents guide](/openai-agents-js/guides/agents#forcing-tool-use) for controlling when and how a model must use tools (`modelSettings.toolChoice`, `toolUseBehavior`, etc.). *** ### Best practices [Section titled “Best practices”](#best-practices) * **Short, explicit descriptions** – describe *what* the tool does *and when to use it*. * **Validate inputs** – use Zod schemas for strict JSON validation where possible. * **Avoid side‑effects in error handlers** – `errorFunction` should return a helpful string, not throw. * **One responsibility per tool** – small, composable tools lead to better model reasoning. *** ## Related guides [Section titled “Related guides”](#related-guides) * [Agents](/openai-agents-js/guides/agents) for defining tool-bearing agents and controlling `toolUseBehavior`. * [Agent orchestration](/openai-agents-js/guides/multi-agent) for deciding when to use agents as tools versus handoffs. * [Running agents](/openai-agents-js/guides/running-agents) for execution flow, streaming, and conversation state. * [Models](/openai-agents-js/guides/models) for hosted OpenAI model configuration and Responses transport choices. * [Guardrails](/openai-agents-js/guides/guardrails) to validate tool inputs or outputs. * Dive into the TypeDoc reference for [`tool()`](/openai-agents-js/openai/agents/functions/tool) and the various hosted tool types. # Tracing > Learn how to trace your agent runs The Agents SDK includes built-in tracing, collecting a comprehensive record of events during an agent run: LLM generations, tool calls, handoffs, guardrails, and even custom events that occur. Using the [Traces dashboard](https://platform.openai.com/traces), you can debug, visualize, and monitor your workflows during development and in production. Note Tracing is enabled by default in server runtimes (Node.js, Deno, Bun). It is disabled by default in browsers and when `NODE_ENV=test`. There are two ways to disable tracing in server environments: 1. You can globally disable tracing by setting the env var `OPENAI_AGENTS_DISABLE_TRACING=1` 2. You can disable tracing on a runner by setting [`RunConfig.tracingDisabled`](/openai-agents-js/openai/agents-core/type-aliases/runconfig/#tracingdisabled) to `true` in `new Runner(...)` ***For organizations operating under a Zero Data Retention (ZDR) policy using OpenAI’s APIs, tracing is unavailable.*** ## Export loop lifecycle [Section titled “Export loop lifecycle”](#export-loop-lifecycle) In supported server runtimes, traces are exported on a regular interval. In some runtimes, including Cloudflare Workers, the automatic export loop is unavailable even though tracing itself is still enabled. In those environments you should call `getGlobalTraceProvider().forceFlush()` as part of your request lifecycle to export queued traces before the runtime is torn down. This guidance does not apply to browsers because tracing is disabled there by default. For example, in a Cloudflare Worker, you should wrap your code into a `try/catch/finally` block and use `forceFlush()` with `waitUntil` to ensure that traces are exported before the worker exits. ```typescript import { getGlobalTraceProvider } from '@openai/agents'; export default { async fetch(request, env, ctx): Promise { try { // your agent code here return new Response(`success`); } catch (error) { console.error(error); return new Response(String(error), { status: 500 }); } finally { // make sure to flush any remaining traces before exiting ctx.waitUntil(getGlobalTraceProvider().forceFlush()); } }, }; ``` ## Traces and spans [Section titled “Traces and spans”](#traces-and-spans) * **Traces** represent a single end-to-end operation of a “workflow”. They’re composed of Spans. Traces have the following properties: * `workflow_name`: This is the logical workflow or app. For example “Code generation” or “Customer service”. * `trace_id`: A unique ID for the trace. Automatically generated if you don’t pass one. Must have the format `trace_<32_alphanumeric>`. * `group_id`: Optional group ID, to link multiple traces from the same conversation. For example, you might use a chat thread ID. * `disabled`: If True, the trace will not be recorded. * `metadata`: Optional metadata for the trace. * **Spans** represent operations that have a start and end time. Spans have: * `started_at` and `ended_at` timestamps. * `trace_id`, to represent the trace they belong to * `parent_id`, which points to the parent Span of this Span (if any) * `span_data`, which is information about the Span. For example, `AgentSpanData` contains information about the Agent, `GenerationSpanData` contains information about the LLM generation, etc. ## Default tracing [Section titled “Default tracing”](#default-tracing) By default, the SDK traces the following: * The entire `run()` or `Runner.run()` is wrapped in a `Trace`. * Each time an agent runs, it is wrapped in `AgentSpan` * LLM generations are wrapped in `GenerationSpan` * Function tool calls are each wrapped in `FunctionSpan` * Guardrails are wrapped in `GuardrailSpan` * Handoffs are wrapped in `HandoffSpan` By default, the trace is named “Agent workflow”. You can set this name if you use `withTrace`, or you can can configure the name and other properties with the [`RunConfig.workflowName`](/openai-agents-js/openai/agents-core/type-aliases/runconfig/#workflowname). In addition, you can set up [custom trace processors](#custom-tracing-processors) to push traces to other destinations (as a replacement, or secondary destination). ### Voice agent tracing [Section titled “Voice agent tracing”](#voice-agent-tracing) If you are using `RealtimeAgent` and `RealtimeSession` with the default OpenAI Realtime API, tracing will automatically happen on the Realtime API side unless you disable it on the `RealtimeSession` using `tracingDisabled: true` or using the `OPENAI_AGENTS_DISABLE_TRACING` environment variable. Check out the [Voice agents guide](/openai-agents-js/guides/voice-agents) for more details. ## Higher level traces [Section titled “Higher level traces”](#higher-level-traces) Sometimes, you might want multiple calls to `run()` to be part of a single trace. You can do this by wrapping the entire code in a `withTrace()`. ```typescript import { Agent, run, withTrace } from '@openai/agents'; const agent = new Agent({ name: 'Joke generator', instructions: 'Tell funny jokes.', }); await withTrace('Joke workflow', async () => { const result = await run(agent, 'Tell me a joke'); const secondResult = await run( agent, `Rate this joke: ${result.finalOutput}`, ); console.log(`Joke: ${result.finalOutput}`); console.log(`Rating: ${secondResult.finalOutput}`); }); ``` 1. Because the two calls to `run` are wrapped in a `withTrace()`, the individual runs will be part of the overall trace rather than creating two traces. ## Creating traces [Section titled “Creating traces”](#creating-traces) You can use the [`withTrace()`](/openai-agents-js/openai/agents-core/functions/withtrace/) function to create a trace. Alternatively, you can use `getGlobalTraceProvider().createTrace()` to create a new trace manually and pass it into `withTrace()`. The current trace is tracked via a [Node.js `AsyncLocalStorage`](https://nodejs.org/api/async_context.html#class-asynclocalstorage) or the respective environment polyfills. This means that it works with concurrency automatically. ## Creating spans [Section titled “Creating spans”](#creating-spans) You can use the various `create*Span()` (e.g. `createGenerationSpan()`, `createFunctionSpan()`, etc.) methods to create a span. In general, you don’t need to manually create spans. A [`createCustomSpan()`](/openai-agents-js/openai/agents-core/functions/createcustomspan/) function is available for tracking custom span information. Spans are automatically part of the current trace, and are nested under the nearest current span, which is tracked via a [Node.js `AsyncLocalStorage`](https://nodejs.org/api/async_context.html#class-asynclocalstorage) or the respective environment polyfills. ## Sensitive data [Section titled “Sensitive data”](#sensitive-data) Certain spans may capture potentially sensitive data. The `createGenerationSpan()` stores the inputs/outputs of the LLM generation, and `createFunctionSpan()` stores the inputs/outputs of function calls. These may contain sensitive data, so you can disable capturing that data via [`RunConfig.traceIncludeSensitiveData`](/openai-agents-js/openai/agents-core/type-aliases/runconfig/#traceincludesensitivedata). ## OpenAI tracing exporter [Section titled “OpenAI tracing exporter”](#openai-tracing-exporter) In supported server runtimes, the default tracing setup already exports to OpenAI. Use `setTracingExportApiKey()` when trace export should use a different credential than `OPENAI_API_KEY`. If you need custom ingest behavior, instantiate [`OpenAITracingExporter`](/openai-agents-js/openai/agents-openai/classes/openaitracingexporter) yourself and install it with `setTraceProcessors(...)` or `addTraceProcessor(...)`. The exporter supports `apiKey`, `endpoint`, `organization`, `project`, `maxRetries`, `baseDelay`, and `maxDelay`. If you replace the default processors and later want to restore the default OpenAI exporter with a batch processor, call [`setDefaultOpenAITracingExporter()`](/openai-agents-js/openai/agents-openai/functions/setdefaultopenaitracingexporter/). ## Custom tracing processors [Section titled “Custom tracing processors”](#custom-tracing-processors) The high level architecture for tracing is: * At initialization, we create a global [`TraceProvider`](/openai-agents-js/openai/agents-core/classes/traceprovider), which is responsible for creating traces and can be accessed through [`getGlobalTraceProvider()`](/openai-agents-js/openai/agents-core/functions/getglobaltraceprovider/). * We configure the `TraceProvider` with a [`BatchTraceProcessor`](/openai-agents-js/openai/agents-core/classes/batchtraceprocessor/) that sends traces/spans in batches to a [`OpenAITracingExporter`](/openai-agents-js/openai/agents-openai/classes/openaitracingexporter/), which exports the spans and traces to the OpenAI backend in batches. To customize this default setup, to send traces to alternative or additional backends or modifying exporter behavior, you have two options: 1. [`addTraceProcessor()`](/openai-agents-js/openai/agents-core/functions/addtraceprocessor) lets you add an **additional** trace processor that will receive traces and spans as they are ready. This lets you do your own processing in addition to sending traces to OpenAI’s backend. 2. [`setTraceProcessors()`](/openai-agents-js/openai/agents-core/functions/settraceprocessors) lets you **replace** the default processors with your own trace processors. This means traces will not be sent to the OpenAI backend unless you include a `TracingProcessor` that does so. ## External tracing processors list [Section titled “External tracing processors list”](#external-tracing-processors-list) * [AgentOps](https://docs.agentops.ai/v2/usage/typescript-sdk#openai-agents-integration) * [Respan](https://www.respan.ai/docs/integrations/openai-agents-sdk) * [PromptLayer](https://docs.promptlayer.com/languages/integrations#openai-agents-sdk) # Troubleshooting > Learn how to troubleshoot issues with the OpenAI Agents SDK. ## Supported environments [Section titled “Supported environments”](#supported-environments) The OpenAI Agents SDK is supported on the following server environments: * Node.js 22+ * Deno 2.35+ * Bun 1.2.5+ ### Limited support [Section titled “Limited support”](#limited-support) * **Cloudflare Workers**: The Agents SDK can be used in Cloudflare Workers, but currently comes with some limitations: * The SDK current requires `nodejs_compat` to be enabled * Traces need to be manually flushed at the end of the request. [See the tracing guide](/openai-agents-js/guides/tracing#export-loop-lifecycle) for more details. * Due to Cloudflare Workers’ limited support for `AsyncLocalStorage` some traces might not be accurate * Outbound WebSocket connections must use a fetch-based upgrade (not the global `WebSocket` constructor). For Realtime, use the Cloudflare transport in `@openai/agents-extensions` (`CloudflareRealtimeTransportLayer`). * **Responses API WebSocket transport**: * Requires a global `WebSocket` implementation. * The `WebSocket` implementation must support custom headers for the handshake. * Many browser-style WebSocket APIs (and some edge runtimes) do not support custom outbound headers. In those environments, use the default HTTP Responses transport instead. * If you see errors mentioning a missing global `WebSocket` implementation or lack of custom-header support, the runtime websocket implementation is not compatible with the Responses WebSocket transport. * **Browsers**: * The core SDK can be bundled for browser use, but tracing is disabled by default there. * **v8 isolates**: * While you should be able to bundle the SDK for v8 isolates if you use a bundler with the right browser polyfills, tracing will not work * v8 isolates have not been extensively tested ## Debug logging [Section titled “Debug logging”](#debug-logging) If you are running into problems with the SDK, you can enable debug logging to get more information about what is happening. Enable debug logging by setting the `DEBUG` environment variable to `openai-agents:*`. ```bash DEBUG=openai-agents:* ``` Alternatively, you can scope the debugging to specific parts of the SDK: * `openai-agents:core` — for the main execution logic of the SDK * `openai-agents:openai` — for the OpenAI API calls * `openai-agents:realtime` — for the Realtime Agents components # Voice Agents > Build realtime voice assistants using RealtimeAgent and RealtimeSession ## Overview [Section titled “Overview”](#overview) ![Realtime Agents](https://cdn.openai.com/API/docs/images/diagram-speech-to-speech.png) Voice Agents let you build low-latency spoken interfaces on top of OpenAI speech-to-speech models. The SDK keeps the Realtime API mental model intact, but wraps the raw event flow in `RealtimeAgent`, `RealtimeSession`, and transport helpers that make tools, guardrails, handoffs, and session history easier to work with. Under the hood, the same Realtime concepts from the official [Realtime API with WebRTC](https://developers.openai.com/api/docs/guides/realtime-webrtc/), [Realtime conversations](https://developers.openai.com/api/docs/guides/realtime-conversations/), and [voice activity detection](https://developers.openai.com/api/docs/guides/realtime-vad/) guides still apply. The Voice Agents SDK adds a TypeScript-first layer on top of that API so you can stay focused on product logic instead of rebuilding transport and event handling from scratch. Note Start with the Quickstart if you are connecting a browser client with WebRTC. Jump to the transport guide first if you are deciding between WebRTC, WebSocket, SIP, Twilio, or Cloudflare Workers. ## Start here [Section titled “Start here”](#start-here) [Voice Agents Quickstart ](/openai-agents-js/guides/voice-agents/quickstart)Build your first realtime voice assistant using the OpenAI Agents SDK in minutes. [Building Voice Agents ](/openai-agents-js/guides/voice-agents/build)Learn how session lifecycle, VAD, interruptions, multimodal input, tools, and history work in the SDK. [Realtime Transport Layer ](/openai-agents-js/guides/voice-agents/transport)Choose between WebRTC, WebSocket, SIP, or a custom transport, and know when to drop down to raw events. ## What the SDK adds [Section titled “What the SDK adds”](#what-the-sdk-adds) * Browser-first WebRTC setup with ephemeral client tokens. * Server-side WebSocket and SIP transport options. * Automatic interruption handling and local conversation history updates. * Multi-agent orchestration through realtime handoffs. * Function tools, hosted MCP tools, approvals, and delegation patterns. * Output guardrails and tracing support for live spoken interactions. ## Pick the next page [Section titled “Pick the next page”](#pick-the-next-page) | If you need to… | Go here | | --------------------------------------------------------------------------------- | --------------------------------------------------------------------------- | | Connect a browser client safely with WebRTC and ephemeral tokens | [Voice Agents Quickstart](/openai-agents-js/guides/voice-agents/quickstart) | | Understand session lifecycle, VAD, interruptions, image input, tools, and history | [Building Voice Agents](/openai-agents-js/guides/voice-agents/build) | | Decide between WebRTC, WebSocket, SIP, and custom transports | [Realtime Transport Layer](/openai-agents-js/guides/voice-agents/transport) | | Run a phone or telephony experience on Twilio | [Realtime Agents on Twilio](/openai-agents-js/extensions/twilio) | | Connect from Cloudflare Workers or other workerd runtimes | [Realtime Agents on Cloudflare](/openai-agents-js/extensions/cloudflare) | ## Why speech-to-speech [Section titled “Why speech-to-speech”](#why-speech-to-speech) Speech-to-speech models process user audio directly, so you do not have to build a separate speech-to-text, text reasoning, and text-to-speech chain for every turn. That keeps latency down and makes interruptions, mixed text and voice input, and tool calls feel much more natural in realtime applications. ![Speech-to-speech model](https://cdn.openai.com/API/docs/images/diagram-chained-agent.png) # Building Voice Agents > Learn how to build voice agents using the OpenAI Agents SDK, how session behavior works, and which realtime features are available. Caution Choose your architecture early: * `OpenAIRealtimeWebRTC` is the simplest browser path and handles audio input/output for you. * `OpenAIRealtimeWebSocket` gives you more control, but you must manage audio capture and playback yourself. * Function tools run wherever the `RealtimeSession` runs. If the session runs in the browser, the tool runs in the browser too. * Realtime handoffs keep the same live session model. Voice changes only work before the session has produced audio output. If you need a different backend model, delegate through a tool instead of a handoff. ## Session setup [Section titled “Session setup”](#session-setup) ### Audio handling [Section titled “Audio handling”](#audio-handling) Some transport layers like the default `OpenAIRealtimeWebRTC` handle audio input and output automatically for you. For other transport mechanisms like `OpenAIRealtimeWebSocket` you have to handle session audio yourself: ```typescript import { RealtimeAgent, RealtimeSession, TransportLayerAudio, } from '@openai/agents/realtime'; const agent = new RealtimeAgent({ name: 'My agent' }); const session = new RealtimeSession(agent); const newlyRecordedAudio = new ArrayBuffer(0); session.on('audio', (event: TransportLayerAudio) => { // play your audio }); // send new audio to the agent session.sendAudio(newlyRecordedAudio); ``` When the underlying transport supports it, `session.muted` reports the current mute state and `session.mute(true | false)` toggles microphone capture. `OpenAIRealtimeWebSocket` does not implement muting: `session.muted` returns `null` and `session.mute()` throws, so for websocket setups you should pause capture on your side and stop calling `sendAudio()` until the microphone should be live again. ### Session configuration [Section titled “Session configuration”](#session-configuration) Configure the session itself when you create [`RealtimeSession`](/openai-agents-js/openai/agents-realtime/classes/realtimesession/), usually through the `model` option and the `config` object. `connect(...)` is for connection-time concerns such as credentials, endpoint URL, and SIP call attachment rather than arbitrary session fields. ```typescript import { RealtimeAgent, RealtimeSession } from '@openai/agents/realtime'; const agent = new RealtimeAgent({ name: 'Greeter', instructions: 'Greet the user with cheer and answer questions.', }); const session = new RealtimeSession(agent, { model: 'gpt-realtime-2', config: { outputModalities: ['audio'], reasoning: { effort: 'low', }, parallelToolCalls: true, audio: { input: { format: 'pcm16', transcription: { model: 'gpt-4o-mini-transcribe', }, }, output: { format: 'pcm16', }, }, }, }); ``` Under the hood, the SDK normalizes this configuration into the Realtime [`session.update`](https://developers.openai.com/api/reference/resources/realtime/client-events/#session.update) shape. If you need a raw session field that does not have a matching property in [RealtimeSessionConfig](/openai-agents-js/openai/agents-realtime/type-aliases/realtimesessionconfig/), use `providerData` or send a raw `session.update` through `session.transport.sendEvent(...)`. Prefer the newer SDK config shape with `outputModalities`, `audio.input`, and `audio.output`. Older SDK aliases such as `modalities`, `inputAudioFormat`, `outputAudioFormat`, `inputAudioTranscription`, and `turnDetection` are still normalized for backwards compatibility, but new code should use the nested `audio` structure shown here. For reasoning-capable Realtime models such as `gpt-realtime-2`, set `reasoning.effort` on the session config. Higher reasoning effort can increase latency and token usage. You can also set `parallelToolCalls` when you want to control whether the model may call multiple tools in parallel. For speech-to-speech sessions, the usual choice is `outputModalities: ['audio']`, which gives you audio output plus transcripts. Switch to `['text']` only when you want text-only responses. For parameters that are new and do not have a matching parameter in [RealtimeSessionConfig](/openai-agents-js/openai/agents-realtime/type-aliases/realtimesessionconfig/), you can use `providerData`. Anything passed in `providerData` is forwarded as part of the raw `session` object. Additional `RealtimeSession` options you can set at construction time: | Option | Type | Purpose | | --------------------------------------------- | --------------------------------- | --------------------------------------------------------------------------------------- | | `context` | `TContext` | Extra local context merged into the session context. | | `historyStoreAudio` | `boolean` | Store audio data in the local history snapshot (disabled by default). | | `outputGuardrails` | `RealtimeOutputGuardrail[]` | Output guardrails for the session (see [Guardrails](#guardrails)). | | `outputGuardrailSettings` | `{ debounceTextLength?: number }` | Guardrail cadence. Defaults to `100`; use `-1` to only run once full text is available. | | `tracingDisabled` | `boolean` | Disable tracing for the session. | | `groupId` | `string` | Group traces across sessions or backend runs. Requires `workflowName`. | | `traceMetadata` | `Record` | Custom metadata to attach to session traces. Requires `workflowName`. | | `workflowName` | `string` | Friendly name for the trace workflow. | | `automaticallyTriggerResponseForMcpToolCalls` | `boolean` | Auto-trigger a model response when an MCP tool call completes (default: `true`). | | `toolErrorFormatter` | `ToolErrorFormatter` | Customize tool approval rejection messages returned to the model. | `connect(...)` options: | Option | Type | Purpose | | -------- | --------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- | | `apiKey` | `string \| (() => string \| Promise)` | API key (or lazy loader) used for this connection. | | `model` | `OpenAIRealtimeModels \| string` | Present in the transport-level options type. For `RealtimeSession`, set the model in the constructor; raw transports can also use a model at connect time. | | `url` | `string` | Optional custom Realtime endpoint URL. | | `callId` | `string` | Attach to an existing SIP-initiated call/session. | ### Conversation lifecycle [Section titled “Conversation lifecycle”](#conversation-lifecycle) `RealtimeSession` sits on top of a long-lived Realtime connection. It keeps a local copy of conversation history, listens for transport events, runs tools and output guardrails, and keeps the active agent configuration synchronized with the transport. The underlying API behavior still matters: * A successful connection starts with a `session.created` event, and later config changes produce `session.updated`. * Most session properties can be changed over time, but `model` cannot change mid-conversation, `voice` can only change before the session has produced audio output, and tracing should be decided up front because the Realtime API does not let you modify tracing after it is enabled. * The Realtime API currently limits a single session to 60 minutes. * Input audio transcription is asynchronous, so the transcript for the latest utterance can arrive after response generation has already started. At the SDK layer, `await session.connect()` means “the transport is ready enough to start the conversation”, but the exact point differs by transport: * In the default browser WebRTC transport, the SDK sends the initial `session.update` as soon as the data channel opens and tries to wait for the corresponding `session.updated` event before resolving `connect()`. This is there to avoid audio reaching the server before your instructions, tools, and modalities are applied. If that acknowledgement never arrives, `connect()` falls back to resolving after a short timeout. * In the default server-side WebSocket transport, `connect()` resolves once the socket is open and the initial config has been sent. The matching `session.updated` event can therefore arrive after `connect()` has already resolved. If you need the raw event model, read the official [Realtime conversations guide](https://developers.openai.com/api/docs/guides/realtime-conversations/) alongside this page. ## Interaction flow [Section titled “Interaction flow”](#interaction-flow) ### Turn detection and voice activity detection [Section titled “Turn detection and voice activity detection”](#turn-detection-and-voice-activity-detection) By default, Realtime sessions use built-in voice activity detection (VAD) so the API can decide when the user has started or stopped speaking and when to create a response. The SDK exposes this through `audio.input.turnDetection`. ```typescript import { RealtimeSession } from '@openai/agents/realtime'; import { agent } from './agent'; const session = new RealtimeSession(agent, { model: 'gpt-realtime-2', config: { audio: { input: { turnDetection: { type: 'semantic_vad', eagerness: 'medium', createResponse: true, interruptResponse: true, }, }, }, }, }); ``` Two common modes are: * `semantic_vad`, which aims for more natural turn boundaries and can wait a little longer when the user sounds like they are not finished yet. * `server_vad`, which is more threshold-driven and exposes settings such as `threshold`, `prefixPaddingMs`, `silenceDurationMs`, and `idleTimeoutMs`. Set `audio.input.turnDetection` to `null` if you want to manage turn boundaries yourself. The official [voice activity detection guide](https://developers.openai.com/api/docs/guides/realtime-vad/) and [Realtime conversations guide](https://developers.openai.com/api/docs/guides/realtime-conversations/#voice-activity-detection) describe the underlying behavior in more detail. ### Interruptions [Section titled “Interruptions”](#interruptions) When VAD is enabled, speaking over the agent can interrupt the current response. On the WebSocket transport, the SDK listens for `input_audio_buffer.speech_started`, truncates the assistant audio to what the user actually heard, and emits an `audio_interrupted` event. That event is especially useful when you manage playback yourself in WebSocket setups. ```typescript import { session } from './agent'; session.on('audio_interrupted', () => { // handle local playback interruption }); ``` If you want to expose a manual stop button, call `interrupt()` yourself: ```typescript import { session } from './agent'; session.interrupt(); // this will still trigger the `audio_interrupted` event for you // to cut off the audio playback when using WebSockets ``` WebRTC and WebSocket both stop the in-progress response, but the low-level mechanics differ by transport. WebRTC clears buffered output audio for you. In WebSocket setups you still need to stop local playback yourself, and the local history updates when the corresponding truncation and conversation events come back from the transport. ### Text input [Section titled “Text input”](#text-input) Use `sendMessage()` when you want to send typed input or additional structured user content into the live conversation. ```typescript import { RealtimeSession, RealtimeAgent } from '@openai/agents/realtime'; const agent = new RealtimeAgent({ name: 'Assistant', }); const session = new RealtimeSession(agent, { model: 'gpt-realtime-2', }); session.sendMessage('Hello, how are you?'); ``` This is useful for mixed text and voice UIs, out-of-band context injection, or pairing spoken input with explicit typed clarifications. ### Image input [Section titled “Image input”](#image-input) Realtime speech-to-speech sessions can also include images. In the SDK, use `addImage()` to attach an image to the current conversation. ```typescript import { RealtimeAgent, RealtimeSession } from '@openai/agents/realtime'; const agent = new RealtimeAgent({ name: 'Assistant', }); const session = new RealtimeSession(agent, { model: 'gpt-realtime-2', }); const imageDataUrl = 'data:image/png;base64,...'; session.addImage(imageDataUrl, { triggerResponse: false }); session.sendMessage('Describe what is in this image.'); ``` Passing `triggerResponse: false` lets you batch the image with a later text or audio turn before asking the model to respond. This lines up with the official [Realtime conversations image input guidance](https://developers.openai.com/api/docs/guides/realtime-conversations/#image-inputs). ### Manual response control [Section titled “Manual response control”](#manual-response-control) At the higher SDK layer, `sendMessage()` and `addImage()` trigger a response for you by default. Manual response control matters when you are working with raw transport events, push-to-talk flows, or custom moderation / validation steps. ```typescript import { RealtimeAgent, RealtimeSession } from '@openai/agents/realtime'; const agent = new RealtimeAgent({ name: 'Greeter', instructions: 'Greet the user with cheer and answer questions.', }); const session = new RealtimeSession(agent, { model: 'gpt-realtime-2', }); session.transport.on('*', (event) => { // JSON parsed version of the event received on the connection }); // Send any valid event as JSON. For example triggering a new response session.transport.sendEvent({ type: 'response.create', // ... }); ``` There are two common cases: 1. If you disable VAD entirely with `audio.input.turnDetection = null`, you are responsible for committing audio turns and then sending `response.create`. 2. If you keep VAD enabled but set `turnDetection.interruptResponse = false` and `turnDetection.createResponse = false`, the API still detects turns but leaves response creation up to you. That second pattern is useful when you want to inspect or moderate user input before the model responds. It matches the official [Realtime conversations guidance on disabling automatic responses](https://developers.openai.com/api/docs/guides/realtime-conversations/#keep-vad-but-disable-automatic-responses). ## Agent capabilities [Section titled “Agent capabilities”](#agent-capabilities) ### Handoffs [Section titled “Handoffs”](#handoffs) Similarly to regular agents, you can use handoffs to break your agent into multiple agents and orchestrate between them to improve performance and better scope the problem. ```typescript import { RealtimeAgent } from '@openai/agents/realtime'; const mathTutorAgent = new RealtimeAgent({ name: 'Math Tutor', handoffDescription: 'Specialist agent for math questions', instructions: 'You provide help with math problems. Explain your reasoning at each step and include examples', }); const agent = new RealtimeAgent({ name: 'Greeter', instructions: 'Greet the user with cheer and answer questions.', handoffs: [mathTutorAgent], }); ``` Unlike regular agents, handoffs behave slightly differently for Realtime Agents. When a handoff is performed, the ongoing session is updated with the new agent configuration in place. Because of this, the new agent automatically has access to the ongoing conversation history and input filters are currently not applied. Because the session stays live, the model for that session does not change during a handoff. Voice changes follow the underlying Realtime API rule: they only work before the session has produced audio output. Realtime handoffs are primarily for swapping between `RealtimeAgent` configurations on the same session; if you need to use a different model, for example a reasoning model like `gpt-5.4`, or delegate to a non-realtime backend agent, use [delegation through tools](#delegation-through-tools). ### Tools [Section titled “Tools”](#tools) Just like regular agents, Realtime Agents can call tools to perform actions. Realtime supports **function tools** (executed locally) and **hosted MCP tools** (executed remotely by the Realtime API). You can define a function tool using the same `tool()` helper you would use for a regular agent. ```typescript import { tool, RealtimeAgent } from '@openai/agents/realtime'; import { z } from 'zod'; const getWeather = tool({ name: 'get_weather', description: 'Return the weather for a city.', parameters: z.object({ city: z.string() }), async execute({ city }) { return `The weather in ${city} is sunny.`; }, }); const weatherAgent = new RealtimeAgent({ name: 'Weather assistant', instructions: 'Answer weather questions.', tools: [getWeather], }); ``` #### Function tools [Section titled “Function tools”](#function-tools) Function tools run in the same environment as your `RealtimeSession`. This means if you are running your session in the browser, the tool executes in the browser. If you need to perform sensitive actions, call your backend from inside the tool and let the server do the privileged work. This lets a browser-side tool act as a thin backchannel to server-side logic. For example, [`examples/realtime-next`](https://github.com/openai/openai-agents-js/tree/main/examples/realtime-next) defines a `refundBackchannel` tool in the browser that forwards the request and current conversation history to `handleRefundRequest(...)` on the server, where a separate `Runner` can use a different agent or model to evaluate the refund before returning the result to the voice session. #### Hosted MCP tools [Section titled “Hosted MCP tools”](#hosted-mcp-tools) Hosted MCP tools can be configured with `hostedMcpTool` and are executed remotely. When MCP tool availability changes the session emits `mcp_tools_changed`. To prevent the session from auto-triggering a model response after MCP tool calls complete, set `automaticallyTriggerResponseForMcpToolCalls: false`. The current filtered MCP tool list is also available as `session.availableMcpTools`. Both that property and the `mcp_tools_changed` event reflect only the hosted MCP servers enabled on the active agent, after applying any `allowed_tools` filters from the agent configuration. Hosted MCP setup is easiest to reason about if you treat secure server selection, headers, and approvals as pre-connect configuration. Before `RealtimeSession.connect()` opens the transport, the SDK resolves the active agent’s hosted MCP tool definitions and includes the supported MCP fields in the initial session config it sends to the Realtime API. That timing matters most in browser WebRTC apps. The ephemeral client secret is always minted on your server, so any hosted MCP credentials or custom `headers` that must stay secret should be attached in that server-side `POST /v1/realtime/client_secrets` request as part of the initial `session` payload. Do not put long-lived credentials in browser code and plan to add them later after `connect()` starts. At the Realtime API level, later `session.update` calls can still change tools and other mutable session fields, and the SDK itself sends `session.update` when the active agent changes. In browser apps, though, you should treat secure Hosted MCP initialization as a server-side, pre-connect concern and keep the browser-side `RealtimeSession` config aligned with what your server minted. #### Background results [Section titled “Background results”](#background-results) While the tool is executing the agent will not be able to process new requests from the user. One way to improve the experience is by telling your agent to announce when it is about to execute a tool or say specific phrases to buy the agent some time to execute the tool. If a function tool should finish without immediately triggering another model response, return `backgroundResult(output)` from `@openai/agents/realtime`. This sends the tool output back to the session while leaving response triggering under your control. #### Timeouts [Section titled “Timeouts”](#timeouts) Function tool timeout options (`timeoutMs`, `timeoutBehavior`, `timeoutErrorFunction`) work the same way in Realtime sessions. With the default `error_as_result`, the timeout message is sent as tool output. With `raise_exception`, the session emits an `error` event with [`ToolTimeoutError`](/openai-agents-js/openai/agents-core/classes/tooltimeouterror) and does not send tool output for that call. #### Accessing the conversation history [Section titled “Accessing the conversation history”](#accessing-the-conversation-history) In addition to the arguments that the agent called a particular tool with, you can also access a snapshot of the current conversation history tracked by the Realtime Session. This can be useful if you need to perform a more complex action based on the current state of the conversation or are planning to use [tools for delegation](#delegation-through-tools). ```typescript import { tool, RealtimeContextData, RealtimeItem, } from '@openai/agents/realtime'; import { z } from 'zod'; const parameters = z.object({ request: z.string(), }); const refundTool = tool({ name: 'Refund Expert', description: 'Evaluate a refund', parameters, execute: async ({ request }, details) => { // The history might not be available const history: RealtimeItem[] = details?.context?.history ?? []; // making your call to process the refund request }, }); ``` Note The history passed in is a snapshot of the history at the time of the tool call. The transcription of the last thing the user said might not be available yet. #### Approval before tool execution [Section titled “Approval before tool execution”](#approval-before-tool-execution) If you define your tool with `needsApproval: true` the agent emits a `tool_approval_requested` event before executing the tool. By listening to this event you can show a UI to the user to approve or reject the tool call. Resolve the request with `await session.approve(request.approvalItem)` or `await session.reject(request.approvalItem)`. For function tools you can pass `{ alwaysApprove: true }` or `{ alwaysReject: true }` to reuse the same decision for repeated calls during the rest of the session, and `session.reject(request.approvalItem, { message: '...' })` to send a custom rejection message back to the model for that specific call. Hosted MCP approvals do not support sticky approve/reject; restrict those tools with the hosted MCP `allowedTools` configuration instead. If you do not pass a per-call rejection `message`, the session falls back to `toolErrorFormatter` (if configured) and then to the SDK default rejection text. ```typescript import { session } from './agent'; session.on('tool_approval_requested', (_context, _agent, request) => { // show a UI to the user to approve or reject the tool call // you can use the `session.approve(...)` or `session.reject(...)` methods to approve or reject the tool call session.approve(request.approvalItem); // or session.reject(request.approvalItem); }); ``` Note While the voice agent is waiting for approval for the tool call, the agent will not be able to process new requests from the user. ### Guardrails [Section titled “Guardrails”](#guardrails) Guardrails offer a way to monitor whether what the agent has said violated a set of rules and immediately cut off the response. These checks run against the transcript stream of the agent’s response. In audio sessions, the SDK uses output audio transcripts and transcript deltas, so the important prerequisite is transcript availability rather than a separate text output modality. The guardrails you provide run asynchronously as a model response is returned, allowing you to cut off the response based on a predefined classification trigger, for example “mentions a specific banned word”. When a guardrail trips the session emits a `guardrail_tripped` event. The event also provides a `details` object containing the `itemId` that triggered the guardrail. ```typescript import { RealtimeOutputGuardrail, RealtimeAgent, RealtimeSession, } from '@openai/agents/realtime'; const agent = new RealtimeAgent({ name: 'Greeter', instructions: 'Greet the user with cheer and answer questions.', }); const guardrails: RealtimeOutputGuardrail[] = [ { name: 'No mention of Dom', async execute({ agentOutput }) { const domInOutput = agentOutput.includes('Dom'); return { tripwireTriggered: domInOutput, outputInfo: { domInOutput }, }; }, }, ]; const guardedSession = new RealtimeSession(agent, { outputGuardrails: guardrails, }); ``` By default guardrails run every 100 characters and again when the final transcript is available. Because speaking the text usually takes longer than generating the transcript, this often lets the guardrail cut off unsafe output before the user hears it. If you want to modify this behavior you can pass an `outputGuardrailSettings` object to the session. Set `debounceTextLength: -1` when you only want to evaluate the fully generated transcript once, at the end of the response. ```typescript import { RealtimeAgent, RealtimeSession } from '@openai/agents/realtime'; const agent = new RealtimeAgent({ name: 'Greeter', instructions: 'Greet the user with cheer and answer questions.', }); const guardedSession = new RealtimeSession(agent, { outputGuardrails: [ /*...*/ ], outputGuardrailSettings: { debounceTextLength: 500, // run guardrail every 500 characters or set it to -1 to run it only at the end }, }); ``` ## Conversation state and delegation [Section titled “Conversation state and delegation”](#conversation-state-and-delegation) ### Conversation history management [Section titled “Conversation history management”](#conversation-history-management) `RealtimeSession` automatically maintains a local `history` snapshot that tracks user messages, assistant output, tool calls, and truncation state. You can render it in the UI, inspect it inside tools, or update it when you need to correct or remove items. As the conversation changes the session emits `history_updated`. If you need to request history changes, use `updateHistory()`. It asks the transport to diff the current history and send the necessary delete/create events; the local `session.history` view updates as the corresponding conversation events come back. ```typescript import { RealtimeSession, RealtimeAgent } from '@openai/agents/realtime'; const agent = new RealtimeAgent({ name: 'Assistant', }); const session = new RealtimeSession(agent, { model: 'gpt-realtime-2', }); await session.connect({ apiKey: '' }); // listening to the history_updated event session.on('history_updated', (history) => { // returns the full history of the session console.log(history); }); // Option 1: explicit setting session.updateHistory([ /* specific history */ ]); // Option 2: override based on current state like removing all agent messages session.updateHistory((currentHistory) => { return currentHistory.filter( (item) => !(item.type === 'message' && item.role === 'assistant'), ); }); ``` #### Limitations [Section titled “Limitations”](#limitations) 1. You cannot currently edit function tool calls after the fact. 2. Assistant text in history depends on available transcripts, including `output_audio.transcript`. 3. Responses truncated by interruption do not retain a final transcript. 4. Input audio transcription is best treated as a rough guide to what the user said, not an exact copy of how the model interpreted the audio. ### Delegation through tools [Section titled “Delegation through tools”](#delegation-through-tools) ![Delegation through tools](https://cdn.openai.com/API/docs/diagram-speech-to-speech-agent-tools.png) By combining the conversation history with a tool call, you can delegate the conversation to another backend agent to perform a more complex action and then pass it back as the result to the user. ```typescript import { RealtimeAgent, RealtimeContextData, tool, } from '@openai/agents/realtime'; import { handleRefundRequest } from './serverAgent'; import z from 'zod'; const refundSupervisorParameters = z.object({ request: z.string(), }); const refundSupervisor = tool< typeof refundSupervisorParameters, RealtimeContextData >({ name: 'escalateToRefundSupervisor', description: 'Escalate a refund request to the refund supervisor', parameters: refundSupervisorParameters, execute: async ({ request }, details) => { // This will execute on the server return handleRefundRequest(request, details?.context?.history ?? []); }, }); const agent = new RealtimeAgent({ name: 'Customer Support', instructions: 'You are a customer support agent. If you receive any requests for refunds, you need to delegate to your supervisor.', tools: [refundSupervisor], }); ``` The code below then runs on the server, in this example via a Next.js Server Action. ```typescript // This runs on the server import 'server-only'; import { Agent, run } from '@openai/agents'; import type { RealtimeItem } from '@openai/agents/realtime'; import z from 'zod'; const agent = new Agent({ name: 'Refund Expert', instructions: 'You are a refund expert. You are given a request to process a refund and you need to determine if the request is valid.', model: 'gpt-5.4', outputType: z.object({ reasong: z.string(), refundApproved: z.boolean(), }), }); export async function handleRefundRequest( request: string, history: RealtimeItem[], ) { const input = ` The user has requested a refund. The request is: ${request} Current conversation history: ${JSON.stringify(history, null, 2)} `.trim(); const result = await run(agent, input); return JSON.stringify(result.finalOutput, null, 2); } ``` # Voice Agents Quickstart > Build your first realtime voice assistant using the OpenAI Agents SDK in minutes. Note This quickstart uses `@openai/agents`, which is the recommended default for most apps. If you prefer the standalone Realtime package, install `@openai/agents-realtime` and replace imports from `@openai/agents/realtime` with `@openai/agents-realtime` in the examples below. ## Project setup and credentials [Section titled “Project setup and credentials”](#project-setup-and-credentials) 1. **Create a project** In this quickstart we will create a voice agent you can use in the browser. If you want to scaffold a new project, you can start with [`Next.js`](https://nextjs.org/docs/getting-started/installation) or [`Vite`](https://vite.dev/guide/installation.html). ```bash npm create vite@latest my-project -- --template vanilla-ts ``` 2. **Install the recommended package** (requires Zod v4) ```bash npm install @openai/agents zod ``` 3. **Generate a client ephemeral token** As this application will run in the user’s browser, we need a secure way to connect to the model through the Realtime API. The recommended flow matches the official [Realtime API with WebRTC](https://developers.openai.com/api/docs/guides/realtime-webrtc/) guide: your backend creates a short-lived ephemeral client token, then your browser uses that token to establish the WebRTC connection. For testing purposes you can also generate a token using `curl` and your regular OpenAI API key. ```bash export OPENAI_API_KEY="sk-proj-...(your own key here)" curl -X POST https://api.openai.com/v1/realtime/client_secrets \ -H "Authorization: Bearer $OPENAI_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "session": { "type": "realtime", "model": "gpt-realtime-2" } }' ``` The response contains a top-level `value` field that starts with the `ek_` prefix, plus the effective `session` object. Use `value` as the client secret when establishing the WebRTC connection. This token is short-lived, so your backend should mint a fresh one when needed. If your browser session needs hosted MCP tools with `authorization` or custom `headers`, include that hosted MCP configuration in the server-side `session` payload you send to `POST /v1/realtime/client_secrets` instead of exposing those credentials in browser code. Note Production browser flow: the browser asks your backend for a fresh ephemeral token, your backend calls `POST /v1/realtime/client_secrets` with a server API key, and the browser passes the returned `ek_...` token to `session.connect(...)`. ## Create and connect the voice agent [Section titled “Create and connect the voice agent”](#create-and-connect-the-voice-agent) 1. **Create your first Agent** Creating a new [`RealtimeAgent`](/openai-agents-js/openai/agents-realtime/classes/realtimeagent/) is very similar to creating a regular [`Agent`](/openai-agents-js/guides/agents). ```typescript import { RealtimeAgent } from '@openai/agents/realtime'; const agent = new RealtimeAgent({ name: 'Assistant', instructions: 'You are a helpful assistant.', }); ``` 2. **Create a session** Unlike a regular agent, a voice agent is continuously running inside a `RealtimeSession` that handles the conversation and connection to the model over time. This session also manages audio processing, interruptions, and the broader conversation lifecycle that you will configure later on. ```typescript import { RealtimeSession } from '@openai/agents/realtime'; const session = new RealtimeSession(agent, { model: 'gpt-realtime-2', }); ``` The `RealtimeSession` constructor takes an `agent` as the first argument. This agent will be the first one your user interacts with. 3. **Connect to the session** To connect to the session you need to pass the client ephemeral token you generated earlier. ```typescript await session.connect({ apiKey: 'ek_...(put your own key here)' }); ``` In the browser, this connects to the Realtime API using WebRTC and automatically configures microphone capture and audio playback for you. On that default WebRTC path, the SDK sends the initial session configuration as soon as the data channel opens and tries to wait for the matching `session.updated` acknowledgement before `connect()` resolves, with a timeout fallback if that acknowledgement never arrives. If you run `RealtimeSession` in a server runtime such as Node.js, the SDK automatically falls back to WebSocket instead; on the WebSocket path, `connect()` resolves after the socket opens and the initial config has been sent, so `session.updated` may arrive slightly later. You can learn more about the transport choices in the [Realtime Transport Layer](/openai-agents-js/guides/voice-agents/transport) guide. Note If you want lower-level control over the peer connection or raw transport events, see the [`/raw-client` example in `examples/realtime-next`](https://github.com/openai/openai-agents-js/tree/main/examples/realtime-next). ## Run and test the app [Section titled “Run and test the app”](#run-and-test-the-app) 1. **Putting it all together** ```typescript import { RealtimeAgent, RealtimeSession } from '@openai/agents/realtime'; export async function setupCounter(element: HTMLButtonElement) { // .... // for quickly start, you can append the following code to the auto-generated TS code const agent = new RealtimeAgent({ name: 'Assistant', instructions: 'You are a helpful assistant.', }); const session = new RealtimeSession(agent); // Automatically connects your microphone and audio output in the browser via WebRTC. try { await session.connect({ // To get this ephemeral key string, you can run the following command or implement the equivalent on the server side: // curl -s -X POST https://api.openai.com/v1/realtime/client_secrets -H "Authorization: Bearer $OPENAI_API_KEY" -H "Content-Type: application/json" -d '{"session": {"type": "realtime", "model": "gpt-realtime-2"}}' | jq .value apiKey: 'ek_...(put your own key here)', }); console.log('You are connected!'); } catch (e) { console.error(e); } } ``` 2. **Fire up the app and start talking** Start your web server and open the page that includes your new Realtime Agent code. You should see a microphone permission request. Once you grant access, you should be able to start talking to your agent. ```bash npm run dev ``` ## Next Steps [Section titled “Next Steps”](#next-steps) From here you can start designing and building your own voice agent: * Add [tools](/openai-agents-js/guides/voice-agents/build#tools), [handoffs](/openai-agents-js/guides/voice-agents/build#handoffs), and [guardrails](/openai-agents-js/guides/voice-agents/build#guardrails). * Learn how [turn detection and voice activity detection](/openai-agents-js/guides/voice-agents/build#turn-detection-and-voice-activity-detection), [interruptions](/openai-agents-js/guides/voice-agents/build#interruptions), and [manual response control](/openai-agents-js/guides/voice-agents/build#manual-response-control) affect the conversation loop. * Add [text input](/openai-agents-js/guides/voice-agents/build#text-input), [image input](/openai-agents-js/guides/voice-agents/build#image-input), and [session history management](/openai-agents-js/guides/voice-agents/build#conversation-history-management). * Choose the right transport for your deployment: [WebRTC](/openai-agents-js/guides/voice-agents/transport#webrtc-is-the-default-browser-choice), [WebSocket](/openai-agents-js/guides/voice-agents/transport#websocket-is-the-default-server-choice), or [a custom transport](/openai-agents-js/guides/voice-agents/transport#bring-your-own-transport). # Realtime Transport Layer > Learn about the different transport layers that can be used with Realtime Agents. Choose the transport based on where the session runs and how much raw media or event control you need. | Scenario | Recommended transport | Why | | ----------------------------------------------- | ------------------------------ | ------------------------------------------------------------------------------------------------------ | | Browser speech-to-speech app | `OpenAIRealtimeWebRTC` | Lowest-friction path. The SDK manages microphone capture, playback, and the WebRTC connection for you. | | Server-side voice loop or custom audio pipeline | `OpenAIRealtimeWebSocket` | Works well when you already control audio capture/playback and want direct event access. | | SIP or telephony bridge | `OpenAIRealtimeSIP` | Attaches a `RealtimeSession` to an existing SIP-initiated Realtime call by `callId`. | | Cloudflare Workers / workerd | Cloudflare extension transport | workerd cannot open outbound WebSockets with the global `WebSocket` constructor. | | Provider-specific phone flow on Twilio | Twilio extension transport | Handles Twilio audio forwarding and interruption behavior for you. | Note If you are building a browser product and do not have a reason to manage raw audio yourself, start with WebRTC. If you are running on the server or bridging another media system, start with WebSocket or SIP. ## Default transport layers [Section titled “Default transport layers”](#default-transport-layers) ### WebRTC is the default browser choice [Section titled “WebRTC is the default browser choice”](#webrtc-is-the-default-browser-choice) The default browser transport uses WebRTC. Audio is captured from the microphone and played back automatically, which is why the [Quickstart](/openai-agents-js/guides/voice-agents/quickstart) can connect with just an ephemeral token and `session.connect(...)`. On this path, `session.connect()` tries to wait until the initial session configuration has been acknowledged with `session.updated` before it resolves, so your instructions and tools are applied before audio starts flowing. There is still a timeout fallback if that acknowledgement never arrives. To use your own media stream or audio element, provide an `OpenAIRealtimeWebRTC` instance when creating the session. ```typescript import { RealtimeAgent, RealtimeSession, OpenAIRealtimeWebRTC, } from '@openai/agents/realtime'; const agent = new RealtimeAgent({ name: 'Greeter', instructions: 'Greet the user with cheer and answer questions.', }); async function main() { const transport = new OpenAIRealtimeWebRTC({ mediaStream: await navigator.mediaDevices.getUserMedia({ audio: true }), audioElement: document.createElement('audio'), }); const customSession = new RealtimeSession(agent, { transport }); } ``` For lower-level customization, `OpenAIRealtimeWebRTC` also accepts `changePeerConnection`, which lets you inspect or replace the freshly created `RTCPeerConnection` before the offer is generated. ### WebSocket is the default server choice [Section titled “WebSocket is the default server choice”](#websocket-is-the-default-server-choice) Pass `transport: 'websocket'` or an instance of `OpenAIRealtimeWebSocket` when creating the session to use a WebSocket connection instead of WebRTC. This works well for server-side use cases, telephony bridges, and custom audio pipelines. On the WebSocket path, `session.connect()` resolves once the socket is open and the initial config has been sent. The matching `session.updated` event may arrive slightly later, so do not assume `connect()` means that update has already been echoed back. ```typescript import { RealtimeAgent, RealtimeSession } from '@openai/agents/realtime'; const agent = new RealtimeAgent({ name: 'Greeter', instructions: 'Greet the user with cheer and answer questions.', }); const myRecordedArrayBuffer = new ArrayBuffer(0); const wsSession = new RealtimeSession(agent, { transport: 'websocket', model: 'gpt-realtime-2', }); await wsSession.connect({ apiKey: process.env.OPENAI_API_KEY! }); wsSession.on('audio', (event) => { // event.data is a chunk of PCM16 audio }); wsSession.sendAudio(myRecordedArrayBuffer); ``` Use any recording/playback library to handle the raw PCM16 audio bytes. For advanced integrations, `OpenAIRealtimeWebSocket` accepts `createWebSocket()` so you can supply your own socket implementation, and `skipOpenEventListeners` when that custom connector is responsible for transitioning the socket into the connected state. The Cloudflare transport in `@openai/agents-extensions` is built on these hooks. ### SIP is for call providers and telephony bridges [Section titled “SIP is for call providers and telephony bridges”](#sip-is-for-call-providers-and-telephony-bridges) Use `OpenAIRealtimeSIP` when you want a `RealtimeSession` to attach to an existing SIP-initiated Realtime call. It is a thin SIP-aware transport: audio is handled by the SIP call itself, and you connect the SDK session by `callId`. 1. Accept the incoming call by generating an initial session configuration with `OpenAIRealtimeSIP.buildInitialConfig()`. This ensures the SIP invitation and the later SDK session start from the same defaults. 2. Attach a `RealtimeSession` that uses the `OpenAIRealtimeSIP` transport and connect with the `callId` issued by the provider webhook. 3. If you need provider-specific media forwarding or event bridging, use an integration transport such as the Twilio extension. Caution SIP call acceptance only supports a subset of Realtime turn-detection fields. `OpenAIRealtimeSIP.buildInitialConfig()` throws locally if your config includes `threshold`, `prefixPaddingMs`, or `silenceDurationMs` (or their snake\_case equivalents) because the Realtime Calls API rejects those `session.audio.input.turn_detection` properties for SIP sessions. ```typescript import OpenAI from 'openai'; import { OpenAIRealtimeSIP, RealtimeAgent, RealtimeSession, type RealtimeSessionOptions, } from '@openai/agents/realtime'; const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY!, webhookSecret: process.env.OPENAI_WEBHOOK_SECRET!, }); const agent = new RealtimeAgent({ name: 'Receptionist', instructions: 'Welcome the caller, answer scheduling questions, and hand off if the caller requests a human.', }); const sessionOptions: Partial = { model: 'gpt-realtime-2', config: { audio: { input: { turnDetection: { type: 'semantic_vad', interruptResponse: true }, }, }, }, }; export async function acceptIncomingCall(callId: string): Promise { const initialConfig = await OpenAIRealtimeSIP.buildInitialConfig( agent, sessionOptions, ); await openai.realtime.calls.accept(callId, initialConfig); } export async function attachRealtimeSession( callId: string, ): Promise { const session = new RealtimeSession(agent, { transport: new OpenAIRealtimeSIP(), ...sessionOptions, }); session.on('history_added', (item) => { console.log('Realtime update:', item.type); }); await session.connect({ apiKey: process.env.OPENAI_API_KEY!, callId, }); return session; } ``` ### Cloudflare Workers and workerd [Section titled “Cloudflare Workers and workerd”](#cloudflare-workers-and-workerd) Cloudflare Workers and other workerd runtimes cannot open outbound WebSockets using the global `WebSocket` constructor. Use the Cloudflare transport from the extensions package, which performs the `fetch()`-based upgrade internally. ```typescript import { CloudflareRealtimeTransportLayer } from '@openai/agents-extensions'; import { RealtimeAgent, RealtimeSession } from '@openai/agents/realtime'; const agent = new RealtimeAgent({ name: 'My Agent', }); // Create a transport that connects to OpenAI Realtime via Cloudflare/workerd's fetch-based upgrade. const cfTransport = new CloudflareRealtimeTransportLayer({ url: 'wss://api.openai.com/v1/realtime?model=gpt-realtime-2', }); const session = new RealtimeSession(agent, { // Set your own transport. transport: cfTransport, }); ``` For the full setup, read [Realtime Agents on Cloudflare](/openai-agents-js/extensions/cloudflare). ### Twilio phone calls [Section titled “Twilio phone calls”](#twilio-phone-calls) You can connect a `RealtimeSession` to Twilio using either raw WebSockets or the dedicated Twilio transport in `@openai/agents-extensions`. The dedicated transport is the better default when you want the SDK to handle interruption timing and audio forwarding for Twilio Media Streams. For the full setup, read [Realtime Agents on Twilio](/openai-agents-js/extensions/twilio). ### Bring your own transport [Section titled “Bring your own transport”](#bring-your-own-transport) If you want to use a different speech-to-speech API or have your own custom transport mechanism, you can implement the `RealtimeTransportLayer` interface and emit the `RealtimeTransportEventTypes` events yourself. ## Access raw Realtime events when you need them [Section titled “Access raw Realtime events when you need them”](#access-raw-realtime-events-when-you-need-them) If you want more direct access to the underlying Realtime API, you have two options. ### Option 1 - Accessing the transport layer [Section titled “Option 1 - Accessing the transport layer”](#option-1---accessing-the-transport-layer) If you still want to benefit from all of the capabilities of the `RealtimeSession` you can access your transport layer through `session.transport`. The transport layer emits every event it receives under the `*` event and you can send raw events using `sendEvent()`. This is the escape hatch for low-level operations such as `session.update`, `response.create`, or `response.cancel`. ```typescript import { RealtimeAgent, RealtimeSession } from '@openai/agents/realtime'; const agent = new RealtimeAgent({ name: 'Greeter', instructions: 'Greet the user with cheer and answer questions.', }); const session = new RealtimeSession(agent, { model: 'gpt-realtime-2', }); session.transport.on('*', (event) => { // JSON parsed version of the event received on the connection }); // Send any valid event as JSON. For example triggering a new response session.transport.sendEvent({ type: 'response.create', // ... }); ``` ### Option 2 - Only using the transport layer [Section titled “Option 2 - Only using the transport layer”](#option-2---only-using-the-transport-layer) If you do not need automatic tool execution, guardrails, or local history management, you can also use the transport layer as a “thin” client that just manages connection and interruptions. ```typescript import { OpenAIRealtimeWebRTC } from '@openai/agents/realtime'; const client = new OpenAIRealtimeWebRTC(); const audioBuffer = new ArrayBuffer(0); await client.connect({ apiKey: '', model: 'gpt-realtime-2', initialSessionConfig: { instructions: 'Speak like a pirate', outputModalities: ['audio'], audio: { input: { format: 'pcm16', }, output: { format: 'pcm16', voice: 'ash', }, }, }, }); // optionally for WebSockets client.on('audio', (newAudio) => {}); client.sendAudio(audioBuffer); ``` # Agent The class representing an AI agent configured with instructions, tools, guardrails, handoffs and more. We strongly recommend passing `instructions`, which is the “system prompt” for the agent. In addition, you can pass `handoffDescription`, which is a human-readable description of the agent, used when the agent is used inside tools/handoffs. Agents are generic on the context type. The context is a (mutable) object you create. It is passed to tool functions, handoffs, guardrails, etc. ## Extends [Section titled “Extends”](#extends) * [`AgentHooks`](/openai-agents-js/openai/agents-core/classes/agenthooks/)<`TContext`, `TOutput`> ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | ----------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------- | | `TContext` | [`UnknownContext`](/openai-agents-js/openai/agents-core/type-aliases/unknowncontext/) | | `TOutput` *extends* [`AgentOutputType`](/openai-agents-js/openai/agents-core/type-aliases/agentoutputtype/) | [`TextOutput`](/openai-agents-js/openai/agents-core/type-aliases/textoutput/) | ## Implements [Section titled “Implements”](#implements) * [`AgentConfiguration`](/openai-agents-js/openai/agents-core/interfaces/agentconfiguration/)<`TContext`, `TOutput`> ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new Agent(config): Agent; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | -------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `config` | { `handoffDescription?`: `string`; `handoffOutputTypeWarningEnabled?`: `boolean`; `handoffs?`: ( \| `Agent`<`any`, `any`> \| [`Handoff`](/openai-agents-js/openai/agents-core/classes/handoff/)<`any`, `TOutput`>)\[]; `inputGuardrails?`: [`InputGuardrail`](/openai-agents-js/openai/agents-core/interfaces/inputguardrail/)\[]; `instructions?`: `string` \| ((`runContext`, `agent`) => `string` \| `Promise`<`string`>); `mcpConfig?`: { `convertSchemasToStrict?`: `boolean`; `errorFunction?`: \| [`MCPToolErrorFunction`](/openai-agents-js/openai/agents-core/type-aliases/mcptoolerrorfunction/) \| `null`; `includeServerInToolNames?`: `boolean`; }; `mcpServers?`: [`MCPServer`](/openai-agents-js/openai/agents-core/interfaces/mcpserver/)\[]; `model?`: \| `string` \| [`Model`](/openai-agents-js/openai/agents-core/interfaces/model/); `modelSettings?`: [`ModelSettings`](/openai-agents-js/openai/agents-core/type-aliases/modelsettings/); `name`: `string`; `outputGuardrails?`: [`OutputGuardrail`](/openai-agents-js/openai/agents-core/interfaces/outputguardrail/)<`TOutput`, `TContext`>\[]; `outputType?`: `TOutput`; `prompt?`: `Prompt` \| ((`runContext`, `agent`) => `Prompt` \| `Promise`<`Prompt`>); `resetToolChoice?`: `boolean`; `tools?`: [`Tool`](/openai-agents-js/openai/agents-core/type-aliases/tool/)<`TContext`>\[]; `toolUseBehavior?`: [`ToolUseBehavior`](/openai-agents-js/openai/agents-core/type-aliases/toolusebehavior/); } | ‐ | | `config.handoffDescription?` | `string` | A description of the agent. This is used when the agent is used as a handoff, so that an LLM knows what it does and when to invoke it. | | `config.handoffOutputTypeWarningEnabled?` | `boolean` | The warning log would be enabled when multiple output types by handoff agents are detected. | | `config.handoffs?` | ( \| `Agent`<`any`, `any`> \| [`Handoff`](/openai-agents-js/openai/agents-core/classes/handoff/)<`any`, `TOutput`>)\[] | Handoffs are sub-agents that the agent can delegate to. You can provide a list of handoffs, and the agent can choose to delegate to them if relevant. Allows for separation of concerns and modularity. | | `config.inputGuardrails?` | [`InputGuardrail`](/openai-agents-js/openai/agents-core/interfaces/inputguardrail/)\[] | A list of checks that run in parallel to the agent by default; set `runInParallel` to false to block LLM/tool calls until the guardrail completes. Runs only if the agent is the first agent in the chain. | | `config.instructions?` | `string` \| ((`runContext`, `agent`) => `string` \| `Promise`<`string`>) | The instructions for the agent. Will be used as the “system prompt” when this agent is invoked. Describes what the agent should do, and how it responds.Can either be a string, or a function that dynamically generates instructions for the agent. If you provide a function, it will be called with the context and the agent instance. It must return a string. | | `config.mcpConfig?` | { `convertSchemasToStrict?`: `boolean`; `errorFunction?`: \| [`MCPToolErrorFunction`](/openai-agents-js/openai/agents-core/type-aliases/mcptoolerrorfunction/) \| `null`; `includeServerInToolNames?`: `boolean`; } | Configuration for MCP servers used by this agent. | | `config.mcpConfig.convertSchemasToStrict?` | `boolean` | Try to convert MCP tool schemas to strict JSON schema. | | `config.mcpConfig.errorFunction?` | \| [`MCPToolErrorFunction`](/openai-agents-js/openai/agents-core/type-aliases/mcptoolerrorfunction/) \| `null` | Optional function to convert MCP tool failures into model-visible messages. Set to null to rethrow errors instead of converting them. Server-level errorFunction values take precedence. | | `config.mcpConfig.includeServerInToolNames?` | `boolean` | Prefix local MCP tool names with their server name before exposing them to the model. The SDK still invokes the original MCP tool name on the original server. | | `config.mcpServers?` | [`MCPServer`](/openai-agents-js/openai/agents-core/interfaces/mcpserver/)\[] | A list of [Model Context Protocol](https://modelcontextprotocol.io/) servers the agent can use. Every time the agent runs, it will include tools from these servers in the list of available tools.NOTE: You are expected to manage the lifecycle of these servers. Specifically, you must call `server.connect()` before passing it to the agent, and `server.close()` when the server is no longer needed. Consider using `connectMcpServers` or `MCPServers` to keep open/close in the same place. | | `config.model?` | \| `string` \| [`Model`](/openai-agents-js/openai/agents-core/interfaces/model/) | The model implementation to use when invoking the LLM.By default, if not set, the agent will use the default model returned by getDefaultModel (currently “gpt-5.4-mini”). | | `config.modelSettings?` | [`ModelSettings`](/openai-agents-js/openai/agents-core/type-aliases/modelsettings/) | Configures model-specific tuning parameters (e.g. temperature, top\_p, etc.) | | `config.name` | `string` | ‐ | | `config.outputGuardrails?` | [`OutputGuardrail`](/openai-agents-js/openai/agents-core/interfaces/outputguardrail/)<`TOutput`, `TContext`>\[] | A list of checks that run on the final output of the agent, after generating a response. Runs only if the agent produces a final output. | | `config.outputType?` | `TOutput` | The type of the output object. If not provided, the output will be a string. | | `config.prompt?` | `Prompt` \| ((`runContext`, `agent`) => `Prompt` \| `Promise`<`Prompt`>) | The prompt template to use for the agent (OpenAI Responses API only).Can either be a prompt template object, or a function that returns a prompt template object. If a function is provided, it will be called with the run context and the agent instance. It must return a prompt template object. | | `config.resetToolChoice?` | `boolean` | Whether to reset the tool choice to the default value after a tool has been called. Defaults to `true`. This ensures that the agent doesn’t enter an infinite loop of tool usage. | | `config.tools?` | [`Tool`](/openai-agents-js/openai/agents-core/type-aliases/tool/)<`TContext`>\[] | A list of tools the agent can use. | | `config.toolUseBehavior?` | [`ToolUseBehavior`](/openai-agents-js/openai/agents-core/type-aliases/toolusebehavior/) | This lets you configure how tool use is handled.- run\_llm\_again: The default behavior. Tools are run, and then the LLM receives the results and gets to respond. - stop\_on\_first\_tool: The output of the first tool call is used as the final output. This means that the LLM does not process the result of the tool call. - A list of tool names: The agent will stop running if any of the tools in the list are called. The final output will be the output of the first matching tool call. The LLM does not process the result of the tool call. - A function: if you pass a function, it will be called with the run context and the list of tool results. It must return a `ToolsToFinalOutputResult`, which determines whether the tool call resulted in a final output.NOTE: This configuration is specific to `FunctionTools`. Hosted tools, such as file search, web search, etc. are always processed by the LLM | #### Returns [Section titled “Returns”](#returns) `Agent`<`TContext`, `TOutput`> #### Overrides [Section titled “Overrides”](#overrides) [`AgentHooks`](/openai-agents-js/openai/agents-core/classes/agenthooks/).[`constructor`](/openai-agents-js/openai/agents-core/classes/agenthooks/#constructor) ## Properties [Section titled “Properties”](#properties) ### handoffDescription [Section titled “handoffDescription”](#handoffdescription) ```ts handoffDescription: string; ``` A description of the agent. This is used when the agent is used as a handoff, so that an LLM knows what it does and when to invoke it. #### Implementation of [Section titled “Implementation of”](#implementation-of) [`AgentConfiguration`](/openai-agents-js/openai/agents-core/interfaces/agentconfiguration/).[`handoffDescription`](/openai-agents-js/openai/agents-core/interfaces/agentconfiguration/#handoffdescription) *** ### handoffs [Section titled “handoffs”](#handoffs) ```ts handoffs: ( | Agent | Handoff)[]; ``` Handoffs are sub-agents that the agent can delegate to. You can provide a list of handoffs, and the agent can choose to delegate to them if relevant. Allows for separation of concerns and modularity. #### Implementation of [Section titled “Implementation of”](#implementation-of-1) [`AgentConfiguration`](/openai-agents-js/openai/agents-core/interfaces/agentconfiguration/).[`handoffs`](/openai-agents-js/openai/agents-core/interfaces/agentconfiguration/#handoffs) *** ### inputGuardrails [Section titled “inputGuardrails”](#inputguardrails) ```ts inputGuardrails: InputGuardrail[]; ``` A list of checks that run in parallel to the agent by default; set `runInParallel` to false to block LLM/tool calls until the guardrail completes. Runs only if the agent is the first agent in the chain. #### Implementation of [Section titled “Implementation of”](#implementation-of-2) [`AgentConfiguration`](/openai-agents-js/openai/agents-core/interfaces/agentconfiguration/).[`inputGuardrails`](/openai-agents-js/openai/agents-core/interfaces/agentconfiguration/#inputguardrails) *** ### instructions [Section titled “instructions”](#instructions) ```ts instructions: string | ((runContext, agent) => string | Promise); ``` The instructions for the agent. Will be used as the “system prompt” when this agent is invoked. Describes what the agent should do, and how it responds. Can either be a string, or a function that dynamically generates instructions for the agent. If you provide a function, it will be called with the context and the agent instance. It must return a string. #### Implementation of [Section titled “Implementation of”](#implementation-of-3) [`AgentConfiguration`](/openai-agents-js/openai/agents-core/interfaces/agentconfiguration/).[`instructions`](/openai-agents-js/openai/agents-core/interfaces/agentconfiguration/#instructions) *** ### mcpConfig [Section titled “mcpConfig”](#mcpconfig) ```ts mcpConfig: object; ``` Configuration for MCP servers used by this agent. | Name | Type | Description | | --------------------------- | -------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `convertSchemasToStrict?` | `boolean` | Try to convert MCP tool schemas to strict JSON schema. | | `errorFunction?` | \| [`MCPToolErrorFunction`](/openai-agents-js/openai/agents-core/type-aliases/mcptoolerrorfunction/) \| `null` | Optional function to convert MCP tool failures into model-visible messages. Set to null to rethrow errors instead of converting them. Server-level errorFunction values take precedence. | | `includeServerInToolNames?` | `boolean` | Prefix local MCP tool names with their server name before exposing them to the model. The SDK still invokes the original MCP tool name on the original server. | #### Implementation of [Section titled “Implementation of”](#implementation-of-4) [`AgentConfiguration`](/openai-agents-js/openai/agents-core/interfaces/agentconfiguration/).[`mcpConfig`](/openai-agents-js/openai/agents-core/interfaces/agentconfiguration/#mcpconfig) *** ### mcpServers [Section titled “mcpServers”](#mcpservers) ```ts mcpServers: MCPServer[]; ``` A list of [Model Context Protocol](https://modelcontextprotocol.io/) servers the agent can use. Every time the agent runs, it will include tools from these servers in the list of available tools. NOTE: You are expected to manage the lifecycle of these servers. Specifically, you must call `server.connect()` before passing it to the agent, and `server.close()` when the server is no longer needed. Consider using `connectMcpServers` or `MCPServers` to keep open/close in the same place. #### Implementation of [Section titled “Implementation of”](#implementation-of-5) [`AgentConfiguration`](/openai-agents-js/openai/agents-core/interfaces/agentconfiguration/).[`mcpServers`](/openai-agents-js/openai/agents-core/interfaces/agentconfiguration/#mcpservers) *** ### model [Section titled “model”](#model) ```ts model: | string | Model; ``` The model implementation to use when invoking the LLM. By default, if not set, the agent will use the default model returned by getDefaultModel (currently “gpt-5.4-mini”). #### Implementation of [Section titled “Implementation of”](#implementation-of-6) [`AgentConfiguration`](/openai-agents-js/openai/agents-core/interfaces/agentconfiguration/).[`model`](/openai-agents-js/openai/agents-core/interfaces/agentconfiguration/#model) *** ### modelSettings [Section titled “modelSettings”](#modelsettings) ```ts modelSettings: ModelSettings; ``` Configures model-specific tuning parameters (e.g. temperature, top\_p, etc.) #### Implementation of [Section titled “Implementation of”](#implementation-of-7) [`AgentConfiguration`](/openai-agents-js/openai/agents-core/interfaces/agentconfiguration/).[`modelSettings`](/openai-agents-js/openai/agents-core/interfaces/agentconfiguration/#modelsettings) *** ### name [Section titled “name”](#name) ```ts name: string; ``` #### Implementation of [Section titled “Implementation of”](#implementation-of-8) [`AgentConfiguration`](/openai-agents-js/openai/agents-core/interfaces/agentconfiguration/).[`name`](/openai-agents-js/openai/agents-core/interfaces/agentconfiguration/#name) *** ### outputGuardrails [Section titled “outputGuardrails”](#outputguardrails) ```ts outputGuardrails: OutputGuardrail, TContext>[]; ``` A list of checks that run on the final output of the agent, after generating a response. Runs only if the agent produces a final output. #### Implementation of [Section titled “Implementation of”](#implementation-of-9) [`AgentConfiguration`](/openai-agents-js/openai/agents-core/interfaces/agentconfiguration/).[`outputGuardrails`](/openai-agents-js/openai/agents-core/interfaces/agentconfiguration/#outputguardrails) *** ### outputType [Section titled “outputType”](#outputtype) ```ts outputType: TOutput; ``` The type of the output object. If not provided, the output will be a string. #### Implementation of [Section titled “Implementation of”](#implementation-of-10) [`AgentConfiguration`](/openai-agents-js/openai/agents-core/interfaces/agentconfiguration/).[`outputType`](/openai-agents-js/openai/agents-core/interfaces/agentconfiguration/#outputtype) *** ### prompt? [Section titled “prompt?”](#prompt) ```ts optional prompt?: Prompt | ((runContext, agent) => Prompt | Promise); ``` The prompt template to use for the agent (OpenAI Responses API only). Can either be a prompt template object, or a function that returns a prompt template object. If a function is provided, it will be called with the run context and the agent instance. It must return a prompt template object. #### Implementation of [Section titled “Implementation of”](#implementation-of-11) [`AgentConfiguration`](/openai-agents-js/openai/agents-core/interfaces/agentconfiguration/).[`prompt`](/openai-agents-js/openai/agents-core/interfaces/agentconfiguration/#prompt) *** ### resetToolChoice [Section titled “resetToolChoice”](#resettoolchoice) ```ts resetToolChoice: boolean; ``` Whether to reset the tool choice to the default value after a tool has been called. Defaults to `true`. This ensures that the agent doesn’t enter an infinite loop of tool usage. #### Implementation of [Section titled “Implementation of”](#implementation-of-12) [`AgentConfiguration`](/openai-agents-js/openai/agents-core/interfaces/agentconfiguration/).[`resetToolChoice`](/openai-agents-js/openai/agents-core/interfaces/agentconfiguration/#resettoolchoice) *** ### tools [Section titled “tools”](#tools) ```ts tools: Tool[]; ``` A list of tools the agent can use. #### Implementation of [Section titled “Implementation of”](#implementation-of-13) [`AgentConfiguration`](/openai-agents-js/openai/agents-core/interfaces/agentconfiguration/).[`tools`](/openai-agents-js/openai/agents-core/interfaces/agentconfiguration/#tools) *** ### toolUseBehavior [Section titled “toolUseBehavior”](#toolusebehavior) ```ts toolUseBehavior: ToolUseBehavior; ``` This lets you configure how tool use is handled. * run\_llm\_again: The default behavior. Tools are run, and then the LLM receives the results and gets to respond. * stop\_on\_first\_tool: The output of the first tool call is used as the final output. This means that the LLM does not process the result of the tool call. * A list of tool names: The agent will stop running if any of the tools in the list are called. The final output will be the output of the first matching tool call. The LLM does not process the result of the tool call. * A function: if you pass a function, it will be called with the run context and the list of tool results. It must return a `ToolsToFinalOutputResult`, which determines whether the tool call resulted in a final output. NOTE: This configuration is specific to `FunctionTools`. Hosted tools, such as file search, web search, etc. are always processed by the LLM #### Implementation of [Section titled “Implementation of”](#implementation-of-14) [`AgentConfiguration`](/openai-agents-js/openai/agents-core/interfaces/agentconfiguration/).[`toolUseBehavior`](/openai-agents-js/openai/agents-core/interfaces/agentconfiguration/#toolusebehavior) *** ### DEFAULT\_MODEL\_PLACEHOLDER [Section titled “DEFAULT\_MODEL\_PLACEHOLDER”](#default_model_placeholder) ```ts static DEFAULT_MODEL_PLACEHOLDER: string = ''; ``` ## Accessors [Section titled “Accessors”](#accessors) ### outputSchemaName [Section titled “outputSchemaName”](#outputschemaname) #### Get Signature [Section titled “Get Signature”](#get-signature) ```ts get outputSchemaName(): string; ``` Output schema name. ##### Returns [Section titled “Returns”](#returns-1) `string` ## Methods [Section titled “Methods”](#methods) ### asTool() [Section titled “asTool()”](#astool) #### Call Signature [Section titled “Call Signature”](#call-signature) ```ts asTool(this, options): AgentTool>; ``` Transform this agent into a tool, callable by other agents. This is different from handoffs in two ways: 1. In handoffs, the new agent receives the conversation history. In this tool, the new agent receives generated input. 2. In handoffs, the new agent takes over the conversation. In this tool, the new agent is called as a tool, and the conversation is continued by the original agent. ##### Type Parameters [Section titled “Type Parameters”](#type-parameters-1) | Type Parameter | Default type | | ------------------------------------------------- | ------------------------------ | | `TAgent` *extends* `Agent`<`TContext`, `TOutput`> | `Agent`<`TContext`, `TOutput`> | ##### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | Description | | --------- | --------------------------------------------------- | --------------------- | | `this` | `TAgent` | ‐ | | `options` | `AgentToolOptionsWithDefault`<`TContext`, `TAgent`> | Options for the tool. | ##### Returns [Section titled “Returns”](#returns-2) `AgentTool`<`TContext`, `TAgent`, `ZodObject`<{ `input`: `ZodString`; }, `$strip`>> A tool that runs the agent and returns the output text. #### Call Signature [Section titled “Call Signature”](#call-signature-1) ```ts asTool(this, options): AgentTool; ``` Transform this agent into a tool, callable by other agents. This is different from handoffs in two ways: 1. In handoffs, the new agent receives the conversation history. In this tool, the new agent receives generated input. 2. In handoffs, the new agent takes over the conversation. In this tool, the new agent is called as a tool, and the conversation is continued by the original agent. ##### Type Parameters [Section titled “Type Parameters”](#type-parameters-2) | Type Parameter | Default type | | -------------------------------------------------- | ------------------------------------------------ | | `TAgent` *extends* `Agent`<`TContext`, `TOutput`> | `Agent`<`TContext`, `TOutput`> | | `TParameters` *extends* `AgentToolInputParameters` | `ZodObject`<{ `input`: `ZodString`; }, `$strip`> | ##### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | Description | | --------- | --------------------------------------------------------------------- | --------------------- | | `this` | `TAgent` | ‐ | | `options` | `AgentToolOptionsWithParameters`<`TContext`, `TAgent`, `TParameters`> | Options for the tool. | ##### Returns [Section titled “Returns”](#returns-3) `AgentTool`<`TContext`, `TAgent`, `TParameters`> A tool that runs the agent and returns the output text. *** ### clone() [Section titled “clone()”](#clone) ```ts clone(config): Agent; ``` Makes a copy of the agent, with the given arguments changed. For example, you could do: ```plaintext const newAgent = agent.clone({ instructions: 'New instructions' }) ``` #### Parameters [Section titled “Parameters”](#parameters-3) | Parameter | Type | Description | | --------- | ----------------------------------------------------------------------------------------------------------------------------- | ---------------------------------- | | `config` | `Partial`<[`AgentConfiguration`](/openai-agents-js/openai/agents-core/interfaces/agentconfiguration/)<`TContext`, `TOutput`>> | A partial configuration to change. | #### Returns [Section titled “Returns”](#returns-4) `Agent`<`TContext`, `TOutput`> A new agent with the given changes. *** ### emit() [Section titled “emit()”](#emit) ```ts emit(type, ...args): boolean; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-3) | Type Parameter | | ------------------------------------------------------------ | | `K` *extends* keyof `AgentHookEvents`<`TContext`, `TOutput`> | #### Parameters [Section titled “Parameters”](#parameters-4) | Parameter | Type | | --------- | ---------------------------------------------- | | `type` | `K` | | …`args` | `AgentHookEvents`<`TContext`, `TOutput`>\[`K`] | #### Returns [Section titled “Returns”](#returns-5) `boolean` #### Inherited from [Section titled “Inherited from”](#inherited-from) [`AgentHooks`](/openai-agents-js/openai/agents-core/classes/agenthooks/).[`emit`](/openai-agents-js/openai/agents-core/classes/agenthooks/#emit) *** ### getAllTools() [Section titled “getAllTools()”](#getalltools) ```ts getAllTools(runContext): Promise[]>; ``` ALl agent tools, including the MCPl and function tools. #### Parameters [Section titled “Parameters”](#parameters-5) | Parameter | Type | | ------------ | ------------------------------------------------------------------------------------ | | `runContext` | [`RunContext`](/openai-agents-js/openai/agents-core/classes/runcontext/)<`TContext`> | #### Returns [Section titled “Returns”](#returns-6) `Promise`<[`Tool`](/openai-agents-js/openai/agents-core/type-aliases/tool/)<`TContext`>\[]> all configured tools *** ### getEnabledHandoffs() [Section titled “getEnabledHandoffs()”](#getenabledhandoffs) ```ts getEnabledHandoffs(runContext): Promise[]>; ``` Returns the handoffs that should be exposed to the model for the current run. Handoffs that provide an `isEnabled` function returning `false` are omitted. #### Parameters [Section titled “Parameters”](#parameters-6) | Parameter | Type | | ------------ | ------------------------------------------------------------------------------------ | | `runContext` | [`RunContext`](/openai-agents-js/openai/agents-core/classes/runcontext/)<`TContext`> | #### Returns [Section titled “Returns”](#returns-7) `Promise`<[`Handoff`](/openai-agents-js/openai/agents-core/classes/handoff/)<`any`, `any`>\[]> *** ### getMcpTools() [Section titled “getMcpTools()”](#getmcptools) ```ts getMcpTools(runContext): Promise[]>; ``` Fetches the available tools from the MCP servers. #### Parameters [Section titled “Parameters”](#parameters-7) | Parameter | Type | | ------------ | ------------------------------------------------------------------------------------ | | `runContext` | [`RunContext`](/openai-agents-js/openai/agents-core/classes/runcontext/)<`TContext`> | #### Returns [Section titled “Returns”](#returns-8) `Promise`<[`Tool`](/openai-agents-js/openai/agents-core/type-aliases/tool/)<`TContext`>\[]> the MCP powered tools *** ### getPrompt() [Section titled “getPrompt()”](#getprompt) ```ts getPrompt(runContext): Promise; ``` Returns the prompt template for the agent, if defined. If the agent has a function as its prompt, this function will be called with the runContext and the agent instance. #### Parameters [Section titled “Parameters”](#parameters-8) | Parameter | Type | | ------------ | ------------------------------------------------------------------------------------ | | `runContext` | [`RunContext`](/openai-agents-js/openai/agents-core/classes/runcontext/)<`TContext`> | #### Returns [Section titled “Returns”](#returns-9) `Promise`<`Prompt` | `undefined`> *** ### getSystemPrompt() [Section titled “getSystemPrompt()”](#getsystemprompt) ```ts getSystemPrompt(runContext): Promise; ``` Returns the system prompt for the agent. If the agent has a function as its instructions, this function will be called with the runContext and the agent instance. #### Parameters [Section titled “Parameters”](#parameters-9) | Parameter | Type | | ------------ | ------------------------------------------------------------------------------------ | | `runContext` | [`RunContext`](/openai-agents-js/openai/agents-core/classes/runcontext/)<`TContext`> | #### Returns [Section titled “Returns”](#returns-10) `Promise`<`string` | `undefined`> *** ### hasExplicitToolConfig() [Section titled “hasExplicitToolConfig()”](#hasexplicittoolconfig) ```ts hasExplicitToolConfig(): boolean; ``` #### Returns [Section titled “Returns”](#returns-11) `boolean` *** ### off() [Section titled “off()”](#off) ```ts off(type, listener): EventEmitter>; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-4) | Type Parameter | | ------------------------------------------------------------ | | `K` *extends* keyof `AgentHookEvents`<`TContext`, `TOutput`> | #### Parameters [Section titled “Parameters”](#parameters-10) | Parameter | Type | | ---------- | ------------------- | | `type` | `K` | | `listener` | (…`args`) => `void` | #### Returns [Section titled “Returns”](#returns-12) `EventEmitter`<`AgentHookEvents`<`TContext`, `TOutput`>> #### Inherited from [Section titled “Inherited from”](#inherited-from-1) [`AgentHooks`](/openai-agents-js/openai/agents-core/classes/agenthooks/).[`off`](/openai-agents-js/openai/agents-core/classes/agenthooks/#off) *** ### on() [Section titled “on()”](#on) ```ts on(type, listener): EventEmitter>; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-5) | Type Parameter | | ------------------------------------------------------------ | | `K` *extends* keyof `AgentHookEvents`<`TContext`, `TOutput`> | #### Parameters [Section titled “Parameters”](#parameters-11) | Parameter | Type | | ---------- | ------------------- | | `type` | `K` | | `listener` | (…`args`) => `void` | #### Returns [Section titled “Returns”](#returns-13) `EventEmitter`<`AgentHookEvents`<`TContext`, `TOutput`>> #### Inherited from [Section titled “Inherited from”](#inherited-from-2) [`AgentHooks`](/openai-agents-js/openai/agents-core/classes/agenthooks/).[`on`](/openai-agents-js/openai/agents-core/classes/agenthooks/#on) *** ### once() [Section titled “once()”](#once) ```ts once(type, listener): EventEmitter>; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-6) | Type Parameter | | ------------------------------------------------------------ | | `K` *extends* keyof `AgentHookEvents`<`TContext`, `TOutput`> | #### Parameters [Section titled “Parameters”](#parameters-12) | Parameter | Type | | ---------- | ------------------- | | `type` | `K` | | `listener` | (…`args`) => `void` | #### Returns [Section titled “Returns”](#returns-14) `EventEmitter`<`AgentHookEvents`<`TContext`, `TOutput`>> #### Inherited from [Section titled “Inherited from”](#inherited-from-3) [`AgentHooks`](/openai-agents-js/openai/agents-core/classes/agenthooks/).[`once`](/openai-agents-js/openai/agents-core/classes/agenthooks/#once) *** ### processFinalOutput() [Section titled “processFinalOutput()”](#processfinaloutput) ```ts processFinalOutput(output): ResolvedAgentOutput; ``` Processes the final output of the agent. #### Parameters [Section titled “Parameters”](#parameters-13) | Parameter | Type | Description | | --------- | -------- | ------------------------ | | `output` | `string` | The output of the agent. | #### Returns [Section titled “Returns”](#returns-15) `ResolvedAgentOutput`<`TOutput`> The parsed out. *** ### toJSON() [Section titled “toJSON()”](#tojson) ```ts toJSON(): object; ``` Returns a JSON representation of the agent, which is serializable. #### Returns [Section titled “Returns”](#returns-16) `object` A JSON object containing the agent’s name. ##### name [Section titled “name”](#name-1) ```ts name: string; ``` *** ### create() [Section titled “create()”](#create) ```ts static create(config): Agent>; ``` Create an Agent with handoffs and automatically infer the union type for TOutput from the handoff agents’ output types. #### Type Parameters [Section titled “Type Parameters”](#type-parameters-7) | Type Parameter | Default type | | ------------------------------------------------------------------------------------------------------------------------------------------------ | ------------ | | `TOutput` *extends* [`AgentOutputType`](/openai-agents-js/openai/agents-core/type-aliases/agentoutputtype/)<`unknown`> | `"text"` | | `Handoffs` *extends* readonly ( \| `Agent`<`any`, `any`> \| [`Handoff`](/openai-agents-js/openai/agents-core/classes/handoff/)<`any`, `any`>)\[] | \[] | #### Parameters [Section titled “Parameters”](#parameters-14) | Parameter | Type | | --------- | ------------------------------------------------------------------------------------------------------------------------------ | | `config` | [`AgentConfigWithHandoffs`](/openai-agents-js/openai/agents-core/type-aliases/agentconfigwithhandoffs/)<`TOutput`, `Handoffs`> | #### Returns [Section titled “Returns”](#returns-17) `Agent`<`unknown`, `TOutput` | `HandoffsOutputUnion`<`Handoffs`>> # AgentHooks Event emitter that every Agent instance inherits from and that emits events for the lifecycle of the agent. ## Extends [Section titled “Extends”](#extends) * `EventEmitterDelegate`<`AgentHookEvents`<`TContext`, `TOutput`>> ## Extended by [Section titled “Extended by”](#extended-by) * [`Agent`](/openai-agents-js/openai/agents-core/classes/agent/) ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | ----------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------- | | `TContext` | [`UnknownContext`](/openai-agents-js/openai/agents-core/type-aliases/unknowncontext/) | | `TOutput` *extends* [`AgentOutputType`](/openai-agents-js/openai/agents-core/type-aliases/agentoutputtype/) | [`TextOutput`](/openai-agents-js/openai/agents-core/type-aliases/textoutput/) | ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new AgentHooks(): AgentHooks; ``` #### Returns [Section titled “Returns”](#returns) `AgentHooks`<`TContext`, `TOutput`> #### Inherited from [Section titled “Inherited from”](#inherited-from) ```ts EventEmitterDelegate>.constructor ``` ## Methods [Section titled “Methods”](#methods) ### emit() [Section titled “emit()”](#emit) ```ts emit(type, ...args): boolean; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-1) | Type Parameter | | ------------------------------------------------------------ | | `K` *extends* keyof `AgentHookEvents`<`TContext`, `TOutput`> | #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ---------------------------------------------- | | `type` | `K` | | …`args` | `AgentHookEvents`<`TContext`, `TOutput`>\[`K`] | #### Returns [Section titled “Returns”](#returns-1) `boolean` #### Inherited from [Section titled “Inherited from”](#inherited-from-1) ```ts EventEmitterDelegate.emit ``` *** ### off() [Section titled “off()”](#off) ```ts off(type, listener): EventEmitter>; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-2) | Type Parameter | | ------------------------------------------------------------ | | `K` *extends* keyof `AgentHookEvents`<`TContext`, `TOutput`> | #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | ---------- | ------------------- | | `type` | `K` | | `listener` | (…`args`) => `void` | #### Returns [Section titled “Returns”](#returns-2) `EventEmitter`<`AgentHookEvents`<`TContext`, `TOutput`>> #### Inherited from [Section titled “Inherited from”](#inherited-from-2) ```ts EventEmitterDelegate.off ``` *** ### on() [Section titled “on()”](#on) ```ts on(type, listener): EventEmitter>; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-3) | Type Parameter | | ------------------------------------------------------------ | | `K` *extends* keyof `AgentHookEvents`<`TContext`, `TOutput`> | #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | ---------- | ------------------- | | `type` | `K` | | `listener` | (…`args`) => `void` | #### Returns [Section titled “Returns”](#returns-3) `EventEmitter`<`AgentHookEvents`<`TContext`, `TOutput`>> #### Inherited from [Section titled “Inherited from”](#inherited-from-3) ```ts EventEmitterDelegate.on ``` *** ### once() [Section titled “once()”](#once) ```ts once(type, listener): EventEmitter>; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-4) | Type Parameter | | ------------------------------------------------------------ | | `K` *extends* keyof `AgentHookEvents`<`TContext`, `TOutput`> | #### Parameters [Section titled “Parameters”](#parameters-3) | Parameter | Type | | ---------- | ------------------- | | `type` | `K` | | `listener` | (…`args`) => `void` | #### Returns [Section titled “Returns”](#returns-4) `EventEmitter`<`AgentHookEvents`<`TContext`, `TOutput`>> #### Inherited from [Section titled “Inherited from”](#inherited-from-4) ```ts EventEmitterDelegate.once ``` # AgentsError Base class for all errors thrown by the library. ## Extends [Section titled “Extends”](#extends) * `Error` ## Extended by [Section titled “Extended by”](#extended-by) * [`GuardrailExecutionError`](/openai-agents-js/openai/agents-core/classes/guardrailexecutionerror/) * [`InputGuardrailTripwireTriggered`](/openai-agents-js/openai/agents-core/classes/inputguardrailtripwiretriggered/) * [`MaxTurnsExceededError`](/openai-agents-js/openai/agents-core/classes/maxturnsexceedederror/) * [`ModelBehaviorError`](/openai-agents-js/openai/agents-core/classes/modelbehaviorerror/) * [`ModelRefusalError`](/openai-agents-js/openai/agents-core/classes/modelrefusalerror/) * [`OutputGuardrailTripwireTriggered`](/openai-agents-js/openai/agents-core/classes/outputguardrailtripwiretriggered/) * [`ToolInputGuardrailTripwireTriggered`](/openai-agents-js/openai/agents-core/classes/toolinputguardrailtripwiretriggered/) * [`ToolOutputGuardrailTripwireTriggered`](/openai-agents-js/openai/agents-core/classes/tooloutputguardrailtripwiretriggered/) * [`ToolCallError`](/openai-agents-js/openai/agents-core/classes/toolcallerror/) * [`ToolTimeoutError`](/openai-agents-js/openai/agents-core/classes/tooltimeouterror/) * [`UserError`](/openai-agents-js/openai/agents-core/classes/usererror/) * [`SystemError`](/openai-agents-js/openai/agents-core/classes/systemerror/) ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new AgentsError(message, state?): AgentsError; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- | | `message` | `string` | | `state?` | [`RunState`](/openai-agents-js/openai/agents-core/classes/runstate/)<`any`, [`Agent`](/openai-agents-js/openai/agents-core/classes/agent/)<`any`, `any`>> | #### Returns [Section titled “Returns”](#returns) `AgentsError` #### Overrides [Section titled “Overrides”](#overrides) ```ts Error.constructor ``` ## Properties [Section titled “Properties”](#properties) ### message [Section titled “message”](#message) ```ts message: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from) ```ts Error.message ``` *** ### name [Section titled “name”](#name) ```ts name: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-1) ```ts Error.name ``` *** ### stack? [Section titled “stack?”](#stack) ```ts optional stack?: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-2) ```ts Error.stack ``` *** ### state? [Section titled “state?”](#state) ```ts optional state?: RunState>; ``` *** ### stackTraceLimit [Section titled “stackTraceLimit”](#stacktracelimit) ```ts static stackTraceLimit: number; ``` The `Error.stackTraceLimit` property specifies the number of stack frames collected by a stack trace (whether generated by `new Error().stack` or `Error.captureStackTrace(obj)`). The default value is `10` but may be set to any valid JavaScript number. Changes will affect any stack trace captured *after* the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames. #### Inherited from [Section titled “Inherited from”](#inherited-from-3) ```ts Error.stackTraceLimit ``` ## Methods [Section titled “Methods”](#methods) ### captureStackTrace() [Section titled “captureStackTrace()”](#capturestacktrace) ```ts static captureStackTrace(targetObject, constructorOpt?): void; ``` Creates a `.stack` property on `targetObject`, which when accessed returns a string representing the location in the code at which `Error.captureStackTrace()` was called. ```js const myObject = {}; Error.captureStackTrace(myObject); myObject.stack; // Similar to `new Error().stack` ``` The first line of the trace will be prefixed with `${myObject.name}: ${myObject.message}`. The optional `constructorOpt` argument accepts a function. If given, all frames above `constructorOpt`, including `constructorOpt`, will be omitted from the generated stack trace. The `constructorOpt` argument is useful for hiding implementation details of error generation from the user. For instance: ```js function a() { b(); } function b() { c(); } function c() { // Create an error without stack trace to avoid calculating the stack trace twice. const { stackTraceLimit } = Error; Error.stackTraceLimit = 0; const error = new Error(); Error.stackTraceLimit = stackTraceLimit; // Capture the stack trace above function b Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace throw error; } a(); ``` #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | ----------------- | ---------- | | `targetObject` | `object` | | `constructorOpt?` | `Function` | #### Returns [Section titled “Returns”](#returns-1) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-4) ```ts Error.captureStackTrace ``` *** ### prepareStackTrace() [Section titled “prepareStackTrace()”](#preparestacktrace) ```ts static prepareStackTrace(err, stackTraces): any; ``` #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | ------------- | ------------- | | `err` | `Error` | | `stackTraces` | `CallSite`\[] | #### Returns [Section titled “Returns”](#returns-2) `any` #### See [Section titled “See”](#see) #### Inherited from [Section titled “Inherited from”](#inherited-from-5) ```ts Error.prepareStackTrace ``` # BatchTraceProcessor Interface for processing traces ## Implements [Section titled “Implements”](#implements) * [`TracingProcessor`](/openai-agents-js/openai/agents-core/interfaces/tracingprocessor/) ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new BatchTraceProcessor(exporter, __namedParameters?): BatchTraceProcessor; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ------------------- | ------------------------------------------------------------------------------------- | | `exporter` | [`TracingExporter`](/openai-agents-js/openai/agents-core/interfaces/tracingexporter/) | | `__namedParameters` | `BatchTraceProcessorOptions` | #### Returns [Section titled “Returns”](#returns) `BatchTraceProcessor` ## Methods [Section titled “Methods”](#methods) ### forceFlush() [Section titled “forceFlush()”](#forceflush) ```ts forceFlush(): Promise; ``` Called when a trace is being flushed #### Returns [Section titled “Returns”](#returns-1) `Promise`<`void`> #### Implementation of [Section titled “Implementation of”](#implementation-of) [`TracingProcessor`](/openai-agents-js/openai/agents-core/interfaces/tracingprocessor/).[`forceFlush`](/openai-agents-js/openai/agents-core/interfaces/tracingprocessor/#forceflush) *** ### onSpanEnd() [Section titled “onSpanEnd()”](#onspanend) ```ts onSpanEnd(span): Promise; ``` Called when a span is ended #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | --------- | ------ | | `span` | `Span` | #### Returns [Section titled “Returns”](#returns-2) `Promise`<`void`> #### Implementation of [Section titled “Implementation of”](#implementation-of-1) [`TracingProcessor`](/openai-agents-js/openai/agents-core/interfaces/tracingprocessor/).[`onSpanEnd`](/openai-agents-js/openai/agents-core/interfaces/tracingprocessor/#onspanend) *** ### onSpanStart() [Section titled “onSpanStart()”](#onspanstart) ```ts onSpanStart(_span): Promise; ``` Called when a span is started #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | --------- | ------ | | `_span` | `Span` | #### Returns [Section titled “Returns”](#returns-3) `Promise`<`void`> #### Implementation of [Section titled “Implementation of”](#implementation-of-2) [`TracingProcessor`](/openai-agents-js/openai/agents-core/interfaces/tracingprocessor/).[`onSpanStart`](/openai-agents-js/openai/agents-core/interfaces/tracingprocessor/#onspanstart) *** ### onTraceEnd() [Section titled “onTraceEnd()”](#ontraceend) ```ts onTraceEnd(_trace): Promise; ``` Called when a trace is ended #### Parameters [Section titled “Parameters”](#parameters-3) | Parameter | Type | | --------- | -------------------------------------------------------------- | | `_trace` | [`Trace`](/openai-agents-js/openai/agents-core/classes/trace/) | #### Returns [Section titled “Returns”](#returns-4) `Promise`<`void`> #### Implementation of [Section titled “Implementation of”](#implementation-of-3) [`TracingProcessor`](/openai-agents-js/openai/agents-core/interfaces/tracingprocessor/).[`onTraceEnd`](/openai-agents-js/openai/agents-core/interfaces/tracingprocessor/#ontraceend) *** ### onTraceStart() [Section titled “onTraceStart()”](#ontracestart) ```ts onTraceStart(trace): Promise; ``` Called when a trace is started #### Parameters [Section titled “Parameters”](#parameters-4) | Parameter | Type | | --------- | -------------------------------------------------------------- | | `trace` | [`Trace`](/openai-agents-js/openai/agents-core/classes/trace/) | #### Returns [Section titled “Returns”](#returns-5) `Promise`<`void`> #### Implementation of [Section titled “Implementation of”](#implementation-of-4) [`TracingProcessor`](/openai-agents-js/openai/agents-core/interfaces/tracingprocessor/).[`onTraceStart`](/openai-agents-js/openai/agents-core/interfaces/tracingprocessor/#ontracestart) *** ### shutdown() [Section titled “shutdown()”](#shutdown) ```ts shutdown(timeout?): Promise; ``` Called when the trace processor is shutting down #### Parameters [Section titled “Parameters”](#parameters-5) | Parameter | Type | | ---------- | -------- | | `timeout?` | `number` | #### Returns [Section titled “Returns”](#returns-6) `Promise`<`void`> #### Implementation of [Section titled “Implementation of”](#implementation-of-5) [`TracingProcessor`](/openai-agents-js/openai/agents-core/interfaces/tracingprocessor/).[`shutdown`](/openai-agents-js/openai/agents-core/interfaces/tracingprocessor/#shutdown) *** ### start() [Section titled “start()”](#start) ```ts start(): void; ``` Called when the trace processor should start processing traces. Only available if the processor is performing tasks like exporting traces in a loop to start the loop #### Returns [Section titled “Returns”](#returns-7) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-6) [`TracingProcessor`](/openai-agents-js/openai/agents-core/interfaces/tracingprocessor/).[`start`](/openai-agents-js/openai/agents-core/interfaces/tracingprocessor/#start) # ConsoleSpanExporter Prints the traces and spans to the console ## Implements [Section titled “Implements”](#implements) * [`TracingExporter`](/openai-agents-js/openai/agents-core/interfaces/tracingexporter/) ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new ConsoleSpanExporter(): ConsoleSpanExporter; ``` #### Returns [Section titled “Returns”](#returns) `ConsoleSpanExporter` ## Methods [Section titled “Methods”](#methods) ### export() [Section titled “export()”](#export) ```ts export(items): Promise; ``` Export the given traces and spans #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | --------- | ----------------------------------------------------------------------------- | ------------------------------ | | `items` | (`Span` \| [`Trace`](/openai-agents-js/openai/agents-core/classes/trace/))\[] | The traces and spans to export | #### Returns [Section titled “Returns”](#returns-1) `Promise`<`void`> #### Implementation of [Section titled “Implementation of”](#implementation-of) [`TracingExporter`](/openai-agents-js/openai/agents-core/interfaces/tracingexporter/).[`export`](/openai-agents-js/openai/agents-core/interfaces/tracingexporter/#export) # GuardrailExecutionError Error thrown when a guardrail execution fails. ## Extends [Section titled “Extends”](#extends) * [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/) ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new GuardrailExecutionError( message, error, state?): GuardrailExecutionError; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- | | `message` | `string` | | `error` | `Error` | | `state?` | [`RunState`](/openai-agents-js/openai/agents-core/classes/runstate/)<`any`, [`Agent`](/openai-agents-js/openai/agents-core/classes/agent/)<`any`, `any`>> | #### Returns [Section titled “Returns”](#returns) `GuardrailExecutionError` #### Overrides [Section titled “Overrides”](#overrides) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`constructor`](/openai-agents-js/openai/agents-core/classes/agentserror/#constructor) ## Properties [Section titled “Properties”](#properties) ### error [Section titled “error”](#error) ```ts error: Error; ``` *** ### message [Section titled “message”](#message) ```ts message: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`message`](/openai-agents-js/openai/agents-core/classes/agentserror/#message) *** ### name [Section titled “name”](#name) ```ts name: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-1) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`name`](/openai-agents-js/openai/agents-core/classes/agentserror/#name) *** ### stack? [Section titled “stack?”](#stack) ```ts optional stack?: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-2) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`stack`](/openai-agents-js/openai/agents-core/classes/agentserror/#stack) *** ### state? [Section titled “state?”](#state) ```ts optional state?: RunState>; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-3) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`state`](/openai-agents-js/openai/agents-core/classes/agentserror/#state) *** ### stackTraceLimit [Section titled “stackTraceLimit”](#stacktracelimit) ```ts static stackTraceLimit: number; ``` The `Error.stackTraceLimit` property specifies the number of stack frames collected by a stack trace (whether generated by `new Error().stack` or `Error.captureStackTrace(obj)`). The default value is `10` but may be set to any valid JavaScript number. Changes will affect any stack trace captured *after* the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames. #### Inherited from [Section titled “Inherited from”](#inherited-from-4) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`stackTraceLimit`](/openai-agents-js/openai/agents-core/classes/agentserror/#stacktracelimit) ## Methods [Section titled “Methods”](#methods) ### captureStackTrace() [Section titled “captureStackTrace()”](#capturestacktrace) ```ts static captureStackTrace(targetObject, constructorOpt?): void; ``` Creates a `.stack` property on `targetObject`, which when accessed returns a string representing the location in the code at which `Error.captureStackTrace()` was called. ```js const myObject = {}; Error.captureStackTrace(myObject); myObject.stack; // Similar to `new Error().stack` ``` The first line of the trace will be prefixed with `${myObject.name}: ${myObject.message}`. The optional `constructorOpt` argument accepts a function. If given, all frames above `constructorOpt`, including `constructorOpt`, will be omitted from the generated stack trace. The `constructorOpt` argument is useful for hiding implementation details of error generation from the user. For instance: ```js function a() { b(); } function b() { c(); } function c() { // Create an error without stack trace to avoid calculating the stack trace twice. const { stackTraceLimit } = Error; Error.stackTraceLimit = 0; const error = new Error(); Error.stackTraceLimit = stackTraceLimit; // Capture the stack trace above function b Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace throw error; } a(); ``` #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | ----------------- | ---------- | | `targetObject` | `object` | | `constructorOpt?` | `Function` | #### Returns [Section titled “Returns”](#returns-1) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-5) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`captureStackTrace`](/openai-agents-js/openai/agents-core/classes/agentserror/#capturestacktrace) *** ### prepareStackTrace() [Section titled “prepareStackTrace()”](#preparestacktrace) ```ts static prepareStackTrace(err, stackTraces): any; ``` #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | ------------- | ------------- | | `err` | `Error` | | `stackTraces` | `CallSite`\[] | #### Returns [Section titled “Returns”](#returns-2) `any` #### See [Section titled “See”](#see) #### Inherited from [Section titled “Inherited from”](#inherited-from-6) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`prepareStackTrace`](/openai-agents-js/openai/agents-core/classes/agentserror/#preparestacktrace) # Handoff ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | ----------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------- | | `TContext` | [`UnknownContext`](/openai-agents-js/openai/agents-core/type-aliases/unknowncontext/) | | `TOutput` *extends* [`AgentOutputType`](/openai-agents-js/openai/agents-core/type-aliases/agentoutputtype/) | [`TextOutput`](/openai-agents-js/openai/agents-core/type-aliases/textoutput/) | ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new Handoff(agent, onInvokeHandoff): Handoff; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `agent` | [`Agent`](/openai-agents-js/openai/agents-core/classes/agent/)<`TContext`, `TOutput`> | | `onInvokeHandoff` | (`context`, `args`) => \| [`Agent`](/openai-agents-js/openai/agents-core/classes/agent/)<`TContext`, `TOutput`> \| `Promise`<[`Agent`](/openai-agents-js/openai/agents-core/classes/agent/)<`TContext`, `TOutput`>> | #### Returns [Section titled “Returns”](#returns) `Handoff`<`TContext`, `TOutput`> ## Properties [Section titled “Properties”](#properties) ### agent [Section titled “agent”](#agent) ```ts agent: Agent; ``` The agent that is being handed off to. *** ### agentName [Section titled “agentName”](#agentname) ```ts agentName: string; ``` The name of the agent that is being handed off to. *** ### inputFilter? [Section titled “inputFilter?”](#inputfilter) ```ts optional inputFilter?: HandoffInputFilter; ``` A function that filters the inputs that are passed to the next agent. By default, the new agent sees the entire conversation history. In some cases, you may want to filter inputs e.g. to remove older inputs, or remove tools from existing inputs. The function will receive the entire conversation hisstory so far, including the input item that triggered the handoff and a tool call output item representing the handoff tool’s output. You are free to modify the input history or new items as you see fit. The next agent that runs will receive \`handoffInputData.allItems *** ### inputJsonSchema [Section titled “inputJsonSchema”](#inputjsonschema) ```ts inputJsonSchema: JsonObjectSchema; ``` The JSON schema for the handoff input. Can be empty if the handoff does not take an input *** ### isEnabled [Section titled “isEnabled”](#isenabled) ```ts isEnabled: HandoffEnabledFunction; ``` *** ### onInvokeHandoff [Section titled “onInvokeHandoff”](#oninvokehandoff) ```ts onInvokeHandoff: (context, args) => | Agent | Promise>; ``` The function that invokes the handoff. The parameters passed are: 1. The handoff run context 2. The arguments from the LLM, as a JSON string. Empty string if inputJsonSchema is empty. Must return an agent #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | --------- | ------------------------------------------------------------------------------------ | | `context` | [`RunContext`](/openai-agents-js/openai/agents-core/classes/runcontext/)<`TContext`> | | `args` | `string` | #### Returns [Section titled “Returns”](#returns-1) \| [`Agent`](/openai-agents-js/openai/agents-core/classes/agent/)<`TContext`, `TOutput`> | `Promise`<[`Agent`](/openai-agents-js/openai/agents-core/classes/agent/)<`TContext`, `TOutput`>> *** ### strictJsonSchema [Section titled “strictJsonSchema”](#strictjsonschema) ```ts strictJsonSchema: boolean = true; ``` Whether the input JSON schema is in strict mode. We **strongly** recommend setting this to true, as it increases the likelihood of correct JSON input. *** ### toolDescription [Section titled “toolDescription”](#tooldescription) ```ts toolDescription: string; ``` The description of the tool that represents the handoff. *** ### toolName [Section titled “toolName”](#toolname) ```ts toolName: string; ``` The name of the tool that represents the handoff. ## Methods [Section titled “Methods”](#methods) ### getHandoffAsFunctionTool() [Section titled “getHandoffAsFunctionTool()”](#gethandoffasfunctiontool) ```ts getHandoffAsFunctionTool(): object; ``` Returns a function tool definition that can be used to invoke the handoff. #### Returns [Section titled “Returns”](#returns-2) `object` ##### description [Section titled “description”](#description) ```ts description: string; ``` ##### name [Section titled “name”](#name) ```ts name: string; ``` ##### parameters [Section titled “parameters”](#parameters-2) ```ts parameters: JsonObjectSchema; ``` ##### strict [Section titled “strict”](#strict) ```ts strict: boolean; ``` ##### type [Section titled “type”](#type) ```ts type: "function"; ``` # InputGuardrailTripwireTriggered Error thrown when an input guardrail tripwire is triggered. ## Extends [Section titled “Extends”](#extends) * [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/) ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new InputGuardrailTripwireTriggered( message, result, state?): InputGuardrailTripwireTriggered; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ----------------------------------------------------------------------------------------------- | | `message` | `string` | | `result` | [`InputGuardrailResult`](/openai-agents-js/openai/agents-core/interfaces/inputguardrailresult/) | | `state?` | [`RunState`](/openai-agents-js/openai/agents-core/classes/runstate/)<`any`, `any`> | #### Returns [Section titled “Returns”](#returns) `InputGuardrailTripwireTriggered` #### Overrides [Section titled “Overrides”](#overrides) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`constructor`](/openai-agents-js/openai/agents-core/classes/agentserror/#constructor) ## Properties [Section titled “Properties”](#properties) ### message [Section titled “message”](#message) ```ts message: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`message`](/openai-agents-js/openai/agents-core/classes/agentserror/#message) *** ### name [Section titled “name”](#name) ```ts name: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-1) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`name`](/openai-agents-js/openai/agents-core/classes/agentserror/#name) *** ### result [Section titled “result”](#result) ```ts result: InputGuardrailResult; ``` *** ### stack? [Section titled “stack?”](#stack) ```ts optional stack?: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-2) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`stack`](/openai-agents-js/openai/agents-core/classes/agentserror/#stack) *** ### state? [Section titled “state?”](#state) ```ts optional state?: RunState>; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-3) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`state`](/openai-agents-js/openai/agents-core/classes/agentserror/#state) *** ### stackTraceLimit [Section titled “stackTraceLimit”](#stacktracelimit) ```ts static stackTraceLimit: number; ``` The `Error.stackTraceLimit` property specifies the number of stack frames collected by a stack trace (whether generated by `new Error().stack` or `Error.captureStackTrace(obj)`). The default value is `10` but may be set to any valid JavaScript number. Changes will affect any stack trace captured *after* the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames. #### Inherited from [Section titled “Inherited from”](#inherited-from-4) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`stackTraceLimit`](/openai-agents-js/openai/agents-core/classes/agentserror/#stacktracelimit) ## Methods [Section titled “Methods”](#methods) ### captureStackTrace() [Section titled “captureStackTrace()”](#capturestacktrace) ```ts static captureStackTrace(targetObject, constructorOpt?): void; ``` Creates a `.stack` property on `targetObject`, which when accessed returns a string representing the location in the code at which `Error.captureStackTrace()` was called. ```js const myObject = {}; Error.captureStackTrace(myObject); myObject.stack; // Similar to `new Error().stack` ``` The first line of the trace will be prefixed with `${myObject.name}: ${myObject.message}`. The optional `constructorOpt` argument accepts a function. If given, all frames above `constructorOpt`, including `constructorOpt`, will be omitted from the generated stack trace. The `constructorOpt` argument is useful for hiding implementation details of error generation from the user. For instance: ```js function a() { b(); } function b() { c(); } function c() { // Create an error without stack trace to avoid calculating the stack trace twice. const { stackTraceLimit } = Error; Error.stackTraceLimit = 0; const error = new Error(); Error.stackTraceLimit = stackTraceLimit; // Capture the stack trace above function b Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace throw error; } a(); ``` #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | ----------------- | ---------- | | `targetObject` | `object` | | `constructorOpt?` | `Function` | #### Returns [Section titled “Returns”](#returns-1) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-5) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`captureStackTrace`](/openai-agents-js/openai/agents-core/classes/agentserror/#capturestacktrace) *** ### prepareStackTrace() [Section titled “prepareStackTrace()”](#preparestacktrace) ```ts static prepareStackTrace(err, stackTraces): any; ``` #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | ------------- | ------------- | | `err` | `Error` | | `stackTraces` | `CallSite`\[] | #### Returns [Section titled “Returns”](#returns-2) `any` #### See [Section titled “See”](#see) #### Inherited from [Section titled “Inherited from”](#inherited-from-6) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`prepareStackTrace`](/openai-agents-js/openai/agents-core/classes/agentserror/#preparestacktrace) # MaxTurnsExceededError Error thrown when the maximum number of turns is exceeded. ## Extends [Section titled “Extends”](#extends) * [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/) ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new MaxTurnsExceededError(message, state?): MaxTurnsExceededError; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- | | `message` | `string` | | `state?` | [`RunState`](/openai-agents-js/openai/agents-core/classes/runstate/)<`any`, [`Agent`](/openai-agents-js/openai/agents-core/classes/agent/)<`any`, `any`>> | #### Returns [Section titled “Returns”](#returns) `MaxTurnsExceededError` #### Inherited from [Section titled “Inherited from”](#inherited-from) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`constructor`](/openai-agents-js/openai/agents-core/classes/agentserror/#constructor) ## Properties [Section titled “Properties”](#properties) ### message [Section titled “message”](#message) ```ts message: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-1) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`message`](/openai-agents-js/openai/agents-core/classes/agentserror/#message) *** ### name [Section titled “name”](#name) ```ts name: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-2) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`name`](/openai-agents-js/openai/agents-core/classes/agentserror/#name) *** ### stack? [Section titled “stack?”](#stack) ```ts optional stack?: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-3) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`stack`](/openai-agents-js/openai/agents-core/classes/agentserror/#stack) *** ### state? [Section titled “state?”](#state) ```ts optional state?: RunState>; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-4) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`state`](/openai-agents-js/openai/agents-core/classes/agentserror/#state) *** ### stackTraceLimit [Section titled “stackTraceLimit”](#stacktracelimit) ```ts static stackTraceLimit: number; ``` The `Error.stackTraceLimit` property specifies the number of stack frames collected by a stack trace (whether generated by `new Error().stack` or `Error.captureStackTrace(obj)`). The default value is `10` but may be set to any valid JavaScript number. Changes will affect any stack trace captured *after* the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames. #### Inherited from [Section titled “Inherited from”](#inherited-from-5) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`stackTraceLimit`](/openai-agents-js/openai/agents-core/classes/agentserror/#stacktracelimit) ## Methods [Section titled “Methods”](#methods) ### captureStackTrace() [Section titled “captureStackTrace()”](#capturestacktrace) ```ts static captureStackTrace(targetObject, constructorOpt?): void; ``` Creates a `.stack` property on `targetObject`, which when accessed returns a string representing the location in the code at which `Error.captureStackTrace()` was called. ```js const myObject = {}; Error.captureStackTrace(myObject); myObject.stack; // Similar to `new Error().stack` ``` The first line of the trace will be prefixed with `${myObject.name}: ${myObject.message}`. The optional `constructorOpt` argument accepts a function. If given, all frames above `constructorOpt`, including `constructorOpt`, will be omitted from the generated stack trace. The `constructorOpt` argument is useful for hiding implementation details of error generation from the user. For instance: ```js function a() { b(); } function b() { c(); } function c() { // Create an error without stack trace to avoid calculating the stack trace twice. const { stackTraceLimit } = Error; Error.stackTraceLimit = 0; const error = new Error(); Error.stackTraceLimit = stackTraceLimit; // Capture the stack trace above function b Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace throw error; } a(); ``` #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | ----------------- | ---------- | | `targetObject` | `object` | | `constructorOpt?` | `Function` | #### Returns [Section titled “Returns”](#returns-1) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-6) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`captureStackTrace`](/openai-agents-js/openai/agents-core/classes/agentserror/#capturestacktrace) *** ### prepareStackTrace() [Section titled “prepareStackTrace()”](#preparestacktrace) ```ts static prepareStackTrace(err, stackTraces): any; ``` #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | ------------- | ------------- | | `err` | `Error` | | `stackTraces` | `CallSite`\[] | #### Returns [Section titled “Returns”](#returns-2) `any` #### See [Section titled “See”](#see) #### Inherited from [Section titled “Inherited from”](#inherited-from-7) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`prepareStackTrace`](/openai-agents-js/openai/agents-core/classes/agentserror/#preparestacktrace) # MCPServers Manages MCP server lifecycle and exposes only connected servers. ## Properties [Section titled “Properties”](#properties) ### \[asyncDispose] [Section titled “\[asyncDispose\]”](#asyncdispose) ```ts [asyncDispose]: () => Promise; ``` #### Returns [Section titled “Returns”](#returns) `Promise`<`void`> ## Accessors [Section titled “Accessors”](#accessors) ### active [Section titled “active”](#active) #### Get Signature [Section titled “Get Signature”](#get-signature) ```ts get active(): MCPServer[]; ``` ##### Returns [Section titled “Returns”](#returns-1) [`MCPServer`](/openai-agents-js/openai/agents-core/interfaces/mcpserver/)\[] *** ### all [Section titled “all”](#all) #### Get Signature [Section titled “Get Signature”](#get-signature-1) ```ts get all(): MCPServer[]; ``` ##### Returns [Section titled “Returns”](#returns-2) [`MCPServer`](/openai-agents-js/openai/agents-core/interfaces/mcpserver/)\[] *** ### errors [Section titled “errors”](#errors) #### Get Signature [Section titled “Get Signature”](#get-signature-2) ```ts get errors(): ReadonlyMap; ``` ##### Returns [Section titled “Returns”](#returns-3) `ReadonlyMap`<[`MCPServer`](/openai-agents-js/openai/agents-core/interfaces/mcpserver/), `Error`> *** ### failed [Section titled “failed”](#failed) #### Get Signature [Section titled “Get Signature”](#get-signature-3) ```ts get failed(): MCPServer[]; ``` ##### Returns [Section titled “Returns”](#returns-4) [`MCPServer`](/openai-agents-js/openai/agents-core/interfaces/mcpserver/)\[] ## Methods [Section titled “Methods”](#methods) ### close() [Section titled “close()”](#close) ```ts close(): Promise; ``` #### Returns [Section titled “Returns”](#returns-5) `Promise`<`void`> *** ### reconnect() [Section titled “reconnect()”](#reconnect) ```ts reconnect(options?): Promise; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ------------------------------------------------------------------------------------------------------------- | | `options` | [`MCPServersReconnectOptions`](/openai-agents-js/openai/agents-core/type-aliases/mcpserversreconnectoptions/) | #### Returns [Section titled “Returns”](#returns-6) `Promise`<[`MCPServer`](/openai-agents-js/openai/agents-core/interfaces/mcpserver/)\[]> *** ### open() [Section titled “open()”](#open) ```ts static open(servers, options?): Promise; ``` #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | ---------- | ------------------------------------------------------------------------------------------- | | `servers` | [`MCPServer`](/openai-agents-js/openai/agents-core/interfaces/mcpserver/)\[] | | `options?` | [`MCPServersOptions`](/openai-agents-js/openai/agents-core/type-aliases/mcpserversoptions/) | #### Returns [Section titled “Returns”](#returns-7) `Promise`<`MCPServers`> # MCPServerSSE Extended MCP server surface for servers that expose resources. ## Extends [Section titled “Extends”](#extends) * `BaseMCPServerSSE` ## Implements [Section titled “Implements”](#implements) * [`MCPServerWithResources`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/) ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new MCPServerSSE(options): MCPServerSSE; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | --------------------- | | `options` | `MCPServerSSEOptions` | #### Returns [Section titled “Returns”](#returns) `MCPServerSSE` #### Overrides [Section titled “Overrides”](#overrides) ```ts BaseMCPServerSSE.constructor ``` ## Properties [Section titled “Properties”](#properties) ### cacheToolsList [Section titled “cacheToolsList”](#cachetoolslist) ```ts cacheToolsList: boolean; ``` #### Implementation of [Section titled “Implementation of”](#implementation-of) [`MCPServerWithResources`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/).[`cacheToolsList`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/#cachetoolslist) #### Inherited from [Section titled “Inherited from”](#inherited-from) ```ts BaseMCPServerSSE.cacheToolsList ``` *** ### errorFunction? [Section titled “errorFunction?”](#errorfunction) ```ts optional errorFunction?: | MCPToolErrorFunction | null; ``` Optional function to convert MCP tool failures into model-visible messages. Set to null to rethrow errors instead of converting them. #### Implementation of [Section titled “Implementation of”](#implementation-of-1) [`MCPServerWithResources`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/).[`errorFunction`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/#errorfunction) #### Inherited from [Section titled “Inherited from”](#inherited-from-1) ```ts BaseMCPServerSSE.errorFunction ``` *** ### toolFilter? [Section titled “toolFilter?”](#toolfilter) ```ts optional toolFilter?: | MCPToolFilterStatic | MCPToolFilterCallable; ``` #### Implementation of [Section titled “Implementation of”](#implementation-of-2) [`MCPServerWithResources`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/).[`toolFilter`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/#toolfilter) #### Inherited from [Section titled “Inherited from”](#inherited-from-2) ```ts BaseMCPServerSSE.toolFilter ``` *** ### toolMetaResolver? [Section titled “toolMetaResolver?”](#toolmetaresolver) ```ts optional toolMetaResolver?: MCPToolMetaResolver; ``` #### Implementation of [Section titled “Implementation of”](#implementation-of-3) [`MCPServerWithResources`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/).[`toolMetaResolver`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/#toolmetaresolver) #### Inherited from [Section titled “Inherited from”](#inherited-from-3) ```ts BaseMCPServerSSE.toolMetaResolver ``` ## Accessors [Section titled “Accessors”](#accessors) ### name [Section titled “name”](#name) #### Get Signature [Section titled “Get Signature”](#get-signature) ```ts get name(): string; ``` ##### Returns [Section titled “Returns”](#returns-1) `string` #### Implementation of [Section titled “Implementation of”](#implementation-of-4) [`MCPServerWithResources`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/).[`name`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/#name) #### Overrides [Section titled “Overrides”](#overrides-1) ```ts BaseMCPServerSSE.name ``` ## Methods [Section titled “Methods”](#methods) ### callTool() [Section titled “callTool()”](#calltool) ```ts callTool( toolName, args, meta?): Promise; ``` #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | ---------- | --------------------------------------- | | `toolName` | `string` | | `args` | `Record`<`string`, `unknown`> \| `null` | | `meta?` | `Record`<`string`, `unknown`> \| `null` | #### Returns [Section titled “Returns”](#returns-2) `Promise`<`object`\[]> #### Implementation of [Section titled “Implementation of”](#implementation-of-5) [`MCPServerWithResources`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/).[`callTool`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/#calltool) #### Overrides [Section titled “Overrides”](#overrides-2) ```ts BaseMCPServerSSE.callTool ``` *** ### close() [Section titled “close()”](#close) ```ts close(): Promise; ``` #### Returns [Section titled “Returns”](#returns-3) `Promise`<`void`> #### Implementation of [Section titled “Implementation of”](#implementation-of-6) [`MCPServerWithResources`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/).[`close`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/#close) #### Overrides [Section titled “Overrides”](#overrides-3) ```ts BaseMCPServerSSE.close ``` *** ### connect() [Section titled “connect()”](#connect) ```ts connect(): Promise; ``` #### Returns [Section titled “Returns”](#returns-4) `Promise`<`void`> #### Implementation of [Section titled “Implementation of”](#implementation-of-7) [`MCPServerWithResources`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/).[`connect`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/#connect) #### Overrides [Section titled “Overrides”](#overrides-4) ```ts BaseMCPServerSSE.connect ``` *** ### invalidateToolsCache() [Section titled “invalidateToolsCache()”](#invalidatetoolscache) ```ts invalidateToolsCache(): Promise; ``` #### Returns [Section titled “Returns”](#returns-5) `Promise`<`void`> #### Implementation of [Section titled “Implementation of”](#implementation-of-8) [`MCPServerWithResources`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/).[`invalidateToolsCache`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/#invalidatetoolscache) #### Overrides [Section titled “Overrides”](#overrides-5) ```ts BaseMCPServerSSE.invalidateToolsCache ``` *** ### listResources() [Section titled “listResources()”](#listresources) ```ts listResources(params?): Promise; ``` #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | --------- | --------------------------------------------------------------------------------------------------- | | `params?` | [`MCPListResourcesParams`](/openai-agents-js/openai/agents-core/interfaces/mcplistresourcesparams/) | #### Returns [Section titled “Returns”](#returns-6) `Promise`<[`MCPListResourcesResult`](/openai-agents-js/openai/agents-core/interfaces/mcplistresourcesresult/)> #### Implementation of [Section titled “Implementation of”](#implementation-of-9) [`MCPServerWithResources`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/).[`listResources`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/#listresources) #### Overrides [Section titled “Overrides”](#overrides-6) ```ts BaseMCPServerSSE.listResources ``` *** ### listResourceTemplates() [Section titled “listResourceTemplates()”](#listresourcetemplates) ```ts listResourceTemplates(params?): Promise; ``` #### Parameters [Section titled “Parameters”](#parameters-3) | Parameter | Type | | --------- | --------------------------------------------------------------------------------------------------- | | `params?` | [`MCPListResourcesParams`](/openai-agents-js/openai/agents-core/interfaces/mcplistresourcesparams/) | #### Returns [Section titled “Returns”](#returns-7) `Promise`<[`MCPListResourceTemplatesResult`](/openai-agents-js/openai/agents-core/interfaces/mcplistresourcetemplatesresult/)> #### Implementation of [Section titled “Implementation of”](#implementation-of-10) [`MCPServerWithResources`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/).[`listResourceTemplates`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/#listresourcetemplates) #### Overrides [Section titled “Overrides”](#overrides-7) ```ts BaseMCPServerSSE.listResourceTemplates ``` *** ### listTools() [Section titled “listTools()”](#listtools) ```ts listTools(): Promise; ``` #### Returns [Section titled “Returns”](#returns-8) `Promise`<`object`\[]> #### Implementation of [Section titled “Implementation of”](#implementation-of-11) [`MCPServerWithResources`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/).[`listTools`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/#listtools) #### Overrides [Section titled “Overrides”](#overrides-8) ```ts BaseMCPServerSSE.listTools ``` *** ### readResource() [Section titled “readResource()”](#readresource) ```ts readResource(uri): Promise; ``` #### Parameters [Section titled “Parameters”](#parameters-4) | Parameter | Type | | --------- | -------- | | `uri` | `string` | #### Returns [Section titled “Returns”](#returns-9) `Promise`<[`MCPReadResourceResult`](/openai-agents-js/openai/agents-core/interfaces/mcpreadresourceresult/)> #### Implementation of [Section titled “Implementation of”](#implementation-of-12) [`MCPServerWithResources`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/).[`readResource`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/#readresource) #### Overrides [Section titled “Overrides”](#overrides-9) ```ts BaseMCPServerSSE.readResource ``` # MCPServerStdio Public interface of an MCP server that provides tools. You can use this class to pass MCP server settings to your agent. ## Extends [Section titled “Extends”](#extends) * `BaseMCPServerStdio` ## Implements [Section titled “Implements”](#implements) * [`MCPServerWithResources`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/) ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new MCPServerStdio(options): MCPServerStdio; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ----------------------- | | `options` | `MCPServerStdioOptions` | #### Returns [Section titled “Returns”](#returns) `MCPServerStdio` #### Overrides [Section titled “Overrides”](#overrides) ```ts BaseMCPServerStdio.constructor ``` ## Properties [Section titled “Properties”](#properties) ### cacheToolsList [Section titled “cacheToolsList”](#cachetoolslist) ```ts cacheToolsList: boolean; ``` #### Implementation of [Section titled “Implementation of”](#implementation-of) [`MCPServerWithResources`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/).[`cacheToolsList`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/#cachetoolslist) #### Inherited from [Section titled “Inherited from”](#inherited-from) ```ts BaseMCPServerStdio.cacheToolsList ``` *** ### errorFunction? [Section titled “errorFunction?”](#errorfunction) ```ts optional errorFunction?: | MCPToolErrorFunction | null; ``` Optional function to convert MCP tool failures into model-visible messages. Set to null to rethrow errors instead of converting them. #### Implementation of [Section titled “Implementation of”](#implementation-of-1) [`MCPServerWithResources`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/).[`errorFunction`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/#errorfunction) #### Inherited from [Section titled “Inherited from”](#inherited-from-1) ```ts BaseMCPServerStdio.errorFunction ``` *** ### toolFilter? [Section titled “toolFilter?”](#toolfilter) ```ts optional toolFilter?: | MCPToolFilterStatic | MCPToolFilterCallable; ``` #### Implementation of [Section titled “Implementation of”](#implementation-of-2) [`MCPServerWithResources`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/).[`toolFilter`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/#toolfilter) #### Inherited from [Section titled “Inherited from”](#inherited-from-2) ```ts BaseMCPServerStdio.toolFilter ``` *** ### toolMetaResolver? [Section titled “toolMetaResolver?”](#toolmetaresolver) ```ts optional toolMetaResolver?: MCPToolMetaResolver; ``` #### Implementation of [Section titled “Implementation of”](#implementation-of-3) [`MCPServerWithResources`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/).[`toolMetaResolver`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/#toolmetaresolver) #### Inherited from [Section titled “Inherited from”](#inherited-from-3) ```ts BaseMCPServerStdio.toolMetaResolver ``` ## Accessors [Section titled “Accessors”](#accessors) ### name [Section titled “name”](#name) #### Get Signature [Section titled “Get Signature”](#get-signature) ```ts get name(): string; ``` ##### Returns [Section titled “Returns”](#returns-1) `string` #### Implementation of [Section titled “Implementation of”](#implementation-of-4) [`MCPServerWithResources`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/).[`name`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/#name) #### Overrides [Section titled “Overrides”](#overrides-1) ```ts BaseMCPServerStdio.name ``` ## Methods [Section titled “Methods”](#methods) ### callTool() [Section titled “callTool()”](#calltool) ```ts callTool( toolName, args, meta?): Promise; ``` #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | ---------- | --------------------------------------- | | `toolName` | `string` | | `args` | `Record`<`string`, `unknown`> \| `null` | | `meta?` | `Record`<`string`, `unknown`> \| `null` | #### Returns [Section titled “Returns”](#returns-2) `Promise`<`object`\[]> #### Implementation of [Section titled “Implementation of”](#implementation-of-5) [`MCPServerWithResources`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/).[`callTool`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/#calltool) #### Overrides [Section titled “Overrides”](#overrides-2) ```ts BaseMCPServerStdio.callTool ``` *** ### close() [Section titled “close()”](#close) ```ts close(): Promise; ``` #### Returns [Section titled “Returns”](#returns-3) `Promise`<`void`> #### Implementation of [Section titled “Implementation of”](#implementation-of-6) [`MCPServerWithResources`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/).[`close`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/#close) #### Overrides [Section titled “Overrides”](#overrides-3) ```ts BaseMCPServerStdio.close ``` *** ### connect() [Section titled “connect()”](#connect) ```ts connect(): Promise; ``` #### Returns [Section titled “Returns”](#returns-4) `Promise`<`void`> #### Implementation of [Section titled “Implementation of”](#implementation-of-7) [`MCPServerWithResources`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/).[`connect`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/#connect) #### Overrides [Section titled “Overrides”](#overrides-4) ```ts BaseMCPServerStdio.connect ``` *** ### invalidateToolsCache() [Section titled “invalidateToolsCache()”](#invalidatetoolscache) ```ts invalidateToolsCache(): Promise; ``` #### Returns [Section titled “Returns”](#returns-5) `Promise`<`void`> #### Implementation of [Section titled “Implementation of”](#implementation-of-8) [`MCPServerWithResources`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/).[`invalidateToolsCache`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/#invalidatetoolscache) #### Overrides [Section titled “Overrides”](#overrides-5) ```ts BaseMCPServerStdio.invalidateToolsCache ``` *** ### listResources() [Section titled “listResources()”](#listresources) ```ts listResources(params?): Promise; ``` #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | --------- | --------------------------------------------------------------------------------------------------- | | `params?` | [`MCPListResourcesParams`](/openai-agents-js/openai/agents-core/interfaces/mcplistresourcesparams/) | #### Returns [Section titled “Returns”](#returns-6) `Promise`<[`MCPListResourcesResult`](/openai-agents-js/openai/agents-core/interfaces/mcplistresourcesresult/)> #### Implementation of [Section titled “Implementation of”](#implementation-of-9) [`MCPServerWithResources`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/).[`listResources`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/#listresources) #### Overrides [Section titled “Overrides”](#overrides-6) ```ts BaseMCPServerStdio.listResources ``` *** ### listResourceTemplates() [Section titled “listResourceTemplates()”](#listresourcetemplates) ```ts listResourceTemplates(params?): Promise; ``` #### Parameters [Section titled “Parameters”](#parameters-3) | Parameter | Type | | --------- | --------------------------------------------------------------------------------------------------- | | `params?` | [`MCPListResourcesParams`](/openai-agents-js/openai/agents-core/interfaces/mcplistresourcesparams/) | #### Returns [Section titled “Returns”](#returns-7) `Promise`<[`MCPListResourceTemplatesResult`](/openai-agents-js/openai/agents-core/interfaces/mcplistresourcetemplatesresult/)> #### Implementation of [Section titled “Implementation of”](#implementation-of-10) [`MCPServerWithResources`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/).[`listResourceTemplates`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/#listresourcetemplates) #### Overrides [Section titled “Overrides”](#overrides-7) ```ts BaseMCPServerStdio.listResourceTemplates ``` *** ### listTools() [Section titled “listTools()”](#listtools) ```ts listTools(): Promise; ``` #### Returns [Section titled “Returns”](#returns-8) `Promise`<`object`\[]> #### Implementation of [Section titled “Implementation of”](#implementation-of-11) [`MCPServerWithResources`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/).[`listTools`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/#listtools) #### Overrides [Section titled “Overrides”](#overrides-8) ```ts BaseMCPServerStdio.listTools ``` *** ### readResource() [Section titled “readResource()”](#readresource) ```ts readResource(uri): Promise; ``` #### Parameters [Section titled “Parameters”](#parameters-4) | Parameter | Type | | --------- | -------- | | `uri` | `string` | #### Returns [Section titled “Returns”](#returns-9) `Promise`<[`MCPReadResourceResult`](/openai-agents-js/openai/agents-core/interfaces/mcpreadresourceresult/)> #### Implementation of [Section titled “Implementation of”](#implementation-of-12) [`MCPServerWithResources`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/).[`readResource`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/#readresource) #### Overrides [Section titled “Overrides”](#overrides-9) ```ts BaseMCPServerStdio.readResource ``` # MCPServerStreamableHttp Extended MCP server surface for servers that expose resources. ## Extends [Section titled “Extends”](#extends) * `BaseMCPServerStreamableHttp` ## Implements [Section titled “Implements”](#implements) * [`MCPServerWithResources`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/) ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new MCPServerStreamableHttp(options): MCPServerStreamableHttp; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | -------------------------------- | | `options` | `MCPServerStreamableHttpOptions` | #### Returns [Section titled “Returns”](#returns) `MCPServerStreamableHttp` #### Overrides [Section titled “Overrides”](#overrides) ```ts BaseMCPServerStreamableHttp.constructor ``` ## Properties [Section titled “Properties”](#properties) ### cacheToolsList [Section titled “cacheToolsList”](#cachetoolslist) ```ts cacheToolsList: boolean; ``` #### Implementation of [Section titled “Implementation of”](#implementation-of) [`MCPServerWithResources`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/).[`cacheToolsList`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/#cachetoolslist) #### Inherited from [Section titled “Inherited from”](#inherited-from) ```ts BaseMCPServerStreamableHttp.cacheToolsList ``` *** ### errorFunction? [Section titled “errorFunction?”](#errorfunction) ```ts optional errorFunction?: | MCPToolErrorFunction | null; ``` Optional function to convert MCP tool failures into model-visible messages. Set to null to rethrow errors instead of converting them. #### Implementation of [Section titled “Implementation of”](#implementation-of-1) [`MCPServerWithResources`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/).[`errorFunction`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/#errorfunction) #### Inherited from [Section titled “Inherited from”](#inherited-from-1) ```ts BaseMCPServerStreamableHttp.errorFunction ``` *** ### toolFilter? [Section titled “toolFilter?”](#toolfilter) ```ts optional toolFilter?: | MCPToolFilterStatic | MCPToolFilterCallable; ``` #### Implementation of [Section titled “Implementation of”](#implementation-of-2) [`MCPServerWithResources`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/).[`toolFilter`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/#toolfilter) #### Inherited from [Section titled “Inherited from”](#inherited-from-2) ```ts BaseMCPServerStreamableHttp.toolFilter ``` *** ### toolMetaResolver? [Section titled “toolMetaResolver?”](#toolmetaresolver) ```ts optional toolMetaResolver?: MCPToolMetaResolver; ``` #### Implementation of [Section titled “Implementation of”](#implementation-of-3) [`MCPServerWithResources`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/).[`toolMetaResolver`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/#toolmetaresolver) #### Inherited from [Section titled “Inherited from”](#inherited-from-3) ```ts BaseMCPServerStreamableHttp.toolMetaResolver ``` ## Accessors [Section titled “Accessors”](#accessors) ### name [Section titled “name”](#name) #### Get Signature [Section titled “Get Signature”](#get-signature) ```ts get name(): string; ``` ##### Returns [Section titled “Returns”](#returns-1) `string` #### Implementation of [Section titled “Implementation of”](#implementation-of-4) [`MCPServerWithResources`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/).[`name`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/#name) #### Overrides [Section titled “Overrides”](#overrides-1) ```ts BaseMCPServerStreamableHttp.name ``` *** ### sessionId [Section titled “sessionId”](#sessionid) #### Get Signature [Section titled “Get Signature”](#get-signature-1) ```ts get sessionId(): string | undefined; ``` ##### Returns [Section titled “Returns”](#returns-2) `string` | `undefined` #### Overrides [Section titled “Overrides”](#overrides-2) ```ts BaseMCPServerStreamableHttp.sessionId ``` ## Methods [Section titled “Methods”](#methods) ### callTool() [Section titled “callTool()”](#calltool) ```ts callTool( toolName, args, meta?): Promise; ``` #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | ---------- | --------------------------------------- | | `toolName` | `string` | | `args` | `Record`<`string`, `unknown`> \| `null` | | `meta?` | `Record`<`string`, `unknown`> \| `null` | #### Returns [Section titled “Returns”](#returns-3) `Promise`<`object`\[]> #### Implementation of [Section titled “Implementation of”](#implementation-of-5) [`MCPServerWithResources`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/).[`callTool`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/#calltool) #### Overrides [Section titled “Overrides”](#overrides-3) ```ts BaseMCPServerStreamableHttp.callTool ``` *** ### close() [Section titled “close()”](#close) ```ts close(): Promise; ``` #### Returns [Section titled “Returns”](#returns-4) `Promise`<`void`> #### Implementation of [Section titled “Implementation of”](#implementation-of-6) [`MCPServerWithResources`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/).[`close`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/#close) #### Overrides [Section titled “Overrides”](#overrides-4) ```ts BaseMCPServerStreamableHttp.close ``` *** ### connect() [Section titled “connect()”](#connect) ```ts connect(): Promise; ``` #### Returns [Section titled “Returns”](#returns-5) `Promise`<`void`> #### Implementation of [Section titled “Implementation of”](#implementation-of-7) [`MCPServerWithResources`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/).[`connect`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/#connect) #### Overrides [Section titled “Overrides”](#overrides-5) ```ts BaseMCPServerStreamableHttp.connect ``` *** ### invalidateToolsCache() [Section titled “invalidateToolsCache()”](#invalidatetoolscache) ```ts invalidateToolsCache(): Promise; ``` #### Returns [Section titled “Returns”](#returns-6) `Promise`<`void`> #### Implementation of [Section titled “Implementation of”](#implementation-of-8) [`MCPServerWithResources`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/).[`invalidateToolsCache`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/#invalidatetoolscache) #### Overrides [Section titled “Overrides”](#overrides-6) ```ts BaseMCPServerStreamableHttp.invalidateToolsCache ``` *** ### listResources() [Section titled “listResources()”](#listresources) ```ts listResources(params?): Promise; ``` #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | --------- | --------------------------------------------------------------------------------------------------- | | `params?` | [`MCPListResourcesParams`](/openai-agents-js/openai/agents-core/interfaces/mcplistresourcesparams/) | #### Returns [Section titled “Returns”](#returns-7) `Promise`<[`MCPListResourcesResult`](/openai-agents-js/openai/agents-core/interfaces/mcplistresourcesresult/)> #### Implementation of [Section titled “Implementation of”](#implementation-of-9) [`MCPServerWithResources`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/).[`listResources`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/#listresources) #### Overrides [Section titled “Overrides”](#overrides-7) ```ts BaseMCPServerStreamableHttp.listResources ``` *** ### listResourceTemplates() [Section titled “listResourceTemplates()”](#listresourcetemplates) ```ts listResourceTemplates(params?): Promise; ``` #### Parameters [Section titled “Parameters”](#parameters-3) | Parameter | Type | | --------- | --------------------------------------------------------------------------------------------------- | | `params?` | [`MCPListResourcesParams`](/openai-agents-js/openai/agents-core/interfaces/mcplistresourcesparams/) | #### Returns [Section titled “Returns”](#returns-8) `Promise`<[`MCPListResourceTemplatesResult`](/openai-agents-js/openai/agents-core/interfaces/mcplistresourcetemplatesresult/)> #### Implementation of [Section titled “Implementation of”](#implementation-of-10) [`MCPServerWithResources`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/).[`listResourceTemplates`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/#listresourcetemplates) #### Overrides [Section titled “Overrides”](#overrides-8) ```ts BaseMCPServerStreamableHttp.listResourceTemplates ``` *** ### listTools() [Section titled “listTools()”](#listtools) ```ts listTools(): Promise; ``` #### Returns [Section titled “Returns”](#returns-9) `Promise`<`object`\[]> #### Implementation of [Section titled “Implementation of”](#implementation-of-11) [`MCPServerWithResources`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/).[`listTools`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/#listtools) #### Overrides [Section titled “Overrides”](#overrides-9) ```ts BaseMCPServerStreamableHttp.listTools ``` *** ### readResource() [Section titled “readResource()”](#readresource) ```ts readResource(uri): Promise; ``` #### Parameters [Section titled “Parameters”](#parameters-4) | Parameter | Type | | --------- | -------- | | `uri` | `string` | #### Returns [Section titled “Returns”](#returns-10) `Promise`<[`MCPReadResourceResult`](/openai-agents-js/openai/agents-core/interfaces/mcpreadresourceresult/)> #### Implementation of [Section titled “Implementation of”](#implementation-of-12) [`MCPServerWithResources`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/).[`readResource`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/#readresource) #### Overrides [Section titled “Overrides”](#overrides-10) ```ts BaseMCPServerStreamableHttp.readResource ``` # MemorySession Simple in-memory session store intended for demos or tests. Not recommended for production use. ## Implements [Section titled “Implements”](#implements) * [`SessionHistoryRewriteAwareSession`](/openai-agents-js/openai/agents-core/interfaces/sessionhistoryrewriteawaresession/) ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new MemorySession(options?): MemorySession; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ---------------------- | | `options` | `MemorySessionOptions` | #### Returns [Section titled “Returns”](#returns) `MemorySession` ## Methods [Section titled “Methods”](#methods) ### addItems() [Section titled “addItems()”](#additems) ```ts addItems(items): Promise; ``` Append new items to the conversation history. #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | Description | | --------- | ---------------------------------------------------------------------------------------- | ------------------------------------ | | `items` | [`AgentInputItem`](/openai-agents-js/openai/agents-core/type-aliases/agentinputitem/)\[] | Items to add to the session history. | #### Returns [Section titled “Returns”](#returns-1) `Promise`<`void`> #### Implementation of [Section titled “Implementation of”](#implementation-of) [`SessionHistoryRewriteAwareSession`](/openai-agents-js/openai/agents-core/interfaces/sessionhistoryrewriteawaresession/).[`addItems`](/openai-agents-js/openai/agents-core/interfaces/sessionhistoryrewriteawaresession/#additems) *** ### applyHistoryMutations() [Section titled “applyHistoryMutations()”](#applyhistorymutations) ```ts applyHistoryMutations(args): Promise; ``` #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | --------- | ----------------------------------------------------------------------------------------------------------- | | `args` | [`SessionHistoryRewriteArgs`](/openai-agents-js/openai/agents-core/type-aliases/sessionhistoryrewriteargs/) | #### Returns [Section titled “Returns”](#returns-2) `Promise`<`void`> #### Implementation of [Section titled “Implementation of”](#implementation-of-1) [`SessionHistoryRewriteAwareSession`](/openai-agents-js/openai/agents-core/interfaces/sessionhistoryrewriteawaresession/).[`applyHistoryMutations`](/openai-agents-js/openai/agents-core/interfaces/sessionhistoryrewriteawaresession/#applyhistorymutations) *** ### clearSession() [Section titled “clearSession()”](#clearsession) ```ts clearSession(): Promise; ``` Remove all items that belong to the session and reset its state. #### Returns [Section titled “Returns”](#returns-3) `Promise`<`void`> #### Implementation of [Section titled “Implementation of”](#implementation-of-2) [`SessionHistoryRewriteAwareSession`](/openai-agents-js/openai/agents-core/interfaces/sessionhistoryrewriteawaresession/).[`clearSession`](/openai-agents-js/openai/agents-core/interfaces/sessionhistoryrewriteawaresession/#clearsession) *** ### getItems() [Section titled “getItems()”](#getitems) ```ts getItems(limit?): Promise; ``` Retrieve items from the conversation history. #### Parameters [Section titled “Parameters”](#parameters-3) | Parameter | Type | Description | | --------- | -------- | --------------------------------------------------------------------------------------------------------------------------- | | `limit?` | `number` | The maximum number of items to return. When provided the most recent limit items should be returned in chronological order. | #### Returns [Section titled “Returns”](#returns-4) `Promise`<[`AgentInputItem`](/openai-agents-js/openai/agents-core/type-aliases/agentinputitem/)\[]> #### Implementation of [Section titled “Implementation of”](#implementation-of-3) [`SessionHistoryRewriteAwareSession`](/openai-agents-js/openai/agents-core/interfaces/sessionhistoryrewriteawaresession/).[`getItems`](/openai-agents-js/openai/agents-core/interfaces/sessionhistoryrewriteawaresession/#getitems) *** ### getSessionId() [Section titled “getSessionId()”](#getsessionid) ```ts getSessionId(): Promise; ``` Ensure and return the identifier for this session. #### Returns [Section titled “Returns”](#returns-5) `Promise`<`string`> #### Implementation of [Section titled “Implementation of”](#implementation-of-4) [`SessionHistoryRewriteAwareSession`](/openai-agents-js/openai/agents-core/interfaces/sessionhistoryrewriteawaresession/).[`getSessionId`](/openai-agents-js/openai/agents-core/interfaces/sessionhistoryrewriteawaresession/#getsessionid) *** ### popItem() [Section titled “popItem()”](#popitem) ```ts popItem(): Promise< | AgentInputItem | undefined>; ``` Remove and return the most recent item from the conversation history if it exists. #### Returns [Section titled “Returns”](#returns-6) `Promise`< | [`AgentInputItem`](/openai-agents-js/openai/agents-core/type-aliases/agentinputitem/) | `undefined`> #### Implementation of [Section titled “Implementation of”](#implementation-of-5) [`SessionHistoryRewriteAwareSession`](/openai-agents-js/openai/agents-core/interfaces/sessionhistoryrewriteawaresession/).[`popItem`](/openai-agents-js/openai/agents-core/interfaces/sessionhistoryrewriteawaresession/#popitem) # ModelBehaviorError Error thrown when a model behavior is unexpected. ## Extends [Section titled “Extends”](#extends) * [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/) ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new ModelBehaviorError(message, state?): ModelBehaviorError; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- | | `message` | `string` | | `state?` | [`RunState`](/openai-agents-js/openai/agents-core/classes/runstate/)<`any`, [`Agent`](/openai-agents-js/openai/agents-core/classes/agent/)<`any`, `any`>> | #### Returns [Section titled “Returns”](#returns) `ModelBehaviorError` #### Inherited from [Section titled “Inherited from”](#inherited-from) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`constructor`](/openai-agents-js/openai/agents-core/classes/agentserror/#constructor) ## Properties [Section titled “Properties”](#properties) ### message [Section titled “message”](#message) ```ts message: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-1) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`message`](/openai-agents-js/openai/agents-core/classes/agentserror/#message) *** ### name [Section titled “name”](#name) ```ts name: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-2) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`name`](/openai-agents-js/openai/agents-core/classes/agentserror/#name) *** ### stack? [Section titled “stack?”](#stack) ```ts optional stack?: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-3) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`stack`](/openai-agents-js/openai/agents-core/classes/agentserror/#stack) *** ### state? [Section titled “state?”](#state) ```ts optional state?: RunState>; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-4) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`state`](/openai-agents-js/openai/agents-core/classes/agentserror/#state) *** ### stackTraceLimit [Section titled “stackTraceLimit”](#stacktracelimit) ```ts static stackTraceLimit: number; ``` The `Error.stackTraceLimit` property specifies the number of stack frames collected by a stack trace (whether generated by `new Error().stack` or `Error.captureStackTrace(obj)`). The default value is `10` but may be set to any valid JavaScript number. Changes will affect any stack trace captured *after* the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames. #### Inherited from [Section titled “Inherited from”](#inherited-from-5) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`stackTraceLimit`](/openai-agents-js/openai/agents-core/classes/agentserror/#stacktracelimit) ## Methods [Section titled “Methods”](#methods) ### captureStackTrace() [Section titled “captureStackTrace()”](#capturestacktrace) ```ts static captureStackTrace(targetObject, constructorOpt?): void; ``` Creates a `.stack` property on `targetObject`, which when accessed returns a string representing the location in the code at which `Error.captureStackTrace()` was called. ```js const myObject = {}; Error.captureStackTrace(myObject); myObject.stack; // Similar to `new Error().stack` ``` The first line of the trace will be prefixed with `${myObject.name}: ${myObject.message}`. The optional `constructorOpt` argument accepts a function. If given, all frames above `constructorOpt`, including `constructorOpt`, will be omitted from the generated stack trace. The `constructorOpt` argument is useful for hiding implementation details of error generation from the user. For instance: ```js function a() { b(); } function b() { c(); } function c() { // Create an error without stack trace to avoid calculating the stack trace twice. const { stackTraceLimit } = Error; Error.stackTraceLimit = 0; const error = new Error(); Error.stackTraceLimit = stackTraceLimit; // Capture the stack trace above function b Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace throw error; } a(); ``` #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | ----------------- | ---------- | | `targetObject` | `object` | | `constructorOpt?` | `Function` | #### Returns [Section titled “Returns”](#returns-1) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-6) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`captureStackTrace`](/openai-agents-js/openai/agents-core/classes/agentserror/#capturestacktrace) *** ### prepareStackTrace() [Section titled “prepareStackTrace()”](#preparestacktrace) ```ts static prepareStackTrace(err, stackTraces): any; ``` #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | ------------- | ------------- | | `err` | `Error` | | `stackTraces` | `CallSite`\[] | #### Returns [Section titled “Returns”](#returns-2) `any` #### See [Section titled “See”](#see) #### Inherited from [Section titled “Inherited from”](#inherited-from-7) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`prepareStackTrace`](/openai-agents-js/openai/agents-core/classes/agentserror/#preparestacktrace) # ModelRefusalError Error thrown when the model refuses to produce output. ## Extends [Section titled “Extends”](#extends) * [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/) ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new ModelRefusalError(refusal, state?): ModelRefusalError; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- | | `refusal` | `string` | | `state?` | [`RunState`](/openai-agents-js/openai/agents-core/classes/runstate/)<`any`, [`Agent`](/openai-agents-js/openai/agents-core/classes/agent/)<`any`, `any`>> | #### Returns [Section titled “Returns”](#returns) `ModelRefusalError` #### Overrides [Section titled “Overrides”](#overrides) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`constructor`](/openai-agents-js/openai/agents-core/classes/agentserror/#constructor) ## Properties [Section titled “Properties”](#properties) ### message [Section titled “message”](#message) ```ts message: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`message`](/openai-agents-js/openai/agents-core/classes/agentserror/#message) *** ### name [Section titled “name”](#name) ```ts name: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-1) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`name`](/openai-agents-js/openai/agents-core/classes/agentserror/#name) *** ### refusal [Section titled “refusal”](#refusal) ```ts refusal: string; ``` The refusal text returned by the model. *** ### stack? [Section titled “stack?”](#stack) ```ts optional stack?: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-2) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`stack`](/openai-agents-js/openai/agents-core/classes/agentserror/#stack) *** ### state? [Section titled “state?”](#state) ```ts optional state?: RunState>; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-3) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`state`](/openai-agents-js/openai/agents-core/classes/agentserror/#state) *** ### stackTraceLimit [Section titled “stackTraceLimit”](#stacktracelimit) ```ts static stackTraceLimit: number; ``` The `Error.stackTraceLimit` property specifies the number of stack frames collected by a stack trace (whether generated by `new Error().stack` or `Error.captureStackTrace(obj)`). The default value is `10` but may be set to any valid JavaScript number. Changes will affect any stack trace captured *after* the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames. #### Inherited from [Section titled “Inherited from”](#inherited-from-4) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`stackTraceLimit`](/openai-agents-js/openai/agents-core/classes/agentserror/#stacktracelimit) ## Methods [Section titled “Methods”](#methods) ### captureStackTrace() [Section titled “captureStackTrace()”](#capturestacktrace) ```ts static captureStackTrace(targetObject, constructorOpt?): void; ``` Creates a `.stack` property on `targetObject`, which when accessed returns a string representing the location in the code at which `Error.captureStackTrace()` was called. ```js const myObject = {}; Error.captureStackTrace(myObject); myObject.stack; // Similar to `new Error().stack` ``` The first line of the trace will be prefixed with `${myObject.name}: ${myObject.message}`. The optional `constructorOpt` argument accepts a function. If given, all frames above `constructorOpt`, including `constructorOpt`, will be omitted from the generated stack trace. The `constructorOpt` argument is useful for hiding implementation details of error generation from the user. For instance: ```js function a() { b(); } function b() { c(); } function c() { // Create an error without stack trace to avoid calculating the stack trace twice. const { stackTraceLimit } = Error; Error.stackTraceLimit = 0; const error = new Error(); Error.stackTraceLimit = stackTraceLimit; // Capture the stack trace above function b Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace throw error; } a(); ``` #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | ----------------- | ---------- | | `targetObject` | `object` | | `constructorOpt?` | `Function` | #### Returns [Section titled “Returns”](#returns-1) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-5) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`captureStackTrace`](/openai-agents-js/openai/agents-core/classes/agentserror/#capturestacktrace) *** ### prepareStackTrace() [Section titled “prepareStackTrace()”](#preparestacktrace) ```ts static prepareStackTrace(err, stackTraces): any; ``` #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | ------------- | ------------- | | `err` | `Error` | | `stackTraces` | `CallSite`\[] | #### Returns [Section titled “Returns”](#returns-2) `any` #### See [Section titled “See”](#see) #### Inherited from [Section titled “Inherited from”](#inherited-from-6) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`prepareStackTrace`](/openai-agents-js/openai/agents-core/classes/agentserror/#preparestacktrace) # NoopSpan ## Extends [Section titled “Extends”](#extends) * [`Span`](/openai-agents-js/openai/agents-core/classes/span/)<`TSpanData`> ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | ----------------------------------------------------------------------------------------------- | | `TSpanData` *extends* [`SpanData`](/openai-agents-js/openai/agents-core/type-aliases/spandata/) | ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new NoopSpan(data, processor): NoopSpan; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ----------- | --------------------------------------------------------------------------------------- | | `data` | `TSpanData` | | `processor` | [`TracingProcessor`](/openai-agents-js/openai/agents-core/interfaces/tracingprocessor/) | #### Returns [Section titled “Returns”](#returns) `NoopSpan`<`TSpanData`> #### Overrides [Section titled “Overrides”](#overrides) [`Span`](/openai-agents-js/openai/agents-core/classes/span/).[`constructor`](/openai-agents-js/openai/agents-core/classes/span/#constructor) ## Properties [Section titled “Properties”](#properties) ### type [Section titled “type”](#type) ```ts type: "trace.span"; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from) [`Span`](/openai-agents-js/openai/agents-core/classes/span/).[`type`](/openai-agents-js/openai/agents-core/classes/span/#type) ## Accessors [Section titled “Accessors”](#accessors) ### endedAt [Section titled “endedAt”](#endedat) #### Get Signature [Section titled “Get Signature”](#get-signature) ```ts get endedAt(): string | null; ``` ##### Returns [Section titled “Returns”](#returns-1) `string` | `null` #### Inherited from [Section titled “Inherited from”](#inherited-from-1) [`Span`](/openai-agents-js/openai/agents-core/classes/span/).[`endedAt`](/openai-agents-js/openai/agents-core/classes/span/#endedat) *** ### error [Section titled “error”](#error) #### Get Signature [Section titled “Get Signature”](#get-signature-1) ```ts get error(): | SpanError | null; ``` ##### Returns [Section titled “Returns”](#returns-2) \| [`SpanError`](/openai-agents-js/openai/agents-core/type-aliases/spanerror/) | `null` #### Inherited from [Section titled “Inherited from”](#inherited-from-2) [`Span`](/openai-agents-js/openai/agents-core/classes/span/).[`error`](/openai-agents-js/openai/agents-core/classes/span/#error) *** ### parentId [Section titled “parentId”](#parentid) #### Get Signature [Section titled “Get Signature”](#get-signature-2) ```ts get parentId(): string | null; ``` ##### Returns [Section titled “Returns”](#returns-3) `string` | `null` #### Inherited from [Section titled “Inherited from”](#inherited-from-3) [`Span`](/openai-agents-js/openai/agents-core/classes/span/).[`parentId`](/openai-agents-js/openai/agents-core/classes/span/#parentid) *** ### previousSpan [Section titled “previousSpan”](#previousspan) #### Get Signature [Section titled “Get Signature”](#get-signature-3) ```ts get previousSpan(): | Span | undefined; ``` ##### Returns [Section titled “Returns”](#returns-4) \| [`Span`](/openai-agents-js/openai/agents-core/classes/span/)<`any`> | `undefined` #### Set Signature [Section titled “Set Signature”](#set-signature) ```ts set previousSpan(span): void; ``` ##### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | --------- | ------------------------------------------------------------------------------------- | | `span` | \| [`Span`](/openai-agents-js/openai/agents-core/classes/span/)<`any`> \| `undefined` | ##### Returns [Section titled “Returns”](#returns-5) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-4) [`Span`](/openai-agents-js/openai/agents-core/classes/span/).[`previousSpan`](/openai-agents-js/openai/agents-core/classes/span/#previousspan) *** ### spanData [Section titled “spanData”](#spandata) #### Get Signature [Section titled “Get Signature”](#get-signature-4) ```ts get spanData(): TData; ``` ##### Returns [Section titled “Returns”](#returns-6) `TData` #### Inherited from [Section titled “Inherited from”](#inherited-from-5) [`Span`](/openai-agents-js/openai/agents-core/classes/span/).[`spanData`](/openai-agents-js/openai/agents-core/classes/span/#spandata) *** ### spanId [Section titled “spanId”](#spanid) #### Get Signature [Section titled “Get Signature”](#get-signature-5) ```ts get spanId(): string; ``` ##### Returns [Section titled “Returns”](#returns-7) `string` #### Inherited from [Section titled “Inherited from”](#inherited-from-6) [`Span`](/openai-agents-js/openai/agents-core/classes/span/).[`spanId`](/openai-agents-js/openai/agents-core/classes/span/#spanid) *** ### startedAt [Section titled “startedAt”](#startedat) #### Get Signature [Section titled “Get Signature”](#get-signature-6) ```ts get startedAt(): string | null; ``` ##### Returns [Section titled “Returns”](#returns-8) `string` | `null` #### Inherited from [Section titled “Inherited from”](#inherited-from-7) [`Span`](/openai-agents-js/openai/agents-core/classes/span/).[`startedAt`](/openai-agents-js/openai/agents-core/classes/span/#startedat) *** ### traceId [Section titled “traceId”](#traceid) #### Get Signature [Section titled “Get Signature”](#get-signature-7) ```ts get traceId(): string; ``` ##### Returns [Section titled “Returns”](#returns-9) `string` #### Inherited from [Section titled “Inherited from”](#inherited-from-8) [`Span`](/openai-agents-js/openai/agents-core/classes/span/).[`traceId`](/openai-agents-js/openai/agents-core/classes/span/#traceid) *** ### traceMetadata [Section titled “traceMetadata”](#tracemetadata) #### Get Signature [Section titled “Get Signature”](#get-signature-8) ```ts get traceMetadata(): Record | undefined; ``` ##### Returns [Section titled “Returns”](#returns-10) `Record`<`string`, `any`> | `undefined` #### Inherited from [Section titled “Inherited from”](#inherited-from-9) [`Span`](/openai-agents-js/openai/agents-core/classes/span/).[`traceMetadata`](/openai-agents-js/openai/agents-core/classes/span/#tracemetadata) *** ### tracingApiKey [Section titled “tracingApiKey”](#tracingapikey) #### Get Signature [Section titled “Get Signature”](#get-signature-9) ```ts get tracingApiKey(): string | undefined; ``` ##### Returns [Section titled “Returns”](#returns-11) `string` | `undefined` #### Inherited from [Section titled “Inherited from”](#inherited-from-10) [`Span`](/openai-agents-js/openai/agents-core/classes/span/).[`tracingApiKey`](/openai-agents-js/openai/agents-core/classes/span/#tracingapikey) ## Methods [Section titled “Methods”](#methods) ### clone() [Section titled “clone()”](#clone) ```ts clone(): Span; ``` #### Returns [Section titled “Returns”](#returns-12) [`Span`](/openai-agents-js/openai/agents-core/classes/span/)<`TSpanData`> #### Inherited from [Section titled “Inherited from”](#inherited-from-11) [`Span`](/openai-agents-js/openai/agents-core/classes/span/).[`clone`](/openai-agents-js/openai/agents-core/classes/span/#clone) *** ### end() [Section titled “end()”](#end) ```ts end(): void; ``` #### Returns [Section titled “Returns”](#returns-13) `void` #### Overrides [Section titled “Overrides”](#overrides-1) [`Span`](/openai-agents-js/openai/agents-core/classes/span/).[`end`](/openai-agents-js/openai/agents-core/classes/span/#end) *** ### setError() [Section titled “setError()”](#seterror) ```ts setError(): void; ``` #### Returns [Section titled “Returns”](#returns-14) `void` #### Overrides [Section titled “Overrides”](#overrides-2) [`Span`](/openai-agents-js/openai/agents-core/classes/span/).[`setError`](/openai-agents-js/openai/agents-core/classes/span/#seterror) *** ### start() [Section titled “start()”](#start) ```ts start(): void; ``` #### Returns [Section titled “Returns”](#returns-15) `void` #### Overrides [Section titled “Overrides”](#overrides-3) [`Span`](/openai-agents-js/openai/agents-core/classes/span/).[`start`](/openai-agents-js/openai/agents-core/classes/span/#start) *** ### toJSON() [Section titled “toJSON()”](#tojson) ```ts toJSON(): null; ``` #### Returns [Section titled “Returns”](#returns-16) `null` #### Overrides [Section titled “Overrides”](#overrides-4) [`Span`](/openai-agents-js/openai/agents-core/classes/span/).[`toJSON`](/openai-agents-js/openai/agents-core/classes/span/#tojson) # NoopTrace ## Extends [Section titled “Extends”](#extends) * [`Trace`](/openai-agents-js/openai/agents-core/classes/trace/) ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new NoopTrace(): NoopTrace; ``` #### Returns [Section titled “Returns”](#returns) `NoopTrace` #### Overrides [Section titled “Overrides”](#overrides) [`Trace`](/openai-agents-js/openai/agents-core/classes/trace/).[`constructor`](/openai-agents-js/openai/agents-core/classes/trace/#constructor) ## Properties [Section titled “Properties”](#properties) ### groupId [Section titled “groupId”](#groupid) ```ts groupId: string | null = null; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from) [`Trace`](/openai-agents-js/openai/agents-core/classes/trace/).[`groupId`](/openai-agents-js/openai/agents-core/classes/trace/#groupid) *** ### metadata? [Section titled “metadata?”](#metadata) ```ts optional metadata?: Record; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-1) [`Trace`](/openai-agents-js/openai/agents-core/classes/trace/).[`metadata`](/openai-agents-js/openai/agents-core/classes/trace/#metadata) *** ### name [Section titled “name”](#name) ```ts name: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-2) [`Trace`](/openai-agents-js/openai/agents-core/classes/trace/).[`name`](/openai-agents-js/openai/agents-core/classes/trace/#name) *** ### traceId [Section titled “traceId”](#traceid) ```ts traceId: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-3) [`Trace`](/openai-agents-js/openai/agents-core/classes/trace/).[`traceId`](/openai-agents-js/openai/agents-core/classes/trace/#traceid) *** ### tracingApiKey? [Section titled “tracingApiKey?”](#tracingapikey) ```ts optional tracingApiKey?: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-4) [`Trace`](/openai-agents-js/openai/agents-core/classes/trace/).[`tracingApiKey`](/openai-agents-js/openai/agents-core/classes/trace/#tracingapikey) *** ### type [Section titled “type”](#type) ```ts type: "trace"; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-5) [`Trace`](/openai-agents-js/openai/agents-core/classes/trace/).[`type`](/openai-agents-js/openai/agents-core/classes/trace/#type) ## Methods [Section titled “Methods”](#methods) ### clone() [Section titled “clone()”](#clone) ```ts clone(): Trace; ``` #### Returns [Section titled “Returns”](#returns-1) [`Trace`](/openai-agents-js/openai/agents-core/classes/trace/) #### Inherited from [Section titled “Inherited from”](#inherited-from-6) [`Trace`](/openai-agents-js/openai/agents-core/classes/trace/).[`clone`](/openai-agents-js/openai/agents-core/classes/trace/#clone) *** ### end() [Section titled “end()”](#end) ```ts end(): Promise; ``` #### Returns [Section titled “Returns”](#returns-2) `Promise`<`void`> #### Overrides [Section titled “Overrides”](#overrides-1) [`Trace`](/openai-agents-js/openai/agents-core/classes/trace/).[`end`](/openai-agents-js/openai/agents-core/classes/trace/#end) *** ### start() [Section titled “start()”](#start) ```ts start(): Promise; ``` #### Returns [Section titled “Returns”](#returns-3) `Promise`<`void`> #### Overrides [Section titled “Overrides”](#overrides-2) [`Trace`](/openai-agents-js/openai/agents-core/classes/trace/).[`start`](/openai-agents-js/openai/agents-core/classes/trace/#start) *** ### toJSON() [Section titled “toJSON()”](#tojson) ```ts toJSON(): object | null; ``` Serializes the trace for export or persistence. Set `includeTracingApiKey` to true only when you intentionally need to persist the exporter credentials (for example, when handing off a run to another process that cannot access the original environment). Defaults to false to avoid leaking secrets. #### Returns [Section titled “Returns”](#returns-4) `object` | `null` #### Overrides [Section titled “Overrides”](#overrides-3) [`Trace`](/openai-agents-js/openai/agents-core/classes/trace/).[`toJSON`](/openai-agents-js/openai/agents-core/classes/trace/#tojson) # OutputGuardrailTripwireTriggered Error thrown when an output guardrail tripwire is triggered. ## Extends [Section titled “Extends”](#extends) * [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/) ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | ----------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------- | | `TMeta` *extends* [`OutputGuardrailMetadata`](/openai-agents-js/openai/agents-core/interfaces/outputguardrailmetadata/) | ‐ | | `TOutputType` *extends* [`AgentOutputType`](/openai-agents-js/openai/agents-core/type-aliases/agentoutputtype/) | [`TextOutput`](/openai-agents-js/openai/agents-core/type-aliases/textoutput/) | ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new OutputGuardrailTripwireTriggered( message, result, state?): OutputGuardrailTripwireTriggered; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ------------------------------------------------------------------------------------------------------------------------- | | `message` | `string` | | `result` | [`OutputGuardrailResult`](/openai-agents-js/openai/agents-core/interfaces/outputguardrailresult/)<`TMeta`, `TOutputType`> | | `state?` | [`RunState`](/openai-agents-js/openai/agents-core/classes/runstate/)<`any`, `any`> | #### Returns [Section titled “Returns”](#returns) `OutputGuardrailTripwireTriggered`<`TMeta`, `TOutputType`> #### Overrides [Section titled “Overrides”](#overrides) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`constructor`](/openai-agents-js/openai/agents-core/classes/agentserror/#constructor) ## Properties [Section titled “Properties”](#properties) ### message [Section titled “message”](#message) ```ts message: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`message`](/openai-agents-js/openai/agents-core/classes/agentserror/#message) *** ### name [Section titled “name”](#name) ```ts name: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-1) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`name`](/openai-agents-js/openai/agents-core/classes/agentserror/#name) *** ### result [Section titled “result”](#result) ```ts result: OutputGuardrailResult; ``` *** ### stack? [Section titled “stack?”](#stack) ```ts optional stack?: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-2) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`stack`](/openai-agents-js/openai/agents-core/classes/agentserror/#stack) *** ### state? [Section titled “state?”](#state) ```ts optional state?: RunState>; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-3) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`state`](/openai-agents-js/openai/agents-core/classes/agentserror/#state) *** ### stackTraceLimit [Section titled “stackTraceLimit”](#stacktracelimit) ```ts static stackTraceLimit: number; ``` The `Error.stackTraceLimit` property specifies the number of stack frames collected by a stack trace (whether generated by `new Error().stack` or `Error.captureStackTrace(obj)`). The default value is `10` but may be set to any valid JavaScript number. Changes will affect any stack trace captured *after* the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames. #### Inherited from [Section titled “Inherited from”](#inherited-from-4) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`stackTraceLimit`](/openai-agents-js/openai/agents-core/classes/agentserror/#stacktracelimit) ## Methods [Section titled “Methods”](#methods) ### captureStackTrace() [Section titled “captureStackTrace()”](#capturestacktrace) ```ts static captureStackTrace(targetObject, constructorOpt?): void; ``` Creates a `.stack` property on `targetObject`, which when accessed returns a string representing the location in the code at which `Error.captureStackTrace()` was called. ```js const myObject = {}; Error.captureStackTrace(myObject); myObject.stack; // Similar to `new Error().stack` ``` The first line of the trace will be prefixed with `${myObject.name}: ${myObject.message}`. The optional `constructorOpt` argument accepts a function. If given, all frames above `constructorOpt`, including `constructorOpt`, will be omitted from the generated stack trace. The `constructorOpt` argument is useful for hiding implementation details of error generation from the user. For instance: ```js function a() { b(); } function b() { c(); } function c() { // Create an error without stack trace to avoid calculating the stack trace twice. const { stackTraceLimit } = Error; Error.stackTraceLimit = 0; const error = new Error(); Error.stackTraceLimit = stackTraceLimit; // Capture the stack trace above function b Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace throw error; } a(); ``` #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | ----------------- | ---------- | | `targetObject` | `object` | | `constructorOpt?` | `Function` | #### Returns [Section titled “Returns”](#returns-1) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-5) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`captureStackTrace`](/openai-agents-js/openai/agents-core/classes/agentserror/#capturestacktrace) *** ### prepareStackTrace() [Section titled “prepareStackTrace()”](#preparestacktrace) ```ts static prepareStackTrace(err, stackTraces): any; ``` #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | ------------- | ------------- | | `err` | `Error` | | `stackTraces` | `CallSite`\[] | #### Returns [Section titled “Returns”](#returns-2) `any` #### See [Section titled “See”](#see) #### Inherited from [Section titled “Inherited from”](#inherited-from-6) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`prepareStackTrace`](/openai-agents-js/openai/agents-core/classes/agentserror/#preparestacktrace) # RequestUsage Usage details for a single API request. ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new RequestUsage(input?): RequestUsage; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ------------------------------ | | `input?` | `Partial`<`object` & `object`> | #### Returns [Section titled “Returns”](#returns) `RequestUsage` ## Properties [Section titled “Properties”](#properties) ### endpoint? [Section titled “endpoint?”](#endpoint) ```ts optional endpoint?: string & object | "responses.create" | "responses.compact"; ``` The endpoint that produced this usage entry (e.g., responses.create, responses.compact). *** ### inputTokens [Section titled “inputTokens”](#inputtokens) ```ts inputTokens: number; ``` The number of input tokens used for this request. *** ### inputTokensDetails [Section titled “inputTokensDetails”](#inputtokensdetails) ```ts inputTokensDetails: Record; ``` Details about the input tokens used for this request. *** ### outputTokens [Section titled “outputTokens”](#outputtokens) ```ts outputTokens: number; ``` The number of output tokens used for this request. *** ### outputTokensDetails [Section titled “outputTokensDetails”](#outputtokensdetails) ```ts outputTokensDetails: Record; ``` Details about the output tokens used for this request. *** ### totalTokens [Section titled “totalTokens”](#totaltokens) ```ts totalTokens: number; ``` The total number of tokens sent and received for this request. # RunAgentUpdatedStreamEvent Event that notifies that there is a new agent running. ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new RunAgentUpdatedStreamEvent(agent): RunAgentUpdatedStreamEvent; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | --------- | ---------------------------------------------------------------------------- | ------------- | | `agent` | [`Agent`](/openai-agents-js/openai/agents-core/classes/agent/)<`any`, `any`> | The new agent | #### Returns [Section titled “Returns”](#returns) `RunAgentUpdatedStreamEvent` ## Properties [Section titled “Properties”](#properties) ### agent [Section titled “agent”](#agent) ```ts agent: Agent; ``` The new agent *** ### type [Section titled “type”](#type) ```ts readonly type: "agent_updated_stream_event" = 'agent_updated_stream_event'; ``` # RunContext A context object that is passed to the `Runner.run()` method. ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | ------------------------------------------------------------------------------------- | | `TContext` | [`UnknownContext`](/openai-agents-js/openai/agents-core/type-aliases/unknowncontext/) | ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new RunContext(context?): RunContext; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ---------- | | `context` | `TContext` | #### Returns [Section titled “Returns”](#returns) `RunContext`<`TContext`> ## Properties [Section titled “Properties”](#properties) ### context [Section titled “context”](#context) ```ts context: TContext; ``` The context object you passed to the `Runner.run()` method. *** ### toolInput? [Section titled “toolInput?”](#toolinput) ```ts optional toolInput?: unknown; ``` Structured input for the current agent tool run, when available. *** ### usage [Section titled “usage”](#usage) ```ts usage: Usage; ``` The usage of the agent run so far. For streamed responses, the usage will be updated in real-time ## Methods [Section titled “Methods”](#methods) ### approveTool() [Section titled “approveTool()”](#approvetool) ```ts approveTool(approvalItem, options?): void; ``` Approve a tool call. #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | Description | | ------------------------ | ------------------------------------------------------------------------------------------ | ------------------------------------- | | `approvalItem` | [`RunToolApprovalItem`](/openai-agents-js/openai/agents-core/classes/runtoolapprovalitem/) | The tool approval item to approve. | | `options` | { `alwaysApprove?`: `boolean`; } | Additional approval behavior options. | | `options.alwaysApprove?` | `boolean` | ‐ | #### Returns [Section titled “Returns”](#returns-1) `void` *** ### getRejectionMessage() [Section titled “getRejectionMessage()”](#getrejectionmessage) ```ts getRejectionMessage(toolName, callId): string | undefined; ``` Retrieve the caller-provided rejection message for a specific tool call. #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | Description | | ---------- | -------- | ----------------------------------- | | `toolName` | `string` | The name of the tool. | | `callId` | `string` | The call ID of the tool invocation. | #### Returns [Section titled “Returns”](#returns-2) `string` | `undefined` The message string if one was provided, `undefined` otherwise. *** ### isToolApproved() [Section titled “isToolApproved()”](#istoolapproved) ```ts isToolApproved(approval): boolean | undefined; ``` Check if a tool call has been approved. #### Parameters [Section titled “Parameters”](#parameters-3) | Parameter | Type | Description | | ------------------- | --------------------------------------------- | -------------------------------------------- | | `approval` | { `callId`: `string`; `toolName`: `string`; } | Details about the tool call being evaluated. | | `approval.callId` | `string` | ‐ | | `approval.toolName` | `string` | ‐ | #### Returns [Section titled “Returns”](#returns-3) `boolean` | `undefined` `true` if the tool call has been approved, `false` if blocked and `undefined` if not yet approved or rejected. *** ### rejectTool() [Section titled “rejectTool()”](#rejecttool) ```ts rejectTool(approvalItem, __namedParameters?): void; ``` Reject a tool call. #### Parameters [Section titled “Parameters”](#parameters-4) | Parameter | Type | Description | | --------------------------------- | ------------------------------------------------------------------------------------------ | --------------------------------- | | `approvalItem` | [`RunToolApprovalItem`](/openai-agents-js/openai/agents-core/classes/runtoolapprovalitem/) | The tool approval item to reject. | | `__namedParameters` | { `alwaysReject?`: `boolean`; `message?`: `string`; } | ‐ | | `__namedParameters.alwaysReject?` | `boolean` | ‐ | | `__namedParameters.message?` | `string` | ‐ | #### Returns [Section titled “Returns”](#returns-4) `void` *** ### toJSON() [Section titled “toJSON()”](#tojson) ```ts toJSON(): RunContextJson; ``` #### Returns [Section titled “Returns”](#returns-5) `RunContextJson` # RunHandoffCallItem ## Extends [Section titled “Extends”](#extends) * `RunItemBase` ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new RunHandoffCallItem(rawItem, agent): RunHandoffCallItem; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | ----------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `rawItem` | { `arguments`: `string`; `callId`: `string`; `id?`: `string`; `name`: `string`; `namespace?`: `string`; `providerData?`: `Record`<`string`, `any`>; `status?`: `"in_progress"` \| `"completed"` \| `"incomplete"`; `type`: `"function_call"`; } | ‐ | | `rawItem.arguments` | `string` | The arguments of the function call. | | `rawItem.callId` | `string` | The ID of the tool call. Required to match up the respective tool call result. | | `rawItem.id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `rawItem.name` | `string` | The name of the function. | | `rawItem.namespace?` | `string` | Optional namespace used to qualify the function name for tool search. | | `rawItem.providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `rawItem.status?` | `"in_progress"` \| `"completed"` \| `"incomplete"` | The status of the function call. | | `rawItem.type` | `"function_call"` | ‐ | | `agent` | [`Agent`](/openai-agents-js/openai/agents-core/classes/agent/) | ‐ | #### Returns [Section titled “Returns”](#returns) `RunHandoffCallItem` #### Overrides [Section titled “Overrides”](#overrides) ```ts RunItemBase.constructor ``` ## Properties [Section titled “Properties”](#properties) ### agent [Section titled “agent”](#agent) ```ts agent: Agent; ``` *** ### rawItem [Section titled “rawItem”](#rawitem) ```ts rawItem: object; ``` | Name | Type | Description | | --------------- | -------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `arguments` | `string` | The arguments of the function call. | | `callId` | `string` | The ID of the tool call. Required to match up the respective tool call result. | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `name` | `string` | The name of the function. | | `namespace?` | `string` | Optional namespace used to qualify the function name for tool search. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status?` | `"in_progress"` \| `"completed"` \| `"incomplete"` | The status of the function call. | | `type` | `"function_call"` | ‐ | #### Inherited from [Section titled “Inherited from”](#inherited-from) ```ts RunItemBase.rawItem ``` *** ### type [Section titled “type”](#type) ```ts readonly type: "handoff_call_item"; ``` #### Overrides [Section titled “Overrides”](#overrides-1) ```ts RunItemBase.type ``` ## Methods [Section titled “Methods”](#methods) ### toJSON() [Section titled “toJSON()”](#tojson) ```ts toJSON(): object; ``` #### Returns [Section titled “Returns”](#returns-1) `object` ##### agent [Section titled “agent”](#agent-1) ```ts agent: object; ``` ###### agent.name [Section titled “agent.name”](#agentname) ```ts name: string; ``` ##### rawItem [Section titled “rawItem”](#rawitem-1) ```ts rawItem: | { content: ( | { providerData?: Record; refusal: string; type: "refusal"; } | { providerData?: Record; text: string; type: "output_text"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; } | { image: string; providerData?: Record; type: "image"; })[]; id?: string; providerData?: Record; role: "assistant"; status: "in_progress" | "completed" | "incomplete"; type?: "message"; } | { content: | string | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; })[]; id?: string; providerData?: Record; role: "user"; type?: "message"; } | { content: string; id?: string; providerData?: Record; role: "system"; type?: "message"; } | { arguments?: string; id?: string; name: string; output?: string; providerData?: Record; status?: string; type: "hosted_tool_call"; } | { arguments: string; callId: string; id?: string; name: string; namespace?: string; providerData?: Record; status?: "in_progress" | "completed" | "incomplete"; type: "function_call"; } | { arguments: unknown; call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; type: "tool_search_call"; } | { call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; tools: Record[]; type: "tool_search_output"; } | { callId: string; id?: string; name: string; namespace?: string; output: | string | { providerData?: Record; text: string; type: "text"; } | { detail?: "low" | "high" | "auto" | string & object; image?: | string | { data: string | Uint8Array; mediaType?: string; } | { url: string; } | { fileId: string; }; providerData?: Record; type: "image"; } | { file: | string | { data: string | Uint8Array; filename: string; mediaType: string; } | { filename?: string; url: string; } | { filename?: string; id: string; }; providerData?: Record; type: "file"; } | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; })[]; providerData?: Record; status: "in_progress" | "completed" | "incomplete"; type: "function_call_result"; } | { action?: | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; }; actions?: ( | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; })[]; callId: string; id?: string; providerData?: Record; status: "in_progress" | "completed" | "incomplete"; type: "computer_call"; } | { callId: string; id?: string; output: { data: string; providerData?: Record; type: "computer_screenshot"; }; providerData?: Record; type: "computer_call_result"; } | { action: { commands: string[]; maxOutputLength?: number; timeoutMs?: number; }; callId: string; id?: string; providerData?: Record; status?: "in_progress" | "completed" | "incomplete"; type: "shell_call"; } | { callId: string; id?: string; maxOutputLength?: number; output: object[]; providerData?: Record; type: "shell_call_output"; } | { callId: string; id?: string; operation: | { diff: string; path: string; type: "create_file"; } | { diff: string; moveTo?: string; path: string; type: "update_file"; } | { path: string; type: "delete_file"; }; providerData?: Record; status: "in_progress" | "completed"; type: "apply_patch_call"; } | { callId: string; id?: string; output?: string; providerData?: Record; status: "completed" | "failed"; type: "apply_patch_call_output"; } | { content: object[]; id?: string; providerData?: Record; rawContent?: object[]; type: "reasoning"; } | { created_by?: string; encrypted_content: string; id?: string; providerData?: Record; type: "compaction"; } | { id?: string; providerData?: Record; type: "unknown"; } | undefined; ``` ###### Union Members [Section titled “Union Members”](#union-members) ###### Type Literal [Section titled “Type Literal”](#type-literal) ```ts { content: ( | { providerData?: Record; refusal: string; type: "refusal"; } | { providerData?: Record; text: string; type: "output_text"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; } | { image: string; providerData?: Record; type: "image"; })[]; id?: string; providerData?: Record; role: "assistant"; status: "in_progress" | "completed" | "incomplete"; type?: "message"; } ``` | Name | Type | Description | | --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `content` | ( \| { `providerData?`: `Record`<`string`, `any`>; `refusal`: `string`; `type`: `"refusal"`; } \| { `providerData?`: `Record`<`string`, `any`>; `text`: `string`; `type`: `"output_text"`; } \| { `audio`: \| `string` \| { `id`: `string`; }; `format?`: `string` \| `null`; `providerData?`: `Record`<`string`, `any`>; `transcript?`: `string` \| `null`; `type`: `"audio"`; } \| { `image`: `string`; `providerData?`: `Record`<`string`, `any`>; `type`: `"image"`; })\[] | The content of the message. | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `role` | `"assistant"` | Representing a message from the assistant (i.e. the model) | | `status` | `"in_progress"` \| `"completed"` \| `"incomplete"` | The status of the message. | | `type?` | `"message"` | Any item without a type is treated as a message | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-1) ```ts { content: | string | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; })[]; id?: string; providerData?: Record; role: "user"; type?: "message"; } ``` | Name | Type | Description | | --------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `content` | \| `string` \| ( \| { `providerData?`: `Record`<`string`, `any`>; `text`: `string`; `type`: `"input_text"`; } \| { `detail?`: `string`; `image?`: \| `string` \| { `id`: `string`; }; `providerData?`: `Record`<`string`, `any`>; `type`: `"input_image"`; } \| { `file?`: \| `string` \| { `id`: `string`; } \| { `url`: `string`; }; `filename?`: `string`; `providerData?`: `Record`<`string`, `any`>; `type`: `"input_file"`; } \| { `audio`: \| `string` \| { `id`: `string`; }; `format?`: `string` \| `null`; `providerData?`: `Record`<`string`, `any`>; `transcript?`: `string` \| `null`; `type`: `"audio"`; })\[] | The content of the message. | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `role` | `"user"` | Representing a message from the user | | `type?` | `"message"` | Any item without a type is treated as a message | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-2) ```ts { content: string; id?: string; providerData?: Record; role: "system"; type?: "message"; } ``` | Name | Type | Description | | --------------- | ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `content` | `string` | The content of the message. | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `role` | `"system"` | Representing a system message to the user | | `type?` | `"message"` | Any item without a type is treated as a message | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-3) ```ts { arguments?: string; id?: string; name: string; output?: string; providerData?: Record; status?: string; type: "hosted_tool_call"; } ``` | Name | Type | Description | | --------------- | ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `arguments?` | `string` | The arguments of the hosted tool call. | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `name` | `string` | The name of the hosted tool. For example `web_search_call` or `file_search_call` | | `output?` | `string` | The primary output of the tool call. Additional output might be in the `providerData` field. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status?` | `string` | The status of the tool call. | | `type` | `"hosted_tool_call"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-4) ```ts { arguments: string; callId: string; id?: string; name: string; namespace?: string; providerData?: Record; status?: "in_progress" | "completed" | "incomplete"; type: "function_call"; } ``` | Name | Type | Description | | --------------- | -------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `arguments` | `string` | The arguments of the function call. | | `callId` | `string` | The ID of the tool call. Required to match up the respective tool call result. | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `name` | `string` | The name of the function. | | `namespace?` | `string` | Optional namespace used to qualify the function name for tool search. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status?` | `"in_progress"` \| `"completed"` \| `"incomplete"` | The status of the function call. | | `type` | `"function_call"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-5) ```ts { arguments: unknown; call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; type: "tool_search_call"; } ``` | Name | Type | Default value | Description | | --------------- | ------------------------- | ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `arguments` | `unknown` | `ToolSearchCallArguments` | ‐ | | `call_id?` | `string` \| `null` | ‐ | ‐ | | `callId?` | `string` \| `null` | ‐ | ‐ | | `execution?` | `"client"` \| `"server"` | ‐ | ‐ | | `id?` | `string` | ‐ | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `providerData?` | `Record`<`string`, `any`> | ‐ | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status?` | `string` | ‐ | ‐ | | `type` | `"tool_search_call"` | ‐ | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-6) ```ts { call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; tools: Record[]; type: "tool_search_output"; } ``` | Name | Type | Description | | --------------- | ---------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `call_id?` | `string` \| `null` | ‐ | | `callId?` | `string` \| `null` | ‐ | | `execution?` | `"client"` \| `"server"` | ‐ | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status?` | `string` | ‐ | | `tools` | `Record`<`string`, `any`>\[] | ‐ | | `type` | `"tool_search_output"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-7) ```ts { callId: string; id?: string; name: string; namespace?: string; output: | string | { providerData?: Record; text: string; type: "text"; } | { detail?: "low" | "high" | "auto" | string & object; image?: | string | { data: string | Uint8Array; mediaType?: string; } | { url: string; } | { fileId: string; }; providerData?: Record; type: "image"; } | { file: | string | { data: string | Uint8Array; filename: string; mediaType: string; } | { filename?: string; url: string; } | { filename?: string; id: string; }; providerData?: Record; type: "file"; } | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; })[]; providerData?: Record; status: "in_progress" | "completed" | "incomplete"; type: "function_call_result"; } ``` | Name | Type | Description | | --------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `callId` | `string` | The ID of the tool call. Required to match up the respective tool call result. | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `name` | `string` | The name of the tool that was called | | `namespace?` | `string` | Optional namespace preserved from the originating function call. | | `output` | \| `string` \| { `providerData?`: `Record`<`string`, `any`>; `text`: `string`; `type`: `"text"`; } \| { `detail?`: `"low"` \| `"high"` \| `"auto"` \| `string` & `object`; `image?`: \| `string` \| { `data`: `string` \| `Uint8Array`<`ArrayBuffer`>; `mediaType?`: `string`; } \| { `url`: `string`; } \| { `fileId`: `string`; }; `providerData?`: `Record`<`string`, `any`>; `type`: `"image"`; } \| { `file`: \| `string` \| { `data`: `string` \| `Uint8Array`<`ArrayBuffer`>; `filename`: `string`; `mediaType`: `string`; } \| { `filename?`: `string`; `url`: `string`; } \| { `filename?`: `string`; `id`: `string`; }; `providerData?`: `Record`<`string`, `any`>; `type`: `"file"`; } \| ( \| { `providerData?`: `Record`<`string`, `any`>; `text`: `string`; `type`: `"input_text"`; } \| { `detail?`: `string`; `image?`: \| `string` \| { `id`: `string`; }; `providerData?`: `Record`<`string`, `any`>; `type`: `"input_image"`; } \| { `file?`: \| `string` \| { `id`: `string`; } \| { `url`: `string`; }; `filename?`: `string`; `providerData?`: `Record`<`string`, `any`>; `type`: `"input_file"`; })\[] | The output of the tool call. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status` | `"in_progress"` \| `"completed"` \| `"incomplete"` | The status of the tool call. | | `type` | `"function_call_result"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-8) ```ts { action?: | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; }; actions?: ( | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; })[]; callId: string; id?: string; providerData?: Record; status: "in_progress" | "completed" | "incomplete"; type: "computer_call"; } ``` | Name | Type | Description | | --------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `action?` | \| { `type`: `"screenshot"`; } \| { `button`: `"left"` \| `"right"` \| `"wheel"` \| `"back"` \| `"forward"`; `type`: `"click"`; `x`: `number`; `y`: `number`; } \| { `type`: `"double_click"`; `x`: `number`; `y`: `number`; } \| { `scroll_x`: `number`; `scroll_y`: `number`; `type`: `"scroll"`; `x`: `number`; `y`: `number`; } \| { `text`: `string`; `type`: `"type"`; } \| { `type`: `"wait"`; } \| { `type`: `"move"`; `x`: `number`; `y`: `number`; } \| { `keys`: `string`\[]; `type`: `"keypress"`; } \| { `path`: `object`\[]; `type`: `"drag"`; } | The legacy single action to be performed by the computer. | | `actions?` | ( \| { `type`: `"screenshot"`; } \| { `button`: `"left"` \| `"right"` \| `"wheel"` \| `"back"` \| `"forward"`; `type`: `"click"`; `x`: `number`; `y`: `number`; } \| { `type`: `"double_click"`; `x`: `number`; `y`: `number`; } \| { `scroll_x`: `number`; `scroll_y`: `number`; `type`: `"scroll"`; `x`: `number`; `y`: `number`; } \| { `text`: `string`; `type`: `"type"`; } \| { `type`: `"wait"`; } \| { `type`: `"move"`; `x`: `number`; `y`: `number`; } \| { `keys`: `string`\[]; `type`: `"keypress"`; } \| { `path`: `object`\[]; `type`: `"drag"`; })\[] | Batched actions returned by the GA computer tool. | | `callId` | `string` | The ID of the computer call. Required to match up the respective computer call result. | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status` | `"in_progress"` \| `"completed"` \| `"incomplete"` | The status of the computer call. | | `type` | `"computer_call"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-9) ```ts { callId: string; id?: string; output: { data: string; providerData?: Record; type: "computer_screenshot"; }; providerData?: Record; type: "computer_call_result"; } ``` | Name | Type | Default value | Description | | ---------------------- | ------------------------- | -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `callId` | `string` | ‐ | The ID of the computer call. Required to match up the respective computer call result. | | `id?` | `string` | ‐ | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `output` | `object` | `ComputerToolOutput` | The output of the computer call. | | `output.data` | `string` | ‐ | A base64 encoded image data or a URL representing the screenshot. | | `output.providerData?` | `Record`<`string`, `any`> | ‐ | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `output.type` | `"computer_screenshot"` | ‐ | ‐ | | `providerData?` | `Record`<`string`, `any`> | ‐ | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `type` | `"computer_call_result"` | ‐ | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-10) ```ts { action: { commands: string[]; maxOutputLength?: number; timeoutMs?: number; }; callId: string; id?: string; providerData?: Record; status?: "in_progress" | "completed" | "incomplete"; type: "shell_call"; } ``` | Name | Type | Default value | Description | | ------------------------- | -------------------------------------------------- | ------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `action` | `object` | `ShellAction` | ‐ | | `action.commands` | `string`\[] | ‐ | ‐ | | `action.maxOutputLength?` | `number` | ‐ | ‐ | | `action.timeoutMs?` | `number` | ‐ | ‐ | | `callId` | `string` | ‐ | ‐ | | `id?` | `string` | ‐ | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `providerData?` | `Record`<`string`, `any`> | ‐ | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status?` | `"in_progress"` \| `"completed"` \| `"incomplete"` | ‐ | ‐ | | `type` | `"shell_call"` | ‐ | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-11) ```ts { callId: string; id?: string; maxOutputLength?: number; output: object[]; providerData?: Record; type: "shell_call_output"; } ``` | Name | Type | Description | | ------------------ | ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `callId` | `string` | ‐ | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `maxOutputLength?` | `number` | ‐ | | `output` | `object`\[] | ‐ | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `type` | `"shell_call_output"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-12) ```ts { callId: string; id?: string; operation: | { diff: string; path: string; type: "create_file"; } | { diff: string; moveTo?: string; path: string; type: "update_file"; } | { path: string; type: "delete_file"; }; providerData?: Record; status: "in_progress" | "completed"; type: "apply_patch_call"; } ``` | Name | Type | Default value | Description | | --------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `callId` | `string` | ‐ | ‐ | | `id?` | `string` | ‐ | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `operation` | \| { `diff`: `string`; `path`: `string`; `type`: `"create_file"`; } \| { `diff`: `string`; `moveTo?`: `string`; `path`: `string`; `type`: `"update_file"`; } \| { `path`: `string`; `type`: `"delete_file"`; } | `ApplyPatchOperation` | ‐ | | `providerData?` | `Record`<`string`, `any`> | ‐ | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status` | `"in_progress"` \| `"completed"` | ‐ | ‐ | | `type` | `"apply_patch_call"` | ‐ | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-13) ```ts { callId: string; id?: string; output?: string; providerData?: Record; status: "completed" | "failed"; type: "apply_patch_call_output"; } ``` | Name | Type | Description | | --------------- | --------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `callId` | `string` | ‐ | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `output?` | `string` | ‐ | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status` | `"completed"` \| `"failed"` | ‐ | | `type` | `"apply_patch_call_output"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-14) ```ts { content: object[]; id?: string; providerData?: Record; rawContent?: object[]; type: "reasoning"; } ``` | Name | Type | Description | | --------------- | ------------------------- | ------------------------------------------------------------------------------------------------------------- | | `content` | `object`\[] | The user facing representation of the reasoning. Additional information might be in the `providerData` field. | | `id?` | `string` | ‐ | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `rawContent?` | `object`\[] | The raw reasoning text from the model. | | `type` | `"reasoning"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-15) ```ts { created_by?: string; encrypted_content: string; id?: string; providerData?: Record; type: "compaction"; } ``` | Name | Type | Description | | ------------------- | ------------------------- | ------------------------------------------------------------------------------------------------------------ | | `created_by?` | `string` | Identifier for the generator of this compaction item. | | `encrypted_content` | `string` | Encrypted payload returned by the compaction endpoint. | | `id?` | `string` | Identifier for the compaction item. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `type` | `"compaction"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-16) ```ts { id?: string; providerData?: Record; type: "unknown"; } ``` | Name | Type | Description | | --------------- | ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `type` | `"unknown"` | ‐ | *** `undefined` ##### type [Section titled “type”](#type-1) ```ts type: string; ``` #### Overrides [Section titled “Overrides”](#overrides-2) ```ts RunItemBase.toJSON ``` # RunHandoffOutputItem ## Extends [Section titled “Extends”](#extends) * `RunItemBase` ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new RunHandoffOutputItem( rawItem, sourceAgent, targetAgent): RunHandoffOutputItem; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | ----------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `rawItem` | { `callId`: `string`; `id?`: `string`; `name`: `string`; `namespace?`: `string`; `output`: \| `string` \| { `providerData?`: `Record`<`string`, `any`>; `text`: `string`; `type`: `"text"`; } \| { `detail?`: `"low"` \| `"high"` \| `"auto"` \| `string` & `object`; `image?`: \| `string` \| { `data`: `string` \| `Uint8Array`<`ArrayBuffer`>; `mediaType?`: `string`; } \| { `url`: `string`; } \| { `fileId`: `string`; }; `providerData?`: `Record`<`string`, `any`>; `type`: `"image"`; } \| { `file`: \| `string` \| { `data`: `string` \| `Uint8Array`<`ArrayBuffer`>; `filename`: `string`; `mediaType`: `string`; } \| { `filename?`: `string`; `url`: `string`; } \| { `filename?`: `string`; `id`: `string`; }; `providerData?`: `Record`<`string`, `any`>; `type`: `"file"`; } \| ( \| { `providerData?`: `Record`<`string`, `any`>; `text`: `string`; `type`: `"input_text"`; } \| { `detail?`: `string`; `image?`: \| `string` \| { `id`: `string`; }; `providerData?`: `Record`<`string`, `any`>; `type`: `"input_image"`; } \| { `file?`: \| `string` \| { `id`: `string`; } \| { `url`: `string`; }; `filename?`: `string`; `providerData?`: `Record`<`string`, `any`>; `type`: `"input_file"`; })\[]; `providerData?`: `Record`<`string`, `any`>; `status`: `"in_progress"` \| `"completed"` \| `"incomplete"`; `type`: `"function_call_result"`; } | ‐ | | `rawItem.callId` | `string` | The ID of the tool call. Required to match up the respective tool call result. | | `rawItem.id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `rawItem.name` | `string` | The name of the tool that was called | | `rawItem.namespace?` | `string` | Optional namespace preserved from the originating function call. | | `rawItem.output` | \| `string` \| { `providerData?`: `Record`<`string`, `any`>; `text`: `string`; `type`: `"text"`; } \| { `detail?`: `"low"` \| `"high"` \| `"auto"` \| `string` & `object`; `image?`: \| `string` \| { `data`: `string` \| `Uint8Array`<`ArrayBuffer`>; `mediaType?`: `string`; } \| { `url`: `string`; } \| { `fileId`: `string`; }; `providerData?`: `Record`<`string`, `any`>; `type`: `"image"`; } \| { `file`: \| `string` \| { `data`: `string` \| `Uint8Array`<`ArrayBuffer`>; `filename`: `string`; `mediaType`: `string`; } \| { `filename?`: `string`; `url`: `string`; } \| { `filename?`: `string`; `id`: `string`; }; `providerData?`: `Record`<`string`, `any`>; `type`: `"file"`; } \| ( \| { `providerData?`: `Record`<`string`, `any`>; `text`: `string`; `type`: `"input_text"`; } \| { `detail?`: `string`; `image?`: \| `string` \| { `id`: `string`; }; `providerData?`: `Record`<`string`, `any`>; `type`: `"input_image"`; } \| { `file?`: \| `string` \| { `id`: `string`; } \| { `url`: `string`; }; `filename?`: `string`; `providerData?`: `Record`<`string`, `any`>; `type`: `"input_file"`; })\[] | The output of the tool call. | | `rawItem.providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `rawItem.status` | `"in_progress"` \| `"completed"` \| `"incomplete"` | The status of the tool call. | | `rawItem.type` | `"function_call_result"` | ‐ | | `sourceAgent` | [`Agent`](/openai-agents-js/openai/agents-core/classes/agent/)<`any`, `any`> | ‐ | | `targetAgent` | [`Agent`](/openai-agents-js/openai/agents-core/classes/agent/)<`any`, `any`> | ‐ | #### Returns [Section titled “Returns”](#returns) `RunHandoffOutputItem` #### Overrides [Section titled “Overrides”](#overrides) ```ts RunItemBase.constructor ``` ## Properties [Section titled “Properties”](#properties) ### rawItem [Section titled “rawItem”](#rawitem) ```ts rawItem: object; ``` | Name | Type | Description | | --------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `callId` | `string` | The ID of the tool call. Required to match up the respective tool call result. | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `name` | `string` | The name of the tool that was called | | `namespace?` | `string` | Optional namespace preserved from the originating function call. | | `output` | \| `string` \| { `providerData?`: `Record`<`string`, `any`>; `text`: `string`; `type`: `"text"`; } \| { `detail?`: `"low"` \| `"high"` \| `"auto"` \| `string` & `object`; `image?`: \| `string` \| { `data`: `string` \| `Uint8Array`<`ArrayBuffer`>; `mediaType?`: `string`; } \| { `url`: `string`; } \| { `fileId`: `string`; }; `providerData?`: `Record`<`string`, `any`>; `type`: `"image"`; } \| { `file`: \| `string` \| { `data`: `string` \| `Uint8Array`<`ArrayBuffer`>; `filename`: `string`; `mediaType`: `string`; } \| { `filename?`: `string`; `url`: `string`; } \| { `filename?`: `string`; `id`: `string`; }; `providerData?`: `Record`<`string`, `any`>; `type`: `"file"`; } \| ( \| { `providerData?`: `Record`<`string`, `any`>; `text`: `string`; `type`: `"input_text"`; } \| { `detail?`: `string`; `image?`: \| `string` \| { `id`: `string`; }; `providerData?`: `Record`<`string`, `any`>; `type`: `"input_image"`; } \| { `file?`: \| `string` \| { `id`: `string`; } \| { `url`: `string`; }; `filename?`: `string`; `providerData?`: `Record`<`string`, `any`>; `type`: `"input_file"`; })\[] | The output of the tool call. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status` | `"in_progress"` \| `"completed"` \| `"incomplete"` | The status of the tool call. | | `type` | `"function_call_result"` | ‐ | #### Inherited from [Section titled “Inherited from”](#inherited-from) ```ts RunItemBase.rawItem ``` *** ### sourceAgent [Section titled “sourceAgent”](#sourceagent) ```ts sourceAgent: Agent; ``` *** ### targetAgent [Section titled “targetAgent”](#targetagent) ```ts targetAgent: Agent; ``` *** ### type [Section titled “type”](#type) ```ts readonly type: "handoff_output_item"; ``` #### Overrides [Section titled “Overrides”](#overrides-1) ```ts RunItemBase.type ``` ## Methods [Section titled “Methods”](#methods) ### toJSON() [Section titled “toJSON()”](#tojson) ```ts toJSON(): object; ``` #### Returns [Section titled “Returns”](#returns-1) `object` ##### rawItem [Section titled “rawItem”](#rawitem-1) ```ts rawItem: | { content: ( | { providerData?: Record; refusal: string; type: "refusal"; } | { providerData?: Record; text: string; type: "output_text"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; } | { image: string; providerData?: Record; type: "image"; })[]; id?: string; providerData?: Record; role: "assistant"; status: "in_progress" | "completed" | "incomplete"; type?: "message"; } | { content: | string | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; })[]; id?: string; providerData?: Record; role: "user"; type?: "message"; } | { content: string; id?: string; providerData?: Record; role: "system"; type?: "message"; } | { arguments?: string; id?: string; name: string; output?: string; providerData?: Record; status?: string; type: "hosted_tool_call"; } | { arguments: string; callId: string; id?: string; name: string; namespace?: string; providerData?: Record; status?: "in_progress" | "completed" | "incomplete"; type: "function_call"; } | { arguments: unknown; call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; type: "tool_search_call"; } | { call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; tools: Record[]; type: "tool_search_output"; } | { callId: string; id?: string; name: string; namespace?: string; output: | string | { providerData?: Record; text: string; type: "text"; } | { detail?: "low" | "high" | "auto" | string & object; image?: | string | { data: string | Uint8Array; mediaType?: string; } | { url: string; } | { fileId: string; }; providerData?: Record; type: "image"; } | { file: | string | { data: string | Uint8Array; filename: string; mediaType: string; } | { filename?: string; url: string; } | { filename?: string; id: string; }; providerData?: Record; type: "file"; } | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; })[]; providerData?: Record; status: "in_progress" | "completed" | "incomplete"; type: "function_call_result"; } | { action?: | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; }; actions?: ( | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; })[]; callId: string; id?: string; providerData?: Record; status: "in_progress" | "completed" | "incomplete"; type: "computer_call"; } | { callId: string; id?: string; output: { data: string; providerData?: Record; type: "computer_screenshot"; }; providerData?: Record; type: "computer_call_result"; } | { action: { commands: string[]; maxOutputLength?: number; timeoutMs?: number; }; callId: string; id?: string; providerData?: Record; status?: "in_progress" | "completed" | "incomplete"; type: "shell_call"; } | { callId: string; id?: string; maxOutputLength?: number; output: object[]; providerData?: Record; type: "shell_call_output"; } | { callId: string; id?: string; operation: | { diff: string; path: string; type: "create_file"; } | { diff: string; moveTo?: string; path: string; type: "update_file"; } | { path: string; type: "delete_file"; }; providerData?: Record; status: "in_progress" | "completed"; type: "apply_patch_call"; } | { callId: string; id?: string; output?: string; providerData?: Record; status: "completed" | "failed"; type: "apply_patch_call_output"; } | { content: object[]; id?: string; providerData?: Record; rawContent?: object[]; type: "reasoning"; } | { created_by?: string; encrypted_content: string; id?: string; providerData?: Record; type: "compaction"; } | { id?: string; providerData?: Record; type: "unknown"; } | undefined; ``` ###### Union Members [Section titled “Union Members”](#union-members) ###### Type Literal [Section titled “Type Literal”](#type-literal) ```ts { content: ( | { providerData?: Record; refusal: string; type: "refusal"; } | { providerData?: Record; text: string; type: "output_text"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; } | { image: string; providerData?: Record; type: "image"; })[]; id?: string; providerData?: Record; role: "assistant"; status: "in_progress" | "completed" | "incomplete"; type?: "message"; } ``` | Name | Type | Description | | --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `content` | ( \| { `providerData?`: `Record`<`string`, `any`>; `refusal`: `string`; `type`: `"refusal"`; } \| { `providerData?`: `Record`<`string`, `any`>; `text`: `string`; `type`: `"output_text"`; } \| { `audio`: \| `string` \| { `id`: `string`; }; `format?`: `string` \| `null`; `providerData?`: `Record`<`string`, `any`>; `transcript?`: `string` \| `null`; `type`: `"audio"`; } \| { `image`: `string`; `providerData?`: `Record`<`string`, `any`>; `type`: `"image"`; })\[] | The content of the message. | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `role` | `"assistant"` | Representing a message from the assistant (i.e. the model) | | `status` | `"in_progress"` \| `"completed"` \| `"incomplete"` | The status of the message. | | `type?` | `"message"` | Any item without a type is treated as a message | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-1) ```ts { content: | string | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; })[]; id?: string; providerData?: Record; role: "user"; type?: "message"; } ``` | Name | Type | Description | | --------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `content` | \| `string` \| ( \| { `providerData?`: `Record`<`string`, `any`>; `text`: `string`; `type`: `"input_text"`; } \| { `detail?`: `string`; `image?`: \| `string` \| { `id`: `string`; }; `providerData?`: `Record`<`string`, `any`>; `type`: `"input_image"`; } \| { `file?`: \| `string` \| { `id`: `string`; } \| { `url`: `string`; }; `filename?`: `string`; `providerData?`: `Record`<`string`, `any`>; `type`: `"input_file"`; } \| { `audio`: \| `string` \| { `id`: `string`; }; `format?`: `string` \| `null`; `providerData?`: `Record`<`string`, `any`>; `transcript?`: `string` \| `null`; `type`: `"audio"`; })\[] | The content of the message. | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `role` | `"user"` | Representing a message from the user | | `type?` | `"message"` | Any item without a type is treated as a message | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-2) ```ts { content: string; id?: string; providerData?: Record; role: "system"; type?: "message"; } ``` | Name | Type | Description | | --------------- | ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `content` | `string` | The content of the message. | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `role` | `"system"` | Representing a system message to the user | | `type?` | `"message"` | Any item without a type is treated as a message | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-3) ```ts { arguments?: string; id?: string; name: string; output?: string; providerData?: Record; status?: string; type: "hosted_tool_call"; } ``` | Name | Type | Description | | --------------- | ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `arguments?` | `string` | The arguments of the hosted tool call. | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `name` | `string` | The name of the hosted tool. For example `web_search_call` or `file_search_call` | | `output?` | `string` | The primary output of the tool call. Additional output might be in the `providerData` field. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status?` | `string` | The status of the tool call. | | `type` | `"hosted_tool_call"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-4) ```ts { arguments: string; callId: string; id?: string; name: string; namespace?: string; providerData?: Record; status?: "in_progress" | "completed" | "incomplete"; type: "function_call"; } ``` | Name | Type | Description | | --------------- | -------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `arguments` | `string` | The arguments of the function call. | | `callId` | `string` | The ID of the tool call. Required to match up the respective tool call result. | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `name` | `string` | The name of the function. | | `namespace?` | `string` | Optional namespace used to qualify the function name for tool search. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status?` | `"in_progress"` \| `"completed"` \| `"incomplete"` | The status of the function call. | | `type` | `"function_call"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-5) ```ts { arguments: unknown; call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; type: "tool_search_call"; } ``` | Name | Type | Default value | Description | | --------------- | ------------------------- | ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `arguments` | `unknown` | `ToolSearchCallArguments` | ‐ | | `call_id?` | `string` \| `null` | ‐ | ‐ | | `callId?` | `string` \| `null` | ‐ | ‐ | | `execution?` | `"client"` \| `"server"` | ‐ | ‐ | | `id?` | `string` | ‐ | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `providerData?` | `Record`<`string`, `any`> | ‐ | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status?` | `string` | ‐ | ‐ | | `type` | `"tool_search_call"` | ‐ | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-6) ```ts { call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; tools: Record[]; type: "tool_search_output"; } ``` | Name | Type | Description | | --------------- | ---------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `call_id?` | `string` \| `null` | ‐ | | `callId?` | `string` \| `null` | ‐ | | `execution?` | `"client"` \| `"server"` | ‐ | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status?` | `string` | ‐ | | `tools` | `Record`<`string`, `any`>\[] | ‐ | | `type` | `"tool_search_output"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-7) ```ts { callId: string; id?: string; name: string; namespace?: string; output: | string | { providerData?: Record; text: string; type: "text"; } | { detail?: "low" | "high" | "auto" | string & object; image?: | string | { data: string | Uint8Array; mediaType?: string; } | { url: string; } | { fileId: string; }; providerData?: Record; type: "image"; } | { file: | string | { data: string | Uint8Array; filename: string; mediaType: string; } | { filename?: string; url: string; } | { filename?: string; id: string; }; providerData?: Record; type: "file"; } | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; })[]; providerData?: Record; status: "in_progress" | "completed" | "incomplete"; type: "function_call_result"; } ``` | Name | Type | Description | | --------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `callId` | `string` | The ID of the tool call. Required to match up the respective tool call result. | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `name` | `string` | The name of the tool that was called | | `namespace?` | `string` | Optional namespace preserved from the originating function call. | | `output` | \| `string` \| { `providerData?`: `Record`<`string`, `any`>; `text`: `string`; `type`: `"text"`; } \| { `detail?`: `"low"` \| `"high"` \| `"auto"` \| `string` & `object`; `image?`: \| `string` \| { `data`: `string` \| `Uint8Array`<`ArrayBuffer`>; `mediaType?`: `string`; } \| { `url`: `string`; } \| { `fileId`: `string`; }; `providerData?`: `Record`<`string`, `any`>; `type`: `"image"`; } \| { `file`: \| `string` \| { `data`: `string` \| `Uint8Array`<`ArrayBuffer`>; `filename`: `string`; `mediaType`: `string`; } \| { `filename?`: `string`; `url`: `string`; } \| { `filename?`: `string`; `id`: `string`; }; `providerData?`: `Record`<`string`, `any`>; `type`: `"file"`; } \| ( \| { `providerData?`: `Record`<`string`, `any`>; `text`: `string`; `type`: `"input_text"`; } \| { `detail?`: `string`; `image?`: \| `string` \| { `id`: `string`; }; `providerData?`: `Record`<`string`, `any`>; `type`: `"input_image"`; } \| { `file?`: \| `string` \| { `id`: `string`; } \| { `url`: `string`; }; `filename?`: `string`; `providerData?`: `Record`<`string`, `any`>; `type`: `"input_file"`; })\[] | The output of the tool call. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status` | `"in_progress"` \| `"completed"` \| `"incomplete"` | The status of the tool call. | | `type` | `"function_call_result"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-8) ```ts { action?: | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; }; actions?: ( | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; })[]; callId: string; id?: string; providerData?: Record; status: "in_progress" | "completed" | "incomplete"; type: "computer_call"; } ``` | Name | Type | Description | | --------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `action?` | \| { `type`: `"screenshot"`; } \| { `button`: `"left"` \| `"right"` \| `"wheel"` \| `"back"` \| `"forward"`; `type`: `"click"`; `x`: `number`; `y`: `number`; } \| { `type`: `"double_click"`; `x`: `number`; `y`: `number`; } \| { `scroll_x`: `number`; `scroll_y`: `number`; `type`: `"scroll"`; `x`: `number`; `y`: `number`; } \| { `text`: `string`; `type`: `"type"`; } \| { `type`: `"wait"`; } \| { `type`: `"move"`; `x`: `number`; `y`: `number`; } \| { `keys`: `string`\[]; `type`: `"keypress"`; } \| { `path`: `object`\[]; `type`: `"drag"`; } | The legacy single action to be performed by the computer. | | `actions?` | ( \| { `type`: `"screenshot"`; } \| { `button`: `"left"` \| `"right"` \| `"wheel"` \| `"back"` \| `"forward"`; `type`: `"click"`; `x`: `number`; `y`: `number`; } \| { `type`: `"double_click"`; `x`: `number`; `y`: `number`; } \| { `scroll_x`: `number`; `scroll_y`: `number`; `type`: `"scroll"`; `x`: `number`; `y`: `number`; } \| { `text`: `string`; `type`: `"type"`; } \| { `type`: `"wait"`; } \| { `type`: `"move"`; `x`: `number`; `y`: `number`; } \| { `keys`: `string`\[]; `type`: `"keypress"`; } \| { `path`: `object`\[]; `type`: `"drag"`; })\[] | Batched actions returned by the GA computer tool. | | `callId` | `string` | The ID of the computer call. Required to match up the respective computer call result. | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status` | `"in_progress"` \| `"completed"` \| `"incomplete"` | The status of the computer call. | | `type` | `"computer_call"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-9) ```ts { callId: string; id?: string; output: { data: string; providerData?: Record; type: "computer_screenshot"; }; providerData?: Record; type: "computer_call_result"; } ``` | Name | Type | Default value | Description | | ---------------------- | ------------------------- | -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `callId` | `string` | ‐ | The ID of the computer call. Required to match up the respective computer call result. | | `id?` | `string` | ‐ | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `output` | `object` | `ComputerToolOutput` | The output of the computer call. | | `output.data` | `string` | ‐ | A base64 encoded image data or a URL representing the screenshot. | | `output.providerData?` | `Record`<`string`, `any`> | ‐ | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `output.type` | `"computer_screenshot"` | ‐ | ‐ | | `providerData?` | `Record`<`string`, `any`> | ‐ | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `type` | `"computer_call_result"` | ‐ | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-10) ```ts { action: { commands: string[]; maxOutputLength?: number; timeoutMs?: number; }; callId: string; id?: string; providerData?: Record; status?: "in_progress" | "completed" | "incomplete"; type: "shell_call"; } ``` | Name | Type | Default value | Description | | ------------------------- | -------------------------------------------------- | ------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `action` | `object` | `ShellAction` | ‐ | | `action.commands` | `string`\[] | ‐ | ‐ | | `action.maxOutputLength?` | `number` | ‐ | ‐ | | `action.timeoutMs?` | `number` | ‐ | ‐ | | `callId` | `string` | ‐ | ‐ | | `id?` | `string` | ‐ | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `providerData?` | `Record`<`string`, `any`> | ‐ | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status?` | `"in_progress"` \| `"completed"` \| `"incomplete"` | ‐ | ‐ | | `type` | `"shell_call"` | ‐ | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-11) ```ts { callId: string; id?: string; maxOutputLength?: number; output: object[]; providerData?: Record; type: "shell_call_output"; } ``` | Name | Type | Description | | ------------------ | ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `callId` | `string` | ‐ | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `maxOutputLength?` | `number` | ‐ | | `output` | `object`\[] | ‐ | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `type` | `"shell_call_output"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-12) ```ts { callId: string; id?: string; operation: | { diff: string; path: string; type: "create_file"; } | { diff: string; moveTo?: string; path: string; type: "update_file"; } | { path: string; type: "delete_file"; }; providerData?: Record; status: "in_progress" | "completed"; type: "apply_patch_call"; } ``` | Name | Type | Default value | Description | | --------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `callId` | `string` | ‐ | ‐ | | `id?` | `string` | ‐ | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `operation` | \| { `diff`: `string`; `path`: `string`; `type`: `"create_file"`; } \| { `diff`: `string`; `moveTo?`: `string`; `path`: `string`; `type`: `"update_file"`; } \| { `path`: `string`; `type`: `"delete_file"`; } | `ApplyPatchOperation` | ‐ | | `providerData?` | `Record`<`string`, `any`> | ‐ | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status` | `"in_progress"` \| `"completed"` | ‐ | ‐ | | `type` | `"apply_patch_call"` | ‐ | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-13) ```ts { callId: string; id?: string; output?: string; providerData?: Record; status: "completed" | "failed"; type: "apply_patch_call_output"; } ``` | Name | Type | Description | | --------------- | --------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `callId` | `string` | ‐ | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `output?` | `string` | ‐ | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status` | `"completed"` \| `"failed"` | ‐ | | `type` | `"apply_patch_call_output"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-14) ```ts { content: object[]; id?: string; providerData?: Record; rawContent?: object[]; type: "reasoning"; } ``` | Name | Type | Description | | --------------- | ------------------------- | ------------------------------------------------------------------------------------------------------------- | | `content` | `object`\[] | The user facing representation of the reasoning. Additional information might be in the `providerData` field. | | `id?` | `string` | ‐ | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `rawContent?` | `object`\[] | The raw reasoning text from the model. | | `type` | `"reasoning"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-15) ```ts { created_by?: string; encrypted_content: string; id?: string; providerData?: Record; type: "compaction"; } ``` | Name | Type | Description | | ------------------- | ------------------------- | ------------------------------------------------------------------------------------------------------------ | | `created_by?` | `string` | Identifier for the generator of this compaction item. | | `encrypted_content` | `string` | Encrypted payload returned by the compaction endpoint. | | `id?` | `string` | Identifier for the compaction item. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `type` | `"compaction"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-16) ```ts { id?: string; providerData?: Record; type: "unknown"; } ``` | Name | Type | Description | | --------------- | ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `type` | `"unknown"` | ‐ | *** `undefined` ##### sourceAgent [Section titled “sourceAgent”](#sourceagent-1) ```ts sourceAgent: object; ``` ###### sourceAgent.name [Section titled “sourceAgent.name”](#sourceagentname) ```ts name: string; ``` ##### targetAgent [Section titled “targetAgent”](#targetagent-1) ```ts targetAgent: object; ``` ###### targetAgent.name [Section titled “targetAgent.name”](#targetagentname) ```ts name: string; ``` ##### type [Section titled “type”](#type-1) ```ts type: string; ``` #### Overrides [Section titled “Overrides”](#overrides-2) ```ts RunItemBase.toJSON ``` # RunItemStreamEvent Streaming events that wrap a `RunItem`. As the agent processes the LLM response, it will generate these events from new messages, tool calls, tool outputs, handoffs, etc. ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new RunItemStreamEvent(name, item): RunItemStreamEvent; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | --------- | ----------------------------------------------------------------------- | -------------------------- | | `name` | `RunItemStreamEventName` | The name of the event. | | `item` | [`RunItem`](/openai-agents-js/openai/agents-core/type-aliases/runitem/) | The item that was created. | #### Returns [Section titled “Returns”](#returns) `RunItemStreamEvent` ## Properties [Section titled “Properties”](#properties) ### item [Section titled “item”](#item) ```ts item: RunItem; ``` The item that was created. *** ### name [Section titled “name”](#name) ```ts name: RunItemStreamEventName; ``` The name of the event. *** ### type [Section titled “type”](#type) ```ts readonly type: "run_item_stream_event" = 'run_item_stream_event'; ``` # RunMessageOutputItem ## Extends [Section titled “Extends”](#extends) * `RunItemBase` ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new RunMessageOutputItem(rawItem, agent): RunMessageOutputItem; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | ----------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `rawItem` | { `content`: ( \| { `providerData?`: `Record`<`string`, `any`>; `refusal`: `string`; `type`: `"refusal"`; } \| { `providerData?`: `Record`<`string`, `any`>; `text`: `string`; `type`: `"output_text"`; } \| { `audio`: \| `string` \| { `id`: `string`; }; `format?`: `string` \| `null`; `providerData?`: `Record`<`string`, `any`>; `transcript?`: `string` \| `null`; `type`: `"audio"`; } \| { `image`: `string`; `providerData?`: `Record`<`string`, `any`>; `type`: `"image"`; })\[]; `id?`: `string`; `providerData?`: `Record`<`string`, `any`>; `role`: `"assistant"`; `status`: `"in_progress"` \| `"completed"` \| `"incomplete"`; `type?`: `"message"`; } | ‐ | | `rawItem.content` | ( \| { `providerData?`: `Record`<`string`, `any`>; `refusal`: `string`; `type`: `"refusal"`; } \| { `providerData?`: `Record`<`string`, `any`>; `text`: `string`; `type`: `"output_text"`; } \| { `audio`: \| `string` \| { `id`: `string`; }; `format?`: `string` \| `null`; `providerData?`: `Record`<`string`, `any`>; `transcript?`: `string` \| `null`; `type`: `"audio"`; } \| { `image`: `string`; `providerData?`: `Record`<`string`, `any`>; `type`: `"image"`; })\[] | The content of the message. | | `rawItem.id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `rawItem.providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `rawItem.role` | `"assistant"` | Representing a message from the assistant (i.e. the model) | | `rawItem.status` | `"in_progress"` \| `"completed"` \| `"incomplete"` | The status of the message. | | `rawItem.type?` | `"message"` | Any item without a type is treated as a message | | `agent` | [`Agent`](/openai-agents-js/openai/agents-core/classes/agent/) | ‐ | #### Returns [Section titled “Returns”](#returns) `RunMessageOutputItem` #### Overrides [Section titled “Overrides”](#overrides) ```ts RunItemBase.constructor ``` ## Properties [Section titled “Properties”](#properties) ### agent [Section titled “agent”](#agent) ```ts agent: Agent; ``` *** ### rawItem [Section titled “rawItem”](#rawitem) ```ts rawItem: object; ``` | Name | Type | Description | | --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `content` | ( \| { `providerData?`: `Record`<`string`, `any`>; `refusal`: `string`; `type`: `"refusal"`; } \| { `providerData?`: `Record`<`string`, `any`>; `text`: `string`; `type`: `"output_text"`; } \| { `audio`: \| `string` \| { `id`: `string`; }; `format?`: `string` \| `null`; `providerData?`: `Record`<`string`, `any`>; `transcript?`: `string` \| `null`; `type`: `"audio"`; } \| { `image`: `string`; `providerData?`: `Record`<`string`, `any`>; `type`: `"image"`; })\[] | The content of the message. | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `role` | `"assistant"` | Representing a message from the assistant (i.e. the model) | | `status` | `"in_progress"` \| `"completed"` \| `"incomplete"` | The status of the message. | | `type?` | `"message"` | Any item without a type is treated as a message | #### Inherited from [Section titled “Inherited from”](#inherited-from) ```ts RunItemBase.rawItem ``` *** ### type [Section titled “type”](#type) ```ts readonly type: "message_output_item"; ``` #### Overrides [Section titled “Overrides”](#overrides-1) ```ts RunItemBase.type ``` ## Accessors [Section titled “Accessors”](#accessors) ### content [Section titled “content”](#content) #### Get Signature [Section titled “Get Signature”](#get-signature) ```ts get content(): string; ``` ##### Returns [Section titled “Returns”](#returns-1) `string` ## Methods [Section titled “Methods”](#methods) ### toJSON() [Section titled “toJSON()”](#tojson) ```ts toJSON(): object; ``` #### Returns [Section titled “Returns”](#returns-2) `object` ##### agent [Section titled “agent”](#agent-1) ```ts agent: object; ``` ###### agent.name [Section titled “agent.name”](#agentname) ```ts name: string; ``` ##### rawItem [Section titled “rawItem”](#rawitem-1) ```ts rawItem: | { content: ( | { providerData?: Record; refusal: string; type: "refusal"; } | { providerData?: Record; text: string; type: "output_text"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; } | { image: string; providerData?: Record; type: "image"; })[]; id?: string; providerData?: Record; role: "assistant"; status: "in_progress" | "completed" | "incomplete"; type?: "message"; } | { content: | string | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; })[]; id?: string; providerData?: Record; role: "user"; type?: "message"; } | { content: string; id?: string; providerData?: Record; role: "system"; type?: "message"; } | { arguments?: string; id?: string; name: string; output?: string; providerData?: Record; status?: string; type: "hosted_tool_call"; } | { arguments: string; callId: string; id?: string; name: string; namespace?: string; providerData?: Record; status?: "in_progress" | "completed" | "incomplete"; type: "function_call"; } | { arguments: unknown; call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; type: "tool_search_call"; } | { call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; tools: Record[]; type: "tool_search_output"; } | { callId: string; id?: string; name: string; namespace?: string; output: | string | { providerData?: Record; text: string; type: "text"; } | { detail?: "low" | "high" | "auto" | string & object; image?: | string | { data: string | Uint8Array; mediaType?: string; } | { url: string; } | { fileId: string; }; providerData?: Record; type: "image"; } | { file: | string | { data: string | Uint8Array; filename: string; mediaType: string; } | { filename?: string; url: string; } | { filename?: string; id: string; }; providerData?: Record; type: "file"; } | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; })[]; providerData?: Record; status: "in_progress" | "completed" | "incomplete"; type: "function_call_result"; } | { action?: | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; }; actions?: ( | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; })[]; callId: string; id?: string; providerData?: Record; status: "in_progress" | "completed" | "incomplete"; type: "computer_call"; } | { callId: string; id?: string; output: { data: string; providerData?: Record; type: "computer_screenshot"; }; providerData?: Record; type: "computer_call_result"; } | { action: { commands: string[]; maxOutputLength?: number; timeoutMs?: number; }; callId: string; id?: string; providerData?: Record; status?: "in_progress" | "completed" | "incomplete"; type: "shell_call"; } | { callId: string; id?: string; maxOutputLength?: number; output: object[]; providerData?: Record; type: "shell_call_output"; } | { callId: string; id?: string; operation: | { diff: string; path: string; type: "create_file"; } | { diff: string; moveTo?: string; path: string; type: "update_file"; } | { path: string; type: "delete_file"; }; providerData?: Record; status: "in_progress" | "completed"; type: "apply_patch_call"; } | { callId: string; id?: string; output?: string; providerData?: Record; status: "completed" | "failed"; type: "apply_patch_call_output"; } | { content: object[]; id?: string; providerData?: Record; rawContent?: object[]; type: "reasoning"; } | { created_by?: string; encrypted_content: string; id?: string; providerData?: Record; type: "compaction"; } | { id?: string; providerData?: Record; type: "unknown"; } | undefined; ``` ###### Union Members [Section titled “Union Members”](#union-members) ###### Type Literal [Section titled “Type Literal”](#type-literal) ```ts { content: ( | { providerData?: Record; refusal: string; type: "refusal"; } | { providerData?: Record; text: string; type: "output_text"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; } | { image: string; providerData?: Record; type: "image"; })[]; id?: string; providerData?: Record; role: "assistant"; status: "in_progress" | "completed" | "incomplete"; type?: "message"; } ``` | Name | Type | Description | | --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `content` | ( \| { `providerData?`: `Record`<`string`, `any`>; `refusal`: `string`; `type`: `"refusal"`; } \| { `providerData?`: `Record`<`string`, `any`>; `text`: `string`; `type`: `"output_text"`; } \| { `audio`: \| `string` \| { `id`: `string`; }; `format?`: `string` \| `null`; `providerData?`: `Record`<`string`, `any`>; `transcript?`: `string` \| `null`; `type`: `"audio"`; } \| { `image`: `string`; `providerData?`: `Record`<`string`, `any`>; `type`: `"image"`; })\[] | The content of the message. | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `role` | `"assistant"` | Representing a message from the assistant (i.e. the model) | | `status` | `"in_progress"` \| `"completed"` \| `"incomplete"` | The status of the message. | | `type?` | `"message"` | Any item without a type is treated as a message | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-1) ```ts { content: | string | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; })[]; id?: string; providerData?: Record; role: "user"; type?: "message"; } ``` | Name | Type | Description | | --------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `content` | \| `string` \| ( \| { `providerData?`: `Record`<`string`, `any`>; `text`: `string`; `type`: `"input_text"`; } \| { `detail?`: `string`; `image?`: \| `string` \| { `id`: `string`; }; `providerData?`: `Record`<`string`, `any`>; `type`: `"input_image"`; } \| { `file?`: \| `string` \| { `id`: `string`; } \| { `url`: `string`; }; `filename?`: `string`; `providerData?`: `Record`<`string`, `any`>; `type`: `"input_file"`; } \| { `audio`: \| `string` \| { `id`: `string`; }; `format?`: `string` \| `null`; `providerData?`: `Record`<`string`, `any`>; `transcript?`: `string` \| `null`; `type`: `"audio"`; })\[] | The content of the message. | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `role` | `"user"` | Representing a message from the user | | `type?` | `"message"` | Any item without a type is treated as a message | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-2) ```ts { content: string; id?: string; providerData?: Record; role: "system"; type?: "message"; } ``` | Name | Type | Description | | --------------- | ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `content` | `string` | The content of the message. | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `role` | `"system"` | Representing a system message to the user | | `type?` | `"message"` | Any item without a type is treated as a message | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-3) ```ts { arguments?: string; id?: string; name: string; output?: string; providerData?: Record; status?: string; type: "hosted_tool_call"; } ``` | Name | Type | Description | | --------------- | ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `arguments?` | `string` | The arguments of the hosted tool call. | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `name` | `string` | The name of the hosted tool. For example `web_search_call` or `file_search_call` | | `output?` | `string` | The primary output of the tool call. Additional output might be in the `providerData` field. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status?` | `string` | The status of the tool call. | | `type` | `"hosted_tool_call"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-4) ```ts { arguments: string; callId: string; id?: string; name: string; namespace?: string; providerData?: Record; status?: "in_progress" | "completed" | "incomplete"; type: "function_call"; } ``` | Name | Type | Description | | --------------- | -------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `arguments` | `string` | The arguments of the function call. | | `callId` | `string` | The ID of the tool call. Required to match up the respective tool call result. | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `name` | `string` | The name of the function. | | `namespace?` | `string` | Optional namespace used to qualify the function name for tool search. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status?` | `"in_progress"` \| `"completed"` \| `"incomplete"` | The status of the function call. | | `type` | `"function_call"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-5) ```ts { arguments: unknown; call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; type: "tool_search_call"; } ``` | Name | Type | Default value | Description | | --------------- | ------------------------- | ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `arguments` | `unknown` | `ToolSearchCallArguments` | ‐ | | `call_id?` | `string` \| `null` | ‐ | ‐ | | `callId?` | `string` \| `null` | ‐ | ‐ | | `execution?` | `"client"` \| `"server"` | ‐ | ‐ | | `id?` | `string` | ‐ | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `providerData?` | `Record`<`string`, `any`> | ‐ | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status?` | `string` | ‐ | ‐ | | `type` | `"tool_search_call"` | ‐ | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-6) ```ts { call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; tools: Record[]; type: "tool_search_output"; } ``` | Name | Type | Description | | --------------- | ---------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `call_id?` | `string` \| `null` | ‐ | | `callId?` | `string` \| `null` | ‐ | | `execution?` | `"client"` \| `"server"` | ‐ | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status?` | `string` | ‐ | | `tools` | `Record`<`string`, `any`>\[] | ‐ | | `type` | `"tool_search_output"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-7) ```ts { callId: string; id?: string; name: string; namespace?: string; output: | string | { providerData?: Record; text: string; type: "text"; } | { detail?: "low" | "high" | "auto" | string & object; image?: | string | { data: string | Uint8Array; mediaType?: string; } | { url: string; } | { fileId: string; }; providerData?: Record; type: "image"; } | { file: | string | { data: string | Uint8Array; filename: string; mediaType: string; } | { filename?: string; url: string; } | { filename?: string; id: string; }; providerData?: Record; type: "file"; } | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; })[]; providerData?: Record; status: "in_progress" | "completed" | "incomplete"; type: "function_call_result"; } ``` | Name | Type | Description | | --------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `callId` | `string` | The ID of the tool call. Required to match up the respective tool call result. | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `name` | `string` | The name of the tool that was called | | `namespace?` | `string` | Optional namespace preserved from the originating function call. | | `output` | \| `string` \| { `providerData?`: `Record`<`string`, `any`>; `text`: `string`; `type`: `"text"`; } \| { `detail?`: `"low"` \| `"high"` \| `"auto"` \| `string` & `object`; `image?`: \| `string` \| { `data`: `string` \| `Uint8Array`<`ArrayBuffer`>; `mediaType?`: `string`; } \| { `url`: `string`; } \| { `fileId`: `string`; }; `providerData?`: `Record`<`string`, `any`>; `type`: `"image"`; } \| { `file`: \| `string` \| { `data`: `string` \| `Uint8Array`<`ArrayBuffer`>; `filename`: `string`; `mediaType`: `string`; } \| { `filename?`: `string`; `url`: `string`; } \| { `filename?`: `string`; `id`: `string`; }; `providerData?`: `Record`<`string`, `any`>; `type`: `"file"`; } \| ( \| { `providerData?`: `Record`<`string`, `any`>; `text`: `string`; `type`: `"input_text"`; } \| { `detail?`: `string`; `image?`: \| `string` \| { `id`: `string`; }; `providerData?`: `Record`<`string`, `any`>; `type`: `"input_image"`; } \| { `file?`: \| `string` \| { `id`: `string`; } \| { `url`: `string`; }; `filename?`: `string`; `providerData?`: `Record`<`string`, `any`>; `type`: `"input_file"`; })\[] | The output of the tool call. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status` | `"in_progress"` \| `"completed"` \| `"incomplete"` | The status of the tool call. | | `type` | `"function_call_result"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-8) ```ts { action?: | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; }; actions?: ( | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; })[]; callId: string; id?: string; providerData?: Record; status: "in_progress" | "completed" | "incomplete"; type: "computer_call"; } ``` | Name | Type | Description | | --------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `action?` | \| { `type`: `"screenshot"`; } \| { `button`: `"left"` \| `"right"` \| `"wheel"` \| `"back"` \| `"forward"`; `type`: `"click"`; `x`: `number`; `y`: `number`; } \| { `type`: `"double_click"`; `x`: `number`; `y`: `number`; } \| { `scroll_x`: `number`; `scroll_y`: `number`; `type`: `"scroll"`; `x`: `number`; `y`: `number`; } \| { `text`: `string`; `type`: `"type"`; } \| { `type`: `"wait"`; } \| { `type`: `"move"`; `x`: `number`; `y`: `number`; } \| { `keys`: `string`\[]; `type`: `"keypress"`; } \| { `path`: `object`\[]; `type`: `"drag"`; } | The legacy single action to be performed by the computer. | | `actions?` | ( \| { `type`: `"screenshot"`; } \| { `button`: `"left"` \| `"right"` \| `"wheel"` \| `"back"` \| `"forward"`; `type`: `"click"`; `x`: `number`; `y`: `number`; } \| { `type`: `"double_click"`; `x`: `number`; `y`: `number`; } \| { `scroll_x`: `number`; `scroll_y`: `number`; `type`: `"scroll"`; `x`: `number`; `y`: `number`; } \| { `text`: `string`; `type`: `"type"`; } \| { `type`: `"wait"`; } \| { `type`: `"move"`; `x`: `number`; `y`: `number`; } \| { `keys`: `string`\[]; `type`: `"keypress"`; } \| { `path`: `object`\[]; `type`: `"drag"`; })\[] | Batched actions returned by the GA computer tool. | | `callId` | `string` | The ID of the computer call. Required to match up the respective computer call result. | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status` | `"in_progress"` \| `"completed"` \| `"incomplete"` | The status of the computer call. | | `type` | `"computer_call"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-9) ```ts { callId: string; id?: string; output: { data: string; providerData?: Record; type: "computer_screenshot"; }; providerData?: Record; type: "computer_call_result"; } ``` | Name | Type | Default value | Description | | ---------------------- | ------------------------- | -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `callId` | `string` | ‐ | The ID of the computer call. Required to match up the respective computer call result. | | `id?` | `string` | ‐ | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `output` | `object` | `ComputerToolOutput` | The output of the computer call. | | `output.data` | `string` | ‐ | A base64 encoded image data or a URL representing the screenshot. | | `output.providerData?` | `Record`<`string`, `any`> | ‐ | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `output.type` | `"computer_screenshot"` | ‐ | ‐ | | `providerData?` | `Record`<`string`, `any`> | ‐ | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `type` | `"computer_call_result"` | ‐ | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-10) ```ts { action: { commands: string[]; maxOutputLength?: number; timeoutMs?: number; }; callId: string; id?: string; providerData?: Record; status?: "in_progress" | "completed" | "incomplete"; type: "shell_call"; } ``` | Name | Type | Default value | Description | | ------------------------- | -------------------------------------------------- | ------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `action` | `object` | `ShellAction` | ‐ | | `action.commands` | `string`\[] | ‐ | ‐ | | `action.maxOutputLength?` | `number` | ‐ | ‐ | | `action.timeoutMs?` | `number` | ‐ | ‐ | | `callId` | `string` | ‐ | ‐ | | `id?` | `string` | ‐ | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `providerData?` | `Record`<`string`, `any`> | ‐ | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status?` | `"in_progress"` \| `"completed"` \| `"incomplete"` | ‐ | ‐ | | `type` | `"shell_call"` | ‐ | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-11) ```ts { callId: string; id?: string; maxOutputLength?: number; output: object[]; providerData?: Record; type: "shell_call_output"; } ``` | Name | Type | Description | | ------------------ | ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `callId` | `string` | ‐ | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `maxOutputLength?` | `number` | ‐ | | `output` | `object`\[] | ‐ | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `type` | `"shell_call_output"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-12) ```ts { callId: string; id?: string; operation: | { diff: string; path: string; type: "create_file"; } | { diff: string; moveTo?: string; path: string; type: "update_file"; } | { path: string; type: "delete_file"; }; providerData?: Record; status: "in_progress" | "completed"; type: "apply_patch_call"; } ``` | Name | Type | Default value | Description | | --------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `callId` | `string` | ‐ | ‐ | | `id?` | `string` | ‐ | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `operation` | \| { `diff`: `string`; `path`: `string`; `type`: `"create_file"`; } \| { `diff`: `string`; `moveTo?`: `string`; `path`: `string`; `type`: `"update_file"`; } \| { `path`: `string`; `type`: `"delete_file"`; } | `ApplyPatchOperation` | ‐ | | `providerData?` | `Record`<`string`, `any`> | ‐ | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status` | `"in_progress"` \| `"completed"` | ‐ | ‐ | | `type` | `"apply_patch_call"` | ‐ | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-13) ```ts { callId: string; id?: string; output?: string; providerData?: Record; status: "completed" | "failed"; type: "apply_patch_call_output"; } ``` | Name | Type | Description | | --------------- | --------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `callId` | `string` | ‐ | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `output?` | `string` | ‐ | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status` | `"completed"` \| `"failed"` | ‐ | | `type` | `"apply_patch_call_output"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-14) ```ts { content: object[]; id?: string; providerData?: Record; rawContent?: object[]; type: "reasoning"; } ``` | Name | Type | Description | | --------------- | ------------------------- | ------------------------------------------------------------------------------------------------------------- | | `content` | `object`\[] | The user facing representation of the reasoning. Additional information might be in the `providerData` field. | | `id?` | `string` | ‐ | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `rawContent?` | `object`\[] | The raw reasoning text from the model. | | `type` | `"reasoning"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-15) ```ts { created_by?: string; encrypted_content: string; id?: string; providerData?: Record; type: "compaction"; } ``` | Name | Type | Description | | ------------------- | ------------------------- | ------------------------------------------------------------------------------------------------------------ | | `created_by?` | `string` | Identifier for the generator of this compaction item. | | `encrypted_content` | `string` | Encrypted payload returned by the compaction endpoint. | | `id?` | `string` | Identifier for the compaction item. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `type` | `"compaction"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-16) ```ts { id?: string; providerData?: Record; type: "unknown"; } ``` | Name | Type | Description | | --------------- | ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `type` | `"unknown"` | ‐ | *** `undefined` ##### type [Section titled “type”](#type-1) ```ts type: string; ``` #### Overrides [Section titled “Overrides”](#overrides-2) ```ts RunItemBase.toJSON ``` # Runner Orchestrates agent execution, including guardrails, tool calls, session persistence, and tracing. Reuse a `Runner` instance when you want consistent configuration across multiple runs. ## Extends [Section titled “Extends”](#extends) * `RunHooks`<`any`, [`AgentOutputType`](/openai-agents-js/openai/agents-core/type-aliases/agentoutputtype/)<`unknown`>> ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new Runner(config?): Runner; ``` Creates a runner with optional defaults that apply to every subsequent run invocation. #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | --------- | -------------------------------------------------------------------------------------- | --------------------------------------------------------------- | | `config` | `Partial`<[`RunConfig`](/openai-agents-js/openai/agents-core/type-aliases/runconfig/)> | Overrides for models, guardrails, tracing, or session behavior. | #### Returns [Section titled “Returns”](#returns) `Runner` #### Overrides [Section titled “Overrides”](#overrides) ```ts RunHooks>.constructor ``` ## Properties [Section titled “Properties”](#properties) ### config [Section titled “config”](#config) ```ts readonly config: RunConfig; ``` ## Methods [Section titled “Methods”](#methods) ### emit() [Section titled “emit()”](#emit) ```ts emit(type, ...args): boolean; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | ---------------------------------------------------------------------------------------------------------------------------------------------- | | `K` *extends* keyof `RunHookEvents`<`any`, [`AgentOutputType`](/openai-agents-js/openai/agents-core/type-aliases/agentoutputtype/)<`unknown`>> | #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | --------- | -------------------------------------------------------------------------------------------------------------------------------- | | `type` | `K` | | …`args` | `RunHookEvents`<`any`, [`AgentOutputType`](/openai-agents-js/openai/agents-core/type-aliases/agentoutputtype/)<`unknown`>>\[`K`] | #### Returns [Section titled “Returns”](#returns-1) `boolean` #### Inherited from [Section titled “Inherited from”](#inherited-from) ```ts RunHooks.emit ``` *** ### off() [Section titled “off()”](#off) ```ts off(type, listener): EventEmitter>>; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-1) | Type Parameter | | ---------------------------------------------------------------------------------------------------------------------------------------------- | | `K` *extends* keyof `RunHookEvents`<`any`, [`AgentOutputType`](/openai-agents-js/openai/agents-core/type-aliases/agentoutputtype/)<`unknown`>> | #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | ---------- | ------------------- | | `type` | `K` | | `listener` | (…`args`) => `void` | #### Returns [Section titled “Returns”](#returns-2) `EventEmitter`<`RunHookEvents`<`any`, [`AgentOutputType`](/openai-agents-js/openai/agents-core/type-aliases/agentoutputtype/)<`unknown`>>> #### Inherited from [Section titled “Inherited from”](#inherited-from-1) ```ts RunHooks.off ``` *** ### on() [Section titled “on()”](#on) ```ts on(type, listener): EventEmitter>>; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-2) | Type Parameter | | ---------------------------------------------------------------------------------------------------------------------------------------------- | | `K` *extends* keyof `RunHookEvents`<`any`, [`AgentOutputType`](/openai-agents-js/openai/agents-core/type-aliases/agentoutputtype/)<`unknown`>> | #### Parameters [Section titled “Parameters”](#parameters-3) | Parameter | Type | | ---------- | ------------------- | | `type` | `K` | | `listener` | (…`args`) => `void` | #### Returns [Section titled “Returns”](#returns-3) `EventEmitter`<`RunHookEvents`<`any`, [`AgentOutputType`](/openai-agents-js/openai/agents-core/type-aliases/agentoutputtype/)<`unknown`>>> #### Inherited from [Section titled “Inherited from”](#inherited-from-2) ```ts RunHooks.on ``` *** ### once() [Section titled “once()”](#once) ```ts once(type, listener): EventEmitter>>; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-3) | Type Parameter | | ---------------------------------------------------------------------------------------------------------------------------------------------- | | `K` *extends* keyof `RunHookEvents`<`any`, [`AgentOutputType`](/openai-agents-js/openai/agents-core/type-aliases/agentoutputtype/)<`unknown`>> | #### Parameters [Section titled “Parameters”](#parameters-4) | Parameter | Type | | ---------- | ------------------- | | `type` | `K` | | `listener` | (…`args`) => `void` | #### Returns [Section titled “Returns”](#returns-4) `EventEmitter`<`RunHookEvents`<`any`, [`AgentOutputType`](/openai-agents-js/openai/agents-core/type-aliases/agentoutputtype/)<`unknown`>>> #### Inherited from [Section titled “Inherited from”](#inherited-from-3) ```ts RunHooks.once ``` *** ### run() [Section titled “run()”](#run) #### Call Signature [Section titled “Call Signature”](#call-signature) ```ts run( agent, input, options?): Promise>; ``` Run a workflow starting at the given agent. The agent will run in a loop until a final output is generated. The loop runs like so: 1. The agent is invoked with the given input. 2. If there is a final output (i.e. the agent produces something of type `agent.outputType`, the loop terminates. 3. If there’s a handoff, we run the loop again, with the new agent. 4. Else, we run tool calls (if any), and re-run the loop. In two cases, the agent may raise an exception: 1. If the maxTurns is exceeded, a MaxTurnsExceeded exception is raised unless handled. 2. If a guardrail tripwire is triggered, a GuardrailTripwireTriggered exception is raised. Note that only the first agent’s input guardrails are run. ##### Type Parameters [Section titled “Type Parameters”](#type-parameters-4) | Type Parameter | Default type | | ----------------------------------------------------------------------------------------------- | ------------ | | `TAgent` *extends* [`Agent`](/openai-agents-js/openai/agents-core/classes/agent/)<`any`, `any`> | ‐ | | `TContext` | `undefined` | ##### Parameters [Section titled “Parameters”](#parameters-5) | Parameter | Type | Description | | ---------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------ | | `agent` | `TAgent` | The starting agent to run. | | `input` | \| `string` \| [`AgentInputItem`](/openai-agents-js/openai/agents-core/type-aliases/agentinputitem/)\[] \| [`RunState`](/openai-agents-js/openai/agents-core/classes/runstate/)<`TContext`, `TAgent`> | The initial input to the agent. You can pass a string or an array of `AgentInputItem`. | | `options?` | [`NonStreamRunOptions`](/openai-agents-js/openai/agents-core/type-aliases/nonstreamrunoptions/)<`TContext`, `TAgent`> | Options for the run, including streaming behavior, execution context, and the maximum number of turns. | ##### Returns [Section titled “Returns”](#returns-5) `Promise`<[`RunResult`](/openai-agents-js/openai/agents-core/classes/runresult/)<`TContext`, `TAgent`>> The result of the run. #### Call Signature [Section titled “Call Signature”](#call-signature-1) ```ts run( agent, input, options?): Promise>; ``` Run a workflow starting at the given agent. The agent will run in a loop until a final output is generated. The loop runs like so: 1. The agent is invoked with the given input. 2. If there is a final output (i.e. the agent produces something of type `agent.outputType`, the loop terminates. 3. If there’s a handoff, we run the loop again, with the new agent. 4. Else, we run tool calls (if any), and re-run the loop. In two cases, the agent may raise an exception: 1. If the maxTurns is exceeded, a MaxTurnsExceeded exception is raised unless handled. 2. If a guardrail tripwire is triggered, a GuardrailTripwireTriggered exception is raised. Note that only the first agent’s input guardrails are run. ##### Type Parameters [Section titled “Type Parameters”](#type-parameters-5) | Type Parameter | Default type | | ----------------------------------------------------------------------------------------------- | ------------ | | `TAgent` *extends* [`Agent`](/openai-agents-js/openai/agents-core/classes/agent/)<`any`, `any`> | ‐ | | `TContext` | `undefined` | ##### Parameters [Section titled “Parameters”](#parameters-6) | Parameter | Type | Description | | ---------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------ | | `agent` | `TAgent` | The starting agent to run. | | `input` | \| `string` \| [`AgentInputItem`](/openai-agents-js/openai/agents-core/type-aliases/agentinputitem/)\[] \| [`RunState`](/openai-agents-js/openai/agents-core/classes/runstate/)<`TContext`, `TAgent`> | The initial input to the agent. You can pass a string or an array of `AgentInputItem`. | | `options?` | [`StreamRunOptions`](/openai-agents-js/openai/agents-core/type-aliases/streamrunoptions/)<`TContext`, `TAgent`> | Options for the run, including streaming behavior, execution context, and the maximum number of turns. | ##### Returns [Section titled “Returns”](#returns-6) `Promise`<[`StreamedRunResult`](/openai-agents-js/openai/agents-core/classes/streamedrunresult/)<`TContext`, `TAgent`>> The result of the run. # RunRawModelStreamEvent Streaming event from the LLM. These are `raw` events, i.e. they are directly passed through from the LLM. ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new RunRawModelStreamEvent(data, source?): RunRawModelStreamEvent; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | --------- | ------------------------------------------------------------------------------- | --------------------------------------------- | | `data` | [`StreamEvent`](/openai-agents-js/openai/agents-core/type-aliases/streamevent/) | The raw responses stream events from the LLM. | | `source` | `string` \| `undefined` | ‐ | #### Returns [Section titled “Returns”](#returns) `RunRawModelStreamEvent` ## Properties [Section titled “Properties”](#properties) ### data [Section titled “data”](#data) ```ts data: StreamEvent; ``` The raw responses stream events from the LLM. *** ### source [Section titled “source”](#source) ```ts readonly source: string | undefined; ``` *** ### type [Section titled “type”](#type) ```ts readonly type: "raw_model_stream_event" = 'raw_model_stream_event'; ``` The type of the event. # RunReasoningItem ## Extends [Section titled “Extends”](#extends) * `RunItemBase` ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new RunReasoningItem(rawItem, agent): RunReasoningItem; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------- | | `rawItem` | { `content`: `object`\[]; `id?`: `string`; `providerData?`: `Record`<`string`, `any`>; `rawContent?`: `object`\[]; `type`: `"reasoning"`; } | ‐ | | `rawItem.content` | `object`\[] | The user facing representation of the reasoning. Additional information might be in the `providerData` field. | | `rawItem.id?` | `string` | ‐ | | `rawItem.providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `rawItem.rawContent?` | `object`\[] | The raw reasoning text from the model. | | `rawItem.type` | `"reasoning"` | ‐ | | `agent` | [`Agent`](/openai-agents-js/openai/agents-core/classes/agent/) | ‐ | #### Returns [Section titled “Returns”](#returns) `RunReasoningItem` #### Overrides [Section titled “Overrides”](#overrides) ```ts RunItemBase.constructor ``` ## Properties [Section titled “Properties”](#properties) ### agent [Section titled “agent”](#agent) ```ts agent: Agent; ``` *** ### rawItem [Section titled “rawItem”](#rawitem) ```ts rawItem: object; ``` | Name | Type | Description | | --------------- | ------------------------- | ------------------------------------------------------------------------------------------------------------- | | `content` | `object`\[] | The user facing representation of the reasoning. Additional information might be in the `providerData` field. | | `id?` | `string` | ‐ | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `rawContent?` | `object`\[] | The raw reasoning text from the model. | | `type` | `"reasoning"` | ‐ | #### Inherited from [Section titled “Inherited from”](#inherited-from) ```ts RunItemBase.rawItem ``` *** ### type [Section titled “type”](#type) ```ts readonly type: "reasoning_item"; ``` #### Overrides [Section titled “Overrides”](#overrides-1) ```ts RunItemBase.type ``` ## Methods [Section titled “Methods”](#methods) ### toJSON() [Section titled “toJSON()”](#tojson) ```ts toJSON(): object; ``` #### Returns [Section titled “Returns”](#returns-1) `object` ##### agent [Section titled “agent”](#agent-1) ```ts agent: object; ``` ###### agent.name [Section titled “agent.name”](#agentname) ```ts name: string; ``` ##### rawItem [Section titled “rawItem”](#rawitem-1) ```ts rawItem: | { content: ( | { providerData?: Record; refusal: string; type: "refusal"; } | { providerData?: Record; text: string; type: "output_text"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; } | { image: string; providerData?: Record; type: "image"; })[]; id?: string; providerData?: Record; role: "assistant"; status: "in_progress" | "completed" | "incomplete"; type?: "message"; } | { content: | string | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; })[]; id?: string; providerData?: Record; role: "user"; type?: "message"; } | { content: string; id?: string; providerData?: Record; role: "system"; type?: "message"; } | { arguments?: string; id?: string; name: string; output?: string; providerData?: Record; status?: string; type: "hosted_tool_call"; } | { arguments: string; callId: string; id?: string; name: string; namespace?: string; providerData?: Record; status?: "in_progress" | "completed" | "incomplete"; type: "function_call"; } | { arguments: unknown; call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; type: "tool_search_call"; } | { call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; tools: Record[]; type: "tool_search_output"; } | { callId: string; id?: string; name: string; namespace?: string; output: | string | { providerData?: Record; text: string; type: "text"; } | { detail?: "low" | "high" | "auto" | string & object; image?: | string | { data: string | Uint8Array; mediaType?: string; } | { url: string; } | { fileId: string; }; providerData?: Record; type: "image"; } | { file: | string | { data: string | Uint8Array; filename: string; mediaType: string; } | { filename?: string; url: string; } | { filename?: string; id: string; }; providerData?: Record; type: "file"; } | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; })[]; providerData?: Record; status: "in_progress" | "completed" | "incomplete"; type: "function_call_result"; } | { action?: | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; }; actions?: ( | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; })[]; callId: string; id?: string; providerData?: Record; status: "in_progress" | "completed" | "incomplete"; type: "computer_call"; } | { callId: string; id?: string; output: { data: string; providerData?: Record; type: "computer_screenshot"; }; providerData?: Record; type: "computer_call_result"; } | { action: { commands: string[]; maxOutputLength?: number; timeoutMs?: number; }; callId: string; id?: string; providerData?: Record; status?: "in_progress" | "completed" | "incomplete"; type: "shell_call"; } | { callId: string; id?: string; maxOutputLength?: number; output: object[]; providerData?: Record; type: "shell_call_output"; } | { callId: string; id?: string; operation: | { diff: string; path: string; type: "create_file"; } | { diff: string; moveTo?: string; path: string; type: "update_file"; } | { path: string; type: "delete_file"; }; providerData?: Record; status: "in_progress" | "completed"; type: "apply_patch_call"; } | { callId: string; id?: string; output?: string; providerData?: Record; status: "completed" | "failed"; type: "apply_patch_call_output"; } | { content: object[]; id?: string; providerData?: Record; rawContent?: object[]; type: "reasoning"; } | { created_by?: string; encrypted_content: string; id?: string; providerData?: Record; type: "compaction"; } | { id?: string; providerData?: Record; type: "unknown"; } | undefined; ``` ###### Union Members [Section titled “Union Members”](#union-members) ###### Type Literal [Section titled “Type Literal”](#type-literal) ```ts { content: ( | { providerData?: Record; refusal: string; type: "refusal"; } | { providerData?: Record; text: string; type: "output_text"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; } | { image: string; providerData?: Record; type: "image"; })[]; id?: string; providerData?: Record; role: "assistant"; status: "in_progress" | "completed" | "incomplete"; type?: "message"; } ``` | Name | Type | Description | | --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `content` | ( \| { `providerData?`: `Record`<`string`, `any`>; `refusal`: `string`; `type`: `"refusal"`; } \| { `providerData?`: `Record`<`string`, `any`>; `text`: `string`; `type`: `"output_text"`; } \| { `audio`: \| `string` \| { `id`: `string`; }; `format?`: `string` \| `null`; `providerData?`: `Record`<`string`, `any`>; `transcript?`: `string` \| `null`; `type`: `"audio"`; } \| { `image`: `string`; `providerData?`: `Record`<`string`, `any`>; `type`: `"image"`; })\[] | The content of the message. | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `role` | `"assistant"` | Representing a message from the assistant (i.e. the model) | | `status` | `"in_progress"` \| `"completed"` \| `"incomplete"` | The status of the message. | | `type?` | `"message"` | Any item without a type is treated as a message | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-1) ```ts { content: | string | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; })[]; id?: string; providerData?: Record; role: "user"; type?: "message"; } ``` | Name | Type | Description | | --------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `content` | \| `string` \| ( \| { `providerData?`: `Record`<`string`, `any`>; `text`: `string`; `type`: `"input_text"`; } \| { `detail?`: `string`; `image?`: \| `string` \| { `id`: `string`; }; `providerData?`: `Record`<`string`, `any`>; `type`: `"input_image"`; } \| { `file?`: \| `string` \| { `id`: `string`; } \| { `url`: `string`; }; `filename?`: `string`; `providerData?`: `Record`<`string`, `any`>; `type`: `"input_file"`; } \| { `audio`: \| `string` \| { `id`: `string`; }; `format?`: `string` \| `null`; `providerData?`: `Record`<`string`, `any`>; `transcript?`: `string` \| `null`; `type`: `"audio"`; })\[] | The content of the message. | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `role` | `"user"` | Representing a message from the user | | `type?` | `"message"` | Any item without a type is treated as a message | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-2) ```ts { content: string; id?: string; providerData?: Record; role: "system"; type?: "message"; } ``` | Name | Type | Description | | --------------- | ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `content` | `string` | The content of the message. | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `role` | `"system"` | Representing a system message to the user | | `type?` | `"message"` | Any item without a type is treated as a message | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-3) ```ts { arguments?: string; id?: string; name: string; output?: string; providerData?: Record; status?: string; type: "hosted_tool_call"; } ``` | Name | Type | Description | | --------------- | ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `arguments?` | `string` | The arguments of the hosted tool call. | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `name` | `string` | The name of the hosted tool. For example `web_search_call` or `file_search_call` | | `output?` | `string` | The primary output of the tool call. Additional output might be in the `providerData` field. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status?` | `string` | The status of the tool call. | | `type` | `"hosted_tool_call"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-4) ```ts { arguments: string; callId: string; id?: string; name: string; namespace?: string; providerData?: Record; status?: "in_progress" | "completed" | "incomplete"; type: "function_call"; } ``` | Name | Type | Description | | --------------- | -------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `arguments` | `string` | The arguments of the function call. | | `callId` | `string` | The ID of the tool call. Required to match up the respective tool call result. | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `name` | `string` | The name of the function. | | `namespace?` | `string` | Optional namespace used to qualify the function name for tool search. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status?` | `"in_progress"` \| `"completed"` \| `"incomplete"` | The status of the function call. | | `type` | `"function_call"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-5) ```ts { arguments: unknown; call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; type: "tool_search_call"; } ``` | Name | Type | Default value | Description | | --------------- | ------------------------- | ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `arguments` | `unknown` | `ToolSearchCallArguments` | ‐ | | `call_id?` | `string` \| `null` | ‐ | ‐ | | `callId?` | `string` \| `null` | ‐ | ‐ | | `execution?` | `"client"` \| `"server"` | ‐ | ‐ | | `id?` | `string` | ‐ | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `providerData?` | `Record`<`string`, `any`> | ‐ | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status?` | `string` | ‐ | ‐ | | `type` | `"tool_search_call"` | ‐ | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-6) ```ts { call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; tools: Record[]; type: "tool_search_output"; } ``` | Name | Type | Description | | --------------- | ---------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `call_id?` | `string` \| `null` | ‐ | | `callId?` | `string` \| `null` | ‐ | | `execution?` | `"client"` \| `"server"` | ‐ | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status?` | `string` | ‐ | | `tools` | `Record`<`string`, `any`>\[] | ‐ | | `type` | `"tool_search_output"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-7) ```ts { callId: string; id?: string; name: string; namespace?: string; output: | string | { providerData?: Record; text: string; type: "text"; } | { detail?: "low" | "high" | "auto" | string & object; image?: | string | { data: string | Uint8Array; mediaType?: string; } | { url: string; } | { fileId: string; }; providerData?: Record; type: "image"; } | { file: | string | { data: string | Uint8Array; filename: string; mediaType: string; } | { filename?: string; url: string; } | { filename?: string; id: string; }; providerData?: Record; type: "file"; } | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; })[]; providerData?: Record; status: "in_progress" | "completed" | "incomplete"; type: "function_call_result"; } ``` | Name | Type | Description | | --------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `callId` | `string` | The ID of the tool call. Required to match up the respective tool call result. | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `name` | `string` | The name of the tool that was called | | `namespace?` | `string` | Optional namespace preserved from the originating function call. | | `output` | \| `string` \| { `providerData?`: `Record`<`string`, `any`>; `text`: `string`; `type`: `"text"`; } \| { `detail?`: `"low"` \| `"high"` \| `"auto"` \| `string` & `object`; `image?`: \| `string` \| { `data`: `string` \| `Uint8Array`<`ArrayBuffer`>; `mediaType?`: `string`; } \| { `url`: `string`; } \| { `fileId`: `string`; }; `providerData?`: `Record`<`string`, `any`>; `type`: `"image"`; } \| { `file`: \| `string` \| { `data`: `string` \| `Uint8Array`<`ArrayBuffer`>; `filename`: `string`; `mediaType`: `string`; } \| { `filename?`: `string`; `url`: `string`; } \| { `filename?`: `string`; `id`: `string`; }; `providerData?`: `Record`<`string`, `any`>; `type`: `"file"`; } \| ( \| { `providerData?`: `Record`<`string`, `any`>; `text`: `string`; `type`: `"input_text"`; } \| { `detail?`: `string`; `image?`: \| `string` \| { `id`: `string`; }; `providerData?`: `Record`<`string`, `any`>; `type`: `"input_image"`; } \| { `file?`: \| `string` \| { `id`: `string`; } \| { `url`: `string`; }; `filename?`: `string`; `providerData?`: `Record`<`string`, `any`>; `type`: `"input_file"`; })\[] | The output of the tool call. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status` | `"in_progress"` \| `"completed"` \| `"incomplete"` | The status of the tool call. | | `type` | `"function_call_result"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-8) ```ts { action?: | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; }; actions?: ( | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; })[]; callId: string; id?: string; providerData?: Record; status: "in_progress" | "completed" | "incomplete"; type: "computer_call"; } ``` | Name | Type | Description | | --------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `action?` | \| { `type`: `"screenshot"`; } \| { `button`: `"left"` \| `"right"` \| `"wheel"` \| `"back"` \| `"forward"`; `type`: `"click"`; `x`: `number`; `y`: `number`; } \| { `type`: `"double_click"`; `x`: `number`; `y`: `number`; } \| { `scroll_x`: `number`; `scroll_y`: `number`; `type`: `"scroll"`; `x`: `number`; `y`: `number`; } \| { `text`: `string`; `type`: `"type"`; } \| { `type`: `"wait"`; } \| { `type`: `"move"`; `x`: `number`; `y`: `number`; } \| { `keys`: `string`\[]; `type`: `"keypress"`; } \| { `path`: `object`\[]; `type`: `"drag"`; } | The legacy single action to be performed by the computer. | | `actions?` | ( \| { `type`: `"screenshot"`; } \| { `button`: `"left"` \| `"right"` \| `"wheel"` \| `"back"` \| `"forward"`; `type`: `"click"`; `x`: `number`; `y`: `number`; } \| { `type`: `"double_click"`; `x`: `number`; `y`: `number`; } \| { `scroll_x`: `number`; `scroll_y`: `number`; `type`: `"scroll"`; `x`: `number`; `y`: `number`; } \| { `text`: `string`; `type`: `"type"`; } \| { `type`: `"wait"`; } \| { `type`: `"move"`; `x`: `number`; `y`: `number`; } \| { `keys`: `string`\[]; `type`: `"keypress"`; } \| { `path`: `object`\[]; `type`: `"drag"`; })\[] | Batched actions returned by the GA computer tool. | | `callId` | `string` | The ID of the computer call. Required to match up the respective computer call result. | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status` | `"in_progress"` \| `"completed"` \| `"incomplete"` | The status of the computer call. | | `type` | `"computer_call"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-9) ```ts { callId: string; id?: string; output: { data: string; providerData?: Record; type: "computer_screenshot"; }; providerData?: Record; type: "computer_call_result"; } ``` | Name | Type | Default value | Description | | ---------------------- | ------------------------- | -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `callId` | `string` | ‐ | The ID of the computer call. Required to match up the respective computer call result. | | `id?` | `string` | ‐ | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `output` | `object` | `ComputerToolOutput` | The output of the computer call. | | `output.data` | `string` | ‐ | A base64 encoded image data or a URL representing the screenshot. | | `output.providerData?` | `Record`<`string`, `any`> | ‐ | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `output.type` | `"computer_screenshot"` | ‐ | ‐ | | `providerData?` | `Record`<`string`, `any`> | ‐ | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `type` | `"computer_call_result"` | ‐ | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-10) ```ts { action: { commands: string[]; maxOutputLength?: number; timeoutMs?: number; }; callId: string; id?: string; providerData?: Record; status?: "in_progress" | "completed" | "incomplete"; type: "shell_call"; } ``` | Name | Type | Default value | Description | | ------------------------- | -------------------------------------------------- | ------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `action` | `object` | `ShellAction` | ‐ | | `action.commands` | `string`\[] | ‐ | ‐ | | `action.maxOutputLength?` | `number` | ‐ | ‐ | | `action.timeoutMs?` | `number` | ‐ | ‐ | | `callId` | `string` | ‐ | ‐ | | `id?` | `string` | ‐ | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `providerData?` | `Record`<`string`, `any`> | ‐ | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status?` | `"in_progress"` \| `"completed"` \| `"incomplete"` | ‐ | ‐ | | `type` | `"shell_call"` | ‐ | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-11) ```ts { callId: string; id?: string; maxOutputLength?: number; output: object[]; providerData?: Record; type: "shell_call_output"; } ``` | Name | Type | Description | | ------------------ | ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `callId` | `string` | ‐ | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `maxOutputLength?` | `number` | ‐ | | `output` | `object`\[] | ‐ | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `type` | `"shell_call_output"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-12) ```ts { callId: string; id?: string; operation: | { diff: string; path: string; type: "create_file"; } | { diff: string; moveTo?: string; path: string; type: "update_file"; } | { path: string; type: "delete_file"; }; providerData?: Record; status: "in_progress" | "completed"; type: "apply_patch_call"; } ``` | Name | Type | Default value | Description | | --------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `callId` | `string` | ‐ | ‐ | | `id?` | `string` | ‐ | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `operation` | \| { `diff`: `string`; `path`: `string`; `type`: `"create_file"`; } \| { `diff`: `string`; `moveTo?`: `string`; `path`: `string`; `type`: `"update_file"`; } \| { `path`: `string`; `type`: `"delete_file"`; } | `ApplyPatchOperation` | ‐ | | `providerData?` | `Record`<`string`, `any`> | ‐ | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status` | `"in_progress"` \| `"completed"` | ‐ | ‐ | | `type` | `"apply_patch_call"` | ‐ | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-13) ```ts { callId: string; id?: string; output?: string; providerData?: Record; status: "completed" | "failed"; type: "apply_patch_call_output"; } ``` | Name | Type | Description | | --------------- | --------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `callId` | `string` | ‐ | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `output?` | `string` | ‐ | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status` | `"completed"` \| `"failed"` | ‐ | | `type` | `"apply_patch_call_output"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-14) ```ts { content: object[]; id?: string; providerData?: Record; rawContent?: object[]; type: "reasoning"; } ``` | Name | Type | Description | | --------------- | ------------------------- | ------------------------------------------------------------------------------------------------------------- | | `content` | `object`\[] | The user facing representation of the reasoning. Additional information might be in the `providerData` field. | | `id?` | `string` | ‐ | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `rawContent?` | `object`\[] | The raw reasoning text from the model. | | `type` | `"reasoning"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-15) ```ts { created_by?: string; encrypted_content: string; id?: string; providerData?: Record; type: "compaction"; } ``` | Name | Type | Description | | ------------------- | ------------------------- | ------------------------------------------------------------------------------------------------------------ | | `created_by?` | `string` | Identifier for the generator of this compaction item. | | `encrypted_content` | `string` | Encrypted payload returned by the compaction endpoint. | | `id?` | `string` | Identifier for the compaction item. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `type` | `"compaction"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-16) ```ts { id?: string; providerData?: Record; type: "unknown"; } ``` | Name | Type | Description | | --------------- | ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `type` | `"unknown"` | ‐ | *** `undefined` ##### type [Section titled “type”](#type-1) ```ts type: string; ``` #### Overrides [Section titled “Overrides”](#overrides-2) ```ts RunItemBase.toJSON ``` # RunResult The result of an agent run. ## Extends [Section titled “Extends”](#extends) * `RunResultBase`<`TContext`, `TAgent`> ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `TContext` | | `TAgent` *extends* [`Agent`](/openai-agents-js/openai/agents-core/classes/agent/)<`TContext`, [`AgentOutputType`](/openai-agents-js/openai/agents-core/type-aliases/agentoutputtype/)> | ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new RunResult(state): RunResult; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ------------------------------------------------------------------------------------------ | | `state` | [`RunState`](/openai-agents-js/openai/agents-core/classes/runstate/)<`TContext`, `TAgent`> | #### Returns [Section titled “Returns”](#returns) `RunResult`<`TContext`, `TAgent`> #### Overrides [Section titled “Overrides”](#overrides) ```ts RunResultBase.constructor ``` ## Properties [Section titled “Properties”](#properties) ### state [Section titled “state”](#state) ```ts readonly state: RunState; ``` The state of the run. #### Inherited from [Section titled “Inherited from”](#inherited-from) ```ts RunResultBase.state ``` ## Accessors [Section titled “Accessors”](#accessors) ### activeAgent [Section titled “activeAgent”](#activeagent) #### Get Signature [Section titled “Get Signature”](#get-signature) ```ts get activeAgent(): TAgent | undefined; ``` The agent that should handle the next turn. This is an alias for the last agent that completed a turn. ##### Returns [Section titled “Returns”](#returns-1) `TAgent` | `undefined` #### Inherited from [Section titled “Inherited from”](#inherited-from-1) ```ts RunResultBase.activeAgent ``` *** ### agentToolInvocation [Section titled “agentToolInvocation”](#agenttoolinvocation) #### Get Signature [Section titled “Get Signature”](#get-signature-1) ```ts get agentToolInvocation(): | Readonly<{ toolArguments?: string; toolCallId?: string; toolName: string; }> | undefined; ``` Metadata about the nested `Agent.asTool()` invocation that produced this result, when applicable. ##### Returns [Section titled “Returns”](#returns-2) \| `Readonly`<{ `toolArguments?`: `string`; `toolCallId?`: `string`; `toolName`: `string`; }> | `undefined` #### Inherited from [Section titled “Inherited from”](#inherited-from-2) ```ts RunResultBase.agentToolInvocation ``` *** ### finalOutput [Section titled “finalOutput”](#finaloutput) #### Get Signature [Section titled “Get Signature”](#get-signature-2) ```ts get finalOutput(): ResolvedAgentOutput | undefined; ``` The final output of the agent. If the output type was set to anything other than `text`, this will be parsed either as JSON or using the Zod schema you provided. ##### Returns [Section titled “Returns”](#returns-3) `ResolvedAgentOutput`<`TAgent`\[`"outputType"`]> | `undefined` #### Inherited from [Section titled “Inherited from”](#inherited-from-3) ```ts RunResultBase.finalOutput ``` *** ### history [Section titled “history”](#history) #### Get Signature [Section titled “Get Signature”](#get-signature-3) ```ts get history(): AgentInputItem[]; ``` The history of the agent run. This includes the input items and the new items generated during the agent run. This can be used as inputs for the next agent run. ##### Returns [Section titled “Returns”](#returns-4) [`AgentInputItem`](/openai-agents-js/openai/agents-core/type-aliases/agentinputitem/)\[] #### Inherited from [Section titled “Inherited from”](#inherited-from-4) ```ts RunResultBase.history ``` *** ### input [Section titled “input”](#input) #### Get Signature [Section titled “Get Signature”](#get-signature-4) ```ts get input(): | string | AgentInputItem[]; ``` A copy of the original input items. ##### Returns [Section titled “Returns”](#returns-5) \| `string` | [`AgentInputItem`](/openai-agents-js/openai/agents-core/type-aliases/agentinputitem/)\[] #### Inherited from [Section titled “Inherited from”](#inherited-from-5) ```ts RunResultBase.input ``` *** ### inputGuardrailResults [Section titled “inputGuardrailResults”](#inputguardrailresults) #### Get Signature [Section titled “Get Signature”](#get-signature-5) ```ts get inputGuardrailResults(): InputGuardrailResult[]; ``` Guardrail results for the input messages. ##### Returns [Section titled “Returns”](#returns-6) [`InputGuardrailResult`](/openai-agents-js/openai/agents-core/interfaces/inputguardrailresult/)\[] #### Inherited from [Section titled “Inherited from”](#inherited-from-6) ```ts RunResultBase.inputGuardrailResults ``` *** ### interruptions [Section titled “interruptions”](#interruptions) #### Get Signature [Section titled “Get Signature”](#get-signature-6) ```ts get interruptions(): RunToolApprovalItem[]; ``` Any interruptions that occurred during the agent run for example for tool approvals. ##### Returns [Section titled “Returns”](#returns-7) [`RunToolApprovalItem`](/openai-agents-js/openai/agents-core/classes/runtoolapprovalitem/)\[] #### Inherited from [Section titled “Inherited from”](#inherited-from-7) ```ts RunResultBase.interruptions ``` *** ### lastAgent [Section titled “lastAgent”](#lastagent) #### Get Signature [Section titled “Get Signature”](#get-signature-7) ```ts get lastAgent(): TAgent | undefined; ``` The last agent that was run ##### Returns [Section titled “Returns”](#returns-8) `TAgent` | `undefined` #### Inherited from [Section titled “Inherited from”](#inherited-from-8) ```ts RunResultBase.lastAgent ``` *** ### lastResponseId [Section titled “lastResponseId”](#lastresponseid) #### Get Signature [Section titled “Get Signature”](#get-signature-8) ```ts get lastResponseId(): string | undefined; ``` The last response ID generated by the model during the agent run. ##### Returns [Section titled “Returns”](#returns-9) `string` | `undefined` #### Inherited from [Section titled “Inherited from”](#inherited-from-9) ```ts RunResultBase.lastResponseId ``` *** ### newItems [Section titled “newItems”](#newitems) #### Get Signature [Section titled “Get Signature”](#get-signature-9) ```ts get newItems(): RunItem[]; ``` The run items generated during the agent run. This associates the model data with the agents. For the model data that can be used as inputs for the next agent run, use the `output` property. ##### Returns [Section titled “Returns”](#returns-10) [`RunItem`](/openai-agents-js/openai/agents-core/type-aliases/runitem/)\[] #### Inherited from [Section titled “Inherited from”](#inherited-from-10) ```ts RunResultBase.newItems ``` *** ### output [Section titled “output”](#output) #### Get Signature [Section titled “Get Signature”](#get-signature-10) ```ts get output(): AgentOutputItem[]; ``` The new items generated during the agent run. These include things like new messages, tool calls and their outputs, etc. It does not include information about the agents and instead represents the model data. For the output including the agents, use the `newItems` property. ##### Returns [Section titled “Returns”](#returns-11) [`AgentOutputItem`](/openai-agents-js/openai/agents-core/type-aliases/agentoutputitem/)\[] #### Inherited from [Section titled “Inherited from”](#inherited-from-11) ```ts RunResultBase.output ``` *** ### outputGuardrailResults [Section titled “outputGuardrailResults”](#outputguardrailresults) #### Get Signature [Section titled “Get Signature”](#get-signature-11) ```ts get outputGuardrailResults(): OutputGuardrailResult[]; ``` Guardrail results for the final output of the agent. ##### Returns [Section titled “Returns”](#returns-12) [`OutputGuardrailResult`](/openai-agents-js/openai/agents-core/interfaces/outputguardrailresult/)<[`OutputGuardrailMetadata`](/openai-agents-js/openai/agents-core/interfaces/outputguardrailmetadata/), `"text"`>\[] #### Inherited from [Section titled “Inherited from”](#inherited-from-12) ```ts RunResultBase.outputGuardrailResults ``` *** ### rawResponses [Section titled “rawResponses”](#rawresponses) #### Get Signature [Section titled “Get Signature”](#get-signature-12) ```ts get rawResponses(): ModelResponse[]; ``` The raw LLM responses generated by the model during the agent run. ##### Returns [Section titled “Returns”](#returns-13) [`ModelResponse`](/openai-agents-js/openai/agents-core/type-aliases/modelresponse/)\[] #### Inherited from [Section titled “Inherited from”](#inherited-from-13) ```ts RunResultBase.rawResponses ``` *** ### runContext [Section titled “runContext”](#runcontext) #### Get Signature [Section titled “Get Signature”](#get-signature-13) ```ts get runContext(): RunContext; ``` The public run context for this run. ##### Returns [Section titled “Returns”](#returns-14) [`RunContext`](/openai-agents-js/openai/agents-core/classes/runcontext/)<`TContext`> #### Inherited from [Section titled “Inherited from”](#inherited-from-14) ```ts RunResultBase.runContext ``` *** ### toolInputGuardrailResults [Section titled “toolInputGuardrailResults”](#toolinputguardrailresults) #### Get Signature [Section titled “Get Signature”](#get-signature-14) ```ts get toolInputGuardrailResults(): ToolInputGuardrailResult[]; ``` Guardrail results for tool inputs. ##### Returns [Section titled “Returns”](#returns-15) [`ToolInputGuardrailResult`](/openai-agents-js/openai/agents-core/interfaces/toolinputguardrailresult/)\[] #### Inherited from [Section titled “Inherited from”](#inherited-from-15) ```ts RunResultBase.toolInputGuardrailResults ``` *** ### toolOutputGuardrailResults [Section titled “toolOutputGuardrailResults”](#tooloutputguardrailresults) #### Get Signature [Section titled “Get Signature”](#get-signature-15) ```ts get toolOutputGuardrailResults(): ToolOutputGuardrailResult[]; ``` Guardrail results for tool outputs. ##### Returns [Section titled “Returns”](#returns-16) [`ToolOutputGuardrailResult`](/openai-agents-js/openai/agents-core/interfaces/tooloutputguardrailresult/)\[] #### Inherited from [Section titled “Inherited from”](#inherited-from-16) ```ts RunResultBase.toolOutputGuardrailResults ``` # RunState Serializable snapshot of an agent’s run, including context, usage and trace. While this class has publicly writable properties (prefixed with `_`), they are not meant to be used directly. To read these properties, use the `RunResult` instead. Manipulation of the state directly can lead to unexpected behavior and should be avoided. Instead, use the `approve` and `reject` methods to interact with the state. ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | ----------------------------------------------------------------------------------------------- | | `TContext` | | `TAgent` *extends* [`Agent`](/openai-agents-js/openai/agents-core/classes/agent/)<`any`, `any`> | ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new RunState( context, originalInput, startingAgent, maxTurns): RunState; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------------- | ------------------------------------------------------------------------------------------------------- | | `context` | [`RunContext`](/openai-agents-js/openai/agents-core/classes/runcontext/)<`TContext`> | | `originalInput` | \| `string` \| [`AgentInputItem`](/openai-agents-js/openai/agents-core/type-aliases/agentinputitem/)\[] | | `startingAgent` | `TAgent` | | `maxTurns` | `number` \| `null` | #### Returns [Section titled “Returns”](#returns) `RunState`<`TContext`, `TAgent`> ## Properties [Section titled “Properties”](#properties) ### \_agentToolInvocation [Section titled “\_agentToolInvocation”](#_agenttoolinvocation) ```ts _agentToolInvocation: | Readonly<{ toolArguments?: string; toolCallId?: string; toolName: string; }> | undefined; ``` Runtime-only metadata for the current nested agent-tool invocation. *** ### \_context [Section titled “\_context”](#_context) ```ts _context: RunContext; ``` Run context tracking approvals, usage, and other metadata. *** ### \_conversationId [Section titled “\_conversationId”](#_conversationid) ```ts _conversationId: string | undefined; ``` Conversation identifier when the server manages conversation history. *** ### \_currentAgent [Section titled “\_currentAgent”](#_currentagent) ```ts _currentAgent: TAgent; ``` The agent currently handling the conversation. *** ### \_currentAgentSpan [Section titled “\_currentAgentSpan”](#_currentagentspan) ```ts _currentAgentSpan: | Span | undefined; ``` Active tracing span for the current agent if tracing is enabled. *** ### \_currentStep [Section titled “\_currentStep”](#_currentstep) ```ts _currentStep: | { newAgent: any; type: "next_step_handoff"; } | { output: string; type: "next_step_final_output"; } | { type: "next_step_run_again"; } | { data: Record; type: "next_step_interruption"; } | undefined = undefined; ``` Next step computed for the agent to take. *** ### \_currentTurn [Section titled “\_currentTurn”](#_currentturn) ```ts _currentTurn: number = 0; ``` Current turn number in the conversation. *** ### \_currentTurnInProgress [Section titled “\_currentTurnInProgress”](#_currentturninprogress) ```ts _currentTurnInProgress: boolean = false; ``` Whether the current turn has already been counted (useful when resuming mid-turn). *** ### \_currentTurnPersistedItemCount [Section titled “\_currentTurnPersistedItemCount”](#_currentturnpersisteditemcount) ```ts _currentTurnPersistedItemCount: number; ``` Number of `_generatedItems` already flushed to session storage for the current turn. Persisting the entire turn on every save would duplicate responses and tool outputs. Instead, `saveToSession` appends only the delta since the previous write. This counter tracks how many generated run items from *this turn* were already written so the next save can slice off only the new entries. When a turn is interrupted (e.g., awaiting tool approval) and later resumed, we rewind the counter before continuing so the pending tool output still gets stored. *** ### \_finalOutputSource [Section titled “\_finalOutputSource”](#_finaloutputsource) ```ts _finalOutputSource: FinalOutputSource | undefined; ``` Indicates how the final output was produced for the current run. This value is not serialized. *** ### \_generatedItems [Section titled “\_generatedItems”](#_generateditems) ```ts _generatedItems: RunItem[]; ``` Items generated by the agent during the run. *** ### \_inputGuardrailResults [Section titled “\_inputGuardrailResults”](#_inputguardrailresults) ```ts _inputGuardrailResults: InputGuardrailResult[]; ``` Results from input guardrails applied to the run. *** ### \_lastModelSettings [Section titled “\_lastModelSettings”](#_lastmodelsettings) ```ts _lastModelSettings: | ModelSettings | undefined; ``` Effective model settings used for the most recent model call. *** ### \_lastProcessedResponse [Section titled “\_lastProcessedResponse”](#_lastprocessedresponse) ```ts _lastProcessedResponse: ProcessedResponse | undefined = undefined; ``` Parsed model response after applying guardrails and tools. *** ### \_lastTurnResponse [Section titled “\_lastTurnResponse”](#_lastturnresponse) ```ts _lastTurnResponse: | ModelResponse | undefined; ``` Last model response for the previous turn. *** ### \_maxTurns [Section titled “\_maxTurns”](#_maxturns) ```ts _maxTurns: number | null; ``` Maximum allowed turns before forcing termination. *** ### \_modelResponses [Section titled “\_modelResponses”](#_modelresponses) ```ts _modelResponses: ModelResponse[]; ``` Responses from the model so far. *** ### \_noActiveAgentRun [Section titled “\_noActiveAgentRun”](#_noactiveagentrun) ```ts _noActiveAgentRun: boolean = true; ``` Whether the run has an active agent step in progress. *** ### \_originalInput [Section titled “\_originalInput”](#_originalinput) ```ts _originalInput: | string | AgentInputItem[]; ``` Original user input prior to any processing. *** ### \_outputGuardrailResults [Section titled “\_outputGuardrailResults”](#_outputguardrailresults) ```ts _outputGuardrailResults: OutputGuardrailResult[]; ``` Results from output guardrails applied to the run. *** ### \_pendingAgentToolRuns [Section titled “\_pendingAgentToolRuns”](#_pendingagenttoolruns) ```ts _pendingAgentToolRuns: Map; ``` Serialized pending nested agent runs keyed by tool name and call id. *** ### \_previousResponseId [Section titled “\_previousResponseId”](#_previousresponseid) ```ts _previousResponseId: string | undefined; ``` Latest response identifier returned by the server for server-managed conversations. *** ### \_reasoningItemIdPolicy [Section titled “\_reasoningItemIdPolicy”](#_reasoningitemidpolicy) ```ts _reasoningItemIdPolicy: | ReasoningItemIdPolicy | undefined; ``` Runtime options that control how run items are converted into model turn input. This value is serialized so resumed runs keep the same turn-input behavior. *** ### \_sandbox [Section titled “\_sandbox”](#_sandbox) ```ts _sandbox: | { backendId: string; currentAgentKey: string; currentAgentName: string; sessionsByAgent: Record; manifest: Record; providerState: Record; snapshot?: Record | null; snapshotFingerprint?: string | null; snapshotFingerprintVersion?: string | null; version: 1; workspaceReady: boolean; }; }>; sessionState: { backendId: string; exposedPorts?: Record; manifest: Record; providerState: Record; snapshot?: Record | null; snapshotFingerprint?: string | null; snapshotFingerprintVersion?: string | null; version: 1; workspaceReady: boolean; }; } | undefined = undefined; ``` Persisted sandbox session metadata for sandbox-agent resume. *** ### \_toolInputGuardrailResults [Section titled “\_toolInputGuardrailResults”](#_toolinputguardrailresults) ```ts _toolInputGuardrailResults: ToolInputGuardrailResult[]; ``` Results from tool input guardrails applied during tool execution. *** ### \_toolOutputGuardrailResults [Section titled “\_toolOutputGuardrailResults”](#_tooloutputguardrailresults) ```ts _toolOutputGuardrailResults: ToolOutputGuardrailResult[]; ``` Results from tool output guardrails applied during tool execution. *** ### \_toolSearchRuntimeToolsByAgent [Section titled “\_toolSearchRuntimeToolsByAgent”](#_toolsearchruntimetoolsbyagent) ```ts _toolSearchRuntimeToolsByAgent: Map, ToolSearchRuntimeToolState>; ``` Runtime-only tool\_search-loaded tools, scoped by agent object and preserved across turns for the lifetime of this in-memory run. *** ### \_toolUseTracker [Section titled “\_toolUseTracker”](#_toolusetracker) ```ts _toolUseTracker: AgentToolUseTracker; ``` Tracks what tools each agent has used. *** ### \_trace [Section titled “\_trace”](#_trace) ```ts _trace: Trace | null = null; ``` Trace associated with this run if tracing is enabled. ## Accessors [Section titled “Accessors”](#accessors) ### currentAgent [Section titled “currentAgent”](#currentagent) #### Get Signature [Section titled “Get Signature”](#get-signature) ```ts get currentAgent(): TAgent; ``` Returns the agent currently handling the run. ##### Returns [Section titled “Returns”](#returns-1) `TAgent` *** ### history [Section titled “history”](#history) #### Get Signature [Section titled “Get Signature”](#get-signature-1) ```ts get history(): AgentInputItem[]; ``` The history of the agent run. This includes the input items and the new items generated during the run. This can be used as inputs for the next agent run. ##### Returns [Section titled “Returns”](#returns-2) [`AgentInputItem`](/openai-agents-js/openai/agents-core/type-aliases/agentinputitem/)\[] *** ### usage [Section titled “usage”](#usage) #### Get Signature [Section titled “Get Signature”](#get-signature-2) ```ts get usage(): Usage; ``` The usage aggregated for this run. This includes per-request breakdowns when available. ##### Returns [Section titled “Returns”](#returns-3) [`Usage`](/openai-agents-js/openai/agents-core/classes/usage/) ## Methods [Section titled “Methods”](#methods) ### approve() [Section titled “approve()”](#approve) ```ts approve(approvalItem, options?): void; ``` Approves a tool call requested by the agent through an interruption and approval item request. To approve the request use this method and then run the agent again with the same state object to continue the execution. By default it will only approve the current tool call. To allow the tool to be used multiple times throughout the run, set the `alwaysApprove` option to `true`. #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | Description | | ------------------------ | ------------------------------------------------------------------------------------------ | --------------------------------------------------- | | `approvalItem` | [`RunToolApprovalItem`](/openai-agents-js/openai/agents-core/classes/runtoolapprovalitem/) | The tool call approval item to approve. | | `options` | { `alwaysApprove?`: `boolean`; } | Options for the approval. | | `options.alwaysApprove?` | `boolean` | Approve this tool for all future calls in this run. | #### Returns [Section titled “Returns”](#returns-4) `void` *** ### clearPendingAgentToolRun() [Section titled “clearPendingAgentToolRun()”](#clearpendingagenttoolrun) ```ts clearPendingAgentToolRun(toolName, callId): void; ``` #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | ---------- | -------- | | `toolName` | `string` | | `callId` | `string` | #### Returns [Section titled “Returns”](#returns-5) `void` *** ### getInterruptions() [Section titled “getInterruptions()”](#getinterruptions) ```ts getInterruptions(): RunToolApprovalItem[]; ``` Returns all interruptions if the current step is an interruption otherwise returns an empty array. #### Returns [Section titled “Returns”](#returns-6) [`RunToolApprovalItem`](/openai-agents-js/openai/agents-core/classes/runtoolapprovalitem/)\[] *** ### getPendingAgentToolRun() [Section titled “getPendingAgentToolRun()”](#getpendingagenttoolrun) ```ts getPendingAgentToolRun(toolName, callId): string | undefined; ``` #### Parameters [Section titled “Parameters”](#parameters-3) | Parameter | Type | | ---------- | -------- | | `toolName` | `string` | | `callId` | `string` | #### Returns [Section titled “Returns”](#returns-7) `string` | `undefined` *** ### getToolSearchRuntimeTools() [Section titled “getToolSearchRuntimeTools()”](#gettoolsearchruntimetools) ```ts getToolSearchRuntimeTools(agent): Tool[]; ``` #### Parameters [Section titled “Parameters”](#parameters-4) | Parameter | Type | | --------- | ---------------------------------------------------------------------------- | | `agent` | [`Agent`](/openai-agents-js/openai/agents-core/classes/agent/)<`any`, `any`> | #### Returns [Section titled “Returns”](#returns-8) [`Tool`](/openai-agents-js/openai/agents-core/type-aliases/tool/)<`TContext`>\[] *** ### hasPendingAgentToolRun() [Section titled “hasPendingAgentToolRun()”](#haspendingagenttoolrun) ```ts hasPendingAgentToolRun(toolName, callId): boolean; ``` #### Parameters [Section titled “Parameters”](#parameters-5) | Parameter | Type | | ---------- | -------- | | `toolName` | `string` | | `callId` | `string` | #### Returns [Section titled “Returns”](#returns-9) `boolean` *** ### recordToolSearchRuntimeTools() [Section titled “recordToolSearchRuntimeTools()”](#recordtoolsearchruntimetools) ```ts recordToolSearchRuntimeTools( agent, toolSearchOutput, tools): void; ``` #### Parameters [Section titled “Parameters”](#parameters-6) | Parameter | Type | Description | | -------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `agent` | [`Agent`](/openai-agents-js/openai/agents-core/classes/agent/)<`any`, `any`> | ‐ | | `toolSearchOutput` | { `call_id?`: `string` \| `null`; `callId?`: `string` \| `null`; `execution?`: `"client"` \| `"server"`; `id?`: `string`; `providerData?`: `Record`<`string`, `any`>; `status?`: `string`; `tools`: `Record`<`string`, `any`>\[]; `type`: `"tool_search_output"`; } | ‐ | | `toolSearchOutput.call_id?` | `string` \| `null` | ‐ | | `toolSearchOutput.callId?` | `string` \| `null` | ‐ | | `toolSearchOutput.execution?` | `"client"` \| `"server"` | ‐ | | `toolSearchOutput.id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `toolSearchOutput.providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `toolSearchOutput.status?` | `string` | ‐ | | `toolSearchOutput.tools` | `Record`<`string`, `any`>\[] | ‐ | | `toolSearchOutput.type` | `"tool_search_output"` | ‐ | | `tools` | [`Tool`](/openai-agents-js/openai/agents-core/type-aliases/tool/)<`TContext`>\[] | ‐ | #### Returns [Section titled “Returns”](#returns-10) `void` *** ### reject() [Section titled “reject()”](#reject) ```ts reject(approvalItem, options?): void; ``` Rejects a tool call requested by the agent through an interruption and approval item request. To reject the request use this method and then run the agent again with the same state object to continue the execution. By default it will only reject the current tool call. To reject the tool for all future calls throughout the run, set the `alwaysReject` option to `true`. When `message` is provided, it is used as the rejection text sent to the model. Otherwise, `toolErrorFormatter` (if configured) or the SDK default is used. #### Parameters [Section titled “Parameters”](#parameters-7) | Parameter | Type | Description | | ----------------------- | ------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------- | | `approvalItem` | [`RunToolApprovalItem`](/openai-agents-js/openai/agents-core/classes/runtoolapprovalitem/) | The tool call approval item to reject. | | `options` | { `alwaysReject?`: `boolean`; `message?`: `string`; } | Options for the rejection. | | `options.alwaysReject?` | `boolean` | Reject this tool for all future calls in this run. | | `options.message?` | `string` | The rejection text sent to the model. If not provided, `toolErrorFormatter` (if configured) or the SDK default is used. | #### Returns [Section titled “Returns”](#returns-11) `void` *** ### resetTurnPersistence() [Section titled “resetTurnPersistence()”](#resetturnpersistence) ```ts resetTurnPersistence(): void; ``` Resets the counter that tracks how many items were persisted for the current turn. #### Returns [Section titled “Returns”](#returns-12) `void` *** ### rewindTurnPersistence() [Section titled “rewindTurnPersistence()”](#rewindturnpersistence) ```ts rewindTurnPersistence(count): void; ``` Rewinds the persisted item counter when pending approvals require re-writing outputs. #### Parameters [Section titled “Parameters”](#parameters-8) | Parameter | Type | | --------- | -------- | | `count` | `number` | #### Returns [Section titled “Returns”](#returns-13) `void` *** ### setConversationContext() [Section titled “setConversationContext()”](#setconversationcontext) ```ts setConversationContext(conversationId?, previousResponseId?): void; ``` Updates server-managed conversation identifiers as a single operation. #### Parameters [Section titled “Parameters”](#parameters-9) | Parameter | Type | | --------------------- | -------- | | `conversationId?` | `string` | | `previousResponseId?` | `string` | #### Returns [Section titled “Returns”](#returns-14) `void` *** ### setCurrentAgent() [Section titled “setCurrentAgent()”](#setcurrentagent) ```ts setCurrentAgent(agent): void; ``` Switches the active agent handling the run. #### Parameters [Section titled “Parameters”](#parameters-10) | Parameter | Type | | --------- | -------- | | `agent` | `TAgent` | #### Returns [Section titled “Returns”](#returns-15) `void` *** ### setCurrentAgentSpan() [Section titled “setCurrentAgentSpan()”](#setcurrentagentspan) ```ts setCurrentAgentSpan(span?): void; ``` Updates the agent span associated with the current run. #### Parameters [Section titled “Parameters”](#parameters-11) | Parameter | Type | | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------- | | `span?` | [`Span`](/openai-agents-js/openai/agents-core/classes/span/)<[`AgentSpanData`](/openai-agents-js/openai/agents-core/type-aliases/agentspandata/)> | #### Returns [Section titled “Returns”](#returns-16) `void` *** ### setPendingAgentToolRun() [Section titled “setPendingAgentToolRun()”](#setpendingagenttoolrun) ```ts setPendingAgentToolRun( toolName, callId, serializedState): void; ``` #### Parameters [Section titled “Parameters”](#parameters-12) | Parameter | Type | | ----------------- | -------- | | `toolName` | `string` | | `callId` | `string` | | `serializedState` | `string` | #### Returns [Section titled “Returns”](#returns-17) `void` *** ### setReasoningItemIdPolicy() [Section titled “setReasoningItemIdPolicy()”](#setreasoningitemidpolicy) ```ts setReasoningItemIdPolicy(policy?): void; ``` Updates runtime options for converting run items into turn input. #### Parameters [Section titled “Parameters”](#parameters-13) | Parameter | Type | | --------- | --------------------------------------------------------------------------------------------------- | | `policy?` | [`ReasoningItemIdPolicy`](/openai-agents-js/openai/agents-core/type-aliases/reasoningitemidpolicy/) | #### Returns [Section titled “Returns”](#returns-18) `void` *** ### toJSON() [Section titled “toJSON()”](#tojson) ```ts toJSON(options?): object; ``` Serializes the run state. By default, tracing API keys are omitted to prevent accidental persistence of secrets. Pass `includeTracingApiKey: true` only when you intentionally need to migrate a run along with its tracing credentials (e.g., to rehydrate in a separate process that lacks the original environment variables). #### Parameters [Section titled “Parameters”](#parameters-14) | Parameter | Type | | ------------------------------- | --------------------------------------- | | `options` | { `includeTracingApiKey?`: `boolean`; } | | `options.includeTracingApiKey?` | `boolean` | #### Returns [Section titled “Returns”](#returns-19) `object` ##### $schemaVersion [Section titled “$schemaVersion”](#schemaversion) ```ts $schemaVersion: | "1.0" | "1.1" | "1.2" | "1.3" | "1.4" | "1.5" | "1.6" | "1.7" | "1.8" | "1.9" | "1.10" | "1.11"; ``` ##### context [Section titled “context”](#context) ```ts context: object; ``` ###### context.approvals [Section titled “context.approvals”](#contextapprovals) ```ts approvals: Record; rejected: boolean | string[]; stickyRejectMessage?: string; }>; ``` ###### context.context [Section titled “context.context”](#contextcontext) ```ts context: Record; ``` ###### context.toolInput? [Section titled “context.toolInput?”](#contexttoolinput) ```ts optional toolInput?: any; ``` ###### context.usage [Section titled “context.usage”](#contextusage) ```ts usage: object = usageSchema; ``` ###### context.usage.inputTokens [Section titled “context.usage.inputTokens”](#contextusageinputtokens) ```ts inputTokens: number; ``` ###### context.usage.inputTokensDetails? [Section titled “context.usage.inputTokensDetails?”](#contextusageinputtokensdetails) ```ts optional inputTokensDetails?: Record[]; ``` ###### context.usage.outputTokens [Section titled “context.usage.outputTokens”](#contextusageoutputtokens) ```ts outputTokens: number; ``` ###### context.usage.outputTokensDetails? [Section titled “context.usage.outputTokensDetails?”](#contextusageoutputtokensdetails) ```ts optional outputTokensDetails?: Record[]; ``` ###### context.usage.requests [Section titled “context.usage.requests”](#contextusagerequests) ```ts requests: number; ``` ###### context.usage.requestUsageEntries? [Section titled “context.usage.requestUsageEntries?”](#contextusagerequestusageentries) ```ts optional requestUsageEntries?: object[]; ``` ###### context.usage.totalTokens [Section titled “context.usage.totalTokens”](#contextusagetotaltokens) ```ts totalTokens: number; ``` ##### conversationId? [Section titled “conversationId?”](#conversationid) ```ts optional conversationId?: string; ``` ##### currentAgent [Section titled “currentAgent”](#currentagent-1) ```ts currentAgent: object = serializedAgentSchema; ``` ###### currentAgent.identity? [Section titled “currentAgent.identity?”](#currentagentidentity) ```ts optional identity?: string; ``` ###### currentAgent.name [Section titled “currentAgent.name”](#currentagentname) ```ts name: string; ``` ##### currentAgentSpan? [Section titled “currentAgentSpan?”](#currentagentspan) ```ts optional currentAgentSpan?: SerializedSpanType | null; ``` ##### currentStep? [Section titled “currentStep?”](#currentstep) ```ts optional currentStep?: | { newAgent: any; type: "next_step_handoff"; } | { output: string; type: "next_step_final_output"; } | { type: "next_step_run_again"; } | { data: Record; type: "next_step_interruption"; }; ``` ##### currentTurn [Section titled “currentTurn”](#currentturn) ```ts currentTurn: number; ``` ##### currentTurnInProgress? [Section titled “currentTurnInProgress?”](#currentturninprogress) ```ts optional currentTurnInProgress?: boolean; ``` ##### currentTurnPersistedItemCount? [Section titled “currentTurnPersistedItemCount?”](#currentturnpersisteditemcount) ```ts optional currentTurnPersistedItemCount?: number; ``` ##### generatedItems [Section titled “generatedItems”](#generateditems) ```ts generatedItems: ( | { agent: { identity?: string; name: string; }; rawItem: { content: ( | { providerData?: Record; refusal: string; type: "refusal"; } | { providerData?: Record; text: string; type: "output_text"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; } | { image: string; providerData?: Record; type: "image"; })[]; id?: string; providerData?: Record; role: "assistant"; status: "in_progress" | "completed" | "incomplete"; type?: "message"; }; type: "message_output_item"; } | { agent: { identity?: string; name: string; }; rawItem: { arguments: unknown; call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; type: "tool_search_call"; }; type: "tool_search_call_item"; } | { agent: { identity?: string; name: string; }; rawItem: { call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; tools: Record[]; type: "tool_search_output"; }; type: "tool_search_output_item"; } | { agent: { identity?: string; name: string; }; rawItem: | { arguments?: string; id?: string; name: string; output?: string; providerData?: Record; status?: string; type: "hosted_tool_call"; } | { arguments: string; callId: string; id?: string; name: string; namespace?: string; providerData?: Record; status?: "in_progress" | "completed" | "incomplete"; type: "function_call"; } | { action?: | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; }; actions?: ( | { type: "screenshot"; } | { button: ... | ... | ... | ... | ...; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: ...[]; type: "keypress"; } | { path: ...[]; type: "drag"; })[]; callId: string; id?: string; providerData?: Record; status: "in_progress" | "completed" | "incomplete"; type: "computer_call"; } | { action: { commands: string[]; maxOutputLength?: number; timeoutMs?: number; }; callId: string; id?: string; providerData?: Record; status?: "in_progress" | "completed" | "incomplete"; type: "shell_call"; } | { callId: string; id?: string; operation: | { diff: string; path: string; type: "create_file"; } | { diff: string; moveTo?: string; path: string; type: "update_file"; } | { path: string; type: "delete_file"; }; providerData?: Record; status: "in_progress" | "completed"; type: "apply_patch_call"; }; type: "tool_call_item"; } | { agent: { identity?: string; name: string; }; output: string; rawItem: | { callId: string; id?: string; name: string; namespace?: string; output: | string | { providerData?: Record; text: string; type: "text"; } | { detail?: "low" | "high" | "auto" | string & object; image?: | string | { data: ... | ...; mediaType?: ... | ...; } | { url: string; } | { fileId: string; }; providerData?: Record; type: "image"; } | { file: | string | { data: ... | ...; filename: string; mediaType: string; } | { filename?: ... | ...; url: string; } | { filename?: ... | ...; id: string; }; providerData?: Record; type: "file"; } | ( | { providerData?: ... | ...; text: string; type: "input_text"; } | { detail?: ... | ...; image?: ... | ... | ...; providerData?: ... | ...; type: "input_image"; } | { file?: ... | ... | ... | ...; filename?: ... | ...; providerData?: ... | ...; type: "input_file"; })[]; providerData?: Record; status: "in_progress" | "completed" | "incomplete"; type: "function_call_result"; } | { callId: string; id?: string; output: { data: string; providerData?: Record; type: "computer_screenshot"; }; providerData?: Record; type: "computer_call_result"; } | { callId: string; id?: string; maxOutputLength?: number; output: object[]; providerData?: Record; type: "shell_call_output"; } | { callId: string; id?: string; output?: string; providerData?: Record; status: "completed" | "failed"; type: "apply_patch_call_output"; }; type: "tool_call_output_item"; } | { agent: { identity?: string; name: string; }; rawItem: { content: object[]; id?: string; providerData?: Record; rawContent?: object[]; type: "reasoning"; }; type: "reasoning_item"; } | { agent: { identity?: string; name: string; }; rawItem: { arguments: string; callId: string; id?: string; name: string; namespace?: string; providerData?: Record; status?: "in_progress" | "completed" | "incomplete"; type: "function_call"; }; type: "handoff_call_item"; } | { rawItem: { callId: string; id?: string; name: string; namespace?: string; output: | string | { providerData?: Record; text: string; type: "text"; } | { detail?: "low" | "high" | "auto" | string & object; image?: | string | { data: string | Uint8Array<...>; mediaType?: string; } | { url: string; } | { fileId: string; }; providerData?: Record; type: "image"; } | { file: | string | { data: string | Uint8Array<...>; filename: string; mediaType: string; } | { filename?: string; url: string; } | { filename?: string; id: string; }; providerData?: Record; type: "file"; } | ( | { providerData?: Record<..., ...>; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: ...; }; providerData?: Record<..., ...>; type: "input_image"; } | { file?: | string | { id: ...; } | { url: ...; }; filename?: string; providerData?: Record<..., ...>; type: "input_file"; })[]; providerData?: Record; status: "in_progress" | "completed" | "incomplete"; type: "function_call_result"; }; sourceAgent: { identity?: string; name: string; }; targetAgent: { identity?: string; name: string; }; type: "handoff_output_item"; } | { agent: { identity?: string; name: string; }; rawItem: | { arguments?: string; id?: string; name: string; output?: string; providerData?: Record; status?: string; type: "hosted_tool_call"; } | { arguments: string; callId: string; id?: string; name: string; namespace?: string; providerData?: Record; status?: "in_progress" | "completed" | "incomplete"; type: "function_call"; } | { action?: | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; }; actions?: ( | { type: "screenshot"; } | { button: ... | ... | ... | ... | ...; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: ...[]; type: "keypress"; } | { path: ...[]; type: "drag"; })[]; callId: string; id?: string; providerData?: Record; status: "in_progress" | "completed" | "incomplete"; type: "computer_call"; } | { action: { commands: string[]; maxOutputLength?: number; timeoutMs?: number; }; callId: string; id?: string; providerData?: Record; status?: "in_progress" | "completed" | "incomplete"; type: "shell_call"; } | { callId: string; id?: string; operation: | { diff: string; path: string; type: "create_file"; } | { diff: string; moveTo?: string; path: string; type: "update_file"; } | { path: string; type: "delete_file"; }; providerData?: Record; status: "in_progress" | "completed"; type: "apply_patch_call"; }; toolName?: string; type: "tool_approval_item"; })[]; ``` ##### inputGuardrailResults [Section titled “inputGuardrailResults”](#inputguardrailresults) ```ts inputGuardrailResults: object[]; ``` ##### lastModelResponse? [Section titled “lastModelResponse?”](#lastmodelresponse) ```ts optional lastModelResponse?: object; ``` ###### lastModelResponse.output [Section titled “lastModelResponse.output”](#lastmodelresponseoutput) ```ts output: ( | { content: ( | { providerData?: Record<..., ...>; refusal: string; type: "refusal"; } | { providerData?: Record<..., ...>; text: string; type: "output_text"; } | { audio: | string | { id: ...; }; format?: string | null; providerData?: Record<..., ...>; transcript?: string | null; type: "audio"; } | { image: string; providerData?: Record<..., ...>; type: "image"; })[]; id?: string; providerData?: Record; role: "assistant"; status: "in_progress" | "completed" | "incomplete"; type?: "message"; } | { arguments?: string; id?: string; name: string; output?: string; providerData?: Record; status?: string; type: "hosted_tool_call"; } | { arguments: string; callId: string; id?: string; name: string; namespace?: string; providerData?: Record; status?: "in_progress" | "completed" | "incomplete"; type: "function_call"; } | { arguments: unknown; call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; type: "tool_search_call"; } | { call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; tools: Record[]; type: "tool_search_output"; } | { callId: string; id?: string; name: string; namespace?: string; output: | string | { providerData?: Record; text: string; type: "text"; } | { detail?: "low" | "high" | "auto" | string & object; image?: | string | { data: ... | ...; mediaType?: ... | ...; } | { url: string; } | { fileId: string; }; providerData?: Record; type: "image"; } | { file: | string | { data: ... | ...; filename: string; mediaType: string; } | { filename?: ... | ...; url: string; } | { filename?: ... | ...; id: string; }; providerData?: Record; type: "file"; } | ( | { providerData?: ... | ...; text: string; type: "input_text"; } | { detail?: ... | ...; image?: ... | ... | ...; providerData?: ... | ...; type: "input_image"; } | { file?: ... | ... | ... | ...; filename?: ... | ...; providerData?: ... | ...; type: "input_file"; })[]; providerData?: Record; status: "in_progress" | "completed" | "incomplete"; type: "function_call_result"; } | { action?: | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; }; actions?: ( | { type: "screenshot"; } | { button: ... | ... | ... | ... | ...; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: ...[]; type: "keypress"; } | { path: ...[]; type: "drag"; })[]; callId: string; id?: string; providerData?: Record; status: "in_progress" | "completed" | "incomplete"; type: "computer_call"; } | { action: { commands: string[]; maxOutputLength?: number; timeoutMs?: number; }; callId: string; id?: string; providerData?: Record; status?: "in_progress" | "completed" | "incomplete"; type: "shell_call"; } | { callId: string; id?: string; maxOutputLength?: number; output: object[]; providerData?: Record; type: "shell_call_output"; } | { callId: string; id?: string; operation: | { diff: string; path: string; type: "create_file"; } | { diff: string; moveTo?: string; path: string; type: "update_file"; } | { path: string; type: "delete_file"; }; providerData?: Record; status: "in_progress" | "completed"; type: "apply_patch_call"; } | { callId: string; id?: string; output?: string; providerData?: Record; status: "completed" | "failed"; type: "apply_patch_call_output"; } | { content: object[]; id?: string; providerData?: Record; rawContent?: object[]; type: "reasoning"; } | { created_by?: string; encrypted_content: string; id?: string; providerData?: Record; type: "compaction"; } | { id?: string; providerData?: Record; type: "unknown"; })[]; ``` ###### lastModelResponse.providerData? [Section titled “lastModelResponse.providerData?”](#lastmodelresponseproviderdata) ```ts optional providerData?: Record; ``` ###### lastModelResponse.requestId? [Section titled “lastModelResponse.requestId?”](#lastmodelresponserequestid) ```ts optional requestId?: string; ``` ###### lastModelResponse.responseId? [Section titled “lastModelResponse.responseId?”](#lastmodelresponseresponseid) ```ts optional responseId?: string; ``` ###### lastModelResponse.usage [Section titled “lastModelResponse.usage”](#lastmodelresponseusage) ```ts usage: object = usageSchema; ``` ###### lastModelResponse.usage.inputTokens [Section titled “lastModelResponse.usage.inputTokens”](#lastmodelresponseusageinputtokens) ```ts inputTokens: number; ``` ###### lastModelResponse.usage.inputTokensDetails? [Section titled “lastModelResponse.usage.inputTokensDetails?”](#lastmodelresponseusageinputtokensdetails) ```ts optional inputTokensDetails?: Record[]; ``` ###### lastModelResponse.usage.outputTokens [Section titled “lastModelResponse.usage.outputTokens”](#lastmodelresponseusageoutputtokens) ```ts outputTokens: number; ``` ###### lastModelResponse.usage.outputTokensDetails? [Section titled “lastModelResponse.usage.outputTokensDetails?”](#lastmodelresponseusageoutputtokensdetails) ```ts optional outputTokensDetails?: Record[]; ``` ###### lastModelResponse.usage.requests [Section titled “lastModelResponse.usage.requests”](#lastmodelresponseusagerequests) ```ts requests: number; ``` ###### lastModelResponse.usage.requestUsageEntries? [Section titled “lastModelResponse.usage.requestUsageEntries?”](#lastmodelresponseusagerequestusageentries) ```ts optional requestUsageEntries?: object[]; ``` ###### lastModelResponse.usage.totalTokens [Section titled “lastModelResponse.usage.totalTokens”](#lastmodelresponseusagetotaltokens) ```ts totalTokens: number; ``` ##### lastProcessedResponse? [Section titled “lastProcessedResponse?”](#lastprocessedresponse) ```ts optional lastProcessedResponse?: object; ``` ###### lastProcessedResponse.applyPatchActions? [Section titled “lastProcessedResponse.applyPatchActions?”](#lastprocessedresponseapplypatchactions) ```ts optional applyPatchActions?: object[]; ``` ###### lastProcessedResponse.computerActions [Section titled “lastProcessedResponse.computerActions”](#lastprocessedresponsecomputeractions) ```ts computerActions: object[]; ``` ###### lastProcessedResponse.functions [Section titled “lastProcessedResponse.functions”](#lastprocessedresponsefunctions) ```ts functions: object[]; ``` ###### lastProcessedResponse.handoffs [Section titled “lastProcessedResponse.handoffs”](#lastprocessedresponsehandoffs) ```ts handoffs: object[]; ``` ###### lastProcessedResponse.mcpApprovalRequests? [Section titled “lastProcessedResponse.mcpApprovalRequests?”](#lastprocessedresponsemcpapprovalrequests) ```ts optional mcpApprovalRequests?: object[]; ``` ###### lastProcessedResponse.newItems [Section titled “lastProcessedResponse.newItems”](#lastprocessedresponsenewitems) ```ts newItems: ( | { agent: { identity?: string; name: string; }; rawItem: { content: ( | { providerData?: ... | ...; refusal: string; type: "refusal"; } | { providerData?: ... | ...; text: string; type: "output_text"; } | { audio: ... | ...; format?: ... | ... | ...; providerData?: ... | ...; transcript?: ... | ... | ...; type: "audio"; } | { image: string; providerData?: ... | ...; type: "image"; })[]; id?: string; providerData?: Record; role: "assistant"; status: "in_progress" | "completed" | "incomplete"; type?: "message"; }; type: "message_output_item"; } | { agent: { identity?: string; name: string; }; rawItem: { arguments: unknown; call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; type: "tool_search_call"; }; type: "tool_search_call_item"; } | { agent: { identity?: string; name: string; }; rawItem: { call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; tools: Record[]; type: "tool_search_output"; }; type: "tool_search_output_item"; } | { agent: { identity?: string; name: string; }; rawItem: | { arguments?: string; id?: string; name: string; output?: string; providerData?: Record; status?: string; type: "hosted_tool_call"; } | { arguments: string; callId: string; id?: string; name: string; namespace?: string; providerData?: Record; status?: "in_progress" | "completed" | "incomplete"; type: "function_call"; } | { action?: | { type: "screenshot"; } | { button: ... | ... | ... | ... | ...; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: ...[]; type: "keypress"; } | { path: ...[]; type: "drag"; }; actions?: (... | ... | ... | ... | ... | ... | ... | ... | ...)[]; callId: string; id?: string; providerData?: Record; status: "in_progress" | "completed" | "incomplete"; type: "computer_call"; } | { action: { commands: string[]; maxOutputLength?: number; timeoutMs?: number; }; callId: string; id?: string; providerData?: Record; status?: "in_progress" | "completed" | "incomplete"; type: "shell_call"; } | { callId: string; id?: string; operation: | { diff: string; path: string; type: "create_file"; } | { diff: string; moveTo?: ... | ...; path: string; type: "update_file"; } | { path: string; type: "delete_file"; }; providerData?: Record; status: "in_progress" | "completed"; type: "apply_patch_call"; }; type: "tool_call_item"; } | { agent: { identity?: string; name: string; }; output: string; rawItem: | { callId: string; id?: string; name: string; namespace?: string; output: | string | { providerData?: ... | ...; text: string; type: "text"; } | { detail?: ... | ... | ... | ... | ...; image?: ... | ... | ... | ... | ...; providerData?: ... | ...; type: "image"; } | { file: ... | ... | ... | ...; providerData?: ... | ...; type: "file"; } | (... | ... | ...)[]; providerData?: Record; status: "in_progress" | "completed" | "incomplete"; type: "function_call_result"; } | { callId: string; id?: string; output: { data: string; providerData?: Record<..., ...>; type: "computer_screenshot"; }; providerData?: Record; type: "computer_call_result"; } | { callId: string; id?: string; maxOutputLength?: number; output: object[]; providerData?: Record; type: "shell_call_output"; } | { callId: string; id?: string; output?: string; providerData?: Record; status: "completed" | "failed"; type: "apply_patch_call_output"; }; type: "tool_call_output_item"; } | { agent: { identity?: string; name: string; }; rawItem: { content: object[]; id?: string; providerData?: Record; rawContent?: object[]; type: "reasoning"; }; type: "reasoning_item"; } | { agent: { identity?: string; name: string; }; rawItem: { arguments: string; callId: string; id?: string; name: string; namespace?: string; providerData?: Record; status?: "in_progress" | "completed" | "incomplete"; type: "function_call"; }; type: "handoff_call_item"; } | { rawItem: { callId: string; id?: string; name: string; namespace?: string; output: | string | { providerData?: Record<..., ...>; text: string; type: "text"; } | { detail?: "low" | "high" | "auto" | ... & ...; image?: | string | { data: ...; mediaType?: ...; } | { url: ...; } | { fileId: ...; }; providerData?: Record<..., ...>; type: "image"; } | { file: | string | { data: ...; filename: ...; mediaType: ...; } | { filename?: ...; url: ...; } | { filename?: ...; id: ...; }; providerData?: Record<..., ...>; type: "file"; } | ( | { providerData?: ...; text: ...; type: ...; } | { detail?: ...; image?: ...; providerData?: ...; type: ...; } | { file?: ...; filename?: ...; providerData?: ...; type: ...; })[]; providerData?: Record; status: "in_progress" | "completed" | "incomplete"; type: "function_call_result"; }; sourceAgent: { identity?: string; name: string; }; targetAgent: { identity?: string; name: string; }; type: "handoff_output_item"; } | { agent: { identity?: string; name: string; }; rawItem: | { arguments?: string; id?: string; name: string; output?: string; providerData?: Record; status?: string; type: "hosted_tool_call"; } | { arguments: string; callId: string; id?: string; name: string; namespace?: string; providerData?: Record; status?: "in_progress" | "completed" | "incomplete"; type: "function_call"; } | { action?: | { type: "screenshot"; } | { button: ... | ... | ... | ... | ...; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: ...[]; type: "keypress"; } | { path: ...[]; type: "drag"; }; actions?: (... | ... | ... | ... | ... | ... | ... | ... | ...)[]; callId: string; id?: string; providerData?: Record; status: "in_progress" | "completed" | "incomplete"; type: "computer_call"; } | { action: { commands: string[]; maxOutputLength?: number; timeoutMs?: number; }; callId: string; id?: string; providerData?: Record; status?: "in_progress" | "completed" | "incomplete"; type: "shell_call"; } | { callId: string; id?: string; operation: | { diff: string; path: string; type: "create_file"; } | { diff: string; moveTo?: ... | ...; path: string; type: "update_file"; } | { path: string; type: "delete_file"; }; providerData?: Record; status: "in_progress" | "completed"; type: "apply_patch_call"; }; toolName?: string; type: "tool_approval_item"; })[]; ``` ###### lastProcessedResponse.shellActions? [Section titled “lastProcessedResponse.shellActions?”](#lastprocessedresponseshellactions) ```ts optional shellActions?: object[]; ``` ###### lastProcessedResponse.toolsUsed [Section titled “lastProcessedResponse.toolsUsed”](#lastprocessedresponsetoolsused) ```ts toolsUsed: string[]; ``` ##### maxTurns [Section titled “maxTurns”](#maxturns) ```ts maxTurns: number | null; ``` ##### modelResponses [Section titled “modelResponses”](#modelresponses) ```ts modelResponses: object[]; ``` ##### noActiveAgentRun [Section titled “noActiveAgentRun”](#noactiveagentrun) ```ts noActiveAgentRun: boolean; ``` ##### originalInput [Section titled “originalInput”](#originalinput) ```ts originalInput: | string | ( | { content: ( | { providerData?: Record; refusal: string; type: "refusal"; } | { providerData?: Record; text: string; type: "output_text"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; } | { image: string; providerData?: Record; type: "image"; })[]; id?: string; providerData?: Record; role: "assistant"; status: "in_progress" | "completed" | "incomplete"; type?: "message"; } | { content: | string | ( | { providerData?: Record<..., ...>; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: ...; }; providerData?: Record<..., ...>; type: "input_image"; } | { file?: | string | { id: ...; } | { url: ...; }; filename?: string; providerData?: Record<..., ...>; type: "input_file"; } | { audio: | string | { id: ...; }; format?: string | null; providerData?: Record<..., ...>; transcript?: string | null; type: "audio"; })[]; id?: string; providerData?: Record; role: "user"; type?: "message"; } | { content: string; id?: string; providerData?: Record; role: "system"; type?: "message"; } | { arguments?: string; id?: string; name: string; output?: string; providerData?: Record; status?: string; type: "hosted_tool_call"; } | { arguments: string; callId: string; id?: string; name: string; namespace?: string; providerData?: Record; status?: "in_progress" | "completed" | "incomplete"; type: "function_call"; } | { arguments: unknown; call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; type: "tool_search_call"; } | { call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; tools: Record[]; type: "tool_search_output"; } | { callId: string; id?: string; name: string; namespace?: string; output: | string | { providerData?: Record; text: string; type: "text"; } | { detail?: "low" | "high" | "auto" | string & object; image?: | string | { data: string | Uint8Array<...>; mediaType?: string; } | { url: string; } | { fileId: string; }; providerData?: Record; type: "image"; } | { file: | string | { data: string | Uint8Array<...>; filename: string; mediaType: string; } | { filename?: string; url: string; } | { filename?: string; id: string; }; providerData?: Record; type: "file"; } | ( | { providerData?: Record<..., ...>; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: ...; }; providerData?: Record<..., ...>; type: "input_image"; } | { file?: | string | { id: ...; } | { url: ...; }; filename?: string; providerData?: Record<..., ...>; type: "input_file"; })[]; providerData?: Record; status: "in_progress" | "completed" | "incomplete"; type: "function_call_result"; } | { action?: | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; }; actions?: ( | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; })[]; callId: string; id?: string; providerData?: Record; status: "in_progress" | "completed" | "incomplete"; type: "computer_call"; } | { callId: string; id?: string; output: { data: string; providerData?: Record; type: "computer_screenshot"; }; providerData?: Record; type: "computer_call_result"; } | { action: { commands: string[]; maxOutputLength?: number; timeoutMs?: number; }; callId: string; id?: string; providerData?: Record; status?: "in_progress" | "completed" | "incomplete"; type: "shell_call"; } | { callId: string; id?: string; maxOutputLength?: number; output: object[]; providerData?: Record; type: "shell_call_output"; } | { callId: string; id?: string; operation: | { diff: string; path: string; type: "create_file"; } | { diff: string; moveTo?: string; path: string; type: "update_file"; } | { path: string; type: "delete_file"; }; providerData?: Record; status: "in_progress" | "completed"; type: "apply_patch_call"; } | { callId: string; id?: string; output?: string; providerData?: Record; status: "completed" | "failed"; type: "apply_patch_call_output"; } | { content: object[]; id?: string; providerData?: Record; rawContent?: object[]; type: "reasoning"; } | { created_by?: string; encrypted_content: string; id?: string; providerData?: Record; type: "compaction"; } | { id?: string; providerData?: Record; type: "unknown"; })[]; ``` ##### outputGuardrailResults [Section titled “outputGuardrailResults”](#outputguardrailresults) ```ts outputGuardrailResults: object[]; ``` ##### pendingAgentToolRuns [Section titled “pendingAgentToolRuns”](#pendingagenttoolruns) ```ts pendingAgentToolRuns: Record; ``` ##### previousResponseId? [Section titled “previousResponseId?”](#previousresponseid) ```ts optional previousResponseId?: string; ``` ##### reasoningItemIdPolicy? [Section titled “reasoningItemIdPolicy?”](#reasoningitemidpolicy) ```ts optional reasoningItemIdPolicy?: "preserve" | "omit"; ``` ##### sandbox? [Section titled “sandbox?”](#sandbox) ```ts optional sandbox?: object; ``` ###### sandbox.backendId [Section titled “sandbox.backendId”](#sandboxbackendid) ```ts backendId: string; ``` ###### sandbox.currentAgentKey [Section titled “sandbox.currentAgentKey”](#sandboxcurrentagentkey) ```ts currentAgentKey: string; ``` ###### sandbox.currentAgentName [Section titled “sandbox.currentAgentName”](#sandboxcurrentagentname) ```ts currentAgentName: string; ``` ###### sandbox.sessionsByAgent [Section titled “sandbox.sessionsByAgent”](#sandboxsessionsbyagent) ```ts sessionsByAgent: Record; manifest: Record; providerState: Record; snapshot?: Record | null; snapshotFingerprint?: string | null; snapshotFingerprintVersion?: string | null; version: 1; workspaceReady: boolean; }; }>; ``` ###### sandbox.sessionState [Section titled “sandbox.sessionState”](#sandboxsessionstate) ```ts sessionState: object = sandboxSessionStateEnvelopeSchema; ``` ###### sandbox.sessionState.backendId [Section titled “sandbox.sessionState.backendId”](#sandboxsessionstatebackendid) ```ts backendId: string; ``` ###### sandbox.sessionState.exposedPorts? [Section titled “sandbox.sessionState.exposedPorts?”](#sandboxsessionstateexposedports) ```ts optional exposedPorts?: Record; ``` ###### sandbox.sessionState.manifest [Section titled “sandbox.sessionState.manifest”](#sandboxsessionstatemanifest) ```ts manifest: Record; ``` ###### sandbox.sessionState.providerState [Section titled “sandbox.sessionState.providerState”](#sandboxsessionstateproviderstate) ```ts providerState: Record; ``` ###### sandbox.sessionState.snapshot? [Section titled “sandbox.sessionState.snapshot?”](#sandboxsessionstatesnapshot) ```ts optional snapshot?: Record | null; ``` ###### sandbox.sessionState.snapshotFingerprint? [Section titled “sandbox.sessionState.snapshotFingerprint?”](#sandboxsessionstatesnapshotfingerprint) ```ts optional snapshotFingerprint?: string | null; ``` ###### sandbox.sessionState.snapshotFingerprintVersion? [Section titled “sandbox.sessionState.snapshotFingerprintVersion?”](#sandboxsessionstatesnapshotfingerprintversion) ```ts optional snapshotFingerprintVersion?: string | null; ``` ###### sandbox.sessionState.version [Section titled “sandbox.sessionState.version”](#sandboxsessionstateversion) ```ts version: 1; ``` ###### sandbox.sessionState.workspaceReady [Section titled “sandbox.sessionState.workspaceReady”](#sandboxsessionstateworkspaceready) ```ts workspaceReady: boolean; ``` ##### toolInputGuardrailResults [Section titled “toolInputGuardrailResults”](#toolinputguardrailresults) ```ts toolInputGuardrailResults: object[]; ``` ##### toolOutputGuardrailResults [Section titled “toolOutputGuardrailResults”](#tooloutputguardrailresults) ```ts toolOutputGuardrailResults: object[]; ``` ##### toolUseTracker [Section titled “toolUseTracker”](#toolusetracker) ```ts toolUseTracker: Record; ``` ##### trace [Section titled “trace”](#trace) ```ts trace: | { group_id: string | null; id: string; metadata: Record; object: "trace"; tracing_api_key?: string | null; workflow_name: string; } | null; ``` *** ### toString() [Section titled “toString()”](#tostring) ```ts toString(options?): string; ``` Serializes the run state to a string. This method is used to serialize the run state to a string that can be used to resume the run later. #### Parameters [Section titled “Parameters”](#parameters-15) | Parameter | Type | | ------------------------------- | --------------------------------------- | | `options` | { `includeTracingApiKey?`: `boolean`; } | | `options.includeTracingApiKey?` | `boolean` | #### Returns [Section titled “Returns”](#returns-20) `string` The serialized run state. *** ### fromString() [Section titled “fromString()”](#fromstring) ```ts static fromString(initialAgent, str): Promise>; ``` Deserializes a run state from a string. This method is used to deserialize a run state from a string that was serialized using the `toString` method. #### Type Parameters [Section titled “Type Parameters”](#type-parameters-1) | Type Parameter | | ----------------------------------------------------------------------------------------------- | | `TContext` | | `TAgent` *extends* [`Agent`](/openai-agents-js/openai/agents-core/classes/agent/)<`any`, `any`> | #### Parameters [Section titled “Parameters”](#parameters-16) | Parameter | Type | | -------------- | -------- | | `initialAgent` | `TAgent` | | `str` | `string` | #### Returns [Section titled “Returns”](#returns-21) `Promise`<`RunState`<`TContext`, `TAgent`>> *** ### fromStringWithContext() [Section titled “fromStringWithContext()”](#fromstringwithcontext) ```ts static fromStringWithContext( initialAgent, str, context, options?): Promise>; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-2) | Type Parameter | | ----------------------------------------------------------------------------------------------- | | `TContext` | | `TAgent` *extends* [`Agent`](/openai-agents-js/openai/agents-core/classes/agent/)<`any`, `any`> | #### Parameters [Section titled “Parameters”](#parameters-17) | Parameter | Type | | -------------------------- | ------------------------------------------------------------------------------------ | | `initialAgent` | `TAgent` | | `str` | `string` | | `context` | [`RunContext`](/openai-agents-js/openai/agents-core/classes/runcontext/)<`TContext`> | | `options` | { `contextStrategy?`: `ContextOverrideStrategy`; } | | `options.contextStrategy?` | `ContextOverrideStrategy` | #### Returns [Section titled “Returns”](#returns-22) `Promise`<`RunState`<`TContext`, `TAgent`>> # RuntimeEventEmitter The `EventEmitter` class is defined and exposed by the `node:events` module: ```js import { EventEmitter } from 'node:events'; ``` All `EventEmitter`s emit the event `'newListener'` when new listeners are added and `'removeListener'` when existing listeners are removed. It supports the following option: ## Since [Section titled “Since”](#since) v0.1.26 ## Extends [Section titled “Extends”](#extends) * `EventEmitter`<`T`> ## Extended by [Section titled “Extended by”](#extended-by) * [`EventEmitterAsyncResource`](/openai-agents-js/openai/agents-core/openai/namespaces/runtimeeventemitter/classes/eventemitterasyncresource/) ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | ----------------------------- | ----------------- | | `T` *extends* `EventMap`<`T`> | `DefaultEventMap` | ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new RuntimeEventEmitter(options?): EventEmitter; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ---------- | --------------------- | | `options?` | `EventEmitterOptions` | #### Returns [Section titled “Returns”](#returns) `EventEmitter`<`T`> #### Inherited from [Section titled “Inherited from”](#inherited-from) ```ts NodeJS.EventEmitter.constructor ``` ## Properties [Section titled “Properties”](#properties) ### captureRejections [Section titled “captureRejections”](#capturerejections) ```ts static captureRejections: boolean; ``` Value: [boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type) Change the default `captureRejections` option on all new `EventEmitter` objects. #### Since [Section titled “Since”](#since-1) v13.4.0, v12.16.0 *** ### captureRejectionSymbol [Section titled “captureRejectionSymbol”](#capturerejectionsymbol) ```ts readonly static captureRejectionSymbol: typeof captureRejectionSymbol; ``` Value: `Symbol.for('nodejs.rejection')` See how to write a custom `rejection handler`. #### Since [Section titled “Since”](#since-2) v13.4.0, v12.16.0 *** ### defaultMaxListeners [Section titled “defaultMaxListeners”](#defaultmaxlisteners) ```ts static defaultMaxListeners: number; ``` By default, a maximum of `10` listeners can be registered for any single event. This limit can be changed for individual `EventEmitter` instances using the `emitter.setMaxListeners(n)` method. To change the default for *all*`EventEmitter` instances, the `events.defaultMaxListeners` property can be used. If this value is not a positive number, a `RangeError` is thrown. Take caution when setting the `events.defaultMaxListeners` because the change affects *all* `EventEmitter` instances, including those created before the change is made. However, calling `emitter.setMaxListeners(n)` still has precedence over `events.defaultMaxListeners`. This is not a hard limit. The `EventEmitter` instance will allow more listeners to be added but will output a trace warning to stderr indicating that a “possible EventEmitter memory leak” has been detected. For any single `EventEmitter`, the `emitter.getMaxListeners()` and `emitter.setMaxListeners()` methods can be used to temporarily avoid this warning: ```js import { EventEmitter } from 'node:events'; const emitter = new EventEmitter(); emitter.setMaxListeners(emitter.getMaxListeners() + 1); emitter.once('event', () => { // do stuff emitter.setMaxListeners(Math.max(emitter.getMaxListeners() - 1, 0)); }); ``` The `--trace-warnings` command-line flag can be used to display the stack trace for such warnings. The emitted warning can be inspected with `process.on('warning')` and will have the additional `emitter`, `type`, and `count` properties, referring to the event emitter instance, the event’s name and the number of attached listeners, respectively. Its `name` property is set to `'MaxListenersExceededWarning'`. #### Since [Section titled “Since”](#since-3) v0.11.2 *** ### errorMonitor [Section titled “errorMonitor”](#errormonitor) ```ts readonly static errorMonitor: typeof errorMonitor; ``` This symbol shall be used to install a listener for only monitoring `'error'` events. Listeners installed using this symbol are called before the regular `'error'` listeners are called. Installing a listener using this symbol does not change the behavior once an `'error'` event is emitted. Therefore, the process will still crash if no regular `'error'` listener is installed. #### Since [Section titled “Since”](#since-4) v13.6.0, v12.17.0 ## Methods [Section titled “Methods”](#methods) ### \[captureRejectionSymbol]\()? [Section titled “\[captureRejectionSymbol\]()?”](#capturerejectionsymbol-1) ```ts optional [captureRejectionSymbol]( error, event, ... args): void; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-1) | Type Parameter | | -------------- | | `K` | #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | --------- | ---------------- | | `error` | `Error` | | `event` | `Key`<`K`, `T`> | | …`args` | `Args`<`K`, `T`> | #### Returns [Section titled “Returns”](#returns-1) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-1) ```ts NodeJS.EventEmitter.[captureRejectionSymbol] ``` *** ### addListener() [Section titled “addListener()”](#addlistener) ```ts addListener(eventName, listener): this; ``` Alias for `emitter.on(eventName, listener)`. #### Type Parameters [Section titled “Type Parameters”](#type-parameters-2) | Type Parameter | | -------------- | | `K` | #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | ----------- | -------------------- | | `eventName` | `Key`<`K`, `T`> | | `listener` | `Listener`<`K`, `T`> | #### Returns [Section titled “Returns”](#returns-2) `this` #### Since [Section titled “Since”](#since-5) v0.1.26 #### Inherited from [Section titled “Inherited from”](#inherited-from-2) ```ts NodeJS.EventEmitter.addListener ``` *** ### emit() [Section titled “emit()”](#emit) ```ts emit(eventName, ...args): boolean; ``` Synchronously calls each of the listeners registered for the event named `eventName`, in the order they were registered, passing the supplied arguments to each. Returns `true` if the event had listeners, `false` otherwise. ```js import { EventEmitter } from 'node:events'; const myEmitter = new EventEmitter(); // First listener myEmitter.on('event', function firstListener() { console.log('Helloooo! first listener'); }); // Second listener myEmitter.on('event', function secondListener(arg1, arg2) { console.log(`event with parameters ${arg1}, ${arg2} in second listener`); }); // Third listener myEmitter.on('event', function thirdListener(...args) { const parameters = args.join(', '); console.log(`event with parameters ${parameters} in third listener`); }); console.log(myEmitter.listeners('event')); myEmitter.emit('event', 1, 2, 3, 4, 5); // Prints: // [ // [Function: firstListener], // [Function: secondListener], // [Function: thirdListener] // ] // Helloooo! first listener // event with parameters 1, 2 in second listener // event with parameters 1, 2, 3, 4, 5 in third listener ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-3) | Type Parameter | | -------------- | | `K` | #### Parameters [Section titled “Parameters”](#parameters-3) | Parameter | Type | | ----------- | ---------------- | | `eventName` | `Key`<`K`, `T`> | | …`args` | `Args`<`K`, `T`> | #### Returns [Section titled “Returns”](#returns-3) `boolean` #### Since [Section titled “Since”](#since-6) v0.1.26 #### Inherited from [Section titled “Inherited from”](#inherited-from-3) ```ts NodeJS.EventEmitter.emit ``` *** ### eventNames() [Section titled “eventNames()”](#eventnames) ```ts eventNames(): string | symbol & Key2[]; ``` Returns an array listing the events for which the emitter has registered listeners. The values in the array are strings or `Symbol`s. ```js import { EventEmitter } from 'node:events'; const myEE = new EventEmitter(); myEE.on('foo', () => {}); myEE.on('bar', () => {}); const sym = Symbol('symbol'); myEE.on(sym, () => {}); console.log(myEE.eventNames()); // Prints: [ 'foo', 'bar', Symbol(symbol) ] ``` #### Returns [Section titled “Returns”](#returns-4) `string` | `symbol` & `Key2`<`unknown`, `T`>\[] #### Since [Section titled “Since”](#since-7) v6.0.0 #### Inherited from [Section titled “Inherited from”](#inherited-from-4) ```ts NodeJS.EventEmitter.eventNames ``` *** ### getMaxListeners() [Section titled “getMaxListeners()”](#getmaxlisteners) ```ts getMaxListeners(): number; ``` Returns the current max listener value for the `EventEmitter` which is either set by `emitter.setMaxListeners(n)` or defaults to [EventEmitter.defaultMaxListeners](/openai-agents-js/openai/agents-core/classes/runtimeeventemitter/#defaultmaxlisteners). #### Returns [Section titled “Returns”](#returns-5) `number` #### Since [Section titled “Since”](#since-8) v1.0.0 #### Inherited from [Section titled “Inherited from”](#inherited-from-5) ```ts NodeJS.EventEmitter.getMaxListeners ``` *** ### listenerCount() [Section titled “listenerCount()”](#listenercount) ```ts listenerCount(eventName, listener?): number; ``` Returns the number of listeners listening for the event named `eventName`. If `listener` is provided, it will return how many times the listener is found in the list of the listeners of the event. #### Type Parameters [Section titled “Type Parameters”](#type-parameters-4) | Type Parameter | | -------------- | | `K` | #### Parameters [Section titled “Parameters”](#parameters-4) | Parameter | Type | Description | | ----------- | -------------------------------- | ---------------------------------------- | | `eventName` | `Key`<`K`, `T`> | The name of the event being listened for | | `listener?` | `Listener`<`K`, `T`, `Function`> | The event handler function | #### Returns [Section titled “Returns”](#returns-6) `number` #### Since [Section titled “Since”](#since-9) v3.2.0 #### Inherited from [Section titled “Inherited from”](#inherited-from-6) ```ts NodeJS.EventEmitter.listenerCount ``` *** ### listeners() [Section titled “listeners()”](#listeners) ```ts listeners(eventName): Listener[]; ``` Returns a copy of the array of listeners for the event named `eventName`. ```js server.on('connection', (stream) => { console.log('someone connected!'); }); console.log(util.inspect(server.listeners('connection'))); // Prints: [ [Function] ] ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-5) | Type Parameter | | -------------- | | `K` | #### Parameters [Section titled “Parameters”](#parameters-5) | Parameter | Type | | ----------- | --------------- | | `eventName` | `Key`<`K`, `T`> | #### Returns [Section titled “Returns”](#returns-7) `Listener`<`K`, `T`, `Function`>\[] #### Since [Section titled “Since”](#since-10) v0.1.26 #### Inherited from [Section titled “Inherited from”](#inherited-from-7) ```ts NodeJS.EventEmitter.listeners ``` *** ### off() [Section titled “off()”](#off) ```ts off(eventName, listener): this; ``` Alias for `emitter.removeListener()`. #### Type Parameters [Section titled “Type Parameters”](#type-parameters-6) | Type Parameter | | -------------- | | `K` | #### Parameters [Section titled “Parameters”](#parameters-6) | Parameter | Type | | ----------- | -------------------- | | `eventName` | `Key`<`K`, `T`> | | `listener` | `Listener`<`K`, `T`> | #### Returns [Section titled “Returns”](#returns-8) `this` #### Since [Section titled “Since”](#since-11) v10.0.0 #### Inherited from [Section titled “Inherited from”](#inherited-from-8) ```ts NodeJS.EventEmitter.off ``` *** ### on() [Section titled “on()”](#on) ```ts on(eventName, listener): this; ``` Adds the `listener` function to the end of the listeners array for the event named `eventName`. No checks are made to see if the `listener` has already been added. Multiple calls passing the same combination of `eventName` and `listener` will result in the `listener` being added, and called, multiple times. ```js server.on('connection', (stream) => { console.log('someone connected!'); }); ``` Returns a reference to the `EventEmitter`, so that calls can be chained. By default, event listeners are invoked in the order they are added. The `emitter.prependListener()` method can be used as an alternative to add the event listener to the beginning of the listeners array. ```js import { EventEmitter } from 'node:events'; const myEE = new EventEmitter(); myEE.on('foo', () => console.log('a')); myEE.prependListener('foo', () => console.log('b')); myEE.emit('foo'); // Prints: // b // a ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-7) | Type Parameter | | -------------- | | `K` | #### Parameters [Section titled “Parameters”](#parameters-7) | Parameter | Type | Description | | ----------- | -------------------- | ---------------------- | | `eventName` | `Key`<`K`, `T`> | The name of the event. | | `listener` | `Listener`<`K`, `T`> | The callback function | #### Returns [Section titled “Returns”](#returns-9) `this` #### Since [Section titled “Since”](#since-12) v0.1.101 #### Inherited from [Section titled “Inherited from”](#inherited-from-9) ```ts NodeJS.EventEmitter.on ``` *** ### once() [Section titled “once()”](#once) ```ts once(eventName, listener): this; ``` Adds a **one-time** `listener` function for the event named `eventName`. The next time `eventName` is triggered, this listener is removed and then invoked. ```js server.once('connection', (stream) => { console.log('Ah, we have our first user!'); }); ``` Returns a reference to the `EventEmitter`, so that calls can be chained. By default, event listeners are invoked in the order they are added. The `emitter.prependOnceListener()` method can be used as an alternative to add the event listener to the beginning of the listeners array. ```js import { EventEmitter } from 'node:events'; const myEE = new EventEmitter(); myEE.once('foo', () => console.log('a')); myEE.prependOnceListener('foo', () => console.log('b')); myEE.emit('foo'); // Prints: // b // a ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-8) | Type Parameter | | -------------- | | `K` | #### Parameters [Section titled “Parameters”](#parameters-8) | Parameter | Type | Description | | ----------- | -------------------- | ---------------------- | | `eventName` | `Key`<`K`, `T`> | The name of the event. | | `listener` | `Listener`<`K`, `T`> | The callback function | #### Returns [Section titled “Returns”](#returns-10) `this` #### Since [Section titled “Since”](#since-13) v0.3.0 #### Inherited from [Section titled “Inherited from”](#inherited-from-10) ```ts NodeJS.EventEmitter.once ``` *** ### prependListener() [Section titled “prependListener()”](#prependlistener) ```ts prependListener(eventName, listener): this; ``` Adds the `listener` function to the *beginning* of the listeners array for the event named `eventName`. No checks are made to see if the `listener` has already been added. Multiple calls passing the same combination of `eventName` and `listener` will result in the `listener` being added, and called, multiple times. ```js server.prependListener('connection', (stream) => { console.log('someone connected!'); }); ``` Returns a reference to the `EventEmitter`, so that calls can be chained. #### Type Parameters [Section titled “Type Parameters”](#type-parameters-9) | Type Parameter | | -------------- | | `K` | #### Parameters [Section titled “Parameters”](#parameters-9) | Parameter | Type | Description | | ----------- | -------------------- | ---------------------- | | `eventName` | `Key`<`K`, `T`> | The name of the event. | | `listener` | `Listener`<`K`, `T`> | The callback function | #### Returns [Section titled “Returns”](#returns-11) `this` #### Since [Section titled “Since”](#since-14) v6.0.0 #### Inherited from [Section titled “Inherited from”](#inherited-from-11) ```ts NodeJS.EventEmitter.prependListener ``` *** ### prependOnceListener() [Section titled “prependOnceListener()”](#prependoncelistener) ```ts prependOnceListener(eventName, listener): this; ``` Adds a **one-time**`listener` function for the event named `eventName` to the *beginning* of the listeners array. The next time `eventName` is triggered, this listener is removed, and then invoked. ```js server.prependOnceListener('connection', (stream) => { console.log('Ah, we have our first user!'); }); ``` Returns a reference to the `EventEmitter`, so that calls can be chained. #### Type Parameters [Section titled “Type Parameters”](#type-parameters-10) | Type Parameter | | -------------- | | `K` | #### Parameters [Section titled “Parameters”](#parameters-10) | Parameter | Type | Description | | ----------- | -------------------- | ---------------------- | | `eventName` | `Key`<`K`, `T`> | The name of the event. | | `listener` | `Listener`<`K`, `T`> | The callback function | #### Returns [Section titled “Returns”](#returns-12) `this` #### Since [Section titled “Since”](#since-15) v6.0.0 #### Inherited from [Section titled “Inherited from”](#inherited-from-12) ```ts NodeJS.EventEmitter.prependOnceListener ``` *** ### rawListeners() [Section titled “rawListeners()”](#rawlisteners) ```ts rawListeners(eventName): Listener[]; ``` Returns a copy of the array of listeners for the event named `eventName`, including any wrappers (such as those created by `.once()`). ```js import { EventEmitter } from 'node:events'; const emitter = new EventEmitter(); emitter.once('log', () => console.log('log once')); // Returns a new Array with a function `onceWrapper` which has a property // `listener` which contains the original listener bound above const listeners = emitter.rawListeners('log'); const logFnWrapper = listeners[0]; // Logs "log once" to the console and does not unbind the `once` event logFnWrapper.listener(); // Logs "log once" to the console and removes the listener logFnWrapper(); emitter.on('log', () => console.log('log persistently')); // Will return a new Array with a single function bound by `.on()` above const newListeners = emitter.rawListeners('log'); // Logs "log persistently" twice newListeners[0](); emitter.emit('log'); ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-11) | Type Parameter | | -------------- | | `K` | #### Parameters [Section titled “Parameters”](#parameters-11) | Parameter | Type | | ----------- | --------------- | | `eventName` | `Key`<`K`, `T`> | #### Returns [Section titled “Returns”](#returns-13) `Listener`<`K`, `T`, `Function`>\[] #### Since [Section titled “Since”](#since-16) v9.4.0 #### Inherited from [Section titled “Inherited from”](#inherited-from-13) ```ts NodeJS.EventEmitter.rawListeners ``` *** ### removeAllListeners() [Section titled “removeAllListeners()”](#removealllisteners) ```ts removeAllListeners(eventName?): this; ``` Removes all listeners, or those of the specified `eventName`. It is bad practice to remove listeners added elsewhere in the code, particularly when the `EventEmitter` instance was created by some other component or module (e.g. sockets or file streams). Returns a reference to the `EventEmitter`, so that calls can be chained. #### Parameters [Section titled “Parameters”](#parameters-12) | Parameter | Type | | ------------ | --------------------- | | `eventName?` | `Key`<`unknown`, `T`> | #### Returns [Section titled “Returns”](#returns-14) `this` #### Since [Section titled “Since”](#since-17) v0.1.26 #### Inherited from [Section titled “Inherited from”](#inherited-from-14) ```ts NodeJS.EventEmitter.removeAllListeners ``` *** ### removeListener() [Section titled “removeListener()”](#removelistener) ```ts removeListener(eventName, listener): this; ``` Removes the specified `listener` from the listener array for the event named `eventName`. ```js const callback = (stream) => { console.log('someone connected!'); }; server.on('connection', callback); // ... server.removeListener('connection', callback); ``` `removeListener()` will remove, at most, one instance of a listener from the listener array. If any single listener has been added multiple times to the listener array for the specified `eventName`, then `removeListener()` must be called multiple times to remove each instance. Once an event is emitted, all listeners attached to it at the time of emitting are called in order. This implies that any `removeListener()` or `removeAllListeners()` calls *after* emitting and *before* the last listener finishes execution will not remove them from`emit()` in progress. Subsequent events behave as expected. ```js import { EventEmitter } from 'node:events'; class MyEmitter extends EventEmitter {} const myEmitter = new MyEmitter(); const callbackA = () => { console.log('A'); myEmitter.removeListener('event', callbackB); }; const callbackB = () => { console.log('B'); }; myEmitter.on('event', callbackA); myEmitter.on('event', callbackB); // callbackA removes listener callbackB but it will still be called. // Internal listener array at time of emit [callbackA, callbackB] myEmitter.emit('event'); // Prints: // A // B // callbackB is now removed. // Internal listener array [callbackA] myEmitter.emit('event'); // Prints: // A ``` Because listeners are managed using an internal array, calling this will change the position indices of any listener registered *after* the listener being removed. This will not impact the order in which listeners are called, but it means that any copies of the listener array as returned by the `emitter.listeners()` method will need to be recreated. When a single function has been added as a handler multiple times for a single event (as in the example below), `removeListener()` will remove the most recently added instance. In the example the `once('ping')` listener is removed: ```js import { EventEmitter } from 'node:events'; const ee = new EventEmitter(); function pong() { console.log('pong'); } ee.on('ping', pong); ee.once('ping', pong); ee.removeListener('ping', pong); ee.emit('ping'); ee.emit('ping'); ``` Returns a reference to the `EventEmitter`, so that calls can be chained. #### Type Parameters [Section titled “Type Parameters”](#type-parameters-12) | Type Parameter | | -------------- | | `K` | #### Parameters [Section titled “Parameters”](#parameters-13) | Parameter | Type | | ----------- | -------------------- | | `eventName` | `Key`<`K`, `T`> | | `listener` | `Listener`<`K`, `T`> | #### Returns [Section titled “Returns”](#returns-15) `this` #### Since [Section titled “Since”](#since-18) v0.1.26 #### Inherited from [Section titled “Inherited from”](#inherited-from-15) ```ts NodeJS.EventEmitter.removeListener ``` *** ### setMaxListeners() [Section titled “setMaxListeners()”](#setmaxlisteners) ```ts setMaxListeners(n): this; ``` By default `EventEmitter`s will print a warning if more than `10` listeners are added for a particular event. This is a useful default that helps finding memory leaks. The `emitter.setMaxListeners()` method allows the limit to be modified for this specific `EventEmitter` instance. The value can be set to `Infinity` (or `0`) to indicate an unlimited number of listeners. Returns a reference to the `EventEmitter`, so that calls can be chained. #### Parameters [Section titled “Parameters”](#parameters-14) | Parameter | Type | | --------- | -------- | | `n` | `number` | #### Returns [Section titled “Returns”](#returns-16) `this` #### Since [Section titled “Since”](#since-19) v0.3.5 #### Inherited from [Section titled “Inherited from”](#inherited-from-16) ```ts NodeJS.EventEmitter.setMaxListeners ``` *** ### addAbortListener() [Section titled “addAbortListener()”](#addabortlistener) ```ts static addAbortListener(signal, resource): Disposable; ``` Listens once to the `abort` event on the provided `signal`. Listening to the `abort` event on abort signals is unsafe and may lead to resource leaks since another third party with the signal can call `e.stopImmediatePropagation()`. Unfortunately Node.js cannot change this since it would violate the web standard. Additionally, the original API makes it easy to forget to remove listeners. This API allows safely using `AbortSignal`s in Node.js APIs by solving these two issues by listening to the event such that `stopImmediatePropagation` does not prevent the listener from running. Returns a disposable so that it may be unsubscribed from more easily. ```js import { addAbortListener } from 'node:events'; function example(signal) { let disposable; try { signal.addEventListener('abort', (e) => e.stopImmediatePropagation()); disposable = addAbortListener(signal, (e) => { // Do something when signal is aborted. }); } finally { disposable?.[Symbol.dispose](); } } ``` #### Parameters [Section titled “Parameters”](#parameters-15) | Parameter | Type | | ---------- | ------------------- | | `signal` | `AbortSignal` | | `resource` | (`event`) => `void` | #### Returns [Section titled “Returns”](#returns-17) `Disposable` Disposable that removes the `abort` listener. #### Since [Section titled “Since”](#since-20) v20.5.0 *** ### getEventListeners() [Section titled “getEventListeners()”](#geteventlisteners) ```ts static getEventListeners(emitter, name): Function[]; ``` Returns a copy of the array of listeners for the event named `eventName`. For `EventEmitter`s this behaves exactly the same as calling `.listeners` on the emitter. For `EventTarget`s this is the only way to get the event listeners for the event target. This is useful for debugging and diagnostic purposes. ```js import { getEventListeners, EventEmitter } from 'node:events'; { const ee = new EventEmitter(); const listener = () => console.log('Events are fun'); ee.on('foo', listener); console.log(getEventListeners(ee, 'foo')); // [ [Function: listener] ] } { const et = new EventTarget(); const listener = () => console.log('Events are fun'); et.addEventListener('foo', listener); console.log(getEventListeners(et, 'foo')); // [ [Function: listener] ] } ``` #### Parameters [Section titled “Parameters”](#parameters-16) | Parameter | Type | | --------- | -------------------------------------------------- | | `emitter` | `EventTarget` \| `EventEmitter`<`DefaultEventMap`> | | `name` | `string` \| `symbol` | #### Returns [Section titled “Returns”](#returns-18) `Function`\[] #### Since [Section titled “Since”](#since-21) v15.2.0, v14.17.0 *** ### getMaxListeners() [Section titled “getMaxListeners()”](#getmaxlisteners-1) ```ts static getMaxListeners(emitter): number; ``` Returns the currently set max amount of listeners. For `EventEmitter`s this behaves exactly the same as calling `.getMaxListeners` on the emitter. For `EventTarget`s this is the only way to get the max event listeners for the event target. If the number of event handlers on a single EventTarget exceeds the max set, the EventTarget will print a warning. ```js import { getMaxListeners, setMaxListeners, EventEmitter } from 'node:events'; { const ee = new EventEmitter(); console.log(getMaxListeners(ee)); // 10 setMaxListeners(11, ee); console.log(getMaxListeners(ee)); // 11 } { const et = new EventTarget(); console.log(getMaxListeners(et)); // 10 setMaxListeners(11, et); console.log(getMaxListeners(et)); // 11 } ``` #### Parameters [Section titled “Parameters”](#parameters-17) | Parameter | Type | | --------- | -------------------------------------------------- | | `emitter` | `EventTarget` \| `EventEmitter`<`DefaultEventMap`> | #### Returns [Section titled “Returns”](#returns-19) `number` #### Since [Section titled “Since”](#since-22) v19.9.0 #### Inherited from [Section titled “Inherited from”](#inherited-from-17) ```ts NodeJS.EventEmitter.getMaxListeners ``` *** ### ~~listenerCount()~~ [Section titled “listenerCount()”](#listenercount-1) ```ts static listenerCount(emitter, eventName): number; ``` A class method that returns the number of listeners for the given `eventName` registered on the given `emitter`. ```js import { EventEmitter, listenerCount } from 'node:events'; const myEmitter = new EventEmitter(); myEmitter.on('event', () => {}); myEmitter.on('event', () => {}); console.log(listenerCount(myEmitter, 'event')); // Prints: 2 ``` Deprecated Since v3.2.0 - Use `listenerCount` instead. #### Parameters [Section titled “Parameters”](#parameters-18) | Parameter | Type | Description | | ----------- | -------------------- | -------------------- | | `emitter` | `EventEmitter` | The emitter to query | | `eventName` | `string` \| `symbol` | The event name | #### Returns [Section titled “Returns”](#returns-20) `number` #### Since [Section titled “Since”](#since-23) v0.9.12 #### Inherited from [Section titled “Inherited from”](#inherited-from-18) ```ts NodeJS.EventEmitter.listenerCount ``` *** ### on() [Section titled “on()”](#on-1) #### Call Signature [Section titled “Call Signature”](#call-signature) ```ts static on( emitter, eventName, options?): AsyncIterator; ``` ```js import { on, EventEmitter } from 'node:events'; import process from 'node:process'; const ee = new EventEmitter(); // Emit later on process.nextTick(() => { ee.emit('foo', 'bar'); ee.emit('foo', 42); }); for await (const event of on(ee, 'foo')) { // The execution of this inner block is synchronous and it // processes one event at a time (even with await). Do not use // if concurrent execution is required. console.log(event); // prints ['bar'] [42] } // Unreachable here ``` Returns an `AsyncIterator` that iterates `eventName` events. It will throw if the `EventEmitter` emits `'error'`. It removes all listeners when exiting the loop. The `value` returned by each iteration is an array composed of the emitted event arguments. An `AbortSignal` can be used to cancel waiting on events: ```js import { on, EventEmitter } from 'node:events'; import process from 'node:process'; const ac = new AbortController(); (async () => { const ee = new EventEmitter(); // Emit later on process.nextTick(() => { ee.emit('foo', 'bar'); ee.emit('foo', 42); }); for await (const event of on(ee, 'foo', { signal: ac.signal })) { // The execution of this inner block is synchronous and it // processes one event at a time (even with await). Do not use // if concurrent execution is required. console.log(event); // prints ['bar'] [42] } // Unreachable here })(); process.nextTick(() => ac.abort()); ``` Use the `close` option to specify an array of event names that will end the iteration: ```js import { on, EventEmitter } from 'node:events'; import process from 'node:process'; const ee = new EventEmitter(); // Emit later on process.nextTick(() => { ee.emit('foo', 'bar'); ee.emit('foo', 42); ee.emit('close'); }); for await (const event of on(ee, 'foo', { close: ['close'] })) { console.log(event); // prints ['bar'] [42] } // the loop will exit after 'close' is emitted console.log('done'); // prints 'done' ``` ##### Parameters [Section titled “Parameters”](#parameters-19) | Parameter | Type | | ----------- | ----------------------------------- | | `emitter` | `EventEmitter` | | `eventName` | `string` \| `symbol` | | `options?` | `StaticEventEmitterIteratorOptions` | ##### Returns [Section titled “Returns”](#returns-21) `AsyncIterator`<`any`\[]> An `AsyncIterator` that iterates `eventName` events emitted by the `emitter` ##### Since [Section titled “Since”](#since-24) v13.6.0, v12.16.0 ##### Inherited from [Section titled “Inherited from”](#inherited-from-19) ```ts NodeJS.EventEmitter.on ``` #### Call Signature [Section titled “Call Signature”](#call-signature-1) ```ts static on( emitter, eventName, options?): AsyncIterator; ``` ```js import { on, EventEmitter } from 'node:events'; import process from 'node:process'; const ee = new EventEmitter(); // Emit later on process.nextTick(() => { ee.emit('foo', 'bar'); ee.emit('foo', 42); }); for await (const event of on(ee, 'foo')) { // The execution of this inner block is synchronous and it // processes one event at a time (even with await). Do not use // if concurrent execution is required. console.log(event); // prints ['bar'] [42] } // Unreachable here ``` Returns an `AsyncIterator` that iterates `eventName` events. It will throw if the `EventEmitter` emits `'error'`. It removes all listeners when exiting the loop. The `value` returned by each iteration is an array composed of the emitted event arguments. An `AbortSignal` can be used to cancel waiting on events: ```js import { on, EventEmitter } from 'node:events'; import process from 'node:process'; const ac = new AbortController(); (async () => { const ee = new EventEmitter(); // Emit later on process.nextTick(() => { ee.emit('foo', 'bar'); ee.emit('foo', 42); }); for await (const event of on(ee, 'foo', { signal: ac.signal })) { // The execution of this inner block is synchronous and it // processes one event at a time (even with await). Do not use // if concurrent execution is required. console.log(event); // prints ['bar'] [42] } // Unreachable here })(); process.nextTick(() => ac.abort()); ``` Use the `close` option to specify an array of event names that will end the iteration: ```js import { on, EventEmitter } from 'node:events'; import process from 'node:process'; const ee = new EventEmitter(); // Emit later on process.nextTick(() => { ee.emit('foo', 'bar'); ee.emit('foo', 42); ee.emit('close'); }); for await (const event of on(ee, 'foo', { close: ['close'] })) { console.log(event); // prints ['bar'] [42] } // the loop will exit after 'close' is emitted console.log('done'); // prints 'done' ``` ##### Parameters [Section titled “Parameters”](#parameters-20) | Parameter | Type | | ----------- | ----------------------------------- | | `emitter` | `EventTarget` | | `eventName` | `string` | | `options?` | `StaticEventEmitterIteratorOptions` | ##### Returns [Section titled “Returns”](#returns-22) `AsyncIterator`<`any`\[]> An `AsyncIterator` that iterates `eventName` events emitted by the `emitter` ##### Since [Section titled “Since”](#since-25) v13.6.0, v12.16.0 ##### Inherited from [Section titled “Inherited from”](#inherited-from-20) ```ts NodeJS.EventEmitter.on ``` *** ### once() [Section titled “once()”](#once-1) #### Call Signature [Section titled “Call Signature”](#call-signature-2) ```ts static once( emitter, eventName, options?): Promise; ``` Creates a `Promise` that is fulfilled when the `EventEmitter` emits the given event or that is rejected if the `EventEmitter` emits `'error'` while waiting. The `Promise` will resolve with an array of all the arguments emitted to the given event. This method is intentionally generic and works with the web platform [EventTarget](https://dom.spec.whatwg.org/#interface-eventtarget) interface, which has no special`'error'` event semantics and does not listen to the `'error'` event. ```js import { once, EventEmitter } from 'node:events'; import process from 'node:process'; const ee = new EventEmitter(); process.nextTick(() => { ee.emit('myevent', 42); }); const [value] = await once(ee, 'myevent'); console.log(value); const err = new Error('kaboom'); process.nextTick(() => { ee.emit('error', err); }); try { await once(ee, 'myevent'); } catch (err) { console.error('error happened', err); } ``` The special handling of the `'error'` event is only used when `events.once()` is used to wait for another event. If `events.once()` is used to wait for the ‘`error'` event itself, then it is treated as any other kind of event without special handling: ```js import { EventEmitter, once } from 'node:events'; const ee = new EventEmitter(); once(ee, 'error') .then(([err]) => console.log('ok', err.message)) .catch((err) => console.error('error', err.message)); ee.emit('error', new Error('boom')); // Prints: ok boom ``` An `AbortSignal` can be used to cancel waiting for the event: ```js import { EventEmitter, once } from 'node:events'; const ee = new EventEmitter(); const ac = new AbortController(); async function foo(emitter, event, signal) { try { await once(emitter, event, { signal }); console.log('event emitted!'); } catch (error) { if (error.name === 'AbortError') { console.error('Waiting for the event was canceled!'); } else { console.error('There was an error', error.message); } } } foo(ee, 'foo', ac.signal); ac.abort(); // Abort waiting for the event ee.emit('foo'); // Prints: Waiting for the event was canceled! ``` ##### Parameters [Section titled “Parameters”](#parameters-21) | Parameter | Type | | ----------- | --------------------------- | | `emitter` | `EventEmitter` | | `eventName` | `string` \| `symbol` | | `options?` | `StaticEventEmitterOptions` | ##### Returns [Section titled “Returns”](#returns-23) `Promise`<`any`\[]> ##### Since [Section titled “Since”](#since-26) v11.13.0, v10.16.0 ##### Inherited from [Section titled “Inherited from”](#inherited-from-21) ```ts NodeJS.EventEmitter.once ``` #### Call Signature [Section titled “Call Signature”](#call-signature-3) ```ts static once( emitter, eventName, options?): Promise; ``` Creates a `Promise` that is fulfilled when the `EventEmitter` emits the given event or that is rejected if the `EventEmitter` emits `'error'` while waiting. The `Promise` will resolve with an array of all the arguments emitted to the given event. This method is intentionally generic and works with the web platform [EventTarget](https://dom.spec.whatwg.org/#interface-eventtarget) interface, which has no special`'error'` event semantics and does not listen to the `'error'` event. ```js import { once, EventEmitter } from 'node:events'; import process from 'node:process'; const ee = new EventEmitter(); process.nextTick(() => { ee.emit('myevent', 42); }); const [value] = await once(ee, 'myevent'); console.log(value); const err = new Error('kaboom'); process.nextTick(() => { ee.emit('error', err); }); try { await once(ee, 'myevent'); } catch (err) { console.error('error happened', err); } ``` The special handling of the `'error'` event is only used when `events.once()` is used to wait for another event. If `events.once()` is used to wait for the ‘`error'` event itself, then it is treated as any other kind of event without special handling: ```js import { EventEmitter, once } from 'node:events'; const ee = new EventEmitter(); once(ee, 'error') .then(([err]) => console.log('ok', err.message)) .catch((err) => console.error('error', err.message)); ee.emit('error', new Error('boom')); // Prints: ok boom ``` An `AbortSignal` can be used to cancel waiting for the event: ```js import { EventEmitter, once } from 'node:events'; const ee = new EventEmitter(); const ac = new AbortController(); async function foo(emitter, event, signal) { try { await once(emitter, event, { signal }); console.log('event emitted!'); } catch (error) { if (error.name === 'AbortError') { console.error('Waiting for the event was canceled!'); } else { console.error('There was an error', error.message); } } } foo(ee, 'foo', ac.signal); ac.abort(); // Abort waiting for the event ee.emit('foo'); // Prints: Waiting for the event was canceled! ``` ##### Parameters [Section titled “Parameters”](#parameters-22) | Parameter | Type | | ----------- | --------------------------- | | `emitter` | `EventTarget` | | `eventName` | `string` | | `options?` | `StaticEventEmitterOptions` | ##### Returns [Section titled “Returns”](#returns-24) `Promise`<`any`\[]> ##### Since [Section titled “Since”](#since-27) v11.13.0, v10.16.0 ##### Inherited from [Section titled “Inherited from”](#inherited-from-22) ```ts NodeJS.EventEmitter.once ``` *** ### setMaxListeners() [Section titled “setMaxListeners()”](#setmaxlisteners-1) ```ts static setMaxListeners(n?, ...eventTargets): void; ``` ```js import { setMaxListeners, EventEmitter } from 'node:events'; const target = new EventTarget(); const emitter = new EventEmitter(); setMaxListeners(5, target, emitter); ``` #### Parameters [Section titled “Parameters”](#parameters-23) | Parameter | Type | Description | | ---------------- | ------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `n?` | `number` | A non-negative number. The maximum number of listeners per `EventTarget` event. | | …`eventTargets?` | (`EventTarget` \| `EventEmitter`<`DefaultEventMap`>)\[] | Zero or more {EventTarget} or {EventEmitter} instances. If none are specified, `n` is set as the default max for all newly created {EventTarget} and {EventEmitter} objects. | #### Returns [Section titled “Returns”](#returns-25) `void` #### Since [Section titled “Since”](#since-28) v15.4.0 #### Inherited from [Section titled “Inherited from”](#inherited-from-23) ```ts NodeJS.EventEmitter.setMaxListeners ``` # RunToolApprovalItem ## Extends [Section titled “Extends”](#extends) * `RunItemBase` ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new RunToolApprovalItem( rawItem, agent, toolName?): RunToolApprovalItem; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------- | | `rawItem` | \| { `arguments?`: `string`; `id?`: `string`; `name`: `string`; `output?`: `string`; `providerData?`: `Record`<`string`, `any`>; `status?`: `string`; `type`: `"hosted_tool_call"`; } \| { `arguments`: `string`; `callId`: `string`; `id?`: `string`; `name`: `string`; `namespace?`: `string`; `providerData?`: `Record`<`string`, `any`>; `status?`: `"in_progress"` \| `"completed"` \| `"incomplete"`; `type`: `"function_call"`; } \| { `action?`: \| { `type`: `"screenshot"`; } \| { `button`: `"left"` \| `"right"` \| `"wheel"` \| `"back"` \| `"forward"`; `type`: `"click"`; `x`: `number`; `y`: `number`; } \| { `type`: `"double_click"`; `x`: `number`; `y`: `number`; } \| { `scroll_x`: `number`; `scroll_y`: `number`; `type`: `"scroll"`; `x`: `number`; `y`: `number`; } \| { `text`: `string`; `type`: `"type"`; } \| { `type`: `"wait"`; } \| { `type`: `"move"`; `x`: `number`; `y`: `number`; } \| { `keys`: `string`\[]; `type`: `"keypress"`; } \| { `path`: `object`\[]; `type`: `"drag"`; }; `actions?`: ( \| { `type`: `"screenshot"`; } \| { `button`: `"left"` \| `"right"` \| `"wheel"` \| `"back"` \| `"forward"`; `type`: `"click"`; `x`: `number`; `y`: `number`; } \| { `type`: `"double_click"`; `x`: `number`; `y`: `number`; } \| { `scroll_x`: `number`; `scroll_y`: `number`; `type`: `"scroll"`; `x`: `number`; `y`: `number`; } \| { `text`: `string`; `type`: `"type"`; } \| { `type`: `"wait"`; } \| { `type`: `"move"`; `x`: `number`; `y`: `number`; } \| { `keys`: `string`\[]; `type`: `"keypress"`; } \| { `path`: `object`\[]; `type`: `"drag"`; })\[]; `callId`: `string`; `id?`: `string`; `providerData?`: `Record`<`string`, `any`>; `status`: `"in_progress"` \| `"completed"` \| `"incomplete"`; `type`: `"computer_call"`; } \| { `action`: { `commands`: `string`\[]; `maxOutputLength?`: `number`; `timeoutMs?`: `number`; }; `callId`: `string`; `id?`: `string`; `providerData?`: `Record`<`string`, `any`>; `status?`: `"in_progress"` \| `"completed"` \| `"incomplete"`; `type`: `"shell_call"`; } \| { `callId`: `string`; `id?`: `string`; `operation`: \| { `diff`: `string`; `path`: `string`; `type`: `"create_file"`; } \| { `diff`: `string`; `moveTo?`: `string`; `path`: `string`; `type`: `"update_file"`; } \| { `path`: `string`; `type`: `"delete_file"`; }; `providerData?`: `Record`<`string`, `any`>; `status`: `"in_progress"` \| `"completed"`; `type`: `"apply_patch_call"`; } | ‐ | | `agent` | [`Agent`](/openai-agents-js/openai/agents-core/classes/agent/)<`any`, `any`> | ‐ | | `toolName?` | `string` | Explicit tool name to use for approval tracking when not present on the raw item. | #### Returns [Section titled “Returns”](#returns) `RunToolApprovalItem` #### Overrides [Section titled “Overrides”](#overrides) ```ts RunItemBase.constructor ``` ## Properties [Section titled “Properties”](#properties) ### agent [Section titled “agent”](#agent) ```ts agent: Agent; ``` *** ### rawItem [Section titled “rawItem”](#rawitem) ```ts rawItem: | { arguments?: string; id?: string; name: string; output?: string; providerData?: Record; status?: string; type: "hosted_tool_call"; } | { arguments: string; callId: string; id?: string; name: string; namespace?: string; providerData?: Record; status?: "in_progress" | "completed" | "incomplete"; type: "function_call"; } | { action?: | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; }; actions?: ( | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; })[]; callId: string; id?: string; providerData?: Record; status: "in_progress" | "completed" | "incomplete"; type: "computer_call"; } | { action: { commands: string[]; maxOutputLength?: number; timeoutMs?: number; }; callId: string; id?: string; providerData?: Record; status?: "in_progress" | "completed" | "incomplete"; type: "shell_call"; } | { callId: string; id?: string; operation: | { diff: string; path: string; type: "create_file"; } | { diff: string; moveTo?: string; path: string; type: "update_file"; } | { path: string; type: "delete_file"; }; providerData?: Record; status: "in_progress" | "completed"; type: "apply_patch_call"; }; ``` #### Union Members [Section titled “Union Members”](#union-members) ##### Type Literal [Section titled “Type Literal”](#type-literal) ```ts { arguments?: string; id?: string; name: string; output?: string; providerData?: Record; status?: string; type: "hosted_tool_call"; } ``` | Name | Type | Description | | --------------- | ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `arguments?` | `string` | The arguments of the hosted tool call. | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `name` | `string` | The name of the hosted tool. For example `web_search_call` or `file_search_call` | | `output?` | `string` | The primary output of the tool call. Additional output might be in the `providerData` field. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status?` | `string` | The status of the tool call. | | `type` | `"hosted_tool_call"` | ‐ | *** ##### Type Literal [Section titled “Type Literal”](#type-literal-1) ```ts { arguments: string; callId: string; id?: string; name: string; namespace?: string; providerData?: Record; status?: "in_progress" | "completed" | "incomplete"; type: "function_call"; } ``` | Name | Type | Description | | --------------- | -------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `arguments` | `string` | The arguments of the function call. | | `callId` | `string` | The ID of the tool call. Required to match up the respective tool call result. | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `name` | `string` | The name of the function. | | `namespace?` | `string` | Optional namespace used to qualify the function name for tool search. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status?` | `"in_progress"` \| `"completed"` \| `"incomplete"` | The status of the function call. | | `type` | `"function_call"` | ‐ | *** ##### Type Literal [Section titled “Type Literal”](#type-literal-2) ```ts { action?: | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; }; actions?: ( | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; })[]; callId: string; id?: string; providerData?: Record; status: "in_progress" | "completed" | "incomplete"; type: "computer_call"; } ``` | Name | Type | Description | | --------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `action?` | \| { `type`: `"screenshot"`; } \| { `button`: `"left"` \| `"right"` \| `"wheel"` \| `"back"` \| `"forward"`; `type`: `"click"`; `x`: `number`; `y`: `number`; } \| { `type`: `"double_click"`; `x`: `number`; `y`: `number`; } \| { `scroll_x`: `number`; `scroll_y`: `number`; `type`: `"scroll"`; `x`: `number`; `y`: `number`; } \| { `text`: `string`; `type`: `"type"`; } \| { `type`: `"wait"`; } \| { `type`: `"move"`; `x`: `number`; `y`: `number`; } \| { `keys`: `string`\[]; `type`: `"keypress"`; } \| { `path`: `object`\[]; `type`: `"drag"`; } | The legacy single action to be performed by the computer. | | `actions?` | ( \| { `type`: `"screenshot"`; } \| { `button`: `"left"` \| `"right"` \| `"wheel"` \| `"back"` \| `"forward"`; `type`: `"click"`; `x`: `number`; `y`: `number`; } \| { `type`: `"double_click"`; `x`: `number`; `y`: `number`; } \| { `scroll_x`: `number`; `scroll_y`: `number`; `type`: `"scroll"`; `x`: `number`; `y`: `number`; } \| { `text`: `string`; `type`: `"type"`; } \| { `type`: `"wait"`; } \| { `type`: `"move"`; `x`: `number`; `y`: `number`; } \| { `keys`: `string`\[]; `type`: `"keypress"`; } \| { `path`: `object`\[]; `type`: `"drag"`; })\[] | Batched actions returned by the GA computer tool. | | `callId` | `string` | The ID of the computer call. Required to match up the respective computer call result. | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status` | `"in_progress"` \| `"completed"` \| `"incomplete"` | The status of the computer call. | | `type` | `"computer_call"` | ‐ | *** ##### Type Literal [Section titled “Type Literal”](#type-literal-3) ```ts { action: { commands: string[]; maxOutputLength?: number; timeoutMs?: number; }; callId: string; id?: string; providerData?: Record; status?: "in_progress" | "completed" | "incomplete"; type: "shell_call"; } ``` | Name | Type | Default value | Description | | ------------------------- | -------------------------------------------------- | ------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `action` | `object` | `ShellAction` | ‐ | | `action.commands` | `string`\[] | ‐ | ‐ | | `action.maxOutputLength?` | `number` | ‐ | ‐ | | `action.timeoutMs?` | `number` | ‐ | ‐ | | `callId` | `string` | ‐ | ‐ | | `id?` | `string` | ‐ | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `providerData?` | `Record`<`string`, `any`> | ‐ | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status?` | `"in_progress"` \| `"completed"` \| `"incomplete"` | ‐ | ‐ | | `type` | `"shell_call"` | ‐ | ‐ | *** ##### Type Literal [Section titled “Type Literal”](#type-literal-4) ```ts { callId: string; id?: string; operation: | { diff: string; path: string; type: "create_file"; } | { diff: string; moveTo?: string; path: string; type: "update_file"; } | { path: string; type: "delete_file"; }; providerData?: Record; status: "in_progress" | "completed"; type: "apply_patch_call"; } ``` | Name | Type | Default value | Description | | --------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `callId` | `string` | ‐ | ‐ | | `id?` | `string` | ‐ | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `operation` | \| { `diff`: `string`; `path`: `string`; `type`: `"create_file"`; } \| { `diff`: `string`; `moveTo?`: `string`; `path`: `string`; `type`: `"update_file"`; } \| { `path`: `string`; `type`: `"delete_file"`; } | `ApplyPatchOperation` | ‐ | | `providerData?` | `Record`<`string`, `any`> | ‐ | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status` | `"in_progress"` \| `"completed"` | ‐ | ‐ | | `type` | `"apply_patch_call"` | ‐ | ‐ | #### Inherited from [Section titled “Inherited from”](#inherited-from) ```ts RunItemBase.rawItem ``` *** ### toolName? [Section titled “toolName?”](#toolname) ```ts optional toolName?: string; ``` Explicit tool name to use for approval tracking when not present on the raw item. *** ### type [Section titled “type”](#type) ```ts readonly type: "tool_approval_item"; ``` #### Overrides [Section titled “Overrides”](#overrides-1) ```ts RunItemBase.type ``` ## Accessors [Section titled “Accessors”](#accessors) ### arguments [Section titled “arguments”](#arguments) #### Get Signature [Section titled “Get Signature”](#get-signature) ```ts get arguments(): string | undefined; ``` Returns the arguments if the raw item has an arguments property otherwise this will be undefined. ##### Returns [Section titled “Returns”](#returns-1) `string` | `undefined` *** ### name [Section titled “name”](#name) #### Get Signature [Section titled “Get Signature”](#get-signature-1) ```ts get name(): string | undefined; ``` Returns the tool name if available on the raw item or provided explicitly. Kept for backwards compatibility with code that previously relied on `rawItem.name`. ##### Returns [Section titled “Returns”](#returns-2) `string` | `undefined` ## Methods [Section titled “Methods”](#methods) ### toJSON() [Section titled “toJSON()”](#tojson) ```ts toJSON(): object; ``` #### Returns [Section titled “Returns”](#returns-3) `object` ##### agent [Section titled “agent”](#agent-1) ```ts agent: object; ``` ###### agent.name [Section titled “agent.name”](#agentname) ```ts name: string; ``` ##### rawItem [Section titled “rawItem”](#rawitem-1) ```ts rawItem: | { content: ( | { providerData?: Record; refusal: string; type: "refusal"; } | { providerData?: Record; text: string; type: "output_text"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; } | { image: string; providerData?: Record; type: "image"; })[]; id?: string; providerData?: Record; role: "assistant"; status: "in_progress" | "completed" | "incomplete"; type?: "message"; } | { content: | string | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; })[]; id?: string; providerData?: Record; role: "user"; type?: "message"; } | { content: string; id?: string; providerData?: Record; role: "system"; type?: "message"; } | { arguments?: string; id?: string; name: string; output?: string; providerData?: Record; status?: string; type: "hosted_tool_call"; } | { arguments: string; callId: string; id?: string; name: string; namespace?: string; providerData?: Record; status?: "in_progress" | "completed" | "incomplete"; type: "function_call"; } | { arguments: unknown; call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; type: "tool_search_call"; } | { call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; tools: Record[]; type: "tool_search_output"; } | { callId: string; id?: string; name: string; namespace?: string; output: | string | { providerData?: Record; text: string; type: "text"; } | { detail?: "low" | "high" | "auto" | string & object; image?: | string | { data: string | Uint8Array; mediaType?: string; } | { url: string; } | { fileId: string; }; providerData?: Record; type: "image"; } | { file: | string | { data: string | Uint8Array; filename: string; mediaType: string; } | { filename?: string; url: string; } | { filename?: string; id: string; }; providerData?: Record; type: "file"; } | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; })[]; providerData?: Record; status: "in_progress" | "completed" | "incomplete"; type: "function_call_result"; } | { action?: | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; }; actions?: ( | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; })[]; callId: string; id?: string; providerData?: Record; status: "in_progress" | "completed" | "incomplete"; type: "computer_call"; } | { callId: string; id?: string; output: { data: string; providerData?: Record; type: "computer_screenshot"; }; providerData?: Record; type: "computer_call_result"; } | { action: { commands: string[]; maxOutputLength?: number; timeoutMs?: number; }; callId: string; id?: string; providerData?: Record; status?: "in_progress" | "completed" | "incomplete"; type: "shell_call"; } | { callId: string; id?: string; maxOutputLength?: number; output: object[]; providerData?: Record; type: "shell_call_output"; } | { callId: string; id?: string; operation: | { diff: string; path: string; type: "create_file"; } | { diff: string; moveTo?: string; path: string; type: "update_file"; } | { path: string; type: "delete_file"; }; providerData?: Record; status: "in_progress" | "completed"; type: "apply_patch_call"; } | { callId: string; id?: string; output?: string; providerData?: Record; status: "completed" | "failed"; type: "apply_patch_call_output"; } | { content: object[]; id?: string; providerData?: Record; rawContent?: object[]; type: "reasoning"; } | { created_by?: string; encrypted_content: string; id?: string; providerData?: Record; type: "compaction"; } | { id?: string; providerData?: Record; type: "unknown"; } | undefined; ``` ###### Union Members [Section titled “Union Members”](#union-members-1) ###### Type Literal [Section titled “Type Literal”](#type-literal-5) ```ts { content: ( | { providerData?: Record; refusal: string; type: "refusal"; } | { providerData?: Record; text: string; type: "output_text"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; } | { image: string; providerData?: Record; type: "image"; })[]; id?: string; providerData?: Record; role: "assistant"; status: "in_progress" | "completed" | "incomplete"; type?: "message"; } ``` | Name | Type | Description | | --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `content` | ( \| { `providerData?`: `Record`<`string`, `any`>; `refusal`: `string`; `type`: `"refusal"`; } \| { `providerData?`: `Record`<`string`, `any`>; `text`: `string`; `type`: `"output_text"`; } \| { `audio`: \| `string` \| { `id`: `string`; }; `format?`: `string` \| `null`; `providerData?`: `Record`<`string`, `any`>; `transcript?`: `string` \| `null`; `type`: `"audio"`; } \| { `image`: `string`; `providerData?`: `Record`<`string`, `any`>; `type`: `"image"`; })\[] | The content of the message. | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `role` | `"assistant"` | Representing a message from the assistant (i.e. the model) | | `status` | `"in_progress"` \| `"completed"` \| `"incomplete"` | The status of the message. | | `type?` | `"message"` | Any item without a type is treated as a message | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-6) ```ts { content: | string | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; })[]; id?: string; providerData?: Record; role: "user"; type?: "message"; } ``` | Name | Type | Description | | --------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `content` | \| `string` \| ( \| { `providerData?`: `Record`<`string`, `any`>; `text`: `string`; `type`: `"input_text"`; } \| { `detail?`: `string`; `image?`: \| `string` \| { `id`: `string`; }; `providerData?`: `Record`<`string`, `any`>; `type`: `"input_image"`; } \| { `file?`: \| `string` \| { `id`: `string`; } \| { `url`: `string`; }; `filename?`: `string`; `providerData?`: `Record`<`string`, `any`>; `type`: `"input_file"`; } \| { `audio`: \| `string` \| { `id`: `string`; }; `format?`: `string` \| `null`; `providerData?`: `Record`<`string`, `any`>; `transcript?`: `string` \| `null`; `type`: `"audio"`; })\[] | The content of the message. | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `role` | `"user"` | Representing a message from the user | | `type?` | `"message"` | Any item without a type is treated as a message | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-7) ```ts { content: string; id?: string; providerData?: Record; role: "system"; type?: "message"; } ``` | Name | Type | Description | | --------------- | ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `content` | `string` | The content of the message. | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `role` | `"system"` | Representing a system message to the user | | `type?` | `"message"` | Any item without a type is treated as a message | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-8) ```ts { arguments?: string; id?: string; name: string; output?: string; providerData?: Record; status?: string; type: "hosted_tool_call"; } ``` | Name | Type | Description | | --------------- | ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `arguments?` | `string` | The arguments of the hosted tool call. | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `name` | `string` | The name of the hosted tool. For example `web_search_call` or `file_search_call` | | `output?` | `string` | The primary output of the tool call. Additional output might be in the `providerData` field. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status?` | `string` | The status of the tool call. | | `type` | `"hosted_tool_call"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-9) ```ts { arguments: string; callId: string; id?: string; name: string; namespace?: string; providerData?: Record; status?: "in_progress" | "completed" | "incomplete"; type: "function_call"; } ``` | Name | Type | Description | | --------------- | -------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `arguments` | `string` | The arguments of the function call. | | `callId` | `string` | The ID of the tool call. Required to match up the respective tool call result. | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `name` | `string` | The name of the function. | | `namespace?` | `string` | Optional namespace used to qualify the function name for tool search. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status?` | `"in_progress"` \| `"completed"` \| `"incomplete"` | The status of the function call. | | `type` | `"function_call"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-10) ```ts { arguments: unknown; call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; type: "tool_search_call"; } ``` | Name | Type | Default value | Description | | --------------- | ------------------------- | ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `arguments` | `unknown` | `ToolSearchCallArguments` | ‐ | | `call_id?` | `string` \| `null` | ‐ | ‐ | | `callId?` | `string` \| `null` | ‐ | ‐ | | `execution?` | `"client"` \| `"server"` | ‐ | ‐ | | `id?` | `string` | ‐ | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `providerData?` | `Record`<`string`, `any`> | ‐ | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status?` | `string` | ‐ | ‐ | | `type` | `"tool_search_call"` | ‐ | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-11) ```ts { call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; tools: Record[]; type: "tool_search_output"; } ``` | Name | Type | Description | | --------------- | ---------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `call_id?` | `string` \| `null` | ‐ | | `callId?` | `string` \| `null` | ‐ | | `execution?` | `"client"` \| `"server"` | ‐ | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status?` | `string` | ‐ | | `tools` | `Record`<`string`, `any`>\[] | ‐ | | `type` | `"tool_search_output"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-12) ```ts { callId: string; id?: string; name: string; namespace?: string; output: | string | { providerData?: Record; text: string; type: "text"; } | { detail?: "low" | "high" | "auto" | string & object; image?: | string | { data: string | Uint8Array; mediaType?: string; } | { url: string; } | { fileId: string; }; providerData?: Record; type: "image"; } | { file: | string | { data: string | Uint8Array; filename: string; mediaType: string; } | { filename?: string; url: string; } | { filename?: string; id: string; }; providerData?: Record; type: "file"; } | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; })[]; providerData?: Record; status: "in_progress" | "completed" | "incomplete"; type: "function_call_result"; } ``` | Name | Type | Description | | --------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `callId` | `string` | The ID of the tool call. Required to match up the respective tool call result. | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `name` | `string` | The name of the tool that was called | | `namespace?` | `string` | Optional namespace preserved from the originating function call. | | `output` | \| `string` \| { `providerData?`: `Record`<`string`, `any`>; `text`: `string`; `type`: `"text"`; } \| { `detail?`: `"low"` \| `"high"` \| `"auto"` \| `string` & `object`; `image?`: \| `string` \| { `data`: `string` \| `Uint8Array`<`ArrayBuffer`>; `mediaType?`: `string`; } \| { `url`: `string`; } \| { `fileId`: `string`; }; `providerData?`: `Record`<`string`, `any`>; `type`: `"image"`; } \| { `file`: \| `string` \| { `data`: `string` \| `Uint8Array`<`ArrayBuffer`>; `filename`: `string`; `mediaType`: `string`; } \| { `filename?`: `string`; `url`: `string`; } \| { `filename?`: `string`; `id`: `string`; }; `providerData?`: `Record`<`string`, `any`>; `type`: `"file"`; } \| ( \| { `providerData?`: `Record`<`string`, `any`>; `text`: `string`; `type`: `"input_text"`; } \| { `detail?`: `string`; `image?`: \| `string` \| { `id`: `string`; }; `providerData?`: `Record`<`string`, `any`>; `type`: `"input_image"`; } \| { `file?`: \| `string` \| { `id`: `string`; } \| { `url`: `string`; }; `filename?`: `string`; `providerData?`: `Record`<`string`, `any`>; `type`: `"input_file"`; })\[] | The output of the tool call. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status` | `"in_progress"` \| `"completed"` \| `"incomplete"` | The status of the tool call. | | `type` | `"function_call_result"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-13) ```ts { action?: | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; }; actions?: ( | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; })[]; callId: string; id?: string; providerData?: Record; status: "in_progress" | "completed" | "incomplete"; type: "computer_call"; } ``` | Name | Type | Description | | --------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `action?` | \| { `type`: `"screenshot"`; } \| { `button`: `"left"` \| `"right"` \| `"wheel"` \| `"back"` \| `"forward"`; `type`: `"click"`; `x`: `number`; `y`: `number`; } \| { `type`: `"double_click"`; `x`: `number`; `y`: `number`; } \| { `scroll_x`: `number`; `scroll_y`: `number`; `type`: `"scroll"`; `x`: `number`; `y`: `number`; } \| { `text`: `string`; `type`: `"type"`; } \| { `type`: `"wait"`; } \| { `type`: `"move"`; `x`: `number`; `y`: `number`; } \| { `keys`: `string`\[]; `type`: `"keypress"`; } \| { `path`: `object`\[]; `type`: `"drag"`; } | The legacy single action to be performed by the computer. | | `actions?` | ( \| { `type`: `"screenshot"`; } \| { `button`: `"left"` \| `"right"` \| `"wheel"` \| `"back"` \| `"forward"`; `type`: `"click"`; `x`: `number`; `y`: `number`; } \| { `type`: `"double_click"`; `x`: `number`; `y`: `number`; } \| { `scroll_x`: `number`; `scroll_y`: `number`; `type`: `"scroll"`; `x`: `number`; `y`: `number`; } \| { `text`: `string`; `type`: `"type"`; } \| { `type`: `"wait"`; } \| { `type`: `"move"`; `x`: `number`; `y`: `number`; } \| { `keys`: `string`\[]; `type`: `"keypress"`; } \| { `path`: `object`\[]; `type`: `"drag"`; })\[] | Batched actions returned by the GA computer tool. | | `callId` | `string` | The ID of the computer call. Required to match up the respective computer call result. | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status` | `"in_progress"` \| `"completed"` \| `"incomplete"` | The status of the computer call. | | `type` | `"computer_call"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-14) ```ts { callId: string; id?: string; output: { data: string; providerData?: Record; type: "computer_screenshot"; }; providerData?: Record; type: "computer_call_result"; } ``` | Name | Type | Default value | Description | | ---------------------- | ------------------------- | -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `callId` | `string` | ‐ | The ID of the computer call. Required to match up the respective computer call result. | | `id?` | `string` | ‐ | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `output` | `object` | `ComputerToolOutput` | The output of the computer call. | | `output.data` | `string` | ‐ | A base64 encoded image data or a URL representing the screenshot. | | `output.providerData?` | `Record`<`string`, `any`> | ‐ | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `output.type` | `"computer_screenshot"` | ‐ | ‐ | | `providerData?` | `Record`<`string`, `any`> | ‐ | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `type` | `"computer_call_result"` | ‐ | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-15) ```ts { action: { commands: string[]; maxOutputLength?: number; timeoutMs?: number; }; callId: string; id?: string; providerData?: Record; status?: "in_progress" | "completed" | "incomplete"; type: "shell_call"; } ``` | Name | Type | Default value | Description | | ------------------------- | -------------------------------------------------- | ------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `action` | `object` | `ShellAction` | ‐ | | `action.commands` | `string`\[] | ‐ | ‐ | | `action.maxOutputLength?` | `number` | ‐ | ‐ | | `action.timeoutMs?` | `number` | ‐ | ‐ | | `callId` | `string` | ‐ | ‐ | | `id?` | `string` | ‐ | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `providerData?` | `Record`<`string`, `any`> | ‐ | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status?` | `"in_progress"` \| `"completed"` \| `"incomplete"` | ‐ | ‐ | | `type` | `"shell_call"` | ‐ | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-16) ```ts { callId: string; id?: string; maxOutputLength?: number; output: object[]; providerData?: Record; type: "shell_call_output"; } ``` | Name | Type | Description | | ------------------ | ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `callId` | `string` | ‐ | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `maxOutputLength?` | `number` | ‐ | | `output` | `object`\[] | ‐ | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `type` | `"shell_call_output"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-17) ```ts { callId: string; id?: string; operation: | { diff: string; path: string; type: "create_file"; } | { diff: string; moveTo?: string; path: string; type: "update_file"; } | { path: string; type: "delete_file"; }; providerData?: Record; status: "in_progress" | "completed"; type: "apply_patch_call"; } ``` | Name | Type | Default value | Description | | --------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `callId` | `string` | ‐ | ‐ | | `id?` | `string` | ‐ | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `operation` | \| { `diff`: `string`; `path`: `string`; `type`: `"create_file"`; } \| { `diff`: `string`; `moveTo?`: `string`; `path`: `string`; `type`: `"update_file"`; } \| { `path`: `string`; `type`: `"delete_file"`; } | `ApplyPatchOperation` | ‐ | | `providerData?` | `Record`<`string`, `any`> | ‐ | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status` | `"in_progress"` \| `"completed"` | ‐ | ‐ | | `type` | `"apply_patch_call"` | ‐ | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-18) ```ts { callId: string; id?: string; output?: string; providerData?: Record; status: "completed" | "failed"; type: "apply_patch_call_output"; } ``` | Name | Type | Description | | --------------- | --------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `callId` | `string` | ‐ | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `output?` | `string` | ‐ | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status` | `"completed"` \| `"failed"` | ‐ | | `type` | `"apply_patch_call_output"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-19) ```ts { content: object[]; id?: string; providerData?: Record; rawContent?: object[]; type: "reasoning"; } ``` | Name | Type | Description | | --------------- | ------------------------- | ------------------------------------------------------------------------------------------------------------- | | `content` | `object`\[] | The user facing representation of the reasoning. Additional information might be in the `providerData` field. | | `id?` | `string` | ‐ | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `rawContent?` | `object`\[] | The raw reasoning text from the model. | | `type` | `"reasoning"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-20) ```ts { created_by?: string; encrypted_content: string; id?: string; providerData?: Record; type: "compaction"; } ``` | Name | Type | Description | | ------------------- | ------------------------- | ------------------------------------------------------------------------------------------------------------ | | `created_by?` | `string` | Identifier for the generator of this compaction item. | | `encrypted_content` | `string` | Encrypted payload returned by the compaction endpoint. | | `id?` | `string` | Identifier for the compaction item. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `type` | `"compaction"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-21) ```ts { id?: string; providerData?: Record; type: "unknown"; } ``` | Name | Type | Description | | --------------- | ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `type` | `"unknown"` | ‐ | *** `undefined` ##### toolName [Section titled “toolName”](#toolname-1) ```ts toolName: string | undefined; ``` ##### type [Section titled “type”](#type-1) ```ts type: string; ``` #### Overrides [Section titled “Overrides”](#overrides-2) ```ts RunItemBase.toJSON ``` # RunToolCallItem ## Extends [Section titled “Extends”](#extends) * `RunItemBase` ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new RunToolCallItem(rawItem, agent): RunToolCallItem; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | `rawItem` | \| { `arguments?`: `string`; `id?`: `string`; `name`: `string`; `output?`: `string`; `providerData?`: `Record`<`string`, `any`>; `status?`: `string`; `type`: `"hosted_tool_call"`; } \| { `arguments`: `string`; `callId`: `string`; `id?`: `string`; `name`: `string`; `namespace?`: `string`; `providerData?`: `Record`<`string`, `any`>; `status?`: `"in_progress"` \| `"completed"` \| `"incomplete"`; `type`: `"function_call"`; } \| { `action?`: \| { `type`: `"screenshot"`; } \| { `button`: `"left"` \| `"right"` \| `"wheel"` \| `"back"` \| `"forward"`; `type`: `"click"`; `x`: `number`; `y`: `number`; } \| { `type`: `"double_click"`; `x`: `number`; `y`: `number`; } \| { `scroll_x`: `number`; `scroll_y`: `number`; `type`: `"scroll"`; `x`: `number`; `y`: `number`; } \| { `text`: `string`; `type`: `"type"`; } \| { `type`: `"wait"`; } \| { `type`: `"move"`; `x`: `number`; `y`: `number`; } \| { `keys`: `string`\[]; `type`: `"keypress"`; } \| { `path`: `object`\[]; `type`: `"drag"`; }; `actions?`: ( \| { `type`: `"screenshot"`; } \| { `button`: `"left"` \| `"right"` \| `"wheel"` \| `"back"` \| `"forward"`; `type`: `"click"`; `x`: `number`; `y`: `number`; } \| { `type`: `"double_click"`; `x`: `number`; `y`: `number`; } \| { `scroll_x`: `number`; `scroll_y`: `number`; `type`: `"scroll"`; `x`: `number`; `y`: `number`; } \| { `text`: `string`; `type`: `"type"`; } \| { `type`: `"wait"`; } \| { `type`: `"move"`; `x`: `number`; `y`: `number`; } \| { `keys`: `string`\[]; `type`: `"keypress"`; } \| { `path`: `object`\[]; `type`: `"drag"`; })\[]; `callId`: `string`; `id?`: `string`; `providerData?`: `Record`<`string`, `any`>; `status`: `"in_progress"` \| `"completed"` \| `"incomplete"`; `type`: `"computer_call"`; } \| { `action`: { `commands`: `string`\[]; `maxOutputLength?`: `number`; `timeoutMs?`: `number`; }; `callId`: `string`; `id?`: `string`; `providerData?`: `Record`<`string`, `any`>; `status?`: `"in_progress"` \| `"completed"` \| `"incomplete"`; `type`: `"shell_call"`; } \| { `callId`: `string`; `id?`: `string`; `operation`: \| { `diff`: `string`; `path`: `string`; `type`: `"create_file"`; } \| { `diff`: `string`; `moveTo?`: `string`; `path`: `string`; `type`: `"update_file"`; } \| { `path`: `string`; `type`: `"delete_file"`; }; `providerData?`: `Record`<`string`, `any`>; `status`: `"in_progress"` \| `"completed"`; `type`: `"apply_patch_call"`; } | | `agent` | [`Agent`](/openai-agents-js/openai/agents-core/classes/agent/) | #### Returns [Section titled “Returns”](#returns) `RunToolCallItem` #### Overrides [Section titled “Overrides”](#overrides) ```ts RunItemBase.constructor ``` ## Properties [Section titled “Properties”](#properties) ### agent [Section titled “agent”](#agent) ```ts agent: Agent; ``` *** ### rawItem [Section titled “rawItem”](#rawitem) ```ts rawItem: | { arguments?: string; id?: string; name: string; output?: string; providerData?: Record; status?: string; type: "hosted_tool_call"; } | { arguments: string; callId: string; id?: string; name: string; namespace?: string; providerData?: Record; status?: "in_progress" | "completed" | "incomplete"; type: "function_call"; } | { action?: | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; }; actions?: ( | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; })[]; callId: string; id?: string; providerData?: Record; status: "in_progress" | "completed" | "incomplete"; type: "computer_call"; } | { action: { commands: string[]; maxOutputLength?: number; timeoutMs?: number; }; callId: string; id?: string; providerData?: Record; status?: "in_progress" | "completed" | "incomplete"; type: "shell_call"; } | { callId: string; id?: string; operation: | { diff: string; path: string; type: "create_file"; } | { diff: string; moveTo?: string; path: string; type: "update_file"; } | { path: string; type: "delete_file"; }; providerData?: Record; status: "in_progress" | "completed"; type: "apply_patch_call"; }; ``` #### Union Members [Section titled “Union Members”](#union-members) ##### Type Literal [Section titled “Type Literal”](#type-literal) ```ts { arguments?: string; id?: string; name: string; output?: string; providerData?: Record; status?: string; type: "hosted_tool_call"; } ``` | Name | Type | Description | | --------------- | ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `arguments?` | `string` | The arguments of the hosted tool call. | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `name` | `string` | The name of the hosted tool. For example `web_search_call` or `file_search_call` | | `output?` | `string` | The primary output of the tool call. Additional output might be in the `providerData` field. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status?` | `string` | The status of the tool call. | | `type` | `"hosted_tool_call"` | ‐ | *** ##### Type Literal [Section titled “Type Literal”](#type-literal-1) ```ts { arguments: string; callId: string; id?: string; name: string; namespace?: string; providerData?: Record; status?: "in_progress" | "completed" | "incomplete"; type: "function_call"; } ``` | Name | Type | Description | | --------------- | -------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `arguments` | `string` | The arguments of the function call. | | `callId` | `string` | The ID of the tool call. Required to match up the respective tool call result. | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `name` | `string` | The name of the function. | | `namespace?` | `string` | Optional namespace used to qualify the function name for tool search. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status?` | `"in_progress"` \| `"completed"` \| `"incomplete"` | The status of the function call. | | `type` | `"function_call"` | ‐ | *** ##### Type Literal [Section titled “Type Literal”](#type-literal-2) ```ts { action?: | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; }; actions?: ( | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; })[]; callId: string; id?: string; providerData?: Record; status: "in_progress" | "completed" | "incomplete"; type: "computer_call"; } ``` | Name | Type | Description | | --------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `action?` | \| { `type`: `"screenshot"`; } \| { `button`: `"left"` \| `"right"` \| `"wheel"` \| `"back"` \| `"forward"`; `type`: `"click"`; `x`: `number`; `y`: `number`; } \| { `type`: `"double_click"`; `x`: `number`; `y`: `number`; } \| { `scroll_x`: `number`; `scroll_y`: `number`; `type`: `"scroll"`; `x`: `number`; `y`: `number`; } \| { `text`: `string`; `type`: `"type"`; } \| { `type`: `"wait"`; } \| { `type`: `"move"`; `x`: `number`; `y`: `number`; } \| { `keys`: `string`\[]; `type`: `"keypress"`; } \| { `path`: `object`\[]; `type`: `"drag"`; } | The legacy single action to be performed by the computer. | | `actions?` | ( \| { `type`: `"screenshot"`; } \| { `button`: `"left"` \| `"right"` \| `"wheel"` \| `"back"` \| `"forward"`; `type`: `"click"`; `x`: `number`; `y`: `number`; } \| { `type`: `"double_click"`; `x`: `number`; `y`: `number`; } \| { `scroll_x`: `number`; `scroll_y`: `number`; `type`: `"scroll"`; `x`: `number`; `y`: `number`; } \| { `text`: `string`; `type`: `"type"`; } \| { `type`: `"wait"`; } \| { `type`: `"move"`; `x`: `number`; `y`: `number`; } \| { `keys`: `string`\[]; `type`: `"keypress"`; } \| { `path`: `object`\[]; `type`: `"drag"`; })\[] | Batched actions returned by the GA computer tool. | | `callId` | `string` | The ID of the computer call. Required to match up the respective computer call result. | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status` | `"in_progress"` \| `"completed"` \| `"incomplete"` | The status of the computer call. | | `type` | `"computer_call"` | ‐ | *** ##### Type Literal [Section titled “Type Literal”](#type-literal-3) ```ts { action: { commands: string[]; maxOutputLength?: number; timeoutMs?: number; }; callId: string; id?: string; providerData?: Record; status?: "in_progress" | "completed" | "incomplete"; type: "shell_call"; } ``` | Name | Type | Default value | Description | | ------------------------- | -------------------------------------------------- | ------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `action` | `object` | `ShellAction` | ‐ | | `action.commands` | `string`\[] | ‐ | ‐ | | `action.maxOutputLength?` | `number` | ‐ | ‐ | | `action.timeoutMs?` | `number` | ‐ | ‐ | | `callId` | `string` | ‐ | ‐ | | `id?` | `string` | ‐ | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `providerData?` | `Record`<`string`, `any`> | ‐ | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status?` | `"in_progress"` \| `"completed"` \| `"incomplete"` | ‐ | ‐ | | `type` | `"shell_call"` | ‐ | ‐ | *** ##### Type Literal [Section titled “Type Literal”](#type-literal-4) ```ts { callId: string; id?: string; operation: | { diff: string; path: string; type: "create_file"; } | { diff: string; moveTo?: string; path: string; type: "update_file"; } | { path: string; type: "delete_file"; }; providerData?: Record; status: "in_progress" | "completed"; type: "apply_patch_call"; } ``` | Name | Type | Default value | Description | | --------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `callId` | `string` | ‐ | ‐ | | `id?` | `string` | ‐ | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `operation` | \| { `diff`: `string`; `path`: `string`; `type`: `"create_file"`; } \| { `diff`: `string`; `moveTo?`: `string`; `path`: `string`; `type`: `"update_file"`; } \| { `path`: `string`; `type`: `"delete_file"`; } | `ApplyPatchOperation` | ‐ | | `providerData?` | `Record`<`string`, `any`> | ‐ | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status` | `"in_progress"` \| `"completed"` | ‐ | ‐ | | `type` | `"apply_patch_call"` | ‐ | ‐ | #### Inherited from [Section titled “Inherited from”](#inherited-from) ```ts RunItemBase.rawItem ``` *** ### type [Section titled “type”](#type) ```ts readonly type: "tool_call_item"; ``` #### Overrides [Section titled “Overrides”](#overrides-1) ```ts RunItemBase.type ``` ## Accessors [Section titled “Accessors”](#accessors) ### callId [Section titled “callId”](#callid) #### Get Signature [Section titled “Get Signature”](#get-signature) ```ts get callId(): string | undefined; ``` ##### Returns [Section titled “Returns”](#returns-1) `string` | `undefined` *** ### toolName [Section titled “toolName”](#toolname) #### Get Signature [Section titled “Get Signature”](#get-signature-1) ```ts get toolName(): string | undefined; ``` ##### Returns [Section titled “Returns”](#returns-2) `string` | `undefined` ## Methods [Section titled “Methods”](#methods) ### toJSON() [Section titled “toJSON()”](#tojson) ```ts toJSON(): object; ``` #### Returns [Section titled “Returns”](#returns-3) `object` ##### agent [Section titled “agent”](#agent-1) ```ts agent: object; ``` ###### agent.name [Section titled “agent.name”](#agentname) ```ts name: string; ``` ##### rawItem [Section titled “rawItem”](#rawitem-1) ```ts rawItem: | { content: ( | { providerData?: Record; refusal: string; type: "refusal"; } | { providerData?: Record; text: string; type: "output_text"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; } | { image: string; providerData?: Record; type: "image"; })[]; id?: string; providerData?: Record; role: "assistant"; status: "in_progress" | "completed" | "incomplete"; type?: "message"; } | { content: | string | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; })[]; id?: string; providerData?: Record; role: "user"; type?: "message"; } | { content: string; id?: string; providerData?: Record; role: "system"; type?: "message"; } | { arguments?: string; id?: string; name: string; output?: string; providerData?: Record; status?: string; type: "hosted_tool_call"; } | { arguments: string; callId: string; id?: string; name: string; namespace?: string; providerData?: Record; status?: "in_progress" | "completed" | "incomplete"; type: "function_call"; } | { arguments: unknown; call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; type: "tool_search_call"; } | { call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; tools: Record[]; type: "tool_search_output"; } | { callId: string; id?: string; name: string; namespace?: string; output: | string | { providerData?: Record; text: string; type: "text"; } | { detail?: "low" | "high" | "auto" | string & object; image?: | string | { data: string | Uint8Array; mediaType?: string; } | { url: string; } | { fileId: string; }; providerData?: Record; type: "image"; } | { file: | string | { data: string | Uint8Array; filename: string; mediaType: string; } | { filename?: string; url: string; } | { filename?: string; id: string; }; providerData?: Record; type: "file"; } | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; })[]; providerData?: Record; status: "in_progress" | "completed" | "incomplete"; type: "function_call_result"; } | { action?: | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; }; actions?: ( | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; })[]; callId: string; id?: string; providerData?: Record; status: "in_progress" | "completed" | "incomplete"; type: "computer_call"; } | { callId: string; id?: string; output: { data: string; providerData?: Record; type: "computer_screenshot"; }; providerData?: Record; type: "computer_call_result"; } | { action: { commands: string[]; maxOutputLength?: number; timeoutMs?: number; }; callId: string; id?: string; providerData?: Record; status?: "in_progress" | "completed" | "incomplete"; type: "shell_call"; } | { callId: string; id?: string; maxOutputLength?: number; output: object[]; providerData?: Record; type: "shell_call_output"; } | { callId: string; id?: string; operation: | { diff: string; path: string; type: "create_file"; } | { diff: string; moveTo?: string; path: string; type: "update_file"; } | { path: string; type: "delete_file"; }; providerData?: Record; status: "in_progress" | "completed"; type: "apply_patch_call"; } | { callId: string; id?: string; output?: string; providerData?: Record; status: "completed" | "failed"; type: "apply_patch_call_output"; } | { content: object[]; id?: string; providerData?: Record; rawContent?: object[]; type: "reasoning"; } | { created_by?: string; encrypted_content: string; id?: string; providerData?: Record; type: "compaction"; } | { id?: string; providerData?: Record; type: "unknown"; } | undefined; ``` ###### Union Members [Section titled “Union Members”](#union-members-1) ###### Type Literal [Section titled “Type Literal”](#type-literal-5) ```ts { content: ( | { providerData?: Record; refusal: string; type: "refusal"; } | { providerData?: Record; text: string; type: "output_text"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; } | { image: string; providerData?: Record; type: "image"; })[]; id?: string; providerData?: Record; role: "assistant"; status: "in_progress" | "completed" | "incomplete"; type?: "message"; } ``` | Name | Type | Description | | --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `content` | ( \| { `providerData?`: `Record`<`string`, `any`>; `refusal`: `string`; `type`: `"refusal"`; } \| { `providerData?`: `Record`<`string`, `any`>; `text`: `string`; `type`: `"output_text"`; } \| { `audio`: \| `string` \| { `id`: `string`; }; `format?`: `string` \| `null`; `providerData?`: `Record`<`string`, `any`>; `transcript?`: `string` \| `null`; `type`: `"audio"`; } \| { `image`: `string`; `providerData?`: `Record`<`string`, `any`>; `type`: `"image"`; })\[] | The content of the message. | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `role` | `"assistant"` | Representing a message from the assistant (i.e. the model) | | `status` | `"in_progress"` \| `"completed"` \| `"incomplete"` | The status of the message. | | `type?` | `"message"` | Any item without a type is treated as a message | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-6) ```ts { content: | string | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; })[]; id?: string; providerData?: Record; role: "user"; type?: "message"; } ``` | Name | Type | Description | | --------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `content` | \| `string` \| ( \| { `providerData?`: `Record`<`string`, `any`>; `text`: `string`; `type`: `"input_text"`; } \| { `detail?`: `string`; `image?`: \| `string` \| { `id`: `string`; }; `providerData?`: `Record`<`string`, `any`>; `type`: `"input_image"`; } \| { `file?`: \| `string` \| { `id`: `string`; } \| { `url`: `string`; }; `filename?`: `string`; `providerData?`: `Record`<`string`, `any`>; `type`: `"input_file"`; } \| { `audio`: \| `string` \| { `id`: `string`; }; `format?`: `string` \| `null`; `providerData?`: `Record`<`string`, `any`>; `transcript?`: `string` \| `null`; `type`: `"audio"`; })\[] | The content of the message. | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `role` | `"user"` | Representing a message from the user | | `type?` | `"message"` | Any item without a type is treated as a message | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-7) ```ts { content: string; id?: string; providerData?: Record; role: "system"; type?: "message"; } ``` | Name | Type | Description | | --------------- | ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `content` | `string` | The content of the message. | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `role` | `"system"` | Representing a system message to the user | | `type?` | `"message"` | Any item without a type is treated as a message | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-8) ```ts { arguments?: string; id?: string; name: string; output?: string; providerData?: Record; status?: string; type: "hosted_tool_call"; } ``` | Name | Type | Description | | --------------- | ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `arguments?` | `string` | The arguments of the hosted tool call. | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `name` | `string` | The name of the hosted tool. For example `web_search_call` or `file_search_call` | | `output?` | `string` | The primary output of the tool call. Additional output might be in the `providerData` field. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status?` | `string` | The status of the tool call. | | `type` | `"hosted_tool_call"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-9) ```ts { arguments: string; callId: string; id?: string; name: string; namespace?: string; providerData?: Record; status?: "in_progress" | "completed" | "incomplete"; type: "function_call"; } ``` | Name | Type | Description | | --------------- | -------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `arguments` | `string` | The arguments of the function call. | | `callId` | `string` | The ID of the tool call. Required to match up the respective tool call result. | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `name` | `string` | The name of the function. | | `namespace?` | `string` | Optional namespace used to qualify the function name for tool search. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status?` | `"in_progress"` \| `"completed"` \| `"incomplete"` | The status of the function call. | | `type` | `"function_call"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-10) ```ts { arguments: unknown; call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; type: "tool_search_call"; } ``` | Name | Type | Default value | Description | | --------------- | ------------------------- | ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `arguments` | `unknown` | `ToolSearchCallArguments` | ‐ | | `call_id?` | `string` \| `null` | ‐ | ‐ | | `callId?` | `string` \| `null` | ‐ | ‐ | | `execution?` | `"client"` \| `"server"` | ‐ | ‐ | | `id?` | `string` | ‐ | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `providerData?` | `Record`<`string`, `any`> | ‐ | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status?` | `string` | ‐ | ‐ | | `type` | `"tool_search_call"` | ‐ | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-11) ```ts { call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; tools: Record[]; type: "tool_search_output"; } ``` | Name | Type | Description | | --------------- | ---------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `call_id?` | `string` \| `null` | ‐ | | `callId?` | `string` \| `null` | ‐ | | `execution?` | `"client"` \| `"server"` | ‐ | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status?` | `string` | ‐ | | `tools` | `Record`<`string`, `any`>\[] | ‐ | | `type` | `"tool_search_output"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-12) ```ts { callId: string; id?: string; name: string; namespace?: string; output: | string | { providerData?: Record; text: string; type: "text"; } | { detail?: "low" | "high" | "auto" | string & object; image?: | string | { data: string | Uint8Array; mediaType?: string; } | { url: string; } | { fileId: string; }; providerData?: Record; type: "image"; } | { file: | string | { data: string | Uint8Array; filename: string; mediaType: string; } | { filename?: string; url: string; } | { filename?: string; id: string; }; providerData?: Record; type: "file"; } | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; })[]; providerData?: Record; status: "in_progress" | "completed" | "incomplete"; type: "function_call_result"; } ``` | Name | Type | Description | | --------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `callId` | `string` | The ID of the tool call. Required to match up the respective tool call result. | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `name` | `string` | The name of the tool that was called | | `namespace?` | `string` | Optional namespace preserved from the originating function call. | | `output` | \| `string` \| { `providerData?`: `Record`<`string`, `any`>; `text`: `string`; `type`: `"text"`; } \| { `detail?`: `"low"` \| `"high"` \| `"auto"` \| `string` & `object`; `image?`: \| `string` \| { `data`: `string` \| `Uint8Array`<`ArrayBuffer`>; `mediaType?`: `string`; } \| { `url`: `string`; } \| { `fileId`: `string`; }; `providerData?`: `Record`<`string`, `any`>; `type`: `"image"`; } \| { `file`: \| `string` \| { `data`: `string` \| `Uint8Array`<`ArrayBuffer`>; `filename`: `string`; `mediaType`: `string`; } \| { `filename?`: `string`; `url`: `string`; } \| { `filename?`: `string`; `id`: `string`; }; `providerData?`: `Record`<`string`, `any`>; `type`: `"file"`; } \| ( \| { `providerData?`: `Record`<`string`, `any`>; `text`: `string`; `type`: `"input_text"`; } \| { `detail?`: `string`; `image?`: \| `string` \| { `id`: `string`; }; `providerData?`: `Record`<`string`, `any`>; `type`: `"input_image"`; } \| { `file?`: \| `string` \| { `id`: `string`; } \| { `url`: `string`; }; `filename?`: `string`; `providerData?`: `Record`<`string`, `any`>; `type`: `"input_file"`; })\[] | The output of the tool call. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status` | `"in_progress"` \| `"completed"` \| `"incomplete"` | The status of the tool call. | | `type` | `"function_call_result"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-13) ```ts { action?: | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; }; actions?: ( | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; })[]; callId: string; id?: string; providerData?: Record; status: "in_progress" | "completed" | "incomplete"; type: "computer_call"; } ``` | Name | Type | Description | | --------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `action?` | \| { `type`: `"screenshot"`; } \| { `button`: `"left"` \| `"right"` \| `"wheel"` \| `"back"` \| `"forward"`; `type`: `"click"`; `x`: `number`; `y`: `number`; } \| { `type`: `"double_click"`; `x`: `number`; `y`: `number`; } \| { `scroll_x`: `number`; `scroll_y`: `number`; `type`: `"scroll"`; `x`: `number`; `y`: `number`; } \| { `text`: `string`; `type`: `"type"`; } \| { `type`: `"wait"`; } \| { `type`: `"move"`; `x`: `number`; `y`: `number`; } \| { `keys`: `string`\[]; `type`: `"keypress"`; } \| { `path`: `object`\[]; `type`: `"drag"`; } | The legacy single action to be performed by the computer. | | `actions?` | ( \| { `type`: `"screenshot"`; } \| { `button`: `"left"` \| `"right"` \| `"wheel"` \| `"back"` \| `"forward"`; `type`: `"click"`; `x`: `number`; `y`: `number`; } \| { `type`: `"double_click"`; `x`: `number`; `y`: `number`; } \| { `scroll_x`: `number`; `scroll_y`: `number`; `type`: `"scroll"`; `x`: `number`; `y`: `number`; } \| { `text`: `string`; `type`: `"type"`; } \| { `type`: `"wait"`; } \| { `type`: `"move"`; `x`: `number`; `y`: `number`; } \| { `keys`: `string`\[]; `type`: `"keypress"`; } \| { `path`: `object`\[]; `type`: `"drag"`; })\[] | Batched actions returned by the GA computer tool. | | `callId` | `string` | The ID of the computer call. Required to match up the respective computer call result. | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status` | `"in_progress"` \| `"completed"` \| `"incomplete"` | The status of the computer call. | | `type` | `"computer_call"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-14) ```ts { callId: string; id?: string; output: { data: string; providerData?: Record; type: "computer_screenshot"; }; providerData?: Record; type: "computer_call_result"; } ``` | Name | Type | Default value | Description | | ---------------------- | ------------------------- | -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `callId` | `string` | ‐ | The ID of the computer call. Required to match up the respective computer call result. | | `id?` | `string` | ‐ | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `output` | `object` | `ComputerToolOutput` | The output of the computer call. | | `output.data` | `string` | ‐ | A base64 encoded image data or a URL representing the screenshot. | | `output.providerData?` | `Record`<`string`, `any`> | ‐ | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `output.type` | `"computer_screenshot"` | ‐ | ‐ | | `providerData?` | `Record`<`string`, `any`> | ‐ | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `type` | `"computer_call_result"` | ‐ | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-15) ```ts { action: { commands: string[]; maxOutputLength?: number; timeoutMs?: number; }; callId: string; id?: string; providerData?: Record; status?: "in_progress" | "completed" | "incomplete"; type: "shell_call"; } ``` | Name | Type | Default value | Description | | ------------------------- | -------------------------------------------------- | ------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `action` | `object` | `ShellAction` | ‐ | | `action.commands` | `string`\[] | ‐ | ‐ | | `action.maxOutputLength?` | `number` | ‐ | ‐ | | `action.timeoutMs?` | `number` | ‐ | ‐ | | `callId` | `string` | ‐ | ‐ | | `id?` | `string` | ‐ | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `providerData?` | `Record`<`string`, `any`> | ‐ | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status?` | `"in_progress"` \| `"completed"` \| `"incomplete"` | ‐ | ‐ | | `type` | `"shell_call"` | ‐ | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-16) ```ts { callId: string; id?: string; maxOutputLength?: number; output: object[]; providerData?: Record; type: "shell_call_output"; } ``` | Name | Type | Description | | ------------------ | ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `callId` | `string` | ‐ | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `maxOutputLength?` | `number` | ‐ | | `output` | `object`\[] | ‐ | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `type` | `"shell_call_output"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-17) ```ts { callId: string; id?: string; operation: | { diff: string; path: string; type: "create_file"; } | { diff: string; moveTo?: string; path: string; type: "update_file"; } | { path: string; type: "delete_file"; }; providerData?: Record; status: "in_progress" | "completed"; type: "apply_patch_call"; } ``` | Name | Type | Default value | Description | | --------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `callId` | `string` | ‐ | ‐ | | `id?` | `string` | ‐ | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `operation` | \| { `diff`: `string`; `path`: `string`; `type`: `"create_file"`; } \| { `diff`: `string`; `moveTo?`: `string`; `path`: `string`; `type`: `"update_file"`; } \| { `path`: `string`; `type`: `"delete_file"`; } | `ApplyPatchOperation` | ‐ | | `providerData?` | `Record`<`string`, `any`> | ‐ | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status` | `"in_progress"` \| `"completed"` | ‐ | ‐ | | `type` | `"apply_patch_call"` | ‐ | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-18) ```ts { callId: string; id?: string; output?: string; providerData?: Record; status: "completed" | "failed"; type: "apply_patch_call_output"; } ``` | Name | Type | Description | | --------------- | --------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `callId` | `string` | ‐ | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `output?` | `string` | ‐ | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status` | `"completed"` \| `"failed"` | ‐ | | `type` | `"apply_patch_call_output"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-19) ```ts { content: object[]; id?: string; providerData?: Record; rawContent?: object[]; type: "reasoning"; } ``` | Name | Type | Description | | --------------- | ------------------------- | ------------------------------------------------------------------------------------------------------------- | | `content` | `object`\[] | The user facing representation of the reasoning. Additional information might be in the `providerData` field. | | `id?` | `string` | ‐ | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `rawContent?` | `object`\[] | The raw reasoning text from the model. | | `type` | `"reasoning"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-20) ```ts { created_by?: string; encrypted_content: string; id?: string; providerData?: Record; type: "compaction"; } ``` | Name | Type | Description | | ------------------- | ------------------------- | ------------------------------------------------------------------------------------------------------------ | | `created_by?` | `string` | Identifier for the generator of this compaction item. | | `encrypted_content` | `string` | Encrypted payload returned by the compaction endpoint. | | `id?` | `string` | Identifier for the compaction item. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `type` | `"compaction"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-21) ```ts { id?: string; providerData?: Record; type: "unknown"; } ``` | Name | Type | Description | | --------------- | ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `type` | `"unknown"` | ‐ | *** `undefined` ##### type [Section titled “type”](#type-1) ```ts type: string; ``` #### Overrides [Section titled “Overrides”](#overrides-2) ```ts RunItemBase.toJSON ``` # RunToolCallOutputItem ## Extends [Section titled “Extends”](#extends) * `RunItemBase` ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new RunToolCallOutputItem( rawItem, agent, output): RunToolCallOutputItem; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `rawItem` | \| { `callId`: `string`; `id?`: `string`; `name`: `string`; `namespace?`: `string`; `output`: \| `string` \| { `providerData?`: `Record`<`string`, `any`>; `text`: `string`; `type`: `"text"`; } \| { `detail?`: `"low"` \| `"high"` \| `"auto"` \| `string` & `object`; `image?`: \| `string` \| { `data`: `string` \| `Uint8Array`<`ArrayBuffer`>; `mediaType?`: `string`; } \| { `url`: `string`; } \| { `fileId`: `string`; }; `providerData?`: `Record`<`string`, `any`>; `type`: `"image"`; } \| { `file`: \| `string` \| { `data`: `string` \| `Uint8Array`<`ArrayBuffer`>; `filename`: `string`; `mediaType`: `string`; } \| { `filename?`: `string`; `url`: `string`; } \| { `filename?`: `string`; `id`: `string`; }; `providerData?`: `Record`<`string`, `any`>; `type`: `"file"`; } \| ( \| { `providerData?`: `Record`<`string`, `any`>; `text`: `string`; `type`: `"input_text"`; } \| { `detail?`: `string`; `image?`: \| `string` \| { `id`: `string`; }; `providerData?`: `Record`<`string`, `any`>; `type`: `"input_image"`; } \| { `file?`: \| `string` \| { `id`: `string`; } \| { `url`: `string`; }; `filename?`: `string`; `providerData?`: `Record`<`string`, `any`>; `type`: `"input_file"`; })\[]; `providerData?`: `Record`<`string`, `any`>; `status`: `"in_progress"` \| `"completed"` \| `"incomplete"`; `type`: `"function_call_result"`; } \| { `callId`: `string`; `id?`: `string`; `output`: { `data`: `string`; `providerData?`: `Record`<`string`, `any`>; `type`: `"computer_screenshot"`; }; `providerData?`: `Record`<`string`, `any`>; `type`: `"computer_call_result"`; } \| { `callId`: `string`; `id?`: `string`; `maxOutputLength?`: `number`; `output`: `object`\[]; `providerData?`: `Record`<`string`, `any`>; `type`: `"shell_call_output"`; } \| { `callId`: `string`; `id?`: `string`; `output?`: `string`; `providerData?`: `Record`<`string`, `any`>; `status`: `"completed"` \| `"failed"`; `type`: `"apply_patch_call_output"`; } | | `agent` | [`Agent`](/openai-agents-js/openai/agents-core/classes/agent/)<`any`, `any`> | | `output` | `unknown` | #### Returns [Section titled “Returns”](#returns) `RunToolCallOutputItem` #### Overrides [Section titled “Overrides”](#overrides) ```ts RunItemBase.constructor ``` ## Properties [Section titled “Properties”](#properties) ### agent [Section titled “agent”](#agent) ```ts agent: Agent; ``` *** ### output [Section titled “output”](#output) ```ts output: unknown; ``` *** ### rawItem [Section titled “rawItem”](#rawitem) ```ts rawItem: | { callId: string; id?: string; name: string; namespace?: string; output: | string | { providerData?: Record; text: string; type: "text"; } | { detail?: "low" | "high" | "auto" | string & object; image?: | string | { data: string | Uint8Array; mediaType?: string; } | { url: string; } | { fileId: string; }; providerData?: Record; type: "image"; } | { file: | string | { data: string | Uint8Array; filename: string; mediaType: string; } | { filename?: string; url: string; } | { filename?: string; id: string; }; providerData?: Record; type: "file"; } | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; })[]; providerData?: Record; status: "in_progress" | "completed" | "incomplete"; type: "function_call_result"; } | { callId: string; id?: string; output: { data: string; providerData?: Record; type: "computer_screenshot"; }; providerData?: Record; type: "computer_call_result"; } | { callId: string; id?: string; maxOutputLength?: number; output: object[]; providerData?: Record; type: "shell_call_output"; } | { callId: string; id?: string; output?: string; providerData?: Record; status: "completed" | "failed"; type: "apply_patch_call_output"; }; ``` #### Union Members [Section titled “Union Members”](#union-members) ##### Type Literal [Section titled “Type Literal”](#type-literal) ```ts { callId: string; id?: string; name: string; namespace?: string; output: | string | { providerData?: Record; text: string; type: "text"; } | { detail?: "low" | "high" | "auto" | string & object; image?: | string | { data: string | Uint8Array; mediaType?: string; } | { url: string; } | { fileId: string; }; providerData?: Record; type: "image"; } | { file: | string | { data: string | Uint8Array; filename: string; mediaType: string; } | { filename?: string; url: string; } | { filename?: string; id: string; }; providerData?: Record; type: "file"; } | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; })[]; providerData?: Record; status: "in_progress" | "completed" | "incomplete"; type: "function_call_result"; } ``` | Name | Type | Description | | --------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `callId` | `string` | The ID of the tool call. Required to match up the respective tool call result. | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `name` | `string` | The name of the tool that was called | | `namespace?` | `string` | Optional namespace preserved from the originating function call. | | `output` | \| `string` \| { `providerData?`: `Record`<`string`, `any`>; `text`: `string`; `type`: `"text"`; } \| { `detail?`: `"low"` \| `"high"` \| `"auto"` \| `string` & `object`; `image?`: \| `string` \| { `data`: `string` \| `Uint8Array`<`ArrayBuffer`>; `mediaType?`: `string`; } \| { `url`: `string`; } \| { `fileId`: `string`; }; `providerData?`: `Record`<`string`, `any`>; `type`: `"image"`; } \| { `file`: \| `string` \| { `data`: `string` \| `Uint8Array`<`ArrayBuffer`>; `filename`: `string`; `mediaType`: `string`; } \| { `filename?`: `string`; `url`: `string`; } \| { `filename?`: `string`; `id`: `string`; }; `providerData?`: `Record`<`string`, `any`>; `type`: `"file"`; } \| ( \| { `providerData?`: `Record`<`string`, `any`>; `text`: `string`; `type`: `"input_text"`; } \| { `detail?`: `string`; `image?`: \| `string` \| { `id`: `string`; }; `providerData?`: `Record`<`string`, `any`>; `type`: `"input_image"`; } \| { `file?`: \| `string` \| { `id`: `string`; } \| { `url`: `string`; }; `filename?`: `string`; `providerData?`: `Record`<`string`, `any`>; `type`: `"input_file"`; })\[] | The output of the tool call. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status` | `"in_progress"` \| `"completed"` \| `"incomplete"` | The status of the tool call. | | `type` | `"function_call_result"` | ‐ | *** ##### Type Literal [Section titled “Type Literal”](#type-literal-1) ```ts { callId: string; id?: string; output: { data: string; providerData?: Record; type: "computer_screenshot"; }; providerData?: Record; type: "computer_call_result"; } ``` | Name | Type | Default value | Description | | ---------------------- | ------------------------- | -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `callId` | `string` | ‐ | The ID of the computer call. Required to match up the respective computer call result. | | `id?` | `string` | ‐ | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `output` | `object` | `ComputerToolOutput` | The output of the computer call. | | `output.data` | `string` | ‐ | A base64 encoded image data or a URL representing the screenshot. | | `output.providerData?` | `Record`<`string`, `any`> | ‐ | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `output.type` | `"computer_screenshot"` | ‐ | ‐ | | `providerData?` | `Record`<`string`, `any`> | ‐ | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `type` | `"computer_call_result"` | ‐ | ‐ | *** ##### Type Literal [Section titled “Type Literal”](#type-literal-2) ```ts { callId: string; id?: string; maxOutputLength?: number; output: object[]; providerData?: Record; type: "shell_call_output"; } ``` | Name | Type | Description | | ------------------ | ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `callId` | `string` | ‐ | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `maxOutputLength?` | `number` | ‐ | | `output` | `object`\[] | ‐ | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `type` | `"shell_call_output"` | ‐ | *** ##### Type Literal [Section titled “Type Literal”](#type-literal-3) ```ts { callId: string; id?: string; output?: string; providerData?: Record; status: "completed" | "failed"; type: "apply_patch_call_output"; } ``` | Name | Type | Description | | --------------- | --------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `callId` | `string` | ‐ | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `output?` | `string` | ‐ | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status` | `"completed"` \| `"failed"` | ‐ | | `type` | `"apply_patch_call_output"` | ‐ | #### Inherited from [Section titled “Inherited from”](#inherited-from) ```ts RunItemBase.rawItem ``` *** ### type [Section titled “type”](#type) ```ts readonly type: "tool_call_output_item"; ``` #### Overrides [Section titled “Overrides”](#overrides-1) ```ts RunItemBase.type ``` ## Accessors [Section titled “Accessors”](#accessors) ### callId [Section titled “callId”](#callid) #### Get Signature [Section titled “Get Signature”](#get-signature) ```ts get callId(): string | undefined; ``` ##### Returns [Section titled “Returns”](#returns-1) `string` | `undefined` ## Methods [Section titled “Methods”](#methods) ### toJSON() [Section titled “toJSON()”](#tojson) ```ts toJSON(): object; ``` #### Returns [Section titled “Returns”](#returns-2) `object` ##### agent [Section titled “agent”](#agent-1) ```ts agent: object; ``` ###### agent.name [Section titled “agent.name”](#agentname) ```ts name: string; ``` ##### output [Section titled “output”](#output-1) ```ts output: string; ``` ##### rawItem [Section titled “rawItem”](#rawitem-1) ```ts rawItem: | { content: ( | { providerData?: Record; refusal: string; type: "refusal"; } | { providerData?: Record; text: string; type: "output_text"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; } | { image: string; providerData?: Record; type: "image"; })[]; id?: string; providerData?: Record; role: "assistant"; status: "in_progress" | "completed" | "incomplete"; type?: "message"; } | { content: | string | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; })[]; id?: string; providerData?: Record; role: "user"; type?: "message"; } | { content: string; id?: string; providerData?: Record; role: "system"; type?: "message"; } | { arguments?: string; id?: string; name: string; output?: string; providerData?: Record; status?: string; type: "hosted_tool_call"; } | { arguments: string; callId: string; id?: string; name: string; namespace?: string; providerData?: Record; status?: "in_progress" | "completed" | "incomplete"; type: "function_call"; } | { arguments: unknown; call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; type: "tool_search_call"; } | { call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; tools: Record[]; type: "tool_search_output"; } | { callId: string; id?: string; name: string; namespace?: string; output: | string | { providerData?: Record; text: string; type: "text"; } | { detail?: "low" | "high" | "auto" | string & object; image?: | string | { data: string | Uint8Array; mediaType?: string; } | { url: string; } | { fileId: string; }; providerData?: Record; type: "image"; } | { file: | string | { data: string | Uint8Array; filename: string; mediaType: string; } | { filename?: string; url: string; } | { filename?: string; id: string; }; providerData?: Record; type: "file"; } | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; })[]; providerData?: Record; status: "in_progress" | "completed" | "incomplete"; type: "function_call_result"; } | { action?: | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; }; actions?: ( | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; })[]; callId: string; id?: string; providerData?: Record; status: "in_progress" | "completed" | "incomplete"; type: "computer_call"; } | { callId: string; id?: string; output: { data: string; providerData?: Record; type: "computer_screenshot"; }; providerData?: Record; type: "computer_call_result"; } | { action: { commands: string[]; maxOutputLength?: number; timeoutMs?: number; }; callId: string; id?: string; providerData?: Record; status?: "in_progress" | "completed" | "incomplete"; type: "shell_call"; } | { callId: string; id?: string; maxOutputLength?: number; output: object[]; providerData?: Record; type: "shell_call_output"; } | { callId: string; id?: string; operation: | { diff: string; path: string; type: "create_file"; } | { diff: string; moveTo?: string; path: string; type: "update_file"; } | { path: string; type: "delete_file"; }; providerData?: Record; status: "in_progress" | "completed"; type: "apply_patch_call"; } | { callId: string; id?: string; output?: string; providerData?: Record; status: "completed" | "failed"; type: "apply_patch_call_output"; } | { content: object[]; id?: string; providerData?: Record; rawContent?: object[]; type: "reasoning"; } | { created_by?: string; encrypted_content: string; id?: string; providerData?: Record; type: "compaction"; } | { id?: string; providerData?: Record; type: "unknown"; } | undefined; ``` ###### Union Members [Section titled “Union Members”](#union-members-1) ###### Type Literal [Section titled “Type Literal”](#type-literal-4) ```ts { content: ( | { providerData?: Record; refusal: string; type: "refusal"; } | { providerData?: Record; text: string; type: "output_text"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; } | { image: string; providerData?: Record; type: "image"; })[]; id?: string; providerData?: Record; role: "assistant"; status: "in_progress" | "completed" | "incomplete"; type?: "message"; } ``` | Name | Type | Description | | --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `content` | ( \| { `providerData?`: `Record`<`string`, `any`>; `refusal`: `string`; `type`: `"refusal"`; } \| { `providerData?`: `Record`<`string`, `any`>; `text`: `string`; `type`: `"output_text"`; } \| { `audio`: \| `string` \| { `id`: `string`; }; `format?`: `string` \| `null`; `providerData?`: `Record`<`string`, `any`>; `transcript?`: `string` \| `null`; `type`: `"audio"`; } \| { `image`: `string`; `providerData?`: `Record`<`string`, `any`>; `type`: `"image"`; })\[] | The content of the message. | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `role` | `"assistant"` | Representing a message from the assistant (i.e. the model) | | `status` | `"in_progress"` \| `"completed"` \| `"incomplete"` | The status of the message. | | `type?` | `"message"` | Any item without a type is treated as a message | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-5) ```ts { content: | string | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; })[]; id?: string; providerData?: Record; role: "user"; type?: "message"; } ``` | Name | Type | Description | | --------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `content` | \| `string` \| ( \| { `providerData?`: `Record`<`string`, `any`>; `text`: `string`; `type`: `"input_text"`; } \| { `detail?`: `string`; `image?`: \| `string` \| { `id`: `string`; }; `providerData?`: `Record`<`string`, `any`>; `type`: `"input_image"`; } \| { `file?`: \| `string` \| { `id`: `string`; } \| { `url`: `string`; }; `filename?`: `string`; `providerData?`: `Record`<`string`, `any`>; `type`: `"input_file"`; } \| { `audio`: \| `string` \| { `id`: `string`; }; `format?`: `string` \| `null`; `providerData?`: `Record`<`string`, `any`>; `transcript?`: `string` \| `null`; `type`: `"audio"`; })\[] | The content of the message. | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `role` | `"user"` | Representing a message from the user | | `type?` | `"message"` | Any item without a type is treated as a message | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-6) ```ts { content: string; id?: string; providerData?: Record; role: "system"; type?: "message"; } ``` | Name | Type | Description | | --------------- | ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `content` | `string` | The content of the message. | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `role` | `"system"` | Representing a system message to the user | | `type?` | `"message"` | Any item without a type is treated as a message | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-7) ```ts { arguments?: string; id?: string; name: string; output?: string; providerData?: Record; status?: string; type: "hosted_tool_call"; } ``` | Name | Type | Description | | --------------- | ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `arguments?` | `string` | The arguments of the hosted tool call. | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `name` | `string` | The name of the hosted tool. For example `web_search_call` or `file_search_call` | | `output?` | `string` | The primary output of the tool call. Additional output might be in the `providerData` field. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status?` | `string` | The status of the tool call. | | `type` | `"hosted_tool_call"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-8) ```ts { arguments: string; callId: string; id?: string; name: string; namespace?: string; providerData?: Record; status?: "in_progress" | "completed" | "incomplete"; type: "function_call"; } ``` | Name | Type | Description | | --------------- | -------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `arguments` | `string` | The arguments of the function call. | | `callId` | `string` | The ID of the tool call. Required to match up the respective tool call result. | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `name` | `string` | The name of the function. | | `namespace?` | `string` | Optional namespace used to qualify the function name for tool search. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status?` | `"in_progress"` \| `"completed"` \| `"incomplete"` | The status of the function call. | | `type` | `"function_call"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-9) ```ts { arguments: unknown; call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; type: "tool_search_call"; } ``` | Name | Type | Default value | Description | | --------------- | ------------------------- | ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `arguments` | `unknown` | `ToolSearchCallArguments` | ‐ | | `call_id?` | `string` \| `null` | ‐ | ‐ | | `callId?` | `string` \| `null` | ‐ | ‐ | | `execution?` | `"client"` \| `"server"` | ‐ | ‐ | | `id?` | `string` | ‐ | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `providerData?` | `Record`<`string`, `any`> | ‐ | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status?` | `string` | ‐ | ‐ | | `type` | `"tool_search_call"` | ‐ | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-10) ```ts { call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; tools: Record[]; type: "tool_search_output"; } ``` | Name | Type | Description | | --------------- | ---------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `call_id?` | `string` \| `null` | ‐ | | `callId?` | `string` \| `null` | ‐ | | `execution?` | `"client"` \| `"server"` | ‐ | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status?` | `string` | ‐ | | `tools` | `Record`<`string`, `any`>\[] | ‐ | | `type` | `"tool_search_output"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-11) ```ts { callId: string; id?: string; name: string; namespace?: string; output: | string | { providerData?: Record; text: string; type: "text"; } | { detail?: "low" | "high" | "auto" | string & object; image?: | string | { data: string | Uint8Array; mediaType?: string; } | { url: string; } | { fileId: string; }; providerData?: Record; type: "image"; } | { file: | string | { data: string | Uint8Array; filename: string; mediaType: string; } | { filename?: string; url: string; } | { filename?: string; id: string; }; providerData?: Record; type: "file"; } | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; })[]; providerData?: Record; status: "in_progress" | "completed" | "incomplete"; type: "function_call_result"; } ``` | Name | Type | Description | | --------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `callId` | `string` | The ID of the tool call. Required to match up the respective tool call result. | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `name` | `string` | The name of the tool that was called | | `namespace?` | `string` | Optional namespace preserved from the originating function call. | | `output` | \| `string` \| { `providerData?`: `Record`<`string`, `any`>; `text`: `string`; `type`: `"text"`; } \| { `detail?`: `"low"` \| `"high"` \| `"auto"` \| `string` & `object`; `image?`: \| `string` \| { `data`: `string` \| `Uint8Array`<`ArrayBuffer`>; `mediaType?`: `string`; } \| { `url`: `string`; } \| { `fileId`: `string`; }; `providerData?`: `Record`<`string`, `any`>; `type`: `"image"`; } \| { `file`: \| `string` \| { `data`: `string` \| `Uint8Array`<`ArrayBuffer`>; `filename`: `string`; `mediaType`: `string`; } \| { `filename?`: `string`; `url`: `string`; } \| { `filename?`: `string`; `id`: `string`; }; `providerData?`: `Record`<`string`, `any`>; `type`: `"file"`; } \| ( \| { `providerData?`: `Record`<`string`, `any`>; `text`: `string`; `type`: `"input_text"`; } \| { `detail?`: `string`; `image?`: \| `string` \| { `id`: `string`; }; `providerData?`: `Record`<`string`, `any`>; `type`: `"input_image"`; } \| { `file?`: \| `string` \| { `id`: `string`; } \| { `url`: `string`; }; `filename?`: `string`; `providerData?`: `Record`<`string`, `any`>; `type`: `"input_file"`; })\[] | The output of the tool call. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status` | `"in_progress"` \| `"completed"` \| `"incomplete"` | The status of the tool call. | | `type` | `"function_call_result"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-12) ```ts { action?: | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; }; actions?: ( | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; })[]; callId: string; id?: string; providerData?: Record; status: "in_progress" | "completed" | "incomplete"; type: "computer_call"; } ``` | Name | Type | Description | | --------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `action?` | \| { `type`: `"screenshot"`; } \| { `button`: `"left"` \| `"right"` \| `"wheel"` \| `"back"` \| `"forward"`; `type`: `"click"`; `x`: `number`; `y`: `number`; } \| { `type`: `"double_click"`; `x`: `number`; `y`: `number`; } \| { `scroll_x`: `number`; `scroll_y`: `number`; `type`: `"scroll"`; `x`: `number`; `y`: `number`; } \| { `text`: `string`; `type`: `"type"`; } \| { `type`: `"wait"`; } \| { `type`: `"move"`; `x`: `number`; `y`: `number`; } \| { `keys`: `string`\[]; `type`: `"keypress"`; } \| { `path`: `object`\[]; `type`: `"drag"`; } | The legacy single action to be performed by the computer. | | `actions?` | ( \| { `type`: `"screenshot"`; } \| { `button`: `"left"` \| `"right"` \| `"wheel"` \| `"back"` \| `"forward"`; `type`: `"click"`; `x`: `number`; `y`: `number`; } \| { `type`: `"double_click"`; `x`: `number`; `y`: `number`; } \| { `scroll_x`: `number`; `scroll_y`: `number`; `type`: `"scroll"`; `x`: `number`; `y`: `number`; } \| { `text`: `string`; `type`: `"type"`; } \| { `type`: `"wait"`; } \| { `type`: `"move"`; `x`: `number`; `y`: `number`; } \| { `keys`: `string`\[]; `type`: `"keypress"`; } \| { `path`: `object`\[]; `type`: `"drag"`; })\[] | Batched actions returned by the GA computer tool. | | `callId` | `string` | The ID of the computer call. Required to match up the respective computer call result. | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status` | `"in_progress"` \| `"completed"` \| `"incomplete"` | The status of the computer call. | | `type` | `"computer_call"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-13) ```ts { callId: string; id?: string; output: { data: string; providerData?: Record; type: "computer_screenshot"; }; providerData?: Record; type: "computer_call_result"; } ``` | Name | Type | Default value | Description | | ---------------------- | ------------------------- | -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `callId` | `string` | ‐ | The ID of the computer call. Required to match up the respective computer call result. | | `id?` | `string` | ‐ | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `output` | `object` | `ComputerToolOutput` | The output of the computer call. | | `output.data` | `string` | ‐ | A base64 encoded image data or a URL representing the screenshot. | | `output.providerData?` | `Record`<`string`, `any`> | ‐ | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `output.type` | `"computer_screenshot"` | ‐ | ‐ | | `providerData?` | `Record`<`string`, `any`> | ‐ | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `type` | `"computer_call_result"` | ‐ | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-14) ```ts { action: { commands: string[]; maxOutputLength?: number; timeoutMs?: number; }; callId: string; id?: string; providerData?: Record; status?: "in_progress" | "completed" | "incomplete"; type: "shell_call"; } ``` | Name | Type | Default value | Description | | ------------------------- | -------------------------------------------------- | ------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `action` | `object` | `ShellAction` | ‐ | | `action.commands` | `string`\[] | ‐ | ‐ | | `action.maxOutputLength?` | `number` | ‐ | ‐ | | `action.timeoutMs?` | `number` | ‐ | ‐ | | `callId` | `string` | ‐ | ‐ | | `id?` | `string` | ‐ | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `providerData?` | `Record`<`string`, `any`> | ‐ | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status?` | `"in_progress"` \| `"completed"` \| `"incomplete"` | ‐ | ‐ | | `type` | `"shell_call"` | ‐ | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-15) ```ts { callId: string; id?: string; maxOutputLength?: number; output: object[]; providerData?: Record; type: "shell_call_output"; } ``` | Name | Type | Description | | ------------------ | ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `callId` | `string` | ‐ | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `maxOutputLength?` | `number` | ‐ | | `output` | `object`\[] | ‐ | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `type` | `"shell_call_output"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-16) ```ts { callId: string; id?: string; operation: | { diff: string; path: string; type: "create_file"; } | { diff: string; moveTo?: string; path: string; type: "update_file"; } | { path: string; type: "delete_file"; }; providerData?: Record; status: "in_progress" | "completed"; type: "apply_patch_call"; } ``` | Name | Type | Default value | Description | | --------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `callId` | `string` | ‐ | ‐ | | `id?` | `string` | ‐ | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `operation` | \| { `diff`: `string`; `path`: `string`; `type`: `"create_file"`; } \| { `diff`: `string`; `moveTo?`: `string`; `path`: `string`; `type`: `"update_file"`; } \| { `path`: `string`; `type`: `"delete_file"`; } | `ApplyPatchOperation` | ‐ | | `providerData?` | `Record`<`string`, `any`> | ‐ | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status` | `"in_progress"` \| `"completed"` | ‐ | ‐ | | `type` | `"apply_patch_call"` | ‐ | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-17) ```ts { callId: string; id?: string; output?: string; providerData?: Record; status: "completed" | "failed"; type: "apply_patch_call_output"; } ``` | Name | Type | Description | | --------------- | --------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `callId` | `string` | ‐ | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `output?` | `string` | ‐ | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status` | `"completed"` \| `"failed"` | ‐ | | `type` | `"apply_patch_call_output"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-18) ```ts { content: object[]; id?: string; providerData?: Record; rawContent?: object[]; type: "reasoning"; } ``` | Name | Type | Description | | --------------- | ------------------------- | ------------------------------------------------------------------------------------------------------------- | | `content` | `object`\[] | The user facing representation of the reasoning. Additional information might be in the `providerData` field. | | `id?` | `string` | ‐ | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `rawContent?` | `object`\[] | The raw reasoning text from the model. | | `type` | `"reasoning"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-19) ```ts { created_by?: string; encrypted_content: string; id?: string; providerData?: Record; type: "compaction"; } ``` | Name | Type | Description | | ------------------- | ------------------------- | ------------------------------------------------------------------------------------------------------------ | | `created_by?` | `string` | Identifier for the generator of this compaction item. | | `encrypted_content` | `string` | Encrypted payload returned by the compaction endpoint. | | `id?` | `string` | Identifier for the compaction item. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `type` | `"compaction"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-20) ```ts { id?: string; providerData?: Record; type: "unknown"; } ``` | Name | Type | Description | | --------------- | ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `type` | `"unknown"` | ‐ | *** `undefined` ##### type [Section titled “type”](#type-1) ```ts type: string; ``` #### Overrides [Section titled “Overrides”](#overrides-2) ```ts RunItemBase.toJSON ``` # RunToolSearchCallItem ## Extends [Section titled “Extends”](#extends) * `RunItemBase` ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new RunToolSearchCallItem(rawItem, agent): RunToolSearchCallItem; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | ----------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `rawItem` | { `arguments`: `unknown`; `call_id?`: `string` \| `null`; `callId?`: `string` \| `null`; `execution?`: `"client"` \| `"server"`; `id?`: `string`; `providerData?`: `Record`<`string`, `any`>; `status?`: `string`; `type`: `"tool_search_call"`; } | ‐ | | `rawItem.arguments` | `unknown` | ‐ | | `rawItem.call_id?` | `string` \| `null` | ‐ | | `rawItem.callId?` | `string` \| `null` | ‐ | | `rawItem.execution?` | `"client"` \| `"server"` | ‐ | | `rawItem.id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `rawItem.providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `rawItem.status?` | `string` | ‐ | | `rawItem.type` | `"tool_search_call"` | ‐ | | `agent` | [`Agent`](/openai-agents-js/openai/agents-core/classes/agent/) | ‐ | #### Returns [Section titled “Returns”](#returns) `RunToolSearchCallItem` #### Overrides [Section titled “Overrides”](#overrides) ```ts RunItemBase.constructor ``` ## Properties [Section titled “Properties”](#properties) ### agent [Section titled “agent”](#agent) ```ts agent: Agent; ``` *** ### rawItem [Section titled “rawItem”](#rawitem) ```ts rawItem: object; ``` | Name | Type | Default value | Description | | --------------- | ------------------------- | ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `arguments` | `unknown` | `ToolSearchCallArguments` | ‐ | | `call_id?` | `string` \| `null` | ‐ | ‐ | | `callId?` | `string` \| `null` | ‐ | ‐ | | `execution?` | `"client"` \| `"server"` | ‐ | ‐ | | `id?` | `string` | ‐ | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `providerData?` | `Record`<`string`, `any`> | ‐ | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status?` | `string` | ‐ | ‐ | | `type` | `"tool_search_call"` | ‐ | ‐ | #### Inherited from [Section titled “Inherited from”](#inherited-from) ```ts RunItemBase.rawItem ``` *** ### type [Section titled “type”](#type) ```ts readonly type: "tool_search_call_item"; ``` #### Overrides [Section titled “Overrides”](#overrides-1) ```ts RunItemBase.type ``` ## Methods [Section titled “Methods”](#methods) ### toJSON() [Section titled “toJSON()”](#tojson) ```ts toJSON(): object; ``` #### Returns [Section titled “Returns”](#returns-1) `object` ##### agent [Section titled “agent”](#agent-1) ```ts agent: object; ``` ###### agent.name [Section titled “agent.name”](#agentname) ```ts name: string; ``` ##### rawItem [Section titled “rawItem”](#rawitem-1) ```ts rawItem: | { content: ( | { providerData?: Record; refusal: string; type: "refusal"; } | { providerData?: Record; text: string; type: "output_text"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; } | { image: string; providerData?: Record; type: "image"; })[]; id?: string; providerData?: Record; role: "assistant"; status: "in_progress" | "completed" | "incomplete"; type?: "message"; } | { content: | string | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; })[]; id?: string; providerData?: Record; role: "user"; type?: "message"; } | { content: string; id?: string; providerData?: Record; role: "system"; type?: "message"; } | { arguments?: string; id?: string; name: string; output?: string; providerData?: Record; status?: string; type: "hosted_tool_call"; } | { arguments: string; callId: string; id?: string; name: string; namespace?: string; providerData?: Record; status?: "in_progress" | "completed" | "incomplete"; type: "function_call"; } | { arguments: unknown; call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; type: "tool_search_call"; } | { call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; tools: Record[]; type: "tool_search_output"; } | { callId: string; id?: string; name: string; namespace?: string; output: | string | { providerData?: Record; text: string; type: "text"; } | { detail?: "low" | "high" | "auto" | string & object; image?: | string | { data: string | Uint8Array; mediaType?: string; } | { url: string; } | { fileId: string; }; providerData?: Record; type: "image"; } | { file: | string | { data: string | Uint8Array; filename: string; mediaType: string; } | { filename?: string; url: string; } | { filename?: string; id: string; }; providerData?: Record; type: "file"; } | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; })[]; providerData?: Record; status: "in_progress" | "completed" | "incomplete"; type: "function_call_result"; } | { action?: | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; }; actions?: ( | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; })[]; callId: string; id?: string; providerData?: Record; status: "in_progress" | "completed" | "incomplete"; type: "computer_call"; } | { callId: string; id?: string; output: { data: string; providerData?: Record; type: "computer_screenshot"; }; providerData?: Record; type: "computer_call_result"; } | { action: { commands: string[]; maxOutputLength?: number; timeoutMs?: number; }; callId: string; id?: string; providerData?: Record; status?: "in_progress" | "completed" | "incomplete"; type: "shell_call"; } | { callId: string; id?: string; maxOutputLength?: number; output: object[]; providerData?: Record; type: "shell_call_output"; } | { callId: string; id?: string; operation: | { diff: string; path: string; type: "create_file"; } | { diff: string; moveTo?: string; path: string; type: "update_file"; } | { path: string; type: "delete_file"; }; providerData?: Record; status: "in_progress" | "completed"; type: "apply_patch_call"; } | { callId: string; id?: string; output?: string; providerData?: Record; status: "completed" | "failed"; type: "apply_patch_call_output"; } | { content: object[]; id?: string; providerData?: Record; rawContent?: object[]; type: "reasoning"; } | { created_by?: string; encrypted_content: string; id?: string; providerData?: Record; type: "compaction"; } | { id?: string; providerData?: Record; type: "unknown"; } | undefined; ``` ###### Union Members [Section titled “Union Members”](#union-members) ###### Type Literal [Section titled “Type Literal”](#type-literal) ```ts { content: ( | { providerData?: Record; refusal: string; type: "refusal"; } | { providerData?: Record; text: string; type: "output_text"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; } | { image: string; providerData?: Record; type: "image"; })[]; id?: string; providerData?: Record; role: "assistant"; status: "in_progress" | "completed" | "incomplete"; type?: "message"; } ``` | Name | Type | Description | | --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `content` | ( \| { `providerData?`: `Record`<`string`, `any`>; `refusal`: `string`; `type`: `"refusal"`; } \| { `providerData?`: `Record`<`string`, `any`>; `text`: `string`; `type`: `"output_text"`; } \| { `audio`: \| `string` \| { `id`: `string`; }; `format?`: `string` \| `null`; `providerData?`: `Record`<`string`, `any`>; `transcript?`: `string` \| `null`; `type`: `"audio"`; } \| { `image`: `string`; `providerData?`: `Record`<`string`, `any`>; `type`: `"image"`; })\[] | The content of the message. | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `role` | `"assistant"` | Representing a message from the assistant (i.e. the model) | | `status` | `"in_progress"` \| `"completed"` \| `"incomplete"` | The status of the message. | | `type?` | `"message"` | Any item without a type is treated as a message | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-1) ```ts { content: | string | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; })[]; id?: string; providerData?: Record; role: "user"; type?: "message"; } ``` | Name | Type | Description | | --------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `content` | \| `string` \| ( \| { `providerData?`: `Record`<`string`, `any`>; `text`: `string`; `type`: `"input_text"`; } \| { `detail?`: `string`; `image?`: \| `string` \| { `id`: `string`; }; `providerData?`: `Record`<`string`, `any`>; `type`: `"input_image"`; } \| { `file?`: \| `string` \| { `id`: `string`; } \| { `url`: `string`; }; `filename?`: `string`; `providerData?`: `Record`<`string`, `any`>; `type`: `"input_file"`; } \| { `audio`: \| `string` \| { `id`: `string`; }; `format?`: `string` \| `null`; `providerData?`: `Record`<`string`, `any`>; `transcript?`: `string` \| `null`; `type`: `"audio"`; })\[] | The content of the message. | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `role` | `"user"` | Representing a message from the user | | `type?` | `"message"` | Any item without a type is treated as a message | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-2) ```ts { content: string; id?: string; providerData?: Record; role: "system"; type?: "message"; } ``` | Name | Type | Description | | --------------- | ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `content` | `string` | The content of the message. | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `role` | `"system"` | Representing a system message to the user | | `type?` | `"message"` | Any item without a type is treated as a message | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-3) ```ts { arguments?: string; id?: string; name: string; output?: string; providerData?: Record; status?: string; type: "hosted_tool_call"; } ``` | Name | Type | Description | | --------------- | ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `arguments?` | `string` | The arguments of the hosted tool call. | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `name` | `string` | The name of the hosted tool. For example `web_search_call` or `file_search_call` | | `output?` | `string` | The primary output of the tool call. Additional output might be in the `providerData` field. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status?` | `string` | The status of the tool call. | | `type` | `"hosted_tool_call"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-4) ```ts { arguments: string; callId: string; id?: string; name: string; namespace?: string; providerData?: Record; status?: "in_progress" | "completed" | "incomplete"; type: "function_call"; } ``` | Name | Type | Description | | --------------- | -------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `arguments` | `string` | The arguments of the function call. | | `callId` | `string` | The ID of the tool call. Required to match up the respective tool call result. | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `name` | `string` | The name of the function. | | `namespace?` | `string` | Optional namespace used to qualify the function name for tool search. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status?` | `"in_progress"` \| `"completed"` \| `"incomplete"` | The status of the function call. | | `type` | `"function_call"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-5) ```ts { arguments: unknown; call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; type: "tool_search_call"; } ``` | Name | Type | Default value | Description | | --------------- | ------------------------- | ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `arguments` | `unknown` | `ToolSearchCallArguments` | ‐ | | `call_id?` | `string` \| `null` | ‐ | ‐ | | `callId?` | `string` \| `null` | ‐ | ‐ | | `execution?` | `"client"` \| `"server"` | ‐ | ‐ | | `id?` | `string` | ‐ | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `providerData?` | `Record`<`string`, `any`> | ‐ | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status?` | `string` | ‐ | ‐ | | `type` | `"tool_search_call"` | ‐ | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-6) ```ts { call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; tools: Record[]; type: "tool_search_output"; } ``` | Name | Type | Description | | --------------- | ---------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `call_id?` | `string` \| `null` | ‐ | | `callId?` | `string` \| `null` | ‐ | | `execution?` | `"client"` \| `"server"` | ‐ | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status?` | `string` | ‐ | | `tools` | `Record`<`string`, `any`>\[] | ‐ | | `type` | `"tool_search_output"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-7) ```ts { callId: string; id?: string; name: string; namespace?: string; output: | string | { providerData?: Record; text: string; type: "text"; } | { detail?: "low" | "high" | "auto" | string & object; image?: | string | { data: string | Uint8Array; mediaType?: string; } | { url: string; } | { fileId: string; }; providerData?: Record; type: "image"; } | { file: | string | { data: string | Uint8Array; filename: string; mediaType: string; } | { filename?: string; url: string; } | { filename?: string; id: string; }; providerData?: Record; type: "file"; } | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; })[]; providerData?: Record; status: "in_progress" | "completed" | "incomplete"; type: "function_call_result"; } ``` | Name | Type | Description | | --------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `callId` | `string` | The ID of the tool call. Required to match up the respective tool call result. | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `name` | `string` | The name of the tool that was called | | `namespace?` | `string` | Optional namespace preserved from the originating function call. | | `output` | \| `string` \| { `providerData?`: `Record`<`string`, `any`>; `text`: `string`; `type`: `"text"`; } \| { `detail?`: `"low"` \| `"high"` \| `"auto"` \| `string` & `object`; `image?`: \| `string` \| { `data`: `string` \| `Uint8Array`<`ArrayBuffer`>; `mediaType?`: `string`; } \| { `url`: `string`; } \| { `fileId`: `string`; }; `providerData?`: `Record`<`string`, `any`>; `type`: `"image"`; } \| { `file`: \| `string` \| { `data`: `string` \| `Uint8Array`<`ArrayBuffer`>; `filename`: `string`; `mediaType`: `string`; } \| { `filename?`: `string`; `url`: `string`; } \| { `filename?`: `string`; `id`: `string`; }; `providerData?`: `Record`<`string`, `any`>; `type`: `"file"`; } \| ( \| { `providerData?`: `Record`<`string`, `any`>; `text`: `string`; `type`: `"input_text"`; } \| { `detail?`: `string`; `image?`: \| `string` \| { `id`: `string`; }; `providerData?`: `Record`<`string`, `any`>; `type`: `"input_image"`; } \| { `file?`: \| `string` \| { `id`: `string`; } \| { `url`: `string`; }; `filename?`: `string`; `providerData?`: `Record`<`string`, `any`>; `type`: `"input_file"`; })\[] | The output of the tool call. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status` | `"in_progress"` \| `"completed"` \| `"incomplete"` | The status of the tool call. | | `type` | `"function_call_result"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-8) ```ts { action?: | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; }; actions?: ( | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; })[]; callId: string; id?: string; providerData?: Record; status: "in_progress" | "completed" | "incomplete"; type: "computer_call"; } ``` | Name | Type | Description | | --------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `action?` | \| { `type`: `"screenshot"`; } \| { `button`: `"left"` \| `"right"` \| `"wheel"` \| `"back"` \| `"forward"`; `type`: `"click"`; `x`: `number`; `y`: `number`; } \| { `type`: `"double_click"`; `x`: `number`; `y`: `number`; } \| { `scroll_x`: `number`; `scroll_y`: `number`; `type`: `"scroll"`; `x`: `number`; `y`: `number`; } \| { `text`: `string`; `type`: `"type"`; } \| { `type`: `"wait"`; } \| { `type`: `"move"`; `x`: `number`; `y`: `number`; } \| { `keys`: `string`\[]; `type`: `"keypress"`; } \| { `path`: `object`\[]; `type`: `"drag"`; } | The legacy single action to be performed by the computer. | | `actions?` | ( \| { `type`: `"screenshot"`; } \| { `button`: `"left"` \| `"right"` \| `"wheel"` \| `"back"` \| `"forward"`; `type`: `"click"`; `x`: `number`; `y`: `number`; } \| { `type`: `"double_click"`; `x`: `number`; `y`: `number`; } \| { `scroll_x`: `number`; `scroll_y`: `number`; `type`: `"scroll"`; `x`: `number`; `y`: `number`; } \| { `text`: `string`; `type`: `"type"`; } \| { `type`: `"wait"`; } \| { `type`: `"move"`; `x`: `number`; `y`: `number`; } \| { `keys`: `string`\[]; `type`: `"keypress"`; } \| { `path`: `object`\[]; `type`: `"drag"`; })\[] | Batched actions returned by the GA computer tool. | | `callId` | `string` | The ID of the computer call. Required to match up the respective computer call result. | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status` | `"in_progress"` \| `"completed"` \| `"incomplete"` | The status of the computer call. | | `type` | `"computer_call"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-9) ```ts { callId: string; id?: string; output: { data: string; providerData?: Record; type: "computer_screenshot"; }; providerData?: Record; type: "computer_call_result"; } ``` | Name | Type | Default value | Description | | ---------------------- | ------------------------- | -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `callId` | `string` | ‐ | The ID of the computer call. Required to match up the respective computer call result. | | `id?` | `string` | ‐ | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `output` | `object` | `ComputerToolOutput` | The output of the computer call. | | `output.data` | `string` | ‐ | A base64 encoded image data or a URL representing the screenshot. | | `output.providerData?` | `Record`<`string`, `any`> | ‐ | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `output.type` | `"computer_screenshot"` | ‐ | ‐ | | `providerData?` | `Record`<`string`, `any`> | ‐ | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `type` | `"computer_call_result"` | ‐ | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-10) ```ts { action: { commands: string[]; maxOutputLength?: number; timeoutMs?: number; }; callId: string; id?: string; providerData?: Record; status?: "in_progress" | "completed" | "incomplete"; type: "shell_call"; } ``` | Name | Type | Default value | Description | | ------------------------- | -------------------------------------------------- | ------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `action` | `object` | `ShellAction` | ‐ | | `action.commands` | `string`\[] | ‐ | ‐ | | `action.maxOutputLength?` | `number` | ‐ | ‐ | | `action.timeoutMs?` | `number` | ‐ | ‐ | | `callId` | `string` | ‐ | ‐ | | `id?` | `string` | ‐ | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `providerData?` | `Record`<`string`, `any`> | ‐ | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status?` | `"in_progress"` \| `"completed"` \| `"incomplete"` | ‐ | ‐ | | `type` | `"shell_call"` | ‐ | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-11) ```ts { callId: string; id?: string; maxOutputLength?: number; output: object[]; providerData?: Record; type: "shell_call_output"; } ``` | Name | Type | Description | | ------------------ | ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `callId` | `string` | ‐ | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `maxOutputLength?` | `number` | ‐ | | `output` | `object`\[] | ‐ | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `type` | `"shell_call_output"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-12) ```ts { callId: string; id?: string; operation: | { diff: string; path: string; type: "create_file"; } | { diff: string; moveTo?: string; path: string; type: "update_file"; } | { path: string; type: "delete_file"; }; providerData?: Record; status: "in_progress" | "completed"; type: "apply_patch_call"; } ``` | Name | Type | Default value | Description | | --------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `callId` | `string` | ‐ | ‐ | | `id?` | `string` | ‐ | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `operation` | \| { `diff`: `string`; `path`: `string`; `type`: `"create_file"`; } \| { `diff`: `string`; `moveTo?`: `string`; `path`: `string`; `type`: `"update_file"`; } \| { `path`: `string`; `type`: `"delete_file"`; } | `ApplyPatchOperation` | ‐ | | `providerData?` | `Record`<`string`, `any`> | ‐ | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status` | `"in_progress"` \| `"completed"` | ‐ | ‐ | | `type` | `"apply_patch_call"` | ‐ | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-13) ```ts { callId: string; id?: string; output?: string; providerData?: Record; status: "completed" | "failed"; type: "apply_patch_call_output"; } ``` | Name | Type | Description | | --------------- | --------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `callId` | `string` | ‐ | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `output?` | `string` | ‐ | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status` | `"completed"` \| `"failed"` | ‐ | | `type` | `"apply_patch_call_output"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-14) ```ts { content: object[]; id?: string; providerData?: Record; rawContent?: object[]; type: "reasoning"; } ``` | Name | Type | Description | | --------------- | ------------------------- | ------------------------------------------------------------------------------------------------------------- | | `content` | `object`\[] | The user facing representation of the reasoning. Additional information might be in the `providerData` field. | | `id?` | `string` | ‐ | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `rawContent?` | `object`\[] | The raw reasoning text from the model. | | `type` | `"reasoning"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-15) ```ts { created_by?: string; encrypted_content: string; id?: string; providerData?: Record; type: "compaction"; } ``` | Name | Type | Description | | ------------------- | ------------------------- | ------------------------------------------------------------------------------------------------------------ | | `created_by?` | `string` | Identifier for the generator of this compaction item. | | `encrypted_content` | `string` | Encrypted payload returned by the compaction endpoint. | | `id?` | `string` | Identifier for the compaction item. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `type` | `"compaction"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-16) ```ts { id?: string; providerData?: Record; type: "unknown"; } ``` | Name | Type | Description | | --------------- | ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `type` | `"unknown"` | ‐ | *** `undefined` ##### type [Section titled “type”](#type-1) ```ts type: string; ``` #### Overrides [Section titled “Overrides”](#overrides-2) ```ts RunItemBase.toJSON ``` # RunToolSearchOutputItem ## Extends [Section titled “Extends”](#extends) * `RunItemBase` ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new RunToolSearchOutputItem(rawItem, agent): RunToolSearchOutputItem; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `rawItem` | { `call_id?`: `string` \| `null`; `callId?`: `string` \| `null`; `execution?`: `"client"` \| `"server"`; `id?`: `string`; `providerData?`: `Record`<`string`, `any`>; `status?`: `string`; `tools`: `Record`<`string`, `any`>\[]; `type`: `"tool_search_output"`; } | ‐ | | `rawItem.call_id?` | `string` \| `null` | ‐ | | `rawItem.callId?` | `string` \| `null` | ‐ | | `rawItem.execution?` | `"client"` \| `"server"` | ‐ | | `rawItem.id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `rawItem.providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `rawItem.status?` | `string` | ‐ | | `rawItem.tools` | `Record`<`string`, `any`>\[] | ‐ | | `rawItem.type` | `"tool_search_output"` | ‐ | | `agent` | [`Agent`](/openai-agents-js/openai/agents-core/classes/agent/) | ‐ | #### Returns [Section titled “Returns”](#returns) `RunToolSearchOutputItem` #### Overrides [Section titled “Overrides”](#overrides) ```ts RunItemBase.constructor ``` ## Properties [Section titled “Properties”](#properties) ### agent [Section titled “agent”](#agent) ```ts agent: Agent; ``` *** ### rawItem [Section titled “rawItem”](#rawitem) ```ts rawItem: object; ``` | Name | Type | Description | | --------------- | ---------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `call_id?` | `string` \| `null` | ‐ | | `callId?` | `string` \| `null` | ‐ | | `execution?` | `"client"` \| `"server"` | ‐ | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status?` | `string` | ‐ | | `tools` | `Record`<`string`, `any`>\[] | ‐ | | `type` | `"tool_search_output"` | ‐ | #### Inherited from [Section titled “Inherited from”](#inherited-from) ```ts RunItemBase.rawItem ``` *** ### type [Section titled “type”](#type) ```ts readonly type: "tool_search_output_item"; ``` #### Overrides [Section titled “Overrides”](#overrides-1) ```ts RunItemBase.type ``` ## Methods [Section titled “Methods”](#methods) ### toJSON() [Section titled “toJSON()”](#tojson) ```ts toJSON(): object; ``` #### Returns [Section titled “Returns”](#returns-1) `object` ##### agent [Section titled “agent”](#agent-1) ```ts agent: object; ``` ###### agent.name [Section titled “agent.name”](#agentname) ```ts name: string; ``` ##### rawItem [Section titled “rawItem”](#rawitem-1) ```ts rawItem: | { content: ( | { providerData?: Record; refusal: string; type: "refusal"; } | { providerData?: Record; text: string; type: "output_text"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; } | { image: string; providerData?: Record; type: "image"; })[]; id?: string; providerData?: Record; role: "assistant"; status: "in_progress" | "completed" | "incomplete"; type?: "message"; } | { content: | string | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; })[]; id?: string; providerData?: Record; role: "user"; type?: "message"; } | { content: string; id?: string; providerData?: Record; role: "system"; type?: "message"; } | { arguments?: string; id?: string; name: string; output?: string; providerData?: Record; status?: string; type: "hosted_tool_call"; } | { arguments: string; callId: string; id?: string; name: string; namespace?: string; providerData?: Record; status?: "in_progress" | "completed" | "incomplete"; type: "function_call"; } | { arguments: unknown; call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; type: "tool_search_call"; } | { call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; tools: Record[]; type: "tool_search_output"; } | { callId: string; id?: string; name: string; namespace?: string; output: | string | { providerData?: Record; text: string; type: "text"; } | { detail?: "low" | "high" | "auto" | string & object; image?: | string | { data: string | Uint8Array; mediaType?: string; } | { url: string; } | { fileId: string; }; providerData?: Record; type: "image"; } | { file: | string | { data: string | Uint8Array; filename: string; mediaType: string; } | { filename?: string; url: string; } | { filename?: string; id: string; }; providerData?: Record; type: "file"; } | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; })[]; providerData?: Record; status: "in_progress" | "completed" | "incomplete"; type: "function_call_result"; } | { action?: | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; }; actions?: ( | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; })[]; callId: string; id?: string; providerData?: Record; status: "in_progress" | "completed" | "incomplete"; type: "computer_call"; } | { callId: string; id?: string; output: { data: string; providerData?: Record; type: "computer_screenshot"; }; providerData?: Record; type: "computer_call_result"; } | { action: { commands: string[]; maxOutputLength?: number; timeoutMs?: number; }; callId: string; id?: string; providerData?: Record; status?: "in_progress" | "completed" | "incomplete"; type: "shell_call"; } | { callId: string; id?: string; maxOutputLength?: number; output: object[]; providerData?: Record; type: "shell_call_output"; } | { callId: string; id?: string; operation: | { diff: string; path: string; type: "create_file"; } | { diff: string; moveTo?: string; path: string; type: "update_file"; } | { path: string; type: "delete_file"; }; providerData?: Record; status: "in_progress" | "completed"; type: "apply_patch_call"; } | { callId: string; id?: string; output?: string; providerData?: Record; status: "completed" | "failed"; type: "apply_patch_call_output"; } | { content: object[]; id?: string; providerData?: Record; rawContent?: object[]; type: "reasoning"; } | { created_by?: string; encrypted_content: string; id?: string; providerData?: Record; type: "compaction"; } | { id?: string; providerData?: Record; type: "unknown"; } | undefined; ``` ###### Union Members [Section titled “Union Members”](#union-members) ###### Type Literal [Section titled “Type Literal”](#type-literal) ```ts { content: ( | { providerData?: Record; refusal: string; type: "refusal"; } | { providerData?: Record; text: string; type: "output_text"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; } | { image: string; providerData?: Record; type: "image"; })[]; id?: string; providerData?: Record; role: "assistant"; status: "in_progress" | "completed" | "incomplete"; type?: "message"; } ``` | Name | Type | Description | | --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `content` | ( \| { `providerData?`: `Record`<`string`, `any`>; `refusal`: `string`; `type`: `"refusal"`; } \| { `providerData?`: `Record`<`string`, `any`>; `text`: `string`; `type`: `"output_text"`; } \| { `audio`: \| `string` \| { `id`: `string`; }; `format?`: `string` \| `null`; `providerData?`: `Record`<`string`, `any`>; `transcript?`: `string` \| `null`; `type`: `"audio"`; } \| { `image`: `string`; `providerData?`: `Record`<`string`, `any`>; `type`: `"image"`; })\[] | The content of the message. | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `role` | `"assistant"` | Representing a message from the assistant (i.e. the model) | | `status` | `"in_progress"` \| `"completed"` \| `"incomplete"` | The status of the message. | | `type?` | `"message"` | Any item without a type is treated as a message | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-1) ```ts { content: | string | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; })[]; id?: string; providerData?: Record; role: "user"; type?: "message"; } ``` | Name | Type | Description | | --------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `content` | \| `string` \| ( \| { `providerData?`: `Record`<`string`, `any`>; `text`: `string`; `type`: `"input_text"`; } \| { `detail?`: `string`; `image?`: \| `string` \| { `id`: `string`; }; `providerData?`: `Record`<`string`, `any`>; `type`: `"input_image"`; } \| { `file?`: \| `string` \| { `id`: `string`; } \| { `url`: `string`; }; `filename?`: `string`; `providerData?`: `Record`<`string`, `any`>; `type`: `"input_file"`; } \| { `audio`: \| `string` \| { `id`: `string`; }; `format?`: `string` \| `null`; `providerData?`: `Record`<`string`, `any`>; `transcript?`: `string` \| `null`; `type`: `"audio"`; })\[] | The content of the message. | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `role` | `"user"` | Representing a message from the user | | `type?` | `"message"` | Any item without a type is treated as a message | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-2) ```ts { content: string; id?: string; providerData?: Record; role: "system"; type?: "message"; } ``` | Name | Type | Description | | --------------- | ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `content` | `string` | The content of the message. | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `role` | `"system"` | Representing a system message to the user | | `type?` | `"message"` | Any item without a type is treated as a message | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-3) ```ts { arguments?: string; id?: string; name: string; output?: string; providerData?: Record; status?: string; type: "hosted_tool_call"; } ``` | Name | Type | Description | | --------------- | ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `arguments?` | `string` | The arguments of the hosted tool call. | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `name` | `string` | The name of the hosted tool. For example `web_search_call` or `file_search_call` | | `output?` | `string` | The primary output of the tool call. Additional output might be in the `providerData` field. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status?` | `string` | The status of the tool call. | | `type` | `"hosted_tool_call"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-4) ```ts { arguments: string; callId: string; id?: string; name: string; namespace?: string; providerData?: Record; status?: "in_progress" | "completed" | "incomplete"; type: "function_call"; } ``` | Name | Type | Description | | --------------- | -------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `arguments` | `string` | The arguments of the function call. | | `callId` | `string` | The ID of the tool call. Required to match up the respective tool call result. | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `name` | `string` | The name of the function. | | `namespace?` | `string` | Optional namespace used to qualify the function name for tool search. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status?` | `"in_progress"` \| `"completed"` \| `"incomplete"` | The status of the function call. | | `type` | `"function_call"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-5) ```ts { arguments: unknown; call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; type: "tool_search_call"; } ``` | Name | Type | Default value | Description | | --------------- | ------------------------- | ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `arguments` | `unknown` | `ToolSearchCallArguments` | ‐ | | `call_id?` | `string` \| `null` | ‐ | ‐ | | `callId?` | `string` \| `null` | ‐ | ‐ | | `execution?` | `"client"` \| `"server"` | ‐ | ‐ | | `id?` | `string` | ‐ | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `providerData?` | `Record`<`string`, `any`> | ‐ | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status?` | `string` | ‐ | ‐ | | `type` | `"tool_search_call"` | ‐ | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-6) ```ts { call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; tools: Record[]; type: "tool_search_output"; } ``` | Name | Type | Description | | --------------- | ---------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `call_id?` | `string` \| `null` | ‐ | | `callId?` | `string` \| `null` | ‐ | | `execution?` | `"client"` \| `"server"` | ‐ | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status?` | `string` | ‐ | | `tools` | `Record`<`string`, `any`>\[] | ‐ | | `type` | `"tool_search_output"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-7) ```ts { callId: string; id?: string; name: string; namespace?: string; output: | string | { providerData?: Record; text: string; type: "text"; } | { detail?: "low" | "high" | "auto" | string & object; image?: | string | { data: string | Uint8Array; mediaType?: string; } | { url: string; } | { fileId: string; }; providerData?: Record; type: "image"; } | { file: | string | { data: string | Uint8Array; filename: string; mediaType: string; } | { filename?: string; url: string; } | { filename?: string; id: string; }; providerData?: Record; type: "file"; } | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; })[]; providerData?: Record; status: "in_progress" | "completed" | "incomplete"; type: "function_call_result"; } ``` | Name | Type | Description | | --------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `callId` | `string` | The ID of the tool call. Required to match up the respective tool call result. | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `name` | `string` | The name of the tool that was called | | `namespace?` | `string` | Optional namespace preserved from the originating function call. | | `output` | \| `string` \| { `providerData?`: `Record`<`string`, `any`>; `text`: `string`; `type`: `"text"`; } \| { `detail?`: `"low"` \| `"high"` \| `"auto"` \| `string` & `object`; `image?`: \| `string` \| { `data`: `string` \| `Uint8Array`<`ArrayBuffer`>; `mediaType?`: `string`; } \| { `url`: `string`; } \| { `fileId`: `string`; }; `providerData?`: `Record`<`string`, `any`>; `type`: `"image"`; } \| { `file`: \| `string` \| { `data`: `string` \| `Uint8Array`<`ArrayBuffer`>; `filename`: `string`; `mediaType`: `string`; } \| { `filename?`: `string`; `url`: `string`; } \| { `filename?`: `string`; `id`: `string`; }; `providerData?`: `Record`<`string`, `any`>; `type`: `"file"`; } \| ( \| { `providerData?`: `Record`<`string`, `any`>; `text`: `string`; `type`: `"input_text"`; } \| { `detail?`: `string`; `image?`: \| `string` \| { `id`: `string`; }; `providerData?`: `Record`<`string`, `any`>; `type`: `"input_image"`; } \| { `file?`: \| `string` \| { `id`: `string`; } \| { `url`: `string`; }; `filename?`: `string`; `providerData?`: `Record`<`string`, `any`>; `type`: `"input_file"`; })\[] | The output of the tool call. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status` | `"in_progress"` \| `"completed"` \| `"incomplete"` | The status of the tool call. | | `type` | `"function_call_result"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-8) ```ts { action?: | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; }; actions?: ( | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; })[]; callId: string; id?: string; providerData?: Record; status: "in_progress" | "completed" | "incomplete"; type: "computer_call"; } ``` | Name | Type | Description | | --------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `action?` | \| { `type`: `"screenshot"`; } \| { `button`: `"left"` \| `"right"` \| `"wheel"` \| `"back"` \| `"forward"`; `type`: `"click"`; `x`: `number`; `y`: `number`; } \| { `type`: `"double_click"`; `x`: `number`; `y`: `number`; } \| { `scroll_x`: `number`; `scroll_y`: `number`; `type`: `"scroll"`; `x`: `number`; `y`: `number`; } \| { `text`: `string`; `type`: `"type"`; } \| { `type`: `"wait"`; } \| { `type`: `"move"`; `x`: `number`; `y`: `number`; } \| { `keys`: `string`\[]; `type`: `"keypress"`; } \| { `path`: `object`\[]; `type`: `"drag"`; } | The legacy single action to be performed by the computer. | | `actions?` | ( \| { `type`: `"screenshot"`; } \| { `button`: `"left"` \| `"right"` \| `"wheel"` \| `"back"` \| `"forward"`; `type`: `"click"`; `x`: `number`; `y`: `number`; } \| { `type`: `"double_click"`; `x`: `number`; `y`: `number`; } \| { `scroll_x`: `number`; `scroll_y`: `number`; `type`: `"scroll"`; `x`: `number`; `y`: `number`; } \| { `text`: `string`; `type`: `"type"`; } \| { `type`: `"wait"`; } \| { `type`: `"move"`; `x`: `number`; `y`: `number`; } \| { `keys`: `string`\[]; `type`: `"keypress"`; } \| { `path`: `object`\[]; `type`: `"drag"`; })\[] | Batched actions returned by the GA computer tool. | | `callId` | `string` | The ID of the computer call. Required to match up the respective computer call result. | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status` | `"in_progress"` \| `"completed"` \| `"incomplete"` | The status of the computer call. | | `type` | `"computer_call"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-9) ```ts { callId: string; id?: string; output: { data: string; providerData?: Record; type: "computer_screenshot"; }; providerData?: Record; type: "computer_call_result"; } ``` | Name | Type | Default value | Description | | ---------------------- | ------------------------- | -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `callId` | `string` | ‐ | The ID of the computer call. Required to match up the respective computer call result. | | `id?` | `string` | ‐ | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `output` | `object` | `ComputerToolOutput` | The output of the computer call. | | `output.data` | `string` | ‐ | A base64 encoded image data or a URL representing the screenshot. | | `output.providerData?` | `Record`<`string`, `any`> | ‐ | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `output.type` | `"computer_screenshot"` | ‐ | ‐ | | `providerData?` | `Record`<`string`, `any`> | ‐ | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `type` | `"computer_call_result"` | ‐ | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-10) ```ts { action: { commands: string[]; maxOutputLength?: number; timeoutMs?: number; }; callId: string; id?: string; providerData?: Record; status?: "in_progress" | "completed" | "incomplete"; type: "shell_call"; } ``` | Name | Type | Default value | Description | | ------------------------- | -------------------------------------------------- | ------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `action` | `object` | `ShellAction` | ‐ | | `action.commands` | `string`\[] | ‐ | ‐ | | `action.maxOutputLength?` | `number` | ‐ | ‐ | | `action.timeoutMs?` | `number` | ‐ | ‐ | | `callId` | `string` | ‐ | ‐ | | `id?` | `string` | ‐ | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `providerData?` | `Record`<`string`, `any`> | ‐ | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status?` | `"in_progress"` \| `"completed"` \| `"incomplete"` | ‐ | ‐ | | `type` | `"shell_call"` | ‐ | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-11) ```ts { callId: string; id?: string; maxOutputLength?: number; output: object[]; providerData?: Record; type: "shell_call_output"; } ``` | Name | Type | Description | | ------------------ | ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `callId` | `string` | ‐ | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `maxOutputLength?` | `number` | ‐ | | `output` | `object`\[] | ‐ | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `type` | `"shell_call_output"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-12) ```ts { callId: string; id?: string; operation: | { diff: string; path: string; type: "create_file"; } | { diff: string; moveTo?: string; path: string; type: "update_file"; } | { path: string; type: "delete_file"; }; providerData?: Record; status: "in_progress" | "completed"; type: "apply_patch_call"; } ``` | Name | Type | Default value | Description | | --------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `callId` | `string` | ‐ | ‐ | | `id?` | `string` | ‐ | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `operation` | \| { `diff`: `string`; `path`: `string`; `type`: `"create_file"`; } \| { `diff`: `string`; `moveTo?`: `string`; `path`: `string`; `type`: `"update_file"`; } \| { `path`: `string`; `type`: `"delete_file"`; } | `ApplyPatchOperation` | ‐ | | `providerData?` | `Record`<`string`, `any`> | ‐ | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status` | `"in_progress"` \| `"completed"` | ‐ | ‐ | | `type` | `"apply_patch_call"` | ‐ | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-13) ```ts { callId: string; id?: string; output?: string; providerData?: Record; status: "completed" | "failed"; type: "apply_patch_call_output"; } ``` | Name | Type | Description | | --------------- | --------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `callId` | `string` | ‐ | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `output?` | `string` | ‐ | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status` | `"completed"` \| `"failed"` | ‐ | | `type` | `"apply_patch_call_output"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-14) ```ts { content: object[]; id?: string; providerData?: Record; rawContent?: object[]; type: "reasoning"; } ``` | Name | Type | Description | | --------------- | ------------------------- | ------------------------------------------------------------------------------------------------------------- | | `content` | `object`\[] | The user facing representation of the reasoning. Additional information might be in the `providerData` field. | | `id?` | `string` | ‐ | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `rawContent?` | `object`\[] | The raw reasoning text from the model. | | `type` | `"reasoning"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-15) ```ts { created_by?: string; encrypted_content: string; id?: string; providerData?: Record; type: "compaction"; } ``` | Name | Type | Description | | ------------------- | ------------------------- | ------------------------------------------------------------------------------------------------------------ | | `created_by?` | `string` | Identifier for the generator of this compaction item. | | `encrypted_content` | `string` | Encrypted payload returned by the compaction endpoint. | | `id?` | `string` | Identifier for the compaction item. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `type` | `"compaction"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-16) ```ts { id?: string; providerData?: Record; type: "unknown"; } ``` | Name | Type | Description | | --------------- | ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `type` | `"unknown"` | ‐ | *** `undefined` ##### type [Section titled “type”](#type-1) ```ts type: string; ``` #### Overrides [Section titled “Overrides”](#overrides-2) ```ts RunItemBase.toJSON ``` # Span ## Extended by [Section titled “Extended by”](#extended-by) * [`NoopSpan`](/openai-agents-js/openai/agents-core/classes/noopspan/) ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | ------------------------------------------------------------------------------------------- | | `TData` *extends* [`SpanData`](/openai-agents-js/openai/agents-core/type-aliases/spandata/) | ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new Span(options, processor): Span; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ----------- | ---------------------------------------------------------------------------------------- | | `options` | [`SpanOptions`](/openai-agents-js/openai/agents-core/type-aliases/spanoptions/)<`TData`> | | `processor` | [`TracingProcessor`](/openai-agents-js/openai/agents-core/interfaces/tracingprocessor/) | #### Returns [Section titled “Returns”](#returns) `Span`<`TData`> ## Properties [Section titled “Properties”](#properties) ### type [Section titled “type”](#type) ```ts type: "trace.span"; ``` ## Accessors [Section titled “Accessors”](#accessors) ### endedAt [Section titled “endedAt”](#endedat) #### Get Signature [Section titled “Get Signature”](#get-signature) ```ts get endedAt(): string | null; ``` ##### Returns [Section titled “Returns”](#returns-1) `string` | `null` *** ### error [Section titled “error”](#error) #### Get Signature [Section titled “Get Signature”](#get-signature-1) ```ts get error(): | SpanError | null; ``` ##### Returns [Section titled “Returns”](#returns-2) \| [`SpanError`](/openai-agents-js/openai/agents-core/type-aliases/spanerror/) | `null` *** ### parentId [Section titled “parentId”](#parentid) #### Get Signature [Section titled “Get Signature”](#get-signature-2) ```ts get parentId(): string | null; ``` ##### Returns [Section titled “Returns”](#returns-3) `string` | `null` *** ### previousSpan [Section titled “previousSpan”](#previousspan) #### Get Signature [Section titled “Get Signature”](#get-signature-3) ```ts get previousSpan(): Span | undefined; ``` ##### Returns [Section titled “Returns”](#returns-4) `Span`<`any`> | `undefined` #### Set Signature [Section titled “Set Signature”](#set-signature) ```ts set previousSpan(span): void; ``` ##### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | --------- | ---------------------------- | | `span` | `Span`<`any`> \| `undefined` | ##### Returns [Section titled “Returns”](#returns-5) `void` *** ### spanData [Section titled “spanData”](#spandata) #### Get Signature [Section titled “Get Signature”](#get-signature-4) ```ts get spanData(): TData; ``` ##### Returns [Section titled “Returns”](#returns-6) `TData` *** ### spanId [Section titled “spanId”](#spanid) #### Get Signature [Section titled “Get Signature”](#get-signature-5) ```ts get spanId(): string; ``` ##### Returns [Section titled “Returns”](#returns-7) `string` *** ### startedAt [Section titled “startedAt”](#startedat) #### Get Signature [Section titled “Get Signature”](#get-signature-6) ```ts get startedAt(): string | null; ``` ##### Returns [Section titled “Returns”](#returns-8) `string` | `null` *** ### traceId [Section titled “traceId”](#traceid) #### Get Signature [Section titled “Get Signature”](#get-signature-7) ```ts get traceId(): string; ``` ##### Returns [Section titled “Returns”](#returns-9) `string` *** ### traceMetadata [Section titled “traceMetadata”](#tracemetadata) #### Get Signature [Section titled “Get Signature”](#get-signature-8) ```ts get traceMetadata(): Record | undefined; ``` ##### Returns [Section titled “Returns”](#returns-10) `Record`<`string`, `any`> | `undefined` *** ### tracingApiKey [Section titled “tracingApiKey”](#tracingapikey) #### Get Signature [Section titled “Get Signature”](#get-signature-9) ```ts get tracingApiKey(): string | undefined; ``` ##### Returns [Section titled “Returns”](#returns-11) `string` | `undefined` ## Methods [Section titled “Methods”](#methods) ### clone() [Section titled “clone()”](#clone) ```ts clone(): Span; ``` #### Returns [Section titled “Returns”](#returns-12) `Span`<`TData`> *** ### end() [Section titled “end()”](#end) ```ts end(): void; ``` #### Returns [Section titled “Returns”](#returns-13) `void` *** ### setError() [Section titled “setError()”](#seterror) ```ts setError(error): void; ``` #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | --------- | --------------------------------------------------------------------------- | | `error` | [`SpanError`](/openai-agents-js/openai/agents-core/type-aliases/spanerror/) | #### Returns [Section titled “Returns”](#returns-14) `void` *** ### start() [Section titled “start()”](#start) ```ts start(): void; ``` #### Returns [Section titled “Returns”](#returns-15) `void` *** ### toJSON() [Section titled “toJSON()”](#tojson) ```ts toJSON(): object | null; ``` #### Returns [Section titled “Returns”](#returns-16) `object` | `null` # StreamedRunResult The result of an agent run in streaming mode. ## Extends [Section titled “Extends”](#extends) * `RunResultBase`<`TContext`, `TAgent`> ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `TContext` | | `TAgent` *extends* [`Agent`](/openai-agents-js/openai/agents-core/classes/agent/)<`TContext`, [`AgentOutputType`](/openai-agents-js/openai/agents-core/type-aliases/agentoutputtype/)> | ## Implements [Section titled “Implements”](#implements) * `AsyncIterable`<[`RunStreamEvent`](/openai-agents-js/openai/agents-core/type-aliases/runstreamevent/)> ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new StreamedRunResult(result?): StreamedRunResult; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ---------------- | ---------------------------------------------------------------------------------------------------------------------------------- | | `result` | { `signal?`: `AbortSignal`; `state`: [`RunState`](/openai-agents-js/openai/agents-core/classes/runstate/)<`TContext`, `TAgent`>; } | | `result.signal?` | `AbortSignal` | | `result.state` | [`RunState`](/openai-agents-js/openai/agents-core/classes/runstate/)<`TContext`, `TAgent`> | #### Returns [Section titled “Returns”](#returns) `StreamedRunResult`<`TContext`, `TAgent`> #### Overrides [Section titled “Overrides”](#overrides) ```ts RunResultBase.constructor ``` ## Properties [Section titled “Properties”](#properties) ### currentTurn [Section titled “currentTurn”](#currentturn) ```ts currentTurn: number = 0; ``` The current turn number *** ### maxTurns [Section titled “maxTurns”](#maxturns) ```ts maxTurns: number | null | undefined; ``` The maximum number of turns that can be run *** ### state [Section titled “state”](#state) ```ts readonly state: RunState; ``` The state of the run. #### Inherited from [Section titled “Inherited from”](#inherited-from) ```ts RunResultBase.state ``` ## Accessors [Section titled “Accessors”](#accessors) ### activeAgent [Section titled “activeAgent”](#activeagent) #### Get Signature [Section titled “Get Signature”](#get-signature) ```ts get activeAgent(): TAgent | undefined; ``` The agent that should handle the next turn. This is an alias for the last agent that completed a turn. ##### Returns [Section titled “Returns”](#returns-1) `TAgent` | `undefined` #### Inherited from [Section titled “Inherited from”](#inherited-from-1) ```ts RunResultBase.activeAgent ``` *** ### agentToolInvocation [Section titled “agentToolInvocation”](#agenttoolinvocation) #### Get Signature [Section titled “Get Signature”](#get-signature-1) ```ts get agentToolInvocation(): | Readonly<{ toolArguments?: string; toolCallId?: string; toolName: string; }> | undefined; ``` Metadata about the nested `Agent.asTool()` invocation that produced this result, when applicable. ##### Returns [Section titled “Returns”](#returns-2) \| `Readonly`<{ `toolArguments?`: `string`; `toolCallId?`: `string`; `toolName`: `string`; }> | `undefined` #### Inherited from [Section titled “Inherited from”](#inherited-from-2) ```ts RunResultBase.agentToolInvocation ``` *** ### cancelled [Section titled “cancelled”](#cancelled) #### Get Signature [Section titled “Get Signature”](#get-signature-2) ```ts get cancelled(): boolean; ``` Returns true if the stream has been cancelled. ##### Returns [Section titled “Returns”](#returns-3) `boolean` *** ### completed [Section titled “completed”](#completed) #### Get Signature [Section titled “Get Signature”](#get-signature-3) ```ts get completed(): Promise; ``` Await this promise to ensure that the stream has been completed if you are not consuming the stream directly. ##### Returns [Section titled “Returns”](#returns-4) `Promise`<`void`> *** ### currentAgent [Section titled “currentAgent”](#currentagent) #### Get Signature [Section titled “Get Signature”](#get-signature-4) ```ts get currentAgent(): TAgent | undefined; ``` The current agent that is running ##### Returns [Section titled “Returns”](#returns-5) `TAgent` | `undefined` *** ### error [Section titled “error”](#error) #### Get Signature [Section titled “Get Signature”](#get-signature-5) ```ts get error(): unknown; ``` Error thrown during the run, if any. ##### Returns [Section titled “Returns”](#returns-6) `unknown` *** ### finalOutput [Section titled “finalOutput”](#finaloutput) #### Get Signature [Section titled “Get Signature”](#get-signature-6) ```ts get finalOutput(): ResolvedAgentOutput | undefined; ``` The final output of the agent. If the output type was set to anything other than `text`, this will be parsed either as JSON or using the Zod schema you provided. ##### Returns [Section titled “Returns”](#returns-7) `ResolvedAgentOutput`<`TAgent`\[`"outputType"`]> | `undefined` #### Inherited from [Section titled “Inherited from”](#inherited-from-3) ```ts RunResultBase.finalOutput ``` *** ### history [Section titled “history”](#history) #### Get Signature [Section titled “Get Signature”](#get-signature-7) ```ts get history(): AgentInputItem[]; ``` The history of the agent run. This includes the input items and the new items generated during the agent run. This can be used as inputs for the next agent run. ##### Returns [Section titled “Returns”](#returns-8) [`AgentInputItem`](/openai-agents-js/openai/agents-core/type-aliases/agentinputitem/)\[] #### Inherited from [Section titled “Inherited from”](#inherited-from-4) ```ts RunResultBase.history ``` *** ### input [Section titled “input”](#input) #### Get Signature [Section titled “Get Signature”](#get-signature-8) ```ts get input(): | string | AgentInputItem[]; ``` A copy of the original input items. ##### Returns [Section titled “Returns”](#returns-9) \| `string` | [`AgentInputItem`](/openai-agents-js/openai/agents-core/type-aliases/agentinputitem/)\[] #### Inherited from [Section titled “Inherited from”](#inherited-from-5) ```ts RunResultBase.input ``` *** ### inputGuardrailResults [Section titled “inputGuardrailResults”](#inputguardrailresults) #### Get Signature [Section titled “Get Signature”](#get-signature-9) ```ts get inputGuardrailResults(): InputGuardrailResult[]; ``` Guardrail results for the input messages. ##### Returns [Section titled “Returns”](#returns-10) [`InputGuardrailResult`](/openai-agents-js/openai/agents-core/interfaces/inputguardrailresult/)\[] #### Inherited from [Section titled “Inherited from”](#inherited-from-6) ```ts RunResultBase.inputGuardrailResults ``` *** ### interruptions [Section titled “interruptions”](#interruptions) #### Get Signature [Section titled “Get Signature”](#get-signature-10) ```ts get interruptions(): RunToolApprovalItem[]; ``` Any interruptions that occurred during the agent run for example for tool approvals. ##### Returns [Section titled “Returns”](#returns-11) [`RunToolApprovalItem`](/openai-agents-js/openai/agents-core/classes/runtoolapprovalitem/)\[] #### Inherited from [Section titled “Inherited from”](#inherited-from-7) ```ts RunResultBase.interruptions ``` *** ### lastAgent [Section titled “lastAgent”](#lastagent) #### Get Signature [Section titled “Get Signature”](#get-signature-11) ```ts get lastAgent(): TAgent | undefined; ``` The last agent that was run ##### Returns [Section titled “Returns”](#returns-12) `TAgent` | `undefined` #### Inherited from [Section titled “Inherited from”](#inherited-from-8) ```ts RunResultBase.lastAgent ``` *** ### lastResponseId [Section titled “lastResponseId”](#lastresponseid) #### Get Signature [Section titled “Get Signature”](#get-signature-12) ```ts get lastResponseId(): string | undefined; ``` The last response ID generated by the model during the agent run. ##### Returns [Section titled “Returns”](#returns-13) `string` | `undefined` #### Inherited from [Section titled “Inherited from”](#inherited-from-9) ```ts RunResultBase.lastResponseId ``` *** ### newItems [Section titled “newItems”](#newitems) #### Get Signature [Section titled “Get Signature”](#get-signature-13) ```ts get newItems(): RunItem[]; ``` The run items generated during the agent run. This associates the model data with the agents. For the model data that can be used as inputs for the next agent run, use the `output` property. ##### Returns [Section titled “Returns”](#returns-14) [`RunItem`](/openai-agents-js/openai/agents-core/type-aliases/runitem/)\[] #### Inherited from [Section titled “Inherited from”](#inherited-from-10) ```ts RunResultBase.newItems ``` *** ### output [Section titled “output”](#output) #### Get Signature [Section titled “Get Signature”](#get-signature-14) ```ts get output(): AgentOutputItem[]; ``` The new items generated during the agent run. These include things like new messages, tool calls and their outputs, etc. It does not include information about the agents and instead represents the model data. For the output including the agents, use the `newItems` property. ##### Returns [Section titled “Returns”](#returns-15) [`AgentOutputItem`](/openai-agents-js/openai/agents-core/type-aliases/agentoutputitem/)\[] #### Inherited from [Section titled “Inherited from”](#inherited-from-11) ```ts RunResultBase.output ``` *** ### outputGuardrailResults [Section titled “outputGuardrailResults”](#outputguardrailresults) #### Get Signature [Section titled “Get Signature”](#get-signature-15) ```ts get outputGuardrailResults(): OutputGuardrailResult[]; ``` Guardrail results for the final output of the agent. ##### Returns [Section titled “Returns”](#returns-16) [`OutputGuardrailResult`](/openai-agents-js/openai/agents-core/interfaces/outputguardrailresult/)<[`OutputGuardrailMetadata`](/openai-agents-js/openai/agents-core/interfaces/outputguardrailmetadata/), `"text"`>\[] #### Inherited from [Section titled “Inherited from”](#inherited-from-12) ```ts RunResultBase.outputGuardrailResults ``` *** ### rawResponses [Section titled “rawResponses”](#rawresponses) #### Get Signature [Section titled “Get Signature”](#get-signature-16) ```ts get rawResponses(): ModelResponse[]; ``` The raw LLM responses generated by the model during the agent run. ##### Returns [Section titled “Returns”](#returns-17) [`ModelResponse`](/openai-agents-js/openai/agents-core/type-aliases/modelresponse/)\[] #### Inherited from [Section titled “Inherited from”](#inherited-from-13) ```ts RunResultBase.rawResponses ``` *** ### runContext [Section titled “runContext”](#runcontext) #### Get Signature [Section titled “Get Signature”](#get-signature-17) ```ts get runContext(): RunContext; ``` The public run context for this run. ##### Returns [Section titled “Returns”](#returns-18) [`RunContext`](/openai-agents-js/openai/agents-core/classes/runcontext/)<`TContext`> #### Inherited from [Section titled “Inherited from”](#inherited-from-14) ```ts RunResultBase.runContext ``` *** ### toolInputGuardrailResults [Section titled “toolInputGuardrailResults”](#toolinputguardrailresults) #### Get Signature [Section titled “Get Signature”](#get-signature-18) ```ts get toolInputGuardrailResults(): ToolInputGuardrailResult[]; ``` Guardrail results for tool inputs. ##### Returns [Section titled “Returns”](#returns-19) [`ToolInputGuardrailResult`](/openai-agents-js/openai/agents-core/interfaces/toolinputguardrailresult/)\[] #### Inherited from [Section titled “Inherited from”](#inherited-from-15) ```ts RunResultBase.toolInputGuardrailResults ``` *** ### toolOutputGuardrailResults [Section titled “toolOutputGuardrailResults”](#tooloutputguardrailresults) #### Get Signature [Section titled “Get Signature”](#get-signature-19) ```ts get toolOutputGuardrailResults(): ToolOutputGuardrailResult[]; ``` Guardrail results for tool outputs. ##### Returns [Section titled “Returns”](#returns-20) [`ToolOutputGuardrailResult`](/openai-agents-js/openai/agents-core/interfaces/tooloutputguardrailresult/)\[] #### Inherited from [Section titled “Inherited from”](#inherited-from-16) ```ts RunResultBase.toolOutputGuardrailResults ``` ## Methods [Section titled “Methods”](#methods) ### \[asyncIterator]\() [Section titled “\[asyncIterator\]()”](#asynciterator) ```ts asyncIterator: AsyncIterator; ``` #### Returns [Section titled “Returns”](#returns-21) `AsyncIterator`<[`RunStreamEvent`](/openai-agents-js/openai/agents-core/type-aliases/runstreamevent/)> #### Implementation of [Section titled “Implementation of”](#implementation-of) ```ts AsyncIterable.[asyncIterator] ``` *** ### toStream() [Section titled “toStream()”](#tostream) ```ts toStream(): ReadableStream; ``` Returns the underlying readable stream. #### Returns [Section titled “Returns”](#returns-22) `ReadableStream`<[`RunStreamEvent`](/openai-agents-js/openai/agents-core/type-aliases/runstreamevent/)> A readable stream of the agent run. *** ### toTextStream() [Section titled “toTextStream()”](#totextstream) #### Call Signature [Section titled “Call Signature”](#call-signature) ```ts toTextStream(): ReadableStream; ``` Returns a readable stream of the final text output of the agent run. ##### Returns [Section titled “Returns”](#returns-23) `ReadableStream`<`string`> A readable stream of the final output of the agent run. ##### Remarks [Section titled “Remarks”](#remarks) Pass `{ compatibleWithNodeStreams: true }` to receive a Node.js compatible stream instance. #### Call Signature [Section titled “Call Signature”](#call-signature-1) ```ts toTextStream(options?): Readable; ``` Returns a readable stream of the final text output of the agent run. ##### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | ------------------------------------ | ---------------------------------------- | | `options?` | { `compatibleWithNodeStreams`: `true`; } | | `options.compatibleWithNodeStreams?` | `true` | ##### Returns [Section titled “Returns”](#returns-24) `Readable` A readable stream of the final output of the agent run. ##### Remarks [Section titled “Remarks”](#remarks-1) Pass `{ compatibleWithNodeStreams: true }` to receive a Node.js compatible stream instance. #### Call Signature [Section titled “Call Signature”](#call-signature-2) ```ts toTextStream(options?): ReadableStream; ``` Returns a readable stream of the final text output of the agent run. ##### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | ------------------------------------ | ------------------------------------------ | | `options?` | { `compatibleWithNodeStreams?`: `false`; } | | `options.compatibleWithNodeStreams?` | `false` | ##### Returns [Section titled “Returns”](#returns-25) `ReadableStream`<`string`> A readable stream of the final output of the agent run. ##### Remarks [Section titled “Remarks”](#remarks-2) Pass `{ compatibleWithNodeStreams: true }` to receive a Node.js compatible stream instance. # SystemError System error thrown when the library encounters an error that is not caused by the user’s misconfiguration. ## Extends [Section titled “Extends”](#extends) * [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/) ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new SystemError(message, state?): SystemError; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- | | `message` | `string` | | `state?` | [`RunState`](/openai-agents-js/openai/agents-core/classes/runstate/)<`any`, [`Agent`](/openai-agents-js/openai/agents-core/classes/agent/)<`any`, `any`>> | #### Returns [Section titled “Returns”](#returns) `SystemError` #### Inherited from [Section titled “Inherited from”](#inherited-from) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`constructor`](/openai-agents-js/openai/agents-core/classes/agentserror/#constructor) ## Properties [Section titled “Properties”](#properties) ### message [Section titled “message”](#message) ```ts message: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-1) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`message`](/openai-agents-js/openai/agents-core/classes/agentserror/#message) *** ### name [Section titled “name”](#name) ```ts name: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-2) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`name`](/openai-agents-js/openai/agents-core/classes/agentserror/#name) *** ### stack? [Section titled “stack?”](#stack) ```ts optional stack?: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-3) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`stack`](/openai-agents-js/openai/agents-core/classes/agentserror/#stack) *** ### state? [Section titled “state?”](#state) ```ts optional state?: RunState>; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-4) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`state`](/openai-agents-js/openai/agents-core/classes/agentserror/#state) *** ### stackTraceLimit [Section titled “stackTraceLimit”](#stacktracelimit) ```ts static stackTraceLimit: number; ``` The `Error.stackTraceLimit` property specifies the number of stack frames collected by a stack trace (whether generated by `new Error().stack` or `Error.captureStackTrace(obj)`). The default value is `10` but may be set to any valid JavaScript number. Changes will affect any stack trace captured *after* the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames. #### Inherited from [Section titled “Inherited from”](#inherited-from-5) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`stackTraceLimit`](/openai-agents-js/openai/agents-core/classes/agentserror/#stacktracelimit) ## Methods [Section titled “Methods”](#methods) ### captureStackTrace() [Section titled “captureStackTrace()”](#capturestacktrace) ```ts static captureStackTrace(targetObject, constructorOpt?): void; ``` Creates a `.stack` property on `targetObject`, which when accessed returns a string representing the location in the code at which `Error.captureStackTrace()` was called. ```js const myObject = {}; Error.captureStackTrace(myObject); myObject.stack; // Similar to `new Error().stack` ``` The first line of the trace will be prefixed with `${myObject.name}: ${myObject.message}`. The optional `constructorOpt` argument accepts a function. If given, all frames above `constructorOpt`, including `constructorOpt`, will be omitted from the generated stack trace. The `constructorOpt` argument is useful for hiding implementation details of error generation from the user. For instance: ```js function a() { b(); } function b() { c(); } function c() { // Create an error without stack trace to avoid calculating the stack trace twice. const { stackTraceLimit } = Error; Error.stackTraceLimit = 0; const error = new Error(); Error.stackTraceLimit = stackTraceLimit; // Capture the stack trace above function b Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace throw error; } a(); ``` #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | ----------------- | ---------- | | `targetObject` | `object` | | `constructorOpt?` | `Function` | #### Returns [Section titled “Returns”](#returns-1) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-6) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`captureStackTrace`](/openai-agents-js/openai/agents-core/classes/agentserror/#capturestacktrace) *** ### prepareStackTrace() [Section titled “prepareStackTrace()”](#preparestacktrace) ```ts static prepareStackTrace(err, stackTraces): any; ``` #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | ------------- | ------------- | | `err` | `Error` | | `stackTraces` | `CallSite`\[] | #### Returns [Section titled “Returns”](#returns-2) `any` #### See [Section titled “See”](#see) #### Inherited from [Section titled “Inherited from”](#inherited-from-7) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`prepareStackTrace`](/openai-agents-js/openai/agents-core/classes/agentserror/#preparestacktrace) # ToolCallError Error thrown when a tool call fails. ## Extends [Section titled “Extends”](#extends) * [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/) ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new ToolCallError( message, error, state?): ToolCallError; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- | | `message` | `string` | | `error` | `Error` | | `state?` | [`RunState`](/openai-agents-js/openai/agents-core/classes/runstate/)<`any`, [`Agent`](/openai-agents-js/openai/agents-core/classes/agent/)<`any`, `any`>> | #### Returns [Section titled “Returns”](#returns) `ToolCallError` #### Overrides [Section titled “Overrides”](#overrides) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`constructor`](/openai-agents-js/openai/agents-core/classes/agentserror/#constructor) ## Properties [Section titled “Properties”](#properties) ### error [Section titled “error”](#error) ```ts error: Error; ``` *** ### message [Section titled “message”](#message) ```ts message: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`message`](/openai-agents-js/openai/agents-core/classes/agentserror/#message) *** ### name [Section titled “name”](#name) ```ts name: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-1) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`name`](/openai-agents-js/openai/agents-core/classes/agentserror/#name) *** ### stack? [Section titled “stack?”](#stack) ```ts optional stack?: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-2) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`stack`](/openai-agents-js/openai/agents-core/classes/agentserror/#stack) *** ### state? [Section titled “state?”](#state) ```ts optional state?: RunState>; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-3) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`state`](/openai-agents-js/openai/agents-core/classes/agentserror/#state) *** ### stackTraceLimit [Section titled “stackTraceLimit”](#stacktracelimit) ```ts static stackTraceLimit: number; ``` The `Error.stackTraceLimit` property specifies the number of stack frames collected by a stack trace (whether generated by `new Error().stack` or `Error.captureStackTrace(obj)`). The default value is `10` but may be set to any valid JavaScript number. Changes will affect any stack trace captured *after* the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames. #### Inherited from [Section titled “Inherited from”](#inherited-from-4) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`stackTraceLimit`](/openai-agents-js/openai/agents-core/classes/agentserror/#stacktracelimit) ## Methods [Section titled “Methods”](#methods) ### captureStackTrace() [Section titled “captureStackTrace()”](#capturestacktrace) ```ts static captureStackTrace(targetObject, constructorOpt?): void; ``` Creates a `.stack` property on `targetObject`, which when accessed returns a string representing the location in the code at which `Error.captureStackTrace()` was called. ```js const myObject = {}; Error.captureStackTrace(myObject); myObject.stack; // Similar to `new Error().stack` ``` The first line of the trace will be prefixed with `${myObject.name}: ${myObject.message}`. The optional `constructorOpt` argument accepts a function. If given, all frames above `constructorOpt`, including `constructorOpt`, will be omitted from the generated stack trace. The `constructorOpt` argument is useful for hiding implementation details of error generation from the user. For instance: ```js function a() { b(); } function b() { c(); } function c() { // Create an error without stack trace to avoid calculating the stack trace twice. const { stackTraceLimit } = Error; Error.stackTraceLimit = 0; const error = new Error(); Error.stackTraceLimit = stackTraceLimit; // Capture the stack trace above function b Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace throw error; } a(); ``` #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | ----------------- | ---------- | | `targetObject` | `object` | | `constructorOpt?` | `Function` | #### Returns [Section titled “Returns”](#returns-1) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-5) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`captureStackTrace`](/openai-agents-js/openai/agents-core/classes/agentserror/#capturestacktrace) *** ### prepareStackTrace() [Section titled “prepareStackTrace()”](#preparestacktrace) ```ts static prepareStackTrace(err, stackTraces): any; ``` #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | ------------- | ------------- | | `err` | `Error` | | `stackTraces` | `CallSite`\[] | #### Returns [Section titled “Returns”](#returns-2) `any` #### See [Section titled “See”](#see) #### Inherited from [Section titled “Inherited from”](#inherited-from-6) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`prepareStackTrace`](/openai-agents-js/openai/agents-core/classes/agentserror/#preparestacktrace) # ToolInputGuardrailTripwireTriggered Error thrown when a tool input guardrail tripwire is triggered. ## Extends [Section titled “Extends”](#extends) * [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/) ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new ToolInputGuardrailTripwireTriggered( message, result, state?): ToolInputGuardrailTripwireTriggered; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ------------------------------------------------------------------------------------------------------- | | `message` | `string` | | `result` | [`ToolInputGuardrailResult`](/openai-agents-js/openai/agents-core/interfaces/toolinputguardrailresult/) | | `state?` | [`RunState`](/openai-agents-js/openai/agents-core/classes/runstate/)<`any`, `any`> | #### Returns [Section titled “Returns”](#returns) `ToolInputGuardrailTripwireTriggered` #### Overrides [Section titled “Overrides”](#overrides) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`constructor`](/openai-agents-js/openai/agents-core/classes/agentserror/#constructor) ## Properties [Section titled “Properties”](#properties) ### message [Section titled “message”](#message) ```ts message: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`message`](/openai-agents-js/openai/agents-core/classes/agentserror/#message) *** ### name [Section titled “name”](#name) ```ts name: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-1) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`name`](/openai-agents-js/openai/agents-core/classes/agentserror/#name) *** ### result [Section titled “result”](#result) ```ts result: ToolInputGuardrailResult; ``` *** ### stack? [Section titled “stack?”](#stack) ```ts optional stack?: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-2) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`stack`](/openai-agents-js/openai/agents-core/classes/agentserror/#stack) *** ### state? [Section titled “state?”](#state) ```ts optional state?: RunState>; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-3) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`state`](/openai-agents-js/openai/agents-core/classes/agentserror/#state) *** ### stackTraceLimit [Section titled “stackTraceLimit”](#stacktracelimit) ```ts static stackTraceLimit: number; ``` The `Error.stackTraceLimit` property specifies the number of stack frames collected by a stack trace (whether generated by `new Error().stack` or `Error.captureStackTrace(obj)`). The default value is `10` but may be set to any valid JavaScript number. Changes will affect any stack trace captured *after* the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames. #### Inherited from [Section titled “Inherited from”](#inherited-from-4) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`stackTraceLimit`](/openai-agents-js/openai/agents-core/classes/agentserror/#stacktracelimit) ## Methods [Section titled “Methods”](#methods) ### captureStackTrace() [Section titled “captureStackTrace()”](#capturestacktrace) ```ts static captureStackTrace(targetObject, constructorOpt?): void; ``` Creates a `.stack` property on `targetObject`, which when accessed returns a string representing the location in the code at which `Error.captureStackTrace()` was called. ```js const myObject = {}; Error.captureStackTrace(myObject); myObject.stack; // Similar to `new Error().stack` ``` The first line of the trace will be prefixed with `${myObject.name}: ${myObject.message}`. The optional `constructorOpt` argument accepts a function. If given, all frames above `constructorOpt`, including `constructorOpt`, will be omitted from the generated stack trace. The `constructorOpt` argument is useful for hiding implementation details of error generation from the user. For instance: ```js function a() { b(); } function b() { c(); } function c() { // Create an error without stack trace to avoid calculating the stack trace twice. const { stackTraceLimit } = Error; Error.stackTraceLimit = 0; const error = new Error(); Error.stackTraceLimit = stackTraceLimit; // Capture the stack trace above function b Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace throw error; } a(); ``` #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | ----------------- | ---------- | | `targetObject` | `object` | | `constructorOpt?` | `Function` | #### Returns [Section titled “Returns”](#returns-1) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-5) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`captureStackTrace`](/openai-agents-js/openai/agents-core/classes/agentserror/#capturestacktrace) *** ### prepareStackTrace() [Section titled “prepareStackTrace()”](#preparestacktrace) ```ts static prepareStackTrace(err, stackTraces): any; ``` #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | ------------- | ------------- | | `err` | `Error` | | `stackTraces` | `CallSite`\[] | #### Returns [Section titled “Returns”](#returns-2) `any` #### See [Section titled “See”](#see) #### Inherited from [Section titled “Inherited from”](#inherited-from-6) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`prepareStackTrace`](/openai-agents-js/openai/agents-core/classes/agentserror/#preparestacktrace) # ToolOutputGuardrailTripwireTriggered Error thrown when a tool output guardrail tripwire is triggered. ## Extends [Section titled “Extends”](#extends) * [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/) ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new ToolOutputGuardrailTripwireTriggered( message, result, state?): ToolOutputGuardrailTripwireTriggered; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | --------------------------------------------------------------------------------------------------------- | | `message` | `string` | | `result` | [`ToolOutputGuardrailResult`](/openai-agents-js/openai/agents-core/interfaces/tooloutputguardrailresult/) | | `state?` | [`RunState`](/openai-agents-js/openai/agents-core/classes/runstate/)<`any`, `any`> | #### Returns [Section titled “Returns”](#returns) `ToolOutputGuardrailTripwireTriggered` #### Overrides [Section titled “Overrides”](#overrides) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`constructor`](/openai-agents-js/openai/agents-core/classes/agentserror/#constructor) ## Properties [Section titled “Properties”](#properties) ### message [Section titled “message”](#message) ```ts message: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`message`](/openai-agents-js/openai/agents-core/classes/agentserror/#message) *** ### name [Section titled “name”](#name) ```ts name: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-1) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`name`](/openai-agents-js/openai/agents-core/classes/agentserror/#name) *** ### result [Section titled “result”](#result) ```ts result: ToolOutputGuardrailResult; ``` *** ### stack? [Section titled “stack?”](#stack) ```ts optional stack?: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-2) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`stack`](/openai-agents-js/openai/agents-core/classes/agentserror/#stack) *** ### state? [Section titled “state?”](#state) ```ts optional state?: RunState>; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-3) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`state`](/openai-agents-js/openai/agents-core/classes/agentserror/#state) *** ### stackTraceLimit [Section titled “stackTraceLimit”](#stacktracelimit) ```ts static stackTraceLimit: number; ``` The `Error.stackTraceLimit` property specifies the number of stack frames collected by a stack trace (whether generated by `new Error().stack` or `Error.captureStackTrace(obj)`). The default value is `10` but may be set to any valid JavaScript number. Changes will affect any stack trace captured *after* the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames. #### Inherited from [Section titled “Inherited from”](#inherited-from-4) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`stackTraceLimit`](/openai-agents-js/openai/agents-core/classes/agentserror/#stacktracelimit) ## Methods [Section titled “Methods”](#methods) ### captureStackTrace() [Section titled “captureStackTrace()”](#capturestacktrace) ```ts static captureStackTrace(targetObject, constructorOpt?): void; ``` Creates a `.stack` property on `targetObject`, which when accessed returns a string representing the location in the code at which `Error.captureStackTrace()` was called. ```js const myObject = {}; Error.captureStackTrace(myObject); myObject.stack; // Similar to `new Error().stack` ``` The first line of the trace will be prefixed with `${myObject.name}: ${myObject.message}`. The optional `constructorOpt` argument accepts a function. If given, all frames above `constructorOpt`, including `constructorOpt`, will be omitted from the generated stack trace. The `constructorOpt` argument is useful for hiding implementation details of error generation from the user. For instance: ```js function a() { b(); } function b() { c(); } function c() { // Create an error without stack trace to avoid calculating the stack trace twice. const { stackTraceLimit } = Error; Error.stackTraceLimit = 0; const error = new Error(); Error.stackTraceLimit = stackTraceLimit; // Capture the stack trace above function b Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace throw error; } a(); ``` #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | ----------------- | ---------- | | `targetObject` | `object` | | `constructorOpt?` | `Function` | #### Returns [Section titled “Returns”](#returns-1) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-5) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`captureStackTrace`](/openai-agents-js/openai/agents-core/classes/agentserror/#capturestacktrace) *** ### prepareStackTrace() [Section titled “prepareStackTrace()”](#preparestacktrace) ```ts static prepareStackTrace(err, stackTraces): any; ``` #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | ------------- | ------------- | | `err` | `Error` | | `stackTraces` | `CallSite`\[] | #### Returns [Section titled “Returns”](#returns-2) `any` #### See [Section titled “See”](#see) #### Inherited from [Section titled “Inherited from”](#inherited-from-6) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`prepareStackTrace`](/openai-agents-js/openai/agents-core/classes/agentserror/#preparestacktrace) # ToolTimeoutError Error thrown when a function tool invocation exceeds its timeout. ## Extends [Section titled “Extends”](#extends) * [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/) ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new ToolTimeoutError(__namedParameters): ToolTimeoutError; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ----------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `__namedParameters` | { `state?`: [`RunState`](/openai-agents-js/openai/agents-core/classes/runstate/)<`any`, [`Agent`](/openai-agents-js/openai/agents-core/classes/agent/)<`any`, `any`>>; `timeoutMs`: `number`; `toolName`: `string`; } | | `__namedParameters.state?` | [`RunState`](/openai-agents-js/openai/agents-core/classes/runstate/)<`any`, [`Agent`](/openai-agents-js/openai/agents-core/classes/agent/)<`any`, `any`>> | | `__namedParameters.timeoutMs` | `number` | | `__namedParameters.toolName` | `string` | #### Returns [Section titled “Returns”](#returns) `ToolTimeoutError` #### Overrides [Section titled “Overrides”](#overrides) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`constructor`](/openai-agents-js/openai/agents-core/classes/agentserror/#constructor) ## Properties [Section titled “Properties”](#properties) ### message [Section titled “message”](#message) ```ts message: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`message`](/openai-agents-js/openai/agents-core/classes/agentserror/#message) *** ### name [Section titled “name”](#name) ```ts name: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-1) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`name`](/openai-agents-js/openai/agents-core/classes/agentserror/#name) *** ### stack? [Section titled “stack?”](#stack) ```ts optional stack?: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-2) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`stack`](/openai-agents-js/openai/agents-core/classes/agentserror/#stack) *** ### state? [Section titled “state?”](#state) ```ts optional state?: RunState>; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-3) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`state`](/openai-agents-js/openai/agents-core/classes/agentserror/#state) *** ### timeoutMs [Section titled “timeoutMs”](#timeoutms) ```ts timeoutMs: number; ``` *** ### toolName [Section titled “toolName”](#toolname) ```ts toolName: string; ``` *** ### stackTraceLimit [Section titled “stackTraceLimit”](#stacktracelimit) ```ts static stackTraceLimit: number; ``` The `Error.stackTraceLimit` property specifies the number of stack frames collected by a stack trace (whether generated by `new Error().stack` or `Error.captureStackTrace(obj)`). The default value is `10` but may be set to any valid JavaScript number. Changes will affect any stack trace captured *after* the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames. #### Inherited from [Section titled “Inherited from”](#inherited-from-4) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`stackTraceLimit`](/openai-agents-js/openai/agents-core/classes/agentserror/#stacktracelimit) ## Methods [Section titled “Methods”](#methods) ### captureStackTrace() [Section titled “captureStackTrace()”](#capturestacktrace) ```ts static captureStackTrace(targetObject, constructorOpt?): void; ``` Creates a `.stack` property on `targetObject`, which when accessed returns a string representing the location in the code at which `Error.captureStackTrace()` was called. ```js const myObject = {}; Error.captureStackTrace(myObject); myObject.stack; // Similar to `new Error().stack` ``` The first line of the trace will be prefixed with `${myObject.name}: ${myObject.message}`. The optional `constructorOpt` argument accepts a function. If given, all frames above `constructorOpt`, including `constructorOpt`, will be omitted from the generated stack trace. The `constructorOpt` argument is useful for hiding implementation details of error generation from the user. For instance: ```js function a() { b(); } function b() { c(); } function c() { // Create an error without stack trace to avoid calculating the stack trace twice. const { stackTraceLimit } = Error; Error.stackTraceLimit = 0; const error = new Error(); Error.stackTraceLimit = stackTraceLimit; // Capture the stack trace above function b Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace throw error; } a(); ``` #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | ----------------- | ---------- | | `targetObject` | `object` | | `constructorOpt?` | `Function` | #### Returns [Section titled “Returns”](#returns-1) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-5) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`captureStackTrace`](/openai-agents-js/openai/agents-core/classes/agentserror/#capturestacktrace) *** ### prepareStackTrace() [Section titled “prepareStackTrace()”](#preparestacktrace) ```ts static prepareStackTrace(err, stackTraces): any; ``` #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | ------------- | ------------- | | `err` | `Error` | | `stackTraces` | `CallSite`\[] | #### Returns [Section titled “Returns”](#returns-2) `any` #### See [Section titled “See”](#see) #### Inherited from [Section titled “Inherited from”](#inherited-from-6) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`prepareStackTrace`](/openai-agents-js/openai/agents-core/classes/agentserror/#preparestacktrace) # Trace ## Extended by [Section titled “Extended by”](#extended-by) * [`NoopTrace`](/openai-agents-js/openai/agents-core/classes/nooptrace/) ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new Trace(options, processor?): Trace; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ------------ | --------------------------------------------------------------------------------------- | | `options` | `TraceOptions` | | `processor?` | [`TracingProcessor`](/openai-agents-js/openai/agents-core/interfaces/tracingprocessor/) | #### Returns [Section titled “Returns”](#returns) `Trace` ## Properties [Section titled “Properties”](#properties) ### groupId [Section titled “groupId”](#groupid) ```ts groupId: string | null = null; ``` *** ### metadata? [Section titled “metadata?”](#metadata) ```ts optional metadata?: Record; ``` *** ### name [Section titled “name”](#name) ```ts name: string; ``` *** ### traceId [Section titled “traceId”](#traceid) ```ts traceId: string; ``` *** ### tracingApiKey? [Section titled “tracingApiKey?”](#tracingapikey) ```ts optional tracingApiKey?: string; ``` *** ### type [Section titled “type”](#type) ```ts type: "trace"; ``` ## Methods [Section titled “Methods”](#methods) ### clone() [Section titled “clone()”](#clone) ```ts clone(): Trace; ``` #### Returns [Section titled “Returns”](#returns-1) `Trace` *** ### end() [Section titled “end()”](#end) ```ts end(): Promise; ``` #### Returns [Section titled “Returns”](#returns-2) `Promise`<`void`> *** ### start() [Section titled “start()”](#start) ```ts start(): Promise; ``` #### Returns [Section titled “Returns”](#returns-3) `Promise`<`void`> *** ### toJSON() [Section titled “toJSON()”](#tojson) ```ts toJSON(options?): object | null; ``` Serializes the trace for export or persistence. Set `includeTracingApiKey` to true only when you intentionally need to persist the exporter credentials (for example, when handing off a run to another process that cannot access the original environment). Defaults to false to avoid leaking secrets. #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | ------------------------------- | --------------------------------------- | | `options?` | { `includeTracingApiKey?`: `boolean`; } | | `options.includeTracingApiKey?` | `boolean` | #### Returns [Section titled “Returns”](#returns-4) `object` | `null` # TraceProvider ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new TraceProvider(): TraceProvider; ``` #### Returns [Section titled “Returns”](#returns) `TraceProvider` ## Methods [Section titled “Methods”](#methods) ### createSpan() [Section titled “createSpan()”](#createspan) ```ts createSpan(spanOptions, parent?): Span; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | ----------------------------------------------------------------------------------------------- | | `TSpanData` *extends* [`SpanData`](/openai-agents-js/openai/agents-core/type-aliases/spandata/) | #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ------------- | ---------------------------------------------------------------------------------------------------------------------------------------- | | `spanOptions` | `CreateSpanOptions`<`TSpanData`> | | `parent?` | \| [`Span`](/openai-agents-js/openai/agents-core/classes/span/)<`any`> \| [`Trace`](/openai-agents-js/openai/agents-core/classes/trace/) | #### Returns [Section titled “Returns”](#returns-1) [`Span`](/openai-agents-js/openai/agents-core/classes/span/)<`TSpanData`> *** ### createTrace() [Section titled “createTrace()”](#createtrace) ```ts createTrace(traceOptions): Trace; ``` #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | -------------- | -------------- | | `traceOptions` | `TraceOptions` | #### Returns [Section titled “Returns”](#returns-2) [`Trace`](/openai-agents-js/openai/agents-core/classes/trace/) *** ### forceFlush() [Section titled “forceFlush()”](#forceflush) ```ts forceFlush(): Promise; ``` #### Returns [Section titled “Returns”](#returns-3) `Promise`<`void`> *** ### getCurrentSpan() [Section titled “getCurrentSpan()”](#getcurrentspan) ```ts getCurrentSpan(): | Span | null; ``` #### Returns [Section titled “Returns”](#returns-4) \| [`Span`](/openai-agents-js/openai/agents-core/classes/span/)<`any`> | `null` *** ### getCurrentTrace() [Section titled “getCurrentTrace()”](#getcurrenttrace) ```ts getCurrentTrace(): Trace | null; ``` Get the current trace. #### Returns [Section titled “Returns”](#returns-5) [`Trace`](/openai-agents-js/openai/agents-core/classes/trace/) | `null` The current trace. *** ### registerProcessor() [Section titled “registerProcessor()”](#registerprocessor) ```ts registerProcessor(processor): void; ``` Add a processor to the list of processors. Each processor will receive all traces/spans. #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | Description | | ----------- | --------------------------------------------------------------------------------------- | --------------------- | | `processor` | [`TracingProcessor`](/openai-agents-js/openai/agents-core/interfaces/tracingprocessor/) | The processor to add. | #### Returns [Section titled “Returns”](#returns-6) `void` *** ### setDisabled() [Section titled “setDisabled()”](#setdisabled) ```ts setDisabled(disabled): void; ``` #### Parameters [Section titled “Parameters”](#parameters-3) | Parameter | Type | | ---------- | --------- | | `disabled` | `boolean` | #### Returns [Section titled “Returns”](#returns-7) `void` *** ### setProcessors() [Section titled “setProcessors()”](#setprocessors) ```ts setProcessors(processors): void; ``` Set the list of processors. This will replace any existing processors. #### Parameters [Section titled “Parameters”](#parameters-4) | Parameter | Type | Description | | ------------ | ------------------------------------------------------------------------------------------ | ------------------------------ | | `processors` | [`TracingProcessor`](/openai-agents-js/openai/agents-core/interfaces/tracingprocessor/)\[] | The list of processors to set. | #### Returns [Section titled “Returns”](#returns-8) `void` *** ### shutdown() [Section titled “shutdown()”](#shutdown) ```ts shutdown(timeout?): Promise; ``` #### Parameters [Section titled “Parameters”](#parameters-5) | Parameter | Type | | ---------- | -------- | | `timeout?` | `number` | #### Returns [Section titled “Returns”](#returns-9) `Promise`<`void`> *** ### startExportLoop() [Section titled “startExportLoop()”](#startexportloop) ```ts startExportLoop(): void; ``` #### Returns [Section titled “Returns”](#returns-10) `void` # Usage Tracks token usage and request counts for an agent run. ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new Usage(input?): Usage; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ------------ | | `input?` | `UsageInput` | #### Returns [Section titled “Returns”](#returns) `Usage` ## Properties [Section titled “Properties”](#properties) ### inputTokens [Section titled “inputTokens”](#inputtokens) ```ts inputTokens: number; ``` The number of input tokens used across all requests. *** ### inputTokensDetails [Section titled “inputTokensDetails”](#inputtokensdetails) ```ts inputTokensDetails: Record[] = []; ``` Details about the input tokens used across all requests. *** ### outputTokens [Section titled “outputTokens”](#outputtokens) ```ts outputTokens: number; ``` The number of output tokens used across all requests. *** ### outputTokensDetails [Section titled “outputTokensDetails”](#outputtokensdetails) ```ts outputTokensDetails: Record[] = []; ``` Details about the output tokens used across all requests. *** ### requests [Section titled “requests”](#requests) ```ts requests: number; ``` The number of requests made to the LLM API. *** ### requestUsageEntries [Section titled “requestUsageEntries”](#requestusageentries) ```ts requestUsageEntries: | RequestUsage[] | undefined; ``` List of per-request usage entries for detailed cost calculations. *** ### totalTokens [Section titled “totalTokens”](#totaltokens) ```ts totalTokens: number; ``` The total number of tokens sent and received, across all requests. ## Methods [Section titled “Methods”](#methods) ### add() [Section titled “add()”](#add) ```ts add(newUsage): void; ``` #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | ---------- | ------- | | `newUsage` | `Usage` | #### Returns [Section titled “Returns”](#returns-1) `void` # UserError Error thrown when the error is caused by the library user’s misconfiguration. ## Extends [Section titled “Extends”](#extends) * [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/) ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new UserError(message, state?): UserError; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- | | `message` | `string` | | `state?` | [`RunState`](/openai-agents-js/openai/agents-core/classes/runstate/)<`any`, [`Agent`](/openai-agents-js/openai/agents-core/classes/agent/)<`any`, `any`>> | #### Returns [Section titled “Returns”](#returns) `UserError` #### Inherited from [Section titled “Inherited from”](#inherited-from) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`constructor`](/openai-agents-js/openai/agents-core/classes/agentserror/#constructor) ## Properties [Section titled “Properties”](#properties) ### message [Section titled “message”](#message) ```ts message: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-1) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`message`](/openai-agents-js/openai/agents-core/classes/agentserror/#message) *** ### name [Section titled “name”](#name) ```ts name: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-2) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`name`](/openai-agents-js/openai/agents-core/classes/agentserror/#name) *** ### stack? [Section titled “stack?”](#stack) ```ts optional stack?: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-3) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`stack`](/openai-agents-js/openai/agents-core/classes/agentserror/#stack) *** ### state? [Section titled “state?”](#state) ```ts optional state?: RunState>; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-4) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`state`](/openai-agents-js/openai/agents-core/classes/agentserror/#state) *** ### stackTraceLimit [Section titled “stackTraceLimit”](#stacktracelimit) ```ts static stackTraceLimit: number; ``` The `Error.stackTraceLimit` property specifies the number of stack frames collected by a stack trace (whether generated by `new Error().stack` or `Error.captureStackTrace(obj)`). The default value is `10` but may be set to any valid JavaScript number. Changes will affect any stack trace captured *after* the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames. #### Inherited from [Section titled “Inherited from”](#inherited-from-5) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`stackTraceLimit`](/openai-agents-js/openai/agents-core/classes/agentserror/#stacktracelimit) ## Methods [Section titled “Methods”](#methods) ### captureStackTrace() [Section titled “captureStackTrace()”](#capturestacktrace) ```ts static captureStackTrace(targetObject, constructorOpt?): void; ``` Creates a `.stack` property on `targetObject`, which when accessed returns a string representing the location in the code at which `Error.captureStackTrace()` was called. ```js const myObject = {}; Error.captureStackTrace(myObject); myObject.stack; // Similar to `new Error().stack` ``` The first line of the trace will be prefixed with `${myObject.name}: ${myObject.message}`. The optional `constructorOpt` argument accepts a function. If given, all frames above `constructorOpt`, including `constructorOpt`, will be omitted from the generated stack trace. The `constructorOpt` argument is useful for hiding implementation details of error generation from the user. For instance: ```js function a() { b(); } function b() { c(); } function c() { // Create an error without stack trace to avoid calculating the stack trace twice. const { stackTraceLimit } = Error; Error.stackTraceLimit = 0; const error = new Error(); Error.stackTraceLimit = stackTraceLimit; // Capture the stack trace above function b Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace throw error; } a(); ``` #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | ----------------- | ---------- | | `targetObject` | `object` | | `constructorOpt?` | `Function` | #### Returns [Section titled “Returns”](#returns-1) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-6) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`captureStackTrace`](/openai-agents-js/openai/agents-core/classes/agentserror/#capturestacktrace) *** ### prepareStackTrace() [Section titled “prepareStackTrace()”](#preparestacktrace) ```ts static prepareStackTrace(err, stackTraces): any; ``` #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | ------------- | ------------- | | `err` | `Error` | | `stackTraces` | `CallSite`\[] | #### Returns [Section titled “Returns”](#returns-2) `any` #### See [Section titled “See”](#see) #### Inherited from [Section titled “Inherited from”](#inherited-from-7) [`AgentsError`](/openai-agents-js/openai/agents-core/classes/agentserror/).[`prepareStackTrace`](/openai-agents-js/openai/agents-core/classes/agentserror/#preparestacktrace) # addTraceProcessor ```ts function addTraceProcessor(processor): void; ``` Add a processor to the list of processors. Each processor will receive all traces/spans. ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | ----------- | --------------------------------------------------------------------------------------- | --------------------- | | `processor` | [`TracingProcessor`](/openai-agents-js/openai/agents-core/interfaces/tracingprocessor/) | The processor to add. | ## Returns [Section titled “Returns”](#returns) `void` # applyDiff ```ts function applyDiff( input, diff, mode?): string; ``` Applies a headerless V4A diff to the provided file content. * mode “default”: patch an existing file using V4A sections (”@@” + +/-/space lines). * mode “create”: create-file syntax that requires every line to start with ”+”. The function preserves trailing newlines from the original file and throws when the diff cannot be applied cleanly. ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Default value | | --------- | ------------------------- | ------------- | | `input` | `string` | `undefined` | | `diff` | `string` | `undefined` | | `mode` | `"default"` \| `"create"` | `'default'` | ## Returns [Section titled “Returns”](#returns) `string` # applyPatchTool ```ts function applyPatchTool(options): ApplyPatchTool; ``` ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `options` | `Partial`<`Omit`<[`ApplyPatchTool`](/openai-agents-js/openai/agents-core/type-aliases/applypatchtool/), `"type"` \| `"needsApproval"` \| `"editor"`>> & `object` | ## Returns [Section titled “Returns”](#returns) [`ApplyPatchTool`](/openai-agents-js/openai/agents-core/type-aliases/applypatchtool/) # applySessionHistoryMutations ```ts function applySessionHistoryMutations(items, mutations): AgentInputItem[]; ``` Applies persisted-history mutations and returns a new canonical item list. ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ----------- | ---------------------------------------------------------------------------------------- | | `items` | [`AgentInputItem`](/openai-agents-js/openai/agents-core/type-aliases/agentinputitem/)\[] | | `mutations` | `SessionHistoryReplaceFunctionCallMutation`\[] | ## Returns [Section titled “Returns”](#returns) [`AgentInputItem`](/openai-agents-js/openai/agents-core/type-aliases/agentinputitem/)\[] # assistant ```ts function assistant(content, options?): object; ``` Creates an assistant message entry for example for multi-shot prompting ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | ---------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------- | | `content` | \| `string` \| ( \| { `providerData?`: `Record`<`string`, `any`>; `refusal`: `string`; `type`: `"refusal"`; } \| { `providerData?`: `Record`<`string`, `any`>; `text`: `string`; `type`: `"output_text"`; } \| { `audio`: \| `string` \| { `id`: `string`; }; `format?`: `string` \| `null`; `providerData?`: `Record`<`string`, `any`>; `transcript?`: `string` \| `null`; `type`: `"audio"`; } \| { `image`: `string`; `providerData?`: `Record`<`string`, `any`>; `type`: `"image"`; })\[] | The assistant response. | | `options?` | `Record`<`string`, `any`> | Any additional options that will be directly passed to the model. | ## Returns [Section titled “Returns”](#returns) A message entry. ### content [Section titled “content”](#content) ```ts content: ( | { providerData?: Record; refusal: string; type: "refusal"; } | { providerData?: Record; text: string; type: "output_text"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; } | { image: string; providerData?: Record; type: "image"; })[]; ``` The content of the message. ### id? [Section titled “id?”](#id) ```ts optional id?: string; ``` An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. ### role [Section titled “role”](#role) ```ts role: "assistant"; ``` Representing a message from the assistant (i.e. the model) ### status [Section titled “status”](#status) ```ts status: "in_progress" | "completed" | "incomplete"; ``` The status of the message. ### type? [Section titled “type?”](#type) ```ts optional type?: "message"; ``` Any item without a type is treated as a message # attachClientToolSearchExecutor ```ts function attachClientToolSearchExecutor(tool, executor): HostedTool; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | ------------ | | `Context` | `unknown` | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ---------- | -------------------------------------------------------------------------------------------------------------------- | | `tool` | [`HostedTool`](/openai-agents-js/openai/agents-core/type-aliases/hostedtool/) | | `executor` | [`ClientToolSearchExecutor`](/openai-agents-js/openai/agents-core/type-aliases/clienttoolsearchexecutor/)<`Context`> | ## Returns [Section titled “Returns”](#returns) [`HostedTool`](/openai-agents-js/openai/agents-core/type-aliases/hostedtool/) # computerTool ```ts function computerTool(options): ComputerTool; ``` Exposes a computer to the agent as a tool to be called. ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | ------------------------------ | ------------ | | `Context` | `unknown` | | `TComputer` *extends* `object` | `object` | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------- | | `options` | { `computer`: `ComputerConfig`<`Context`, `TComputer`>; `name?`: `string`; `needsApproval?`: `boolean` \| `ComputerApprovalFunction`; `onSafetyCheck?`: [`ComputerOnSafetyCheckFunction`](/openai-agents-js/openai/agents-core/type-aliases/computeronsafetycheckfunction/); } | Additional configuration for the computer tool like specifying the location of your agent | | `options.computer` | `ComputerConfig`<`Context`, `TComputer`> | ‐ | | `options.name?` | `string` | ‐ | | `options.needsApproval?` | `boolean` \| `ComputerApprovalFunction` | ‐ | | `options.onSafetyCheck?` | [`ComputerOnSafetyCheckFunction`](/openai-agents-js/openai/agents-core/type-aliases/computeronsafetycheckfunction/) | ‐ | ## Returns [Section titled “Returns”](#returns) [`ComputerTool`](/openai-agents-js/openai/agents-core/type-aliases/computertool/)<`Context`, `TComputer`> a computer tool definition # connectMcpServers ```ts function connectMcpServers(servers, options?): Promise; ``` Connect to multiple MCP servers and return a managed MCPServers instance. ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ---------- | ------------------------------------------------------------------------------------------- | | `servers` | [`MCPServer`](/openai-agents-js/openai/agents-core/interfaces/mcpserver/)\[] | | `options?` | [`MCPServersOptions`](/openai-agents-js/openai/agents-core/type-aliases/mcpserversoptions/) | ## Returns [Section titled “Returns”](#returns) `Promise`<[`MCPServers`](/openai-agents-js/openai/agents-core/classes/mcpservers/)> # createAgentSpan ```ts function createAgentSpan(options?, parent?): Span; ``` Create a new agent span. The span will not be started automatically, you should either use `withAgentSpan()` or call `span.start()` and `span.end()` manually. ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | ---------- | ---------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------- | | `options?` | `DeepPartial`<`CreateSpanOptions`<[`AgentSpanData`](/openai-agents-js/openai/agents-core/type-aliases/agentspandata/)>> | Optional span creation options, including span data and identifiers. | | `parent?` | \| [`Span`](/openai-agents-js/openai/agents-core/classes/span/)<`any`> \| [`Trace`](/openai-agents-js/openai/agents-core/classes/trace/) | The parent span or trace. If not provided, the current trace/span will be used automatically. | ## Returns [Section titled “Returns”](#returns) [`Span`](/openai-agents-js/openai/agents-core/classes/span/)<[`AgentSpanData`](/openai-agents-js/openai/agents-core/type-aliases/agentspandata/)> The newly created agent span. # createCustomSpan ```ts function createCustomSpan(options, parent?): Span; ``` Create a new custom span. The span will not be started automatically, you should either use `withCustomSpan()` or call `span.start()` and `span.end()` manually. ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ---------------------------------------------------------------------------------------------------------------------------------------- | | `options` | `DeepPartial`<`CreateSpanOptions`<[`CustomSpanData`](/openai-agents-js/openai/agents-core/type-aliases/customspandata/)>> & `object` | | `parent?` | \| [`Span`](/openai-agents-js/openai/agents-core/classes/span/)<`any`> \| [`Trace`](/openai-agents-js/openai/agents-core/classes/trace/) | ## Returns [Section titled “Returns”](#returns) [`Span`](/openai-agents-js/openai/agents-core/classes/span/)<[`CustomSpanData`](/openai-agents-js/openai/agents-core/type-aliases/customspandata/)> # createFunctionSpan ```ts function createFunctionSpan(options, parent?): Span; ``` Create a new function span. The span will not be started automatically, you should either use `withFunctionSpan()` or call `span.start()` and `span.end()` manually. ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | --------- | ---------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------- | | `options` | `DeepPartial`<`CreateSpanOptions`<[`FunctionSpanData`](/openai-agents-js/openai/agents-core/type-aliases/functionspandata/)>> & `object` | Optional span creation options, including span data and identifiers. | | `parent?` | \| [`Span`](/openai-agents-js/openai/agents-core/classes/span/)<`any`> \| [`Trace`](/openai-agents-js/openai/agents-core/classes/trace/) | The parent span or trace. If not provided, the current trace/span will be used automatically. | ## Returns [Section titled “Returns”](#returns) [`Span`](/openai-agents-js/openai/agents-core/classes/span/)<[`FunctionSpanData`](/openai-agents-js/openai/agents-core/type-aliases/functionspandata/)> The newly created function span. # createGenerationSpan ```ts function createGenerationSpan(options?, parent?): Span; ``` Create a new generation span. The span will not be started automatically, you should either use `withGenerationSpan()` or call `span.start()` and `span.end()` manually. This span captures the details of a model generation, including input/output message sequences, model information, and usage data. If you only need to capture a model response identifier, consider using `createResponseSpan()` instead. agents-core keeps generation usage payloads as provided. Backend-specific schema constraints are enforced by each exporter. For example, the OpenAI tracing exporter in `@openai/agents-openai` keeps top-level usage to `input_tokens` and `output_tokens` for OpenAI traces ingest, and maps additional usage fields under `usage.details`. Third-party exporters can apply their own mapping. ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ---------- | ---------------------------------------------------------------------------------------------------------------------------------------- | | `options?` | `DeepPartial`<`CreateSpanOptions`<[`GenerationSpanData`](/openai-agents-js/openai/agents-core/type-aliases/generationspandata/)>> | | `parent?` | \| [`Span`](/openai-agents-js/openai/agents-core/classes/span/)<`any`> \| [`Trace`](/openai-agents-js/openai/agents-core/classes/trace/) | ## Returns [Section titled “Returns”](#returns) [`Span`](/openai-agents-js/openai/agents-core/classes/span/)<[`GenerationSpanData`](/openai-agents-js/openai/agents-core/type-aliases/generationspandata/)> # createGuardrailSpan ```ts function createGuardrailSpan(options, parent?): Span; ``` Create a new guardrail span. The span will not be started automatically, you should either use `withGuardrailSpan()` or call `span.start()` and `span.end()` manually. ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ------------------------------------------------------------------------------------------------------------------------------------------ | | `options` | `DeepPartial`<`CreateSpanOptions`<[`GuardrailSpanData`](/openai-agents-js/openai/agents-core/type-aliases/guardrailspandata/)>> & `object` | | `parent?` | \| [`Span`](/openai-agents-js/openai/agents-core/classes/span/)<`any`> \| [`Trace`](/openai-agents-js/openai/agents-core/classes/trace/) | ## Returns [Section titled “Returns”](#returns) [`Span`](/openai-agents-js/openai/agents-core/classes/span/)<[`GuardrailSpanData`](/openai-agents-js/openai/agents-core/type-aliases/guardrailspandata/)> # createHandoffSpan ```ts function createHandoffSpan(options?, parent?): Span; ``` Create a new handoff span. The span will not be started automatically, you should either use `withHandoffSpan()` or call `span.start()` and `span.end()` manually. ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | ---------- | ---------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------- | | `options?` | `DeepPartial`<`CreateSpanOptions`<[`HandoffSpanData`](/openai-agents-js/openai/agents-core/type-aliases/handoffspandata/)>> | Optional span creation options, including span data and identifiers. | | `parent?` | \| [`Span`](/openai-agents-js/openai/agents-core/classes/span/)<`any`> \| [`Trace`](/openai-agents-js/openai/agents-core/classes/trace/) | The parent span or trace. If not provided, the current trace/span will be used automatically. | ## Returns [Section titled “Returns”](#returns) [`Span`](/openai-agents-js/openai/agents-core/classes/span/)<[`HandoffSpanData`](/openai-agents-js/openai/agents-core/type-aliases/handoffspandata/)> The newly created handoff span. # createMCPListToolsSpan ```ts function createMCPListToolsSpan(options?, parent?): Span; ``` Create a new MCP list tools span. The span will not be started automatically. ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ---------- | ---------------------------------------------------------------------------------------------------------------------------------------- | | `options?` | `DeepPartial`<`CreateSpanOptions`<[`MCPListToolsSpanData`](/openai-agents-js/openai/agents-core/type-aliases/mcplisttoolsspandata/)>> | | `parent?` | \| [`Span`](/openai-agents-js/openai/agents-core/classes/span/)<`any`> \| [`Trace`](/openai-agents-js/openai/agents-core/classes/trace/) | ## Returns [Section titled “Returns”](#returns) [`Span`](/openai-agents-js/openai/agents-core/classes/span/)<[`MCPListToolsSpanData`](/openai-agents-js/openai/agents-core/type-aliases/mcplisttoolsspandata/)> # createMCPToolStaticFilter ```ts function createMCPToolStaticFilter(options?): | MCPToolFilterStatic | undefined; ``` Convenience helper to create a static tool filter. ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ------------------ | ----------------------------------------------------- | | `options?` | { `allowed?`: `string`\[]; `blocked?`: `string`\[]; } | | `options.allowed?` | `string`\[] | | `options.blocked?` | `string`\[] | ## Returns [Section titled “Returns”](#returns) \| [`MCPToolFilterStatic`](/openai-agents-js/openai/agents-core/interfaces/mcptoolfilterstatic/) | `undefined` # createResponseSpan ```ts function createResponseSpan(options?, parent?): Span; ``` Create a new response span. The span will not be started automatically, you should either use `withResponseSpan()` or call `span.start()` and `span.end()` manually. This span captures the details of a model response, primarily the response identifier. If you need to capture detailed generation information such as input/output messages, model configuration, or usage data, use `createGenerationSpan()` instead. ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | ---------- | ---------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------- | | `options?` | `DeepPartial`<`CreateSpanOptions`<[`ResponseSpanData`](/openai-agents-js/openai/agents-core/type-aliases/responsespandata/)>> | Optional span creation options, including span data and identifiers. | | `parent?` | \| [`Span`](/openai-agents-js/openai/agents-core/classes/span/)<`any`> \| [`Trace`](/openai-agents-js/openai/agents-core/classes/trace/) | The parent span or trace. If not provided, the current trace/span will be used automatically. | ## Returns [Section titled “Returns”](#returns) [`Span`](/openai-agents-js/openai/agents-core/classes/span/)<[`ResponseSpanData`](/openai-agents-js/openai/agents-core/type-aliases/responsespandata/)> The newly created response span. # createSpeechGroupSpan ```ts function createSpeechGroupSpan(options?, parent?): Span; ``` Create a new speech group span. The span will not be started automatically. ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ---------- | ---------------------------------------------------------------------------------------------------------------------------------------- | | `options?` | `DeepPartial`<`CreateSpanOptions`<[`SpeechGroupSpanData`](/openai-agents-js/openai/agents-core/type-aliases/speechgroupspandata/)>> | | `parent?` | \| [`Span`](/openai-agents-js/openai/agents-core/classes/span/)<`any`> \| [`Trace`](/openai-agents-js/openai/agents-core/classes/trace/) | ## Returns [Section titled “Returns”](#returns) [`Span`](/openai-agents-js/openai/agents-core/classes/span/)<[`SpeechGroupSpanData`](/openai-agents-js/openai/agents-core/type-aliases/speechgroupspandata/)> # createSpeechSpan ```ts function createSpeechSpan(options, parent?): Span; ``` Create a new speech span. The span will not be started automatically. ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ---------------------------------------------------------------------------------------------------------------------------------------- | | `options` | `DeepPartial`<`CreateSpanOptions`<[`SpeechSpanData`](/openai-agents-js/openai/agents-core/type-aliases/speechspandata/)>> & `object` | | `parent?` | \| [`Span`](/openai-agents-js/openai/agents-core/classes/span/)<`any`> \| [`Trace`](/openai-agents-js/openai/agents-core/classes/trace/) | ## Returns [Section titled “Returns”](#returns) [`Span`](/openai-agents-js/openai/agents-core/classes/span/)<[`SpeechSpanData`](/openai-agents-js/openai/agents-core/type-aliases/speechspandata/)> # createTranscriptionSpan ```ts function createTranscriptionSpan(options, parent?): Span; ``` Create a new transcription span. The span will not be started automatically. ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | -------------------------------------------------------------------------------------------------------------------------------------------------- | | `options` | `DeepPartial`<`CreateSpanOptions`<[`TranscriptionSpanData`](/openai-agents-js/openai/agents-core/type-aliases/transcriptionspandata/)>> & `object` | | `parent?` | \| [`Span`](/openai-agents-js/openai/agents-core/classes/span/)<`any`> \| [`Trace`](/openai-agents-js/openai/agents-core/classes/trace/) | ## Returns [Section titled “Returns”](#returns) [`Span`](/openai-agents-js/openai/agents-core/classes/span/)<[`TranscriptionSpanData`](/openai-agents-js/openai/agents-core/type-aliases/transcriptionspandata/)> # defineOutputGuardrail ```ts function defineOutputGuardrail(__namedParameters): OutputGuardrailDefinition; ``` Creates an output guardrail definition. ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | ----------------------------------------------------------------------------------------------------------- | ------------ | | `TOutput` *extends* [`AgentOutputType`](/openai-agents-js/openai/agents-core/type-aliases/agentoutputtype/) | `"text"` | | `TContext` | `unknown` | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ------------------- | -------------------------------------------------- | | `__namedParameters` | `DefineOutputGuardrailArgs`<`TOutput`, `TContext`> | ## Returns [Section titled “Returns”](#returns) [`OutputGuardrailDefinition`](/openai-agents-js/openai/agents-core/interfaces/outputguardraildefinition/)<[`OutputGuardrailMetadata`](/openai-agents-js/openai/agents-core/interfaces/outputguardrailmetadata/), `TOutput`, `TContext`> # defineToolInputGuardrail ```ts function defineToolInputGuardrail(args): ToolInputGuardrailDefinition; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | ------------ | | `TContext` | `unknown` | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- | | `args` | { `name`: `string`; `run`: [`ToolInputGuardrailFunction`](/openai-agents-js/openai/agents-core/type-aliases/toolinputguardrailfunction/)<`TContext`>; } | | `args.name` | `string` | | `args.run` | [`ToolInputGuardrailFunction`](/openai-agents-js/openai/agents-core/type-aliases/toolinputguardrailfunction/)<`TContext`> | ## Returns [Section titled “Returns”](#returns) [`ToolInputGuardrailDefinition`](/openai-agents-js/openai/agents-core/interfaces/toolinputguardraildefinition/)<`TContext`> # defineToolOutputGuardrail ```ts function defineToolOutputGuardrail(args): ToolOutputGuardrailDefinition; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | ------------ | | `TContext` | `unknown` | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ----------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- | | `args` | { `name`: `string`; `run`: [`ToolOutputGuardrailFunction`](/openai-agents-js/openai/agents-core/type-aliases/tooloutputguardrailfunction/)<`TContext`>; } | | `args.name` | `string` | | `args.run` | [`ToolOutputGuardrailFunction`](/openai-agents-js/openai/agents-core/type-aliases/tooloutputguardrailfunction/)<`TContext`> | ## Returns [Section titled “Returns”](#returns) [`ToolOutputGuardrailDefinition`](/openai-agents-js/openai/agents-core/interfaces/tooloutputguardraildefinition/)<`TContext`> # extractAllTextOutput ```ts function extractAllTextOutput(items): string; ``` Extract all text output from a list of run items by concatenating the content of all message output items. ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | --------- | -------------------------------------------------------------------------- | ------------------------------------------- | | `items` | [`RunItem`](/openai-agents-js/openai/agents-core/type-aliases/runitem/)\[] | The list of run items to extract text from. | ## Returns [Section titled “Returns”](#returns) `string` A string of all the text output from the run items. # generateGroupId ```ts function generateGroupId(): string; ``` Generate a group ID by creating a random UUID v4 and removing the dashes. This is the equivalent of `uuid4().hex` in Python and prefixing it with `group_`. ## Returns [Section titled “Returns”](#returns) `string` A group ID. # generateSpanId ```ts function generateSpanId(): string; ``` Generate a span ID by creating a random UUID v4 and removing the dashes. This is the equivalent of `uuid4().hex` in Python and prefixing it with `span_`. ## Returns [Section titled “Returns”](#returns) `string` A span ID. # generateTraceId ```ts function generateTraceId(): string; ``` Generate a trace ID by creating a random UUID v4 and removing the dashes. This is the equivalent of `uuid4().hex` in Python and prefixing it with `trace_`. ## Returns [Section titled “Returns”](#returns) `string` A trace ID. # getAllMcpTools ```ts function getAllMcpTools( mcpServersOrOpts, runContext?, agent?, convertSchemasToStrict?): Promise[]>; ``` Returns all MCP tools from the provided servers, using the function tool conversion. If runContext and agent are provided, callable tool filters will be applied. ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | ------------ | | `TContext` | `unknown` | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Default value | | ------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------- | | `mcpServersOrOpts` | \| [`MCPServer`](/openai-agents-js/openai/agents-core/interfaces/mcpserver/)\[] \| [`GetAllMcpToolsOptions`](/openai-agents-js/openai/agents-core/type-aliases/getallmcptoolsoptions/)<`TContext`> | `undefined` | | `runContext?` | [`RunContext`](/openai-agents-js/openai/agents-core/classes/runcontext/)<`TContext`> | `undefined` | | `agent?` | [`Agent`](/openai-agents-js/openai/agents-core/classes/agent/)<`TContext`, `any`> | `undefined` | | `convertSchemasToStrict?` | `boolean` | `false` | ## Returns [Section titled “Returns”](#returns) `Promise`<[`Tool`](/openai-agents-js/openai/agents-core/type-aliases/tool/)<`TContext`>\[]> # getClientToolSearchExecutor ```ts function getClientToolSearchExecutor(tool): | ClientToolSearchExecutor | undefined; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | ------------ | | `Context` | `unknown` | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ---------------------------------------------------------------------------- | | `tool` | [`Tool`](/openai-agents-js/openai/agents-core/type-aliases/tool/)<`Context`> | ## Returns [Section titled “Returns”](#returns) \| [`ClientToolSearchExecutor`](/openai-agents-js/openai/agents-core/type-aliases/clienttoolsearchexecutor/)<`Context`> | `undefined` # getCurrentSpan ```ts function getCurrentSpan(): | Span | null; ``` This function will get the current span from the execution context. ## Returns [Section titled “Returns”](#returns) \| [`Span`](/openai-agents-js/openai/agents-core/classes/span/)<`any`> | `null` The current span or null if there is no span. # getCurrentTrace ```ts function getCurrentTrace(): Trace | null; ``` This function will get the current trace from the execution context. ## Returns [Section titled “Returns”](#returns) [`Trace`](/openai-agents-js/openai/agents-core/classes/trace/) | `null` The current trace or null if there is no trace. # getDefaultModel ```ts function getDefaultModel(): string; ``` Returns the default model name. ## Returns [Section titled “Returns”](#returns) `string` # getDefaultModelSettings ```ts function getDefaultModelSettings(model?): ModelSettings; ``` Returns the default model settings. If the default model is a GPT-5 model, returns the GPT-5 default model settings. Otherwise, returns the legacy default model settings. ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | -------- | | `model?` | `string` | ## Returns [Section titled “Returns”](#returns) [`ModelSettings`](/openai-agents-js/openai/agents-core/type-aliases/modelsettings/) # getGlobalTraceProvider ```ts function getGlobalTraceProvider(): TraceProvider; ``` ## Returns [Section titled “Returns”](#returns) [`TraceProvider`](/openai-agents-js/openai/agents-core/classes/traceprovider/) # getHandoff ```ts function getHandoff(agent): Handoff; ``` Returns a handoff for the given agent. If the agent is already wrapped into a handoff, it will be returned as is. Otherwise, a new handoff instance will be created. ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Description | | ----------------------------------------------------------------------------------------------------------- | ------------------------------ | | `TContext` | The context of the handoff | | `TOutput` *extends* [`AgentOutputType`](/openai-agents-js/openai/agents-core/type-aliases/agentoutputtype/) | The output type of the handoff | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `agent` | \| [`Agent`](/openai-agents-js/openai/agents-core/classes/agent/)<`TContext`, `TOutput`> \| [`Handoff`](/openai-agents-js/openai/agents-core/classes/handoff/)<`TContext`, `TOutput`> | ## Returns [Section titled “Returns”](#returns) [`Handoff`](/openai-agents-js/openai/agents-core/classes/handoff/)<`TContext`, `TOutput`> # getLogger ```ts function getLogger(namespace?): Logger; ``` Get a logger for a given package. ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Default value | Description | | ----------- | -------- | ----------------- | ------------------------------------ | | `namespace` | `string` | `'openai-agents'` | the namespace to use for the logger. | ## Returns [Section titled “Returns”](#returns) `Logger` A logger object with `debug` and `error` methods. # getOrCreateTrace ```ts function getOrCreateTrace(fn, options?): Promise; ``` This function will check if there is an existing active trace in the execution context. If there is, it will run the given function with the existing trace. If there is no trace, it will create a new one and assign it to the execution context of the function. ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | -------------- | | `T` | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | --------- | -------------------- | ----------------------------------------------------- | | `fn` | () => `Promise`<`T`> | The fzunction to run and assign the trace context to. | | `options` | `TraceOptions` | Options for the creation of the trace | ## Returns [Section titled “Returns”](#returns) `Promise`<`T`> # getToolSearchRuntimeToolKey ```ts function getToolSearchRuntimeToolKey(tool): string | undefined; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | ------------ | | `Context` | `unknown` | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ---------------------------------------------------------------------------- | | `tool` | [`Tool`](/openai-agents-js/openai/agents-core/type-aliases/tool/)<`Context`> | ## Returns [Section titled “Returns”](#returns) `string` | `undefined` # getTransferMessage ```ts function getTransferMessage(agent): string; ``` Generates the message that will be given as tool output to the model that requested the handoff. ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | ----------------------------------------------------------------------------------------------------------- | | `TContext` | | `TOutput` *extends* [`AgentOutputType`](/openai-agents-js/openai/agents-core/type-aliases/agentoutputtype/) | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | --------- | ------------------------------------------------------------------------------------- | ------------------------ | | `agent` | [`Agent`](/openai-agents-js/openai/agents-core/classes/agent/)<`TContext`, `TOutput`> | The agent to transfer to | ## Returns [Section titled “Returns”](#returns) `string` The message that will be given as tool output to the model that requested the handoff # gpt5ReasoningSettingsRequired ```ts function gpt5ReasoningSettingsRequired(modelName): boolean; ``` Returns True if the model name is a GPT-5 model and reasoning settings are required. ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ----------- | -------- | | `modelName` | `string` | ## Returns [Section titled “Returns”](#returns) `boolean` # handoff ```ts function handoff(agent, config?): Handoff; ``` Creates a handoff from an agent. Handoffs are automatically created when you pass an agent into the `handoffs` option of the `Agent` constructor. Alternatively, you can use this function to create a handoff manually, giving you more control over configuration. ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | Description | | ---------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------- | ------------------------------ | | `TContext` | `unknown` | The context of the handoff | | `TOutput` *extends* [`AgentOutputType`](/openai-agents-js/openai/agents-core/type-aliases/agentoutputtype/) | `"text"` | The output type of the handoff | | `TInputType` *extends* [`ToolInputParameters`](/openai-agents-js/openai/agents-core/type-aliases/toolinputparameters/) | [`ToolInputParameters`](/openai-agents-js/openai/agents-core/type-aliases/toolinputparameters/) | The input type of the handoff | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ------------------------------------------------------------------------------------- | | `agent` | [`Agent`](/openai-agents-js/openai/agents-core/classes/agent/)<`TContext`, `TOutput`> | | `config` | `HandoffConfig`<`TInputType`, `TContext`> | ## Returns [Section titled “Returns”](#returns) [`Handoff`](/openai-agents-js/openai/agents-core/classes/handoff/)<`TContext`, `TOutput`> # hostedMcpTool ```ts function hostedMcpTool(options): HostedMCPTool; ``` Creates a hosted MCP tool definition. ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | ------------ | | `Context` | `unknown` | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | --------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------- | | `options` | `object` & ({ serverLabel: string; serverUrl?: string \| undefined; authorization?: string \| undefined; headers?: Record\ \| undefined; } \| { serverLabel: string; connectorId: string; authorization?: string \| undefined; headers?: Record<…> \| undefined; }) & ({ …; } \| … 1 more … \| { …; }) | Configuration for the hosted MCP tool, including server connection details and approval requirements. | ## Returns [Section titled “Returns”](#returns) [`HostedMCPTool`](/openai-agents-js/openai/agents-core/type-aliases/hostedmcptool/)<`Context`> # invalidateServerToolsCache ```ts function invalidateServerToolsCache(serverName): Promise; ``` Remove cached tools for the given server so the next lookup fetches fresh data. ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | ------------ | -------- | ----------------------------------------------------- | | `serverName` | `string` | Name of the MCP server whose cache should be cleared. | ## Returns [Section titled “Returns”](#returns) `Promise`<`void`> # invokeFunctionTool ```ts function invokeFunctionTool(args): Promise; ``` Invoke a function tool while enforcing optional per-tool timeout settings. ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | ----------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------- | | `Context` | `unknown` | | `TParameters` *extends* [`ToolInputParameters`](/openai-agents-js/openai/agents-core/type-aliases/toolinputparameters/) | [`ToolInputParameters`](/openai-agents-js/openai/agents-core/type-aliases/toolinputparameters/) | | `Result` | `unknown` | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ---------------------------------------------------------------- | | `args` | `FunctionToolInvocationArgs`<`Context`, `TParameters`, `Result`> | ## Returns [Section titled “Returns”](#returns) `Promise`<`string` | `Result`> # isGpt5Default ```ts function isGpt5Default(): boolean; ``` Returns True if the default model is a GPT-5 model. This is used to determine if the default model settings are compatible with GPT-5 models. If the default model is not a GPT-5 model, the model settings are compatible with other models. ## Returns [Section titled “Returns”](#returns) `boolean` # isOpenAIResponsesCompactionAwareSession ```ts function isOpenAIResponsesCompactionAwareSession(session): session is OpenAIResponsesCompactionAwareSession; ``` ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | --------------------------------------------------------------------------------------- | | `session` | \| [`Session`](/openai-agents-js/openai/agents-core/interfaces/session/) \| `undefined` | ## Returns [Section titled “Returns”](#returns) `session is OpenAIResponsesCompactionAwareSession` # isSessionHistoryRewriteAwareSession ```ts function isSessionHistoryRewriteAwareSession(session): session is SessionHistoryRewriteAwareSession; ``` ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | --------------------------------------------------------------------------------------- | | `session` | \| [`Session`](/openai-agents-js/openai/agents-core/interfaces/session/) \| `undefined` | ## Returns [Section titled “Returns”](#returns) `session is SessionHistoryRewriteAwareSession` # mcpToFunctionTool ```ts function mcpToFunctionTool( mcpTool, server, convertSchemasToStrict, options?): | FunctionTool, string> | FunctionTool, string>; ``` ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `mcpTool` | { `description?`: `string`; `inputSchema`: { `additionalProperties`: `boolean`; `properties`: `Record`<`string`, `any`>; `required`: `string`\[]; `type`: `"object"`; }; `name`: `string`; } | | `mcpTool.description?` | `string` | | `mcpTool.inputSchema` | { `additionalProperties`: `boolean`; `properties`: `Record`<`string`, `any`>; `required`: `string`\[]; `type`: `"object"`; } | | `mcpTool.inputSchema.additionalProperties` | `boolean` | | `mcpTool.inputSchema.properties` | `Record`<`string`, `any`> | | `mcpTool.inputSchema.required` | `string`\[] | | `mcpTool.inputSchema.type` | `"object"` | | `mcpTool.name` | `string` | | `server` | [`MCPServer`](/openai-agents-js/openai/agents-core/interfaces/mcpserver/) | | `convertSchemasToStrict` | `boolean` | | `options` | `MCPFunctionToolConversionOptions` | ## Returns [Section titled “Returns”](#returns) \| [`FunctionTool`](/openai-agents-js/openai/agents-core/type-aliases/functiontool/)<`any`, `JsonObjectSchemaStrict`<`any`>, `string`> | [`FunctionTool`](/openai-agents-js/openai/agents-core/type-aliases/functiontool/)<`any`, `JsonObjectSchemaNonStrict`<`any`>, `string`> # resetCurrentSpan ```ts function resetCurrentSpan(): void; ``` ## Returns [Section titled “Returns”](#returns) `void` # resolveToolInputGuardrails ```ts function resolveToolInputGuardrails(guardrails?): ToolInputGuardrailDefinition[]; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | ------------ | | `TContext` | `unknown` | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ------------- | --------------------------------------- | | `guardrails?` | `ToolInputGuardrailInit`<`TContext`>\[] | ## Returns [Section titled “Returns”](#returns) [`ToolInputGuardrailDefinition`](/openai-agents-js/openai/agents-core/interfaces/toolinputguardraildefinition/)<`TContext`>\[] # resolveToolOutputGuardrails ```ts function resolveToolOutputGuardrails(guardrails?): ToolOutputGuardrailDefinition[]; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | ------------ | | `TContext` | `unknown` | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ------------- | ---------------------------------------- | | `guardrails?` | `ToolOutputGuardrailInit`<`TContext`>\[] | ## Returns [Section titled “Returns”](#returns) [`ToolOutputGuardrailDefinition`](/openai-agents-js/openai/agents-core/interfaces/tooloutputguardraildefinition/)<`TContext`>\[] # run ## Call Signature [Section titled “Call Signature”](#call-signature) ```ts function run( agent, input, options?): Promise>; ``` Executes an agent workflow with the shared default `Runner` instance. ### Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | ----------------------------------------------------------------------------------------------- | ------------ | | `TAgent` *extends* [`Agent`](/openai-agents-js/openai/agents-core/classes/agent/)<`any`, `any`> | ‐ | | `TContext` | `undefined` | ### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | ---------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------- | | `agent` | `TAgent` | The entry agent to invoke. | | `input` | \| `string` \| [`AgentInputItem`](/openai-agents-js/openai/agents-core/type-aliases/agentinputitem/)\[] \| [`RunState`](/openai-agents-js/openai/agents-core/classes/runstate/)<`TContext`, `TAgent`> | A string utterance, structured input items, or a resumed `RunState`. | | `options?` | [`NonStreamRunOptions`](/openai-agents-js/openai/agents-core/type-aliases/nonstreamrunoptions/)<`TContext`, `TAgent`> | Controls streaming mode, context, session handling, and turn limits. | ### Returns [Section titled “Returns”](#returns) `Promise`<[`RunResult`](/openai-agents-js/openai/agents-core/classes/runresult/)<`TContext`, `TAgent`>> A `RunResult` when `stream` is false, otherwise a `StreamedRunResult`. ## Call Signature [Section titled “Call Signature”](#call-signature-1) ```ts function run( agent, input, options?): Promise>; ``` Executes an agent workflow with the shared default `Runner` instance. ### Type Parameters [Section titled “Type Parameters”](#type-parameters-1) | Type Parameter | Default type | | ----------------------------------------------------------------------------------------------- | ------------ | | `TAgent` *extends* [`Agent`](/openai-agents-js/openai/agents-core/classes/agent/)<`any`, `any`> | ‐ | | `TContext` | `undefined` | ### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | Description | | ---------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------- | | `agent` | `TAgent` | The entry agent to invoke. | | `input` | \| `string` \| [`AgentInputItem`](/openai-agents-js/openai/agents-core/type-aliases/agentinputitem/)\[] \| [`RunState`](/openai-agents-js/openai/agents-core/classes/runstate/)<`TContext`, `TAgent`> | A string utterance, structured input items, or a resumed `RunState`. | | `options?` | [`StreamRunOptions`](/openai-agents-js/openai/agents-core/type-aliases/streamrunoptions/)<`TContext`, `TAgent`> | Controls streaming mode, context, session handling, and turn limits. | ### Returns [Section titled “Returns”](#returns-1) `Promise`<[`StreamedRunResult`](/openai-agents-js/openai/agents-core/classes/streamedrunresult/)<`TContext`, `TAgent`>> A `RunResult` when `stream` is false, otherwise a `StreamedRunResult`. # runToolInputGuardrails ```ts function runToolInputGuardrails(__namedParameters): Promise< | { type: "allow"; } | { message: string; type: "reject"; }>; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | ----------------------------------------------------------------------------------------------- | | `TContext` | | `TAgent` *extends* [`Agent`](/openai-agents-js/openai/agents-core/classes/agent/)<`any`, `any`> | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | ------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `__namedParameters` | { `agent`: `TAgent`; `context`: [`RunContext`](/openai-agents-js/openai/agents-core/classes/runcontext/)<`TContext`>; `guardrails?`: [`ToolInputGuardrailDefinition`](/openai-agents-js/openai/agents-core/interfaces/toolinputguardraildefinition/)<`TContext`>\[]; `onResult?`: (`result`) => `void`; `toolCall`: { `arguments`: `string`; `callId`: `string`; `id?`: `string`; `name`: `string`; `namespace?`: `string`; `providerData?`: `Record`<`string`, `any`>; `status?`: `"in_progress"` \| `"completed"` \| `"incomplete"`; `type`: `"function_call"`; }; } | ‐ | | `__namedParameters.agent` | `TAgent` | ‐ | | `__namedParameters.context` | [`RunContext`](/openai-agents-js/openai/agents-core/classes/runcontext/)<`TContext`> | ‐ | | `__namedParameters.guardrails?` | [`ToolInputGuardrailDefinition`](/openai-agents-js/openai/agents-core/interfaces/toolinputguardraildefinition/)<`TContext`>\[] | ‐ | | `__namedParameters.onResult?` | (`result`) => `void` | ‐ | | `__namedParameters.toolCall` | { `arguments`: `string`; `callId`: `string`; `id?`: `string`; `name`: `string`; `namespace?`: `string`; `providerData?`: `Record`<`string`, `any`>; `status?`: `"in_progress"` \| `"completed"` \| `"incomplete"`; `type`: `"function_call"`; } | ‐ | | `__namedParameters.toolCall.arguments` | `string` | The arguments of the function call. | | `__namedParameters.toolCall.callId` | `string` | The ID of the tool call. Required to match up the respective tool call result. | | `__namedParameters.toolCall.id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `__namedParameters.toolCall.name` | `string` | The name of the function. | | `__namedParameters.toolCall.namespace?` | `string` | Optional namespace used to qualify the function name for tool search. | | `__namedParameters.toolCall.providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `__namedParameters.toolCall.status?` | `"in_progress"` \| `"completed"` \| `"incomplete"` | The status of the function call. | | `__namedParameters.toolCall.type` | `"function_call"` | ‐ | ## Returns [Section titled “Returns”](#returns) `Promise`< | { `type`: `"allow"`; } | { `message`: `string`; `type`: `"reject"`; }> # runToolOutputGuardrails ```ts function runToolOutputGuardrails(__namedParameters): Promise; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | ----------------------------------------------------------------------------------------------- | | `TContext` | | `TAgent` *extends* [`Agent`](/openai-agents-js/openai/agents-core/classes/agent/)<`any`, `any`> | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | ------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `__namedParameters` | { `agent`: `TAgent`; `context`: [`RunContext`](/openai-agents-js/openai/agents-core/classes/runcontext/)<`TContext`>; `guardrails?`: [`ToolOutputGuardrailDefinition`](/openai-agents-js/openai/agents-core/interfaces/tooloutputguardraildefinition/)<`TContext`>\[]; `onResult?`: (`result`) => `void`; `toolCall`: { `arguments`: `string`; `callId`: `string`; `id?`: `string`; `name`: `string`; `namespace?`: `string`; `providerData?`: `Record`<`string`, `any`>; `status?`: `"in_progress"` \| `"completed"` \| `"incomplete"`; `type`: `"function_call"`; }; `toolOutput`: `unknown`; } | ‐ | | `__namedParameters.agent` | `TAgent` | ‐ | | `__namedParameters.context` | [`RunContext`](/openai-agents-js/openai/agents-core/classes/runcontext/)<`TContext`> | ‐ | | `__namedParameters.guardrails?` | [`ToolOutputGuardrailDefinition`](/openai-agents-js/openai/agents-core/interfaces/tooloutputguardraildefinition/)<`TContext`>\[] | ‐ | | `__namedParameters.onResult?` | (`result`) => `void` | ‐ | | `__namedParameters.toolCall` | { `arguments`: `string`; `callId`: `string`; `id?`: `string`; `name`: `string`; `namespace?`: `string`; `providerData?`: `Record`<`string`, `any`>; `status?`: `"in_progress"` \| `"completed"` \| `"incomplete"`; `type`: `"function_call"`; } | ‐ | | `__namedParameters.toolCall.arguments` | `string` | The arguments of the function call. | | `__namedParameters.toolCall.callId` | `string` | The ID of the tool call. Required to match up the respective tool call result. | | `__namedParameters.toolCall.id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `__namedParameters.toolCall.name` | `string` | The name of the function. | | `__namedParameters.toolCall.namespace?` | `string` | Optional namespace used to qualify the function name for tool search. | | `__namedParameters.toolCall.providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `__namedParameters.toolCall.status?` | `"in_progress"` \| `"completed"` \| `"incomplete"` | The status of the function call. | | `__namedParameters.toolCall.type` | `"function_call"` | ‐ | | `__namedParameters.toolOutput` | `unknown` | ‐ | ## Returns [Section titled “Returns”](#returns) `Promise`<`unknown`> # setCurrentSpan ```ts function setCurrentSpan(span): void; ``` This function will set the current span in the execution context. ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | --------- | ------------------------------------------------------------------- | ------------------------------------ | | `span` | [`Span`](/openai-agents-js/openai/agents-core/classes/span/)<`any`> | The span to set as the current span. | ## Returns [Section titled “Returns”](#returns) `void` # setDefaultModelProvider ```ts function setDefaultModelProvider(provider): void; ``` Set the model provider used when no explicit provider is supplied. ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | ---------- | --------------------------------------------------------------------------------- | ------------------------------- | | `provider` | [`ModelProvider`](/openai-agents-js/openai/agents-core/interfaces/modelprovider/) | The provider to use by default. | ## Returns [Section titled “Returns”](#returns) `void` # setTraceProcessors ```ts function setTraceProcessors(processors): void; ``` Set the list of processors. This will replace any existing processors. ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | ------------ | ------------------------------------------------------------------------------------------ | ------------------------------ | | `processors` | [`TracingProcessor`](/openai-agents-js/openai/agents-core/interfaces/tracingprocessor/)\[] | The list of processors to set. | ## Returns [Section titled “Returns”](#returns) `void` # setTracingDisabled ```ts function setTracingDisabled(disabled): void; ``` Set the disabled state of the tracing provider. ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | ---------- | --------- | --------------------------- | | `disabled` | `boolean` | Whether to disable tracing. | ## Returns [Section titled “Returns”](#returns) `void` # shellTool ## Call Signature [Section titled “Call Signature”](#call-signature) ```ts function shellTool(options): NormalizedLocalShellTool; ``` ### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ----------------------- | | `options` | `LocalShellToolOptions` | ### Returns [Section titled “Returns”](#returns) `NormalizedLocalShellTool` ## Call Signature [Section titled “Call Signature”](#call-signature-1) ```ts function shellTool(options): HostedShellTool; ``` ### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | --------- | ------------------------ | | `options` | `HostedShellToolOptions` | ### Returns [Section titled “Returns”](#returns-1) `HostedShellTool` # startTraceExportLoop ```ts function startTraceExportLoop(): void; ``` Start the trace export loop. ## Returns [Section titled “Returns”](#returns) `void` # system ```ts function system(input, options?): object; ``` Creates a system message entry ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | ---------- | ------------------------- | ----------------------------------------------------------------- | | `input` | `string` | The system prompt. | | `options?` | `Record`<`string`, `any`> | Any additional options that will be directly passed to the model. | ## Returns [Section titled “Returns”](#returns) A message entry. ### content [Section titled “content”](#content) ```ts content: string; ``` The content of the message. ### id? [Section titled “id?”](#id) ```ts optional id?: string; ``` An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. ### role [Section titled “role”](#role) ```ts role: "system"; ``` Representing a system message to the user ### type? [Section titled “type?”](#type) ```ts optional type?: "message"; ``` Any item without a type is treated as a message # tool ```ts function tool(options): FunctionTool; ``` Exposes a function to the agent as a tool to be called ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | ----------------------------------------------------------------------------------------------------------------------- | ------------ | | `TParameters` *extends* [`ToolInputParameters`](/openai-agents-js/openai/agents-core/type-aliases/toolinputparameters/) | `undefined` | | `Context` | `unknown` | | `Result` | `string` | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | --------- | --------------------------------------------------------------------------------------------------------- | ------------------------ | | `options` | [`ToolOptions`](/openai-agents-js/openai/agents-core/type-aliases/tooloptions/)<`TParameters`, `Context`> | The options for the tool | ## Returns [Section titled “Returns”](#returns) [`FunctionTool`](/openai-agents-js/openai/agents-core/type-aliases/functiontool/)<`Context`, `TParameters`, `Result`> A new tool # toolNamespace ```ts function toolNamespace(options): TTools; ``` Responses API only. Group function tools under a shared namespace. ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | ------------------------------------------------ | | `TTools` *extends* readonly `AnyFunctionTool`\[] | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | --------- | ----------------------------------------------------------------------------------------------------------- | ------------------------------------------------ | | `options` | [`ToolNamespaceOptions`](/openai-agents-js/openai/agents-core/type-aliases/toolnamespaceoptions/)<`TTools`> | Namespace metadata and function tools to attach. | ## Returns [Section titled “Returns”](#returns) `TTools` shallow-cloned function tools carrying namespace metadata. # user ```ts function user(input, options?): object; ``` Creates a user message entry ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | ---------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------- | | `input` | \| `string` \| ( \| { `providerData?`: `Record`<`string`, `any`>; `text`: `string`; `type`: `"input_text"`; } \| { `detail?`: `string`; `image?`: \| `string` \| { `id`: `string`; }; `providerData?`: `Record`<`string`, `any`>; `type`: `"input_image"`; } \| { `file?`: \| `string` \| { `id`: `string`; } \| { `url`: `string`; }; `filename?`: `string`; `providerData?`: `Record`<`string`, `any`>; `type`: `"input_file"`; } \| { `audio`: \| `string` \| { `id`: `string`; }; `format?`: `string` \| `null`; `providerData?`: `Record`<`string`, `any`>; `transcript?`: `string` \| `null`; `type`: `"audio"`; })\[] | The input message from the user. | | `options?` | `Record`<`string`, `any`> | Any additional options that will be directly passed to the model. | ## Returns [Section titled “Returns”](#returns) A message entry. ### content [Section titled “content”](#content) ```ts content: | string | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; })[]; ``` The content of the message. ### id? [Section titled “id?”](#id) ```ts optional id?: string; ``` An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. ### role [Section titled “role”](#role) ```ts role: "user"; ``` Representing a message from the user ### type? [Section titled “type?”](#type) ```ts optional type?: "message"; ``` Any item without a type is treated as a message # withTrace ```ts function withTrace( trace, fn, options?): Promise; ``` This function will create a new trace and assign it to the execution context of the function passed to it. ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | -------------- | | `T` | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | --------- | -------------------------------------------------------------------------- | ---------------------------------------------------- | | `trace` | `string` \| [`Trace`](/openai-agents-js/openai/agents-core/classes/trace/) | ‐ | | `fn` | (`trace`) => `Promise`<`T`> | The function to run and assign the trace context to. | | `options` | `TraceOptions` | Options for the creation of the trace | ## Returns [Section titled “Returns”](#returns) `Promise`<`T`> # AgentConfiguration Configuration for an agent. ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | Description | | ----------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------- | ------------------------------- | | `TContext` | [`UnknownContext`](/openai-agents-js/openai/agents-core/type-aliases/unknowncontext/) | The type of the context object. | | `TOutput` *extends* [`AgentOutputType`](/openai-agents-js/openai/agents-core/type-aliases/agentoutputtype/) | [`TextOutput`](/openai-agents-js/openai/agents-core/type-aliases/textoutput/) | The type of the output object. | ## Properties [Section titled “Properties”](#properties) ### handoffDescription [Section titled “handoffDescription”](#handoffdescription) ```ts handoffDescription: string; ``` A description of the agent. This is used when the agent is used as a handoff, so that an LLM knows what it does and when to invoke it. *** ### handoffOutputTypeWarningEnabled? [Section titled “handoffOutputTypeWarningEnabled?”](#handoffoutputtypewarningenabled) ```ts optional handoffOutputTypeWarningEnabled?: boolean; ``` The warning log would be enabled when multiple output types by handoff agents are detected. *** ### handoffs [Section titled “handoffs”](#handoffs) ```ts handoffs: ( | Agent | Handoff)[]; ``` Handoffs are sub-agents that the agent can delegate to. You can provide a list of handoffs, and the agent can choose to delegate to them if relevant. Allows for separation of concerns and modularity. *** ### inputGuardrails [Section titled “inputGuardrails”](#inputguardrails) ```ts inputGuardrails: InputGuardrail[]; ``` A list of checks that run in parallel to the agent by default; set `runInParallel` to false to block LLM/tool calls until the guardrail completes. Runs only if the agent is the first agent in the chain. *** ### instructions [Section titled “instructions”](#instructions) ```ts instructions: string | ((runContext, agent) => string | Promise); ``` The instructions for the agent. Will be used as the “system prompt” when this agent is invoked. Describes what the agent should do, and how it responds. Can either be a string, or a function that dynamically generates instructions for the agent. If you provide a function, it will be called with the context and the agent instance. It must return a string. *** ### mcpConfig [Section titled “mcpConfig”](#mcpconfig) ```ts mcpConfig: object; ``` Configuration for MCP servers used by this agent. | Name | Type | Description | | --------------------------- | -------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `convertSchemasToStrict?` | `boolean` | Try to convert MCP tool schemas to strict JSON schema. | | `errorFunction?` | \| [`MCPToolErrorFunction`](/openai-agents-js/openai/agents-core/type-aliases/mcptoolerrorfunction/) \| `null` | Optional function to convert MCP tool failures into model-visible messages. Set to null to rethrow errors instead of converting them. Server-level errorFunction values take precedence. | | `includeServerInToolNames?` | `boolean` | Prefix local MCP tool names with their server name before exposing them to the model. The SDK still invokes the original MCP tool name on the original server. | *** ### mcpServers [Section titled “mcpServers”](#mcpservers) ```ts mcpServers: MCPServer[]; ``` A list of [Model Context Protocol](https://modelcontextprotocol.io/) servers the agent can use. Every time the agent runs, it will include tools from these servers in the list of available tools. NOTE: You are expected to manage the lifecycle of these servers. Specifically, you must call `server.connect()` before passing it to the agent, and `server.close()` when the server is no longer needed. Consider using `connectMcpServers` or `MCPServers` to keep open/close in the same place. *** ### model [Section titled “model”](#model) ```ts model: | string | Model; ``` The model implementation to use when invoking the LLM. By default, if not set, the agent will use the default model returned by getDefaultModel (currently “gpt-5.4-mini”). *** ### modelSettings [Section titled “modelSettings”](#modelsettings) ```ts modelSettings: ModelSettings; ``` Configures model-specific tuning parameters (e.g. temperature, top\_p, etc.) *** ### name [Section titled “name”](#name) ```ts name: string; ``` *** ### outputGuardrails [Section titled “outputGuardrails”](#outputguardrails) ```ts outputGuardrails: OutputGuardrail[]; ``` A list of checks that run on the final output of the agent, after generating a response. Runs only if the agent produces a final output. *** ### outputType [Section titled “outputType”](#outputtype) ```ts outputType: TOutput; ``` The type of the output object. If not provided, the output will be a string. *** ### prompt? [Section titled “prompt?”](#prompt) ```ts optional prompt?: Prompt | ((runContext, agent) => Prompt | Promise); ``` The prompt template to use for the agent (OpenAI Responses API only). Can either be a prompt template object, or a function that returns a prompt template object. If a function is provided, it will be called with the run context and the agent instance. It must return a prompt template object. *** ### resetToolChoice [Section titled “resetToolChoice”](#resettoolchoice) ```ts resetToolChoice: boolean; ``` Whether to reset the tool choice to the default value after a tool has been called. Defaults to `true`. This ensures that the agent doesn’t enter an infinite loop of tool usage. *** ### tools [Section titled “tools”](#tools) ```ts tools: Tool[]; ``` A list of tools the agent can use. *** ### toolUseBehavior [Section titled “toolUseBehavior”](#toolusebehavior) ```ts toolUseBehavior: ToolUseBehavior; ``` This lets you configure how tool use is handled. * run\_llm\_again: The default behavior. Tools are run, and then the LLM receives the results and gets to respond. * stop\_on\_first\_tool: The output of the first tool call is used as the final output. This means that the LLM does not process the result of the tool call. * A list of tool names: The agent will stop running if any of the tools in the list are called. The final output will be the output of the first matching tool call. The LLM does not process the result of the tool call. * A function: if you pass a function, it will be called with the run context and the list of tool results. It must return a `ToolsToFinalOutputResult`, which determines whether the tool call resulted in a final output. NOTE: This configuration is specific to `FunctionTools`. Hosted tools, such as file search, web search, etc. are always processed by the LLM # Editor Host interface responsible for applying diffs on disk. ## Methods [Section titled “Methods”](#methods) ### createFile() [Section titled “createFile()”](#createfile) ```ts createFile(operation, context?): Promise< | void | ApplyPatchResult>; ``` Creates a new file from a V4A diff. #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ----------------- | ------------------------------------------------------------------------------------------------------- | | `operation` | { `diff`: `string`; `path`: `string`; `type`: `"create_file"`; } | | `operation.diff` | `string` | | `operation.path?` | `string` | | `operation.type?` | `"create_file"` | | `context?` | [`EditorInvocationContext`](/openai-agents-js/openai/agents-core/type-aliases/editorinvocationcontext/) | #### Returns [Section titled “Returns”](#returns) `Promise`< | `void` | [`ApplyPatchResult`](/openai-agents-js/openai/agents-core/type-aliases/applypatchresult/)> *** ### deleteFile() [Section titled “deleteFile()”](#deletefile) ```ts deleteFile(operation, context?): Promise< | void | ApplyPatchResult>; ``` Deletes an existing file. #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | ----------------- | ------------------------------------------------------------------------------------------------------- | | `operation` | { `path`: `string`; `type`: `"delete_file"`; } | | `operation.path` | `string` | | `operation.type?` | `"delete_file"` | | `context?` | [`EditorInvocationContext`](/openai-agents-js/openai/agents-core/type-aliases/editorinvocationcontext/) | #### Returns [Section titled “Returns”](#returns-1) `Promise`< | `void` | [`ApplyPatchResult`](/openai-agents-js/openai/agents-core/type-aliases/applypatchresult/)> *** ### updateFile() [Section titled “updateFile()”](#updatefile) ```ts updateFile(operation, context?): Promise< | void | ApplyPatchResult>; ``` Updates an existing file based on a V4A diff. #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | ------------------- | ------------------------------------------------------------------------------------------------------- | | `operation` | { `diff`: `string`; `moveTo?`: `string`; `path`: `string`; `type`: `"update_file"`; } | | `operation.diff` | `string` | | `operation.moveTo?` | `string` | | `operation.path?` | `string` | | `operation.type?` | `"update_file"` | | `context?` | [`EditorInvocationContext`](/openai-agents-js/openai/agents-core/type-aliases/editorinvocationcontext/) | #### Returns [Section titled “Returns”](#returns-2) `Promise`< | `void` | [`ApplyPatchResult`](/openai-agents-js/openai/agents-core/type-aliases/applypatchresult/)> # GuardrailFunctionOutput The output of a guardrail function. ## Properties [Section titled “Properties”](#properties) ### outputInfo [Section titled “outputInfo”](#outputinfo) ```ts outputInfo: any; ``` Optional information about the guardrail’s output. For example, the guardrail could include information about the checks it performed and granular results. *** ### tripwireTriggered [Section titled “tripwireTriggered”](#tripwiretriggered) ```ts tripwireTriggered: boolean; ``` Whether the tripwire was triggered. If triggered, the agent’s execution will be halted. # InputGuardrail A guardrail that checks the input to the agent. ## Properties [Section titled “Properties”](#properties) ### execute [Section titled “execute”](#execute) ```ts execute: InputGuardrailFunction; ``` The function that performs the guardrail check *** ### name [Section titled “name”](#name) ```ts name: string; ``` The name of the guardrail. *** ### runInParallel? [Section titled “runInParallel?”](#runinparallel) ```ts optional runInParallel?: boolean; ``` Whether the guardrail should execute alongside the agent (true, default) or block the agent until it completes (false). # InputGuardrailFunctionArgs Arguments for an input guardrail function. ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | ------------------------------------------------------------------------------------- | | `TContext` | [`UnknownContext`](/openai-agents-js/openai/agents-core/type-aliases/unknowncontext/) | ## Properties [Section titled “Properties”](#properties) ### agent [Section titled “agent”](#agent) ```ts agent: Agent; ``` The agent that is being run. *** ### context [Section titled “context”](#context) ```ts context: RunContext; ``` The context of the agent run. *** ### input [Section titled “input”](#input) ```ts input: | string | ( | { content: ( | { providerData?: Record; refusal: string; type: "refusal"; } | { providerData?: Record; text: string; type: "output_text"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; } | { image: string; providerData?: Record; type: "image"; })[]; id?: string; providerData?: Record; role: "assistant"; status: "in_progress" | "completed" | "incomplete"; type?: "message"; } | { content: | string | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; })[]; id?: string; providerData?: Record; role: "user"; type?: "message"; } | { content: string; id?: string; providerData?: Record; role: "system"; type?: "message"; } | { arguments?: string; id?: string; name: string; output?: string; providerData?: Record; status?: string; type: "hosted_tool_call"; } | { arguments: string; callId: string; id?: string; name: string; namespace?: string; providerData?: Record; status?: "in_progress" | "completed" | "incomplete"; type: "function_call"; } | { arguments: unknown; call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; type: "tool_search_call"; } | { call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; tools: Record[]; type: "tool_search_output"; } | { callId: string; id?: string; name: string; namespace?: string; output: | string | { providerData?: Record; text: string; type: "text"; } | { detail?: "low" | "high" | "auto" | string & object; image?: | string | { data: string | Uint8Array; mediaType?: string; } | { url: string; } | { fileId: string; }; providerData?: Record; type: "image"; } | { file: | string | { data: string | Uint8Array; filename: string; mediaType: string; } | { filename?: string; url: string; } | { filename?: string; id: string; }; providerData?: Record; type: "file"; } | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; })[]; providerData?: Record; status: "in_progress" | "completed" | "incomplete"; type: "function_call_result"; } | { action?: | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; }; actions?: ( | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; })[]; callId: string; id?: string; providerData?: Record; status: "in_progress" | "completed" | "incomplete"; type: "computer_call"; } | { callId: string; id?: string; output: { data: string; providerData?: Record; type: "computer_screenshot"; }; providerData?: Record; type: "computer_call_result"; } | { action: { commands: string[]; maxOutputLength?: number; timeoutMs?: number; }; callId: string; id?: string; providerData?: Record; status?: "in_progress" | "completed" | "incomplete"; type: "shell_call"; } | { callId: string; id?: string; maxOutputLength?: number; output: object[]; providerData?: Record; type: "shell_call_output"; } | { callId: string; id?: string; operation: | { diff: string; path: string; type: "create_file"; } | { diff: string; moveTo?: string; path: string; type: "update_file"; } | { path: string; type: "delete_file"; }; providerData?: Record; status: "in_progress" | "completed"; type: "apply_patch_call"; } | { callId: string; id?: string; output?: string; providerData?: Record; status: "completed" | "failed"; type: "apply_patch_call_output"; } | { content: object[]; id?: string; providerData?: Record; rawContent?: object[]; type: "reasoning"; } | { created_by?: string; encrypted_content: string; id?: string; providerData?: Record; type: "compaction"; } | { id?: string; providerData?: Record; type: "unknown"; })[]; ``` The input to the agent. # InputGuardrailMetadata Metadata for an input guardrail. ## Properties [Section titled “Properties”](#properties) ### name [Section titled “name”](#name) ```ts name: string; ``` *** ### type [Section titled “type”](#type) ```ts type: "input"; ``` # InputGuardrailResult The result of an input guardrail execution. ## Properties [Section titled “Properties”](#properties) ### guardrail [Section titled “guardrail”](#guardrail) ```ts guardrail: InputGuardrailMetadata; ``` The metadata of the guardrail. *** ### output [Section titled “output”](#output) ```ts output: GuardrailFunctionOutput; ``` The output of the guardrail. # MCPBlobResourceContent Binary resource content returned by `readResource`. ## Indexable [Section titled “Indexable”](#indexable) ```ts [key: string]: unknown ``` ## Properties [Section titled “Properties”](#properties) ### blob [Section titled “blob”](#blob) ```ts blob: string; ``` *** ### mimeType? [Section titled “mimeType?”](#mimetype) ```ts optional mimeType?: string; ``` *** ### uri [Section titled “uri”](#uri) ```ts uri: string; ``` # MCPListResourcesParams Minimal params accepted by MCP resource-listing methods. ## Indexable [Section titled “Indexable”](#indexable) ```ts [key: string]: unknown ``` ## Properties [Section titled “Properties”](#properties) ### cursor? [Section titled “cursor?”](#cursor) ```ts optional cursor?: string; ``` # MCPListResourcesResult Result returned by `listResources`. ## Indexable [Section titled “Indexable”](#indexable) ```ts [key: string]: unknown ``` ## Properties [Section titled “Properties”](#properties) ### nextCursor? [Section titled “nextCursor?”](#nextcursor) ```ts optional nextCursor?: string; ``` *** ### resources [Section titled “resources”](#resources) ```ts resources: MCPResource[]; ``` # MCPListResourceTemplatesResult Result returned by `listResourceTemplates`. ## Indexable [Section titled “Indexable”](#indexable) ```ts [key: string]: unknown ``` ## Properties [Section titled “Properties”](#properties) ### nextCursor? [Section titled “nextCursor?”](#nextcursor) ```ts optional nextCursor?: string; ``` *** ### resourceTemplates [Section titled “resourceTemplates”](#resourcetemplates) ```ts resourceTemplates: MCPResourceTemplate[]; ``` # MCPReadResourceResult Result returned by `readResource`. ## Indexable [Section titled “Indexable”](#indexable) ```ts [key: string]: unknown ``` ## Properties [Section titled “Properties”](#properties) ### contents [Section titled “contents”](#contents) ```ts contents: MCPResourceContent[]; ``` # MCPResource Minimal MCP resource definition used by this SDK. ## Indexable [Section titled “Indexable”](#indexable) ```ts [key: string]: unknown ``` ## Properties [Section titled “Properties”](#properties) ### annotations? [Section titled “annotations?”](#annotations) ```ts optional annotations?: Record; ``` *** ### description? [Section titled “description?”](#description) ```ts optional description?: string; ``` *** ### mimeType? [Section titled “mimeType?”](#mimetype) ```ts optional mimeType?: string; ``` *** ### name? [Section titled “name?”](#name) ```ts optional name?: string; ``` *** ### size? [Section titled “size?”](#size) ```ts optional size?: number; ``` *** ### title? [Section titled “title?”](#title) ```ts optional title?: string; ``` *** ### uri [Section titled “uri”](#uri) ```ts uri: string; ``` # MCPResourceTemplate Minimal MCP resource template definition used by this SDK. ## Indexable [Section titled “Indexable”](#indexable) ```ts [key: string]: unknown ``` ## Properties [Section titled “Properties”](#properties) ### annotations? [Section titled “annotations?”](#annotations) ```ts optional annotations?: Record; ``` *** ### description? [Section titled “description?”](#description) ```ts optional description?: string; ``` *** ### mimeType? [Section titled “mimeType?”](#mimetype) ```ts optional mimeType?: string; ``` *** ### name? [Section titled “name?”](#name) ```ts optional name?: string; ``` *** ### title? [Section titled “title?”](#title) ```ts optional title?: string; ``` *** ### uriTemplate [Section titled “uriTemplate”](#uritemplate) ```ts uriTemplate: string; ``` # MCPServer Interface for MCP server implementations. Provides methods for connecting, listing tools, calling tools, and cleanup. ## Extended by [Section titled “Extended by”](#extended-by) * [`MCPServerWithResources`](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/) ## Properties [Section titled “Properties”](#properties) ### cacheToolsList [Section titled “cacheToolsList”](#cachetoolslist) ```ts cacheToolsList: boolean; ``` *** ### errorFunction? [Section titled “errorFunction?”](#errorfunction) ```ts optional errorFunction?: | MCPToolErrorFunction | null; ``` Optional function to convert MCP tool failures into model-visible messages. Set to null to rethrow errors instead of converting them. *** ### name [Section titled “name”](#name) ```ts readonly name: string; ``` *** ### toolFilter? [Section titled “toolFilter?”](#toolfilter) ```ts optional toolFilter?: | MCPToolFilterStatic | MCPToolFilterCallable; ``` *** ### toolMetaResolver? [Section titled “toolMetaResolver?”](#toolmetaresolver) ```ts optional toolMetaResolver?: MCPToolMetaResolver; ``` ## Methods [Section titled “Methods”](#methods) ### callTool() [Section titled “callTool()”](#calltool) ```ts callTool( toolName, args, meta?): Promise; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ---------- | --------------------------------------- | | `toolName` | `string` | | `args` | `Record`<`string`, `unknown`> \| `null` | | `meta?` | `Record`<`string`, `unknown`> \| `null` | #### Returns [Section titled “Returns”](#returns) `Promise`<`object`\[]> *** ### close() [Section titled “close()”](#close) ```ts close(): Promise; ``` #### Returns [Section titled “Returns”](#returns-1) `Promise`<`void`> *** ### connect() [Section titled “connect()”](#connect) ```ts connect(): Promise; ``` #### Returns [Section titled “Returns”](#returns-2) `Promise`<`void`> *** ### invalidateToolsCache() [Section titled “invalidateToolsCache()”](#invalidatetoolscache) ```ts invalidateToolsCache(): Promise; ``` #### Returns [Section titled “Returns”](#returns-3) `Promise`<`void`> *** ### listTools() [Section titled “listTools()”](#listtools) ```ts listTools(): Promise; ``` #### Returns [Section titled “Returns”](#returns-4) `Promise`<`object`\[]> # MCPServerWithResources Extended MCP server surface for servers that expose resources. ## Extends [Section titled “Extends”](#extends) * [`MCPServer`](/openai-agents-js/openai/agents-core/interfaces/mcpserver/) ## Properties [Section titled “Properties”](#properties) ### cacheToolsList [Section titled “cacheToolsList”](#cachetoolslist) ```ts cacheToolsList: boolean; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from) [`MCPServer`](/openai-agents-js/openai/agents-core/interfaces/mcpserver/).[`cacheToolsList`](/openai-agents-js/openai/agents-core/interfaces/mcpserver/#cachetoolslist) *** ### errorFunction? [Section titled “errorFunction?”](#errorfunction) ```ts optional errorFunction?: | MCPToolErrorFunction | null; ``` Optional function to convert MCP tool failures into model-visible messages. Set to null to rethrow errors instead of converting them. #### Inherited from [Section titled “Inherited from”](#inherited-from-1) [`MCPServer`](/openai-agents-js/openai/agents-core/interfaces/mcpserver/).[`errorFunction`](/openai-agents-js/openai/agents-core/interfaces/mcpserver/#errorfunction) *** ### name [Section titled “name”](#name) ```ts readonly name: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-2) [`MCPServer`](/openai-agents-js/openai/agents-core/interfaces/mcpserver/).[`name`](/openai-agents-js/openai/agents-core/interfaces/mcpserver/#name) *** ### toolFilter? [Section titled “toolFilter?”](#toolfilter) ```ts optional toolFilter?: | MCPToolFilterStatic | MCPToolFilterCallable; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-3) [`MCPServer`](/openai-agents-js/openai/agents-core/interfaces/mcpserver/).[`toolFilter`](/openai-agents-js/openai/agents-core/interfaces/mcpserver/#toolfilter) *** ### toolMetaResolver? [Section titled “toolMetaResolver?”](#toolmetaresolver) ```ts optional toolMetaResolver?: MCPToolMetaResolver; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-4) [`MCPServer`](/openai-agents-js/openai/agents-core/interfaces/mcpserver/).[`toolMetaResolver`](/openai-agents-js/openai/agents-core/interfaces/mcpserver/#toolmetaresolver) ## Methods [Section titled “Methods”](#methods) ### callTool() [Section titled “callTool()”](#calltool) ```ts callTool( toolName, args, meta?): Promise; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ---------- | --------------------------------------- | | `toolName` | `string` | | `args` | `Record`<`string`, `unknown`> \| `null` | | `meta?` | `Record`<`string`, `unknown`> \| `null` | #### Returns [Section titled “Returns”](#returns) `Promise`<`object`\[]> #### Inherited from [Section titled “Inherited from”](#inherited-from-5) [`MCPServer`](/openai-agents-js/openai/agents-core/interfaces/mcpserver/).[`callTool`](/openai-agents-js/openai/agents-core/interfaces/mcpserver/#calltool) *** ### close() [Section titled “close()”](#close) ```ts close(): Promise; ``` #### Returns [Section titled “Returns”](#returns-1) `Promise`<`void`> #### Inherited from [Section titled “Inherited from”](#inherited-from-6) [`MCPServer`](/openai-agents-js/openai/agents-core/interfaces/mcpserver/).[`close`](/openai-agents-js/openai/agents-core/interfaces/mcpserver/#close) *** ### connect() [Section titled “connect()”](#connect) ```ts connect(): Promise; ``` #### Returns [Section titled “Returns”](#returns-2) `Promise`<`void`> #### Inherited from [Section titled “Inherited from”](#inherited-from-7) [`MCPServer`](/openai-agents-js/openai/agents-core/interfaces/mcpserver/).[`connect`](/openai-agents-js/openai/agents-core/interfaces/mcpserver/#connect) *** ### invalidateToolsCache() [Section titled “invalidateToolsCache()”](#invalidatetoolscache) ```ts invalidateToolsCache(): Promise; ``` #### Returns [Section titled “Returns”](#returns-3) `Promise`<`void`> #### Inherited from [Section titled “Inherited from”](#inherited-from-8) [`MCPServer`](/openai-agents-js/openai/agents-core/interfaces/mcpserver/).[`invalidateToolsCache`](/openai-agents-js/openai/agents-core/interfaces/mcpserver/#invalidatetoolscache) *** ### listResources() [Section titled “listResources()”](#listresources) ```ts listResources(params?): Promise; ``` #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | --------- | --------------------------------------------------------------------------------------------------- | | `params?` | [`MCPListResourcesParams`](/openai-agents-js/openai/agents-core/interfaces/mcplistresourcesparams/) | #### Returns [Section titled “Returns”](#returns-4) `Promise`<[`MCPListResourcesResult`](/openai-agents-js/openai/agents-core/interfaces/mcplistresourcesresult/)> *** ### listResourceTemplates() [Section titled “listResourceTemplates()”](#listresourcetemplates) ```ts listResourceTemplates(params?): Promise; ``` #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | --------- | --------------------------------------------------------------------------------------------------- | | `params?` | [`MCPListResourcesParams`](/openai-agents-js/openai/agents-core/interfaces/mcplistresourcesparams/) | #### Returns [Section titled “Returns”](#returns-5) `Promise`<[`MCPListResourceTemplatesResult`](/openai-agents-js/openai/agents-core/interfaces/mcplistresourcetemplatesresult/)> *** ### listTools() [Section titled “listTools()”](#listtools) ```ts listTools(): Promise; ``` #### Returns [Section titled “Returns”](#returns-6) `Promise`<`object`\[]> #### Inherited from [Section titled “Inherited from”](#inherited-from-9) [`MCPServer`](/openai-agents-js/openai/agents-core/interfaces/mcpserver/).[`listTools`](/openai-agents-js/openai/agents-core/interfaces/mcpserver/#listtools) *** ### readResource() [Section titled “readResource()”](#readresource) ```ts readResource(uri): Promise; ``` #### Parameters [Section titled “Parameters”](#parameters-3) | Parameter | Type | | --------- | -------- | | `uri` | `string` | #### Returns [Section titled “Returns”](#returns-7) `Promise`<[`MCPReadResourceResult`](/openai-agents-js/openai/agents-core/interfaces/mcpreadresourceresult/)> # MCPTextResourceContent Text resource content returned by `readResource`. ## Indexable [Section titled “Indexable”](#indexable) ```ts [key: string]: unknown ``` ## Properties [Section titled “Properties”](#properties) ### mimeType? [Section titled “mimeType?”](#mimetype) ```ts optional mimeType?: string; ``` *** ### text [Section titled “text”](#text) ```ts text: string; ``` *** ### uri [Section titled “uri”](#uri) ```ts uri: string; ``` # MCPToolFilterContext Context information available to tool filter functions. ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | ------------------------------------------------------------------------------------- | | `TContext` | [`UnknownContext`](/openai-agents-js/openai/agents-core/type-aliases/unknowncontext/) | ## Properties [Section titled “Properties”](#properties) ### agent [Section titled “agent”](#agent) ```ts agent: Agent; ``` The agent requesting the tools. *** ### runContext [Section titled “runContext”](#runcontext) ```ts runContext: RunContext; ``` The current run context. *** ### serverName [Section titled “serverName”](#servername) ```ts serverName: string; ``` Name of the MCP server providing the tools. # MCPToolFilterStatic Static tool filter configuration using allow and block lists. ## Properties [Section titled “Properties”](#properties) ### allowedToolNames? [Section titled “allowedToolNames?”](#allowedtoolnames) ```ts optional allowedToolNames?: string[]; ``` Optional list of tool names to allow. *** ### blockedToolNames? [Section titled “blockedToolNames?”](#blockedtoolnames) ```ts optional blockedToolNames?: string[]; ``` Optional list of tool names to block. # MCPToolMetaContext Context information available to MCP tool meta resolver functions. ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | ------------------------------------------------------------------------------------- | | `TContext` | [`UnknownContext`](/openai-agents-js/openai/agents-core/type-aliases/unknowncontext/) | ## Properties [Section titled “Properties”](#properties) ### arguments [Section titled “arguments”](#arguments) ```ts arguments: Record | null; ``` Parsed tool arguments. *** ### runContext [Section titled “runContext”](#runcontext) ```ts runContext: RunContext; ``` The current run context. *** ### serverName [Section titled “serverName”](#servername) ```ts serverName: string; ``` Name of the MCP server. *** ### toolName [Section titled “toolName”](#toolname) ```ts toolName: string; ``` Name of the tool being invoked. # Model The base interface for calling an LLM. ## Methods [Section titled “Methods”](#methods) ### getResponse() [Section titled “getResponse()”](#getresponse) ```ts getResponse(request): Promise; ``` Get a response from the model. #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | --------- | --------------------------------------------------------------------------------- | ---------------------------------- | | `request` | [`ModelRequest`](/openai-agents-js/openai/agents-core/type-aliases/modelrequest/) | The request to get a response for. | #### Returns [Section titled “Returns”](#returns) `Promise`<[`ModelResponse`](/openai-agents-js/openai/agents-core/type-aliases/modelresponse/)> *** ### getRetryAdvice()? [Section titled “getRetryAdvice()?”](#getretryadvice) ```ts optional getRetryAdvice(args): | ModelRetryAdvice | Promise< | ModelRetryAdvice | undefined> | undefined; ``` Provide optional retry advice for a failed request. #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | --------- | ------------------------------------------------------------------------------------------------------- | | `args` | [`ModelRetryAdviceRequest`](/openai-agents-js/openai/agents-core/type-aliases/modelretryadvicerequest/) | #### Returns [Section titled “Returns”](#returns-1) \| [`ModelRetryAdvice`](/openai-agents-js/openai/agents-core/type-aliases/modelretryadvice/) | `Promise`< | [`ModelRetryAdvice`](/openai-agents-js/openai/agents-core/type-aliases/modelretryadvice/) | `undefined`> | `undefined` *** ### getStreamedResponse() [Section titled “getStreamedResponse()”](#getstreamedresponse) ```ts getStreamedResponse(request): AsyncIterable; ``` Get a streamed response from the model. #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | --------- | --------------------------------------------------------------------------------- | | `request` | [`ModelRequest`](/openai-agents-js/openai/agents-core/type-aliases/modelrequest/) | #### Returns [Section titled “Returns”](#returns-2) `AsyncIterable`<[`StreamEvent`](/openai-agents-js/openai/agents-core/type-aliases/streamevent/)> # ModelProvider The base interface for a model provider. The model provider is responsible for looking up `Model` instances by name. ## Methods [Section titled “Methods”](#methods) ### getModel() [Section titled “getModel()”](#getmodel) ```ts getModel(modelName?): | Model | Promise; ``` Get a model by name #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | ------------ | -------- | ----------------------------- | | `modelName?` | `string` | The name of the model to get. | #### Returns [Section titled “Returns”](#returns) \| [`Model`](/openai-agents-js/openai/agents-core/interfaces/model/) | `Promise`<[`Model`](/openai-agents-js/openai/agents-core/interfaces/model/)> # OpenAIResponsesCompactionAwareSession Interface representing a persistent session store for conversation history. ## Extends [Section titled “Extends”](#extends) * [`Session`](/openai-agents-js/openai/agents-core/interfaces/session/) ## Methods [Section titled “Methods”](#methods) ### addItems() [Section titled “addItems()”](#additems) ```ts addItems(items): Promise; ``` Append new items to the conversation history. #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | --------- | ---------------------------------------------------------------------------------------- | ------------------------------------ | | `items` | [`AgentInputItem`](/openai-agents-js/openai/agents-core/type-aliases/agentinputitem/)\[] | Items to add to the session history. | #### Returns [Section titled “Returns”](#returns) `Promise`<`void`> #### Inherited from [Section titled “Inherited from”](#inherited-from) [`Session`](/openai-agents-js/openai/agents-core/interfaces/session/).[`addItems`](/openai-agents-js/openai/agents-core/interfaces/session/#additems) *** ### clearSession() [Section titled “clearSession()”](#clearsession) ```ts clearSession(): Promise; ``` Remove all items that belong to the session and reset its state. #### Returns [Section titled “Returns”](#returns-1) `Promise`<`void`> #### Inherited from [Section titled “Inherited from”](#inherited-from-1) [`Session`](/openai-agents-js/openai/agents-core/interfaces/session/).[`clearSession`](/openai-agents-js/openai/agents-core/interfaces/session/#clearsession) *** ### getItems() [Section titled “getItems()”](#getitems) ```ts getItems(limit?): Promise; ``` Retrieve items from the conversation history. #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | Description | | --------- | -------- | --------------------------------------------------------------------------------------------------------------------------- | | `limit?` | `number` | The maximum number of items to return. When provided the most recent limit items should be returned in chronological order. | #### Returns [Section titled “Returns”](#returns-2) `Promise`<[`AgentInputItem`](/openai-agents-js/openai/agents-core/type-aliases/agentinputitem/)\[]> #### Inherited from [Section titled “Inherited from”](#inherited-from-2) [`Session`](/openai-agents-js/openai/agents-core/interfaces/session/).[`getItems`](/openai-agents-js/openai/agents-core/interfaces/session/#getitems) *** ### getSessionId() [Section titled “getSessionId()”](#getsessionid) ```ts getSessionId(): Promise; ``` Ensure and return the identifier for this session. #### Returns [Section titled “Returns”](#returns-3) `Promise`<`string`> #### Inherited from [Section titled “Inherited from”](#inherited-from-3) [`Session`](/openai-agents-js/openai/agents-core/interfaces/session/).[`getSessionId`](/openai-agents-js/openai/agents-core/interfaces/session/#getsessionid) *** ### popItem() [Section titled “popItem()”](#popitem) ```ts popItem(): Promise< | AgentInputItem | undefined>; ``` Remove and return the most recent item from the conversation history if it exists. #### Returns [Section titled “Returns”](#returns-4) `Promise`< | [`AgentInputItem`](/openai-agents-js/openai/agents-core/type-aliases/agentinputitem/) | `undefined`> #### Inherited from [Section titled “Inherited from”](#inherited-from-4) [`Session`](/openai-agents-js/openai/agents-core/interfaces/session/).[`popItem`](/openai-agents-js/openai/agents-core/interfaces/session/#popitem) *** ### prepareHistoryItemForModelInput()? [Section titled “prepareHistoryItemForModelInput()?”](#preparehistoryitemformodelinput) ```ts optional prepareHistoryItemForModelInput(item): AgentInputItem; ``` Optionally rewrite a stored history item before it is sent back to the model. Session implementations can use this to strip provider-managed replay metadata while preserving their public `getItems()` shape for UI and deletion workflows. #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | --------- | ------------------------------------------------------------------------------------- | | `item` | [`AgentInputItem`](/openai-agents-js/openai/agents-core/type-aliases/agentinputitem/) | #### Returns [Section titled “Returns”](#returns-5) [`AgentInputItem`](/openai-agents-js/openai/agents-core/type-aliases/agentinputitem/) #### Inherited from [Section titled “Inherited from”](#inherited-from-5) [`Session`](/openai-agents-js/openai/agents-core/interfaces/session/).[`prepareHistoryItemForModelInput`](/openai-agents-js/openai/agents-core/interfaces/session/#preparehistoryitemformodelinput) *** ### preserveReasoningItemIdsForPersistence()? [Section titled “preserveReasoningItemIdsForPersistence()?”](#preservereasoningitemidsforpersistence) ```ts optional preserveReasoningItemIdsForPersistence(): boolean; ``` Optionally preserve reasoning item IDs when persisting generated output. Some remote session stores require provider-assigned reasoning identities to accept stored reasoning items, even when model replay should omit those IDs. #### Returns [Section titled “Returns”](#returns-6) `boolean` #### Inherited from [Section titled “Inherited from”](#inherited-from-6) [`Session`](/openai-agents-js/openai/agents-core/interfaces/session/).[`preserveReasoningItemIdsForPersistence`](/openai-agents-js/openai/agents-core/interfaces/session/#preservereasoningitemidsforpersistence) *** ### runCompaction() [Section titled “runCompaction()”](#runcompaction) ```ts runCompaction(args?): | OpenAIResponsesCompactionResult | Promise< | OpenAIResponsesCompactionResult | null> | null; ``` Invoked by the runner after it persists a completed turn into the session. Implementations may decide to call `responses.compact` (or an equivalent API) and replace the stored history. This hook is best-effort. Implementations should consider handling transient failures and deciding whether to retry or skip compaction for the current turn. #### Parameters [Section titled “Parameters”](#parameters-3) | Parameter | Type | | --------- | ------------------------------------------------------------------------------------------------------------------- | | `args?` | [`OpenAIResponsesCompactionArgs`](/openai-agents-js/openai/agents-core/type-aliases/openairesponsescompactionargs/) | #### Returns [Section titled “Returns”](#returns-7) \| [`OpenAIResponsesCompactionResult`](/openai-agents-js/openai/agents-core/type-aliases/openairesponsescompactionresult/) | `Promise`< | [`OpenAIResponsesCompactionResult`](/openai-agents-js/openai/agents-core/type-aliases/openairesponsescompactionresult/) | `null`> | `null` # OutputGuardrail A guardrail that checks the output of the agent. ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | ----------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------- | | `TOutput` *extends* [`AgentOutputType`](/openai-agents-js/openai/agents-core/type-aliases/agentoutputtype/) | [`TextOutput`](/openai-agents-js/openai/agents-core/type-aliases/textoutput/) | | `TContext` | [`UnknownContext`](/openai-agents-js/openai/agents-core/type-aliases/unknowncontext/) | ## Properties [Section titled “Properties”](#properties) ### execute [Section titled “execute”](#execute) ```ts execute: OutputGuardrailFunction; ``` The function that performs the guardrail check. *** ### name [Section titled “name”](#name) ```ts name: string; ``` The name of the guardrail. # OutputGuardrailDefinition Definition of an output guardrail. ## Extends [Section titled “Extends”](#extends) * [`OutputGuardrailMetadata`](/openai-agents-js/openai/agents-core/interfaces/outputguardrailmetadata/) ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | ----------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------- | | `TMeta` | [`OutputGuardrailMetadata`](/openai-agents-js/openai/agents-core/interfaces/outputguardrailmetadata/) | | `TOutput` *extends* [`AgentOutputType`](/openai-agents-js/openai/agents-core/type-aliases/agentoutputtype/) | [`TextOutput`](/openai-agents-js/openai/agents-core/type-aliases/textoutput/) | | `TContext` | [`UnknownContext`](/openai-agents-js/openai/agents-core/type-aliases/unknowncontext/) | ## Properties [Section titled “Properties”](#properties) ### guardrailFunction [Section titled “guardrailFunction”](#guardrailfunction) ```ts guardrailFunction: OutputGuardrailFunction; ``` *** ### name [Section titled “name”](#name) ```ts name: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from) [`OutputGuardrailMetadata`](/openai-agents-js/openai/agents-core/interfaces/outputguardrailmetadata/).[`name`](/openai-agents-js/openai/agents-core/interfaces/outputguardrailmetadata/#name) *** ### type [Section titled “type”](#type) ```ts type: "output"; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-1) [`OutputGuardrailMetadata`](/openai-agents-js/openai/agents-core/interfaces/outputguardrailmetadata/).[`type`](/openai-agents-js/openai/agents-core/interfaces/outputguardrailmetadata/#type) ## Methods [Section titled “Methods”](#methods) ### run() [Section titled “run()”](#run) ```ts run(args): Promise>; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ------------------------------------------------------------------------------------------------------------------------------------ | | `args` | [`OutputGuardrailFunctionArgs`](/openai-agents-js/openai/agents-core/interfaces/outputguardrailfunctionargs/)<`TContext`, `TOutput`> | #### Returns [Section titled “Returns”](#returns) `Promise`<[`OutputGuardrailResult`](/openai-agents-js/openai/agents-core/interfaces/outputguardrailresult/)<`TMeta`, `TOutput`>> # OutputGuardrailFunctionArgs Arguments for an output guardrail function. ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | ----------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------- | | `TContext` | [`UnknownContext`](/openai-agents-js/openai/agents-core/type-aliases/unknowncontext/) | | `TOutput` *extends* [`AgentOutputType`](/openai-agents-js/openai/agents-core/type-aliases/agentoutputtype/) | [`TextOutput`](/openai-agents-js/openai/agents-core/type-aliases/textoutput/) | ## Properties [Section titled “Properties”](#properties) ### agent [Section titled “agent”](#agent) ```ts agent: Agent; ``` *** ### agentOutput [Section titled “agentOutput”](#agentoutput) ```ts agentOutput: ResolvedAgentOutput; ``` *** ### context [Section titled “context”](#context) ```ts context: RunContext; ``` *** ### details? [Section titled “details?”](#details) ```ts optional details?: object; ``` Additional details about the agent output. | Name | Type | Description | | ---------------- | ------------------------------------------------------------------------------------------ | ------------------------------------------------------------------ | | `modelResponse?` | [`ModelResponse`](/openai-agents-js/openai/agents-core/type-aliases/modelresponse/) | Model response associated with the output if available. | | `output?` | [`AgentOutputItem`](/openai-agents-js/openai/agents-core/type-aliases/agentoutputitem/)\[] | Model output items generated during the run (excluding approvals). | # OutputGuardrailMetadata Metadata for an output guardrail. ## Extended by [Section titled “Extended by”](#extended-by) * [`OutputGuardrailDefinition`](/openai-agents-js/openai/agents-core/interfaces/outputguardraildefinition/) ## Properties [Section titled “Properties”](#properties) ### name [Section titled “name”](#name) ```ts name: string; ``` *** ### type [Section titled “type”](#type) ```ts type: "output"; ``` # OutputGuardrailResult The result of an output guardrail execution. ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | ----------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------- | | `TMeta` | [`OutputGuardrailMetadata`](/openai-agents-js/openai/agents-core/interfaces/outputguardrailmetadata/) | | `TOutput` *extends* [`AgentOutputType`](/openai-agents-js/openai/agents-core/type-aliases/agentoutputtype/) | [`TextOutput`](/openai-agents-js/openai/agents-core/type-aliases/textoutput/) | ## Properties [Section titled “Properties”](#properties) ### agent [Section titled “agent”](#agent) ```ts agent: Agent; ``` The agent that ran. *** ### agentOutput [Section titled “agentOutput”](#agentoutput) ```ts agentOutput: ResolvedAgentOutput; ``` The output of the agent that ran. *** ### guardrail [Section titled “guardrail”](#guardrail) ```ts guardrail: TMeta; ``` The metadata of the guardrail. *** ### output [Section titled “output”](#output) ```ts output: GuardrailFunctionOutput; ``` The output of the guardrail. # Session Interface representing a persistent session store for conversation history. ## Extended by [Section titled “Extended by”](#extended-by) * [`SessionHistoryRewriteAwareSession`](/openai-agents-js/openai/agents-core/interfaces/sessionhistoryrewriteawaresession/) * [`OpenAIResponsesCompactionAwareSession`](/openai-agents-js/openai/agents-core/interfaces/openairesponsescompactionawaresession/) ## Methods [Section titled “Methods”](#methods) ### addItems() [Section titled “addItems()”](#additems) ```ts addItems(items): Promise; ``` Append new items to the conversation history. #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | --------- | ---------------------------------------------------------------------------------------- | ------------------------------------ | | `items` | [`AgentInputItem`](/openai-agents-js/openai/agents-core/type-aliases/agentinputitem/)\[] | Items to add to the session history. | #### Returns [Section titled “Returns”](#returns) `Promise`<`void`> *** ### clearSession() [Section titled “clearSession()”](#clearsession) ```ts clearSession(): Promise; ``` Remove all items that belong to the session and reset its state. #### Returns [Section titled “Returns”](#returns-1) `Promise`<`void`> *** ### getItems() [Section titled “getItems()”](#getitems) ```ts getItems(limit?): Promise; ``` Retrieve items from the conversation history. #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | Description | | --------- | -------- | --------------------------------------------------------------------------------------------------------------------------- | | `limit?` | `number` | The maximum number of items to return. When provided the most recent limit items should be returned in chronological order. | #### Returns [Section titled “Returns”](#returns-2) `Promise`<[`AgentInputItem`](/openai-agents-js/openai/agents-core/type-aliases/agentinputitem/)\[]> *** ### getSessionId() [Section titled “getSessionId()”](#getsessionid) ```ts getSessionId(): Promise; ``` Ensure and return the identifier for this session. #### Returns [Section titled “Returns”](#returns-3) `Promise`<`string`> *** ### popItem() [Section titled “popItem()”](#popitem) ```ts popItem(): Promise< | AgentInputItem | undefined>; ``` Remove and return the most recent item from the conversation history if it exists. #### Returns [Section titled “Returns”](#returns-4) `Promise`< | [`AgentInputItem`](/openai-agents-js/openai/agents-core/type-aliases/agentinputitem/) | `undefined`> *** ### prepareHistoryItemForModelInput()? [Section titled “prepareHistoryItemForModelInput()?”](#preparehistoryitemformodelinput) ```ts optional prepareHistoryItemForModelInput(item): AgentInputItem; ``` Optionally rewrite a stored history item before it is sent back to the model. Session implementations can use this to strip provider-managed replay metadata while preserving their public `getItems()` shape for UI and deletion workflows. #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | --------- | ------------------------------------------------------------------------------------- | | `item` | [`AgentInputItem`](/openai-agents-js/openai/agents-core/type-aliases/agentinputitem/) | #### Returns [Section titled “Returns”](#returns-5) [`AgentInputItem`](/openai-agents-js/openai/agents-core/type-aliases/agentinputitem/) *** ### preserveReasoningItemIdsForPersistence()? [Section titled “preserveReasoningItemIdsForPersistence()?”](#preservereasoningitemidsforpersistence) ```ts optional preserveReasoningItemIdsForPersistence(): boolean; ``` Optionally preserve reasoning item IDs when persisting generated output. Some remote session stores require provider-assigned reasoning identities to accept stored reasoning items, even when model replay should omit those IDs. #### Returns [Section titled “Returns”](#returns-6) `boolean` # SessionHistoryRewriteAwareSession Interface representing a persistent session store for conversation history. ## Extends [Section titled “Extends”](#extends) * [`Session`](/openai-agents-js/openai/agents-core/interfaces/session/) ## Methods [Section titled “Methods”](#methods) ### addItems() [Section titled “addItems()”](#additems) ```ts addItems(items): Promise; ``` Append new items to the conversation history. #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | --------- | ---------------------------------------------------------------------------------------- | ------------------------------------ | | `items` | [`AgentInputItem`](/openai-agents-js/openai/agents-core/type-aliases/agentinputitem/)\[] | Items to add to the session history. | #### Returns [Section titled “Returns”](#returns) `Promise`<`void`> #### Inherited from [Section titled “Inherited from”](#inherited-from) [`Session`](/openai-agents-js/openai/agents-core/interfaces/session/).[`addItems`](/openai-agents-js/openai/agents-core/interfaces/session/#additems) *** ### applyHistoryMutations() [Section titled “applyHistoryMutations()”](#applyhistorymutations) ```ts applyHistoryMutations(args): void | Promise; ``` #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | --------- | ----------------------------------------------------------------------------------------------------------- | | `args` | [`SessionHistoryRewriteArgs`](/openai-agents-js/openai/agents-core/type-aliases/sessionhistoryrewriteargs/) | #### Returns [Section titled “Returns”](#returns-1) `void` | `Promise`<`void`> *** ### clearSession() [Section titled “clearSession()”](#clearsession) ```ts clearSession(): Promise; ``` Remove all items that belong to the session and reset its state. #### Returns [Section titled “Returns”](#returns-2) `Promise`<`void`> #### Inherited from [Section titled “Inherited from”](#inherited-from-1) [`Session`](/openai-agents-js/openai/agents-core/interfaces/session/).[`clearSession`](/openai-agents-js/openai/agents-core/interfaces/session/#clearsession) *** ### getItems() [Section titled “getItems()”](#getitems) ```ts getItems(limit?): Promise; ``` Retrieve items from the conversation history. #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | Description | | --------- | -------- | --------------------------------------------------------------------------------------------------------------------------- | | `limit?` | `number` | The maximum number of items to return. When provided the most recent limit items should be returned in chronological order. | #### Returns [Section titled “Returns”](#returns-3) `Promise`<[`AgentInputItem`](/openai-agents-js/openai/agents-core/type-aliases/agentinputitem/)\[]> #### Inherited from [Section titled “Inherited from”](#inherited-from-2) [`Session`](/openai-agents-js/openai/agents-core/interfaces/session/).[`getItems`](/openai-agents-js/openai/agents-core/interfaces/session/#getitems) *** ### getSessionId() [Section titled “getSessionId()”](#getsessionid) ```ts getSessionId(): Promise; ``` Ensure and return the identifier for this session. #### Returns [Section titled “Returns”](#returns-4) `Promise`<`string`> #### Inherited from [Section titled “Inherited from”](#inherited-from-3) [`Session`](/openai-agents-js/openai/agents-core/interfaces/session/).[`getSessionId`](/openai-agents-js/openai/agents-core/interfaces/session/#getsessionid) *** ### popItem() [Section titled “popItem()”](#popitem) ```ts popItem(): Promise< | AgentInputItem | undefined>; ``` Remove and return the most recent item from the conversation history if it exists. #### Returns [Section titled “Returns”](#returns-5) `Promise`< | [`AgentInputItem`](/openai-agents-js/openai/agents-core/type-aliases/agentinputitem/) | `undefined`> #### Inherited from [Section titled “Inherited from”](#inherited-from-4) [`Session`](/openai-agents-js/openai/agents-core/interfaces/session/).[`popItem`](/openai-agents-js/openai/agents-core/interfaces/session/#popitem) *** ### prepareHistoryItemForModelInput()? [Section titled “prepareHistoryItemForModelInput()?”](#preparehistoryitemformodelinput) ```ts optional prepareHistoryItemForModelInput(item): AgentInputItem; ``` Optionally rewrite a stored history item before it is sent back to the model. Session implementations can use this to strip provider-managed replay metadata while preserving their public `getItems()` shape for UI and deletion workflows. #### Parameters [Section titled “Parameters”](#parameters-3) | Parameter | Type | | --------- | ------------------------------------------------------------------------------------- | | `item` | [`AgentInputItem`](/openai-agents-js/openai/agents-core/type-aliases/agentinputitem/) | #### Returns [Section titled “Returns”](#returns-6) [`AgentInputItem`](/openai-agents-js/openai/agents-core/type-aliases/agentinputitem/) #### Inherited from [Section titled “Inherited from”](#inherited-from-5) [`Session`](/openai-agents-js/openai/agents-core/interfaces/session/).[`prepareHistoryItemForModelInput`](/openai-agents-js/openai/agents-core/interfaces/session/#preparehistoryitemformodelinput) *** ### preserveReasoningItemIdsForPersistence()? [Section titled “preserveReasoningItemIdsForPersistence()?”](#preservereasoningitemidsforpersistence) ```ts optional preserveReasoningItemIdsForPersistence(): boolean; ``` Optionally preserve reasoning item IDs when persisting generated output. Some remote session stores require provider-assigned reasoning identities to accept stored reasoning items, even when model replay should omit those IDs. #### Returns [Section titled “Returns”](#returns-7) `boolean` #### Inherited from [Section titled “Inherited from”](#inherited-from-6) [`Session`](/openai-agents-js/openai/agents-core/interfaces/session/).[`preserveReasoningItemIdsForPersistence`](/openai-agents-js/openai/agents-core/interfaces/session/#preservereasoningitemidsforpersistence) # Shell Executes shell commands on behalf of the agent. ## Methods [Section titled “Methods”](#methods) ### run() [Section titled “run()”](#run) ```ts run(action): Promise; ``` Runs the given action and returns the resulting output. #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ------------------------- | ---------------------------------------------------------------------------------- | | `action` | { `commands`: `string`\[]; `maxOutputLength?`: `number`; `timeoutMs?`: `number`; } | | `action.commands` | `string`\[] | | `action.maxOutputLength?` | `number` | | `action.timeoutMs?` | `number` | #### Returns [Section titled “Returns”](#returns) `Promise`<[`ShellResult`](/openai-agents-js/openai/agents-core/type-aliases/shellresult/)> # ToolGuardrailFunctionOutput The output of a tool guardrail function. `behavior` drives runner control flow; `outputInfo` is optional, structured metadata for tracing or debugging. ## Properties [Section titled “Properties”](#properties) ### behavior [Section titled “behavior”](#behavior) ```ts behavior: ToolGuardrailBehavior; ``` The behavior the runner should take in response to this guardrail. *** ### outputInfo? [Section titled “outputInfo?”](#outputinfo) ```ts optional outputInfo?: any; ``` Additional data about the guardrail evaluation. # ToolGuardrailMetadata ## Properties [Section titled “Properties”](#properties) ### name [Section titled “name”](#name) ```ts name: string; ``` *** ### type [Section titled “type”](#type) ```ts type: "tool_input" | "tool_output"; ``` # ToolInputGuardrailData Input data passed to a tool input guardrail function. ## Extended by [Section titled “Extended by”](#extended-by) * [`ToolOutputGuardrailData`](/openai-agents-js/openai/agents-core/interfaces/tooloutputguardraildata/) ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | ------------------------------------------------------------------------------------- | | `TContext` | [`UnknownContext`](/openai-agents-js/openai/agents-core/type-aliases/unknowncontext/) | ## Properties [Section titled “Properties”](#properties) ### agent [Section titled “agent”](#agent) ```ts agent: Agent; ``` *** ### context [Section titled “context”](#context) ```ts context: RunContext; ``` *** ### toolCall [Section titled “toolCall”](#toolcall) ```ts toolCall: object; ``` | Name | Type | Description | | --------------- | -------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `arguments` | `string` | The arguments of the function call. | | `callId` | `string` | The ID of the tool call. Required to match up the respective tool call result. | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `name` | `string` | The name of the function. | | `namespace?` | `string` | Optional namespace used to qualify the function name for tool search. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status?` | `"in_progress"` \| `"completed"` \| `"incomplete"` | The status of the function call. | | `type` | `"function_call"` | ‐ | # ToolInputGuardrailDefinition ## Extends [Section titled “Extends”](#extends) * `ToolGuardrailBase` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | ------------------------------------------------------------------------------------- | | `TContext` | [`UnknownContext`](/openai-agents-js/openai/agents-core/type-aliases/unknowncontext/) | ## Properties [Section titled “Properties”](#properties) ### name [Section titled “name”](#name) ```ts name: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from) ```ts ToolGuardrailBase.name ``` *** ### run [Section titled “run”](#run) ```ts run: ToolInputGuardrailFunction; ``` *** ### type [Section titled “type”](#type) ```ts type: "tool_input"; ``` # ToolInputGuardrailResult ## Properties [Section titled “Properties”](#properties) ### guardrail [Section titled “guardrail”](#guardrail) ```ts guardrail: ToolGuardrailMetadata & object; ``` #### Type Declaration [Section titled “Type Declaration”](#type-declaration) | Name | Type | | ------ | -------------- | | `type` | `"tool_input"` | *** ### output [Section titled “output”](#output) ```ts output: ToolGuardrailFunctionOutput; ``` # ToolOutputGuardrailData Input data passed to a tool output guardrail function. ## Extends [Section titled “Extends”](#extends) * [`ToolInputGuardrailData`](/openai-agents-js/openai/agents-core/interfaces/toolinputguardraildata/)<`TContext`> ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | ------------------------------------------------------------------------------------- | | `TContext` | [`UnknownContext`](/openai-agents-js/openai/agents-core/type-aliases/unknowncontext/) | ## Properties [Section titled “Properties”](#properties) ### agent [Section titled “agent”](#agent) ```ts agent: Agent; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from) [`ToolInputGuardrailData`](/openai-agents-js/openai/agents-core/interfaces/toolinputguardraildata/).[`agent`](/openai-agents-js/openai/agents-core/interfaces/toolinputguardraildata/#agent) *** ### context [Section titled “context”](#context) ```ts context: RunContext; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-1) [`ToolInputGuardrailData`](/openai-agents-js/openai/agents-core/interfaces/toolinputguardraildata/).[`context`](/openai-agents-js/openai/agents-core/interfaces/toolinputguardraildata/#context) *** ### output [Section titled “output”](#output) ```ts output: unknown; ``` *** ### toolCall [Section titled “toolCall”](#toolcall) ```ts toolCall: object; ``` | Name | Type | Description | | --------------- | -------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | `arguments` | `string` | The arguments of the function call. | | `callId` | `string` | The ID of the tool call. Required to match up the respective tool call result. | | `id?` | `string` | An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. | | `name` | `string` | The name of the function. | | `namespace?` | `string` | Optional namespace used to qualify the function name for tool search. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `status?` | `"in_progress"` \| `"completed"` \| `"incomplete"` | The status of the function call. | | `type` | `"function_call"` | ‐ | #### Inherited from [Section titled “Inherited from”](#inherited-from-2) [`ToolInputGuardrailData`](/openai-agents-js/openai/agents-core/interfaces/toolinputguardraildata/).[`toolCall`](/openai-agents-js/openai/agents-core/interfaces/toolinputguardraildata/#toolcall) # ToolOutputGuardrailDefinition ## Extends [Section titled “Extends”](#extends) * `ToolGuardrailBase` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | ------------------------------------------------------------------------------------- | | `TContext` | [`UnknownContext`](/openai-agents-js/openai/agents-core/type-aliases/unknowncontext/) | ## Properties [Section titled “Properties”](#properties) ### name [Section titled “name”](#name) ```ts name: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from) ```ts ToolGuardrailBase.name ``` *** ### run [Section titled “run”](#run) ```ts run: ToolOutputGuardrailFunction; ``` *** ### type [Section titled “type”](#type) ```ts type: "tool_output"; ``` # ToolOutputGuardrailResult ## Properties [Section titled “Properties”](#properties) ### guardrail [Section titled “guardrail”](#guardrail) ```ts guardrail: ToolGuardrailMetadata & object; ``` #### Type Declaration [Section titled “Type Declaration”](#type-declaration) | Name | Type | | ------ | --------------- | | `type` | `"tool_output"` | *** ### output [Section titled “output”](#output) ```ts output: ToolGuardrailFunctionOutput; ``` # TracingExporter Exports traces and spans. For example, could log them or send them to a backend. ## Methods [Section titled “Methods”](#methods) ### export() [Section titled “export()”](#export) ```ts export(items, signal?): Promise; ``` Export the given traces and spans #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | --------- | ----------------------------------------------------------------------------- | ------------------------------ | | `items` | (`Span` \| [`Trace`](/openai-agents-js/openai/agents-core/classes/trace/))\[] | The traces and spans to export | | `signal?` | `AbortSignal` | ‐ | #### Returns [Section titled “Returns”](#returns) `Promise`<`void`> # TracingProcessor Interface for processing traces ## Methods [Section titled “Methods”](#methods) ### forceFlush() [Section titled “forceFlush()”](#forceflush) ```ts forceFlush(): Promise; ``` Called when a trace is being flushed #### Returns [Section titled “Returns”](#returns) `Promise`<`void`> *** ### onSpanEnd() [Section titled “onSpanEnd()”](#onspanend) ```ts onSpanEnd(span): Promise; ``` Called when a span is ended #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ------ | | `span` | `Span` | #### Returns [Section titled “Returns”](#returns-1) `Promise`<`void`> *** ### onSpanStart() [Section titled “onSpanStart()”](#onspanstart) ```ts onSpanStart(span): Promise; ``` Called when a span is started #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | --------- | ------ | | `span` | `Span` | #### Returns [Section titled “Returns”](#returns-2) `Promise`<`void`> *** ### onTraceEnd() [Section titled “onTraceEnd()”](#ontraceend) ```ts onTraceEnd(trace): Promise; ``` Called when a trace is ended #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | --------- | -------------------------------------------------------------- | | `trace` | [`Trace`](/openai-agents-js/openai/agents-core/classes/trace/) | #### Returns [Section titled “Returns”](#returns-3) `Promise`<`void`> *** ### onTraceStart() [Section titled “onTraceStart()”](#ontracestart) ```ts onTraceStart(trace): Promise; ``` Called when a trace is started #### Parameters [Section titled “Parameters”](#parameters-3) | Parameter | Type | | --------- | -------------------------------------------------------------- | | `trace` | [`Trace`](/openai-agents-js/openai/agents-core/classes/trace/) | #### Returns [Section titled “Returns”](#returns-4) `Promise`<`void`> *** ### shutdown() [Section titled “shutdown()”](#shutdown) ```ts shutdown(timeout?): Promise; ``` Called when the trace processor is shutting down #### Parameters [Section titled “Parameters”](#parameters-4) | Parameter | Type | | ---------- | -------- | | `timeout?` | `number` | #### Returns [Section titled “Returns”](#returns-5) `Promise`<`void`> *** ### start()? [Section titled “start()?”](#start) ```ts optional start(): void; ``` Called when the trace processor should start processing traces. Only available if the processor is performing tasks like exporting traces in a loop to start the loop #### Returns [Section titled “Returns”](#returns-6) `void` # ApplyPatchOperationCreateFile ```ts type ApplyPatchOperationCreateFile = object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### diff [Section titled “diff”](#diff) ```ts diff: string; ``` ### path [Section titled “path”](#path) ```ts path: string; ``` ### type [Section titled “type”](#type) ```ts type: "create_file"; ``` # ApplyPatchOperationDeleteFile ```ts type ApplyPatchOperationDeleteFile = object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### path [Section titled “path”](#path) ```ts path: string; ``` ### type [Section titled “type”](#type) ```ts type: "delete_file"; ``` # ApplyPatchOperationUpdateFile ```ts type ApplyPatchOperationUpdateFile = object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### diff [Section titled “diff”](#diff) ```ts diff: string; ``` ### moveTo? [Section titled “moveTo?”](#moveto) ```ts optional moveTo?: string; ``` ### path [Section titled “path”](#path) ```ts path: string; ``` ### type [Section titled “type”](#type) ```ts type: "update_file"; ``` # AssistantContent ```ts type AssistantContent = | { providerData?: Record; refusal: string; type: "refusal"; } | { providerData?: Record; text: string; type: "output_text"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; } | { image: string; providerData?: Record; type: "image"; }; ``` ## Union Members [Section titled “Union Members”](#union-members) ### Type Literal [Section titled “Type Literal”](#type-literal) ```ts { providerData?: Record; refusal: string; type: "refusal"; } ``` #### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. #### refusal [Section titled “refusal”](#refusal) ```ts refusal: string; ``` The refusal explanation from the model. #### type [Section titled “type”](#type) ```ts type: "refusal"; ``` *** ### Type Literal [Section titled “Type Literal”](#type-literal-1) ```ts { providerData?: Record; text: string; type: "output_text"; } ``` #### providerData? [Section titled “providerData?”](#providerdata-1) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. #### text [Section titled “text”](#text) ```ts text: string; ``` The text output from the model. #### type [Section titled “type”](#type-1) ```ts type: "output_text"; ``` *** ### Type Literal [Section titled “Type Literal”](#type-literal-2) ```ts { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; } ``` #### audio [Section titled “audio”](#audio) ```ts audio: | string | { id: string; }; ``` The audio input to the model. Could be base64 encoded audio data or an object with a file ID. #### format? [Section titled “format?”](#format) ```ts optional format?: string | null; ``` The format of the audio. #### providerData? [Section titled “providerData?”](#providerdata-2) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. #### transcript? [Section titled “transcript?”](#transcript) ```ts optional transcript?: string | null; ``` The transcript of the audio. #### type [Section titled “type”](#type-2) ```ts type: "audio"; ``` *** ### Type Literal [Section titled “Type Literal”](#type-literal-3) ```ts { image: string; providerData?: Record; type: "image"; } ``` #### image [Section titled “image”](#image) ```ts image: string; ``` The image input to the model. Could be base64 encoded image data or an object with a file ID. #### providerData? [Section titled “providerData?”](#providerdata-3) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. #### type [Section titled “type”](#type-3) ```ts type: "image"; ``` # AudioContent ```ts type AudioContent = object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### audio [Section titled “audio”](#audio) ```ts audio: | string | { id: string; }; ``` The audio input to the model. Could be base64 encoded audio data or an object with a file ID. ### format? [Section titled “format?”](#format) ```ts optional format?: string | null; ``` The format of the audio. ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. ### transcript? [Section titled “transcript?”](#transcript) ```ts optional transcript?: string | null; ``` The transcript of the audio. ### type [Section titled “type”](#type) ```ts type: "audio"; ``` # CompactionItem ```ts type CompactionItem = object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### created\_by? [Section titled “created\_by?”](#created_by) ```ts optional created_by?: string; ``` Identifier for the generator of this compaction item. ### encrypted\_content [Section titled “encrypted\_content”](#encrypted_content) ```ts encrypted_content: string; ``` Encrypted payload returned by the compaction endpoint. ### id? [Section titled “id?”](#id) ```ts optional id?: string; ``` Identifier for the compaction item. ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. ### type [Section titled “type”](#type) ```ts type: "compaction"; ``` # ComputerAction ```ts type ComputerAction = | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; }; ``` # ComputerToolOutput ```ts type ComputerToolOutput = object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### data [Section titled “data”](#data) ```ts data: string; ``` A base64 encoded image data or a URL representing the screenshot. ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. ### type [Section titled “type”](#type) ```ts type: "computer_screenshot"; ``` # ImageContent ```ts type ImageContent = object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### image [Section titled “image”](#image) ```ts image: string; ``` The image input to the model. Could be base64 encoded image data or an object with a file ID. ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. ### type [Section titled “type”](#type) ```ts type: "image"; ``` # InputFile ```ts type InputFile = object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### file? [Section titled “file?”](#file) ```ts optional file?: | string | { id: string; } | { url: string; }; ``` The file input to the model. Could be raw data, a URL, or an OpenAI file ID. When passing a string, it is interpreted as inline data or a URL; use `{ id }` for file IDs. ### filename? [Section titled “filename?”](#filename) ```ts optional filename?: string; ``` Optional filename metadata when uploading file data inline. ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. ### type [Section titled “type”](#type) ```ts type: "input_file"; ``` # InputImage ```ts type InputImage = object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### detail? [Section titled “detail?”](#detail) ```ts optional detail?: string; ``` Controls the level of detail requested for image understanding tasks. Future models may add new values, therefore this accepts any string. ### image? [Section titled “image?”](#image) ```ts optional image?: | string | { id: string; }; ``` The image input to the model. Could be provided inline (`image`), as a URL, or by reference to a previously uploaded OpenAI file. ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. ### type [Section titled “type”](#type) ```ts type: "input_image"; ``` # InputText ```ts type InputText = object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. ### text [Section titled “text”](#text) ```ts text: string; ``` A text input for example a message from a user ### type [Section titled “type”](#type) ```ts type: "input_text"; ``` # ItemBase ```ts type ItemBase = object; ``` Every item has a shared of shared item data including an optional ID. ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### id? [Section titled “id?”](#id) ```ts optional id?: string; ``` An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. # MessageItem ```ts type MessageItem = | { content: ( | { providerData?: Record; refusal: string; type: "refusal"; } | { providerData?: Record; text: string; type: "output_text"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; } | { image: string; providerData?: Record; type: "image"; })[]; id?: string; providerData?: Record; role: "assistant"; status: "in_progress" | "completed" | "incomplete"; type?: "message"; } | { content: | string | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; })[]; id?: string; providerData?: Record; role: "user"; type?: "message"; } | { content: string; id?: string; providerData?: Record; role: "system"; type?: "message"; }; ``` ## Union Members [Section titled “Union Members”](#union-members) ### Type Literal [Section titled “Type Literal”](#type-literal) ```ts { content: ( | { providerData?: Record; refusal: string; type: "refusal"; } | { providerData?: Record; text: string; type: "output_text"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; } | { image: string; providerData?: Record; type: "image"; })[]; id?: string; providerData?: Record; role: "assistant"; status: "in_progress" | "completed" | "incomplete"; type?: "message"; } ``` #### content [Section titled “content”](#content) ```ts content: ( | { providerData?: Record; refusal: string; type: "refusal"; } | { providerData?: Record; text: string; type: "output_text"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; } | { image: string; providerData?: Record; type: "image"; })[]; ``` The content of the message. #### id? [Section titled “id?”](#id) ```ts optional id?: string; ``` An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. #### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. #### role [Section titled “role”](#role) ```ts role: "assistant"; ``` Representing a message from the assistant (i.e. the model) #### status [Section titled “status”](#status) ```ts status: "in_progress" | "completed" | "incomplete"; ``` The status of the message. #### type? [Section titled “type?”](#type) ```ts optional type?: "message"; ``` Any item without a type is treated as a message *** ### Type Literal [Section titled “Type Literal”](#type-literal-1) ```ts { content: | string | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; })[]; id?: string; providerData?: Record; role: "user"; type?: "message"; } ``` #### content [Section titled “content”](#content-1) ```ts content: | string | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; })[]; ``` The content of the message. #### id? [Section titled “id?”](#id-1) ```ts optional id?: string; ``` An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. #### providerData? [Section titled “providerData?”](#providerdata-1) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. #### role [Section titled “role”](#role-1) ```ts role: "user"; ``` Representing a message from the user #### type? [Section titled “type?”](#type-1) ```ts optional type?: "message"; ``` Any item without a type is treated as a message *** ### Type Literal [Section titled “Type Literal”](#type-literal-2) ```ts { content: string; id?: string; providerData?: Record; role: "system"; type?: "message"; } ``` #### content [Section titled “content”](#content-2) ```ts content: string; ``` The content of the message. #### id? [Section titled “id?”](#id-2) ```ts optional id?: string; ``` An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. #### providerData? [Section titled “providerData?”](#providerdata-2) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. #### role [Section titled “role”](#role-2) ```ts role: "system"; ``` Representing a system message to the user #### type? [Section titled “type?”](#type-2) ```ts optional type?: "message"; ``` Any item without a type is treated as a message # ModelItem ```ts type ModelItem = | { content: ( | { providerData?: Record; refusal: string; type: "refusal"; } | { providerData?: Record; text: string; type: "output_text"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; } | { image: string; providerData?: Record; type: "image"; })[]; id?: string; providerData?: Record; role: "assistant"; status: "in_progress" | "completed" | "incomplete"; type?: "message"; } | { content: | string | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; })[]; id?: string; providerData?: Record; role: "user"; type?: "message"; } | { content: string; id?: string; providerData?: Record; role: "system"; type?: "message"; } | { arguments?: string; id?: string; name: string; output?: string; providerData?: Record; status?: string; type: "hosted_tool_call"; } | { arguments: string; callId: string; id?: string; name: string; namespace?: string; providerData?: Record; status?: "in_progress" | "completed" | "incomplete"; type: "function_call"; } | { arguments: unknown; call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; type: "tool_search_call"; } | { call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; tools: Record[]; type: "tool_search_output"; } | { callId: string; id?: string; name: string; namespace?: string; output: | string | { providerData?: Record; text: string; type: "text"; } | { detail?: "low" | "high" | "auto" | string & object; image?: | string | { data: string | Uint8Array; mediaType?: string; } | { url: string; } | { fileId: string; }; providerData?: Record; type: "image"; } | { file: | string | { data: string | Uint8Array; filename: string; mediaType: string; } | { filename?: string; url: string; } | { filename?: string; id: string; }; providerData?: Record; type: "file"; } | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; })[]; providerData?: Record; status: "in_progress" | "completed" | "incomplete"; type: "function_call_result"; } | { action?: | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; }; actions?: ( | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; })[]; callId: string; id?: string; providerData?: Record; status: "in_progress" | "completed" | "incomplete"; type: "computer_call"; } | { callId: string; id?: string; output: { data: string; providerData?: Record; type: "computer_screenshot"; }; providerData?: Record; type: "computer_call_result"; } | { action: { commands: string[]; maxOutputLength?: number; timeoutMs?: number; }; callId: string; id?: string; providerData?: Record; status?: "in_progress" | "completed" | "incomplete"; type: "shell_call"; } | { callId: string; id?: string; maxOutputLength?: number; output: object[]; providerData?: Record; type: "shell_call_output"; } | { callId: string; id?: string; operation: | { diff: string; path: string; type: "create_file"; } | { diff: string; moveTo?: string; path: string; type: "update_file"; } | { path: string; type: "delete_file"; }; providerData?: Record; status: "in_progress" | "completed"; type: "apply_patch_call"; } | { callId: string; id?: string; output?: string; providerData?: Record; status: "completed" | "failed"; type: "apply_patch_call_output"; } | { content: object[]; id?: string; providerData?: Record; rawContent?: object[]; type: "reasoning"; } | { created_by?: string; encrypted_content: string; id?: string; providerData?: Record; type: "compaction"; } | { id?: string; providerData?: Record; type: "unknown"; }; ``` ## Union Members [Section titled “Union Members”](#union-members) ### Type Literal [Section titled “Type Literal”](#type-literal) ```ts { content: ( | { providerData?: Record; refusal: string; type: "refusal"; } | { providerData?: Record; text: string; type: "output_text"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; } | { image: string; providerData?: Record; type: "image"; })[]; id?: string; providerData?: Record; role: "assistant"; status: "in_progress" | "completed" | "incomplete"; type?: "message"; } ``` #### content [Section titled “content”](#content) ```ts content: ( | { providerData?: Record; refusal: string; type: "refusal"; } | { providerData?: Record; text: string; type: "output_text"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; } | { image: string; providerData?: Record; type: "image"; })[]; ``` The content of the message. #### id? [Section titled “id?”](#id) ```ts optional id?: string; ``` An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. #### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. #### role [Section titled “role”](#role) ```ts role: "assistant"; ``` Representing a message from the assistant (i.e. the model) #### status [Section titled “status”](#status) ```ts status: "in_progress" | "completed" | "incomplete"; ``` The status of the message. #### type? [Section titled “type?”](#type) ```ts optional type?: "message"; ``` Any item without a type is treated as a message *** ### Type Literal [Section titled “Type Literal”](#type-literal-1) ```ts { content: | string | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; })[]; id?: string; providerData?: Record; role: "user"; type?: "message"; } ``` #### content [Section titled “content”](#content-1) ```ts content: | string | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; })[]; ``` The content of the message. #### id? [Section titled “id?”](#id-1) ```ts optional id?: string; ``` An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. #### providerData? [Section titled “providerData?”](#providerdata-1) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. #### role [Section titled “role”](#role-1) ```ts role: "user"; ``` Representing a message from the user #### type? [Section titled “type?”](#type-1) ```ts optional type?: "message"; ``` Any item without a type is treated as a message *** ### Type Literal [Section titled “Type Literal”](#type-literal-2) ```ts { content: string; id?: string; providerData?: Record; role: "system"; type?: "message"; } ``` #### content [Section titled “content”](#content-2) ```ts content: string; ``` The content of the message. #### id? [Section titled “id?”](#id-2) ```ts optional id?: string; ``` An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. #### providerData? [Section titled “providerData?”](#providerdata-2) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. #### role [Section titled “role”](#role-2) ```ts role: "system"; ``` Representing a system message to the user #### type? [Section titled “type?”](#type-2) ```ts optional type?: "message"; ``` Any item without a type is treated as a message *** ### Type Literal [Section titled “Type Literal”](#type-literal-3) ```ts { arguments?: string; id?: string; name: string; output?: string; providerData?: Record; status?: string; type: "hosted_tool_call"; } ``` #### arguments? [Section titled “arguments?”](#arguments) ```ts optional arguments?: string; ``` The arguments of the hosted tool call. #### id? [Section titled “id?”](#id-3) ```ts optional id?: string; ``` An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. #### name [Section titled “name”](#name) ```ts name: string; ``` The name of the hosted tool. For example `web_search_call` or `file_search_call` #### output? [Section titled “output?”](#output) ```ts optional output?: string; ``` The primary output of the tool call. Additional output might be in the `providerData` field. #### providerData? [Section titled “providerData?”](#providerdata-3) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. #### status? [Section titled “status?”](#status-1) ```ts optional status?: string; ``` The status of the tool call. #### type [Section titled “type”](#type-3) ```ts type: "hosted_tool_call"; ``` *** ### Type Literal [Section titled “Type Literal”](#type-literal-4) ```ts { arguments: string; callId: string; id?: string; name: string; namespace?: string; providerData?: Record; status?: "in_progress" | "completed" | "incomplete"; type: "function_call"; } ``` #### arguments [Section titled “arguments”](#arguments-1) ```ts arguments: string; ``` The arguments of the function call. #### callId [Section titled “callId”](#callid) ```ts callId: string; ``` The ID of the tool call. Required to match up the respective tool call result. #### id? [Section titled “id?”](#id-4) ```ts optional id?: string; ``` An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. #### name [Section titled “name”](#name-1) ```ts name: string; ``` The name of the function. #### namespace? [Section titled “namespace?”](#namespace) ```ts optional namespace?: string; ``` Optional namespace used to qualify the function name for tool search. #### providerData? [Section titled “providerData?”](#providerdata-4) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. #### status? [Section titled “status?”](#status-2) ```ts optional status?: "in_progress" | "completed" | "incomplete"; ``` The status of the function call. #### type [Section titled “type”](#type-4) ```ts type: "function_call"; ``` *** ### Type Literal [Section titled “Type Literal”](#type-literal-5) ```ts { arguments: unknown; call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; type: "tool_search_call"; } ``` #### arguments [Section titled “arguments”](#arguments-2) ```ts arguments: unknown = ToolSearchCallArguments; ``` #### call\_id? [Section titled “call\_id?”](#call_id) ```ts optional call_id?: string | null; ``` #### callId? [Section titled “callId?”](#callid-1) ```ts optional callId?: string | null; ``` #### execution? [Section titled “execution?”](#execution) ```ts optional execution?: "client" | "server"; ``` #### id? [Section titled “id?”](#id-5) ```ts optional id?: string; ``` An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. #### providerData? [Section titled “providerData?”](#providerdata-5) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. #### status? [Section titled “status?”](#status-3) ```ts optional status?: string; ``` #### type [Section titled “type”](#type-5) ```ts type: "tool_search_call"; ``` *** ### Type Literal [Section titled “Type Literal”](#type-literal-6) ```ts { call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; tools: Record[]; type: "tool_search_output"; } ``` #### call\_id? [Section titled “call\_id?”](#call_id-1) ```ts optional call_id?: string | null; ``` #### callId? [Section titled “callId?”](#callid-2) ```ts optional callId?: string | null; ``` #### execution? [Section titled “execution?”](#execution-1) ```ts optional execution?: "client" | "server"; ``` #### id? [Section titled “id?”](#id-6) ```ts optional id?: string; ``` An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. #### providerData? [Section titled “providerData?”](#providerdata-6) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. #### status? [Section titled “status?”](#status-4) ```ts optional status?: string; ``` #### tools [Section titled “tools”](#tools) ```ts tools: Record[]; ``` #### type [Section titled “type”](#type-6) ```ts type: "tool_search_output"; ``` *** ### Type Literal [Section titled “Type Literal”](#type-literal-7) ```ts { callId: string; id?: string; name: string; namespace?: string; output: | string | { providerData?: Record; text: string; type: "text"; } | { detail?: "low" | "high" | "auto" | string & object; image?: | string | { data: string | Uint8Array; mediaType?: string; } | { url: string; } | { fileId: string; }; providerData?: Record; type: "image"; } | { file: | string | { data: string | Uint8Array; filename: string; mediaType: string; } | { filename?: string; url: string; } | { filename?: string; id: string; }; providerData?: Record; type: "file"; } | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; })[]; providerData?: Record; status: "in_progress" | "completed" | "incomplete"; type: "function_call_result"; } ``` #### callId [Section titled “callId”](#callid-3) ```ts callId: string; ``` The ID of the tool call. Required to match up the respective tool call result. #### id? [Section titled “id?”](#id-7) ```ts optional id?: string; ``` An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. #### name [Section titled “name”](#name-2) ```ts name: string; ``` The name of the tool that was called #### namespace? [Section titled “namespace?”](#namespace-1) ```ts optional namespace?: string; ``` Optional namespace preserved from the originating function call. #### output [Section titled “output”](#output-1) ```ts output: | string | { providerData?: Record; text: string; type: "text"; } | { detail?: "low" | "high" | "auto" | string & object; image?: | string | { data: string | Uint8Array; mediaType?: string; } | { url: string; } | { fileId: string; }; providerData?: Record; type: "image"; } | { file: | string | { data: string | Uint8Array; filename: string; mediaType: string; } | { filename?: string; url: string; } | { filename?: string; id: string; }; providerData?: Record; type: "file"; } | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; })[]; ``` The output of the tool call. ##### Union Members [Section titled “Union Members”](#union-members-1) `string` *** ###### Type Literal [Section titled “Type Literal”](#type-literal-8) ```ts { providerData?: Record; text: string; type: "text"; } ``` | Name | Type | Description | | --------------- | ------------------------- | ------------------------------------------------------------------------------------------------------------ | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `text` | `string` | The text output from the model. | | `type` | `"text"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-9) ```ts { detail?: "low" | "high" | "auto" | string & object; image?: | string | { data: string | Uint8Array; mediaType?: string; } | { url: string; } | { fileId: string; }; providerData?: Record; type: "image"; } ``` | Name | Type | Description | | --------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------ | | `detail?` | `"low"` \| `"high"` \| `"auto"` \| `string` & `object` | Controls the requested level of detail for vision models. Use a string to avoid constraining future model capabilities. | | `image?` | \| `string` \| { `data`: `string` \| `Uint8Array`<`ArrayBuffer`>; `mediaType?`: `string`; } \| { `url`: `string`; } \| { `fileId`: `string`; } | Inline image content or a reference to an uploaded file. Accepts a URL/data URL string or an object describing the data/url/fileId source. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `type` | `"image"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-10) ```ts { file: | string | { data: string | Uint8Array; filename: string; mediaType: string; } | { filename?: string; url: string; } | { filename?: string; id: string; }; providerData?: Record; type: "file"; } ``` | Name | Type | Default value | Description | | --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `file` | \| `string` \| { `data`: `string` \| `Uint8Array`<`ArrayBuffer`>; `filename`: `string`; `mediaType`: `string`; } \| { `filename?`: `string`; `url`: `string`; } \| { `filename?`: `string`; `id`: `string`; } | `FileReferenceSchema` | File output reference. Provide either a string (data URL / base64), a data object (requires mediaType + filename), or an object pointing to an uploaded file/URL. | | `providerData?` | `Record`<`string`, `any`> | ‐ | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `type` | `"file"` | ‐ | ‐ | *** ( | { `providerData?`: `Record`<`string`, `any`>; `text`: `string`; `type`: `"input_text"`; } | { `detail?`: `string`; `image?`: | `string` | { `id`: `string`; }; `providerData?`: `Record`<`string`, `any`>; `type`: `"input_image"`; } | { `file?`: | `string` | { `id`: `string`; } | { `url`: `string`; }; `filename?`: `string`; `providerData?`: `Record`<`string`, `any`>; `type`: `"input_file"`; })\[] #### providerData? [Section titled “providerData?”](#providerdata-7) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. #### status [Section titled “status”](#status-5) ```ts status: "in_progress" | "completed" | "incomplete"; ``` The status of the tool call. #### type [Section titled “type”](#type-7) ```ts type: "function_call_result"; ``` *** ### Type Literal [Section titled “Type Literal”](#type-literal-11) ```ts { action?: | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; }; actions?: ( | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; })[]; callId: string; id?: string; providerData?: Record; status: "in_progress" | "completed" | "incomplete"; type: "computer_call"; } ``` #### action? [Section titled “action?”](#action) ```ts optional action?: | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; }; ``` The legacy single action to be performed by the computer. #### actions? [Section titled “actions?”](#actions) ```ts optional actions?: ( | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; })[]; ``` Batched actions returned by the GA computer tool. #### callId [Section titled “callId”](#callid-4) ```ts callId: string; ``` The ID of the computer call. Required to match up the respective computer call result. #### id? [Section titled “id?”](#id-8) ```ts optional id?: string; ``` An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. #### providerData? [Section titled “providerData?”](#providerdata-8) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. #### status [Section titled “status”](#status-6) ```ts status: "in_progress" | "completed" | "incomplete"; ``` The status of the computer call. #### type [Section titled “type”](#type-8) ```ts type: "computer_call"; ``` *** ### Type Literal [Section titled “Type Literal”](#type-literal-12) ```ts { callId: string; id?: string; output: { data: string; providerData?: Record; type: "computer_screenshot"; }; providerData?: Record; type: "computer_call_result"; } ``` #### callId [Section titled “callId”](#callid-5) ```ts callId: string; ``` The ID of the computer call. Required to match up the respective computer call result. #### id? [Section titled “id?”](#id-9) ```ts optional id?: string; ``` An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. #### output [Section titled “output”](#output-2) ```ts output: object = ComputerToolOutput; ``` The output of the computer call. ##### output.data [Section titled “output.data”](#outputdata) ```ts data: string; ``` A base64 encoded image data or a URL representing the screenshot. ##### output.providerData? [Section titled “output.providerData?”](#outputproviderdata) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. ##### output.type [Section titled “output.type”](#outputtype) ```ts type: "computer_screenshot"; ``` #### providerData? [Section titled “providerData?”](#providerdata-9) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. #### type [Section titled “type”](#type-9) ```ts type: "computer_call_result"; ``` *** ### Type Literal [Section titled “Type Literal”](#type-literal-13) ```ts { action: { commands: string[]; maxOutputLength?: number; timeoutMs?: number; }; callId: string; id?: string; providerData?: Record; status?: "in_progress" | "completed" | "incomplete"; type: "shell_call"; } ``` #### action [Section titled “action”](#action-1) ```ts action: object = ShellAction; ``` ##### action.commands [Section titled “action.commands”](#actioncommands) ```ts commands: string[]; ``` ##### action.maxOutputLength? [Section titled “action.maxOutputLength?”](#actionmaxoutputlength) ```ts optional maxOutputLength?: number; ``` ##### action.timeoutMs? [Section titled “action.timeoutMs?”](#actiontimeoutms) ```ts optional timeoutMs?: number; ``` #### callId [Section titled “callId”](#callid-6) ```ts callId: string; ``` #### id? [Section titled “id?”](#id-10) ```ts optional id?: string; ``` An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. #### providerData? [Section titled “providerData?”](#providerdata-10) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. #### status? [Section titled “status?”](#status-7) ```ts optional status?: "in_progress" | "completed" | "incomplete"; ``` #### type [Section titled “type”](#type-10) ```ts type: "shell_call"; ``` *** ### Type Literal [Section titled “Type Literal”](#type-literal-14) ```ts { callId: string; id?: string; maxOutputLength?: number; output: object[]; providerData?: Record; type: "shell_call_output"; } ``` #### callId [Section titled “callId”](#callid-7) ```ts callId: string; ``` #### id? [Section titled “id?”](#id-11) ```ts optional id?: string; ``` An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. #### maxOutputLength? [Section titled “maxOutputLength?”](#maxoutputlength) ```ts optional maxOutputLength?: number; ``` #### output [Section titled “output”](#output-3) ```ts output: object[]; ``` ##### Index Signature [Section titled “Index Signature”](#index-signature) ```ts [key: string]: unknown ``` #### providerData? [Section titled “providerData?”](#providerdata-11) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. #### type [Section titled “type”](#type-11) ```ts type: "shell_call_output"; ``` *** ### Type Literal [Section titled “Type Literal”](#type-literal-15) ```ts { callId: string; id?: string; operation: | { diff: string; path: string; type: "create_file"; } | { diff: string; moveTo?: string; path: string; type: "update_file"; } | { path: string; type: "delete_file"; }; providerData?: Record; status: "in_progress" | "completed"; type: "apply_patch_call"; } ``` #### callId [Section titled “callId”](#callid-8) ```ts callId: string; ``` #### id? [Section titled “id?”](#id-12) ```ts optional id?: string; ``` An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. #### operation [Section titled “operation”](#operation) ```ts operation: | { diff: string; path: string; type: "create_file"; } | { diff: string; moveTo?: string; path: string; type: "update_file"; } | { path: string; type: "delete_file"; } = ApplyPatchOperation; ``` #### providerData? [Section titled “providerData?”](#providerdata-12) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. #### status [Section titled “status”](#status-8) ```ts status: "in_progress" | "completed"; ``` #### type [Section titled “type”](#type-12) ```ts type: "apply_patch_call"; ``` *** ### Type Literal [Section titled “Type Literal”](#type-literal-16) ```ts { callId: string; id?: string; output?: string; providerData?: Record; status: "completed" | "failed"; type: "apply_patch_call_output"; } ``` #### callId [Section titled “callId”](#callid-9) ```ts callId: string; ``` #### id? [Section titled “id?”](#id-13) ```ts optional id?: string; ``` An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. #### output? [Section titled “output?”](#output-4) ```ts optional output?: string; ``` #### providerData? [Section titled “providerData?”](#providerdata-13) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. #### status [Section titled “status”](#status-9) ```ts status: "completed" | "failed"; ``` #### type [Section titled “type”](#type-13) ```ts type: "apply_patch_call_output"; ``` *** ### Type Literal [Section titled “Type Literal”](#type-literal-17) ```ts { content: object[]; id?: string; providerData?: Record; rawContent?: object[]; type: "reasoning"; } ``` #### content [Section titled “content”](#content-3) ```ts content: object[]; ``` The user facing representation of the reasoning. Additional information might be in the `providerData` field. #### id? [Section titled “id?”](#id-14) ```ts optional id?: string; ``` #### providerData? [Section titled “providerData?”](#providerdata-14) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. #### rawContent? [Section titled “rawContent?”](#rawcontent) ```ts optional rawContent?: object[]; ``` The raw reasoning text from the model. #### type [Section titled “type”](#type-14) ```ts type: "reasoning"; ``` *** ### Type Literal [Section titled “Type Literal”](#type-literal-18) ```ts { created_by?: string; encrypted_content: string; id?: string; providerData?: Record; type: "compaction"; } ``` #### created\_by? [Section titled “created\_by?”](#created_by) ```ts optional created_by?: string; ``` Identifier for the generator of this compaction item. #### encrypted\_content [Section titled “encrypted\_content”](#encrypted_content) ```ts encrypted_content: string; ``` Encrypted payload returned by the compaction endpoint. #### id? [Section titled “id?”](#id-15) ```ts optional id?: string; ``` Identifier for the compaction item. #### providerData? [Section titled “providerData?”](#providerdata-15) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. #### type [Section titled “type”](#type-15) ```ts type: "compaction"; ``` *** ### Type Literal [Section titled “Type Literal”](#type-literal-19) ```ts { id?: string; providerData?: Record; type: "unknown"; } ``` #### id? [Section titled “id?”](#id-16) ```ts optional id?: string; ``` An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. #### providerData? [Section titled “providerData?”](#providerdata-16) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. #### type [Section titled “type”](#type-16) ```ts type: "unknown"; ``` # OutputModelItem ```ts type OutputModelItem = | { content: ( | { providerData?: Record; refusal: string; type: "refusal"; } | { providerData?: Record; text: string; type: "output_text"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; } | { image: string; providerData?: Record; type: "image"; })[]; id?: string; providerData?: Record; role: "assistant"; status: "in_progress" | "completed" | "incomplete"; type?: "message"; } | { arguments?: string; id?: string; name: string; output?: string; providerData?: Record; status?: string; type: "hosted_tool_call"; } | { arguments: string; callId: string; id?: string; name: string; namespace?: string; providerData?: Record; status?: "in_progress" | "completed" | "incomplete"; type: "function_call"; } | { arguments: unknown; call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; type: "tool_search_call"; } | { call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; tools: Record[]; type: "tool_search_output"; } | { callId: string; id?: string; name: string; namespace?: string; output: | string | { providerData?: Record; text: string; type: "text"; } | { detail?: "low" | "high" | "auto" | string & object; image?: | string | { data: string | Uint8Array; mediaType?: string; } | { url: string; } | { fileId: string; }; providerData?: Record; type: "image"; } | { file: | string | { data: string | Uint8Array; filename: string; mediaType: string; } | { filename?: string; url: string; } | { filename?: string; id: string; }; providerData?: Record; type: "file"; } | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; })[]; providerData?: Record; status: "in_progress" | "completed" | "incomplete"; type: "function_call_result"; } | { action?: | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; }; actions?: ( | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; })[]; callId: string; id?: string; providerData?: Record; status: "in_progress" | "completed" | "incomplete"; type: "computer_call"; } | { action: { commands: string[]; maxOutputLength?: number; timeoutMs?: number; }; callId: string; id?: string; providerData?: Record; status?: "in_progress" | "completed" | "incomplete"; type: "shell_call"; } | { callId: string; id?: string; maxOutputLength?: number; output: object[]; providerData?: Record; type: "shell_call_output"; } | { callId: string; id?: string; operation: | { diff: string; path: string; type: "create_file"; } | { diff: string; moveTo?: string; path: string; type: "update_file"; } | { path: string; type: "delete_file"; }; providerData?: Record; status: "in_progress" | "completed"; type: "apply_patch_call"; } | { callId: string; id?: string; output?: string; providerData?: Record; status: "completed" | "failed"; type: "apply_patch_call_output"; } | { content: object[]; id?: string; providerData?: Record; rawContent?: object[]; type: "reasoning"; } | { created_by?: string; encrypted_content: string; id?: string; providerData?: Record; type: "compaction"; } | { id?: string; providerData?: Record; type: "unknown"; }; ``` ## Union Members [Section titled “Union Members”](#union-members) ### Type Literal [Section titled “Type Literal”](#type-literal) ```ts { content: ( | { providerData?: Record; refusal: string; type: "refusal"; } | { providerData?: Record; text: string; type: "output_text"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; } | { image: string; providerData?: Record; type: "image"; })[]; id?: string; providerData?: Record; role: "assistant"; status: "in_progress" | "completed" | "incomplete"; type?: "message"; } ``` #### content [Section titled “content”](#content) ```ts content: ( | { providerData?: Record; refusal: string; type: "refusal"; } | { providerData?: Record; text: string; type: "output_text"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; } | { image: string; providerData?: Record; type: "image"; })[]; ``` The content of the message. #### id? [Section titled “id?”](#id) ```ts optional id?: string; ``` An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. #### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. #### role [Section titled “role”](#role) ```ts role: "assistant"; ``` Representing a message from the assistant (i.e. the model) #### status [Section titled “status”](#status) ```ts status: "in_progress" | "completed" | "incomplete"; ``` The status of the message. #### type? [Section titled “type?”](#type) ```ts optional type?: "message"; ``` Any item without a type is treated as a message *** ### Type Literal [Section titled “Type Literal”](#type-literal-1) ```ts { arguments?: string; id?: string; name: string; output?: string; providerData?: Record; status?: string; type: "hosted_tool_call"; } ``` #### arguments? [Section titled “arguments?”](#arguments) ```ts optional arguments?: string; ``` The arguments of the hosted tool call. #### id? [Section titled “id?”](#id-1) ```ts optional id?: string; ``` An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. #### name [Section titled “name”](#name) ```ts name: string; ``` The name of the hosted tool. For example `web_search_call` or `file_search_call` #### output? [Section titled “output?”](#output) ```ts optional output?: string; ``` The primary output of the tool call. Additional output might be in the `providerData` field. #### providerData? [Section titled “providerData?”](#providerdata-1) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. #### status? [Section titled “status?”](#status-1) ```ts optional status?: string; ``` The status of the tool call. #### type [Section titled “type”](#type-1) ```ts type: "hosted_tool_call"; ``` *** ### Type Literal [Section titled “Type Literal”](#type-literal-2) ```ts { arguments: string; callId: string; id?: string; name: string; namespace?: string; providerData?: Record; status?: "in_progress" | "completed" | "incomplete"; type: "function_call"; } ``` #### arguments [Section titled “arguments”](#arguments-1) ```ts arguments: string; ``` The arguments of the function call. #### callId [Section titled “callId”](#callid) ```ts callId: string; ``` The ID of the tool call. Required to match up the respective tool call result. #### id? [Section titled “id?”](#id-2) ```ts optional id?: string; ``` An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. #### name [Section titled “name”](#name-1) ```ts name: string; ``` The name of the function. #### namespace? [Section titled “namespace?”](#namespace) ```ts optional namespace?: string; ``` Optional namespace used to qualify the function name for tool search. #### providerData? [Section titled “providerData?”](#providerdata-2) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. #### status? [Section titled “status?”](#status-2) ```ts optional status?: "in_progress" | "completed" | "incomplete"; ``` The status of the function call. #### type [Section titled “type”](#type-2) ```ts type: "function_call"; ``` *** ### Type Literal [Section titled “Type Literal”](#type-literal-3) ```ts { arguments: unknown; call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; type: "tool_search_call"; } ``` #### arguments [Section titled “arguments”](#arguments-2) ```ts arguments: unknown = ToolSearchCallArguments; ``` #### call\_id? [Section titled “call\_id?”](#call_id) ```ts optional call_id?: string | null; ``` #### callId? [Section titled “callId?”](#callid-1) ```ts optional callId?: string | null; ``` #### execution? [Section titled “execution?”](#execution) ```ts optional execution?: "client" | "server"; ``` #### id? [Section titled “id?”](#id-3) ```ts optional id?: string; ``` An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. #### providerData? [Section titled “providerData?”](#providerdata-3) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. #### status? [Section titled “status?”](#status-3) ```ts optional status?: string; ``` #### type [Section titled “type”](#type-3) ```ts type: "tool_search_call"; ``` *** ### Type Literal [Section titled “Type Literal”](#type-literal-4) ```ts { call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; tools: Record[]; type: "tool_search_output"; } ``` #### call\_id? [Section titled “call\_id?”](#call_id-1) ```ts optional call_id?: string | null; ``` #### callId? [Section titled “callId?”](#callid-2) ```ts optional callId?: string | null; ``` #### execution? [Section titled “execution?”](#execution-1) ```ts optional execution?: "client" | "server"; ``` #### id? [Section titled “id?”](#id-4) ```ts optional id?: string; ``` An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. #### providerData? [Section titled “providerData?”](#providerdata-4) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. #### status? [Section titled “status?”](#status-4) ```ts optional status?: string; ``` #### tools [Section titled “tools”](#tools) ```ts tools: Record[]; ``` #### type [Section titled “type”](#type-4) ```ts type: "tool_search_output"; ``` *** ### Type Literal [Section titled “Type Literal”](#type-literal-5) ```ts { callId: string; id?: string; name: string; namespace?: string; output: | string | { providerData?: Record; text: string; type: "text"; } | { detail?: "low" | "high" | "auto" | string & object; image?: | string | { data: string | Uint8Array; mediaType?: string; } | { url: string; } | { fileId: string; }; providerData?: Record; type: "image"; } | { file: | string | { data: string | Uint8Array; filename: string; mediaType: string; } | { filename?: string; url: string; } | { filename?: string; id: string; }; providerData?: Record; type: "file"; } | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; })[]; providerData?: Record; status: "in_progress" | "completed" | "incomplete"; type: "function_call_result"; } ``` #### callId [Section titled “callId”](#callid-3) ```ts callId: string; ``` The ID of the tool call. Required to match up the respective tool call result. #### id? [Section titled “id?”](#id-5) ```ts optional id?: string; ``` An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. #### name [Section titled “name”](#name-2) ```ts name: string; ``` The name of the tool that was called #### namespace? [Section titled “namespace?”](#namespace-1) ```ts optional namespace?: string; ``` Optional namespace preserved from the originating function call. #### output [Section titled “output”](#output-1) ```ts output: | string | { providerData?: Record; text: string; type: "text"; } | { detail?: "low" | "high" | "auto" | string & object; image?: | string | { data: string | Uint8Array; mediaType?: string; } | { url: string; } | { fileId: string; }; providerData?: Record; type: "image"; } | { file: | string | { data: string | Uint8Array; filename: string; mediaType: string; } | { filename?: string; url: string; } | { filename?: string; id: string; }; providerData?: Record; type: "file"; } | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; })[]; ``` The output of the tool call. ##### Union Members [Section titled “Union Members”](#union-members-1) `string` *** ###### Type Literal [Section titled “Type Literal”](#type-literal-6) ```ts { providerData?: Record; text: string; type: "text"; } ``` | Name | Type | Description | | --------------- | ------------------------- | ------------------------------------------------------------------------------------------------------------ | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `text` | `string` | The text output from the model. | | `type` | `"text"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-7) ```ts { detail?: "low" | "high" | "auto" | string & object; image?: | string | { data: string | Uint8Array; mediaType?: string; } | { url: string; } | { fileId: string; }; providerData?: Record; type: "image"; } ``` | Name | Type | Description | | --------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------ | | `detail?` | `"low"` \| `"high"` \| `"auto"` \| `string` & `object` | Controls the requested level of detail for vision models. Use a string to avoid constraining future model capabilities. | | `image?` | \| `string` \| { `data`: `string` \| `Uint8Array`<`ArrayBuffer`>; `mediaType?`: `string`; } \| { `url`: `string`; } \| { `fileId`: `string`; } | Inline image content or a reference to an uploaded file. Accepts a URL/data URL string or an object describing the data/url/fileId source. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `type` | `"image"` | ‐ | *** ###### Type Literal [Section titled “Type Literal”](#type-literal-8) ```ts { file: | string | { data: string | Uint8Array; filename: string; mediaType: string; } | { filename?: string; url: string; } | { filename?: string; id: string; }; providerData?: Record; type: "file"; } ``` | Name | Type | Default value | Description | | --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `file` | \| `string` \| { `data`: `string` \| `Uint8Array`<`ArrayBuffer`>; `filename`: `string`; `mediaType`: `string`; } \| { `filename?`: `string`; `url`: `string`; } \| { `filename?`: `string`; `id`: `string`; } | `FileReferenceSchema` | File output reference. Provide either a string (data URL / base64), a data object (requires mediaType + filename), or an object pointing to an uploaded file/URL. | | `providerData?` | `Record`<`string`, `any`> | ‐ | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `type` | `"file"` | ‐ | ‐ | *** ( | { `providerData?`: `Record`<`string`, `any`>; `text`: `string`; `type`: `"input_text"`; } | { `detail?`: `string`; `image?`: | `string` | { `id`: `string`; }; `providerData?`: `Record`<`string`, `any`>; `type`: `"input_image"`; } | { `file?`: | `string` | { `id`: `string`; } | { `url`: `string`; }; `filename?`: `string`; `providerData?`: `Record`<`string`, `any`>; `type`: `"input_file"`; })\[] #### providerData? [Section titled “providerData?”](#providerdata-5) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. #### status [Section titled “status”](#status-5) ```ts status: "in_progress" | "completed" | "incomplete"; ``` The status of the tool call. #### type [Section titled “type”](#type-5) ```ts type: "function_call_result"; ``` *** ### Type Literal [Section titled “Type Literal”](#type-literal-9) ```ts { action?: | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; }; actions?: ( | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; })[]; callId: string; id?: string; providerData?: Record; status: "in_progress" | "completed" | "incomplete"; type: "computer_call"; } ``` #### action? [Section titled “action?”](#action) ```ts optional action?: | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; }; ``` The legacy single action to be performed by the computer. #### actions? [Section titled “actions?”](#actions) ```ts optional actions?: ( | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; })[]; ``` Batched actions returned by the GA computer tool. #### callId [Section titled “callId”](#callid-4) ```ts callId: string; ``` The ID of the computer call. Required to match up the respective computer call result. #### id? [Section titled “id?”](#id-6) ```ts optional id?: string; ``` An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. #### providerData? [Section titled “providerData?”](#providerdata-6) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. #### status [Section titled “status”](#status-6) ```ts status: "in_progress" | "completed" | "incomplete"; ``` The status of the computer call. #### type [Section titled “type”](#type-6) ```ts type: "computer_call"; ``` *** ### Type Literal [Section titled “Type Literal”](#type-literal-10) ```ts { action: { commands: string[]; maxOutputLength?: number; timeoutMs?: number; }; callId: string; id?: string; providerData?: Record; status?: "in_progress" | "completed" | "incomplete"; type: "shell_call"; } ``` #### action [Section titled “action”](#action-1) ```ts action: object = ShellAction; ``` ##### action.commands [Section titled “action.commands”](#actioncommands) ```ts commands: string[]; ``` ##### action.maxOutputLength? [Section titled “action.maxOutputLength?”](#actionmaxoutputlength) ```ts optional maxOutputLength?: number; ``` ##### action.timeoutMs? [Section titled “action.timeoutMs?”](#actiontimeoutms) ```ts optional timeoutMs?: number; ``` #### callId [Section titled “callId”](#callid-5) ```ts callId: string; ``` #### id? [Section titled “id?”](#id-7) ```ts optional id?: string; ``` An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. #### providerData? [Section titled “providerData?”](#providerdata-7) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. #### status? [Section titled “status?”](#status-7) ```ts optional status?: "in_progress" | "completed" | "incomplete"; ``` #### type [Section titled “type”](#type-7) ```ts type: "shell_call"; ``` *** ### Type Literal [Section titled “Type Literal”](#type-literal-11) ```ts { callId: string; id?: string; maxOutputLength?: number; output: object[]; providerData?: Record; type: "shell_call_output"; } ``` #### callId [Section titled “callId”](#callid-6) ```ts callId: string; ``` #### id? [Section titled “id?”](#id-8) ```ts optional id?: string; ``` An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. #### maxOutputLength? [Section titled “maxOutputLength?”](#maxoutputlength) ```ts optional maxOutputLength?: number; ``` #### output [Section titled “output”](#output-2) ```ts output: object[]; ``` ##### Index Signature [Section titled “Index Signature”](#index-signature) ```ts [key: string]: unknown ``` #### providerData? [Section titled “providerData?”](#providerdata-8) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. #### type [Section titled “type”](#type-8) ```ts type: "shell_call_output"; ``` *** ### Type Literal [Section titled “Type Literal”](#type-literal-12) ```ts { callId: string; id?: string; operation: | { diff: string; path: string; type: "create_file"; } | { diff: string; moveTo?: string; path: string; type: "update_file"; } | { path: string; type: "delete_file"; }; providerData?: Record; status: "in_progress" | "completed"; type: "apply_patch_call"; } ``` #### callId [Section titled “callId”](#callid-7) ```ts callId: string; ``` #### id? [Section titled “id?”](#id-9) ```ts optional id?: string; ``` An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. #### operation [Section titled “operation”](#operation) ```ts operation: | { diff: string; path: string; type: "create_file"; } | { diff: string; moveTo?: string; path: string; type: "update_file"; } | { path: string; type: "delete_file"; } = ApplyPatchOperation; ``` #### providerData? [Section titled “providerData?”](#providerdata-9) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. #### status [Section titled “status”](#status-8) ```ts status: "in_progress" | "completed"; ``` #### type [Section titled “type”](#type-9) ```ts type: "apply_patch_call"; ``` *** ### Type Literal [Section titled “Type Literal”](#type-literal-13) ```ts { callId: string; id?: string; output?: string; providerData?: Record; status: "completed" | "failed"; type: "apply_patch_call_output"; } ``` #### callId [Section titled “callId”](#callid-8) ```ts callId: string; ``` #### id? [Section titled “id?”](#id-10) ```ts optional id?: string; ``` An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. #### output? [Section titled “output?”](#output-3) ```ts optional output?: string; ``` #### providerData? [Section titled “providerData?”](#providerdata-10) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. #### status [Section titled “status”](#status-9) ```ts status: "completed" | "failed"; ``` #### type [Section titled “type”](#type-10) ```ts type: "apply_patch_call_output"; ``` *** ### Type Literal [Section titled “Type Literal”](#type-literal-14) ```ts { content: object[]; id?: string; providerData?: Record; rawContent?: object[]; type: "reasoning"; } ``` #### content [Section titled “content”](#content-1) ```ts content: object[]; ``` The user facing representation of the reasoning. Additional information might be in the `providerData` field. #### id? [Section titled “id?”](#id-11) ```ts optional id?: string; ``` #### providerData? [Section titled “providerData?”](#providerdata-11) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. #### rawContent? [Section titled “rawContent?”](#rawcontent) ```ts optional rawContent?: object[]; ``` The raw reasoning text from the model. #### type [Section titled “type”](#type-11) ```ts type: "reasoning"; ``` *** ### Type Literal [Section titled “Type Literal”](#type-literal-15) ```ts { created_by?: string; encrypted_content: string; id?: string; providerData?: Record; type: "compaction"; } ``` #### created\_by? [Section titled “created\_by?”](#created_by) ```ts optional created_by?: string; ``` Identifier for the generator of this compaction item. #### encrypted\_content [Section titled “encrypted\_content”](#encrypted_content) ```ts encrypted_content: string; ``` Encrypted payload returned by the compaction endpoint. #### id? [Section titled “id?”](#id-12) ```ts optional id?: string; ``` Identifier for the compaction item. #### providerData? [Section titled “providerData?”](#providerdata-12) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. #### type [Section titled “type”](#type-12) ```ts type: "compaction"; ``` *** ### Type Literal [Section titled “Type Literal”](#type-literal-16) ```ts { id?: string; providerData?: Record; type: "unknown"; } ``` #### id? [Section titled “id?”](#id-13) ```ts optional id?: string; ``` An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. #### providerData? [Section titled “providerData?”](#providerdata-13) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. #### type [Section titled “type”](#type-13) ```ts type: "unknown"; ``` # OutputText ```ts type OutputText = object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. ### text [Section titled “text”](#text) ```ts text: string; ``` The text output from the model. ### type [Section titled “type”](#type) ```ts type: "output_text"; ``` # ReasoningText ```ts type ReasoningText = object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. ### text [Section titled “text”](#text) ```ts text: string; ``` A text input for example a message from a user ### type [Section titled “type”](#type) ```ts type: "reasoning_text"; ``` # Refusal ```ts type Refusal = object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. ### refusal [Section titled “refusal”](#refusal) ```ts refusal: string; ``` The refusal explanation from the model. ### type [Section titled “type”](#type) ```ts type: "refusal"; ``` # RequestUsageData ```ts type RequestUsageData = object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### endpoint? [Section titled “endpoint?”](#endpoint) ```ts optional endpoint?: string; ``` ### inputTokens [Section titled “inputTokens”](#inputtokens) ```ts inputTokens: number; ``` ### inputTokensDetails? [Section titled “inputTokensDetails?”](#inputtokensdetails) ```ts optional inputTokensDetails?: Record; ``` ### outputTokens [Section titled “outputTokens”](#outputtokens) ```ts outputTokens: number; ``` ### outputTokensDetails? [Section titled “outputTokensDetails?”](#outputtokensdetails) ```ts optional outputTokensDetails?: Record; ``` ### totalTokens [Section titled “totalTokens”](#totaltokens) ```ts totalTokens: number; ``` # SharedBase ```ts type SharedBase = object; ``` Every item in the protocol provides a `providerData` field to accommodate custom functionality or new fields ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. # ShellAction ```ts type ShellAction = object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### commands [Section titled “commands”](#commands) ```ts commands: string[]; ``` ### maxOutputLength? [Section titled “maxOutputLength?”](#maxoutputlength) ```ts optional maxOutputLength?: number; ``` ### timeoutMs? [Section titled “timeoutMs?”](#timeoutms) ```ts optional timeoutMs?: number; ``` # ShellCallOutcome ```ts type ShellCallOutcome = | { type: "timeout"; } | { exitCode: number | null; type: "exit"; }; ``` # ShellCallOutputContent ```ts type ShellCallOutputContent = object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ## Index Signature [Section titled “Index Signature”](#index-signature) ```ts [key: string]: unknown ``` ### outcome [Section titled “outcome”](#outcome) ```ts outcome: | { type: "timeout"; } | { exitCode: number | null; type: "exit"; } = ShellCallOutcome; ``` ### stderr [Section titled “stderr”](#stderr) ```ts stderr: string; ``` ### stdout [Section titled “stdout”](#stdout) ```ts stdout: string; ``` # ToolCallItem ```ts type ToolCallItem = | { arguments?: string; id?: string; name: string; output?: string; providerData?: Record; status?: string; type: "hosted_tool_call"; } | { arguments: string; callId: string; id?: string; name: string; namespace?: string; providerData?: Record; status?: "in_progress" | "completed" | "incomplete"; type: "function_call"; } | { action?: | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; }; actions?: ( | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; })[]; callId: string; id?: string; providerData?: Record; status: "in_progress" | "completed" | "incomplete"; type: "computer_call"; } | { action: { commands: string[]; maxOutputLength?: number; timeoutMs?: number; }; callId: string; id?: string; providerData?: Record; status?: "in_progress" | "completed" | "incomplete"; type: "shell_call"; } | { callId: string; id?: string; operation: | { diff: string; path: string; type: "create_file"; } | { diff: string; moveTo?: string; path: string; type: "update_file"; } | { path: string; type: "delete_file"; }; providerData?: Record; status: "in_progress" | "completed"; type: "apply_patch_call"; }; ``` ## Union Members [Section titled “Union Members”](#union-members) ### Type Literal [Section titled “Type Literal”](#type-literal) ```ts { arguments?: string; id?: string; name: string; output?: string; providerData?: Record; status?: string; type: "hosted_tool_call"; } ``` #### arguments? [Section titled “arguments?”](#arguments) ```ts optional arguments?: string; ``` The arguments of the hosted tool call. #### id? [Section titled “id?”](#id) ```ts optional id?: string; ``` An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. #### name [Section titled “name”](#name) ```ts name: string; ``` The name of the hosted tool. For example `web_search_call` or `file_search_call` #### output? [Section titled “output?”](#output) ```ts optional output?: string; ``` The primary output of the tool call. Additional output might be in the `providerData` field. #### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. #### status? [Section titled “status?”](#status) ```ts optional status?: string; ``` The status of the tool call. #### type [Section titled “type”](#type) ```ts type: "hosted_tool_call"; ``` *** ### Type Literal [Section titled “Type Literal”](#type-literal-1) ```ts { arguments: string; callId: string; id?: string; name: string; namespace?: string; providerData?: Record; status?: "in_progress" | "completed" | "incomplete"; type: "function_call"; } ``` #### arguments [Section titled “arguments”](#arguments-1) ```ts arguments: string; ``` The arguments of the function call. #### callId [Section titled “callId”](#callid) ```ts callId: string; ``` The ID of the tool call. Required to match up the respective tool call result. #### id? [Section titled “id?”](#id-1) ```ts optional id?: string; ``` An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. #### name [Section titled “name”](#name-1) ```ts name: string; ``` The name of the function. #### namespace? [Section titled “namespace?”](#namespace) ```ts optional namespace?: string; ``` Optional namespace used to qualify the function name for tool search. #### providerData? [Section titled “providerData?”](#providerdata-1) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. #### status? [Section titled “status?”](#status-1) ```ts optional status?: "in_progress" | "completed" | "incomplete"; ``` The status of the function call. #### type [Section titled “type”](#type-1) ```ts type: "function_call"; ``` *** ### Type Literal [Section titled “Type Literal”](#type-literal-2) ```ts { action?: | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; }; actions?: ( | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; })[]; callId: string; id?: string; providerData?: Record; status: "in_progress" | "completed" | "incomplete"; type: "computer_call"; } ``` #### action? [Section titled “action?”](#action) ```ts optional action?: | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; }; ``` The legacy single action to be performed by the computer. #### actions? [Section titled “actions?”](#actions) ```ts optional actions?: ( | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; })[]; ``` Batched actions returned by the GA computer tool. #### callId [Section titled “callId”](#callid-1) ```ts callId: string; ``` The ID of the computer call. Required to match up the respective computer call result. #### id? [Section titled “id?”](#id-2) ```ts optional id?: string; ``` An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. #### providerData? [Section titled “providerData?”](#providerdata-2) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. #### status [Section titled “status”](#status-2) ```ts status: "in_progress" | "completed" | "incomplete"; ``` The status of the computer call. #### type [Section titled “type”](#type-2) ```ts type: "computer_call"; ``` *** ### Type Literal [Section titled “Type Literal”](#type-literal-3) ```ts { action: { commands: string[]; maxOutputLength?: number; timeoutMs?: number; }; callId: string; id?: string; providerData?: Record; status?: "in_progress" | "completed" | "incomplete"; type: "shell_call"; } ``` #### action [Section titled “action”](#action-1) ```ts action: object = ShellAction; ``` ##### action.commands [Section titled “action.commands”](#actioncommands) ```ts commands: string[]; ``` ##### action.maxOutputLength? [Section titled “action.maxOutputLength?”](#actionmaxoutputlength) ```ts optional maxOutputLength?: number; ``` ##### action.timeoutMs? [Section titled “action.timeoutMs?”](#actiontimeoutms) ```ts optional timeoutMs?: number; ``` #### callId [Section titled “callId”](#callid-2) ```ts callId: string; ``` #### id? [Section titled “id?”](#id-3) ```ts optional id?: string; ``` An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. #### providerData? [Section titled “providerData?”](#providerdata-3) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. #### status? [Section titled “status?”](#status-3) ```ts optional status?: "in_progress" | "completed" | "incomplete"; ``` #### type [Section titled “type”](#type-3) ```ts type: "shell_call"; ``` *** ### Type Literal [Section titled “Type Literal”](#type-literal-4) ```ts { callId: string; id?: string; operation: | { diff: string; path: string; type: "create_file"; } | { diff: string; moveTo?: string; path: string; type: "update_file"; } | { path: string; type: "delete_file"; }; providerData?: Record; status: "in_progress" | "completed"; type: "apply_patch_call"; } ``` #### callId [Section titled “callId”](#callid-3) ```ts callId: string; ``` #### id? [Section titled “id?”](#id-4) ```ts optional id?: string; ``` An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. #### operation [Section titled “operation”](#operation) ```ts operation: | { diff: string; path: string; type: "create_file"; } | { diff: string; moveTo?: string; path: string; type: "update_file"; } | { path: string; type: "delete_file"; } = ApplyPatchOperation; ``` #### providerData? [Section titled “providerData?”](#providerdata-4) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. #### status [Section titled “status”](#status-4) ```ts status: "in_progress" | "completed"; ``` #### type [Section titled “type”](#type-4) ```ts type: "apply_patch_call"; ``` # UsageData ```ts type UsageData = object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### inputTokens [Section titled “inputTokens”](#inputtokens) ```ts inputTokens: number; ``` ### inputTokensDetails? [Section titled “inputTokensDetails?”](#inputtokensdetails) ```ts optional inputTokensDetails?: Record | Record[]; ``` ### outputTokens [Section titled “outputTokens”](#outputtokens) ```ts outputTokens: number; ``` ### outputTokensDetails? [Section titled “outputTokensDetails?”](#outputtokensdetails) ```ts optional outputTokensDetails?: Record | Record[]; ``` ### requests? [Section titled “requests?”](#requests) ```ts optional requests?: number; ``` ### requestUsageEntries? [Section titled “requestUsageEntries?”](#requestusageentries) ```ts optional requestUsageEntries?: object[]; ``` ### totalTokens [Section titled “totalTokens”](#totaltokens) ```ts totalTokens: number; ``` # UserContent ```ts type UserContent = | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; }; ``` ## Union Members [Section titled “Union Members”](#union-members) ### Type Literal [Section titled “Type Literal”](#type-literal) ```ts { providerData?: Record; text: string; type: "input_text"; } ``` #### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. #### text [Section titled “text”](#text) ```ts text: string; ``` A text input for example a message from a user #### type [Section titled “type”](#type) ```ts type: "input_text"; ``` *** ### Type Literal [Section titled “Type Literal”](#type-literal-1) ```ts { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } ``` #### detail? [Section titled “detail?”](#detail) ```ts optional detail?: string; ``` Controls the level of detail requested for image understanding tasks. Future models may add new values, therefore this accepts any string. #### image? [Section titled “image?”](#image) ```ts optional image?: | string | { id: string; }; ``` The image input to the model. Could be provided inline (`image`), as a URL, or by reference to a previously uploaded OpenAI file. #### providerData? [Section titled “providerData?”](#providerdata-1) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. #### type [Section titled “type”](#type-1) ```ts type: "input_image"; ``` *** ### Type Literal [Section titled “Type Literal”](#type-literal-2) ```ts { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; } ``` #### file? [Section titled “file?”](#file) ```ts optional file?: | string | { id: string; } | { url: string; }; ``` The file input to the model. Could be raw data, a URL, or an OpenAI file ID. When passing a string, it is interpreted as inline data or a URL; use `{ id }` for file IDs. #### filename? [Section titled “filename?”](#filename) ```ts optional filename?: string; ``` Optional filename metadata when uploading file data inline. #### providerData? [Section titled “providerData?”](#providerdata-2) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. #### type [Section titled “type”](#type-2) ```ts type: "input_file"; ``` *** ### Type Literal [Section titled “Type Literal”](#type-literal-3) ```ts { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; } ``` #### audio [Section titled “audio”](#audio) ```ts audio: | string | { id: string; }; ``` The audio input to the model. Could be base64 encoded audio data or an object with a file ID. #### format? [Section titled “format?”](#format) ```ts optional format?: string | null; ``` The format of the audio. #### providerData? [Section titled “providerData?”](#providerdata-3) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. #### transcript? [Section titled “transcript?”](#transcript) ```ts optional transcript?: string | null; ``` The transcript of the audio. #### type [Section titled “type”](#type-3) ```ts type: "audio"; ``` # ApplyPatchOperationCreateFile ```ts const ApplyPatchOperationCreateFile: ZodObject; ``` # ApplyPatchOperationDeleteFile ```ts const ApplyPatchOperationDeleteFile: ZodObject; ``` # ApplyPatchOperationUpdateFile ```ts const ApplyPatchOperationUpdateFile: ZodObject; ``` # AssistantContent ```ts const AssistantContent: ZodDiscriminatedUnion; ``` # AudioContent ```ts const AudioContent: ZodObject; ``` # CompactionItem ```ts const CompactionItem: ZodObject; ``` # computerActions ```ts const computerActions: ZodDiscriminatedUnion; ``` # ComputerToolOutput ```ts const ComputerToolOutput: ZodObject; ``` # ImageContent ```ts const ImageContent: ZodObject; ``` # InputFile ```ts const InputFile: ZodObject; ``` # InputImage ```ts const InputImage: ZodObject; ``` # InputText ```ts const InputText: ZodObject; ``` # ItemBase ```ts const ItemBase: ZodObject; ``` Every item has a shared of shared item data including an optional ID. # MessageItem ```ts const MessageItem: ZodDiscriminatedUnion; ``` # ModelItem ```ts const ModelItem: ZodUnion; ``` # OutputModelItem ```ts const OutputModelItem: ZodDiscriminatedUnion; ``` # OutputText ```ts const OutputText: ZodObject; ``` # ReasoningText ```ts const ReasoningText: ZodObject; ``` # Refusal ```ts const Refusal: ZodObject; ``` # RequestUsageData ```ts const RequestUsageData: ZodObject; ``` # SharedBase ```ts const SharedBase: ZodObject; ``` Every item in the protocol provides a `providerData` field to accommodate custom functionality or new fields # ShellAction ```ts const ShellAction: ZodObject; ``` # ShellCallOutcome ```ts const ShellCallOutcome: ZodDiscriminatedUnion; ``` # ShellCallOutputContent ```ts const ShellCallOutputContent: ZodObject; ``` # ToolCallItem ```ts const ToolCallItem: ZodDiscriminatedUnion; ``` # UsageData ```ts const UsageData: ZodObject; ``` # UserContent ```ts const UserContent: ZodDiscriminatedUnion; ``` # EventEmitterAsyncResource Integrates `EventEmitter` with `AsyncResource` for `EventEmitter`s that require manual async tracking. Specifically, all events emitted by instances of `events.EventEmitterAsyncResource` will run within its `async context`. ```js import { EventEmitterAsyncResource, EventEmitter } from 'node:events'; import { notStrictEqual, strictEqual } from 'node:assert'; import { executionAsyncId, triggerAsyncId } from 'node:async_hooks'; // Async tracking tooling will identify this as 'Q'. const ee1 = new EventEmitterAsyncResource({ name: 'Q' }); // 'foo' listeners will run in the EventEmitters async context. ee1.on('foo', () => { strictEqual(executionAsyncId(), ee1.asyncId); strictEqual(triggerAsyncId(), ee1.triggerAsyncId); }); const ee2 = new EventEmitter(); // 'foo' listeners on ordinary EventEmitters that do not track async // context, however, run in the same async context as the emit(). ee2.on('foo', () => { notStrictEqual(executionAsyncId(), ee2.asyncId); notStrictEqual(triggerAsyncId(), ee2.triggerAsyncId); }); Promise.resolve().then(() => { ee1.emit('foo'); ee2.emit('foo'); }); ``` The `EventEmitterAsyncResource` class has the same methods and takes the same options as `EventEmitter` and `AsyncResource` themselves. ## Since [Section titled “Since”](#since) v17.4.0, v16.14.0 ## Extends [Section titled “Extends”](#extends) * [`RuntimeEventEmitter`](/openai-agents-js/openai/agents-core/classes/runtimeeventemitter/) ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new EventEmitterAsyncResource(options?): EventEmitterAsyncResource; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------- | | `options?` | [`EventEmitterAsyncResourceOptions`](/openai-agents-js/openai/agents-core/openai/namespaces/runtimeeventemitter/interfaces/eventemitterasyncresourceoptions/) | Only optional in child class. | #### Returns [Section titled “Returns”](#returns) `EventEmitterAsyncResource` #### Overrides [Section titled “Overrides”](#overrides) [`RuntimeEventEmitter`](/openai-agents-js/openai/agents-core/classes/runtimeeventemitter/).[`constructor`](/openai-agents-js/openai/agents-core/classes/runtimeeventemitter/#constructor) ## Properties [Section titled “Properties”](#properties) ### asyncId [Section titled “asyncId”](#asyncid) ```ts readonly asyncId: number; ``` The unique `asyncId` assigned to the resource. *** ### asyncResource [Section titled “asyncResource”](#asyncresource) ```ts readonly asyncResource: EventEmitterReferencingAsyncResource; ``` The returned `AsyncResource` object has an additional `eventEmitter` property that provides a reference to this `EventEmitterAsyncResource`. *** ### triggerAsyncId [Section titled “triggerAsyncId”](#triggerasyncid) ```ts readonly triggerAsyncId: number; ``` The same triggerAsyncId that is passed to the AsyncResource constructor. *** ### captureRejections [Section titled “captureRejections”](#capturerejections) ```ts static captureRejections: boolean; ``` Value: [boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type) Change the default `captureRejections` option on all new `EventEmitter` objects. #### Since [Section titled “Since”](#since-1) v13.4.0, v12.16.0 #### Inherited from [Section titled “Inherited from”](#inherited-from) [`RuntimeEventEmitter`](/openai-agents-js/openai/agents-core/classes/runtimeeventemitter/).[`captureRejections`](/openai-agents-js/openai/agents-core/classes/runtimeeventemitter/#capturerejections) *** ### captureRejectionSymbol [Section titled “captureRejectionSymbol”](#capturerejectionsymbol) ```ts readonly static captureRejectionSymbol: typeof captureRejectionSymbol; ``` Value: `Symbol.for('nodejs.rejection')` See how to write a custom `rejection handler`. #### Since [Section titled “Since”](#since-2) v13.4.0, v12.16.0 #### Inherited from [Section titled “Inherited from”](#inherited-from-1) [`RuntimeEventEmitter`](/openai-agents-js/openai/agents-core/classes/runtimeeventemitter/).[`captureRejectionSymbol`](/openai-agents-js/openai/agents-core/classes/runtimeeventemitter/#capturerejectionsymbol) *** ### defaultMaxListeners [Section titled “defaultMaxListeners”](#defaultmaxlisteners) ```ts static defaultMaxListeners: number; ``` By default, a maximum of `10` listeners can be registered for any single event. This limit can be changed for individual `EventEmitter` instances using the `emitter.setMaxListeners(n)` method. To change the default for *all*`EventEmitter` instances, the `events.defaultMaxListeners` property can be used. If this value is not a positive number, a `RangeError` is thrown. Take caution when setting the `events.defaultMaxListeners` because the change affects *all* `EventEmitter` instances, including those created before the change is made. However, calling `emitter.setMaxListeners(n)` still has precedence over `events.defaultMaxListeners`. This is not a hard limit. The `EventEmitter` instance will allow more listeners to be added but will output a trace warning to stderr indicating that a “possible EventEmitter memory leak” has been detected. For any single `EventEmitter`, the `emitter.getMaxListeners()` and `emitter.setMaxListeners()` methods can be used to temporarily avoid this warning: ```js import { EventEmitter } from 'node:events'; const emitter = new EventEmitter(); emitter.setMaxListeners(emitter.getMaxListeners() + 1); emitter.once('event', () => { // do stuff emitter.setMaxListeners(Math.max(emitter.getMaxListeners() - 1, 0)); }); ``` The `--trace-warnings` command-line flag can be used to display the stack trace for such warnings. The emitted warning can be inspected with `process.on('warning')` and will have the additional `emitter`, `type`, and `count` properties, referring to the event emitter instance, the event’s name and the number of attached listeners, respectively. Its `name` property is set to `'MaxListenersExceededWarning'`. #### Since [Section titled “Since”](#since-3) v0.11.2 #### Inherited from [Section titled “Inherited from”](#inherited-from-2) [`RuntimeEventEmitter`](/openai-agents-js/openai/agents-core/classes/runtimeeventemitter/).[`defaultMaxListeners`](/openai-agents-js/openai/agents-core/classes/runtimeeventemitter/#defaultmaxlisteners) *** ### errorMonitor [Section titled “errorMonitor”](#errormonitor) ```ts readonly static errorMonitor: typeof errorMonitor; ``` This symbol shall be used to install a listener for only monitoring `'error'` events. Listeners installed using this symbol are called before the regular `'error'` listeners are called. Installing a listener using this symbol does not change the behavior once an `'error'` event is emitted. Therefore, the process will still crash if no regular `'error'` listener is installed. #### Since [Section titled “Since”](#since-4) v13.6.0, v12.17.0 #### Inherited from [Section titled “Inherited from”](#inherited-from-3) [`RuntimeEventEmitter`](/openai-agents-js/openai/agents-core/classes/runtimeeventemitter/).[`errorMonitor`](/openai-agents-js/openai/agents-core/classes/runtimeeventemitter/#errormonitor) ## Methods [Section titled “Methods”](#methods) ### \[captureRejectionSymbol]\()? [Section titled “\[captureRejectionSymbol\]()?”](#capturerejectionsymbol-1) ```ts optional [captureRejectionSymbol]( error, event, ... args): void; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | -------------- | | `K` | #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | --------- | -------------------- | | `error` | `Error` | | `event` | `string` \| `symbol` | | …`args` | `AnyRest` | #### Returns [Section titled “Returns”](#returns-1) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-4) [`RuntimeEventEmitter`](/openai-agents-js/openai/agents-core/classes/runtimeeventemitter/).[`[captureRejectionSymbol]`](/openai-agents-js/openai/agents-core/classes/runtimeeventemitter/#capturerejectionsymbol-1) *** ### addListener() [Section titled “addListener()”](#addlistener) ```ts addListener(eventName, listener): this; ``` Alias for `emitter.on(eventName, listener)`. #### Type Parameters [Section titled “Type Parameters”](#type-parameters-1) | Type Parameter | | -------------- | | `K` | #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | ----------- | -------------------- | | `eventName` | `string` \| `symbol` | | `listener` | (…`args`) => `void` | #### Returns [Section titled “Returns”](#returns-2) `this` #### Since [Section titled “Since”](#since-5) v0.1.26 #### Inherited from [Section titled “Inherited from”](#inherited-from-5) [`RuntimeEventEmitter`](/openai-agents-js/openai/agents-core/classes/runtimeeventemitter/).[`addListener`](/openai-agents-js/openai/agents-core/classes/runtimeeventemitter/#addlistener) *** ### emit() [Section titled “emit()”](#emit) ```ts emit(eventName, ...args): boolean; ``` Synchronously calls each of the listeners registered for the event named `eventName`, in the order they were registered, passing the supplied arguments to each. Returns `true` if the event had listeners, `false` otherwise. ```js import { EventEmitter } from 'node:events'; const myEmitter = new EventEmitter(); // First listener myEmitter.on('event', function firstListener() { console.log('Helloooo! first listener'); }); // Second listener myEmitter.on('event', function secondListener(arg1, arg2) { console.log(`event with parameters ${arg1}, ${arg2} in second listener`); }); // Third listener myEmitter.on('event', function thirdListener(...args) { const parameters = args.join(', '); console.log(`event with parameters ${parameters} in third listener`); }); console.log(myEmitter.listeners('event')); myEmitter.emit('event', 1, 2, 3, 4, 5); // Prints: // [ // [Function: firstListener], // [Function: secondListener], // [Function: thirdListener] // ] // Helloooo! first listener // event with parameters 1, 2 in second listener // event with parameters 1, 2, 3, 4, 5 in third listener ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-2) | Type Parameter | | -------------- | | `K` | #### Parameters [Section titled “Parameters”](#parameters-3) | Parameter | Type | | ----------- | -------------------- | | `eventName` | `string` \| `symbol` | | …`args` | `AnyRest` | #### Returns [Section titled “Returns”](#returns-3) `boolean` #### Since [Section titled “Since”](#since-6) v0.1.26 #### Inherited from [Section titled “Inherited from”](#inherited-from-6) [`RuntimeEventEmitter`](/openai-agents-js/openai/agents-core/classes/runtimeeventemitter/).[`emit`](/openai-agents-js/openai/agents-core/classes/runtimeeventemitter/#emit) *** ### emitDestroy() [Section titled “emitDestroy()”](#emitdestroy) ```ts emitDestroy(): void; ``` Call all `destroy` hooks. This should only ever be called once. An error will be thrown if it is called more than once. This **must** be manually called. If the resource is left to be collected by the GC then the `destroy` hooks will never be called. #### Returns [Section titled “Returns”](#returns-4) `void` *** ### eventNames() [Section titled “eventNames()”](#eventnames) ```ts eventNames(): (string | symbol)[]; ``` Returns an array listing the events for which the emitter has registered listeners. The values in the array are strings or `Symbol`s. ```js import { EventEmitter } from 'node:events'; const myEE = new EventEmitter(); myEE.on('foo', () => {}); myEE.on('bar', () => {}); const sym = Symbol('symbol'); myEE.on(sym, () => {}); console.log(myEE.eventNames()); // Prints: [ 'foo', 'bar', Symbol(symbol) ] ``` #### Returns [Section titled “Returns”](#returns-5) (`string` | `symbol`)\[] #### Since [Section titled “Since”](#since-7) v6.0.0 #### Inherited from [Section titled “Inherited from”](#inherited-from-7) [`RuntimeEventEmitter`](/openai-agents-js/openai/agents-core/classes/runtimeeventemitter/).[`eventNames`](/openai-agents-js/openai/agents-core/classes/runtimeeventemitter/#eventnames) *** ### getMaxListeners() [Section titled “getMaxListeners()”](#getmaxlisteners) ```ts getMaxListeners(): number; ``` Returns the current max listener value for the `EventEmitter` which is either set by `emitter.setMaxListeners(n)` or defaults to [EventEmitter.defaultMaxListeners](/openai-agents-js/openai/agents-core/classes/runtimeeventemitter/#defaultmaxlisteners). #### Returns [Section titled “Returns”](#returns-6) `number` #### Since [Section titled “Since”](#since-8) v1.0.0 #### Inherited from [Section titled “Inherited from”](#inherited-from-8) [`RuntimeEventEmitter`](/openai-agents-js/openai/agents-core/classes/runtimeeventemitter/).[`getMaxListeners`](/openai-agents-js/openai/agents-core/classes/runtimeeventemitter/#getmaxlisteners) *** ### listenerCount() [Section titled “listenerCount()”](#listenercount) ```ts listenerCount(eventName, listener?): number; ``` Returns the number of listeners listening for the event named `eventName`. If `listener` is provided, it will return how many times the listener is found in the list of the listeners of the event. #### Type Parameters [Section titled “Type Parameters”](#type-parameters-3) | Type Parameter | | -------------- | | `K` | #### Parameters [Section titled “Parameters”](#parameters-4) | Parameter | Type | Description | | ----------- | -------------------- | ---------------------------------------- | | `eventName` | `string` \| `symbol` | The name of the event being listened for | | `listener?` | `Function` | The event handler function | #### Returns [Section titled “Returns”](#returns-7) `number` #### Since [Section titled “Since”](#since-9) v3.2.0 #### Inherited from [Section titled “Inherited from”](#inherited-from-9) [`RuntimeEventEmitter`](/openai-agents-js/openai/agents-core/classes/runtimeeventemitter/).[`listenerCount`](/openai-agents-js/openai/agents-core/classes/runtimeeventemitter/#listenercount) *** ### listeners() [Section titled “listeners()”](#listeners) ```ts listeners(eventName): Function[]; ``` Returns a copy of the array of listeners for the event named `eventName`. ```js server.on('connection', (stream) => { console.log('someone connected!'); }); console.log(util.inspect(server.listeners('connection'))); // Prints: [ [Function] ] ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-4) | Type Parameter | | -------------- | | `K` | #### Parameters [Section titled “Parameters”](#parameters-5) | Parameter | Type | | ----------- | -------------------- | | `eventName` | `string` \| `symbol` | #### Returns [Section titled “Returns”](#returns-8) `Function`\[] #### Since [Section titled “Since”](#since-10) v0.1.26 #### Inherited from [Section titled “Inherited from”](#inherited-from-10) [`RuntimeEventEmitter`](/openai-agents-js/openai/agents-core/classes/runtimeeventemitter/).[`listeners`](/openai-agents-js/openai/agents-core/classes/runtimeeventemitter/#listeners) *** ### off() [Section titled “off()”](#off) ```ts off(eventName, listener): this; ``` Alias for `emitter.removeListener()`. #### Type Parameters [Section titled “Type Parameters”](#type-parameters-5) | Type Parameter | | -------------- | | `K` | #### Parameters [Section titled “Parameters”](#parameters-6) | Parameter | Type | | ----------- | -------------------- | | `eventName` | `string` \| `symbol` | | `listener` | (…`args`) => `void` | #### Returns [Section titled “Returns”](#returns-9) `this` #### Since [Section titled “Since”](#since-11) v10.0.0 #### Inherited from [Section titled “Inherited from”](#inherited-from-11) [`RuntimeEventEmitter`](/openai-agents-js/openai/agents-core/classes/runtimeeventemitter/).[`off`](/openai-agents-js/openai/agents-core/classes/runtimeeventemitter/#off) *** ### on() [Section titled “on()”](#on) ```ts on(eventName, listener): this; ``` Adds the `listener` function to the end of the listeners array for the event named `eventName`. No checks are made to see if the `listener` has already been added. Multiple calls passing the same combination of `eventName` and `listener` will result in the `listener` being added, and called, multiple times. ```js server.on('connection', (stream) => { console.log('someone connected!'); }); ``` Returns a reference to the `EventEmitter`, so that calls can be chained. By default, event listeners are invoked in the order they are added. The `emitter.prependListener()` method can be used as an alternative to add the event listener to the beginning of the listeners array. ```js import { EventEmitter } from 'node:events'; const myEE = new EventEmitter(); myEE.on('foo', () => console.log('a')); myEE.prependListener('foo', () => console.log('b')); myEE.emit('foo'); // Prints: // b // a ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-6) | Type Parameter | | -------------- | | `K` | #### Parameters [Section titled “Parameters”](#parameters-7) | Parameter | Type | Description | | ----------- | -------------------- | ---------------------- | | `eventName` | `string` \| `symbol` | The name of the event. | | `listener` | (…`args`) => `void` | The callback function | #### Returns [Section titled “Returns”](#returns-10) `this` #### Since [Section titled “Since”](#since-12) v0.1.101 #### Inherited from [Section titled “Inherited from”](#inherited-from-12) [`RuntimeEventEmitter`](/openai-agents-js/openai/agents-core/classes/runtimeeventemitter/).[`on`](/openai-agents-js/openai/agents-core/classes/runtimeeventemitter/#on) *** ### once() [Section titled “once()”](#once) ```ts once(eventName, listener): this; ``` Adds a **one-time** `listener` function for the event named `eventName`. The next time `eventName` is triggered, this listener is removed and then invoked. ```js server.once('connection', (stream) => { console.log('Ah, we have our first user!'); }); ``` Returns a reference to the `EventEmitter`, so that calls can be chained. By default, event listeners are invoked in the order they are added. The `emitter.prependOnceListener()` method can be used as an alternative to add the event listener to the beginning of the listeners array. ```js import { EventEmitter } from 'node:events'; const myEE = new EventEmitter(); myEE.once('foo', () => console.log('a')); myEE.prependOnceListener('foo', () => console.log('b')); myEE.emit('foo'); // Prints: // b // a ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-7) | Type Parameter | | -------------- | | `K` | #### Parameters [Section titled “Parameters”](#parameters-8) | Parameter | Type | Description | | ----------- | -------------------- | ---------------------- | | `eventName` | `string` \| `symbol` | The name of the event. | | `listener` | (…`args`) => `void` | The callback function | #### Returns [Section titled “Returns”](#returns-11) `this` #### Since [Section titled “Since”](#since-13) v0.3.0 #### Inherited from [Section titled “Inherited from”](#inherited-from-13) [`RuntimeEventEmitter`](/openai-agents-js/openai/agents-core/classes/runtimeeventemitter/).[`once`](/openai-agents-js/openai/agents-core/classes/runtimeeventemitter/#once) *** ### prependListener() [Section titled “prependListener()”](#prependlistener) ```ts prependListener(eventName, listener): this; ``` Adds the `listener` function to the *beginning* of the listeners array for the event named `eventName`. No checks are made to see if the `listener` has already been added. Multiple calls passing the same combination of `eventName` and `listener` will result in the `listener` being added, and called, multiple times. ```js server.prependListener('connection', (stream) => { console.log('someone connected!'); }); ``` Returns a reference to the `EventEmitter`, so that calls can be chained. #### Type Parameters [Section titled “Type Parameters”](#type-parameters-8) | Type Parameter | | -------------- | | `K` | #### Parameters [Section titled “Parameters”](#parameters-9) | Parameter | Type | Description | | ----------- | -------------------- | ---------------------- | | `eventName` | `string` \| `symbol` | The name of the event. | | `listener` | (…`args`) => `void` | The callback function | #### Returns [Section titled “Returns”](#returns-12) `this` #### Since [Section titled “Since”](#since-14) v6.0.0 #### Inherited from [Section titled “Inherited from”](#inherited-from-14) [`RuntimeEventEmitter`](/openai-agents-js/openai/agents-core/classes/runtimeeventemitter/).[`prependListener`](/openai-agents-js/openai/agents-core/classes/runtimeeventemitter/#prependlistener) *** ### prependOnceListener() [Section titled “prependOnceListener()”](#prependoncelistener) ```ts prependOnceListener(eventName, listener): this; ``` Adds a **one-time**`listener` function for the event named `eventName` to the *beginning* of the listeners array. The next time `eventName` is triggered, this listener is removed, and then invoked. ```js server.prependOnceListener('connection', (stream) => { console.log('Ah, we have our first user!'); }); ``` Returns a reference to the `EventEmitter`, so that calls can be chained. #### Type Parameters [Section titled “Type Parameters”](#type-parameters-9) | Type Parameter | | -------------- | | `K` | #### Parameters [Section titled “Parameters”](#parameters-10) | Parameter | Type | Description | | ----------- | -------------------- | ---------------------- | | `eventName` | `string` \| `symbol` | The name of the event. | | `listener` | (…`args`) => `void` | The callback function | #### Returns [Section titled “Returns”](#returns-13) `this` #### Since [Section titled “Since”](#since-15) v6.0.0 #### Inherited from [Section titled “Inherited from”](#inherited-from-15) [`RuntimeEventEmitter`](/openai-agents-js/openai/agents-core/classes/runtimeeventemitter/).[`prependOnceListener`](/openai-agents-js/openai/agents-core/classes/runtimeeventemitter/#prependoncelistener) *** ### rawListeners() [Section titled “rawListeners()”](#rawlisteners) ```ts rawListeners(eventName): Function[]; ``` Returns a copy of the array of listeners for the event named `eventName`, including any wrappers (such as those created by `.once()`). ```js import { EventEmitter } from 'node:events'; const emitter = new EventEmitter(); emitter.once('log', () => console.log('log once')); // Returns a new Array with a function `onceWrapper` which has a property // `listener` which contains the original listener bound above const listeners = emitter.rawListeners('log'); const logFnWrapper = listeners[0]; // Logs "log once" to the console and does not unbind the `once` event logFnWrapper.listener(); // Logs "log once" to the console and removes the listener logFnWrapper(); emitter.on('log', () => console.log('log persistently')); // Will return a new Array with a single function bound by `.on()` above const newListeners = emitter.rawListeners('log'); // Logs "log persistently" twice newListeners[0](); emitter.emit('log'); ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-10) | Type Parameter | | -------------- | | `K` | #### Parameters [Section titled “Parameters”](#parameters-11) | Parameter | Type | | ----------- | -------------------- | | `eventName` | `string` \| `symbol` | #### Returns [Section titled “Returns”](#returns-14) `Function`\[] #### Since [Section titled “Since”](#since-16) v9.4.0 #### Inherited from [Section titled “Inherited from”](#inherited-from-16) [`RuntimeEventEmitter`](/openai-agents-js/openai/agents-core/classes/runtimeeventemitter/).[`rawListeners`](/openai-agents-js/openai/agents-core/classes/runtimeeventemitter/#rawlisteners) *** ### removeAllListeners() [Section titled “removeAllListeners()”](#removealllisteners) ```ts removeAllListeners(eventName?): this; ``` Removes all listeners, or those of the specified `eventName`. It is bad practice to remove listeners added elsewhere in the code, particularly when the `EventEmitter` instance was created by some other component or module (e.g. sockets or file streams). Returns a reference to the `EventEmitter`, so that calls can be chained. #### Parameters [Section titled “Parameters”](#parameters-12) | Parameter | Type | | ------------ | -------------------- | | `eventName?` | `string` \| `symbol` | #### Returns [Section titled “Returns”](#returns-15) `this` #### Since [Section titled “Since”](#since-17) v0.1.26 #### Inherited from [Section titled “Inherited from”](#inherited-from-17) [`RuntimeEventEmitter`](/openai-agents-js/openai/agents-core/classes/runtimeeventemitter/).[`removeAllListeners`](/openai-agents-js/openai/agents-core/classes/runtimeeventemitter/#removealllisteners) *** ### removeListener() [Section titled “removeListener()”](#removelistener) ```ts removeListener(eventName, listener): this; ``` Removes the specified `listener` from the listener array for the event named `eventName`. ```js const callback = (stream) => { console.log('someone connected!'); }; server.on('connection', callback); // ... server.removeListener('connection', callback); ``` `removeListener()` will remove, at most, one instance of a listener from the listener array. If any single listener has been added multiple times to the listener array for the specified `eventName`, then `removeListener()` must be called multiple times to remove each instance. Once an event is emitted, all listeners attached to it at the time of emitting are called in order. This implies that any `removeListener()` or `removeAllListeners()` calls *after* emitting and *before* the last listener finishes execution will not remove them from`emit()` in progress. Subsequent events behave as expected. ```js import { EventEmitter } from 'node:events'; class MyEmitter extends EventEmitter {} const myEmitter = new MyEmitter(); const callbackA = () => { console.log('A'); myEmitter.removeListener('event', callbackB); }; const callbackB = () => { console.log('B'); }; myEmitter.on('event', callbackA); myEmitter.on('event', callbackB); // callbackA removes listener callbackB but it will still be called. // Internal listener array at time of emit [callbackA, callbackB] myEmitter.emit('event'); // Prints: // A // B // callbackB is now removed. // Internal listener array [callbackA] myEmitter.emit('event'); // Prints: // A ``` Because listeners are managed using an internal array, calling this will change the position indices of any listener registered *after* the listener being removed. This will not impact the order in which listeners are called, but it means that any copies of the listener array as returned by the `emitter.listeners()` method will need to be recreated. When a single function has been added as a handler multiple times for a single event (as in the example below), `removeListener()` will remove the most recently added instance. In the example the `once('ping')` listener is removed: ```js import { EventEmitter } from 'node:events'; const ee = new EventEmitter(); function pong() { console.log('pong'); } ee.on('ping', pong); ee.once('ping', pong); ee.removeListener('ping', pong); ee.emit('ping'); ee.emit('ping'); ``` Returns a reference to the `EventEmitter`, so that calls can be chained. #### Type Parameters [Section titled “Type Parameters”](#type-parameters-11) | Type Parameter | | -------------- | | `K` | #### Parameters [Section titled “Parameters”](#parameters-13) | Parameter | Type | | ----------- | -------------------- | | `eventName` | `string` \| `symbol` | | `listener` | (…`args`) => `void` | #### Returns [Section titled “Returns”](#returns-16) `this` #### Since [Section titled “Since”](#since-18) v0.1.26 #### Inherited from [Section titled “Inherited from”](#inherited-from-18) [`RuntimeEventEmitter`](/openai-agents-js/openai/agents-core/classes/runtimeeventemitter/).[`removeListener`](/openai-agents-js/openai/agents-core/classes/runtimeeventemitter/#removelistener) *** ### setMaxListeners() [Section titled “setMaxListeners()”](#setmaxlisteners) ```ts setMaxListeners(n): this; ``` By default `EventEmitter`s will print a warning if more than `10` listeners are added for a particular event. This is a useful default that helps finding memory leaks. The `emitter.setMaxListeners()` method allows the limit to be modified for this specific `EventEmitter` instance. The value can be set to `Infinity` (or `0`) to indicate an unlimited number of listeners. Returns a reference to the `EventEmitter`, so that calls can be chained. #### Parameters [Section titled “Parameters”](#parameters-14) | Parameter | Type | | --------- | -------- | | `n` | `number` | #### Returns [Section titled “Returns”](#returns-17) `this` #### Since [Section titled “Since”](#since-19) v0.3.5 #### Inherited from [Section titled “Inherited from”](#inherited-from-19) [`RuntimeEventEmitter`](/openai-agents-js/openai/agents-core/classes/runtimeeventemitter/).[`setMaxListeners`](/openai-agents-js/openai/agents-core/classes/runtimeeventemitter/#setmaxlisteners) *** ### addAbortListener() [Section titled “addAbortListener()”](#addabortlistener) ```ts static addAbortListener(signal, resource): Disposable; ``` Listens once to the `abort` event on the provided `signal`. Listening to the `abort` event on abort signals is unsafe and may lead to resource leaks since another third party with the signal can call `e.stopImmediatePropagation()`. Unfortunately Node.js cannot change this since it would violate the web standard. Additionally, the original API makes it easy to forget to remove listeners. This API allows safely using `AbortSignal`s in Node.js APIs by solving these two issues by listening to the event such that `stopImmediatePropagation` does not prevent the listener from running. Returns a disposable so that it may be unsubscribed from more easily. ```js import { addAbortListener } from 'node:events'; function example(signal) { let disposable; try { signal.addEventListener('abort', (e) => e.stopImmediatePropagation()); disposable = addAbortListener(signal, (e) => { // Do something when signal is aborted. }); } finally { disposable?.[Symbol.dispose](); } } ``` #### Parameters [Section titled “Parameters”](#parameters-15) | Parameter | Type | | ---------- | ------------------- | | `signal` | `AbortSignal` | | `resource` | (`event`) => `void` | #### Returns [Section titled “Returns”](#returns-18) `Disposable` Disposable that removes the `abort` listener. #### Since [Section titled “Since”](#since-20) v20.5.0 #### Inherited from [Section titled “Inherited from”](#inherited-from-20) [`RuntimeEventEmitter`](/openai-agents-js/openai/agents-core/classes/runtimeeventemitter/).[`addAbortListener`](/openai-agents-js/openai/agents-core/classes/runtimeeventemitter/#addabortlistener) *** ### getEventListeners() [Section titled “getEventListeners()”](#geteventlisteners) ```ts static getEventListeners(emitter, name): Function[]; ``` Returns a copy of the array of listeners for the event named `eventName`. For `EventEmitter`s this behaves exactly the same as calling `.listeners` on the emitter. For `EventTarget`s this is the only way to get the event listeners for the event target. This is useful for debugging and diagnostic purposes. ```js import { getEventListeners, EventEmitter } from 'node:events'; { const ee = new EventEmitter(); const listener = () => console.log('Events are fun'); ee.on('foo', listener); console.log(getEventListeners(ee, 'foo')); // [ [Function: listener] ] } { const et = new EventTarget(); const listener = () => console.log('Events are fun'); et.addEventListener('foo', listener); console.log(getEventListeners(et, 'foo')); // [ [Function: listener] ] } ``` #### Parameters [Section titled “Parameters”](#parameters-16) | Parameter | Type | | --------- | -------------------------------------------------- | | `emitter` | `EventTarget` \| `EventEmitter`<`DefaultEventMap`> | | `name` | `string` \| `symbol` | #### Returns [Section titled “Returns”](#returns-19) `Function`\[] #### Since [Section titled “Since”](#since-21) v15.2.0, v14.17.0 #### Inherited from [Section titled “Inherited from”](#inherited-from-21) [`RuntimeEventEmitter`](/openai-agents-js/openai/agents-core/classes/runtimeeventemitter/).[`getEventListeners`](/openai-agents-js/openai/agents-core/classes/runtimeeventemitter/#geteventlisteners) *** ### getMaxListeners() [Section titled “getMaxListeners()”](#getmaxlisteners-1) ```ts static getMaxListeners(emitter): number; ``` Returns the currently set max amount of listeners. For `EventEmitter`s this behaves exactly the same as calling `.getMaxListeners` on the emitter. For `EventTarget`s this is the only way to get the max event listeners for the event target. If the number of event handlers on a single EventTarget exceeds the max set, the EventTarget will print a warning. ```js import { getMaxListeners, setMaxListeners, EventEmitter } from 'node:events'; { const ee = new EventEmitter(); console.log(getMaxListeners(ee)); // 10 setMaxListeners(11, ee); console.log(getMaxListeners(ee)); // 11 } { const et = new EventTarget(); console.log(getMaxListeners(et)); // 10 setMaxListeners(11, et); console.log(getMaxListeners(et)); // 11 } ``` #### Parameters [Section titled “Parameters”](#parameters-17) | Parameter | Type | | --------- | -------------------------------------------------- | | `emitter` | `EventTarget` \| `EventEmitter`<`DefaultEventMap`> | #### Returns [Section titled “Returns”](#returns-20) `number` #### Since [Section titled “Since”](#since-22) v19.9.0 #### Inherited from [Section titled “Inherited from”](#inherited-from-22) [`RuntimeEventEmitter`](/openai-agents-js/openai/agents-core/classes/runtimeeventemitter/).[`getMaxListeners`](/openai-agents-js/openai/agents-core/classes/runtimeeventemitter/#getmaxlisteners-1) *** ### ~~listenerCount()~~ [Section titled “listenerCount()”](#listenercount-1) ```ts static listenerCount(emitter, eventName): number; ``` A class method that returns the number of listeners for the given `eventName` registered on the given `emitter`. ```js import { EventEmitter, listenerCount } from 'node:events'; const myEmitter = new EventEmitter(); myEmitter.on('event', () => {}); myEmitter.on('event', () => {}); console.log(listenerCount(myEmitter, 'event')); // Prints: 2 ``` Deprecated Since v3.2.0 - Use `listenerCount` instead. #### Parameters [Section titled “Parameters”](#parameters-18) | Parameter | Type | Description | | ----------- | -------------------- | -------------------- | | `emitter` | `EventEmitter` | The emitter to query | | `eventName` | `string` \| `symbol` | The event name | #### Returns [Section titled “Returns”](#returns-21) `number` #### Since [Section titled “Since”](#since-23) v0.9.12 #### Inherited from [Section titled “Inherited from”](#inherited-from-23) [`RuntimeEventEmitter`](/openai-agents-js/openai/agents-core/classes/runtimeeventemitter/).[`listenerCount`](/openai-agents-js/openai/agents-core/classes/runtimeeventemitter/#listenercount-1) *** ### on() [Section titled “on()”](#on-1) #### Call Signature [Section titled “Call Signature”](#call-signature) ```ts static on( emitter, eventName, options?): AsyncIterator; ``` ```js import { on, EventEmitter } from 'node:events'; import process from 'node:process'; const ee = new EventEmitter(); // Emit later on process.nextTick(() => { ee.emit('foo', 'bar'); ee.emit('foo', 42); }); for await (const event of on(ee, 'foo')) { // The execution of this inner block is synchronous and it // processes one event at a time (even with await). Do not use // if concurrent execution is required. console.log(event); // prints ['bar'] [42] } // Unreachable here ``` Returns an `AsyncIterator` that iterates `eventName` events. It will throw if the `EventEmitter` emits `'error'`. It removes all listeners when exiting the loop. The `value` returned by each iteration is an array composed of the emitted event arguments. An `AbortSignal` can be used to cancel waiting on events: ```js import { on, EventEmitter } from 'node:events'; import process from 'node:process'; const ac = new AbortController(); (async () => { const ee = new EventEmitter(); // Emit later on process.nextTick(() => { ee.emit('foo', 'bar'); ee.emit('foo', 42); }); for await (const event of on(ee, 'foo', { signal: ac.signal })) { // The execution of this inner block is synchronous and it // processes one event at a time (even with await). Do not use // if concurrent execution is required. console.log(event); // prints ['bar'] [42] } // Unreachable here })(); process.nextTick(() => ac.abort()); ``` Use the `close` option to specify an array of event names that will end the iteration: ```js import { on, EventEmitter } from 'node:events'; import process from 'node:process'; const ee = new EventEmitter(); // Emit later on process.nextTick(() => { ee.emit('foo', 'bar'); ee.emit('foo', 42); ee.emit('close'); }); for await (const event of on(ee, 'foo', { close: ['close'] })) { console.log(event); // prints ['bar'] [42] } // the loop will exit after 'close' is emitted console.log('done'); // prints 'done' ``` ##### Parameters [Section titled “Parameters”](#parameters-19) | Parameter | Type | | ----------- | ----------------------------------- | | `emitter` | `EventEmitter` | | `eventName` | `string` \| `symbol` | | `options?` | `StaticEventEmitterIteratorOptions` | ##### Returns [Section titled “Returns”](#returns-22) `AsyncIterator`<`any`\[]> An `AsyncIterator` that iterates `eventName` events emitted by the `emitter` ##### Since [Section titled “Since”](#since-24) v13.6.0, v12.16.0 ##### Inherited from [Section titled “Inherited from”](#inherited-from-24) [`RuntimeEventEmitter`](/openai-agents-js/openai/agents-core/classes/runtimeeventemitter/).[`on`](/openai-agents-js/openai/agents-core/classes/runtimeeventemitter/#on-1) #### Call Signature [Section titled “Call Signature”](#call-signature-1) ```ts static on( emitter, eventName, options?): AsyncIterator; ``` ```js import { on, EventEmitter } from 'node:events'; import process from 'node:process'; const ee = new EventEmitter(); // Emit later on process.nextTick(() => { ee.emit('foo', 'bar'); ee.emit('foo', 42); }); for await (const event of on(ee, 'foo')) { // The execution of this inner block is synchronous and it // processes one event at a time (even with await). Do not use // if concurrent execution is required. console.log(event); // prints ['bar'] [42] } // Unreachable here ``` Returns an `AsyncIterator` that iterates `eventName` events. It will throw if the `EventEmitter` emits `'error'`. It removes all listeners when exiting the loop. The `value` returned by each iteration is an array composed of the emitted event arguments. An `AbortSignal` can be used to cancel waiting on events: ```js import { on, EventEmitter } from 'node:events'; import process from 'node:process'; const ac = new AbortController(); (async () => { const ee = new EventEmitter(); // Emit later on process.nextTick(() => { ee.emit('foo', 'bar'); ee.emit('foo', 42); }); for await (const event of on(ee, 'foo', { signal: ac.signal })) { // The execution of this inner block is synchronous and it // processes one event at a time (even with await). Do not use // if concurrent execution is required. console.log(event); // prints ['bar'] [42] } // Unreachable here })(); process.nextTick(() => ac.abort()); ``` Use the `close` option to specify an array of event names that will end the iteration: ```js import { on, EventEmitter } from 'node:events'; import process from 'node:process'; const ee = new EventEmitter(); // Emit later on process.nextTick(() => { ee.emit('foo', 'bar'); ee.emit('foo', 42); ee.emit('close'); }); for await (const event of on(ee, 'foo', { close: ['close'] })) { console.log(event); // prints ['bar'] [42] } // the loop will exit after 'close' is emitted console.log('done'); // prints 'done' ``` ##### Parameters [Section titled “Parameters”](#parameters-20) | Parameter | Type | | ----------- | ----------------------------------- | | `emitter` | `EventTarget` | | `eventName` | `string` | | `options?` | `StaticEventEmitterIteratorOptions` | ##### Returns [Section titled “Returns”](#returns-23) `AsyncIterator`<`any`\[]> An `AsyncIterator` that iterates `eventName` events emitted by the `emitter` ##### Since [Section titled “Since”](#since-25) v13.6.0, v12.16.0 ##### Inherited from [Section titled “Inherited from”](#inherited-from-25) [`RuntimeEventEmitter`](/openai-agents-js/openai/agents-core/classes/runtimeeventemitter/).[`on`](/openai-agents-js/openai/agents-core/classes/runtimeeventemitter/#on-1) *** ### once() [Section titled “once()”](#once-1) #### Call Signature [Section titled “Call Signature”](#call-signature-2) ```ts static once( emitter, eventName, options?): Promise; ``` Creates a `Promise` that is fulfilled when the `EventEmitter` emits the given event or that is rejected if the `EventEmitter` emits `'error'` while waiting. The `Promise` will resolve with an array of all the arguments emitted to the given event. This method is intentionally generic and works with the web platform [EventTarget](https://dom.spec.whatwg.org/#interface-eventtarget) interface, which has no special`'error'` event semantics and does not listen to the `'error'` event. ```js import { once, EventEmitter } from 'node:events'; import process from 'node:process'; const ee = new EventEmitter(); process.nextTick(() => { ee.emit('myevent', 42); }); const [value] = await once(ee, 'myevent'); console.log(value); const err = new Error('kaboom'); process.nextTick(() => { ee.emit('error', err); }); try { await once(ee, 'myevent'); } catch (err) { console.error('error happened', err); } ``` The special handling of the `'error'` event is only used when `events.once()` is used to wait for another event. If `events.once()` is used to wait for the ‘`error'` event itself, then it is treated as any other kind of event without special handling: ```js import { EventEmitter, once } from 'node:events'; const ee = new EventEmitter(); once(ee, 'error') .then(([err]) => console.log('ok', err.message)) .catch((err) => console.error('error', err.message)); ee.emit('error', new Error('boom')); // Prints: ok boom ``` An `AbortSignal` can be used to cancel waiting for the event: ```js import { EventEmitter, once } from 'node:events'; const ee = new EventEmitter(); const ac = new AbortController(); async function foo(emitter, event, signal) { try { await once(emitter, event, { signal }); console.log('event emitted!'); } catch (error) { if (error.name === 'AbortError') { console.error('Waiting for the event was canceled!'); } else { console.error('There was an error', error.message); } } } foo(ee, 'foo', ac.signal); ac.abort(); // Abort waiting for the event ee.emit('foo'); // Prints: Waiting for the event was canceled! ``` ##### Parameters [Section titled “Parameters”](#parameters-21) | Parameter | Type | | ----------- | --------------------------- | | `emitter` | `EventEmitter` | | `eventName` | `string` \| `symbol` | | `options?` | `StaticEventEmitterOptions` | ##### Returns [Section titled “Returns”](#returns-24) `Promise`<`any`\[]> ##### Since [Section titled “Since”](#since-26) v11.13.0, v10.16.0 ##### Inherited from [Section titled “Inherited from”](#inherited-from-26) [`RuntimeEventEmitter`](/openai-agents-js/openai/agents-core/classes/runtimeeventemitter/).[`once`](/openai-agents-js/openai/agents-core/classes/runtimeeventemitter/#once-1) #### Call Signature [Section titled “Call Signature”](#call-signature-3) ```ts static once( emitter, eventName, options?): Promise; ``` Creates a `Promise` that is fulfilled when the `EventEmitter` emits the given event or that is rejected if the `EventEmitter` emits `'error'` while waiting. The `Promise` will resolve with an array of all the arguments emitted to the given event. This method is intentionally generic and works with the web platform [EventTarget](https://dom.spec.whatwg.org/#interface-eventtarget) interface, which has no special`'error'` event semantics and does not listen to the `'error'` event. ```js import { once, EventEmitter } from 'node:events'; import process from 'node:process'; const ee = new EventEmitter(); process.nextTick(() => { ee.emit('myevent', 42); }); const [value] = await once(ee, 'myevent'); console.log(value); const err = new Error('kaboom'); process.nextTick(() => { ee.emit('error', err); }); try { await once(ee, 'myevent'); } catch (err) { console.error('error happened', err); } ``` The special handling of the `'error'` event is only used when `events.once()` is used to wait for another event. If `events.once()` is used to wait for the ‘`error'` event itself, then it is treated as any other kind of event without special handling: ```js import { EventEmitter, once } from 'node:events'; const ee = new EventEmitter(); once(ee, 'error') .then(([err]) => console.log('ok', err.message)) .catch((err) => console.error('error', err.message)); ee.emit('error', new Error('boom')); // Prints: ok boom ``` An `AbortSignal` can be used to cancel waiting for the event: ```js import { EventEmitter, once } from 'node:events'; const ee = new EventEmitter(); const ac = new AbortController(); async function foo(emitter, event, signal) { try { await once(emitter, event, { signal }); console.log('event emitted!'); } catch (error) { if (error.name === 'AbortError') { console.error('Waiting for the event was canceled!'); } else { console.error('There was an error', error.message); } } } foo(ee, 'foo', ac.signal); ac.abort(); // Abort waiting for the event ee.emit('foo'); // Prints: Waiting for the event was canceled! ``` ##### Parameters [Section titled “Parameters”](#parameters-22) | Parameter | Type | | ----------- | --------------------------- | | `emitter` | `EventTarget` | | `eventName` | `string` | | `options?` | `StaticEventEmitterOptions` | ##### Returns [Section titled “Returns”](#returns-25) `Promise`<`any`\[]> ##### Since [Section titled “Since”](#since-27) v11.13.0, v10.16.0 ##### Inherited from [Section titled “Inherited from”](#inherited-from-27) [`RuntimeEventEmitter`](/openai-agents-js/openai/agents-core/classes/runtimeeventemitter/).[`once`](/openai-agents-js/openai/agents-core/classes/runtimeeventemitter/#once-1) *** ### setMaxListeners() [Section titled “setMaxListeners()”](#setmaxlisteners-1) ```ts static setMaxListeners(n?, ...eventTargets): void; ``` ```js import { setMaxListeners, EventEmitter } from 'node:events'; const target = new EventTarget(); const emitter = new EventEmitter(); setMaxListeners(5, target, emitter); ``` #### Parameters [Section titled “Parameters”](#parameters-23) | Parameter | Type | Description | | ---------------- | ------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `n?` | `number` | A non-negative number. The maximum number of listeners per `EventTarget` event. | | …`eventTargets?` | (`EventTarget` \| `EventEmitter`<`DefaultEventMap`>)\[] | Zero or more {EventTarget} or {EventEmitter} instances. If none are specified, `n` is set as the default max for all newly created {EventTarget} and {EventEmitter} objects. | #### Returns [Section titled “Returns”](#returns-26) `void` #### Since [Section titled “Since”](#since-28) v15.4.0 #### Inherited from [Section titled “Inherited from”](#inherited-from-28) [`RuntimeEventEmitter`](/openai-agents-js/openai/agents-core/classes/runtimeeventemitter/).[`setMaxListeners`](/openai-agents-js/openai/agents-core/classes/runtimeeventemitter/#setmaxlisteners-1) # Abortable ## Properties [Section titled “Properties”](#properties) ### signal? [Section titled “signal?”](#signal) ```ts optional signal?: AbortSignal; ``` When provided the corresponding `AbortController` can be used to cancel an asynchronous action. # EventEmitterAsyncResourceOptions ## Extends [Section titled “Extends”](#extends) * `AsyncResourceOptions`.`EventEmitterOptions` ## Properties [Section titled “Properties”](#properties) ### captureRejections? [Section titled “captureRejections?”](#capturerejections) ```ts optional captureRejections?: boolean; ``` Enables automatic capturing of promise rejection. #### Inherited from [Section titled “Inherited from”](#inherited-from) ```ts EventEmitterOptions.captureRejections ``` *** ### name? [Section titled “name?”](#name) ```ts optional name?: string; ``` The type of async event, this is required when instantiating `EventEmitterAsyncResource` directly rather than as a child class. #### Default [Section titled “Default”](#default) ```ts new.target.name if instantiated as a child class. ``` *** ### requireManualDestroy? [Section titled “requireManualDestroy?”](#requiremanualdestroy) ```ts optional requireManualDestroy?: boolean; ``` Disables automatic `emitDestroy` when the object is garbage collected. This usually does not need to be set (even if `emitDestroy` is called manually), unless the resource’s `asyncId` is retrieved and the sensitive API’s `emitDestroy` is called with it. #### Default [Section titled “Default”](#default-1) ```ts false ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-1) ```ts AsyncResourceOptions.requireManualDestroy ``` *** ### triggerAsyncId? [Section titled “triggerAsyncId?”](#triggerasyncid) ```ts optional triggerAsyncId?: number; ``` The ID of the execution context that created this async event. #### Default [Section titled “Default”](#default-2) ```ts executionAsyncId() ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-2) ```ts AsyncResourceOptions.triggerAsyncId ``` # EventEmitterReferencingAsyncResource ## Extends [Section titled “Extends”](#extends) * `AsyncResource` ## Properties [Section titled “Properties”](#properties) ### eventEmitter [Section titled “eventEmitter”](#eventemitter) ```ts readonly eventEmitter: EventEmitterAsyncResource; ``` ## Methods [Section titled “Methods”](#methods) ### asyncId() [Section titled “asyncId()”](#asyncid) ```ts asyncId(): number; ``` #### Returns [Section titled “Returns”](#returns) `number` The unique `asyncId` assigned to the resource. #### Inherited from [Section titled “Inherited from”](#inherited-from) ```ts AsyncResource.asyncId ``` *** ### bind() [Section titled “bind()”](#bind) ```ts bind(fn): Func; ``` Binds the given function to execute to this `AsyncResource`’s scope. #### Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | ----------------------------------- | | `Func` *extends* (…`args`) => `any` | #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | --------- | ------ | ---------------------------------------------------- | | `fn` | `Func` | The function to bind to the current `AsyncResource`. | #### Returns [Section titled “Returns”](#returns-1) `Func` #### Since [Section titled “Since”](#since) v14.8.0, v12.19.0 #### Inherited from [Section titled “Inherited from”](#inherited-from-1) ```ts AsyncResource.bind ``` *** ### emitDestroy() [Section titled “emitDestroy()”](#emitdestroy) ```ts emitDestroy(): this; ``` Call all `destroy` hooks. This should only ever be called once. An error will be thrown if it is called more than once. This **must** be manually called. If the resource is left to be collected by the GC then the `destroy` hooks will never be called. #### Returns [Section titled “Returns”](#returns-2) `this` A reference to `asyncResource`. #### Inherited from [Section titled “Inherited from”](#inherited-from-2) ```ts AsyncResource.emitDestroy ``` *** ### runInAsyncScope() [Section titled “runInAsyncScope()”](#runinasyncscope) ```ts runInAsyncScope( fn, thisArg?, ... args): Result; ``` Call the provided function with the provided arguments in the execution context of the async resource. This will establish the context, trigger the AsyncHooks before callbacks, call the function, trigger the AsyncHooks after callbacks, and then restore the original execution context. #### Type Parameters [Section titled “Type Parameters”](#type-parameters-1) | Type Parameter | | -------------- | | `This` | | `Result` | #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | Description | | ---------- | ----------------------------- | --------------------------------------------------------------------- | | `fn` | (`this`, …`args`) => `Result` | The function to call in the execution context of this async resource. | | `thisArg?` | `This` | The receiver to be used for the function call. | | …`args?` | `any`\[] | Optional arguments to pass to the function. | #### Returns [Section titled “Returns”](#returns-3) `Result` #### Since [Section titled “Since”](#since-1) v9.6.0 #### Inherited from [Section titled “Inherited from”](#inherited-from-3) ```ts AsyncResource.runInAsyncScope ``` *** ### triggerAsyncId() [Section titled “triggerAsyncId()”](#triggerasyncid) ```ts triggerAsyncId(): number; ``` #### Returns [Section titled “Returns”](#returns-4) `number` The same `triggerAsyncId` that is passed to the `AsyncResource` constructor. #### Inherited from [Section titled “Inherited from”](#inherited-from-4) ```ts AsyncResource.triggerAsyncId ``` # NodeEventTarget The `NodeEventTarget` is a Node.js-specific extension to `EventTarget` that emulates a subset of the `EventEmitter` API. ## Since [Section titled “Since”](#since) v14.5.0 ## Extends [Section titled “Extends”](#extends) * `EventTarget` ## Methods [Section titled “Methods”](#methods) ### addEventListener() [Section titled “addEventListener()”](#addeventlistener) ```ts addEventListener( type, callback, options?): void; ``` The **`addEventListener()`** method of the EventTarget interface sets up a function that will be called whenever the specified event is delivered to the target. [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventTarget/addEventListener) #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ---------- | ---------------------------------------------- | | `type` | `string` | | `callback` | `EventListenerOrEventListenerObject` \| `null` | | `options?` | `boolean` \| `AddEventListenerOptions` | #### Returns [Section titled “Returns”](#returns) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from) ```ts EventTarget.addEventListener ``` *** ### addListener() [Section titled “addListener()”](#addlistener) ```ts addListener(type, listener): this; ``` Node.js-specific extension to the `EventTarget` class that emulates the equivalent `EventEmitter` API. The only difference between `addListener()` and `addEventListener()` is that `addListener()` will return a reference to the `EventTarget`. #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | ---------- | ----------------- | | `type` | `string` | | `listener` | (`arg`) => `void` | #### Returns [Section titled “Returns”](#returns-1) `this` #### Since [Section titled “Since”](#since-1) v14.5.0 *** ### dispatchEvent() [Section titled “dispatchEvent()”](#dispatchevent) ```ts dispatchEvent(event): boolean; ``` The **`dispatchEvent()`** method of the EventTarget sends an Event to the object, (synchronously) invoking the affected event listeners in the appropriate order. [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventTarget/dispatchEvent) #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | --------- | ------- | | `event` | `Event` | #### Returns [Section titled “Returns”](#returns-2) `boolean` #### Inherited from [Section titled “Inherited from”](#inherited-from-1) ```ts EventTarget.dispatchEvent ``` *** ### emit() [Section titled “emit()”](#emit) ```ts emit(type, arg): boolean; ``` Node.js-specific extension to the `EventTarget` class that dispatches the `arg` to the list of handlers for `type`. #### Parameters [Section titled “Parameters”](#parameters-3) | Parameter | Type | | --------- | -------- | | `type` | `string` | | `arg` | `any` | #### Returns [Section titled “Returns”](#returns-3) `boolean` `true` if event listeners registered for the `type` exist, otherwise `false`. #### Since [Section titled “Since”](#since-2) v15.2.0 *** ### eventNames() [Section titled “eventNames()”](#eventnames) ```ts eventNames(): string[]; ``` Node.js-specific extension to the `EventTarget` class that returns an array of event `type` names for which event listeners are registered. #### Returns [Section titled “Returns”](#returns-4) `string`\[] #### Since [Section titled “Since”](#since-3) 14.5.0 *** ### getMaxListeners() [Section titled “getMaxListeners()”](#getmaxlisteners) ```ts getMaxListeners(): number; ``` Node.js-specific extension to the `EventTarget` class that returns the number of max event listeners. #### Returns [Section titled “Returns”](#returns-5) `number` #### Since [Section titled “Since”](#since-4) v14.5.0 *** ### listenerCount() [Section titled “listenerCount()”](#listenercount) ```ts listenerCount(type): number; ``` Node.js-specific extension to the `EventTarget` class that returns the number of event listeners registered for the `type`. #### Parameters [Section titled “Parameters”](#parameters-4) | Parameter | Type | | --------- | -------- | | `type` | `string` | #### Returns [Section titled “Returns”](#returns-6) `number` #### Since [Section titled “Since”](#since-5) v14.5.0 *** ### off() [Section titled “off()”](#off) ```ts off( type, listener, options?): this; ``` Node.js-specific alias for `eventTarget.removeEventListener()`. #### Parameters [Section titled “Parameters”](#parameters-5) | Parameter | Type | | ---------- | ---------------------- | | `type` | `string` | | `listener` | (`arg`) => `void` | | `options?` | `EventListenerOptions` | #### Returns [Section titled “Returns”](#returns-7) `this` #### Since [Section titled “Since”](#since-6) v14.5.0 *** ### on() [Section titled “on()”](#on) ```ts on(type, listener): this; ``` Node.js-specific alias for `eventTarget.addEventListener()`. #### Parameters [Section titled “Parameters”](#parameters-6) | Parameter | Type | | ---------- | ----------------- | | `type` | `string` | | `listener` | (`arg`) => `void` | #### Returns [Section titled “Returns”](#returns-8) `this` #### Since [Section titled “Since”](#since-7) v14.5.0 *** ### once() [Section titled “once()”](#once) ```ts once(type, listener): this; ``` Node.js-specific extension to the `EventTarget` class that adds a `once` listener for the given event `type`. This is equivalent to calling `on` with the `once` option set to `true`. #### Parameters [Section titled “Parameters”](#parameters-7) | Parameter | Type | | ---------- | ----------------- | | `type` | `string` | | `listener` | (`arg`) => `void` | #### Returns [Section titled “Returns”](#returns-9) `this` #### Since [Section titled “Since”](#since-8) v14.5.0 *** ### removeAllListeners() [Section titled “removeAllListeners()”](#removealllisteners) ```ts removeAllListeners(type?): this; ``` Node.js-specific extension to the `EventTarget` class. If `type` is specified, removes all registered listeners for `type`, otherwise removes all registered listeners. #### Parameters [Section titled “Parameters”](#parameters-8) | Parameter | Type | | --------- | -------- | | `type?` | `string` | #### Returns [Section titled “Returns”](#returns-10) `this` #### Since [Section titled “Since”](#since-9) v14.5.0 *** ### removeEventListener() [Section titled “removeEventListener()”](#removeeventlistener) ```ts removeEventListener( type, callback, options?): void; ``` The **`removeEventListener()`** method of the EventTarget interface removes an event listener previously registered with EventTarget.addEventListener() from the target. [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventTarget/removeEventListener) #### Parameters [Section titled “Parameters”](#parameters-9) | Parameter | Type | | ---------- | ---------------------------------------------- | | `type` | `string` | | `callback` | `EventListenerOrEventListenerObject` \| `null` | | `options?` | `boolean` \| `EventListenerOptions` | #### Returns [Section titled “Returns”](#returns-11) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-2) ```ts EventTarget.removeEventListener ``` *** ### removeListener() [Section titled “removeListener()”](#removelistener) ```ts removeListener( type, listener, options?): this; ``` Node.js-specific extension to the `EventTarget` class that removes the `listener` for the given `type`. The only difference between `removeListener()` and `removeEventListener()` is that `removeListener()` will return a reference to the `EventTarget`. #### Parameters [Section titled “Parameters”](#parameters-10) | Parameter | Type | | ---------- | ---------------------- | | `type` | `string` | | `listener` | (`arg`) => `void` | | `options?` | `EventListenerOptions` | #### Returns [Section titled “Returns”](#returns-12) `this` #### Since [Section titled “Since”](#since-10) v14.5.0 *** ### setMaxListeners() [Section titled “setMaxListeners()”](#setmaxlisteners) ```ts setMaxListeners(n): void; ``` Node.js-specific extension to the `EventTarget` class that sets the number of max event listeners as `n`. #### Parameters [Section titled “Parameters”](#parameters-11) | Parameter | Type | | --------- | -------- | | `n` | `number` | #### Returns [Section titled “Returns”](#returns-13) `void` #### Since [Section titled “Since”](#since-11) v14.5.0 # @openai/agents-core ## Namespaces [Section titled “Namespaces”](#namespaces) * [protocol](/openai-agents-js/openai/agents-core/openai/namespaces/protocol/readme/) * [RuntimeEventEmitter](/openai-agents-js/openai/agents-core/openai/namespaces/runtimeeventemitter/readme/) ## Classes [Section titled “Classes”](#classes) * [Agent](/openai-agents-js/openai/agents-core/classes/agent/) * [AgentHooks](/openai-agents-js/openai/agents-core/classes/agenthooks/) * [AgentsError](/openai-agents-js/openai/agents-core/classes/agentserror/) * [BatchTraceProcessor](/openai-agents-js/openai/agents-core/classes/batchtraceprocessor/) * [ConsoleSpanExporter](/openai-agents-js/openai/agents-core/classes/consolespanexporter/) * [GuardrailExecutionError](/openai-agents-js/openai/agents-core/classes/guardrailexecutionerror/) * [Handoff](/openai-agents-js/openai/agents-core/classes/handoff/) * [InputGuardrailTripwireTriggered](/openai-agents-js/openai/agents-core/classes/inputguardrailtripwiretriggered/) * [MaxTurnsExceededError](/openai-agents-js/openai/agents-core/classes/maxturnsexceedederror/) * [MCPServers](/openai-agents-js/openai/agents-core/classes/mcpservers/) * [MCPServerSSE](/openai-agents-js/openai/agents-core/classes/mcpserversse/) * [MCPServerStdio](/openai-agents-js/openai/agents-core/classes/mcpserverstdio/) * [MCPServerStreamableHttp](/openai-agents-js/openai/agents-core/classes/mcpserverstreamablehttp/) * [MemorySession](/openai-agents-js/openai/agents-core/classes/memorysession/) * [ModelBehaviorError](/openai-agents-js/openai/agents-core/classes/modelbehaviorerror/) * [ModelRefusalError](/openai-agents-js/openai/agents-core/classes/modelrefusalerror/) * [NoopSpan](/openai-agents-js/openai/agents-core/classes/noopspan/) * [NoopTrace](/openai-agents-js/openai/agents-core/classes/nooptrace/) * [OutputGuardrailTripwireTriggered](/openai-agents-js/openai/agents-core/classes/outputguardrailtripwiretriggered/) * [RequestUsage](/openai-agents-js/openai/agents-core/classes/requestusage/) * [RunAgentUpdatedStreamEvent](/openai-agents-js/openai/agents-core/classes/runagentupdatedstreamevent/) * [RunContext](/openai-agents-js/openai/agents-core/classes/runcontext/) * [RunHandoffCallItem](/openai-agents-js/openai/agents-core/classes/runhandoffcallitem/) * [RunHandoffOutputItem](/openai-agents-js/openai/agents-core/classes/runhandoffoutputitem/) * [RunItemStreamEvent](/openai-agents-js/openai/agents-core/classes/runitemstreamevent/) * [RunMessageOutputItem](/openai-agents-js/openai/agents-core/classes/runmessageoutputitem/) * [Runner](/openai-agents-js/openai/agents-core/classes/runner/) * [RunRawModelStreamEvent](/openai-agents-js/openai/agents-core/classes/runrawmodelstreamevent/) * [RunReasoningItem](/openai-agents-js/openai/agents-core/classes/runreasoningitem/) * [RunResult](/openai-agents-js/openai/agents-core/classes/runresult/) * [RunState](/openai-agents-js/openai/agents-core/classes/runstate/) * [RuntimeEventEmitter](/openai-agents-js/openai/agents-core/classes/runtimeeventemitter/) * [RunToolApprovalItem](/openai-agents-js/openai/agents-core/classes/runtoolapprovalitem/) * [RunToolCallItem](/openai-agents-js/openai/agents-core/classes/runtoolcallitem/) * [RunToolCallOutputItem](/openai-agents-js/openai/agents-core/classes/runtoolcalloutputitem/) * [RunToolSearchCallItem](/openai-agents-js/openai/agents-core/classes/runtoolsearchcallitem/) * [RunToolSearchOutputItem](/openai-agents-js/openai/agents-core/classes/runtoolsearchoutputitem/) * [Span](/openai-agents-js/openai/agents-core/classes/span/) * [StreamedRunResult](/openai-agents-js/openai/agents-core/classes/streamedrunresult/) * [SystemError](/openai-agents-js/openai/agents-core/classes/systemerror/) * [ToolCallError](/openai-agents-js/openai/agents-core/classes/toolcallerror/) * [ToolInputGuardrailTripwireTriggered](/openai-agents-js/openai/agents-core/classes/toolinputguardrailtripwiretriggered/) * [ToolOutputGuardrailTripwireTriggered](/openai-agents-js/openai/agents-core/classes/tooloutputguardrailtripwiretriggered/) * [ToolTimeoutError](/openai-agents-js/openai/agents-core/classes/tooltimeouterror/) * [Trace](/openai-agents-js/openai/agents-core/classes/trace/) * [TraceProvider](/openai-agents-js/openai/agents-core/classes/traceprovider/) * [Usage](/openai-agents-js/openai/agents-core/classes/usage/) * [UserError](/openai-agents-js/openai/agents-core/classes/usererror/) ## Interfaces [Section titled “Interfaces”](#interfaces) * [AgentConfiguration](/openai-agents-js/openai/agents-core/interfaces/agentconfiguration/) * [Editor](/openai-agents-js/openai/agents-core/interfaces/editor/) * [GuardrailFunctionOutput](/openai-agents-js/openai/agents-core/interfaces/guardrailfunctionoutput/) * [InputGuardrail](/openai-agents-js/openai/agents-core/interfaces/inputguardrail/) * [InputGuardrailFunctionArgs](/openai-agents-js/openai/agents-core/interfaces/inputguardrailfunctionargs/) * [InputGuardrailMetadata](/openai-agents-js/openai/agents-core/interfaces/inputguardrailmetadata/) * [InputGuardrailResult](/openai-agents-js/openai/agents-core/interfaces/inputguardrailresult/) * [MCPBlobResourceContent](/openai-agents-js/openai/agents-core/interfaces/mcpblobresourcecontent/) * [MCPListResourcesParams](/openai-agents-js/openai/agents-core/interfaces/mcplistresourcesparams/) * [MCPListResourcesResult](/openai-agents-js/openai/agents-core/interfaces/mcplistresourcesresult/) * [MCPListResourceTemplatesResult](/openai-agents-js/openai/agents-core/interfaces/mcplistresourcetemplatesresult/) * [MCPReadResourceResult](/openai-agents-js/openai/agents-core/interfaces/mcpreadresourceresult/) * [MCPResource](/openai-agents-js/openai/agents-core/interfaces/mcpresource/) * [MCPResourceTemplate](/openai-agents-js/openai/agents-core/interfaces/mcpresourcetemplate/) * [MCPServer](/openai-agents-js/openai/agents-core/interfaces/mcpserver/) * [MCPServerWithResources](/openai-agents-js/openai/agents-core/interfaces/mcpserverwithresources/) * [MCPTextResourceContent](/openai-agents-js/openai/agents-core/interfaces/mcptextresourcecontent/) * [MCPToolFilterContext](/openai-agents-js/openai/agents-core/interfaces/mcptoolfiltercontext/) * [MCPToolFilterStatic](/openai-agents-js/openai/agents-core/interfaces/mcptoolfilterstatic/) * [MCPToolMetaContext](/openai-agents-js/openai/agents-core/interfaces/mcptoolmetacontext/) * [Model](/openai-agents-js/openai/agents-core/interfaces/model/) * [ModelProvider](/openai-agents-js/openai/agents-core/interfaces/modelprovider/) * [OpenAIResponsesCompactionAwareSession](/openai-agents-js/openai/agents-core/interfaces/openairesponsescompactionawaresession/) * [OutputGuardrail](/openai-agents-js/openai/agents-core/interfaces/outputguardrail/) * [OutputGuardrailDefinition](/openai-agents-js/openai/agents-core/interfaces/outputguardraildefinition/) * [OutputGuardrailFunctionArgs](/openai-agents-js/openai/agents-core/interfaces/outputguardrailfunctionargs/) * [OutputGuardrailMetadata](/openai-agents-js/openai/agents-core/interfaces/outputguardrailmetadata/) * [OutputGuardrailResult](/openai-agents-js/openai/agents-core/interfaces/outputguardrailresult/) * [Session](/openai-agents-js/openai/agents-core/interfaces/session/) * [SessionHistoryRewriteAwareSession](/openai-agents-js/openai/agents-core/interfaces/sessionhistoryrewriteawaresession/) * [Shell](/openai-agents-js/openai/agents-core/interfaces/shell/) * [ToolGuardrailFunctionOutput](/openai-agents-js/openai/agents-core/interfaces/toolguardrailfunctionoutput/) * [ToolGuardrailMetadata](/openai-agents-js/openai/agents-core/interfaces/toolguardrailmetadata/) * [ToolInputGuardrailData](/openai-agents-js/openai/agents-core/interfaces/toolinputguardraildata/) * [ToolInputGuardrailDefinition](/openai-agents-js/openai/agents-core/interfaces/toolinputguardraildefinition/) * [ToolInputGuardrailResult](/openai-agents-js/openai/agents-core/interfaces/toolinputguardrailresult/) * [ToolOutputGuardrailData](/openai-agents-js/openai/agents-core/interfaces/tooloutputguardraildata/) * [ToolOutputGuardrailDefinition](/openai-agents-js/openai/agents-core/interfaces/tooloutputguardraildefinition/) * [ToolOutputGuardrailResult](/openai-agents-js/openai/agents-core/interfaces/tooloutputguardrailresult/) * [TracingExporter](/openai-agents-js/openai/agents-core/interfaces/tracingexporter/) * [TracingProcessor](/openai-agents-js/openai/agents-core/interfaces/tracingprocessor/) ## Type Aliases [Section titled “Type Aliases”](#type-aliases) * [AgentConfigWithHandoffs](/openai-agents-js/openai/agents-core/type-aliases/agentconfigwithhandoffs/) * [AgentInputItem](/openai-agents-js/openai/agents-core/type-aliases/agentinputitem/) * [AgentOptions](/openai-agents-js/openai/agents-core/type-aliases/agentoptions/) * [AgentOutputItem](/openai-agents-js/openai/agents-core/type-aliases/agentoutputitem/) * [AgentOutputType](/openai-agents-js/openai/agents-core/type-aliases/agentoutputtype/) * [AgentSpanData](/openai-agents-js/openai/agents-core/type-aliases/agentspandata/) * [AgentToolInvocation](/openai-agents-js/openai/agents-core/type-aliases/agenttoolinvocation/) * [ApplyPatchCallItem](/openai-agents-js/openai/agents-core/type-aliases/applypatchcallitem/) * [ApplyPatchCallItem](/openai-agents-js/openai/agents-core/type-aliases/applypatchcallitem-1/) * [ApplyPatchCallResultItem](/openai-agents-js/openai/agents-core/type-aliases/applypatchcallresultitem/) * [ApplyPatchCallResultItem](/openai-agents-js/openai/agents-core/type-aliases/applypatchcallresultitem-1/) * [ApplyPatchOperation](/openai-agents-js/openai/agents-core/type-aliases/applypatchoperation/) * [ApplyPatchResult](/openai-agents-js/openai/agents-core/type-aliases/applypatchresult/) * [ApplyPatchTool](/openai-agents-js/openai/agents-core/type-aliases/applypatchtool/) * [AssistantMessageItem](/openai-agents-js/openai/agents-core/type-aliases/assistantmessageitem/) * [AssistantMessageItem](/openai-agents-js/openai/agents-core/type-aliases/assistantmessageitem-1/) * [CallModelInputFilter](/openai-agents-js/openai/agents-core/type-aliases/callmodelinputfilter/) * [CallModelInputFilterArgs](/openai-agents-js/openai/agents-core/type-aliases/callmodelinputfilterargs/) * [ClientToolSearchExecutor](/openai-agents-js/openai/agents-core/type-aliases/clienttoolsearchexecutor/) * [ClientToolSearchExecutorArgs](/openai-agents-js/openai/agents-core/type-aliases/clienttoolsearchexecutorargs/) * [ClientToolSearchExecutorResult](/openai-agents-js/openai/agents-core/type-aliases/clienttoolsearchexecutorresult/) * [CompletedAgentToolInvocationRunResult](/openai-agents-js/openai/agents-core/type-aliases/completedagenttoolinvocationrunresult/) * [Computer](/openai-agents-js/openai/agents-core/type-aliases/computer/) * [ComputerCallResultItem](/openai-agents-js/openai/agents-core/type-aliases/computercallresultitem/) * [ComputerCallResultItem](/openai-agents-js/openai/agents-core/type-aliases/computercallresultitem-1/) * [ComputerOnSafetyCheckFunction](/openai-agents-js/openai/agents-core/type-aliases/computeronsafetycheckfunction/) * [ComputerSafetyCheck](/openai-agents-js/openai/agents-core/type-aliases/computersafetycheck/) * [ComputerSafetyCheckResult](/openai-agents-js/openai/agents-core/type-aliases/computersafetycheckresult/) * [ComputerTool](/openai-agents-js/openai/agents-core/type-aliases/computertool/) * [ComputerUseCallItem](/openai-agents-js/openai/agents-core/type-aliases/computerusecallitem/) * [ComputerUseCallItem](/openai-agents-js/openai/agents-core/type-aliases/computerusecallitem-1/) * [CustomSpanData](/openai-agents-js/openai/agents-core/type-aliases/customspandata/) * [EditorInvocationContext](/openai-agents-js/openai/agents-core/type-aliases/editorinvocationcontext/) * [FunctionCallItem](/openai-agents-js/openai/agents-core/type-aliases/functioncallitem/) * [FunctionCallItem](/openai-agents-js/openai/agents-core/type-aliases/functioncallitem-1/) * [FunctionCallResultItem](/openai-agents-js/openai/agents-core/type-aliases/functioncallresultitem/) * [FunctionCallResultItem](/openai-agents-js/openai/agents-core/type-aliases/functioncallresultitem-1/) * [FunctionSpanData](/openai-agents-js/openai/agents-core/type-aliases/functionspandata/) * [FunctionTool](/openai-agents-js/openai/agents-core/type-aliases/functiontool/) * [FunctionToolResult](/openai-agents-js/openai/agents-core/type-aliases/functiontoolresult/) * [FunctionToolTimeoutBehavior](/openai-agents-js/openai/agents-core/type-aliases/functiontooltimeoutbehavior/) * [GenerationSpanData](/openai-agents-js/openai/agents-core/type-aliases/generationspandata/) * [GenerationUsageData](/openai-agents-js/openai/agents-core/type-aliases/generationusagedata/) * [GetAllMcpToolsOptions](/openai-agents-js/openai/agents-core/type-aliases/getallmcptoolsoptions/) * [GuardrailSpanData](/openai-agents-js/openai/agents-core/type-aliases/guardrailspandata/) * [HandoffEnabledFunction](/openai-agents-js/openai/agents-core/type-aliases/handoffenabledfunction/) * [HandoffInputData](/openai-agents-js/openai/agents-core/type-aliases/handoffinputdata/) * [HandoffSpanData](/openai-agents-js/openai/agents-core/type-aliases/handoffspandata/) * [HostedMCPTool](/openai-agents-js/openai/agents-core/type-aliases/hostedmcptool/) * [HostedTool](/openai-agents-js/openai/agents-core/type-aliases/hostedtool/) * [HostedToolCallItem](/openai-agents-js/openai/agents-core/type-aliases/hostedtoolcallitem/) * [HostedToolCallItem](/openai-agents-js/openai/agents-core/type-aliases/hostedtoolcallitem-1/) * [IndividualRunOptions](/openai-agents-js/openai/agents-core/type-aliases/individualrunoptions/) * [InputGuardrailFunction](/openai-agents-js/openai/agents-core/type-aliases/inputguardrailfunction/) * [JsonSchemaDefinition](/openai-agents-js/openai/agents-core/type-aliases/jsonschemadefinition/) * [MCPListToolsSpanData](/openai-agents-js/openai/agents-core/type-aliases/mcplisttoolsspandata/) * [MCPResourceContent](/openai-agents-js/openai/agents-core/type-aliases/mcpresourcecontent/) * [MCPServersOptions](/openai-agents-js/openai/agents-core/type-aliases/mcpserversoptions/) * [MCPServersReconnectOptions](/openai-agents-js/openai/agents-core/type-aliases/mcpserversreconnectoptions/) * [MCPToolCacheKeyGenerator](/openai-agents-js/openai/agents-core/type-aliases/mcptoolcachekeygenerator/) * [MCPToolErrorFunction](/openai-agents-js/openai/agents-core/type-aliases/mcptoolerrorfunction/) * [MCPToolFilterCallable](/openai-agents-js/openai/agents-core/type-aliases/mcptoolfiltercallable/) * [MCPToolMetaResolver](/openai-agents-js/openai/agents-core/type-aliases/mcptoolmetaresolver/) * [ModelInputData](/openai-agents-js/openai/agents-core/type-aliases/modelinputdata/) * [ModelRequest](/openai-agents-js/openai/agents-core/type-aliases/modelrequest/) * [ModelResponse](/openai-agents-js/openai/agents-core/type-aliases/modelresponse/) * [ModelRetryAdvice](/openai-agents-js/openai/agents-core/type-aliases/modelretryadvice/) * [ModelRetryAdviceRequest](/openai-agents-js/openai/agents-core/type-aliases/modelretryadvicerequest/) * [ModelRetryBackoffSettings](/openai-agents-js/openai/agents-core/type-aliases/modelretrybackoffsettings/) * [ModelRetryNormalizedError](/openai-agents-js/openai/agents-core/type-aliases/modelretrynormalizederror/) * [ModelRetrySettings](/openai-agents-js/openai/agents-core/type-aliases/modelretrysettings/) * [ModelSettings](/openai-agents-js/openai/agents-core/type-aliases/modelsettings/) * [ModelSettingsContextManagement](/openai-agents-js/openai/agents-core/type-aliases/modelsettingscontextmanagement/) * [ModelSettingsToolChoice](/openai-agents-js/openai/agents-core/type-aliases/modelsettingstoolchoice/) * [NonStreamRunOptions](/openai-agents-js/openai/agents-core/type-aliases/nonstreamrunoptions/) * [OpenAIResponsesCompactionArgs](/openai-agents-js/openai/agents-core/type-aliases/openairesponsescompactionargs/) * [OpenAIResponsesCompactionResult](/openai-agents-js/openai/agents-core/type-aliases/openairesponsescompactionresult/) * [OutputGuardrailFunction](/openai-agents-js/openai/agents-core/type-aliases/outputguardrailfunction/) * [ReasoningItem](/openai-agents-js/openai/agents-core/type-aliases/reasoningitem/) * [ReasoningItem](/openai-agents-js/openai/agents-core/type-aliases/reasoningitem-1/) * [ReasoningItemIdPolicy](/openai-agents-js/openai/agents-core/type-aliases/reasoningitemidpolicy/) * [ResponseSpanData](/openai-agents-js/openai/agents-core/type-aliases/responsespandata/) * [ResponseStreamEvent](/openai-agents-js/openai/agents-core/type-aliases/responsestreamevent/) * [RetryDecision](/openai-agents-js/openai/agents-core/type-aliases/retrydecision/) * [RetryPolicy](/openai-agents-js/openai/agents-core/type-aliases/retrypolicy/) * [RetryPolicyContext](/openai-agents-js/openai/agents-core/type-aliases/retrypolicycontext/) * [RunConfig](/openai-agents-js/openai/agents-core/type-aliases/runconfig/) * [RunErrorData](/openai-agents-js/openai/agents-core/type-aliases/runerrordata/) * [RunErrorHandler](/openai-agents-js/openai/agents-core/type-aliases/runerrorhandler/) * [RunErrorHandlerInput](/openai-agents-js/openai/agents-core/type-aliases/runerrorhandlerinput/) * [RunErrorHandlerResult](/openai-agents-js/openai/agents-core/type-aliases/runerrorhandlerresult/) * [RunErrorHandlers](/openai-agents-js/openai/agents-core/type-aliases/runerrorhandlers/) * [RunErrorKind](/openai-agents-js/openai/agents-core/type-aliases/runerrorkind/) * [RunItem](/openai-agents-js/openai/agents-core/type-aliases/runitem/) * [RunStreamEvent](/openai-agents-js/openai/agents-core/type-aliases/runstreamevent/) * [SerializedHandoff](/openai-agents-js/openai/agents-core/type-aliases/serializedhandoff/) * [SerializedOutputType](/openai-agents-js/openai/agents-core/type-aliases/serializedoutputtype/) * [SerializedTool](/openai-agents-js/openai/agents-core/type-aliases/serializedtool/) * [SessionHistoryMutation](/openai-agents-js/openai/agents-core/type-aliases/sessionhistorymutation/) * [SessionHistoryRewriteArgs](/openai-agents-js/openai/agents-core/type-aliases/sessionhistoryrewriteargs/) * [SessionInputCallback](/openai-agents-js/openai/agents-core/type-aliases/sessioninputcallback/) * [ShellAction](/openai-agents-js/openai/agents-core/type-aliases/shellaction/) * [ShellCallItem](/openai-agents-js/openai/agents-core/type-aliases/shellcallitem/) * [ShellCallItem](/openai-agents-js/openai/agents-core/type-aliases/shellcallitem-1/) * [ShellCallResultItem](/openai-agents-js/openai/agents-core/type-aliases/shellcallresultitem/) * [ShellCallResultItem](/openai-agents-js/openai/agents-core/type-aliases/shellcallresultitem-1/) * [ShellOutputResult](/openai-agents-js/openai/agents-core/type-aliases/shelloutputresult/) * [ShellResult](/openai-agents-js/openai/agents-core/type-aliases/shellresult/) * [ShellTool](/openai-agents-js/openai/agents-core/type-aliases/shelltool/) * [ShellToolContainerAutoEnvironment](/openai-agents-js/openai/agents-core/type-aliases/shelltoolcontainerautoenvironment/) * [ShellToolContainerNetworkPolicy](/openai-agents-js/openai/agents-core/type-aliases/shelltoolcontainernetworkpolicy/) * [ShellToolContainerNetworkPolicyAllowlist](/openai-agents-js/openai/agents-core/type-aliases/shelltoolcontainernetworkpolicyallowlist/) * [ShellToolContainerNetworkPolicyDisabled](/openai-agents-js/openai/agents-core/type-aliases/shelltoolcontainernetworkpolicydisabled/) * [ShellToolContainerNetworkPolicyDomainSecret](/openai-agents-js/openai/agents-core/type-aliases/shelltoolcontainernetworkpolicydomainsecret/) * [ShellToolContainerReferenceEnvironment](/openai-agents-js/openai/agents-core/type-aliases/shelltoolcontainerreferenceenvironment/) * [ShellToolContainerSkill](/openai-agents-js/openai/agents-core/type-aliases/shelltoolcontainerskill/) * [ShellToolEnvironment](/openai-agents-js/openai/agents-core/type-aliases/shelltoolenvironment/) * [ShellToolHostedEnvironment](/openai-agents-js/openai/agents-core/type-aliases/shelltoolhostedenvironment/) * [ShellToolInlineSkill](/openai-agents-js/openai/agents-core/type-aliases/shelltoolinlineskill/) * [ShellToolInlineSkillSource](/openai-agents-js/openai/agents-core/type-aliases/shelltoolinlineskillsource/) * [ShellToolLocalEnvironment](/openai-agents-js/openai/agents-core/type-aliases/shelltoollocalenvironment/) * [ShellToolLocalSkill](/openai-agents-js/openai/agents-core/type-aliases/shelltoollocalskill/) * [ShellToolSkillReference](/openai-agents-js/openai/agents-core/type-aliases/shelltoolskillreference/) * [SpanData](/openai-agents-js/openai/agents-core/type-aliases/spandata/) * [SpanError](/openai-agents-js/openai/agents-core/type-aliases/spanerror/) * [SpanOptions](/openai-agents-js/openai/agents-core/type-aliases/spanoptions/) * [SpeechGroupSpanData](/openai-agents-js/openai/agents-core/type-aliases/speechgroupspandata/) * [SpeechSpanData](/openai-agents-js/openai/agents-core/type-aliases/speechspandata/) * [StreamEvent](/openai-agents-js/openai/agents-core/type-aliases/streamevent/) * [StreamEvent](/openai-agents-js/openai/agents-core/type-aliases/streamevent-1/) * [StreamEventGenericItem](/openai-agents-js/openai/agents-core/type-aliases/streameventgenericitem/) * [StreamEventGenericItem](/openai-agents-js/openai/agents-core/type-aliases/streameventgenericitem-1/) * [StreamEventResponseCompleted](/openai-agents-js/openai/agents-core/type-aliases/streameventresponsecompleted/) * [StreamEventResponseCompleted](/openai-agents-js/openai/agents-core/type-aliases/streameventresponsecompleted-1/) * [StreamEventResponseStarted](/openai-agents-js/openai/agents-core/type-aliases/streameventresponsestarted/) * [StreamEventResponseStarted](/openai-agents-js/openai/agents-core/type-aliases/streameventresponsestarted-1/) * [StreamEventTextStream](/openai-agents-js/openai/agents-core/type-aliases/streameventtextstream/) * [StreamEventTextStream](/openai-agents-js/openai/agents-core/type-aliases/streameventtextstream-1/) * [StreamRunOptions](/openai-agents-js/openai/agents-core/type-aliases/streamrunoptions/) * [SystemMessageItem](/openai-agents-js/openai/agents-core/type-aliases/systemmessageitem/) * [TextOutput](/openai-agents-js/openai/agents-core/type-aliases/textoutput/) * [Tool](/openai-agents-js/openai/agents-core/type-aliases/tool/) * [ToolCallOutputContent](/openai-agents-js/openai/agents-core/type-aliases/toolcalloutputcontent/) * [ToolCallOutputContent](/openai-agents-js/openai/agents-core/type-aliases/toolcalloutputcontent-1/) * [ToolCallStructuredOutput](/openai-agents-js/openai/agents-core/type-aliases/toolcallstructuredoutput/) * [ToolCallStructuredOutput](/openai-agents-js/openai/agents-core/type-aliases/toolcallstructuredoutput-1/) * [ToolEnabledFunction](/openai-agents-js/openai/agents-core/type-aliases/toolenabledfunction/) * [ToolErrorFormatter](/openai-agents-js/openai/agents-core/type-aliases/toolerrorformatter/) * [ToolErrorFormatterArgs](/openai-agents-js/openai/agents-core/type-aliases/toolerrorformatterargs/) * [ToolExecuteArgument](/openai-agents-js/openai/agents-core/type-aliases/toolexecuteargument/) * [ToolExecutionConfig](/openai-agents-js/openai/agents-core/type-aliases/toolexecutionconfig/) * [ToolGuardrailBehavior](/openai-agents-js/openai/agents-core/type-aliases/toolguardrailbehavior/) * [ToolInputGuardrailFunction](/openai-agents-js/openai/agents-core/type-aliases/toolinputguardrailfunction/) * [ToolInputParameters](/openai-agents-js/openai/agents-core/type-aliases/toolinputparameters/) * [ToolNamespaceOptions](/openai-agents-js/openai/agents-core/type-aliases/toolnamespaceoptions/) * [ToolOptions](/openai-agents-js/openai/agents-core/type-aliases/tooloptions/) * [ToolOptionsWithGuardrails](/openai-agents-js/openai/agents-core/type-aliases/tooloptionswithguardrails/) * [ToolOutputFileContent](/openai-agents-js/openai/agents-core/type-aliases/tooloutputfilecontent/) * [ToolOutputFileContent](/openai-agents-js/openai/agents-core/type-aliases/tooloutputfilecontent-1/) * [ToolOutputGuardrailFunction](/openai-agents-js/openai/agents-core/type-aliases/tooloutputguardrailfunction/) * [ToolOutputImage](/openai-agents-js/openai/agents-core/type-aliases/tooloutputimage/) * [ToolOutputImage](/openai-agents-js/openai/agents-core/type-aliases/tooloutputimage-1/) * [ToolOutputText](/openai-agents-js/openai/agents-core/type-aliases/tooloutputtext/) * [ToolOutputText](/openai-agents-js/openai/agents-core/type-aliases/tooloutputtext-1/) * [ToolReference](/openai-agents-js/openai/agents-core/type-aliases/toolreference/) * [ToolReference](/openai-agents-js/openai/agents-core/type-aliases/toolreference-1/) * [ToolSearchCallArguments](/openai-agents-js/openai/agents-core/type-aliases/toolsearchcallarguments/) * [ToolSearchCallArguments](/openai-agents-js/openai/agents-core/type-aliases/toolsearchcallarguments-1/) * [ToolSearchCallItem](/openai-agents-js/openai/agents-core/type-aliases/toolsearchcallitem/) * [ToolSearchCallItem](/openai-agents-js/openai/agents-core/type-aliases/toolsearchcallitem-1/) * [ToolSearchOutputItem](/openai-agents-js/openai/agents-core/type-aliases/toolsearchoutputitem/) * [ToolSearchOutputItem](/openai-agents-js/openai/agents-core/type-aliases/toolsearchoutputitem-1/) * [ToolSearchOutputTool](/openai-agents-js/openai/agents-core/type-aliases/toolsearchoutputtool/) * [ToolSearchOutputTool](/openai-agents-js/openai/agents-core/type-aliases/toolsearchoutputtool-1/) * [ToolsToFinalOutputResult](/openai-agents-js/openai/agents-core/type-aliases/toolstofinaloutputresult/) * [ToolTimeoutErrorFunction](/openai-agents-js/openai/agents-core/type-aliases/tooltimeouterrorfunction/) * [ToolToFinalOutputFunction](/openai-agents-js/openai/agents-core/type-aliases/tooltofinaloutputfunction/) * [ToolUseBehavior](/openai-agents-js/openai/agents-core/type-aliases/toolusebehavior/) * [ToolUseBehaviorFlags](/openai-agents-js/openai/agents-core/type-aliases/toolusebehaviorflags/) * [TracingConfig](/openai-agents-js/openai/agents-core/type-aliases/tracingconfig/) * [TranscriptionSpanData](/openai-agents-js/openai/agents-core/type-aliases/transcriptionspandata/) * [UnknownContext](/openai-agents-js/openai/agents-core/type-aliases/unknowncontext/) * [UnknownItem](/openai-agents-js/openai/agents-core/type-aliases/unknownitem/) * [UnknownItem](/openai-agents-js/openai/agents-core/type-aliases/unknownitem-1/) * [UserMessageItem](/openai-agents-js/openai/agents-core/type-aliases/usermessageitem/) * [UserMessageItem](/openai-agents-js/openai/agents-core/type-aliases/usermessageitem-1/) ## Variables [Section titled “Variables”](#variables) * [ApplyPatchOperation](/openai-agents-js/openai/agents-core/variables/applypatchoperation/) * [OPENAI\_DEFAULT\_MODEL\_ENV\_VARIABLE\_NAME](/openai-agents-js/openai/agents-core/variables/openai_default_model_env_variable_name/) * [retryPolicies](/openai-agents-js/openai/agents-core/variables/retrypolicies/) * [ToolGuardrailFunctionOutputFactory](/openai-agents-js/openai/agents-core/variables/toolguardrailfunctionoutputfactory/) * [withAgentSpan](/openai-agents-js/openai/agents-core/variables/withagentspan/) * [withCustomSpan](/openai-agents-js/openai/agents-core/variables/withcustomspan/) * [withFunctionSpan](/openai-agents-js/openai/agents-core/variables/withfunctionspan/) * [withGenerationSpan](/openai-agents-js/openai/agents-core/variables/withgenerationspan/) * [withGuardrailSpan](/openai-agents-js/openai/agents-core/variables/withguardrailspan/) * [withHandoffSpan](/openai-agents-js/openai/agents-core/variables/withhandoffspan/) * [withMCPListToolsSpan](/openai-agents-js/openai/agents-core/variables/withmcplisttoolsspan/) * [withResponseSpan](/openai-agents-js/openai/agents-core/variables/withresponsespan/) * [withSpeechGroupSpan](/openai-agents-js/openai/agents-core/variables/withspeechgroupspan/) * [withSpeechSpan](/openai-agents-js/openai/agents-core/variables/withspeechspan/) * [withTranscriptionSpan](/openai-agents-js/openai/agents-core/variables/withtranscriptionspan/) ## Functions [Section titled “Functions”](#functions) * [addTraceProcessor](/openai-agents-js/openai/agents-core/functions/addtraceprocessor/) * [applyDiff](/openai-agents-js/openai/agents-core/functions/applydiff/) * [applyPatchTool](/openai-agents-js/openai/agents-core/functions/applypatchtool/) * [applySessionHistoryMutations](/openai-agents-js/openai/agents-core/functions/applysessionhistorymutations/) * [assistant](/openai-agents-js/openai/agents-core/functions/assistant/) * [attachClientToolSearchExecutor](/openai-agents-js/openai/agents-core/functions/attachclienttoolsearchexecutor/) * [computerTool](/openai-agents-js/openai/agents-core/functions/computertool/) * [connectMcpServers](/openai-agents-js/openai/agents-core/functions/connectmcpservers/) * [createAgentSpan](/openai-agents-js/openai/agents-core/functions/createagentspan/) * [createCustomSpan](/openai-agents-js/openai/agents-core/functions/createcustomspan/) * [createFunctionSpan](/openai-agents-js/openai/agents-core/functions/createfunctionspan/) * [createGenerationSpan](/openai-agents-js/openai/agents-core/functions/creategenerationspan/) * [createGuardrailSpan](/openai-agents-js/openai/agents-core/functions/createguardrailspan/) * [createHandoffSpan](/openai-agents-js/openai/agents-core/functions/createhandoffspan/) * [createMCPListToolsSpan](/openai-agents-js/openai/agents-core/functions/createmcplisttoolsspan/) * [createMCPToolStaticFilter](/openai-agents-js/openai/agents-core/functions/createmcptoolstaticfilter/) * [createResponseSpan](/openai-agents-js/openai/agents-core/functions/createresponsespan/) * [createSpeechGroupSpan](/openai-agents-js/openai/agents-core/functions/createspeechgroupspan/) * [createSpeechSpan](/openai-agents-js/openai/agents-core/functions/createspeechspan/) * [createTranscriptionSpan](/openai-agents-js/openai/agents-core/functions/createtranscriptionspan/) * [defineOutputGuardrail](/openai-agents-js/openai/agents-core/functions/defineoutputguardrail/) * [defineToolInputGuardrail](/openai-agents-js/openai/agents-core/functions/definetoolinputguardrail/) * [defineToolOutputGuardrail](/openai-agents-js/openai/agents-core/functions/definetooloutputguardrail/) * [extractAllTextOutput](/openai-agents-js/openai/agents-core/functions/extractalltextoutput/) * [generateGroupId](/openai-agents-js/openai/agents-core/functions/generategroupid/) * [generateSpanId](/openai-agents-js/openai/agents-core/functions/generatespanid/) * [generateTraceId](/openai-agents-js/openai/agents-core/functions/generatetraceid/) * [getAllMcpTools](/openai-agents-js/openai/agents-core/functions/getallmcptools/) * [getClientToolSearchExecutor](/openai-agents-js/openai/agents-core/functions/getclienttoolsearchexecutor/) * [getCurrentSpan](/openai-agents-js/openai/agents-core/functions/getcurrentspan/) * [getCurrentTrace](/openai-agents-js/openai/agents-core/functions/getcurrenttrace/) * [getDefaultModel](/openai-agents-js/openai/agents-core/functions/getdefaultmodel/) * [getDefaultModelSettings](/openai-agents-js/openai/agents-core/functions/getdefaultmodelsettings/) * [getGlobalTraceProvider](/openai-agents-js/openai/agents-core/functions/getglobaltraceprovider/) * [getHandoff](/openai-agents-js/openai/agents-core/functions/gethandoff/) * [getLogger](/openai-agents-js/openai/agents-core/functions/getlogger/) * [getOrCreateTrace](/openai-agents-js/openai/agents-core/functions/getorcreatetrace/) * [getToolSearchRuntimeToolKey](/openai-agents-js/openai/agents-core/functions/gettoolsearchruntimetoolkey/) * [getTransferMessage](/openai-agents-js/openai/agents-core/functions/gettransfermessage/) * [gpt5ReasoningSettingsRequired](/openai-agents-js/openai/agents-core/functions/gpt5reasoningsettingsrequired/) * [handoff](/openai-agents-js/openai/agents-core/functions/handoff/) * [hostedMcpTool](/openai-agents-js/openai/agents-core/functions/hostedmcptool/) * [invalidateServerToolsCache](/openai-agents-js/openai/agents-core/functions/invalidateservertoolscache/) * [invokeFunctionTool](/openai-agents-js/openai/agents-core/functions/invokefunctiontool/) * [isGpt5Default](/openai-agents-js/openai/agents-core/functions/isgpt5default/) * [isOpenAIResponsesCompactionAwareSession](/openai-agents-js/openai/agents-core/functions/isopenairesponsescompactionawaresession/) * [isSessionHistoryRewriteAwareSession](/openai-agents-js/openai/agents-core/functions/issessionhistoryrewriteawaresession/) * [mcpToFunctionTool](/openai-agents-js/openai/agents-core/functions/mcptofunctiontool/) * [resetCurrentSpan](/openai-agents-js/openai/agents-core/functions/resetcurrentspan/) * [resolveToolInputGuardrails](/openai-agents-js/openai/agents-core/functions/resolvetoolinputguardrails/) * [resolveToolOutputGuardrails](/openai-agents-js/openai/agents-core/functions/resolvetooloutputguardrails/) * [run](/openai-agents-js/openai/agents-core/functions/run/) * [runToolInputGuardrails](/openai-agents-js/openai/agents-core/functions/runtoolinputguardrails/) * [runToolOutputGuardrails](/openai-agents-js/openai/agents-core/functions/runtooloutputguardrails/) * [setCurrentSpan](/openai-agents-js/openai/agents-core/functions/setcurrentspan/) * [setDefaultModelProvider](/openai-agents-js/openai/agents-core/functions/setdefaultmodelprovider/) * [setTraceProcessors](/openai-agents-js/openai/agents-core/functions/settraceprocessors/) * [setTracingDisabled](/openai-agents-js/openai/agents-core/functions/settracingdisabled/) * [shellTool](/openai-agents-js/openai/agents-core/functions/shelltool/) * [startTraceExportLoop](/openai-agents-js/openai/agents-core/functions/starttraceexportloop/) * [system](/openai-agents-js/openai/agents-core/functions/system/) * [tool](/openai-agents-js/openai/agents-core/functions/tool/) * [toolNamespace](/openai-agents-js/openai/agents-core/functions/toolnamespace/) * [user](/openai-agents-js/openai/agents-core/functions/user/) * [withTrace](/openai-agents-js/openai/agents-core/functions/withtrace/) # AgentConfigWithHandoffs ```ts type AgentConfigWithHandoffs = object & Partial>, "name" | "handoffs" | "outputType">>; ``` Helper type for config with handoffs ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### handoffs? [Section titled “handoffs?”](#handoffs) ```ts optional handoffs?: Handoffs; ``` ### name [Section titled “name”](#name) ```ts name: string; ``` ### outputType? [Section titled “outputType?”](#outputtype) ```ts optional outputType?: TOutput; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Description | | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------ | | `TOutput` *extends* [`AgentOutputType`](/openai-agents-js/openai/agents-core/type-aliases/agentoutputtype/) | The type of the output object. | | `Handoffs` *extends* readonly ( \| [`Agent`](/openai-agents-js/openai/agents-core/classes/agent/)<`any`, `any`> \| [`Handoff`](/openai-agents-js/openai/agents-core/classes/handoff/)<`any`, `any`>)\[] | The type of the handoffs. | # AgentInputItem ```ts type AgentInputItem = | UserMessageItem | AssistantMessageItem | SystemMessageItem | ToolSearchCallItem | ToolSearchOutputItem | HostedToolCallItem | FunctionCallItem | ComputerUseCallItem | ShellCallItem | ApplyPatchCallItem | FunctionCallResultItem | ComputerCallResultItem | ShellCallResultItem | ApplyPatchCallResultItem | ReasoningItem | CompactionItem | UnknownItem; ``` Agent input # AgentOptions ```ts type AgentOptions = Expand, "name"> & Partial>>; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | ----------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------- | | `TContext` | [`UnknownContext`](/openai-agents-js/openai/agents-core/type-aliases/unknowncontext/) | | `TOutput` *extends* [`AgentOutputType`](/openai-agents-js/openai/agents-core/type-aliases/agentoutputtype/) | [`TextOutput`](/openai-agents-js/openai/agents-core/type-aliases/textoutput/) | # AgentOutputItem ```ts type AgentOutputItem = | UserMessageItem | AssistantMessageItem | SystemMessageItem | ToolSearchCallItem | ToolSearchOutputItem | HostedToolCallItem | FunctionCallItem | ComputerUseCallItem | ShellCallItem | ApplyPatchCallItem | FunctionCallResultItem | ComputerCallResultItem | ShellCallResultItem | ApplyPatchCallResultItem | ReasoningItem | CompactionItem | UnknownItem; ``` Agent output items # AgentOutputType ```ts type AgentOutputType = | TextOutput | ZodObjectLike | JsonSchemaDefinition | HandoffsOutput; ``` The type of the output object. If not provided, the output will be a string. ‘text’ is a special type that indicates the output will be a string. ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | Description | | ------------------- | ------------------------------------------------------------------------------------- | -------------------------------------- | | `HandoffOutputType` | [`UnknownContext`](/openai-agents-js/openai/agents-core/type-aliases/unknowncontext/) | The type of the output of the handoff. | # AgentSpanData ```ts type AgentSpanData = SpanDataBase & object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### handoffs? [Section titled “handoffs?”](#handoffs) ```ts optional handoffs?: string[]; ``` ### name [Section titled “name”](#name) ```ts name: string; ``` ### output\_type? [Section titled “output\_type?”](#output_type) ```ts optional output_type?: string; ``` ### tools? [Section titled “tools?”](#tools) ```ts optional tools?: string[]; ``` ### type [Section titled “type”](#type) ```ts type: "agent"; ``` # AgentToolInvocation ```ts type AgentToolInvocation = Readonly<{ toolArguments?: string; toolCallId?: string; toolName: string; }>; ``` # ApplyPatchCallItem ```ts type ApplyPatchCallItem = ZodObject; ``` # ApplyPatchCallItem ```ts type ApplyPatchCallItem = object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### callId [Section titled “callId”](#callid) ```ts callId: string; ``` ### id? [Section titled “id?”](#id) ```ts optional id?: string; ``` An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. ### operation [Section titled “operation”](#operation) ```ts operation: | { diff: string; path: string; type: "create_file"; } | { diff: string; moveTo?: string; path: string; type: "update_file"; } | { path: string; type: "delete_file"; } = ApplyPatchOperation; ``` ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. ### status [Section titled “status”](#status) ```ts status: "in_progress" | "completed"; ``` ### type [Section titled “type”](#type) ```ts type: "apply_patch_call"; ``` # ApplyPatchCallResultItem ```ts type ApplyPatchCallResultItem = ZodObject; ``` # ApplyPatchCallResultItem ```ts type ApplyPatchCallResultItem = object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### callId [Section titled “callId”](#callid) ```ts callId: string; ``` ### id? [Section titled “id?”](#id) ```ts optional id?: string; ``` An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. ### output? [Section titled “output?”](#output) ```ts optional output?: string; ``` ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. ### status [Section titled “status”](#status) ```ts status: "completed" | "failed"; ``` ### type [Section titled “type”](#type) ```ts type: "apply_patch_call_output"; ``` # ApplyPatchOperation ```ts type ApplyPatchOperation = | { diff: string; path: string; type: "create_file"; } | { diff: string; moveTo?: string; path: string; type: "update_file"; } | { path: string; type: "delete_file"; }; ``` # ApplyPatchResult ```ts type ApplyPatchResult = object; ``` Result returned by an Editor operation. ## Properties [Section titled “Properties”](#properties) ### output? [Section titled “output?”](#output) ```ts optional output?: string; ``` Optional textual output to forward to the model. *** ### status? [Section titled “status?”](#status) ```ts optional status?: "completed" | "failed"; ``` Whether the operation completed successfully. Defaults to `completed`. # ApplyPatchTool ```ts type ApplyPatchTool = object; ``` ## Properties [Section titled “Properties”](#properties) ### editor [Section titled “editor”](#editor) ```ts editor: Editor; ``` Diff applier invoked when the tool is called. *** ### name [Section titled “name”](#name) ```ts name: string; ``` Public name exposed to the model. Defaults to `apply_patch`. *** ### needsApproval [Section titled “needsApproval”](#needsapproval) ```ts needsApproval: ApplyPatchApprovalFunction; ``` Predicate determining whether this apply\_patch operation requires approval. *** ### onApproval? [Section titled “onApproval?”](#onapproval) ```ts optional onApproval?: ApplyPatchOnApprovalFunction; ``` Optional handler to auto-approve or reject when approval is required. *** ### type [Section titled “type”](#type) ```ts type: "apply_patch"; ``` # AssistantMessageItem ```ts type AssistantMessageItem = ZodObject; ``` # AssistantMessageItem ```ts type AssistantMessageItem = object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### content [Section titled “content”](#content) ```ts content: ( | { providerData?: Record; refusal: string; type: "refusal"; } | { providerData?: Record; text: string; type: "output_text"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; } | { image: string; providerData?: Record; type: "image"; })[]; ``` The content of the message. ### id? [Section titled “id?”](#id) ```ts optional id?: string; ``` An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. ### role [Section titled “role”](#role) ```ts role: "assistant"; ``` Representing a message from the assistant (i.e. the model) ### status [Section titled “status”](#status) ```ts status: "in_progress" | "completed" | "incomplete"; ``` The status of the message. ### type? [Section titled “type?”](#type) ```ts optional type?: "message"; ``` Any item without a type is treated as a message # CallModelInputFilter ```ts type CallModelInputFilter = (args) => | ModelInputData | Promise; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | ------------ | | `TContext` | `unknown` | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | --------------------------------------------------------------------------------------------------------------------- | | `args` | [`CallModelInputFilterArgs`](/openai-agents-js/openai/agents-core/type-aliases/callmodelinputfilterargs/)<`TContext`> | ## Returns [Section titled “Returns”](#returns) \| [`ModelInputData`](/openai-agents-js/openai/agents-core/type-aliases/modelinputdata/) | `Promise`<[`ModelInputData`](/openai-agents-js/openai/agents-core/type-aliases/modelinputdata/)> # CallModelInputFilterArgs ```ts type CallModelInputFilterArgs = object; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | ------------ | | `TContext` | `unknown` | ## Properties [Section titled “Properties”](#properties) ### agent [Section titled “agent”](#agent) ```ts agent: Agent; ``` *** ### context [Section titled “context”](#context) ```ts context: TContext | undefined; ``` *** ### modelData [Section titled “modelData”](#modeldata) ```ts modelData: ModelInputData; ``` # ClientToolSearchExecutor ```ts type ClientToolSearchExecutor = (args) => | ClientToolSearchExecutorResult | Promise>; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | ------------------------------------------------------------------------------------- | | `Context` | [`UnknownContext`](/openai-agents-js/openai/agents-core/type-aliases/unknowncontext/) | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ---------------------------------------------------------------------------------------------------------------------------- | | `args` | [`ClientToolSearchExecutorArgs`](/openai-agents-js/openai/agents-core/type-aliases/clienttoolsearchexecutorargs/)<`Context`> | ## Returns [Section titled “Returns”](#returns) \| [`ClientToolSearchExecutorResult`](/openai-agents-js/openai/agents-core/type-aliases/clienttoolsearchexecutorresult/)<`Context`> | `Promise`<[`ClientToolSearchExecutorResult`](/openai-agents-js/openai/agents-core/type-aliases/clienttoolsearchexecutorresult/)<`Context`>> # ClientToolSearchExecutorArgs ```ts type ClientToolSearchExecutorArgs = object; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | ------------------------------------------------------------------------------------- | | `Context` | [`UnknownContext`](/openai-agents-js/openai/agents-core/type-aliases/unknowncontext/) | ## Properties [Section titled “Properties”](#properties) ### agent [Section titled “agent”](#agent) ```ts agent: Agent; ``` *** ### availableTools [Section titled “availableTools”](#availabletools) ```ts availableTools: Tool[]; ``` *** ### loadDefault [Section titled “loadDefault”](#loaddefault) ```ts loadDefault: ClientToolSearchLoadDefaultFunction; ``` *** ### runContext [Section titled “runContext”](#runcontext) ```ts runContext: RunContext; ``` *** ### toolCall [Section titled “toolCall”](#toolcall) ```ts toolCall: ToolSearchCallItem; ``` # ClientToolSearchExecutorResult ```ts type ClientToolSearchExecutorResult = | Tool | Tool[] | null | undefined; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | ------------------------------------------------------------------------------------- | | `Context` | [`UnknownContext`](/openai-agents-js/openai/agents-core/type-aliases/unknowncontext/) | # CompletedAgentToolInvocationRunResult ```ts type CompletedAgentToolInvocationRunResult = CompletedRunResult & object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### agentToolInvocation [Section titled “agentToolInvocation”](#agenttoolinvocation) ```ts agentToolInvocation: AgentToolInvocation; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | ---------------------------------------------------------------------------------------------------- | | `TContext` | | `TAgent` *extends* [`Agent`](/openai-agents-js/openai/agents-core/classes/agent/)<`TContext`, `any`> | # Computer ```ts type Computer = Expand, never>>; ``` Interface representing a fully implemented computer environment. Combines the base operations with a constraint that no extra action names beyond those in `ComputerAction` are present. # ComputerCallResultItem ```ts type ComputerCallResultItem = ZodObject; ``` # ComputerCallResultItem ```ts type ComputerCallResultItem = object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### callId [Section titled “callId”](#callid) ```ts callId: string; ``` The ID of the computer call. Required to match up the respective computer call result. ### id? [Section titled “id?”](#id) ```ts optional id?: string; ``` An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. ### output [Section titled “output”](#output) ```ts output: object = ComputerToolOutput; ``` The output of the computer call. #### output.data [Section titled “output.data”](#outputdata) ```ts data: string; ``` A base64 encoded image data or a URL representing the screenshot. #### output.providerData? [Section titled “output.providerData?”](#outputproviderdata) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. #### output.type [Section titled “output.type”](#outputtype) ```ts type: "computer_screenshot"; ``` ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. ### type [Section titled “type”](#type) ```ts type: "computer_call_result"; ``` # ComputerOnSafetyCheckFunction ```ts type ComputerOnSafetyCheckFunction = (args) => Promise; ``` ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | -------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `args` | { `pendingSafetyChecks`: [`ComputerSafetyCheck`](/openai-agents-js/openai/agents-core/type-aliases/computersafetycheck/)\[]; `runContext`: [`RunContext`](/openai-agents-js/openai/agents-core/classes/runcontext/); `toolCall`: [`ComputerUseCallItem`](/openai-agents-js/openai/agents-core/type-aliases/computerusecallitem/); } | | `args.pendingSafetyChecks` | [`ComputerSafetyCheck`](/openai-agents-js/openai/agents-core/type-aliases/computersafetycheck/)\[] | | `args.runContext` | [`RunContext`](/openai-agents-js/openai/agents-core/classes/runcontext/) | | `args.toolCall` | [`ComputerUseCallItem`](/openai-agents-js/openai/agents-core/type-aliases/computerusecallitem/) | ## Returns [Section titled “Returns”](#returns) `Promise`<[`ComputerSafetyCheckResult`](/openai-agents-js/openai/agents-core/type-aliases/computersafetycheckresult/)> # ComputerSafetyCheck ```ts type ComputerSafetyCheck = object; ``` ## Indexable [Section titled “Indexable”](#indexable) ```ts [key: string]: unknown ``` ## Properties [Section titled “Properties”](#properties) ### code [Section titled “code”](#code) ```ts code: string; ``` *** ### id [Section titled “id”](#id) ```ts id: string; ``` *** ### message? [Section titled “message?”](#message) ```ts optional message?: string; ``` # ComputerSafetyCheckResult ```ts type ComputerSafetyCheckResult = | void | boolean | { acknowledgedSafetyChecks: ComputerSafetyCheck[]; } | { acknowledged_safety_checks: ComputerSafetyCheck[]; }; ``` # ComputerTool ```ts type ComputerTool = object; ``` Exposes a computer to the model as a tool to be called ## Param [Section titled “Param”](#param) The result of the tool ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | Description | | ----------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------- | ----------------------- | | `Context` | [`UnknownContext`](/openai-agents-js/openai/agents-core/type-aliases/unknowncontext/) | The context of the tool | | `TComputer` *extends* [`Computer`](/openai-agents-js/openai/agents-core/type-aliases/computer/) | [`Computer`](/openai-agents-js/openai/agents-core/type-aliases/computer/) | ‐ | ## Properties [Section titled “Properties”](#properties) ### computer [Section titled “computer”](#computer) ```ts computer: ComputerConfig; ``` The computer to use. *** ### name [Section titled “name”](#name) ```ts name: "computer_use_preview" | string & object; ``` The name of the tool. *** ### needsApproval [Section titled “needsApproval”](#needsapproval) ```ts needsApproval: ComputerApprovalFunction; ``` Predicate determining whether this computer action requires approval. *** ### onSafetyCheck? [Section titled “onSafetyCheck?”](#onsafetycheck) ```ts optional onSafetyCheck?: ComputerOnSafetyCheckFunction; ``` Optional handler to acknowledge pending safety checks. *** ### type [Section titled “type”](#type) ```ts type: "computer"; ``` # ComputerUseCallItem ```ts type ComputerUseCallItem = ZodObject; ``` # ComputerUseCallItem ```ts type ComputerUseCallItem = object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### action? [Section titled “action?”](#action) ```ts optional action?: | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; }; ``` The legacy single action to be performed by the computer. ### actions? [Section titled “actions?”](#actions) ```ts optional actions?: ( | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; })[]; ``` Batched actions returned by the GA computer tool. ### callId [Section titled “callId”](#callid) ```ts callId: string; ``` The ID of the computer call. Required to match up the respective computer call result. ### id? [Section titled “id?”](#id) ```ts optional id?: string; ``` An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. ### status [Section titled “status”](#status) ```ts status: "in_progress" | "completed" | "incomplete"; ``` The status of the computer call. ### type [Section titled “type”](#type) ```ts type: "computer_call"; ``` # CustomSpanData ```ts type CustomSpanData = SpanDataBase & object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### data [Section titled “data”](#data) ```ts data: Record; ``` ### name [Section titled “name”](#name) ```ts name: string; ``` ### type [Section titled “type”](#type) ```ts type: "custom"; ``` # EditorInvocationContext ```ts type EditorInvocationContext = object; ``` Runtime context passed to editor operations. ## Properties [Section titled “Properties”](#properties) ### runContext [Section titled “runContext”](#runcontext) ```ts runContext: RunContext; ``` Current run context. # FunctionCallItem ```ts type FunctionCallItem = ZodObject; ``` # FunctionCallItem ```ts type FunctionCallItem = object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### arguments [Section titled “arguments”](#arguments) ```ts arguments: string; ``` The arguments of the function call. ### callId [Section titled “callId”](#callid) ```ts callId: string; ``` The ID of the tool call. Required to match up the respective tool call result. ### id? [Section titled “id?”](#id) ```ts optional id?: string; ``` An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. ### name [Section titled “name”](#name) ```ts name: string; ``` The name of the function. ### namespace? [Section titled “namespace?”](#namespace) ```ts optional namespace?: string; ``` Optional namespace used to qualify the function name for tool search. ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. ### status? [Section titled “status?”](#status) ```ts optional status?: "in_progress" | "completed" | "incomplete"; ``` The status of the function call. ### type [Section titled “type”](#type) ```ts type: "function_call"; ``` # FunctionCallResultItem ```ts type FunctionCallResultItem = ZodObject; ``` # FunctionCallResultItem ```ts type FunctionCallResultItem = object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### callId [Section titled “callId”](#callid) ```ts callId: string; ``` The ID of the tool call. Required to match up the respective tool call result. ### id? [Section titled “id?”](#id) ```ts optional id?: string; ``` An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. ### name [Section titled “name”](#name) ```ts name: string; ``` The name of the tool that was called ### namespace? [Section titled “namespace?”](#namespace) ```ts optional namespace?: string; ``` Optional namespace preserved from the originating function call. ### output [Section titled “output”](#output) ```ts output: | string | { providerData?: Record; text: string; type: "text"; } | { detail?: "low" | "high" | "auto" | string & object; image?: | string | { data: string | Uint8Array; mediaType?: string; } | { url: string; } | { fileId: string; }; providerData?: Record; type: "image"; } | { file: | string | { data: string | Uint8Array; filename: string; mediaType: string; } | { filename?: string; url: string; } | { filename?: string; id: string; }; providerData?: Record; type: "file"; } | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; })[]; ``` The output of the tool call. #### Union Members [Section titled “Union Members”](#union-members) `string` *** ##### Type Literal [Section titled “Type Literal”](#type-literal) ```ts { providerData?: Record; text: string; type: "text"; } ``` | Name | Type | Description | | --------------- | ------------------------- | ------------------------------------------------------------------------------------------------------------ | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `text` | `string` | The text output from the model. | | `type` | `"text"` | ‐ | *** ##### Type Literal [Section titled “Type Literal”](#type-literal-1) ```ts { detail?: "low" | "high" | "auto" | string & object; image?: | string | { data: string | Uint8Array; mediaType?: string; } | { url: string; } | { fileId: string; }; providerData?: Record; type: "image"; } ``` | Name | Type | Description | | --------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------ | | `detail?` | `"low"` \| `"high"` \| `"auto"` \| `string` & `object` | Controls the requested level of detail for vision models. Use a string to avoid constraining future model capabilities. | | `image?` | \| `string` \| { `data`: `string` \| `Uint8Array`<`ArrayBuffer`>; `mediaType?`: `string`; } \| { `url`: `string`; } \| { `fileId`: `string`; } | Inline image content or a reference to an uploaded file. Accepts a URL/data URL string or an object describing the data/url/fileId source. | | `providerData?` | `Record`<`string`, `any`> | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `type` | `"image"` | ‐ | *** ##### Type Literal [Section titled “Type Literal”](#type-literal-2) ```ts { file: | string | { data: string | Uint8Array; filename: string; mediaType: string; } | { filename?: string; url: string; } | { filename?: string; id: string; }; providerData?: Record; type: "file"; } ``` | Name | Type | Default value | Description | | --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `file` | \| `string` \| { `data`: `string` \| `Uint8Array`<`ArrayBuffer`>; `filename`: `string`; `mediaType`: `string`; } \| { `filename?`: `string`; `url`: `string`; } \| { `filename?`: `string`; `id`: `string`; } | `FileReferenceSchema` | File output reference. Provide either a string (data URL / base64), a data object (requires mediaType + filename), or an object pointing to an uploaded file/URL. | | `providerData?` | `Record`<`string`, `any`> | ‐ | Additional optional provider specific data. Used for custom functionality or model provider specific fields. | | `type` | `"file"` | ‐ | ‐ | *** ( | { `providerData?`: `Record`<`string`, `any`>; `text`: `string`; `type`: `"input_text"`; } | { `detail?`: `string`; `image?`: | `string` | { `id`: `string`; }; `providerData?`: `Record`<`string`, `any`>; `type`: `"input_image"`; } | { `file?`: | `string` | { `id`: `string`; } | { `url`: `string`; }; `filename?`: `string`; `providerData?`: `Record`<`string`, `any`>; `type`: `"input_file"`; })\[] ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. ### status [Section titled “status”](#status) ```ts status: "in_progress" | "completed" | "incomplete"; ``` The status of the tool call. ### type [Section titled “type”](#type) ```ts type: "function_call_result"; ``` # FunctionSpanData ```ts type FunctionSpanData = SpanDataBase & object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### input [Section titled “input”](#input) ```ts input: string; ``` ### mcp\_data? [Section titled “mcp\_data?”](#mcp_data) ```ts optional mcp_data?: string; ``` ### name [Section titled “name”](#name) ```ts name: string; ``` ### output [Section titled “output”](#output) ```ts output: string; ``` ### type [Section titled “type”](#type) ```ts type: "function"; ``` # FunctionTool ```ts type FunctionTool = object; ``` Exposes a function to the agent as a tool to be called ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | Description | | ----------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------- | ----------------------- | | `Context` | [`UnknownContext`](/openai-agents-js/openai/agents-core/type-aliases/unknowncontext/) | The context of the tool | | `TParameters` *extends* [`ToolInputParameters`](/openai-agents-js/openai/agents-core/type-aliases/toolinputparameters/) | `undefined` | ‐ | | `Result` | `unknown` | The result of the tool | ## Properties [Section titled “Properties”](#properties) ### deferLoading? [Section titled “deferLoading?”](#deferloading) ```ts optional deferLoading?: boolean; ``` Responses API only. Hides a top-level function tool definition until tool search loads it. *** ### description [Section titled “description”](#description) ```ts description: string; ``` The description of the tool that helps the model to understand when to use the tool *** ### inputGuardrails? [Section titled “inputGuardrails?”](#inputguardrails) ```ts optional inputGuardrails?: ToolInputGuardrailDefinition[]; ``` Guardrails that run before the tool executes. *** ### invoke [Section titled “invoke”](#invoke) ```ts invoke: (runContext, input, details?) => Promise; ``` The function to invoke when the tool is called. #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ------------ | ----------------------------------------------------------------------------------- | | `runContext` | [`RunContext`](/openai-agents-js/openai/agents-core/classes/runcontext/)<`Context`> | | `input` | `string` | | `details?` | `ToolCallDetails` | #### Returns [Section titled “Returns”](#returns) `Promise`<`string` | `Result`> *** ### isEnabled [Section titled “isEnabled”](#isenabled) ```ts isEnabled: ToolEnabledFunction; ``` Determines whether the tool should be made available to the model for the current run. *** ### name [Section titled “name”](#name) ```ts name: string; ``` The name of the tool. *** ### needsApproval [Section titled “needsApproval”](#needsapproval) ```ts needsApproval: ToolApprovalFunction; ``` Whether the tool needs human approval before it can be called. If this is true, the run will result in an `interruption` that the program has to resolve by approving or rejecting the tool call. *** ### outputGuardrails? [Section titled “outputGuardrails?”](#outputguardrails) ```ts optional outputGuardrails?: ToolOutputGuardrailDefinition[]; ``` Guardrails that run after the tool executes. *** ### parameters [Section titled “parameters”](#parameters-1) ```ts parameters: JsonObjectSchema; ``` A JSON schema describing the parameters of the tool. *** ### strict [Section titled “strict”](#strict) ```ts strict: boolean; ``` Whether the tool is strict. If true, the model must try to strictly follow the schema (might result in slower response times). *** ### timeoutBehavior? [Section titled “timeoutBehavior?”](#timeoutbehavior) ```ts optional timeoutBehavior?: FunctionToolTimeoutBehavior; ``` Defines how timeout errors are handled. * `error_as_result`: return a model-visible timeout message. * `raise_exception`: raise `ToolTimeoutError` and fail the run. *** ### timeoutErrorFunction? [Section titled “timeoutErrorFunction?”](#timeouterrorfunction) ```ts optional timeoutErrorFunction?: ToolTimeoutErrorFunction; ``` Optional formatter for timeout errors when timeoutBehavior is `error_as_result`. *** ### timeoutMs? [Section titled “timeoutMs?”](#timeoutms) ```ts optional timeoutMs?: number; ``` Optional timeout in milliseconds for each tool invocation. *** ### type [Section titled “type”](#type) ```ts type: "function"; ``` # FunctionToolResult ```ts type FunctionToolResult = | { agentRunResult?: RunResult>; interruptions?: RunToolApprovalItem[]; output: string | unknown; runItem: RunToolCallOutputItem; tool: FunctionTool; type: "function_output"; } | { runItem: RunToolApprovalItem; tool: FunctionTool; type: "function_approval"; } | { runItem: RunToolApprovalItem; tool: HostedMCPTool; type: "hosted_mcp_tool_approval"; }; ``` The result of invoking a function tool. Either the actual output of the execution or a tool approval request. These get passed for example to the `toolUseBehavior` option of the `Agent` constructor. ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | ----------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------- | | `Context` | [`UnknownContext`](/openai-agents-js/openai/agents-core/type-aliases/unknowncontext/) | | `TParameters` *extends* [`ToolInputParameters`](/openai-agents-js/openai/agents-core/type-aliases/toolinputparameters/) | `any` | | `Result` | `any` | ## Union Members [Section titled “Union Members”](#union-members) ### Type Literal [Section titled “Type Literal”](#type-literal) ```ts { agentRunResult?: RunResult>; interruptions?: RunToolApprovalItem[]; output: string | unknown; runItem: RunToolCallOutputItem; tool: FunctionTool; type: "function_output"; } ``` #### agentRunResult? [Section titled “agentRunResult?”](#agentrunresult) ```ts optional agentRunResult?: RunResult>; ``` The result returned when the tool execution runs another agent. Populated when the invocation originated from [Agent.asTool](/openai-agents-js/openai/agents-core/classes/agent/#astool) and the nested agent completed a run. #### interruptions? [Section titled “interruptions?”](#interruptions) ```ts optional interruptions?: RunToolApprovalItem[]; ``` Any interruptions collected while the nested agent executed. These are surfaced to allow callers to pause and resume workflows that require approvals. #### output [Section titled “output”](#output) ```ts output: string | unknown; ``` The output of the tool call. This can be a string or a stringifable item. #### runItem [Section titled “runItem”](#runitem) ```ts runItem: RunToolCallOutputItem; ``` The run item representing the tool call output. #### tool [Section titled “tool”](#tool) ```ts tool: FunctionTool; ``` The tool that was called. #### type [Section titled “type”](#type) ```ts type: "function_output"; ``` *** ### Type Literal [Section titled “Type Literal”](#type-literal-1) ```ts { runItem: RunToolApprovalItem; tool: FunctionTool; type: "function_approval"; } ``` #### runItem [Section titled “runItem”](#runitem-1) ```ts runItem: RunToolApprovalItem; ``` The item representing the tool call that is requiring approval. #### tool [Section titled “tool”](#tool-1) ```ts tool: FunctionTool; ``` The tool that is requiring to be approved. #### type [Section titled “type”](#type-1) ```ts type: "function_approval"; ``` Indicates that the tool requires approval before it can be called. *** ### Type Literal [Section titled “Type Literal”](#type-literal-2) ```ts { runItem: RunToolApprovalItem; tool: HostedMCPTool; type: "hosted_mcp_tool_approval"; } ``` #### runItem [Section titled “runItem”](#runitem-2) ```ts runItem: RunToolApprovalItem; ``` The item representing the tool call that is requiring approval. #### tool [Section titled “tool”](#tool-2) ```ts tool: HostedMCPTool; ``` The tool that is requiring to be approved. #### type [Section titled “type”](#type-2) ```ts type: "hosted_mcp_tool_approval"; ``` Indicates that the tool requires approval before it can be called. # FunctionToolTimeoutBehavior ```ts type FunctionToolTimeoutBehavior = "error_as_result" | "raise_exception"; ``` # GenerationSpanData ```ts type GenerationSpanData = SpanDataBase & object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### input? [Section titled “input?”](#input) ```ts optional input?: Record[]; ``` ### model? [Section titled “model?”](#model) ```ts optional model?: string; ``` ### model\_config? [Section titled “model\_config?”](#model_config) ```ts optional model_config?: Record; ``` ### output? [Section titled “output?”](#output) ```ts optional output?: Record[]; ``` ### type [Section titled “type”](#type) ```ts type: "generation"; ``` ### usage? [Section titled “usage?”](#usage) ```ts optional usage?: GenerationUsageData; ``` Usage fields are intentionally flexible in agents-core tracing. Exporters are responsible for backend-specific mapping and validation. For example, the OpenAI tracing exporter in `@openai/agents-openai` keeps top-level generation usage to `input_tokens` and `output_tokens` for OpenAI traces ingest, and maps additional usage fields under `usage.details`. Third-party exporters can choose their own usage schema and transformation strategy. # GenerationUsageData ```ts type GenerationUsageData = object; ``` ## Indexable [Section titled “Indexable”](#indexable) ```ts [key: string]: unknown ``` ## Properties [Section titled “Properties”](#properties) ### details? [Section titled “details?”](#details) ```ts optional details?: Record | null; ``` *** ### input\_tokens? [Section titled “input\_tokens?”](#input_tokens) ```ts optional input_tokens?: number; ``` *** ### output\_tokens? [Section titled “output\_tokens?”](#output_tokens) ```ts optional output_tokens?: number; ``` # GetAllMcpToolsOptions ```ts type GetAllMcpToolsOptions = object; ``` Options for fetching MCP tools. ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | -------------- | | `TContext` | ## Properties [Section titled “Properties”](#properties) ### agent? [Section titled “agent?”](#agent) ```ts optional agent?: Agent; ``` *** ### convertSchemasToStrict? [Section titled “convertSchemasToStrict?”](#convertschemastostrict) ```ts optional convertSchemasToStrict?: boolean; ``` *** ### errorFunction? [Section titled “errorFunction?”](#errorfunction) ```ts optional errorFunction?: | MCPToolErrorFunction | null; ``` *** ### generateMCPToolCacheKey? [Section titled “generateMCPToolCacheKey?”](#generatemcptoolcachekey) ```ts optional generateMCPToolCacheKey?: MCPToolCacheKeyGenerator; ``` *** ### includeServerInToolNames? [Section titled “includeServerInToolNames?”](#includeserverintoolnames) ```ts optional includeServerInToolNames?: boolean; ``` *** ### mcpServers [Section titled “mcpServers”](#mcpservers) ```ts mcpServers: MCPServer[]; ``` *** ### reservedToolNames? [Section titled “reservedToolNames?”](#reservedtoolnames) ```ts optional reservedToolNames?: Set; ``` *** ### runContext? [Section titled “runContext?”](#runcontext) ```ts optional runContext?: RunContext; ``` # GuardrailSpanData ```ts type GuardrailSpanData = SpanDataBase & object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### name [Section titled “name”](#name) ```ts name: string; ``` ### triggered [Section titled “triggered”](#triggered) ```ts triggered: boolean; ``` ### type [Section titled “type”](#type) ```ts type: "guardrail"; ``` # HandoffEnabledFunction ```ts type HandoffEnabledFunction = (args) => Promise; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | ------------------------------------------------------------------------------------- | | `TContext` | [`UnknownContext`](/openai-agents-js/openai/agents-core/type-aliases/unknowncontext/) | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ----------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `args` | { `agent`: [`Agent`](/openai-agents-js/openai/agents-core/classes/agent/)<`any`, `any`>; `runContext`: [`RunContext`](/openai-agents-js/openai/agents-core/classes/runcontext/)<`TContext`>; } | | `args.agent` | [`Agent`](/openai-agents-js/openai/agents-core/classes/agent/)<`any`, `any`> | | `args.runContext` | [`RunContext`](/openai-agents-js/openai/agents-core/classes/runcontext/)<`TContext`> | ## Returns [Section titled “Returns”](#returns) `Promise`<`boolean`> # HandoffInputData ```ts type HandoffInputData = object; ``` Data passed to the handoff function. ## Properties [Section titled “Properties”](#properties) ### inputHistory [Section titled “inputHistory”](#inputhistory) ```ts inputHistory: | string | AgentInputItem[]; ``` The input history before `Runner.run()` was called. *** ### newItems [Section titled “newItems”](#newitems) ```ts newItems: RunItem[]; ``` The new items generated during the current agent turn, including the item that triggered the handoff and the tool output message representing the response from the handoff output. *** ### preHandoffItems [Section titled “preHandoffItems”](#prehandoffitems) ```ts preHandoffItems: RunItem[]; ``` The items generated before the agent turn where the handoff was invoked. *** ### runContext? [Section titled “runContext?”](#runcontext) ```ts optional runContext?: RunContext; ``` The context of the handoff. Note that, since this property was added later on, it’s optional to pass from users. # HandoffSpanData ```ts type HandoffSpanData = SpanDataBase & object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### from\_agent? [Section titled “from\_agent?”](#from_agent) ```ts optional from_agent?: string; ``` ### to\_agent? [Section titled “to\_agent?”](#to_agent) ```ts optional to_agent?: string; ``` ### type [Section titled “type”](#type) ```ts type: "handoff"; ``` # HostedMCPTool ```ts type HostedMCPTool = HostedTool & object; ``` A hosted MCP tool that lets the model call a remote MCP server directly without a round trip back to your code. ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### name [Section titled “name”](#name) ```ts name: "hosted_mcp"; ``` ### providerData [Section titled “providerData”](#providerdata) ```ts providerData: ProviderData.HostedMCPTool; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | ------------------------------------------------------------------------------------- | | `Context` | [`UnknownContext`](/openai-agents-js/openai/agents-core/type-aliases/unknowncontext/) | # HostedTool ```ts type HostedTool = object; ``` A built-in hosted tool that will be executed directly by the model during the request and won’t result in local code executions. Examples of these are `web_search_call` or `file_search_call`. ## Param [Section titled “Param”](#param) The context of the tool ## Param [Section titled “Param”](#param-1) The result of the tool ## Properties [Section titled “Properties”](#properties) ### name [Section titled “name”](#name) ```ts name: string; ``` A unique name for the tool. *** ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` Additional configuration data that gets passed to the tool *** ### type [Section titled “type”](#type) ```ts type: "hosted_tool"; ``` # HostedToolCallItem ```ts type HostedToolCallItem = ZodObject; ``` # HostedToolCallItem ```ts type HostedToolCallItem = object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### arguments? [Section titled “arguments?”](#arguments) ```ts optional arguments?: string; ``` The arguments of the hosted tool call. ### id? [Section titled “id?”](#id) ```ts optional id?: string; ``` An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. ### name [Section titled “name”](#name) ```ts name: string; ``` The name of the hosted tool. For example `web_search_call` or `file_search_call` ### output? [Section titled “output?”](#output) ```ts optional output?: string; ``` The primary output of the tool call. Additional output might be in the `providerData` field. ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. ### status? [Section titled “status?”](#status) ```ts optional status?: string; ``` The status of the tool call. ### type [Section titled “type”](#type) ```ts type: "hosted_tool_call"; ``` # IndividualRunOptions ```ts type IndividualRunOptions = | StreamRunOptions | NonStreamRunOptions; ``` Options polymorphic over streaming or non-streaming execution modes. ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | ----------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------- | | `TContext` | `undefined` | | `TAgent` *extends* [`Agent`](/openai-agents-js/openai/agents-core/classes/agent/)<`any`, `any`> | [`Agent`](/openai-agents-js/openai/agents-core/classes/agent/)<`any`, `any`> | # InputGuardrailFunction ```ts type InputGuardrailFunction = (args) => Promise; ``` The function that performs the actual input guardrail check and returns the decision on whether a guardrail was triggered. ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ----------------------------------------------------------------------------------------------------------- | | `args` | [`InputGuardrailFunctionArgs`](/openai-agents-js/openai/agents-core/interfaces/inputguardrailfunctionargs/) | ## Returns [Section titled “Returns”](#returns) `Promise`<[`GuardrailFunctionOutput`](/openai-agents-js/openai/agents-core/interfaces/guardrailfunctionoutput/)> # JsonSchemaDefinition ```ts type JsonSchemaDefinition = object; ``` Wrapper around a JSON schema used for describing tool parameters. ## Properties [Section titled “Properties”](#properties) ### name [Section titled “name”](#name) ```ts name: string; ``` *** ### schema [Section titled “schema”](#schema) ```ts schema: JsonObjectSchema>; ``` *** ### strict [Section titled “strict”](#strict) ```ts strict: boolean; ``` *** ### type [Section titled “type”](#type) ```ts type: "json_schema"; ``` # MCPListToolsSpanData ```ts type MCPListToolsSpanData = SpanDataBase & object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### result? [Section titled “result?”](#result) ```ts optional result?: string[]; ``` ### server? [Section titled “server?”](#server) ```ts optional server?: string; ``` ### type [Section titled “type”](#type) ```ts type: "mcp_tools"; ``` # MCPResourceContent ```ts type MCPResourceContent = | MCPTextResourceContent | MCPBlobResourceContent; ``` # MCPServersOptions ```ts type MCPServersOptions = object; ``` ## Properties [Section titled “Properties”](#properties) ### closeTimeoutMs? [Section titled “closeTimeoutMs?”](#closetimeoutms) ```ts optional closeTimeoutMs?: number | null; ``` *** ### connectInParallel? [Section titled “connectInParallel?”](#connectinparallel) ```ts optional connectInParallel?: boolean; ``` *** ### connectTimeoutMs? [Section titled “connectTimeoutMs?”](#connecttimeoutms) ```ts optional connectTimeoutMs?: number | null; ``` *** ### dropFailed? [Section titled “dropFailed?”](#dropfailed) ```ts optional dropFailed?: boolean; ``` *** ### strict? [Section titled “strict?”](#strict) ```ts optional strict?: boolean; ``` *** ### suppressAbortError? [Section titled “suppressAbortError?”](#suppressaborterror) ```ts optional suppressAbortError?: boolean; ``` # MCPServersReconnectOptions ```ts type MCPServersReconnectOptions = object; ``` ## Properties [Section titled “Properties”](#properties) ### failedOnly? [Section titled “failedOnly?”](#failedonly) ```ts optional failedOnly?: boolean; ``` # MCPToolCacheKeyGenerator ```ts type MCPToolCacheKeyGenerator = (params) => string; ``` Function signature for generating the MCP tool cache key. Customizable so the cache key can depend on any context—server, agent, runContext, etc. ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | -------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `params` | { `agent?`: [`Agent`](/openai-agents-js/openai/agents-core/classes/agent/)<`any`, `any`>; `runContext?`: [`RunContext`](/openai-agents-js/openai/agents-core/classes/runcontext/)<`any`>; `server`: [`MCPServer`](/openai-agents-js/openai/agents-core/interfaces/mcpserver/); } | | `params.agent?` | [`Agent`](/openai-agents-js/openai/agents-core/classes/agent/)<`any`, `any`> | | `params.runContext?` | [`RunContext`](/openai-agents-js/openai/agents-core/classes/runcontext/)<`any`> | | `params.server` | [`MCPServer`](/openai-agents-js/openai/agents-core/interfaces/mcpserver/) | ## Returns [Section titled “Returns”](#returns) `string` # MCPToolErrorFunction ```ts type MCPToolErrorFunction = (args) => Promise | string; ``` ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | -------------- | ----------------------------------------------------------------------------------------------------------------------- | | `args` | { `context`: [`RunContext`](/openai-agents-js/openai/agents-core/classes/runcontext/); `error`: `Error` \| `unknown`; } | | `args.context` | [`RunContext`](/openai-agents-js/openai/agents-core/classes/runcontext/) | | `args.error` | `Error` \| `unknown` | ## Returns [Section titled “Returns”](#returns) `Promise`<`string`> | `string` # MCPToolFilterCallable ```ts type MCPToolFilterCallable = (context, tool) => Promise; ``` A function that determines whether a tool should be available. ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | ------------------------------------------------------------------------------------- | | `TContext` | [`UnknownContext`](/openai-agents-js/openai/agents-core/type-aliases/unknowncontext/) | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ----------------------------------------------------------------------------------------------------------- | | `context` | [`MCPToolFilterContext`](/openai-agents-js/openai/agents-core/interfaces/mcptoolfiltercontext/)<`TContext`> | | `tool` | `MCPTool` | ## Returns [Section titled “Returns”](#returns) `Promise`<`boolean`> # MCPToolMetaResolver ```ts type MCPToolMetaResolver = (context) => | Promise | null | undefined> | Record | null | undefined; ``` A function that produces MCP request metadata (`_meta`) for tool calls. ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | ------------------------------------------------------------------------------------- | | `TContext` | [`UnknownContext`](/openai-agents-js/openai/agents-core/type-aliases/unknowncontext/) | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ------------------------------------------------------------------------------------------------------- | | `context` | [`MCPToolMetaContext`](/openai-agents-js/openai/agents-core/interfaces/mcptoolmetacontext/)<`TContext`> | ## Returns [Section titled “Returns”](#returns) \| `Promise`<`Record`<`string`, `unknown`> | `null` | `undefined`> | `Record`<`string`, `unknown`> | `null` | `undefined` # ModelInputData ```ts type ModelInputData = object; ``` ## Properties [Section titled “Properties”](#properties) ### input [Section titled “input”](#input) ```ts input: AgentInputItem[]; ``` *** ### instructions? [Section titled “instructions?”](#instructions) ```ts optional instructions?: string; ``` # ModelRequest ```ts type ModelRequest = object; ``` A request to a large language model. ## Properties [Section titled “Properties”](#properties) ### conversationId? [Section titled “conversationId?”](#conversationid) ```ts optional conversationId?: string; ``` The ID of stored conversation to use for the model. see see *** ### handoffs [Section titled “handoffs”](#handoffs) ```ts handoffs: SerializedHandoff[]; ``` The handoffs to use for the model. *** ### input [Section titled “input”](#input) ```ts input: | string | AgentInputItem[]; ``` The input to the model. *** ### modelSettings [Section titled “modelSettings”](#modelsettings) ```ts modelSettings: ModelSettings; ``` The model settings to use for the model. *** ### outputType [Section titled “outputType”](#outputtype) ```ts outputType: SerializedOutputType; ``` The type of the output to use for the model. *** ### overridePromptModel? [Section titled “overridePromptModel?”](#overridepromptmodel) ```ts optional overridePromptModel?: boolean; ``` When true, the resolved model should override the model configured in the prompt template. Providers that support prompt templates should include the explicit model name in the request even when a prompt is supplied. *** ### previousResponseId? [Section titled “previousResponseId?”](#previousresponseid) ```ts optional previousResponseId?: string; ``` The ID of the previous response to use for the model. *** ### prompt? [Section titled “prompt?”](#prompt) ```ts optional prompt?: Prompt; ``` The prompt template to use for the model, if any. *** ### signal? [Section titled “signal?”](#signal) ```ts optional signal?: AbortSignal; ``` An optional signal to abort the model request. *** ### systemInstructions? [Section titled “systemInstructions?”](#systeminstructions) ```ts optional systemInstructions?: string; ``` The system instructions to use for the model. *** ### tools [Section titled “tools”](#tools) ```ts tools: SerializedTool[]; ``` The tools to use for the model. *** ### toolsExplicitlyProvided? [Section titled “toolsExplicitlyProvided?”](#toolsexplicitlyprovided) ```ts optional toolsExplicitlyProvided?: boolean; ``` When true, the caller explicitly configured the tools list (even if empty). Providers can use this to avoid overwriting prompt-defined tools when an agent does not specify its own tools. *** ### tracing [Section titled “tracing”](#tracing) ```ts tracing: ModelTracing; ``` Whether to enable tracing for the model. # ModelResponse ```ts type ModelResponse = object; ``` ## Properties [Section titled “Properties”](#properties) ### output [Section titled “output”](#output) ```ts output: AgentOutputItem[]; ``` A list of outputs (messages, tool calls, etc.) generated by the model. *** ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` Raw response data from the underlying model provider. *** ### requestId? [Section titled “requestId?”](#requestid) ```ts optional requestId?: string; ``` The transport request ID for this model call, if provided by the model SDK or transport. *** ### responseId? [Section titled “responseId?”](#responseid) ```ts optional responseId?: string; ``` An ID for the response which can be used to refer to the response in subsequent calls to the model. Not supported by all model providers. *** ### usage [Section titled “usage”](#usage) ```ts usage: Usage; ``` The usage information for response. # ModelRetryAdvice ```ts type ModelRetryAdvice = object; ``` ## Properties [Section titled “Properties”](#properties) ### normalized? [Section titled “normalized?”](#normalized) ```ts optional normalized?: Partial; ``` Provider-supplied normalized facts that should override generic extraction when present. *** ### reason? [Section titled “reason?”](#reason) ```ts optional reason?: string; ``` Optional explanation for why the provider suggested or vetoed a retry. *** ### replaySafety? [Section titled “replaySafety?”](#replaysafety) ```ts optional replaySafety?: "unsafe" | "safe"; ``` Provider confidence about whether replaying the request is safe. Omit this field when replay safety is unknown. *** ### retryAfterMs? [Section titled “retryAfterMs?”](#retryafterms) ```ts optional retryAfterMs?: number; ``` Optional delay hint in milliseconds from the provider or transport layer. *** ### suggested? [Section titled “suggested?”](#suggested) ```ts optional suggested?: boolean; ``` Optional provider recommendation for whether this error is retryable. The runner still applies safety vetoes first and user policy remains the final authority. # ModelRetryAdviceRequest ```ts type ModelRetryAdviceRequest = object; ``` ## Properties [Section titled “Properties”](#properties) ### attempt [Section titled “attempt”](#attempt) ```ts attempt: number; ``` The 1-based number of the failed attempt. *** ### error [Section titled “error”](#error) ```ts error: unknown; ``` The error thrown by the failed attempt. *** ### request [Section titled “request”](#request) ```ts request: ModelRequest; ``` The failed request that is being evaluated for replay. *** ### stream [Section titled “stream”](#stream) ```ts stream: boolean; ``` Whether the failed request used streaming. # ModelRetryBackoffSettings ```ts type ModelRetryBackoffSettings = object; ``` ## Properties [Section titled “Properties”](#properties) ### initialDelayMs? [Section titled “initialDelayMs?”](#initialdelayms) ```ts optional initialDelayMs?: number; ``` Delay for the first retry in milliseconds. *** ### jitter? [Section titled “jitter?”](#jitter) ```ts optional jitter?: boolean; ``` Whether to apply jitter to the computed backoff delay. *** ### maxDelayMs? [Section titled “maxDelayMs?”](#maxdelayms) ```ts optional maxDelayMs?: number; ``` Maximum delay between retries in milliseconds. *** ### multiplier? [Section titled “multiplier?”](#multiplier) ```ts optional multiplier?: number; ``` Multiplier applied after each retry attempt. # ModelRetryNormalizedError ```ts type ModelRetryNormalizedError = object; ``` ## Properties [Section titled “Properties”](#properties) ### errorCode? [Section titled “errorCode?”](#errorcode) ```ts optional errorCode?: string; ``` Provider or transport-specific error code when exposed. *** ### isAbort [Section titled “isAbort”](#isabort) ```ts isAbort: boolean; ``` Whether the error was caused by an abort signal or abort exception. *** ### isNetworkError [Section titled “isNetworkError”](#isnetworkerror) ```ts isNetworkError: boolean; ``` Whether the error appears to come from a transient transport or connectivity problem. *** ### retryAfterMs? [Section titled “retryAfterMs?”](#retryafterms) ```ts optional retryAfterMs?: number; ``` Suggested delay in milliseconds derived from retry-after style headers. *** ### statusCode? [Section titled “statusCode?”](#statuscode) ```ts optional statusCode?: number; ``` HTTP status code when the provider exposes one. # ModelRetrySettings ```ts type ModelRetrySettings = object; ``` ## Properties [Section titled “Properties”](#properties) ### backoff? [Section titled “backoff?”](#backoff) ```ts optional backoff?: ModelRetryBackoffSettings; ``` Backoff configuration used when the retry policy requests a retry without returning an explicit delay. *** ### maxRetries? [Section titled “maxRetries?”](#maxretries) ```ts optional maxRetries?: number; ``` Number of retries allowed after the initial model request. Retries remain opt-in; no retries occur unless `policy` returns `true`. *** ### policy? [Section titled “policy?”](#policy) ```ts optional policy?: RetryPolicy; ``` Runtime-only retry policy. This callback is not serialized into persisted run state. # ModelSettings ```ts type ModelSettings = object; ``` Settings to use when calling an LLM. This class holds optional model configuration parameters (e.g. temperature, topP, penalties, truncation, etc.). Not all models/providers support all of these parameters, so please check the API documentation for the specific model and provider you are using. ## Properties [Section titled “Properties”](#properties) ### contextManagement? [Section titled “contextManagement?”](#contextmanagement) ```ts optional contextManagement?: ModelSettingsContextManagement; ``` Context-management strategies to apply when calling the model. This setting is available on OpenAI Responses requests, including server-side compaction. See . *** ### frequencyPenalty? [Section titled “frequencyPenalty?”](#frequencypenalty) ```ts optional frequencyPenalty?: number; ``` The frequency penalty to use when calling the model. *** ### maxTokens? [Section titled “maxTokens?”](#maxtokens) ```ts optional maxTokens?: number; ``` The maximum number of output tokens to generate. *** ### parallelToolCalls? [Section titled “parallelToolCalls?”](#paralleltoolcalls) ```ts optional parallelToolCalls?: boolean; ``` Whether to use parallel tool calls when calling the model. Defaults to false if not provided. *** ### presencePenalty? [Section titled “presencePenalty?”](#presencepenalty) ```ts optional presencePenalty?: number; ``` The presence penalty to use when calling the model. *** ### promptCacheRetention? [Section titled “promptCacheRetention?”](#promptcacheretention) ```ts optional promptCacheRetention?: "in-memory" | "24h" | null; ``` Enables prompt caching and controls how long cached content should be retained by the model provider. See for the available options. *** ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` Additional provider specific settings to be passed directly to the model request. *** ### reasoning? [Section titled “reasoning?”](#reasoning) ```ts optional reasoning?: ModelSettingsReasoning; ``` The reasoning settings to use when calling the model. *** ### retry? [Section titled “retry?”](#retry) ```ts optional retry?: ModelRetrySettings; ``` Runtime-only retry configuration for the model request. *** ### store? [Section titled “store?”](#store) ```ts optional store?: boolean; ``` Whether to store the generated model response for later retrieval. Defaults to true if not provided. *** ### temperature? [Section titled “temperature?”](#temperature) ```ts optional temperature?: number; ``` The temperature to use when calling the model. *** ### text? [Section titled “text?”](#text) ```ts optional text?: ModelSettingsText; ``` The text settings to use when calling the model. *** ### toolChoice? [Section titled “toolChoice?”](#toolchoice) ```ts optional toolChoice?: ModelSettingsToolChoice; ``` The tool choice to use when calling the model. *** ### topP? [Section titled “topP?”](#topp) ```ts optional topP?: number; ``` The topP to use when calling the model. *** ### truncation? [Section titled “truncation?”](#truncation) ```ts optional truncation?: "auto" | "disabled"; ``` The truncation strategy to use when calling the model. # ModelSettingsContextManagement ```ts type ModelSettingsContextManagement = object[]; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ## Index Signature [Section titled “Index Signature”](#index-signature) ```ts [key: string]: unknown ``` ### compact\_threshold? [Section titled “compact\_threshold?”](#compact_threshold) ```ts optional compact_threshold?: number; ``` Rendered-token threshold that triggers server-side compaction. ### compactThreshold? [Section titled “compactThreshold?”](#compactthreshold) ```ts optional compactThreshold?: number; ``` Rendered-token threshold that triggers server-side compaction. ### type [Section titled “type”](#type) ```ts type: "compaction" | string & object; ``` The context-management strategy to apply. # ModelSettingsToolChoice ```ts type ModelSettingsToolChoice = "auto" | "required" | "none" | string & object; ``` # NonStreamRunOptions ```ts type NonStreamRunOptions = SharedRunOptions & object; ``` Options for runs that collect the full model response before returning. ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### stream? [Section titled “stream?”](#stream) ```ts optional stream?: false; ``` Run to completion without streaming incremental events; leave undefined or set to `false`. ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | ----------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------- | | `TContext` | `undefined` | | `TAgent` *extends* [`Agent`](/openai-agents-js/openai/agents-core/classes/agent/)<`any`, `any`> | [`Agent`](/openai-agents-js/openai/agents-core/classes/agent/)<`any`, `any`> | # OpenAIResponsesCompactionArgs ```ts type OpenAIResponsesCompactionArgs = object; ``` Session subtype that can run compaction logic after a completed turn is persisted. ## Properties [Section titled “Properties”](#properties) ### compactionMode? [Section titled “compactionMode?”](#compactionmode) ```ts optional compactionMode?: "previous_response_id" | "input" | "auto"; ``` How the compaction request should provide conversation history. When omitted, implementations use their configured default. *** ### force? [Section titled “force?”](#force) ```ts optional force?: boolean; ``` When true, compaction should run regardless of any internal thresholds or hooks. *** ### responseId? [Section titled “responseId?”](#responseid) ```ts optional responseId?: string; ``` The `response.id` from a completed OpenAI Responses API turn, if available. When omitted, implementations may fall back to a cached value or throw. *** ### store? [Section titled “store?”](#store) ```ts optional store?: boolean; ``` Whether the last model response was stored on the server. When set to false, compaction should avoid `previous_response_id` unless explicitly overridden. # OpenAIResponsesCompactionResult ```ts type OpenAIResponsesCompactionResult = object; ``` ## Properties [Section titled “Properties”](#properties) ### usage [Section titled “usage”](#usage) ```ts usage: RequestUsage; ``` # OutputGuardrailFunction ```ts type OutputGuardrailFunction = (args) => Promise; ``` A function that takes an output guardrail function arguments and returns a `GuardrailFunctionOutput`. ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | ----------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------- | | `TOutput` *extends* [`AgentOutputType`](/openai-agents-js/openai/agents-core/type-aliases/agentoutputtype/) | [`TextOutput`](/openai-agents-js/openai/agents-core/type-aliases/textoutput/) | | `TContext` | [`UnknownContext`](/openai-agents-js/openai/agents-core/type-aliases/unknowncontext/) | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ------------------------------------------------------------------------------------------------------------------------------------ | | `args` | [`OutputGuardrailFunctionArgs`](/openai-agents-js/openai/agents-core/interfaces/outputguardrailfunctionargs/)<`TContext`, `TOutput`> | ## Returns [Section titled “Returns”](#returns) `Promise`<[`GuardrailFunctionOutput`](/openai-agents-js/openai/agents-core/interfaces/guardrailfunctionoutput/)> # ReasoningItem ```ts type ReasoningItem = ZodObject; ``` # ReasoningItem ```ts type ReasoningItem = object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### content [Section titled “content”](#content) ```ts content: object[]; ``` The user facing representation of the reasoning. Additional information might be in the `providerData` field. ### id? [Section titled “id?”](#id) ```ts optional id?: string; ``` ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. ### rawContent? [Section titled “rawContent?”](#rawcontent) ```ts optional rawContent?: object[]; ``` The raw reasoning text from the model. ### type [Section titled “type”](#type) ```ts type: "reasoning"; ``` # ReasoningItemIdPolicy ```ts type ReasoningItemIdPolicy = "preserve" | "omit"; ``` # ResponseSpanData ```ts type ResponseSpanData = SpanDataBase & object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### \_input? [Section titled “\_input?”](#_input) ```ts optional _input?: string | Record[]; ``` Not used by the OpenAI tracing provider but helpful for other tracing providers. ### \_response? [Section titled “\_response?”](#_response) ```ts optional _response?: Record; ``` ### response\_id? [Section titled “response\_id?”](#response_id) ```ts optional response_id?: string; ``` ### type [Section titled “type”](#type) ```ts type: "response"; ``` # ResponseStreamEvent ```ts type ResponseStreamEvent = StreamEvent; ``` Event emitted when streaming model responses. # RetryDecision ```ts type RetryDecision = | boolean | { delayMs?: number; reason?: string; retry: boolean; }; ``` ## Union Members [Section titled “Union Members”](#union-members) `boolean` *** ### Type Literal [Section titled “Type Literal”](#type-literal) ```ts { delayMs?: number; reason?: string; retry: boolean; } ``` #### delayMs? [Section titled “delayMs?”](#delayms) ```ts optional delayMs?: number; ``` Optional delay override in milliseconds before the next retry attempt. #### reason? [Section titled “reason?”](#reason) ```ts optional reason?: string; ``` Optional explanation for logging or debugging. #### retry [Section titled “retry”](#retry) ```ts retry: boolean; ``` Whether the failed request should be retried. # RetryPolicy ```ts type RetryPolicy = (context) => | RetryDecision | Promise; ``` ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | --------------------------------------------------------------------------------------------- | | `context` | [`RetryPolicyContext`](/openai-agents-js/openai/agents-core/type-aliases/retrypolicycontext/) | ## Returns [Section titled “Returns”](#returns) \| [`RetryDecision`](/openai-agents-js/openai/agents-core/type-aliases/retrydecision/) | `Promise`<[`RetryDecision`](/openai-agents-js/openai/agents-core/type-aliases/retrydecision/)> # RetryPolicyContext ```ts type RetryPolicyContext = object; ``` ## Properties [Section titled “Properties”](#properties) ### attempt [Section titled “attempt”](#attempt) ```ts attempt: number; ``` The 1-based number of the failed attempt. *** ### error [Section titled “error”](#error) ```ts error: unknown; ``` The error thrown by the failed model attempt. *** ### maxRetries [Section titled “maxRetries”](#maxretries) ```ts maxRetries: number; ``` The configured number of retries allowed after the initial attempt. *** ### normalized [Section titled “normalized”](#normalized) ```ts normalized: ModelRetryNormalizedError; ``` Generic normalized facts extracted from the error and provider advice. *** ### providerAdvice? [Section titled “providerAdvice?”](#provideradvice) ```ts optional providerAdvice?: ModelRetryAdvice; ``` Optional provider guidance for the failure. *** ### stream [Section titled “stream”](#stream) ```ts stream: boolean; ``` Whether the failed request was streaming. # RunConfig ```ts type RunConfig = object; ``` Configures settings for the entire agent run. ## Properties [Section titled “Properties”](#properties) ### callModelInputFilter? [Section titled “callModelInputFilter?”](#callmodelinputfilter) ```ts optional callModelInputFilter?: CallModelInputFilter; ``` Invoked immediately before calling the model, allowing callers to edit the system instructions or input items that will be sent to the model. *** ### groupId? [Section titled “groupId?”](#groupid) ```ts optional groupId?: string; ``` A grouping identifier to use for tracing, to link multiple traces from the same conversation or process. For example, you might use a chat thread ID. *** ### handoffInputFilter? [Section titled “handoffInputFilter?”](#handoffinputfilter) ```ts optional handoffInputFilter?: HandoffInputFilter; ``` A global input filter to apply to all handoffs. If `Handoff.inputFilter` is set, then that will take precedence. The input filter allows you to edit the inputs that are sent to the new agent. See the documentation in `Handoff.inputFilter` for more details. *** ### inputGuardrails? [Section titled “inputGuardrails?”](#inputguardrails) ```ts optional inputGuardrails?: InputGuardrail[]; ``` A list of input guardrails to run on the initial run input. *** ### model? [Section titled “model?”](#model) ```ts optional model?: | string | Model; ``` The model to use for the entire agent run. If set, will override the model set on every agent. The modelProvider passed in below must be able to resolve this model name. *** ### modelProvider [Section titled “modelProvider”](#modelprovider) ```ts modelProvider: ModelProvider; ``` The model provider to use when looking up string model names. Defaults to OpenAI. *** ### modelSettings? [Section titled “modelSettings?”](#modelsettings) ```ts optional modelSettings?: ModelSettings; ``` Configure global model settings. Any non-null values will override the agent-specific model settings. *** ### outputGuardrails? [Section titled “outputGuardrails?”](#outputguardrails) ```ts optional outputGuardrails?: OutputGuardrail>[]; ``` A list of output guardrails to run on the final output of the run. *** ### reasoningItemIdPolicy? [Section titled “reasoningItemIdPolicy?”](#reasoningitemidpolicy) ```ts optional reasoningItemIdPolicy?: ReasoningItemIdPolicy; ``` Controls how run items are converted into model input for subsequent turns. *** ### sandbox? [Section titled “sandbox?”](#sandbox) ```ts optional sandbox?: SandboxRunConfig; ``` Sandbox runtime configuration used when execution reaches a sandbox agent. *** ### sessionInputCallback? [Section titled “sessionInputCallback?”](#sessioninputcallback) ```ts optional sessionInputCallback?: SessionInputCallback; ``` Customizes how session history is combined with the current turn’s input. When omitted, history items are appended before the new input. *** ### toolErrorFormatter? [Section titled “toolErrorFormatter?”](#toolerrorformatter) ```ts optional toolErrorFormatter?: ToolErrorFormatter; ``` Formats tool error messages that are returned to the model. Returning `undefined` falls back to the SDK default message. *** ### toolExecution? [Section titled “toolExecution?”](#toolexecution) ```ts optional toolExecution?: ToolExecutionConfig; ``` SDK-side execution settings for local tool calls. *** ### traceId? [Section titled “traceId?”](#traceid) ```ts optional traceId?: string; ``` A custom trace ID to use for tracing. If not provided, we will generate a new trace ID. *** ### traceIncludeSensitiveData [Section titled “traceIncludeSensitiveData”](#traceincludesensitivedata) ```ts traceIncludeSensitiveData: boolean; ``` Whether we include potentially sensitive data (for example: inputs/outputs of tool calls or LLM generations) in traces. If false, we’ll still create spans for these events, but the sensitive data will not be included. *** ### traceMetadata? [Section titled “traceMetadata?”](#tracemetadata) ```ts optional traceMetadata?: Record; ``` An optional dictionary of additional metadata to include with the trace. *** ### tracing? [Section titled “tracing?”](#tracing) ```ts optional tracing?: TracingConfig; ``` Tracing configuration for this run. Use this to override the API key used when exporting traces. *** ### tracingDisabled [Section titled “tracingDisabled”](#tracingdisabled) ```ts tracingDisabled: boolean; ``` Whether tracing is disabled for the agent run. If disabled, we will not trace the agent run. *** ### workflowName? [Section titled “workflowName?”](#workflowname) ```ts optional workflowName?: string; ``` The name of the run, used for tracing. Should be a logical name for the run, like “Code generation workflow” or “Customer support agent”. # RunErrorData ```ts type RunErrorData = object; ``` Snapshot of run data passed to error handlers. ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | ----------------------------------------------------------------------------------------------- | | `TContext` | | `TAgent` *extends* [`Agent`](/openai-agents-js/openai/agents-core/classes/agent/)<`any`, `any`> | ## Properties [Section titled “Properties”](#properties) ### history [Section titled “history”](#history) ```ts history: AgentInputItem[]; ``` *** ### input [Section titled “input”](#input) ```ts input: | string | AgentInputItem[]; ``` *** ### lastAgent? [Section titled “lastAgent?”](#lastagent) ```ts optional lastAgent?: TAgent; ``` *** ### newItems [Section titled “newItems”](#newitems) ```ts newItems: RunItem[]; ``` *** ### output [Section titled “output”](#output) ```ts output: AgentOutputItem[]; ``` *** ### rawResponses [Section titled “rawResponses”](#rawresponses) ```ts rawResponses: ModelResponse[]; ``` *** ### state? [Section titled “state?”](#state) ```ts optional state?: RunState; ``` # RunErrorHandler ```ts type RunErrorHandler = (input) => | RunErrorHandlerResult | void | Promise< | RunErrorHandlerResult | void>; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | ----------------------------------------------------------------------------------------------- | | `TContext` | | `TAgent` *extends* [`Agent`](/openai-agents-js/openai/agents-core/classes/agent/)<`any`, `any`> | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ----------------------------------------------------------------------------------------------------------------------- | | `input` | [`RunErrorHandlerInput`](/openai-agents-js/openai/agents-core/type-aliases/runerrorhandlerinput/)<`TContext`, `TAgent`> | ## Returns [Section titled “Returns”](#returns) \| [`RunErrorHandlerResult`](/openai-agents-js/openai/agents-core/type-aliases/runerrorhandlerresult/)<`TAgent`> | `void` | `Promise`< | [`RunErrorHandlerResult`](/openai-agents-js/openai/agents-core/type-aliases/runerrorhandlerresult/)<`TAgent`> | `void`> # RunErrorHandlerInput ```ts type RunErrorHandlerInput = object; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | ----------------------------------------------------------------------------------------------- | | `TContext` | | `TAgent` *extends* [`Agent`](/openai-agents-js/openai/agents-core/classes/agent/)<`any`, `any`> | ## Properties [Section titled “Properties”](#properties) ### context [Section titled “context”](#context) ```ts context: RunContext; ``` *** ### error [Section titled “error”](#error) ```ts error: | MaxTurnsExceededError | ModelRefusalError; ``` *** ### runData [Section titled “runData”](#rundata) ```ts runData: RunErrorData; ``` # RunErrorHandlerResult ```ts type RunErrorHandlerResult = object; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | ----------------------------------------------------------------------------------------------- | | `TAgent` *extends* [`Agent`](/openai-agents-js/openai/agents-core/classes/agent/)<`any`, `any`> | ## Properties [Section titled “Properties”](#properties) ### finalOutput [Section titled “finalOutput”](#finaloutput) ```ts finalOutput: ResolvedAgentOutput; ``` The final output to return for the run. *** ### includeInHistory? [Section titled “includeInHistory?”](#includeinhistory) ```ts optional includeInHistory?: boolean; ``` Whether to append the synthesized output to history for subsequent runs. # RunErrorHandlers ```ts type RunErrorHandlers = Partial>> & object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### default? [Section titled “default?”](#default) ```ts optional default?: RunErrorHandler; ``` Fallback handler for supported error kinds. ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | ----------------------------------------------------------------------------------------------- | | `TContext` | | `TAgent` *extends* [`Agent`](/openai-agents-js/openai/agents-core/classes/agent/)<`any`, `any`> | # RunErrorKind ```ts type RunErrorKind = "maxTurns" | "modelRefusal"; ``` Error kinds supported by run error handlers. # RunItem ```ts type RunItem = | RunMessageOutputItem | RunToolCallItem | RunToolSearchCallItem | RunToolSearchOutputItem | RunReasoningItem | RunHandoffCallItem | RunToolCallOutputItem | RunHandoffOutputItem | RunToolApprovalItem; ``` # RunStreamEvent ```ts type RunStreamEvent = | RunRawModelStreamEvent | RunItemStreamEvent | RunAgentUpdatedStreamEvent; ``` A streaming event from an agent run. # SerializedHandoff ```ts type SerializedHandoff = object; ``` ## Properties [Section titled “Properties”](#properties) ### inputJsonSchema [Section titled “inputJsonSchema”](#inputjsonschema) ```ts inputJsonSchema: Handoff["inputJsonSchema"]; ``` The JSON schema for the handoff input. Can be empty if the handoff does not take an input *** ### strictJsonSchema [Section titled “strictJsonSchema”](#strictjsonschema) ```ts strictJsonSchema: Handoff["strictJsonSchema"]; ``` Whether the input JSON schema is in strict mode. We strongly recommend setting this to true, as it increases the likelihood of correct JSON input. *** ### toolDescription [Section titled “toolDescription”](#tooldescription) ```ts toolDescription: Handoff["toolDescription"]; ``` The tool description for the handoff *** ### toolName [Section titled “toolName”](#toolname) ```ts toolName: Handoff["toolName"]; ``` The name of the tool that represents the handoff. # SerializedOutputType ```ts type SerializedOutputType = | JsonSchemaDefinition | TextOutput; ``` The output type passed to the model. Has any Zod types serialized to JSON Schema # SerializedTool ```ts type SerializedTool = | SerializedFunctionTool | SerializedComputerTool | SerializedShellTool | SerializedApplyPatchTool | SerializedHostedTool; ``` # SessionHistoryMutation ```ts type SessionHistoryMutation = SessionHistoryReplaceFunctionCallMutation; ``` # SessionHistoryRewriteArgs ```ts type SessionHistoryRewriteArgs = object; ``` ## Properties [Section titled “Properties”](#properties) ### mutations [Section titled “mutations”](#mutations) ```ts mutations: SessionHistoryMutation[]; ``` # SessionInputCallback ```ts type SessionInputCallback = (historyItems, newItems) => | AgentInputItem[] | Promise; ``` A function that combines session history with new input items before the model call. ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | -------------- | ---------------------------------------------------------------------------------------- | | `historyItems` | [`AgentInputItem`](/openai-agents-js/openai/agents-core/type-aliases/agentinputitem/)\[] | | `newItems` | [`AgentInputItem`](/openai-agents-js/openai/agents-core/type-aliases/agentinputitem/)\[] | ## Returns [Section titled “Returns”](#returns) \| [`AgentInputItem`](/openai-agents-js/openai/agents-core/type-aliases/agentinputitem/)\[] | `Promise`<[`AgentInputItem`](/openai-agents-js/openai/agents-core/type-aliases/agentinputitem/)\[]> # ShellAction ```ts type ShellAction = ShellAction; ``` Describes the work to perform when executing a shell tool call. Re-export protocol type to keep a single source of truth. # ShellCallItem ```ts type ShellCallItem = ZodObject; ``` # ShellCallItem ```ts type ShellCallItem = object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### action [Section titled “action”](#action) ```ts action: object = ShellAction; ``` #### action.commands [Section titled “action.commands”](#actioncommands) ```ts commands: string[]; ``` #### action.maxOutputLength? [Section titled “action.maxOutputLength?”](#actionmaxoutputlength) ```ts optional maxOutputLength?: number; ``` #### action.timeoutMs? [Section titled “action.timeoutMs?”](#actiontimeoutms) ```ts optional timeoutMs?: number; ``` ### callId [Section titled “callId”](#callid) ```ts callId: string; ``` ### id? [Section titled “id?”](#id) ```ts optional id?: string; ``` An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. ### status? [Section titled “status?”](#status) ```ts optional status?: "in_progress" | "completed" | "incomplete"; ``` ### type [Section titled “type”](#type) ```ts type: "shell_call"; ``` # ShellCallResultItem ```ts type ShellCallResultItem = ZodObject; ``` # ShellCallResultItem ```ts type ShellCallResultItem = object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### callId [Section titled “callId”](#callid) ```ts callId: string; ``` ### id? [Section titled “id?”](#id) ```ts optional id?: string; ``` An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. ### maxOutputLength? [Section titled “maxOutputLength?”](#maxoutputlength) ```ts optional maxOutputLength?: number; ``` ### output [Section titled “output”](#output) ```ts output: object[]; ``` #### Index Signature [Section titled “Index Signature”](#index-signature) ```ts [key: string]: unknown ``` ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. ### type [Section titled “type”](#type) ```ts type: "shell_call_output"; ``` # ShellOutputResult ```ts type ShellOutputResult = ShellCallOutputContent; ``` Output for a single executed command. # ShellResult ```ts type ShellResult = object; ``` ## Properties [Section titled “Properties”](#properties) ### maxOutputLength? [Section titled “maxOutputLength?”](#maxoutputlength) ```ts optional maxOutputLength?: number; ``` If you applied truncation yourself, set the limit you enforced for telemetry. *** ### output [Section titled “output”](#output) ```ts output: ShellOutputResult[]; ``` One entry per executed command (or logical chunk) in order. *** ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` Optional provider-specific metadata merged into the tool call output. # ShellTool ```ts type ShellTool = LocalShellTool | HostedShellTool; ``` # ShellToolContainerAutoEnvironment ```ts type ShellToolContainerAutoEnvironment = object; ``` ## Properties [Section titled “Properties”](#properties) ### fileIds? [Section titled “fileIds?”](#fileids) ```ts optional fileIds?: string[]; ``` *** ### memoryLimit? [Section titled “memoryLimit?”](#memorylimit) ```ts optional memoryLimit?: "1g" | "4g" | "16g" | "64g" | null; ``` *** ### networkPolicy? [Section titled “networkPolicy?”](#networkpolicy) ```ts optional networkPolicy?: ShellToolContainerNetworkPolicy; ``` *** ### skills? [Section titled “skills?”](#skills) ```ts optional skills?: ShellToolContainerSkill[]; ``` *** ### type [Section titled “type”](#type) ```ts type: "container_auto"; ``` # ShellToolContainerNetworkPolicy ```ts type ShellToolContainerNetworkPolicy = | ShellToolContainerNetworkPolicyAllowlist | ShellToolContainerNetworkPolicyDisabled; ``` # ShellToolContainerNetworkPolicyAllowlist ```ts type ShellToolContainerNetworkPolicyAllowlist = object; ``` ## Properties [Section titled “Properties”](#properties) ### allowedDomains [Section titled “allowedDomains”](#alloweddomains) ```ts allowedDomains: string[]; ``` *** ### domainSecrets? [Section titled “domainSecrets?”](#domainsecrets) ```ts optional domainSecrets?: ShellToolContainerNetworkPolicyDomainSecret[]; ``` *** ### type [Section titled “type”](#type) ```ts type: "allowlist"; ``` # ShellToolContainerNetworkPolicyDisabled ```ts type ShellToolContainerNetworkPolicyDisabled = object; ``` ## Properties [Section titled “Properties”](#properties) ### type [Section titled “type”](#type) ```ts type: "disabled"; ``` # ShellToolContainerNetworkPolicyDomainSecret ```ts type ShellToolContainerNetworkPolicyDomainSecret = object; ``` ## Properties [Section titled “Properties”](#properties) ### domain [Section titled “domain”](#domain) ```ts domain: string; ``` *** ### name [Section titled “name”](#name) ```ts name: string; ``` *** ### value [Section titled “value”](#value) ```ts value: string; ``` # ShellToolContainerReferenceEnvironment ```ts type ShellToolContainerReferenceEnvironment = object; ``` ## Properties [Section titled “Properties”](#properties) ### containerId [Section titled “containerId”](#containerid) ```ts containerId: string; ``` *** ### type [Section titled “type”](#type) ```ts type: "container_reference"; ``` # ShellToolContainerSkill ```ts type ShellToolContainerSkill = | ShellToolSkillReference | ShellToolInlineSkill; ``` # ShellToolEnvironment ```ts type ShellToolEnvironment = | ShellToolLocalEnvironment | ShellToolHostedEnvironment; ``` # ShellToolHostedEnvironment ```ts type ShellToolHostedEnvironment = | ShellToolContainerAutoEnvironment | ShellToolContainerReferenceEnvironment; ``` # ShellToolInlineSkill ```ts type ShellToolInlineSkill = object; ``` ## Properties [Section titled “Properties”](#properties) ### description [Section titled “description”](#description) ```ts description: string; ``` *** ### name [Section titled “name”](#name) ```ts name: string; ``` *** ### source [Section titled “source”](#source) ```ts source: ShellToolInlineSkillSource; ``` *** ### type [Section titled “type”](#type) ```ts type: "inline"; ``` # ShellToolInlineSkillSource ```ts type ShellToolInlineSkillSource = object; ``` ## Properties [Section titled “Properties”](#properties) ### data [Section titled “data”](#data) ```ts data: string; ``` *** ### mediaType [Section titled “mediaType”](#mediatype) ```ts mediaType: "application/zip"; ``` *** ### type [Section titled “type”](#type) ```ts type: "base64"; ``` # ShellToolLocalEnvironment ```ts type ShellToolLocalEnvironment = object; ``` ## Properties [Section titled “Properties”](#properties) ### skills? [Section titled “skills?”](#skills) ```ts optional skills?: ShellToolLocalSkill[]; ``` *** ### type [Section titled “type”](#type) ```ts type: "local"; ``` # ShellToolLocalSkill ```ts type ShellToolLocalSkill = object; ``` ## Properties [Section titled “Properties”](#properties) ### description [Section titled “description”](#description) ```ts description: string; ``` *** ### name [Section titled “name”](#name) ```ts name: string; ``` *** ### path [Section titled “path”](#path) ```ts path: string; ``` # ShellToolSkillReference ```ts type ShellToolSkillReference = object; ``` ## Properties [Section titled “Properties”](#properties) ### skillId [Section titled “skillId”](#skillid) ```ts skillId: string; ``` *** ### type [Section titled “type”](#type) ```ts type: "skill_reference"; ``` *** ### version? [Section titled “version?”](#version) ```ts optional version?: string; ``` # SpanData ```ts type SpanData = | AgentSpanData | FunctionSpanData | GenerationSpanData | ResponseSpanData | HandoffSpanData | CustomSpanData | GuardrailSpanData | TranscriptionSpanData | SpeechSpanData | SpeechGroupSpanData | MCPListToolsSpanData; ``` # SpanError ```ts type SpanError = object; ``` ## Properties [Section titled “Properties”](#properties) ### data? [Section titled “data?”](#data) ```ts optional data?: Record; ``` *** ### message [Section titled “message”](#message) ```ts message: string; ``` # SpanOptions ```ts type SpanOptions = object; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | ------------------------------------------------------------------------------------------- | | `TData` *extends* [`SpanData`](/openai-agents-js/openai/agents-core/type-aliases/spandata/) | ## Properties [Section titled “Properties”](#properties) ### data [Section titled “data”](#data) ```ts data: TData; ``` *** ### endedAt? [Section titled “endedAt?”](#endedat) ```ts optional endedAt?: string; ``` *** ### error? [Section titled “error?”](#error) ```ts optional error?: SpanError; ``` *** ### parentId? [Section titled “parentId?”](#parentid) ```ts optional parentId?: string; ``` *** ### spanId? [Section titled “spanId?”](#spanid) ```ts optional spanId?: string; ``` *** ### startedAt? [Section titled “startedAt?”](#startedat) ```ts optional startedAt?: string; ``` *** ### traceId [Section titled “traceId”](#traceid) ```ts traceId: string; ``` *** ### traceMetadata? [Section titled “traceMetadata?”](#tracemetadata) ```ts optional traceMetadata?: Record; ``` *** ### tracingApiKey? [Section titled “tracingApiKey?”](#tracingapikey) ```ts optional tracingApiKey?: string; ``` # SpeechGroupSpanData ```ts type SpeechGroupSpanData = SpanDataBase & object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### input? [Section titled “input?”](#input) ```ts optional input?: string; ``` ### type [Section titled “type”](#type) ```ts type: "speech_group"; ``` # SpeechSpanData ```ts type SpeechSpanData = SpanDataBase & object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### input? [Section titled “input?”](#input) ```ts optional input?: string; ``` ### model? [Section titled “model?”](#model) ```ts optional model?: string; ``` ### model\_config? [Section titled “model\_config?”](#model_config) ```ts optional model_config?: Record; ``` ### output [Section titled “output”](#output) ```ts output: object; ``` #### output.data [Section titled “output.data”](#outputdata) ```ts data: string; ``` #### output.format [Section titled “output.format”](#outputformat) ```ts format: "pcm" | string & object; ``` ### type [Section titled “type”](#type) ```ts type: "speech"; ``` # StreamEvent ```ts type StreamEvent = ZodDiscriminatedUnion<[ZodObject<{ delta: ZodString; providerData: ZodOptional>; type: ZodLiteral<"output_text_delta">; }, $strip>, ZodObject<{ providerData: ZodOptional>; response: ZodObject<{ id: ZodString; output: ZodArray, ZodObject<{ arguments: ...; call_id: ...; callId: ...; execution: ...; id: ...; providerData: ...; status: ...; type: ...; }, $strip>, ZodObject<{ call_id: ...; callId: ...; execution: ...; id: ...; providerData: ...; status: ...; tools: ...; type: ...; }, $strip>], "type">>; providerData: ZodOptional>; requestId: ZodOptional; usage: ZodObject<{ inputTokens: ZodNumber; inputTokensDetails: ZodOptional>; outputTokens: ZodNumber; outputTokensDetails: ZodOptional>; requests: ZodOptional; requestUsageEntries: ZodOptional>>; totalTokens: ZodNumber; }, $strip>; }, $strip>; type: ZodLiteral<"response_done">; }, $strip>, ZodObject<{ providerData: ZodOptional>; type: ZodLiteral<"response_started">; }, $strip>, ZodObject<{ event: ZodAny; providerData: ZodOptional>; type: ZodLiteral<"model">; }, $strip>], "type">; ``` # StreamEvent ```ts type StreamEvent = | StreamEventTextStream | StreamEventResponseCompleted | StreamEventResponseStarted | StreamEventGenericItem; ``` # StreamEventGenericItem ```ts type StreamEventGenericItem = ZodObject; ``` Event returned for every item that gets streamed to the model. Used to expose the raw events from the model. # StreamEventGenericItem ```ts type StreamEventGenericItem = object; ``` Event returned for every item that gets streamed to the model. Used to expose the raw events from the model. ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### event [Section titled “event”](#event) ```ts event: any; ``` ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. ### type [Section titled “type”](#type) ```ts type: "model"; ``` # StreamEventResponseCompleted ```ts type StreamEventResponseCompleted = ZodObject; ``` Event returned by the model when a response is completed. # StreamEventResponseCompleted ```ts type StreamEventResponseCompleted = object; ``` Event returned by the model when a response is completed. ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. ### response [Section titled “response”](#response) ```ts response: object; ``` The response from the model. #### response.id [Section titled “response.id”](#responseid) ```ts id: string; ``` The ID of the response. #### response.output [Section titled “response.output”](#responseoutput) ```ts output: ( | { content: ( | { providerData?: Record; refusal: string; type: "refusal"; } | { providerData?: Record; text: string; type: "output_text"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; } | { image: string; providerData?: Record; type: "image"; })[]; id?: string; providerData?: Record; role: "assistant"; status: "in_progress" | "completed" | "incomplete"; type?: "message"; } | { arguments?: string; id?: string; name: string; output?: string; providerData?: Record; status?: string; type: "hosted_tool_call"; } | { arguments: string; callId: string; id?: string; name: string; namespace?: string; providerData?: Record; status?: "in_progress" | "completed" | "incomplete"; type: "function_call"; } | { arguments: unknown; call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; type: "tool_search_call"; } | { call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; tools: Record[]; type: "tool_search_output"; } | { callId: string; id?: string; name: string; namespace?: string; output: | string | { providerData?: Record; text: string; type: "text"; } | { detail?: "low" | "high" | "auto" | string & object; image?: | string | { data: string | Uint8Array<...>; mediaType?: string; } | { url: string; } | { fileId: string; }; providerData?: Record; type: "image"; } | { file: | string | { data: string | Uint8Array<...>; filename: string; mediaType: string; } | { filename?: string; url: string; } | { filename?: string; id: string; }; providerData?: Record; type: "file"; } | ( | { providerData?: Record<..., ...>; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: ...; }; providerData?: Record<..., ...>; type: "input_image"; } | { file?: | string | { id: ...; } | { url: ...; }; filename?: string; providerData?: Record<..., ...>; type: "input_file"; })[]; providerData?: Record; status: "in_progress" | "completed" | "incomplete"; type: "function_call_result"; } | { action?: | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; }; actions?: ( | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; })[]; callId: string; id?: string; providerData?: Record; status: "in_progress" | "completed" | "incomplete"; type: "computer_call"; } | { action: { commands: string[]; maxOutputLength?: number; timeoutMs?: number; }; callId: string; id?: string; providerData?: Record; status?: "in_progress" | "completed" | "incomplete"; type: "shell_call"; } | { callId: string; id?: string; maxOutputLength?: number; output: object[]; providerData?: Record; type: "shell_call_output"; } | { callId: string; id?: string; operation: | { diff: string; path: string; type: "create_file"; } | { diff: string; moveTo?: string; path: string; type: "update_file"; } | { path: string; type: "delete_file"; }; providerData?: Record; status: "in_progress" | "completed"; type: "apply_patch_call"; } | { callId: string; id?: string; output?: string; providerData?: Record; status: "completed" | "failed"; type: "apply_patch_call_output"; } | { content: object[]; id?: string; providerData?: Record; rawContent?: object[]; type: "reasoning"; } | { created_by?: string; encrypted_content: string; id?: string; providerData?: Record; type: "compaction"; } | { id?: string; providerData?: Record; type: "unknown"; })[]; ``` The output from the model. #### response.providerData? [Section titled “response.providerData?”](#responseproviderdata) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. #### response.requestId? [Section titled “response.requestId?”](#responserequestid) ```ts optional requestId?: string; ``` The transport request ID for this model call, if provided by the model SDK or transport. #### response.usage [Section titled “response.usage”](#responseusage) ```ts usage: object = UsageData; ``` The usage data for the response. #### response.usage.inputTokens [Section titled “response.usage.inputTokens”](#responseusageinputtokens) ```ts inputTokens: number; ``` #### response.usage.inputTokensDetails? [Section titled “response.usage.inputTokensDetails?”](#responseusageinputtokensdetails) ```ts optional inputTokensDetails?: Record | Record[]; ``` #### response.usage.outputTokens [Section titled “response.usage.outputTokens”](#responseusageoutputtokens) ```ts outputTokens: number; ``` #### response.usage.outputTokensDetails? [Section titled “response.usage.outputTokensDetails?”](#responseusageoutputtokensdetails) ```ts optional outputTokensDetails?: Record | Record[]; ``` #### response.usage.requests? [Section titled “response.usage.requests?”](#responseusagerequests) ```ts optional requests?: number; ``` #### response.usage.requestUsageEntries? [Section titled “response.usage.requestUsageEntries?”](#responseusagerequestusageentries) ```ts optional requestUsageEntries?: object[]; ``` #### response.usage.totalTokens [Section titled “response.usage.totalTokens”](#responseusagetotaltokens) ```ts totalTokens: number; ``` ### type [Section titled “type”](#type) ```ts type: "response_done"; ``` # StreamEventResponseStarted ```ts type StreamEventResponseStarted = ZodObject; ``` Event returned by the model when a new response is started. # StreamEventResponseStarted ```ts type StreamEventResponseStarted = object; ``` Event returned by the model when a new response is started. ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. ### type [Section titled “type”](#type) ```ts type: "response_started"; ``` # StreamEventTextStream ```ts type StreamEventTextStream = ZodObject; ``` Event returned by the model when new output text is available to stream to the user. # StreamEventTextStream ```ts type StreamEventTextStream = object; ``` Event returned by the model when new output text is available to stream to the user. ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### delta [Section titled “delta”](#delta) ```ts delta: string; ``` The delta text that was streamed by the modelto the user. ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. ### type [Section titled “type”](#type) ```ts type: "output_text_delta"; ``` # StreamRunOptions ```ts type StreamRunOptions = SharedRunOptions & object; ``` Options for runs that stream incremental events as the model responds. ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### stream [Section titled “stream”](#stream) ```ts stream: true; ``` Whether to stream the run. If true, the run will emit events as the model responds. ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | ----------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------- | | `TContext` | `undefined` | | `TAgent` *extends* [`Agent`](/openai-agents-js/openai/agents-core/classes/agent/)<`any`, `any`> | [`Agent`](/openai-agents-js/openai/agents-core/classes/agent/)<`any`, `any`> | # SystemMessageItem ```ts type SystemMessageItem = object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### content [Section titled “content”](#content) ```ts content: string; ``` The content of the message. ### id? [Section titled “id?”](#id) ```ts optional id?: string; ``` An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. ### role [Section titled “role”](#role) ```ts role: "system"; ``` Representing a system message to the user ### type? [Section titled “type?”](#type) ```ts optional type?: "message"; ``` Any item without a type is treated as a message # TextOutput ```ts type TextOutput = "text"; ``` Agent is expected to output text # Tool ```ts type Tool = | FunctionTool | ComputerTool | ShellTool | ApplyPatchTool | HostedTool; ``` A tool that can be called by the model. ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | Description | | -------------- | ------------ | ------------------------------ | | `Context` | `unknown` | The context passed to the tool | # ToolCallOutputContent ```ts type ToolCallOutputContent = ZodDiscriminatedUnion; ``` # ToolCallOutputContent ```ts type ToolCallOutputContent = | { providerData?: Record; text: string; type: "text"; } | { detail?: "low" | "high" | "auto" | string & object; image?: | string | { data: string | Uint8Array; mediaType?: string; } | { url: string; } | { fileId: string; }; providerData?: Record; type: "image"; } | { file: | string | { data: string | Uint8Array; filename: string; mediaType: string; } | { filename?: string; url: string; } | { filename?: string; id: string; }; providerData?: Record; type: "file"; }; ``` ## Union Members [Section titled “Union Members”](#union-members) ### Type Literal [Section titled “Type Literal”](#type-literal) ```ts { providerData?: Record; text: string; type: "text"; } ``` #### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. #### text [Section titled “text”](#text) ```ts text: string; ``` The text output from the model. #### type [Section titled “type”](#type) ```ts type: "text"; ``` *** ### Type Literal [Section titled “Type Literal”](#type-literal-1) ```ts { detail?: "low" | "high" | "auto" | string & object; image?: | string | { data: string | Uint8Array; mediaType?: string; } | { url: string; } | { fileId: string; }; providerData?: Record; type: "image"; } ``` #### detail? [Section titled “detail?”](#detail) ```ts optional detail?: "low" | "high" | "auto" | string & object; ``` Controls the requested level of detail for vision models. Use a string to avoid constraining future model capabilities. #### image? [Section titled “image?”](#image) ```ts optional image?: | string | { data: string | Uint8Array; mediaType?: string; } | { url: string; } | { fileId: string; }; ``` Inline image content or a reference to an uploaded file. Accepts a URL/data URL string or an object describing the data/url/fileId source. #### providerData? [Section titled “providerData?”](#providerdata-1) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. #### type [Section titled “type”](#type-1) ```ts type: "image"; ``` *** ### Type Literal [Section titled “Type Literal”](#type-literal-2) ```ts { file: | string | { data: string | Uint8Array; filename: string; mediaType: string; } | { filename?: string; url: string; } | { filename?: string; id: string; }; providerData?: Record; type: "file"; } ``` #### file [Section titled “file”](#file) ```ts file: | string | { data: string | Uint8Array; filename: string; mediaType: string; } | { filename?: string; url: string; } | { filename?: string; id: string; } = FileReferenceSchema; ``` File output reference. Provide either a string (data URL / base64), a data object (requires mediaType + filename), or an object pointing to an uploaded file/URL. #### providerData? [Section titled “providerData?”](#providerdata-2) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. #### type [Section titled “type”](#type-2) ```ts type: "file"; ``` # ToolCallStructuredOutput ```ts type ToolCallStructuredOutput = ZodDiscriminatedUnion; ``` # ToolCallStructuredOutput ```ts type ToolCallStructuredOutput = | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; }; ``` ## Union Members [Section titled “Union Members”](#union-members) ### Type Literal [Section titled “Type Literal”](#type-literal) ```ts { providerData?: Record; text: string; type: "input_text"; } ``` #### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. #### text [Section titled “text”](#text) ```ts text: string; ``` A text input for example a message from a user #### type [Section titled “type”](#type) ```ts type: "input_text"; ``` *** ### Type Literal [Section titled “Type Literal”](#type-literal-1) ```ts { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } ``` #### detail? [Section titled “detail?”](#detail) ```ts optional detail?: string; ``` Controls the level of detail requested for image understanding tasks. Future models may add new values, therefore this accepts any string. #### image? [Section titled “image?”](#image) ```ts optional image?: | string | { id: string; }; ``` The image input to the model. Could be provided inline (`image`), as a URL, or by reference to a previously uploaded OpenAI file. #### providerData? [Section titled “providerData?”](#providerdata-1) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. #### type [Section titled “type”](#type-1) ```ts type: "input_image"; ``` *** ### Type Literal [Section titled “Type Literal”](#type-literal-2) ```ts { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; } ``` #### file? [Section titled “file?”](#file) ```ts optional file?: | string | { id: string; } | { url: string; }; ``` The file input to the model. Could be raw data, a URL, or an OpenAI file ID. When passing a string, it is interpreted as inline data or a URL; use `{ id }` for file IDs. #### filename? [Section titled “filename?”](#filename) ```ts optional filename?: string; ``` Optional filename metadata when uploading file data inline. #### providerData? [Section titled “providerData?”](#providerdata-2) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. #### type [Section titled “type”](#type-2) ```ts type: "input_file"; ``` # ToolEnabledFunction ```ts type ToolEnabledFunction = (runContext, agent) => Promise; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | ------------------------------------------------------------------------------------- | | `Context` | [`UnknownContext`](/openai-agents-js/openai/agents-core/type-aliases/unknowncontext/) | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ------------ | ----------------------------------------------------------------------------------- | | `runContext` | [`RunContext`](/openai-agents-js/openai/agents-core/classes/runcontext/)<`Context`> | | `agent` | [`Agent`](/openai-agents-js/openai/agents-core/classes/agent/)<`any`, `any`> | ## Returns [Section titled “Returns”](#returns) `Promise`<`boolean`> # ToolErrorFormatter ```ts type ToolErrorFormatter = (args) => Promise | string | undefined; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | ------------ | | `TContext` | `unknown` | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ----------------------------------------------------------------------------------------------------------------- | | `args` | [`ToolErrorFormatterArgs`](/openai-agents-js/openai/agents-core/type-aliases/toolerrorformatterargs/)<`TContext`> | ## Returns [Section titled “Returns”](#returns) `Promise`<`string` | `undefined`> | `string` | `undefined` # ToolErrorFormatterArgs ```ts type ToolErrorFormatterArgs = object; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | --------------------------------------- | --------------------- | | `TContext` | `unknown` | | `TKind` *extends* `"approval_rejected"` | `"approval_rejected"` | ## Properties [Section titled “Properties”](#properties) ### callId [Section titled “callId”](#callid) ```ts callId: string; ``` The unique tool call identifier. *** ### defaultMessage [Section titled “defaultMessage”](#defaultmessage) ```ts defaultMessage: string; ``` The SDK’s default message for this error kind. *** ### kind [Section titled “kind”](#kind) ```ts kind: TKind; ``` The category of tool error being formatted. *** ### runContext [Section titled “runContext”](#runcontext) ```ts runContext: RunContext; ``` The active run context for the current execution. *** ### toolName [Section titled “toolName”](#toolname) ```ts toolName: string; ``` The name of the tool that produced the error. *** ### toolType [Section titled “toolType”](#tooltype) ```ts toolType: "function" | "computer" | "shell" | "apply_patch"; ``` The tool runtime that produced the error. # ToolExecuteArgument ```ts type ToolExecuteArgument = TParameters extends ZodObjectLike ? ZodInfer : TParameters extends JsonObjectSchema ? unknown : string; ``` The arguments to a tool. The type of the arguments are derived from the parameters passed to the tool definition. If the parameters are passed as a JSON schema the type is `unknown`. For Zod schemas it will match the inferred Zod type. Otherwise the type is `string` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | ----------------------------------------------------------------------------------------------------------------------- | | `TParameters` *extends* [`ToolInputParameters`](/openai-agents-js/openai/agents-core/type-aliases/toolinputparameters/) | # ToolExecutionConfig ```ts type ToolExecutionConfig = object; ``` SDK-side execution settings for local tool calls. ## Properties [Section titled “Properties”](#properties) ### maxFunctionToolConcurrency? [Section titled “maxFunctionToolConcurrency?”](#maxfunctiontoolconcurrency) ```ts optional maxFunctionToolConcurrency?: number | null; ``` Maximum number of local function tool calls to execute concurrently. Set to `null` or leave unset to start all function tool calls emitted in a turn. This does not change provider-side `parallelToolCalls` behavior. # ToolGuardrailBehavior ```ts type ToolGuardrailBehavior = | { type: "allow"; } | { message: string; type: "rejectContent"; } | { type: "throwException"; }; ``` The action a tool guardrail should take after evaluation. * `allow`: proceed to the next guardrail or tool execution/output handling. * `rejectContent`: treat the guardrail as rejecting the call/output and short‑circuit with a message. * `throwException`: escalate immediately as a tripwire to fail fast and surface diagnostics. # ToolInputGuardrailFunction ```ts type ToolInputGuardrailFunction = (data) => Promise; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | ------------------------------------------------------------------------------------- | | `TContext` | [`UnknownContext`](/openai-agents-js/openai/agents-core/type-aliases/unknowncontext/) | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | --------------------------------------------------------------------------------------------------------------- | | `data` | [`ToolInputGuardrailData`](/openai-agents-js/openai/agents-core/interfaces/toolinputguardraildata/)<`TContext`> | ## Returns [Section titled “Returns”](#returns) `Promise`<[`ToolGuardrailFunctionOutput`](/openai-agents-js/openai/agents-core/interfaces/toolguardrailfunctionoutput/)> # ToolInputParameters ```ts type ToolInputParameters = undefined | ZodObjectLike | JsonObjectSchema; ``` The parameters of a tool. This can be a Zod schema, a JSON schema or undefined. If a Zod schema is provided, the arguments to the tool will automatically be parsed and validated against the schema. If a JSON schema is provided, the arguments to the tool will be passed as is. If undefined is provided, the arguments to the tool will be passed as a string. # ToolNamespaceOptions ```ts type ToolNamespaceOptions = object; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | ------------------------------------------------ | ----------------------------- | | `TTools` *extends* readonly `AnyFunctionTool`\[] | readonly `AnyFunctionTool`\[] | ## Properties [Section titled “Properties”](#properties) ### description [Section titled “description”](#description) ```ts description: string; ``` Description shared by all tools in the namespace. *** ### name [Section titled “name”](#name) ```ts name: string; ``` The namespace name to expose to the model. *** ### tools [Section titled “tools”](#tools) ```ts tools: TTools; ``` Function tools to attach to the namespace. # ToolOptions ```ts type ToolOptions = | StrictToolOptions, Context> | NonStrictToolOptions, Context>; ``` The options for a tool. ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | Description | | ----------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------- | -------------------------- | | `TParameters` *extends* [`ToolInputParameters`](/openai-agents-js/openai/agents-core/type-aliases/toolinputparameters/) | ‐ | The parameters of the tool | | `Context` | [`UnknownContext`](/openai-agents-js/openai/agents-core/type-aliases/unknowncontext/) | The context of the tool | # ToolOptionsWithGuardrails ```ts type ToolOptionsWithGuardrails = ToolOptions; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | ----------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------- | | `TParameters` *extends* [`ToolInputParameters`](/openai-agents-js/openai/agents-core/type-aliases/toolinputparameters/) | ‐ | | `Context` | [`UnknownContext`](/openai-agents-js/openai/agents-core/type-aliases/unknowncontext/) | # ToolOutputFileContent ```ts type ToolOutputFileContent = ZodObject; ``` # ToolOutputFileContent ```ts type ToolOutputFileContent = object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### file [Section titled “file”](#file) ```ts file: | string | { data: string | Uint8Array; filename: string; mediaType: string; } | { filename?: string; url: string; } | { filename?: string; id: string; } = FileReferenceSchema; ``` File output reference. Provide either a string (data URL / base64), a data object (requires mediaType + filename), or an object pointing to an uploaded file/URL. ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. ### type [Section titled “type”](#type) ```ts type: "file"; ``` # ToolOutputGuardrailFunction ```ts type ToolOutputGuardrailFunction = (data) => Promise; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | ------------------------------------------------------------------------------------- | | `TContext` | [`UnknownContext`](/openai-agents-js/openai/agents-core/type-aliases/unknowncontext/) | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ----------------------------------------------------------------------------------------------------------------- | | `data` | [`ToolOutputGuardrailData`](/openai-agents-js/openai/agents-core/interfaces/tooloutputguardraildata/)<`TContext`> | ## Returns [Section titled “Returns”](#returns) `Promise`<[`ToolGuardrailFunctionOutput`](/openai-agents-js/openai/agents-core/interfaces/toolguardrailfunctionoutput/)> # ToolOutputImage ```ts type ToolOutputImage = ZodObject; ``` # ToolOutputImage ```ts type ToolOutputImage = object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### detail? [Section titled “detail?”](#detail) ```ts optional detail?: "low" | "high" | "auto" | string & object; ``` Controls the requested level of detail for vision models. Use a string to avoid constraining future model capabilities. ### image? [Section titled “image?”](#image) ```ts optional image?: | string | { data: string | Uint8Array; mediaType?: string; } | { url: string; } | { fileId: string; }; ``` Inline image content or a reference to an uploaded file. Accepts a URL/data URL string or an object describing the data/url/fileId source. ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. ### type [Section titled “type”](#type) ```ts type: "image"; ``` # ToolOutputText ```ts type ToolOutputText = ZodObject; ``` # ToolOutputText ```ts type ToolOutputText = object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. ### text [Section titled “text”](#text) ```ts text: string; ``` The text output from the model. ### type [Section titled “type”](#type) ```ts type: "text"; ``` # ToolReference ```ts type ToolReference = ZodObject; ``` # ToolReference ```ts type ToolReference = object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### functionName [Section titled “functionName”](#functionname) ```ts functionName: string; ``` ### namespace? [Section titled “namespace?”](#namespace) ```ts optional namespace?: string; ``` ### type [Section titled “type”](#type) ```ts type: "tool_reference"; ``` # ToolSearchCallArguments ```ts type ToolSearchCallArguments = ZodUnknown; ``` Tool search call arguments are provider-defined. Hosted tool search uses `{ paths, query }`, while client-executed tool search can use a custom schema. # ToolSearchCallArguments ```ts type ToolSearchCallArguments = unknown; ``` Tool search call arguments are provider-defined. Hosted tool search uses `{ paths, query }`, while client-executed tool search can use a custom schema. # ToolSearchCallItem ```ts type ToolSearchCallItem = ZodObject; ``` # ToolSearchCallItem ```ts type ToolSearchCallItem = object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### arguments [Section titled “arguments”](#arguments) ```ts arguments: unknown = ToolSearchCallArguments; ``` ### call\_id? [Section titled “call\_id?”](#call_id) ```ts optional call_id?: string | null; ``` ### callId? [Section titled “callId?”](#callid) ```ts optional callId?: string | null; ``` ### execution? [Section titled “execution?”](#execution) ```ts optional execution?: "client" | "server"; ``` ### id? [Section titled “id?”](#id) ```ts optional id?: string; ``` An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. ### status? [Section titled “status?”](#status) ```ts optional status?: string; ``` ### type [Section titled “type”](#type) ```ts type: "tool_search_call"; ``` # ToolSearchOutputItem ```ts type ToolSearchOutputItem = ZodObject; ``` # ToolSearchOutputItem ```ts type ToolSearchOutputItem = object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### call\_id? [Section titled “call\_id?”](#call_id) ```ts optional call_id?: string | null; ``` ### callId? [Section titled “callId?”](#callid) ```ts optional callId?: string | null; ``` ### execution? [Section titled “execution?”](#execution) ```ts optional execution?: "client" | "server"; ``` ### id? [Section titled “id?”](#id) ```ts optional id?: string; ``` An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. ### status? [Section titled “status?”](#status) ```ts optional status?: string; ``` ### tools [Section titled “tools”](#tools) ```ts tools: Record[]; ``` ### type [Section titled “type”](#type) ```ts type: "tool_search_output"; ``` # ToolSearchOutputTool ```ts type ToolSearchOutputTool = ZodRecord; ``` Tool search outputs may contain tool references or concrete tool definitions. Preserve the payload as returned so stateless continuation can replay it losslessly. # ToolSearchOutputTool ```ts type ToolSearchOutputTool = Record; ``` Tool search outputs may contain tool references or concrete tool definitions. Preserve the payload as returned so stateless continuation can replay it losslessly. # ToolsToFinalOutputResult ```ts type ToolsToFinalOutputResult = | { isFinalOutput: false; isInterrupted: undefined; } | { interruptions: RunToolApprovalItem[]; isFinalOutput: false; isInterrupted: true; } | { finalOutput: string; isFinalOutput: true; isInterrupted: undefined; }; ``` ## Union Members [Section titled “Union Members”](#union-members) ### Type Literal [Section titled “Type Literal”](#type-literal) ```ts { isFinalOutput: false; isInterrupted: undefined; } ``` #### isFinalOutput [Section titled “isFinalOutput”](#isfinaloutput) ```ts isFinalOutput: false; ``` Whether this is the final output. If `false`, the LLM will run again and receive the tool call output #### isInterrupted [Section titled “isInterrupted”](#isinterrupted) ```ts isInterrupted: undefined; ``` Whether the agent was interrupted by a tool approval. If `true`, the LLM will run again and receive the tool call output *** ### Type Literal [Section titled “Type Literal”](#type-literal-1) ```ts { interruptions: RunToolApprovalItem[]; isFinalOutput: false; isInterrupted: true; } ``` #### interruptions [Section titled “interruptions”](#interruptions) ```ts interruptions: RunToolApprovalItem[]; ``` #### isFinalOutput [Section titled “isFinalOutput”](#isfinaloutput-1) ```ts isFinalOutput: false; ``` #### isInterrupted [Section titled “isInterrupted”](#isinterrupted-1) ```ts isInterrupted: true; ``` Whether the agent was interrupted by a tool approval. If `true`, the LLM will run again and receive the tool call output *** ### Type Literal [Section titled “Type Literal”](#type-literal-2) ```ts { finalOutput: string; isFinalOutput: true; isInterrupted: undefined; } ``` #### finalOutput [Section titled “finalOutput”](#finaloutput) ```ts finalOutput: string; ``` The final output. Can be undefined if `isFinalOutput` is `false`, otherwise it must be a string that will be processed based on the `outputType` of the agent. #### isFinalOutput [Section titled “isFinalOutput”](#isfinaloutput-2) ```ts isFinalOutput: true; ``` Whether this is the final output. If `false`, the LLM will run again and receive the tool call output #### isInterrupted [Section titled “isInterrupted”](#isinterrupted-2) ```ts isInterrupted: undefined; ``` Whether the agent was interrupted by a tool approval. If `true`, the LLM will run again and receive the tool call output # ToolTimeoutErrorFunction ```ts type ToolTimeoutErrorFunction = (context, error) => Promise | string; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | ------------------------------------------------------------------------------------- | | `Context` | [`UnknownContext`](/openai-agents-js/openai/agents-core/type-aliases/unknowncontext/) | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ------------------------------------------------------------------------------------ | | `context` | [`RunContext`](/openai-agents-js/openai/agents-core/classes/runcontext/)<`Context`> | | `error` | [`ToolTimeoutError`](/openai-agents-js/openai/agents-core/classes/tooltimeouterror/) | ## Returns [Section titled “Returns”](#returns) `Promise`<`string`> | `string` # ToolToFinalOutputFunction ```ts type ToolToFinalOutputFunction = (context, toolResults) => | ToolsToFinalOutputResult | Promise; ``` A function that takes a run context and a list of tool results and returns a `ToolsToFinalOutputResult`. ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ------------- | ------------------------------------------------------------------------------------------------ | | `context` | [`RunContext`](/openai-agents-js/openai/agents-core/classes/runcontext/) | | `toolResults` | [`FunctionToolResult`](/openai-agents-js/openai/agents-core/type-aliases/functiontoolresult/)\[] | ## Returns [Section titled “Returns”](#returns) \| [`ToolsToFinalOutputResult`](/openai-agents-js/openai/agents-core/type-aliases/toolstofinaloutputresult/) | `Promise`<[`ToolsToFinalOutputResult`](/openai-agents-js/openai/agents-core/type-aliases/toolstofinaloutputresult/)> # ToolUseBehavior ```ts type ToolUseBehavior = | ToolUseBehaviorFlags | { stopAtToolNames: string[]; } | ToolToFinalOutputFunction; ``` The behavior of the agent when a tool is called. ## Union Members [Section titled “Union Members”](#union-members) [`ToolUseBehaviorFlags`](/openai-agents-js/openai/agents-core/type-aliases/toolusebehaviorflags/) *** ### Type Literal [Section titled “Type Literal”](#type-literal) ```ts { stopAtToolNames: string[]; } ``` #### stopAtToolNames [Section titled “stopAtToolNames”](#stopattoolnames) ```ts stopAtToolNames: string[]; ``` List of tool names that will stop the agent from running further. The final output will be the output of the first tool in the list that was called. *** [`ToolToFinalOutputFunction`](/openai-agents-js/openai/agents-core/type-aliases/tooltofinaloutputfunction/) # ToolUseBehaviorFlags ```ts type ToolUseBehaviorFlags = "run_llm_again" | "stop_on_first_tool"; ``` # TracingConfig ```ts type TracingConfig = object; ``` ## Properties [Section titled “Properties”](#properties) ### apiKey? [Section titled “apiKey?”](#apikey) ```ts optional apiKey?: string; ``` # TranscriptionSpanData ```ts type TranscriptionSpanData = SpanDataBase & object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### input [Section titled “input”](#input) ```ts input: object; ``` #### input.data [Section titled “input.data”](#inputdata) ```ts data: string; ``` #### input.format [Section titled “input.format”](#inputformat) ```ts format: "pcm" | string & object; ``` ### model? [Section titled “model?”](#model) ```ts optional model?: string; ``` ### model\_config? [Section titled “model\_config?”](#model_config) ```ts optional model_config?: Record; ``` ### output? [Section titled “output?”](#output) ```ts optional output?: string; ``` ### type [Section titled “type”](#type) ```ts type: "transcription"; ``` # UnknownContext ```ts type UnknownContext = unknown; ``` Context that is being passed around as part of the session is unknown # UnknownItem ```ts type UnknownItem = ZodObject; ``` This is a catch all for items that are not part of the protocol. For example, a model might return an item that is not part of the protocol using this type. In that case everything returned from the model should be passed in the `providerData` field. This enables new features to be added to be added by a model provider without breaking the protocol. # UnknownItem ```ts type UnknownItem = object; ``` This is a catch all for items that are not part of the protocol. For example, a model might return an item that is not part of the protocol using this type. In that case everything returned from the model should be passed in the `providerData` field. This enables new features to be added to be added by a model provider without breaking the protocol. ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### id? [Section titled “id?”](#id) ```ts optional id?: string; ``` An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. ### type [Section titled “type”](#type) ```ts type: "unknown"; ``` # UserMessageItem ```ts type UserMessageItem = ZodObject; ``` # UserMessageItem ```ts type UserMessageItem = object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### content [Section titled “content”](#content) ```ts content: | string | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; })[]; ``` The content of the message. ### id? [Section titled “id?”](#id) ```ts optional id?: string; ``` An ID to identify the item. This is optional by default. If a model provider absolutely requires this field, it will be validated on the model level. ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` Additional optional provider specific data. Used for custom functionality or model provider specific fields. ### role [Section titled “role”](#role) ```ts role: "user"; ``` Representing a message from the user ### type? [Section titled “type?”](#type) ```ts optional type?: "message"; ``` Any item without a type is treated as a message # ApplyPatchOperation ```ts const ApplyPatchOperation: ZodDiscriminatedUnion; ``` # OPENAI_DEFAULT_MODEL_ENV_VARIABLE_NAME ```ts const OPENAI_DEFAULT_MODEL_ENV_VARIABLE_NAME: "OPENAI_DEFAULT_MODEL" = 'OPENAI_DEFAULT_MODEL'; ``` # retryPolicies ```ts const retryPolicies: object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### all() [Section titled “all()”](#all) ```ts readonly all(...policies): RetryPolicy; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ----------- | ---------------------------------------------------------------------------------- | | …`policies` | [`RetryPolicy`](/openai-agents-js/openai/agents-core/type-aliases/retrypolicy/)\[] | #### Returns [Section titled “Returns”](#returns) [`RetryPolicy`](/openai-agents-js/openai/agents-core/type-aliases/retrypolicy/) ### any() [Section titled “any()”](#any) ```ts readonly any(...policies): RetryPolicy; ``` #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | ----------- | ---------------------------------------------------------------------------------- | | …`policies` | [`RetryPolicy`](/openai-agents-js/openai/agents-core/type-aliases/retrypolicy/)\[] | #### Returns [Section titled “Returns”](#returns-1) [`RetryPolicy`](/openai-agents-js/openai/agents-core/type-aliases/retrypolicy/) ### httpStatus() [Section titled “httpStatus()”](#httpstatus) ```ts readonly httpStatus(statuses): RetryPolicy; ``` #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | ---------- | ----------- | | `statuses` | `number`\[] | #### Returns [Section titled “Returns”](#returns-2) [`RetryPolicy`](/openai-agents-js/openai/agents-core/type-aliases/retrypolicy/) ### networkError() [Section titled “networkError()”](#networkerror) ```ts readonly networkError(): RetryPolicy; ``` #### Returns [Section titled “Returns”](#returns-3) [`RetryPolicy`](/openai-agents-js/openai/agents-core/type-aliases/retrypolicy/) ### never() [Section titled “never()”](#never) ```ts readonly never(): RetryPolicy; ``` #### Returns [Section titled “Returns”](#returns-4) [`RetryPolicy`](/openai-agents-js/openai/agents-core/type-aliases/retrypolicy/) ### providerSuggested() [Section titled “providerSuggested()”](#providersuggested) ```ts readonly providerSuggested(): RetryPolicy; ``` #### Returns [Section titled “Returns”](#returns-5) [`RetryPolicy`](/openai-agents-js/openai/agents-core/type-aliases/retrypolicy/) ### retryAfter() [Section titled “retryAfter()”](#retryafter) ```ts readonly retryAfter(): RetryPolicy; ``` #### Returns [Section titled “Returns”](#returns-6) [`RetryPolicy`](/openai-agents-js/openai/agents-core/type-aliases/retrypolicy/) # ToolGuardrailFunctionOutputFactory ```ts const ToolGuardrailFunctionOutputFactory: object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### allow() [Section titled “allow()”](#allow) ```ts allow(outputInfo?): ToolGuardrailFunctionOutput; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ------------- | ----- | | `outputInfo?` | `any` | #### Returns [Section titled “Returns”](#returns) [`ToolGuardrailFunctionOutput`](/openai-agents-js/openai/agents-core/interfaces/toolguardrailfunctionoutput/) ### rejectContent() [Section titled “rejectContent()”](#rejectcontent) ```ts rejectContent(message, outputInfo?): ToolGuardrailFunctionOutput; ``` #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | ------------- | -------- | | `message` | `string` | | `outputInfo?` | `any` | #### Returns [Section titled “Returns”](#returns-1) [`ToolGuardrailFunctionOutput`](/openai-agents-js/openai/agents-core/interfaces/toolguardrailfunctionoutput/) ### throwException() [Section titled “throwException()”](#throwexception) ```ts throwException(outputInfo?): ToolGuardrailFunctionOutput; ``` #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | ------------- | ----- | | `outputInfo?` | `any` | #### Returns [Section titled “Returns”](#returns-2) [`ToolGuardrailFunctionOutput`](/openai-agents-js/openai/agents-core/interfaces/toolguardrailfunctionoutput/) # withAgentSpan ```ts const withAgentSpan: (fn, ...args) => Promise; ``` Create a new agent span and automatically start and end it. ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | -------------- | | `TOutput` | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `fn` | (`span`) => `Promise`<`TOutput`> | | …`args` | \[`DeepPartial`<`CreateSpanOptions`<[`AgentSpanData`](/openai-agents-js/openai/agents-core/type-aliases/agentspandata/)>>, \| [`Span`](/openai-agents-js/openai/agents-core/classes/span/)<`any`> \| [`Trace`](/openai-agents-js/openai/agents-core/classes/trace/)] | ## Returns [Section titled “Returns”](#returns) `Promise`<`TOutput`> # withCustomSpan ```ts const withCustomSpan: (fn, ...args) => Promise; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | -------------- | | `TOutput` | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `fn` | (`span`) => `Promise`<`TOutput`> | | …`args` | \[`DeepPartial`<`CreateSpanOptions`<[`CustomSpanData`](/openai-agents-js/openai/agents-core/type-aliases/customspandata/)>> & `object`, \| [`Span`](/openai-agents-js/openai/agents-core/classes/span/)<`any`> \| [`Trace`](/openai-agents-js/openai/agents-core/classes/trace/)] | ## Returns [Section titled “Returns”](#returns) `Promise`<`TOutput`> # withFunctionSpan ```ts const withFunctionSpan: (fn, ...args) => Promise; ``` Create a new function span and automatically start and end it. ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | -------------- | | `TOutput` | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `fn` | (`span`) => `Promise`<`TOutput`> | | …`args` | \[`DeepPartial`<`CreateSpanOptions`<[`FunctionSpanData`](/openai-agents-js/openai/agents-core/type-aliases/functionspandata/)>> & `object`, \| [`Span`](/openai-agents-js/openai/agents-core/classes/span/)<`any`> \| [`Trace`](/openai-agents-js/openai/agents-core/classes/trace/)] | ## Returns [Section titled “Returns”](#returns) `Promise`<`TOutput`> # withGenerationSpan ```ts const withGenerationSpan: (fn, ...args) => Promise; ``` Automatically create a generation span, run fn and close the span ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | -------------- | | `TOutput` | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | `fn` | (`span`) => `Promise`<`TOutput`> | | …`args` | \[`DeepPartial`<`CreateSpanOptions`<[`GenerationSpanData`](/openai-agents-js/openai/agents-core/type-aliases/generationspandata/)>>, \| [`Span`](/openai-agents-js/openai/agents-core/classes/span/)<`any`> \| [`Trace`](/openai-agents-js/openai/agents-core/classes/trace/)] | ## Returns [Section titled “Returns”](#returns) `Promise`<`TOutput`> # withGuardrailSpan ```ts const withGuardrailSpan: (fn, ...args) => Promise; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | -------------- | | `TOutput` | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `fn` | (`span`) => `Promise`<`TOutput`> | | …`args` | \[`DeepPartial`<`CreateSpanOptions`<[`GuardrailSpanData`](/openai-agents-js/openai/agents-core/type-aliases/guardrailspandata/)>> & `object`, \| [`Span`](/openai-agents-js/openai/agents-core/classes/span/)<`any`> \| [`Trace`](/openai-agents-js/openai/agents-core/classes/trace/)] | ## Returns [Section titled “Returns”](#returns) `Promise`<`TOutput`> # withHandoffSpan ```ts const withHandoffSpan: (fn, ...args) => Promise; ``` Create a new handoff span and automatically start and end it. ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | -------------- | | `TOutput` | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | `fn` | (`span`) => `Promise`<`TOutput`> | | …`args` | \[`DeepPartial`<`CreateSpanOptions`<[`HandoffSpanData`](/openai-agents-js/openai/agents-core/type-aliases/handoffspandata/)>>, \| [`Span`](/openai-agents-js/openai/agents-core/classes/span/)<`any`> \| [`Trace`](/openai-agents-js/openai/agents-core/classes/trace/)] | ## Returns [Section titled “Returns”](#returns) `Promise`<`TOutput`> # withMCPListToolsSpan ```ts const withMCPListToolsSpan: (fn, ...args) => Promise; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | -------------- | | `TOutput` | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `fn` | (`span`) => `Promise`<`TOutput`> | | …`args` | \[`DeepPartial`<`CreateSpanOptions`<[`MCPListToolsSpanData`](/openai-agents-js/openai/agents-core/type-aliases/mcplisttoolsspandata/)>>, \| [`Span`](/openai-agents-js/openai/agents-core/classes/span/)<`any`> \| [`Trace`](/openai-agents-js/openai/agents-core/classes/trace/)] | ## Returns [Section titled “Returns”](#returns) `Promise`<`TOutput`> # withResponseSpan ```ts const withResponseSpan: (fn, ...args) => Promise; ``` Create a new response span and automatically start and end it. This span captures the details of a model response, primarily the response identifier. If you need to capture detailed generation information such as input/output messages, model configuration, or usage data, use `generationSpan()` instead. ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | -------------- | | `TOutput` | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `fn` | (`span`) => `Promise`<`TOutput`> | | …`args` | \[`DeepPartial`<`CreateSpanOptions`<[`ResponseSpanData`](/openai-agents-js/openai/agents-core/type-aliases/responsespandata/)>>, \| [`Span`](/openai-agents-js/openai/agents-core/classes/span/)<`any`> \| [`Trace`](/openai-agents-js/openai/agents-core/classes/trace/)] | ## Returns [Section titled “Returns”](#returns) `Promise`<`TOutput`> # withSpeechGroupSpan ```ts const withSpeechGroupSpan: (fn, ...args) => Promise; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | -------------- | | `TOutput` | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `fn` | (`span`) => `Promise`<`TOutput`> | | …`args` | \[`DeepPartial`<`CreateSpanOptions`<[`SpeechGroupSpanData`](/openai-agents-js/openai/agents-core/type-aliases/speechgroupspandata/)>>, \| [`Span`](/openai-agents-js/openai/agents-core/classes/span/)<`any`> \| [`Trace`](/openai-agents-js/openai/agents-core/classes/trace/)] | ## Returns [Section titled “Returns”](#returns) `Promise`<`TOutput`> # withSpeechSpan ```ts const withSpeechSpan: (fn, ...args) => Promise; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | -------------- | | `TOutput` | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `fn` | (`span`) => `Promise`<`TOutput`> | | …`args` | \[`DeepPartial`<`CreateSpanOptions`<[`SpeechSpanData`](/openai-agents-js/openai/agents-core/type-aliases/speechspandata/)>> & `object`, \| [`Span`](/openai-agents-js/openai/agents-core/classes/span/)<`any`> \| [`Trace`](/openai-agents-js/openai/agents-core/classes/trace/)] | ## Returns [Section titled “Returns”](#returns) `Promise`<`TOutput`> # withTranscriptionSpan ```ts const withTranscriptionSpan: (fn, ...args) => Promise; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | -------------- | | `TOutput` | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `fn` | (`span`) => `Promise`<`TOutput`> | | …`args` | \[`DeepPartial`<`CreateSpanOptions`<[`TranscriptionSpanData`](/openai-agents-js/openai/agents-core/type-aliases/transcriptionspandata/)>> & `object`, \| [`Span`](/openai-agents-js/openai/agents-core/classes/span/)<`any`> \| [`Trace`](/openai-agents-js/openai/agents-core/classes/trace/)] | ## Returns [Section titled “Returns”](#returns) `Promise`<`TOutput`> # CloudflareRealtimeTransportLayer An adapter transport for Cloudflare Workers (workerd) environments. Cloudflare Workers cannot open outbound client WebSockets using the global `WebSocket` constructor. Instead, a `fetch()` request with `Upgrade: websocket` must be performed and the returned `response.webSocket` must be `accept()`ed. This transport encapsulates that pattern and plugs into the Realtime SDK via the factory-based `createWebSocket` option. It behaves like `OpenAIRealtimeWebSocket`, but establishes the connection using `fetch()` and sets `skipOpenEventListeners: true` since workerd sockets do not emit a traditional `open` event after acceptance. Reference: Response API — `response.webSocket` (Cloudflare Workers). . ## Extends [Section titled “Extends”](#extends) * `OpenAIRealtimeWebSocket` ## Implements [Section titled “Implements”](#implements) * `RealtimeTransportLayer` ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new CloudflareRealtimeTransportLayer(options): CloudflareRealtimeTransportLayer; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | -------------------------------- | | `options` | `OpenAIRealtimeWebSocketOptions` | #### Returns [Section titled “Returns”](#returns) `CloudflareRealtimeTransportLayer` #### Overrides [Section titled “Overrides”](#overrides) ```ts OpenAIRealtimeWebSocket.constructor ``` ## Accessors [Section titled “Accessors”](#accessors) ### \_tracingConfig [Section titled “\_tracingConfig”](#_tracingconfig) #### Set Signature [Section titled “Set Signature”](#set-signature) ```ts set _tracingConfig(tracingConfig): void; ``` Sets the internal tracing config. This is used to track the tracing config that has been set during the session.create event. ##### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | --------------- | --------------------------------- | | `tracingConfig` | `RealtimeTracingConfig` \| `null` | ##### Returns [Section titled “Returns”](#returns-1) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from) ```ts OpenAIRealtimeWebSocket._tracingConfig ``` *** ### connectionState [Section titled “connectionState”](#connectionstate) #### Get Signature [Section titled “Get Signature”](#get-signature) ```ts get connectionState(): WebSocketState; ``` The current connection state of the WebSocket connection. ##### Returns [Section titled “Returns”](#returns-2) `WebSocketState` #### Inherited from [Section titled “Inherited from”](#inherited-from-1) ```ts OpenAIRealtimeWebSocket.connectionState ``` *** ### currentModel [Section titled “currentModel”](#currentmodel) #### Get Signature [Section titled “Get Signature”](#get-signature-1) ```ts get currentModel(): OpenAIRealtimeModels; ``` The current model that is being used by the transport layer. ##### Returns [Section titled “Returns”](#returns-3) `OpenAIRealtimeModels` #### Set Signature [Section titled “Set Signature”](#set-signature-1) ```ts set currentModel(model): void; ``` The current model that is being used by the transport layer. **Note**: The model cannot be changed mid conversation. ##### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | --------- | ---------------------- | | `model` | `OpenAIRealtimeModels` | ##### Returns [Section titled “Returns”](#returns-4) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-2) ```ts OpenAIRealtimeWebSocket.currentModel ``` *** ### muted [Section titled “muted”](#muted) #### Get Signature [Section titled “Get Signature”](#get-signature-2) ```ts get muted(): null; ``` Always returns `null` as the WebSocket transport layer does not handle muting. Instead, this should be handled by the client by not triggering the `sendAudio` method. ##### Returns [Section titled “Returns”](#returns-5) `null` #### Implementation of [Section titled “Implementation of”](#implementation-of) ```ts RealtimeTransportLayer.muted ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-3) ```ts OpenAIRealtimeWebSocket.muted ``` *** ### status [Section titled “status”](#status) #### Get Signature [Section titled “Get Signature”](#get-signature-3) ```ts get status(): "connected" | "disconnected" | "connecting"; ``` The current status of the WebSocket connection. ##### Returns [Section titled “Returns”](#returns-6) `"connected"` | `"disconnected"` | `"connecting"` #### Implementation of [Section titled “Implementation of”](#implementation-of-1) ```ts RealtimeTransportLayer.status ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-4) [`TwilioRealtimeTransportLayer`](/openai-agents-js/openai/agents-extensions/classes/twiliorealtimetransportlayer/).[`status`](/openai-agents-js/openai/agents-extensions/classes/twiliorealtimetransportlayer/#status) ## Methods [Section titled “Methods”](#methods) ### \_cancelResponse() [Section titled “\_cancelResponse()”](#_cancelresponse) ```ts _cancelResponse(): void; ``` Send a cancel response event to the Realtime API. This is used to cancel an ongoing response that the model is currently generating. #### Returns [Section titled “Returns”](#returns-7) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-5) ```ts OpenAIRealtimeWebSocket._cancelResponse ``` *** ### \_interrupt() [Section titled “\_interrupt()”](#_interrupt) ```ts _interrupt(elapsedTime, cancelOngoingResponse?): void; ``` Do NOT call this method directly. Call `interrupt()` instead for proper interruption handling. This method is used to send the right events to the API to inform the model that the user has interrupted the response. It might be overridden/extended by an extended transport layer. See the `TwilioRealtimeTransportLayer` for an example. #### Parameters [Section titled “Parameters”](#parameters-3) | Parameter | Type | Description | | ------------------------ | --------- | -------------------------------------------- | | `elapsedTime` | `number` | The elapsed time since the response started. | | `cancelOngoingResponse?` | `boolean` | ‐ | #### Returns [Section titled “Returns”](#returns-8) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-6) ```ts OpenAIRealtimeWebSocket._interrupt ``` *** ### addImage() [Section titled “addImage()”](#addimage) ```ts addImage(image, options?): void; ``` Sends an image to the model #### Parameters [Section titled “Parameters”](#parameters-4) | Parameter | Type | Description | | -------------------------- | ---------------------------------- | -------------------------------------------- | | `image` | `string` | The image to send | | `options?` | { `triggerResponse?`: `boolean`; } | Additional options | | `options.triggerResponse?` | `boolean` | Whether to trigger a response from the model | #### Returns [Section titled “Returns”](#returns-9) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-2) ```ts RealtimeTransportLayer.addImage ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-7) ```ts OpenAIRealtimeWebSocket.addImage ``` *** ### buildSessionPayload() [Section titled “buildSessionPayload()”](#buildsessionpayload) ```ts buildSessionPayload(config): RealtimeSessionPayload; ``` Build the payload object expected by the Realtime API when creating or updating a session. The helper centralises the conversion from camelCase runtime config to the snake\_case payload required by the Realtime API so transports that need a one-off payload (for example SIP call acceptance) can reuse the same logic without duplicating private state. #### Parameters [Section titled “Parameters”](#parameters-5) | Parameter | Type | Description | | --------- | ---------------------------------- | ------------------------------------------ | | `config` | `Partial`<`RealtimeSessionConfig`> | The session config to merge with defaults. | #### Returns [Section titled “Returns”](#returns-10) `RealtimeSessionPayload` #### Inherited from [Section titled “Inherited from”](#inherited-from-8) ```ts OpenAIRealtimeWebSocket.buildSessionPayload ``` *** ### close() [Section titled “close()”](#close) ```ts close(): void; ``` Close the WebSocket connection. This will also reset any internal connection tracking used for interruption handling. #### Returns [Section titled “Returns”](#returns-11) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-3) ```ts RealtimeTransportLayer.close ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-9) ```ts OpenAIRealtimeWebSocket.close ``` *** ### connect() [Section titled “connect()”](#connect) ```ts connect(options): Promise; ``` #### Parameters [Section titled “Parameters”](#parameters-6) | Parameter | Type | | --------- | -------------------------------------- | | `options` | `RealtimeTransportLayerConnectOptions` | #### Returns [Section titled “Returns”](#returns-12) `Promise`<`void`> #### Implementation of [Section titled “Implementation of”](#implementation-of-4) ```ts RealtimeTransportLayer.connect ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-10) ```ts OpenAIRealtimeWebSocket.connect ``` *** ### emit() [Section titled “emit()”](#emit) ```ts emit(type, ...args): boolean; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | ------------------------------------------------- | | `K` *extends* keyof `RealtimeTransportEventTypes` | #### Parameters [Section titled “Parameters”](#parameters-7) | Parameter | Type | | --------- | -------------------------------- | | `type` | `K` | | …`args` | `OpenAIRealtimeEventTypes`\[`K`] | #### Returns [Section titled “Returns”](#returns-13) `boolean` #### Implementation of [Section titled “Implementation of”](#implementation-of-5) ```ts RealtimeTransportLayer.emit ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-11) ```ts OpenAIRealtimeWebSocket.emit ``` *** ### interrupt() [Section titled “interrupt()”](#interrupt) ```ts interrupt(cancelOngoingResponse?): void; ``` Interrupt the ongoing response. This method is triggered automatically by the client when voice activity detection (VAD) is enabled (default) as well as when an output guardrail got triggered. You can also call this method directly if you want to interrupt the conversation for example based on an event in the client. #### Parameters [Section titled “Parameters”](#parameters-8) | Parameter | Type | | ------------------------ | --------- | | `cancelOngoingResponse?` | `boolean` | #### Returns [Section titled “Returns”](#returns-14) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-6) ```ts RealtimeTransportLayer.interrupt ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-12) ```ts OpenAIRealtimeWebSocket.interrupt ``` *** ### mute() [Section titled “mute()”](#mute) ```ts mute(_muted): never; ``` Will throw an error as the WebSocket transport layer does not support muting. #### Parameters [Section titled “Parameters”](#parameters-9) | Parameter | Type | | --------- | --------- | | `_muted` | `boolean` | #### Returns [Section titled “Returns”](#returns-15) `never` #### Implementation of [Section titled “Implementation of”](#implementation-of-7) ```ts RealtimeTransportLayer.mute ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-13) ```ts OpenAIRealtimeWebSocket.mute ``` *** ### off() [Section titled “off()”](#off) ```ts off(type, listener): EventEmitter; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-1) | Type Parameter | | ------------------------------------------------- | | `K` *extends* keyof `RealtimeTransportEventTypes` | #### Parameters [Section titled “Parameters”](#parameters-10) | Parameter | Type | | ---------- | ------------------- | | `type` | `K` | | `listener` | (…`args`) => `void` | #### Returns [Section titled “Returns”](#returns-16) `EventEmitter`<`EventTypes`> #### Implementation of [Section titled “Implementation of”](#implementation-of-8) ```ts RealtimeTransportLayer.off ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-14) ```ts OpenAIRealtimeWebSocket.off ``` *** ### on() [Section titled “on()”](#on) ```ts on(type, listener): EventEmitter; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-2) | Type Parameter | | ------------------------------------------------- | | `K` *extends* keyof `RealtimeTransportEventTypes` | #### Parameters [Section titled “Parameters”](#parameters-11) | Parameter | Type | | ---------- | ------------------- | | `type` | `K` | | `listener` | (…`args`) => `void` | #### Returns [Section titled “Returns”](#returns-17) `EventEmitter`<`EventTypes`> #### Implementation of [Section titled “Implementation of”](#implementation-of-9) ```ts RealtimeTransportLayer.on ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-15) ```ts OpenAIRealtimeWebSocket.on ``` *** ### once() [Section titled “once()”](#once) ```ts once(type, listener): EventEmitter; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-3) | Type Parameter | | ------------------------------------------------- | | `K` *extends* keyof `RealtimeTransportEventTypes` | #### Parameters [Section titled “Parameters”](#parameters-12) | Parameter | Type | | ---------- | ------------------- | | `type` | `K` | | `listener` | (…`args`) => `void` | #### Returns [Section titled “Returns”](#returns-18) `EventEmitter`<`EventTypes`> #### Implementation of [Section titled “Implementation of”](#implementation-of-10) ```ts RealtimeTransportLayer.once ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-16) ```ts OpenAIRealtimeWebSocket.once ``` *** ### requestResponse() [Section titled “requestResponse()”](#requestresponse) ```ts requestResponse(response?): void; ``` #### Parameters [Section titled “Parameters”](#parameters-13) | Parameter | Type | | ----------- | ------------------------- | | `response?` | `Record`<`string`, `any`> | #### Returns [Section titled “Returns”](#returns-19) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-11) ```ts RealtimeTransportLayer.requestResponse ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-17) ```ts OpenAIRealtimeWebSocket.requestResponse ``` *** ### resetHistory() [Section titled “resetHistory()”](#resethistory) ```ts resetHistory(oldHistory, newHistory): void; ``` Reset the history of the conversation. This will create a diff between the old and new history and send the necessary events to the Realtime API to update the history. #### Parameters [Section titled “Parameters”](#parameters-14) | Parameter | Type | Description | | ------------ | ----------------- | ------------------------------------ | | `oldHistory` | `RealtimeItem`\[] | The old history of the conversation. | | `newHistory` | `RealtimeItem`\[] | The new history of the conversation. | #### Returns [Section titled “Returns”](#returns-20) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-12) ```ts RealtimeTransportLayer.resetHistory ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-18) ```ts OpenAIRealtimeWebSocket.resetHistory ``` *** ### sendAudio() [Section titled “sendAudio()”](#sendaudio) ```ts sendAudio(audio, options?): void; ``` Send an audio buffer to the Realtime API. This is used for your client to send audio to the model to respond. #### Parameters [Section titled “Parameters”](#parameters-15) | Parameter | Type | Description | | ----------------- | ------------------------- | --------------------------------- | | `audio` | `ArrayBuffer` | The audio buffer to send. | | `options?` | { `commit?`: `boolean`; } | The options for the audio buffer. | | `options.commit?` | `boolean` | ‐ | #### Returns [Section titled “Returns”](#returns-21) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-13) ```ts RealtimeTransportLayer.sendAudio ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-19) ```ts OpenAIRealtimeWebSocket.sendAudio ``` *** ### sendEvent() [Section titled “sendEvent()”](#sendevent) ```ts sendEvent(event): void; ``` Send an event to the Realtime API. This will stringify the event and send it directly to the API. This can be used if you want to take control over the connection and send events manually. #### Parameters [Section titled “Parameters”](#parameters-16) | Parameter | Type | Description | | --------- | ----------------------- | ------------------ | | `event` | `RealtimeClientMessage` | The event to send. | #### Returns [Section titled “Returns”](#returns-22) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-14) ```ts RealtimeTransportLayer.sendEvent ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-20) ```ts OpenAIRealtimeWebSocket.sendEvent ``` *** ### sendFunctionCallOutput() [Section titled “sendFunctionCallOutput()”](#sendfunctioncalloutput) ```ts sendFunctionCallOutput( toolCall, output, startResponse?): void; ``` Send the output of a function call to the Realtime API. #### Parameters [Section titled “Parameters”](#parameters-17) | Parameter | Type | Description | | ---------------- | ------------------------ | --------------------------------------------------------- | | `toolCall` | `TransportToolCallEvent` | The tool call to send the output for. | | `output` | `string` | The output of the function call. | | `startResponse?` | `boolean` | Whether to start a new response after sending the output. | #### Returns [Section titled “Returns”](#returns-23) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-15) ```ts RealtimeTransportLayer.sendFunctionCallOutput ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-21) ```ts OpenAIRealtimeWebSocket.sendFunctionCallOutput ``` *** ### sendMcpResponse() [Section titled “sendMcpResponse()”](#sendmcpresponse) ```ts sendMcpResponse( approvalRequest, approved, reason?): void; ``` Sends a response for an MCP tool call #### Parameters [Section titled “Parameters”](#parameters-18) | Parameter | Type | Description | | ------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------- | | `approvalRequest` | { `approved?`: `boolean` \| `null`; `arguments`: `z.ZodRecord`<`z.ZodString`, `z.ZodAny`>; `itemId`: `string`; `name`: `string`; `serverLabel`: `string`; `type`: `"mcp_approval_request"`; } | The approval request to respond to | | `approvalRequest.approved?` | `boolean` \| `null` | ‐ | | `approvalRequest.arguments` | `z.ZodRecord`<`z.ZodString`, `z.ZodAny`> | ‐ | | `approvalRequest.itemId?` | `string` | ‐ | | `approvalRequest.name?` | `string` | ‐ | | `approvalRequest.serverLabel?` | `string` | ‐ | | `approvalRequest.type?` | `"mcp_approval_request"` | ‐ | | `approved?` | `boolean` | Whether the tool call was approved or rejected | | `reason?` | `string` | Optional rejection text for the provider/model. | #### Returns [Section titled “Returns”](#returns-24) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-16) ```ts RealtimeTransportLayer.sendMcpResponse ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-22) ```ts OpenAIRealtimeWebSocket.sendMcpResponse ``` *** ### sendMessage() [Section titled “sendMessage()”](#sendmessage) ```ts sendMessage( message, otherEventData, __namedParameters?): void; ``` Send a message to the Realtime API. This will create a new item in the conversation and trigger a response. #### Parameters [Section titled “Parameters”](#parameters-19) | Parameter | Type | Description | | ------------------------------------ | ---------------------------------- | ------------------------------ | | `message` | `RealtimeUserInput` | The message to send. | | `otherEventData` | `Record`<`string`, `any`> | Additional event data to send. | | `__namedParameters?` | { `triggerResponse?`: `boolean`; } | ‐ | | `__namedParameters.triggerResponse?` | `boolean` | ‐ | #### Returns [Section titled “Returns”](#returns-25) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-17) ```ts RealtimeTransportLayer.sendMessage ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-23) ```ts OpenAIRealtimeWebSocket.sendMessage ``` *** ### updateSessionConfig() [Section titled “updateSessionConfig()”](#updatesessionconfig) ```ts updateSessionConfig(config): void; ``` Updates the session config. This will merge it with the current session config with the default values and send it to the Realtime API. #### Parameters [Section titled “Parameters”](#parameters-20) | Parameter | Type | Description | | --------- | ---------------------------------- | ----------------------------- | | `config` | `Partial`<`RealtimeSessionConfig`> | The session config to update. | #### Returns [Section titled “Returns”](#returns-26) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-18) ```ts RealtimeTransportLayer.updateSessionConfig ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-24) ```ts OpenAIRealtimeWebSocket.updateSessionConfig ``` # TwilioRealtimeTransportLayer An adapter to connect a websocket that is receiving messages from Twilio’s Media Streams API to the OpenAI Realtime API via WebSocket. It automatically handles setting the right audio format for the input and output audio, passing the data along and handling the timing for interruptions using Twilio’s `mark` events. It does require you to run your own WebSocket server that is receiving connection requests from Twilio. It will emit all Twilio received messages as `twilio_message` type messages on the `*` handler. If you are using a `RealtimeSession` you can listen to the `transport_event`. ## Example [Section titled “Example”](#example) ```ts const transport = new TwilioRealtimeTransportLayer({ twilioWebSocket: twilioWebSocket, }); transport.on('*', (event) => { if (event.type === 'twilio_message') { console.log('Twilio message:', event.data); } }); ``` ## Extends [Section titled “Extends”](#extends) * `OpenAIRealtimeWebSocket` ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new TwilioRealtimeTransportLayer(options): TwilioRealtimeTransportLayer; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ------------------------------------------------------------------------------------------------------------------------------------- | | `options` | [`TwilioRealtimeTransportLayerOptions`](/openai-agents-js/openai/agents-extensions/type-aliases/twiliorealtimetransportlayeroptions/) | #### Returns [Section titled “Returns”](#returns) `TwilioRealtimeTransportLayer` #### Overrides [Section titled “Overrides”](#overrides) ```ts OpenAIRealtimeWebSocket.constructor ``` ## Accessors [Section titled “Accessors”](#accessors) ### \_tracingConfig [Section titled “\_tracingConfig”](#_tracingconfig) #### Set Signature [Section titled “Set Signature”](#set-signature) ```ts set _tracingConfig(tracingConfig): void; ``` Sets the internal tracing config. This is used to track the tracing config that has been set during the session.create event. ##### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | --------------- | --------------------------------- | | `tracingConfig` | `RealtimeTracingConfig` \| `null` | ##### Returns [Section titled “Returns”](#returns-1) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from) ```ts OpenAIRealtimeWebSocket._tracingConfig ``` *** ### connectionState [Section titled “connectionState”](#connectionstate) #### Get Signature [Section titled “Get Signature”](#get-signature) ```ts get connectionState(): WebSocketState; ``` The current connection state of the WebSocket connection. ##### Returns [Section titled “Returns”](#returns-2) `WebSocketState` #### Inherited from [Section titled “Inherited from”](#inherited-from-1) ```ts OpenAIRealtimeWebSocket.connectionState ``` *** ### currentModel [Section titled “currentModel”](#currentmodel) #### Get Signature [Section titled “Get Signature”](#get-signature-1) ```ts get currentModel(): OpenAIRealtimeModels; ``` The current model that is being used by the transport layer. ##### Returns [Section titled “Returns”](#returns-3) `OpenAIRealtimeModels` #### Set Signature [Section titled “Set Signature”](#set-signature-1) ```ts set currentModel(model): void; ``` The current model that is being used by the transport layer. **Note**: The model cannot be changed mid conversation. ##### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | --------- | ---------------------- | | `model` | `OpenAIRealtimeModels` | ##### Returns [Section titled “Returns”](#returns-4) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-2) ```ts OpenAIRealtimeWebSocket.currentModel ``` *** ### muted [Section titled “muted”](#muted) #### Get Signature [Section titled “Get Signature”](#get-signature-2) ```ts get muted(): null; ``` Always returns `null` as the WebSocket transport layer does not handle muting. Instead, this should be handled by the client by not triggering the `sendAudio` method. ##### Returns [Section titled “Returns”](#returns-5) `null` #### Inherited from [Section titled “Inherited from”](#inherited-from-3) ```ts OpenAIRealtimeWebSocket.muted ``` *** ### status [Section titled “status”](#status) #### Get Signature [Section titled “Get Signature”](#get-signature-3) ```ts get status(): "connected" | "disconnected" | "connecting"; ``` The current status of the WebSocket connection. ##### Returns [Section titled “Returns”](#returns-6) `"connected"` | `"disconnected"` | `"connecting"` #### Inherited from [Section titled “Inherited from”](#inherited-from-4) ```ts OpenAIRealtimeWebSocket.status ``` ## Methods [Section titled “Methods”](#methods) ### \_cancelResponse() [Section titled “\_cancelResponse()”](#_cancelresponse) ```ts _cancelResponse(): void; ``` Send a cancel response event to the Realtime API. This is used to cancel an ongoing response that the model is currently generating. #### Returns [Section titled “Returns”](#returns-7) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-5) ```ts OpenAIRealtimeWebSocket._cancelResponse ``` *** ### \_interrupt() [Section titled “\_interrupt()”](#_interrupt) ```ts _interrupt(_elapsedTime, cancelOngoingResponse?): void; ``` Do NOT call this method directly. Call `interrupt()` instead for proper interruption handling. This method is used to send the right events to the API to inform the model that the user has interrupted the response. It might be overridden/extended by an extended transport layer. See the `TwilioRealtimeTransportLayer` for an example. #### Parameters [Section titled “Parameters”](#parameters-3) | Parameter | Type | Default value | | ----------------------- | --------- | ------------- | | `_elapsedTime` | `number` | `undefined` | | `cancelOngoingResponse` | `boolean` | `true` | #### Returns [Section titled “Returns”](#returns-8) `void` #### Overrides [Section titled “Overrides”](#overrides-1) ```ts OpenAIRealtimeWebSocket._interrupt ``` *** ### \_setInputAndOutputAudioFormat() [Section titled “\_setInputAndOutputAudioFormat()”](#_setinputandoutputaudioformat) ```ts _setInputAndOutputAudioFormat(partialConfig?): Partial; ``` #### Parameters [Section titled “Parameters”](#parameters-4) | Parameter | Type | | ---------------- | ---------------------------------- | | `partialConfig?` | `Partial`<`RealtimeSessionConfig`> | #### Returns [Section titled “Returns”](#returns-9) `Partial`<`RealtimeSessionConfig`> *** ### addImage() [Section titled “addImage()”](#addimage) ```ts addImage(image, options?): void; ``` Sends an image to the model #### Parameters [Section titled “Parameters”](#parameters-5) | Parameter | Type | Description | | -------------------------- | ---------------------------------- | -------------------------------------------- | | `image` | `string` | The image to send | | `options?` | { `triggerResponse?`: `boolean`; } | Additional options | | `options.triggerResponse?` | `boolean` | Whether to trigger a response from the model | #### Returns [Section titled “Returns”](#returns-10) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-6) ```ts OpenAIRealtimeWebSocket.addImage ``` *** ### buildSessionPayload() [Section titled “buildSessionPayload()”](#buildsessionpayload) ```ts buildSessionPayload(config): RealtimeSessionPayload; ``` Build the payload object expected by the Realtime API when creating or updating a session. The helper centralises the conversion from camelCase runtime config to the snake\_case payload required by the Realtime API so transports that need a one-off payload (for example SIP call acceptance) can reuse the same logic without duplicating private state. #### Parameters [Section titled “Parameters”](#parameters-6) | Parameter | Type | Description | | --------- | ---------------------------------- | ------------------------------------------ | | `config` | `Partial`<`RealtimeSessionConfig`> | The session config to merge with defaults. | #### Returns [Section titled “Returns”](#returns-11) `RealtimeSessionPayload` #### Inherited from [Section titled “Inherited from”](#inherited-from-7) ```ts OpenAIRealtimeWebSocket.buildSessionPayload ``` *** ### close() [Section titled “close()”](#close) ```ts close(): void; ``` Close the WebSocket connection. This will also reset any internal connection tracking used for interruption handling. #### Returns [Section titled “Returns”](#returns-12) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-8) ```ts OpenAIRealtimeWebSocket.close ``` *** ### connect() [Section titled “connect()”](#connect) ```ts connect(options): Promise; ``` #### Parameters [Section titled “Parameters”](#parameters-7) | Parameter | Type | | --------- | -------------------------------------- | | `options` | `RealtimeTransportLayerConnectOptions` | #### Returns [Section titled “Returns”](#returns-13) `Promise`<`void`> #### Overrides [Section titled “Overrides”](#overrides-2) ```ts OpenAIRealtimeWebSocket.connect ``` *** ### emit() [Section titled “emit()”](#emit) ```ts emit(type, ...args): boolean; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | ------------------------------------------------- | | `K` *extends* keyof `RealtimeTransportEventTypes` | #### Parameters [Section titled “Parameters”](#parameters-8) | Parameter | Type | | --------- | -------------------------------- | | `type` | `K` | | …`args` | `OpenAIRealtimeEventTypes`\[`K`] | #### Returns [Section titled “Returns”](#returns-14) `boolean` #### Inherited from [Section titled “Inherited from”](#inherited-from-9) ```ts OpenAIRealtimeWebSocket.emit ``` *** ### interrupt() [Section titled “interrupt()”](#interrupt) ```ts interrupt(cancelOngoingResponse?): void; ``` Interrupt the ongoing response. This method is triggered automatically by the client when voice activity detection (VAD) is enabled (default) as well as when an output guardrail got triggered. You can also call this method directly if you want to interrupt the conversation for example based on an event in the client. #### Parameters [Section titled “Parameters”](#parameters-9) | Parameter | Type | | ------------------------ | --------- | | `cancelOngoingResponse?` | `boolean` | #### Returns [Section titled “Returns”](#returns-15) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-10) ```ts OpenAIRealtimeWebSocket.interrupt ``` *** ### mute() [Section titled “mute()”](#mute) ```ts mute(_muted): never; ``` Will throw an error as the WebSocket transport layer does not support muting. #### Parameters [Section titled “Parameters”](#parameters-10) | Parameter | Type | | --------- | --------- | | `_muted` | `boolean` | #### Returns [Section titled “Returns”](#returns-16) `never` #### Inherited from [Section titled “Inherited from”](#inherited-from-11) ```ts OpenAIRealtimeWebSocket.mute ``` *** ### off() [Section titled “off()”](#off) ```ts off(type, listener): EventEmitter; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-1) | Type Parameter | | ------------------------------------------------- | | `K` *extends* keyof `RealtimeTransportEventTypes` | #### Parameters [Section titled “Parameters”](#parameters-11) | Parameter | Type | | ---------- | ------------------- | | `type` | `K` | | `listener` | (…`args`) => `void` | #### Returns [Section titled “Returns”](#returns-17) `EventEmitter`<`EventTypes`> #### Inherited from [Section titled “Inherited from”](#inherited-from-12) ```ts OpenAIRealtimeWebSocket.off ``` *** ### on() [Section titled “on()”](#on) ```ts on(type, listener): EventEmitter; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-2) | Type Parameter | | ------------------------------------------------- | | `K` *extends* keyof `RealtimeTransportEventTypes` | #### Parameters [Section titled “Parameters”](#parameters-12) | Parameter | Type | | ---------- | ------------------- | | `type` | `K` | | `listener` | (…`args`) => `void` | #### Returns [Section titled “Returns”](#returns-18) `EventEmitter`<`EventTypes`> #### Inherited from [Section titled “Inherited from”](#inherited-from-13) ```ts OpenAIRealtimeWebSocket.on ``` *** ### once() [Section titled “once()”](#once) ```ts once(type, listener): EventEmitter; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-3) | Type Parameter | | ------------------------------------------------- | | `K` *extends* keyof `RealtimeTransportEventTypes` | #### Parameters [Section titled “Parameters”](#parameters-13) | Parameter | Type | | ---------- | ------------------- | | `type` | `K` | | `listener` | (…`args`) => `void` | #### Returns [Section titled “Returns”](#returns-19) `EventEmitter`<`EventTypes`> #### Inherited from [Section titled “Inherited from”](#inherited-from-14) ```ts OpenAIRealtimeWebSocket.once ``` *** ### requestResponse() [Section titled “requestResponse()”](#requestresponse) ```ts requestResponse(response?): void; ``` #### Parameters [Section titled “Parameters”](#parameters-14) | Parameter | Type | | ----------- | ------------------------- | | `response?` | `Record`<`string`, `any`> | #### Returns [Section titled “Returns”](#returns-20) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-15) ```ts OpenAIRealtimeWebSocket.requestResponse ``` *** ### resetHistory() [Section titled “resetHistory()”](#resethistory) ```ts resetHistory(oldHistory, newHistory): void; ``` Reset the history of the conversation. This will create a diff between the old and new history and send the necessary events to the Realtime API to update the history. #### Parameters [Section titled “Parameters”](#parameters-15) | Parameter | Type | Description | | ------------ | ----------------- | ------------------------------------ | | `oldHistory` | `RealtimeItem`\[] | The old history of the conversation. | | `newHistory` | `RealtimeItem`\[] | The new history of the conversation. | #### Returns [Section titled “Returns”](#returns-21) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-16) ```ts OpenAIRealtimeWebSocket.resetHistory ``` *** ### sendAudio() [Section titled “sendAudio()”](#sendaudio) ```ts sendAudio(audio, options?): void; ``` Send an audio buffer to the Realtime API. This is used for your client to send audio to the model to respond. #### Parameters [Section titled “Parameters”](#parameters-16) | Parameter | Type | Description | | ----------------- | ------------------------- | --------------------------------- | | `audio` | `ArrayBuffer` | The audio buffer to send. | | `options?` | { `commit?`: `boolean`; } | The options for the audio buffer. | | `options.commit?` | `boolean` | ‐ | #### Returns [Section titled “Returns”](#returns-22) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-17) ```ts OpenAIRealtimeWebSocket.sendAudio ``` *** ### sendEvent() [Section titled “sendEvent()”](#sendevent) ```ts sendEvent(event): void; ``` Send an event to the Realtime API. This will stringify the event and send it directly to the API. This can be used if you want to take control over the connection and send events manually. #### Parameters [Section titled “Parameters”](#parameters-17) | Parameter | Type | Description | | --------- | ----------------------- | ------------------ | | `event` | `RealtimeClientMessage` | The event to send. | #### Returns [Section titled “Returns”](#returns-23) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-18) ```ts OpenAIRealtimeWebSocket.sendEvent ``` *** ### sendFunctionCallOutput() [Section titled “sendFunctionCallOutput()”](#sendfunctioncalloutput) ```ts sendFunctionCallOutput( toolCall, output, startResponse?): void; ``` Send the output of a function call to the Realtime API. #### Parameters [Section titled “Parameters”](#parameters-18) | Parameter | Type | Description | | ---------------- | ------------------------ | --------------------------------------------------------- | | `toolCall` | `TransportToolCallEvent` | The tool call to send the output for. | | `output` | `string` | The output of the function call. | | `startResponse?` | `boolean` | Whether to start a new response after sending the output. | #### Returns [Section titled “Returns”](#returns-24) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-19) ```ts OpenAIRealtimeWebSocket.sendFunctionCallOutput ``` *** ### sendMcpResponse() [Section titled “sendMcpResponse()”](#sendmcpresponse) ```ts sendMcpResponse( approvalRequest, approved, reason?): void; ``` Sends a response for an MCP tool call #### Parameters [Section titled “Parameters”](#parameters-19) | Parameter | Type | Description | | ------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------- | | `approvalRequest` | { `approved?`: `boolean` \| `null`; `arguments`: `z.ZodRecord`<`z.ZodString`, `z.ZodAny`>; `itemId`: `string`; `name`: `string`; `serverLabel`: `string`; `type`: `"mcp_approval_request"`; } | The approval request to respond to | | `approvalRequest.approved?` | `boolean` \| `null` | ‐ | | `approvalRequest.arguments` | `z.ZodRecord`<`z.ZodString`, `z.ZodAny`> | ‐ | | `approvalRequest.itemId?` | `string` | ‐ | | `approvalRequest.name?` | `string` | ‐ | | `approvalRequest.serverLabel?` | `string` | ‐ | | `approvalRequest.type?` | `"mcp_approval_request"` | ‐ | | `approved?` | `boolean` | Whether the tool call was approved or rejected | | `reason?` | `string` | Optional rejection text for the provider/model. | #### Returns [Section titled “Returns”](#returns-25) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-20) ```ts OpenAIRealtimeWebSocket.sendMcpResponse ``` *** ### sendMessage() [Section titled “sendMessage()”](#sendmessage) ```ts sendMessage( message, otherEventData, __namedParameters?): void; ``` Send a message to the Realtime API. This will create a new item in the conversation and trigger a response. #### Parameters [Section titled “Parameters”](#parameters-20) | Parameter | Type | Description | | ------------------------------------ | ---------------------------------- | ------------------------------ | | `message` | `RealtimeUserInput` | The message to send. | | `otherEventData` | `Record`<`string`, `any`> | Additional event data to send. | | `__namedParameters?` | { `triggerResponse?`: `boolean`; } | ‐ | | `__namedParameters.triggerResponse?` | `boolean` | ‐ | #### Returns [Section titled “Returns”](#returns-26) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-21) ```ts OpenAIRealtimeWebSocket.sendMessage ``` *** ### updateSessionConfig() [Section titled “updateSessionConfig()”](#updatesessionconfig) ```ts updateSessionConfig(config): void; ``` Updates the session config. This will merge it with the current session config with the default values and send it to the Realtime API. #### Parameters [Section titled “Parameters”](#parameters-21) | Parameter | Type | Description | | --------- | ---------------------------------- | ----------------------------- | | `config` | `Partial`<`RealtimeSessionConfig`> | The session config to update. | #### Returns [Section titled “Returns”](#returns-27) `void` #### Overrides [Section titled “Overrides”](#overrides-3) ```ts OpenAIRealtimeWebSocket.updateSessionConfig ``` # @openai/agents-extensions ## Classes [Section titled “Classes”](#classes) * [CloudflareRealtimeTransportLayer](/openai-agents-js/openai/agents-extensions/classes/cloudflarerealtimetransportlayer/) * [TwilioRealtimeTransportLayer](/openai-agents-js/openai/agents-extensions/classes/twiliorealtimetransportlayer/) ## Type Aliases [Section titled “Type Aliases”](#type-aliases) * [TwilioRealtimeTransportLayerOptions](/openai-agents-js/openai/agents-extensions/type-aliases/twiliorealtimetransportlayeroptions/) # TwilioRealtimeTransportLayerOptions ```ts type TwilioRealtimeTransportLayerOptions = OpenAIRealtimeWebSocketOptions & object; ``` The options for the Twilio Realtime Transport Layer. ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### twilioWebSocket [Section titled “twilioWebSocket”](#twiliowebsocket) ```ts twilioWebSocket: WebSocket | NodeWebSocket; ``` The websocket that is receiving messages from Twilio’s Media Streams API. Typically the connection gets passed into your request handler when running your WebSocket server. # OpenAIChatCompletionsModel ## Implements [Section titled “Implements”](#implements) * `Model` ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new OpenAIChatCompletionsModel( client, model, options?): OpenAIChatCompletionsModel; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ----------------------------------------------------------------------------------------------------------------------------- | | `client` | `OpenAI` | | `model` | `string` | | `options` | [`OpenAIChatCompletionsModelOptions`](/openai-agents-js/openai/agents-openai/type-aliases/openaichatcompletionsmodeloptions/) | #### Returns [Section titled “Returns”](#returns) `OpenAIChatCompletionsModel` ## Methods [Section titled “Methods”](#methods) ### getResponse() [Section titled “getResponse()”](#getresponse) ```ts getResponse(request): Promise; ``` Get a response from the model. #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | Description | | --------- | -------------- | ---------------------------------- | | `request` | `ModelRequest` | The request to get a response for. | #### Returns [Section titled “Returns”](#returns-1) `Promise`<`ModelResponse`> #### Implementation of [Section titled “Implementation of”](#implementation-of) ```ts Model.getResponse ``` *** ### getRetryAdvice() [Section titled “getRetryAdvice()”](#getretryadvice) ```ts getRetryAdvice(args): ModelRetryAdvice | undefined; ``` Provide optional retry advice for a failed request. #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | --------- | ------------------------- | | `args` | `ModelRetryAdviceRequest` | #### Returns [Section titled “Returns”](#returns-2) `ModelRetryAdvice` | `undefined` #### Implementation of [Section titled “Implementation of”](#implementation-of-1) ```ts Model.getRetryAdvice ``` *** ### getStreamedResponse() [Section titled “getStreamedResponse()”](#getstreamedresponse) ```ts getStreamedResponse(request): AsyncIterable; ``` Get a streamed response from the model. #### Parameters [Section titled “Parameters”](#parameters-3) | Parameter | Type | | --------- | -------------- | | `request` | `ModelRequest` | #### Returns [Section titled “Returns”](#returns-3) `AsyncIterable`<`StreamEvent`> #### Implementation of [Section titled “Implementation of”](#implementation-of-2) ```ts Model.getStreamedResponse ``` # OpenAIConversationsSession ## Implements [Section titled “Implements”](#implements) * `Session` * `OpenAISessionApiTagged`<`"conversations"`> ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new OpenAIConversationsSession(options?): OpenAIConversationsSession; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ----------------------------------------------------------------------------------------------------------------------------- | | `options` | [`OpenAIConversationsSessionOptions`](/openai-agents-js/openai/agents-openai/type-aliases/openaiconversationssessionoptions/) | #### Returns [Section titled “Returns”](#returns) `OpenAIConversationsSession` ## Properties [Section titled “Properties”](#properties) ### \[OPENAI\_SESSION\_API] [Section titled “\[OPENAI\_SESSION\_API\]”](#openai_session_api) ```ts readonly [OPENAI_SESSION_API]: "conversations"; ``` #### Implementation of [Section titled “Implementation of”](#implementation-of) ```ts OpenAISessionApiTagged.[OPENAI_SESSION_API] ``` ## Accessors [Section titled “Accessors”](#accessors) ### sessionId [Section titled “sessionId”](#sessionid) #### Get Signature [Section titled “Get Signature”](#get-signature) ```ts get sessionId(): string | undefined; ``` ##### Returns [Section titled “Returns”](#returns-1) `string` | `undefined` ## Methods [Section titled “Methods”](#methods) ### addItems() [Section titled “addItems()”](#additems) ```ts addItems(items): Promise; ``` Append new items to the conversation history. #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | Description | | --------- | ------------------- | ------------------------------------ | | `items` | `AgentInputItem`\[] | Items to add to the session history. | #### Returns [Section titled “Returns”](#returns-2) `Promise`<`void`> #### Implementation of [Section titled “Implementation of”](#implementation-of-1) ```ts Session.addItems ``` *** ### clearSession() [Section titled “clearSession()”](#clearsession) ```ts clearSession(): Promise; ``` Remove all items that belong to the session and reset its state. #### Returns [Section titled “Returns”](#returns-3) `Promise`<`void`> #### Implementation of [Section titled “Implementation of”](#implementation-of-2) ```ts Session.clearSession ``` *** ### getItems() [Section titled “getItems()”](#getitems) ```ts getItems(limit?): Promise; ``` Retrieve items from the conversation history. #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | Description | | --------- | -------- | --------------------------------------------------------------------------------------------------------------------------- | | `limit?` | `number` | The maximum number of items to return. When provided the most recent limit items should be returned in chronological order. | #### Returns [Section titled “Returns”](#returns-4) `Promise`<`AgentInputItem`\[]> #### Implementation of [Section titled “Implementation of”](#implementation-of-3) ```ts Session.getItems ``` *** ### getSessionId() [Section titled “getSessionId()”](#getsessionid) ```ts getSessionId(): Promise; ``` Ensure and return the identifier for this session. #### Returns [Section titled “Returns”](#returns-5) `Promise`<`string`> #### Implementation of [Section titled “Implementation of”](#implementation-of-4) ```ts Session.getSessionId ``` *** ### popItem() [Section titled “popItem()”](#popitem) ```ts popItem(): Promise; ``` Remove and return the most recent item from the conversation history if it exists. #### Returns [Section titled “Returns”](#returns-6) `Promise`<`AgentInputItem` | `undefined`> #### Implementation of [Section titled “Implementation of”](#implementation-of-5) ```ts Session.popItem ``` *** ### prepareHistoryItemForModelInput() [Section titled “prepareHistoryItemForModelInput()”](#preparehistoryitemformodelinput) ```ts prepareHistoryItemForModelInput(item): AgentInputItem; ``` Optionally rewrite a stored history item before it is sent back to the model. Session implementations can use this to strip provider-managed replay metadata while preserving their public `getItems()` shape for UI and deletion workflows. #### Parameters [Section titled “Parameters”](#parameters-3) | Parameter | Type | | --------- | ---------------- | | `item` | `AgentInputItem` | #### Returns [Section titled “Returns”](#returns-7) `AgentInputItem` #### Implementation of [Section titled “Implementation of”](#implementation-of-6) ```ts Session.prepareHistoryItemForModelInput ``` *** ### preserveReasoningItemIdsForPersistence() [Section titled “preserveReasoningItemIdsForPersistence()”](#preservereasoningitemidsforpersistence) ```ts preserveReasoningItemIdsForPersistence(): boolean; ``` Optionally preserve reasoning item IDs when persisting generated output. Some remote session stores require provider-assigned reasoning identities to accept stored reasoning items, even when model replay should omit those IDs. #### Returns [Section titled “Returns”](#returns-8) `boolean` #### Implementation of [Section titled “Implementation of”](#implementation-of-7) ```ts Session.preserveReasoningItemIdsForPersistence ``` # OpenAIProvider The provider of OpenAI’s models (or Chat Completions compatible ones) ## Implements [Section titled “Implements”](#implements) * `ModelProvider` ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new OpenAIProvider(options?): OpenAIProvider; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ----------------------------------------------------------------------------------------------------- | | `options` | [`OpenAIProviderOptions`](/openai-agents-js/openai/agents-openai/type-aliases/openaiprovideroptions/) | #### Returns [Section titled “Returns”](#returns) `OpenAIProvider` ## Methods [Section titled “Methods”](#methods) ### close() [Section titled “close()”](#close) ```ts close(): Promise; ``` Closes cached model wrappers (for example websocket-backed responses models) and clears cache. #### Returns [Section titled “Returns”](#returns-1) `Promise`<`void`> *** ### getModel() [Section titled “getModel()”](#getmodel) ```ts getModel(modelName?): Promise; ``` Get a model by name #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | Description | | ------------ | -------- | ----------------------------- | | `modelName?` | `string` | The name of the model to get. | #### Returns [Section titled “Returns”](#returns-2) `Promise`<`Model`> #### Implementation of [Section titled “Implementation of”](#implementation-of) ```ts ModelProvider.getModel ``` # OpenAIResponsesCompactionSession Session decorator that triggers `responses.compact` when the stored history grows. This session is intended to be passed to `run()` so the runner can automatically supply the latest `responseId` and invoke compaction after each completed turn is persisted. To debug compaction decisions, enable the `debug` logger for `openai-agents:openai:compaction` (for example, `DEBUG=openai-agents:openai:compaction`). ## Implements [Section titled “Implements”](#implements) * `OpenAIResponsesCompactionAwareSession` * `OpenAISessionApiTagged`<`"responses"`> ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new OpenAIResponsesCompactionSession(options): OpenAIResponsesCompactionSession; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ----------------------------------------------------------------------------------------------------------------------------------------- | | `options` | [`OpenAIResponsesCompactionSessionOptions`](/openai-agents-js/openai/agents-openai/type-aliases/openairesponsescompactionsessionoptions/) | #### Returns [Section titled “Returns”](#returns) `OpenAIResponsesCompactionSession` ## Properties [Section titled “Properties”](#properties) ### \[OPENAI\_SESSION\_API] [Section titled “\[OPENAI\_SESSION\_API\]”](#openai_session_api) ```ts readonly [OPENAI_SESSION_API]: "responses"; ``` #### Implementation of [Section titled “Implementation of”](#implementation-of) ```ts OpenAISessionApiTagged.[OPENAI_SESSION_API] ``` ## Methods [Section titled “Methods”](#methods) ### addItems() [Section titled “addItems()”](#additems) ```ts addItems(items): Promise; ``` Append new items to the conversation history. #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | Description | | --------- | ------------------- | ------------------------------------ | | `items` | `AgentInputItem`\[] | Items to add to the session history. | #### Returns [Section titled “Returns”](#returns-1) `Promise`<`void`> #### Implementation of [Section titled “Implementation of”](#implementation-of-1) ```ts OpenAIResponsesCompactionSessionLike.addItems ``` *** ### clearSession() [Section titled “clearSession()”](#clearsession) ```ts clearSession(): Promise; ``` Remove all items that belong to the session and reset its state. #### Returns [Section titled “Returns”](#returns-2) `Promise`<`void`> #### Implementation of [Section titled “Implementation of”](#implementation-of-2) ```ts OpenAIResponsesCompactionSessionLike.clearSession ``` *** ### getItems() [Section titled “getItems()”](#getitems) ```ts getItems(limit?): Promise; ``` Retrieve items from the conversation history. #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | Description | | --------- | -------- | --------------------------------------------------------------------------------------------------------------------------- | | `limit?` | `number` | The maximum number of items to return. When provided the most recent limit items should be returned in chronological order. | #### Returns [Section titled “Returns”](#returns-3) `Promise`<`AgentInputItem`\[]> #### Implementation of [Section titled “Implementation of”](#implementation-of-3) ```ts OpenAIResponsesCompactionSessionLike.getItems ``` *** ### getSessionId() [Section titled “getSessionId()”](#getsessionid) ```ts getSessionId(): Promise; ``` Ensure and return the identifier for this session. #### Returns [Section titled “Returns”](#returns-4) `Promise`<`string`> #### Implementation of [Section titled “Implementation of”](#implementation-of-4) ```ts OpenAIResponsesCompactionSessionLike.getSessionId ``` *** ### popItem() [Section titled “popItem()”](#popitem) ```ts popItem(): Promise; ``` Remove and return the most recent item from the conversation history if it exists. #### Returns [Section titled “Returns”](#returns-5) `Promise`<`AgentInputItem` | `undefined`> #### Implementation of [Section titled “Implementation of”](#implementation-of-5) ```ts OpenAIResponsesCompactionSessionLike.popItem ``` *** ### runCompaction() [Section titled “runCompaction()”](#runcompaction) ```ts runCompaction(args?): Promise; ``` Invoked by the runner after it persists a completed turn into the session. Implementations may decide to call `responses.compact` (or an equivalent API) and replace the stored history. This hook is best-effort. Implementations should consider handling transient failures and deciding whether to retry or skip compaction for the current turn. #### Parameters [Section titled “Parameters”](#parameters-3) | Parameter | Type | | --------- | ------------------------------- | | `args` | `OpenAIResponsesCompactionArgs` | #### Returns [Section titled “Returns”](#returns-6) `Promise`<`OpenAIResponsesCompactionResult` | `null`> #### Implementation of [Section titled “Implementation of”](#implementation-of-6) ```ts OpenAIResponsesCompactionSessionLike.runCompaction ``` # OpenAIResponsesModel Model implementation that uses OpenAI’s Responses API to generate responses. ## Extended by [Section titled “Extended by”](#extended-by) * [`OpenAIResponsesWSModel`](/openai-agents-js/openai/agents-openai/classes/openairesponseswsmodel/) ## Implements [Section titled “Implements”](#implements) * `Model` ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new OpenAIResponsesModel(client, model): OpenAIResponsesModel; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | -------- | | `client` | `OpenAI` | | `model` | `string` | #### Returns [Section titled “Returns”](#returns) `OpenAIResponsesModel` ## Methods [Section titled “Methods”](#methods) ### getResponse() [Section titled “getResponse()”](#getresponse) ```ts getResponse(request): Promise; ``` Get a response from the OpenAI model using the Responses API. #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | Description | | --------- | -------------- | --------------------------------- | | `request` | `ModelRequest` | The request to send to the model. | #### Returns [Section titled “Returns”](#returns-1) `Promise`<`ModelResponse`> A promise that resolves to the response from the model. #### Implementation of [Section titled “Implementation of”](#implementation-of) ```ts Model.getResponse ``` *** ### getRetryAdvice() [Section titled “getRetryAdvice()”](#getretryadvice) ```ts getRetryAdvice(args): ModelRetryAdvice | undefined; ``` Provide optional retry advice for a failed request. #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | --------- | ------------------------- | | `args` | `ModelRetryAdviceRequest` | #### Returns [Section titled “Returns”](#returns-2) `ModelRetryAdvice` | `undefined` #### Implementation of [Section titled “Implementation of”](#implementation-of-1) ```ts Model.getRetryAdvice ``` *** ### getStreamedResponse() [Section titled “getStreamedResponse()”](#getstreamedresponse) ```ts getStreamedResponse(request): AsyncIterable; ``` Get a streamed response from the OpenAI model using the Responses API. #### Parameters [Section titled “Parameters”](#parameters-3) | Parameter | Type | Description | | --------- | -------------- | --------------------------------- | | `request` | `ModelRequest` | The request to send to the model. | #### Returns [Section titled “Returns”](#returns-3) `AsyncIterable`<`StreamEvent`> An async iterable of the response from the model. #### Implementation of [Section titled “Implementation of”](#implementation-of-2) ```ts Model.getStreamedResponse ``` # OpenAIResponsesWSModel Model implementation that uses the OpenAI Responses API over a websocket transport. ## See [Section titled “See”](#see) ## Extends [Section titled “Extends”](#extends) * [`OpenAIResponsesModel`](/openai-agents-js/openai/agents-openai/classes/openairesponsesmodel/) ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new OpenAIResponsesWSModel( client, model, options?): OpenAIResponsesWSModel; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ------------------------------- | | `client` | `OpenAI` | | `model` | `string` | | `options` | `OpenAIResponsesWSModelOptions` | #### Returns [Section titled “Returns”](#returns) `OpenAIResponsesWSModel` #### Overrides [Section titled “Overrides”](#overrides) [`OpenAIResponsesModel`](/openai-agents-js/openai/agents-openai/classes/openairesponsesmodel/).[`constructor`](/openai-agents-js/openai/agents-openai/classes/openairesponsesmodel/#constructor) ## Methods [Section titled “Methods”](#methods) ### close() [Section titled “close()”](#close) ```ts close(): Promise; ``` #### Returns [Section titled “Returns”](#returns-1) `Promise`<`void`> *** ### getResponse() [Section titled “getResponse()”](#getresponse) ```ts getResponse(request): Promise; ``` Get a response from the OpenAI model using the Responses API. #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | Description | | --------- | -------------- | --------------------------------- | | `request` | `ModelRequest` | The request to send to the model. | #### Returns [Section titled “Returns”](#returns-2) `Promise`<`ModelResponse`> A promise that resolves to the response from the model. #### Inherited from [Section titled “Inherited from”](#inherited-from) [`OpenAIResponsesModel`](/openai-agents-js/openai/agents-openai/classes/openairesponsesmodel/).[`getResponse`](/openai-agents-js/openai/agents-openai/classes/openairesponsesmodel/#getresponse) *** ### getRetryAdvice() [Section titled “getRetryAdvice()”](#getretryadvice) ```ts getRetryAdvice(args): ModelRetryAdvice | undefined; ``` Provide optional retry advice for a failed request. #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | --------- | ------------------------- | | `args` | `ModelRetryAdviceRequest` | #### Returns [Section titled “Returns”](#returns-3) `ModelRetryAdvice` | `undefined` #### Overrides [Section titled “Overrides”](#overrides-1) [`OpenAIResponsesModel`](/openai-agents-js/openai/agents-openai/classes/openairesponsesmodel/).[`getRetryAdvice`](/openai-agents-js/openai/agents-openai/classes/openairesponsesmodel/#getretryadvice) *** ### getStreamedResponse() [Section titled “getStreamedResponse()”](#getstreamedresponse) ```ts getStreamedResponse(request): AsyncIterable; ``` Get a streamed response from the OpenAI model using the Responses API. #### Parameters [Section titled “Parameters”](#parameters-3) | Parameter | Type | Description | | --------- | -------------- | --------------------------------- | | `request` | `ModelRequest` | The request to send to the model. | #### Returns [Section titled “Returns”](#returns-4) `AsyncIterable`<`StreamEvent`> An async iterable of the response from the model. #### Inherited from [Section titled “Inherited from”](#inherited-from-1) [`OpenAIResponsesModel`](/openai-agents-js/openai/agents-openai/classes/openairesponsesmodel/).[`getStreamedResponse`](/openai-agents-js/openai/agents-openai/classes/openairesponsesmodel/#getstreamedresponse) # OpenAITracingExporter A tracing exporter that exports traces to OpenAI’s tracing API. ## Implements [Section titled “Implements”](#implements) * `TracingExporter` ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new OpenAITracingExporter(options?): OpenAITracingExporter; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ------------------------------------------------------------------------------------------------------------------------------ | | `options` | `Partial`<[`OpenAITracingExporterOptions`](/openai-agents-js/openai/agents-openai/type-aliases/openaitracingexporteroptions/)> | #### Returns [Section titled “Returns”](#returns) `OpenAITracingExporter` ## Methods [Section titled “Methods”](#methods) ### export() [Section titled “export()”](#export) ```ts export(items, signal?): Promise; ``` Export the given traces and spans #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | Description | | --------- | ----------------------------- | ------------------------------ | | `items` | (`Span`<`any`> \| `Trace`)\[] | The traces and spans to export | | `signal?` | `AbortSignal` | ‐ | #### Returns [Section titled “Returns”](#returns-1) `Promise`<`void`> #### Implementation of [Section titled “Implementation of”](#implementation-of) ```ts TracingExporter.export ``` # codeInterpreterTool ```ts function codeInterpreterTool(options?): HostedTool; ``` Adds code interpreter abilities to your agent ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | --------- | -------------------------------------------------- | ------------------------------------------------- | | `options` | `Partial`<`Omit`<`CodeInterpreterTool`, `"type"`>> | Additional configuration for the code interpreter | ## Returns [Section titled “Returns”](#returns) `HostedTool` a code interpreter tool definition # fileSearchTool ```ts function fileSearchTool(vectorStoreIds, options?): HostedTool; ``` Adds file search abilities to your agent ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | ---------------- | ------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------- | | `vectorStoreIds` | `string` \| `string`\[] | The IDs of the vector stores to search. | | `options` | `Partial`<`Omit`<`FileSearchTool`, `"type"` \| `"vectorStoreId"`>> | Additional configuration for the file search like specifying the maximum number of results to return. | ## Returns [Section titled “Returns”](#returns) `HostedTool` a file search tool definition # imageGenerationTool ```ts function imageGenerationTool(options?): HostedTool; ``` Adds image generation abilities to your agent ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | --------- | -------------------------------------------------- | ------------------------------------------------- | | `options` | `Partial`<`Omit`<`ImageGenerationTool`, `"type"`>> | Additional configuration for the image generation | ## Returns [Section titled “Returns”](#returns) `HostedTool` an image generation tool definition # isOpenAIChatCompletionsRawModelStreamEvent ```ts function isOpenAIChatCompletionsRawModelStreamEvent(event): event is OpenAIChatCompletionsRawModelStreamEvent; ``` ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ---------------- | | `event` | `RunStreamEvent` | ## Returns [Section titled “Returns”](#returns) `event is OpenAIChatCompletionsRawModelStreamEvent` # isOpenAIResponsesRawModelStreamEvent ```ts function isOpenAIResponsesRawModelStreamEvent(event): event is OpenAIResponsesRawModelStreamEvent; ``` ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ---------------- | | `event` | `RunStreamEvent` | ## Returns [Section titled “Returns”](#returns) `event is OpenAIResponsesRawModelStreamEvent` # setDefaultOpenAIClient ```ts function setDefaultOpenAIClient(client): void; ``` ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | -------- | | `client` | `OpenAI` | ## Returns [Section titled “Returns”](#returns) `void` # setDefaultOpenAIKey ```ts function setDefaultOpenAIKey(key): void; ``` ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | -------- | | `key` | `string` | ## Returns [Section titled “Returns”](#returns) `void` # setDefaultOpenAITracingExporter ```ts function setDefaultOpenAITracingExporter(): void; ``` Sets the OpenAI Tracing exporter as the default exporter with a BatchTraceProcessor handling the traces ## Returns [Section titled “Returns”](#returns) `void` # setOpenAIAPI ```ts function setOpenAIAPI(value): void; ``` ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ------------------------------------- | | `value` | `"responses"` \| `"chat_completions"` | ## Returns [Section titled “Returns”](#returns) `void` # setOpenAIResponsesTransport ```ts function setOpenAIResponsesTransport(value): void; ``` ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ------------------------- | | `value` | `"http"` \| `"websocket"` | ## Returns [Section titled “Returns”](#returns) `void` # setTracingExportApiKey ```ts function setTracingExportApiKey(key): void; ``` ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | -------- | | `key` | `string` | ## Returns [Section titled “Returns”](#returns) `void` # startOpenAIConversationsSession ```ts function startOpenAIConversationsSession(client?): Promise; ``` ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | -------- | | `client?` | `OpenAI` | ## Returns [Section titled “Returns”](#returns) `Promise`<`string`> # toolSearchTool ```ts function toolSearchTool(options?): HostedTool; ``` Adds tool\_search capabilities to your agent. This lets the model search deferred function tools and load them into context on demand. By default, tool search is executed by OpenAI. Set `execution: 'client'` to use a custom loop that receives `tool_search_call` / `tool_search_output` items. The standard runner only supports the default built-in client schema (leave `parameters` unset) and auto-executes `{ paths: string[] }` searches over deferred top-level function tools and deferred namespace members. ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | ------------ | | `Context` | `unknown` | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ------------------------------------------------------------------------------------------------------------------------------- | | `options` | `Partial`<`Omit`<[`ToolSearchTool`](/openai-agents-js/openai/agents-openai/type-aliases/toolsearchtool/)<`Context`>, `"type"`>> | ## Returns [Section titled “Returns”](#returns) `HostedTool` a hosted tool\_search definition. # webSearchTool ```ts function webSearchTool(options?): HostedTool; ``` Adds web search abilities to your agent ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | --------- | -------------------------------------------- | -------------------------------------------------------------------------------------- | | `options` | `Partial`<`Omit`<`WebSearchTool`, `"type"`>> | Additional configuration for the web search like specifying the location of your agent | ## Returns [Section titled “Returns”](#returns) `HostedTool` a web search tool definition # withResponsesWebSocketSession ```ts function withResponsesWebSocketSession(callback, options?): Promise; ``` Runs a callback within a session-scoped Responses API websocket provider/runner and closes the provider afterwards so websocket connections do not keep the process alive. ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | -------------- | | `T` | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ---------- | --------------------------------------------------------------------------------------------------------------------------- | | `callback` | (`session`) => `T` \| `Promise`<`T`> | | `options` | [`ResponsesWebSocketSessionOptions`](/openai-agents-js/openai/agents-openai/type-aliases/responseswebsocketsessionoptions/) | ## Returns [Section titled “Returns”](#returns) `Promise`<`T`> # @openai/agents-openai ## Classes [Section titled “Classes”](#classes) * [OpenAIChatCompletionsModel](/openai-agents-js/openai/agents-openai/classes/openaichatcompletionsmodel/) * [OpenAIConversationsSession](/openai-agents-js/openai/agents-openai/classes/openaiconversationssession/) * [OpenAIProvider](/openai-agents-js/openai/agents-openai/classes/openaiprovider/) * [OpenAIResponsesCompactionSession](/openai-agents-js/openai/agents-openai/classes/openairesponsescompactionsession/) * [OpenAIResponsesModel](/openai-agents-js/openai/agents-openai/classes/openairesponsesmodel/) * [OpenAIResponsesWSModel](/openai-agents-js/openai/agents-openai/classes/openairesponseswsmodel/) * [OpenAITracingExporter](/openai-agents-js/openai/agents-openai/classes/openaitracingexporter/) ## Type Aliases [Section titled “Type Aliases”](#type-aliases) * [OpenAIChatCompletionsModelOptions](/openai-agents-js/openai/agents-openai/type-aliases/openaichatcompletionsmodeloptions/) * [OpenAIChatCompletionsRawModelStreamEvent](/openai-agents-js/openai/agents-openai/type-aliases/openaichatcompletionsrawmodelstreamevent/) * [OpenAIConversationsSessionOptions](/openai-agents-js/openai/agents-openai/type-aliases/openaiconversationssessionoptions/) * [OpenAIProviderOptions](/openai-agents-js/openai/agents-openai/type-aliases/openaiprovideroptions/) * [OpenAIRawModelEventSource](/openai-agents-js/openai/agents-openai/type-aliases/openairawmodeleventsource/) * [OpenAIResponsesCompactionDecisionContext](/openai-agents-js/openai/agents-openai/type-aliases/openairesponsescompactiondecisioncontext/) * [OpenAIResponsesCompactionMode](/openai-agents-js/openai/agents-openai/type-aliases/openairesponsescompactionmode/) * [OpenAIResponsesCompactionSessionOptions](/openai-agents-js/openai/agents-openai/type-aliases/openairesponsescompactionsessionoptions/) * [OpenAIResponsesRawModelStreamEvent](/openai-agents-js/openai/agents-openai/type-aliases/openairesponsesrawmodelstreamevent/) * [OpenAIResponsesWebSocketOptions](/openai-agents-js/openai/agents-openai/type-aliases/openairesponseswebsocketoptions/) * [OpenAITracingExporterOptions](/openai-agents-js/openai/agents-openai/type-aliases/openaitracingexporteroptions/) * [ResponsesWebSocketSession](/openai-agents-js/openai/agents-openai/type-aliases/responseswebsocketsession/) * [ResponsesWebSocketSessionOptions](/openai-agents-js/openai/agents-openai/type-aliases/responseswebsocketsessionoptions/) * [ToolSearchTool](/openai-agents-js/openai/agents-openai/type-aliases/toolsearchtool/) ## Variables [Section titled “Variables”](#variables) * [OPENAI\_CHAT\_COMPLETIONS\_RAW\_MODEL\_EVENT\_SOURCE](/openai-agents-js/openai/agents-openai/variables/openai_chat_completions_raw_model_event_source/) * [OPENAI\_RESPONSES\_RAW\_MODEL\_EVENT\_SOURCE](/openai-agents-js/openai/agents-openai/variables/openai_responses_raw_model_event_source/) ## Functions [Section titled “Functions”](#functions) * [codeInterpreterTool](/openai-agents-js/openai/agents-openai/functions/codeinterpretertool/) * [fileSearchTool](/openai-agents-js/openai/agents-openai/functions/filesearchtool/) * [imageGenerationTool](/openai-agents-js/openai/agents-openai/functions/imagegenerationtool/) * [isOpenAIChatCompletionsRawModelStreamEvent](/openai-agents-js/openai/agents-openai/functions/isopenaichatcompletionsrawmodelstreamevent/) * [isOpenAIResponsesRawModelStreamEvent](/openai-agents-js/openai/agents-openai/functions/isopenairesponsesrawmodelstreamevent/) * [setDefaultOpenAIClient](/openai-agents-js/openai/agents-openai/functions/setdefaultopenaiclient/) * [setDefaultOpenAIKey](/openai-agents-js/openai/agents-openai/functions/setdefaultopenaikey/) * [setDefaultOpenAITracingExporter](/openai-agents-js/openai/agents-openai/functions/setdefaultopenaitracingexporter/) * [setOpenAIAPI](/openai-agents-js/openai/agents-openai/functions/setopenaiapi/) * [setOpenAIResponsesTransport](/openai-agents-js/openai/agents-openai/functions/setopenairesponsestransport/) * [setTracingExportApiKey](/openai-agents-js/openai/agents-openai/functions/settracingexportapikey/) * [startOpenAIConversationsSession](/openai-agents-js/openai/agents-openai/functions/startopenaiconversationssession/) * [toolSearchTool](/openai-agents-js/openai/agents-openai/functions/toolsearchtool/) * [webSearchTool](/openai-agents-js/openai/agents-openai/functions/websearchtool/) * [withResponsesWebSocketSession](/openai-agents-js/openai/agents-openai/functions/withresponseswebsocketsession/) # OpenAIChatCompletionsModelOptions ```ts type OpenAIChatCompletionsModelOptions = object; ``` A model that uses (or is compatible with) OpenAI’s Chat Completions API. ## Properties [Section titled “Properties”](#properties) ### strictFeatureValidation? [Section titled “strictFeatureValidation?”](#strictfeaturevalidation) ```ts optional strictFeatureValidation?: boolean; ``` When true, reject Responses-only features that Chat Completions cannot honor. Defaults to false, which preserves the previous ignore-and-warn behavior. # OpenAIChatCompletionsRawModelStreamEvent ```ts type OpenAIChatCompletionsRawModelStreamEvent = Omit & object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### data [Section titled “data”](#data) ```ts data: OpenAIRawModelEventData; ``` ### source [Section titled “source”](#source) ```ts source: typeof OPENAI_CHAT_COMPLETIONS_RAW_MODEL_EVENT_SOURCE; ``` # OpenAIConversationsSessionOptions ```ts type OpenAIConversationsSessionOptions = object; ``` ## Properties [Section titled “Properties”](#properties) ### apiKey? [Section titled “apiKey?”](#apikey) ```ts optional apiKey?: string; ``` *** ### baseURL? [Section titled “baseURL?”](#baseurl) ```ts optional baseURL?: string; ``` *** ### client? [Section titled “client?”](#client) ```ts optional client?: OpenAI; ``` *** ### conversationId? [Section titled “conversationId?”](#conversationid) ```ts optional conversationId?: string; ``` *** ### organization? [Section titled “organization?”](#organization) ```ts optional organization?: string; ``` *** ### project? [Section titled “project?”](#project) ```ts optional project?: string; ``` # OpenAIProviderOptions ```ts type OpenAIProviderOptions = object; ``` Options for OpenAIProvider. ## Properties [Section titled “Properties”](#properties) ### apiKey? [Section titled “apiKey?”](#apikey) ```ts optional apiKey?: string; ``` *** ### baseURL? [Section titled “baseURL?”](#baseurl) ```ts optional baseURL?: string; ``` *** ### cacheResponsesWebSocketModels? [Section titled “cacheResponsesWebSocketModels?”](#cacheresponseswebsocketmodels) ```ts optional cacheResponsesWebSocketModels?: boolean; ``` *** ### openAIClient? [Section titled “openAIClient?”](#openaiclient) ```ts optional openAIClient?: OpenAI; ``` *** ### organization? [Section titled “organization?”](#organization) ```ts optional organization?: string; ``` *** ### project? [Section titled “project?”](#project) ```ts optional project?: string; ``` *** ### responsesWebSocketOptions? [Section titled “responsesWebSocketOptions?”](#responseswebsocketoptions) ```ts optional responsesWebSocketOptions?: OpenAIResponsesWebSocketOptions; ``` *** ### strictFeatureValidation? [Section titled “strictFeatureValidation?”](#strictfeaturevalidation) ```ts optional strictFeatureValidation?: boolean; ``` When false, Chat Completions models warn and ignore Responses-only features such as previousResponseId, conversationId, and prompt. When true, they raise UserError instead. *** ### useResponses? [Section titled “useResponses?”](#useresponses) ```ts optional useResponses?: boolean; ``` *** ### useResponsesWebSocket? [Section titled “useResponsesWebSocket?”](#useresponseswebsocket) ```ts optional useResponsesWebSocket?: boolean; ``` *** ### websocketBaseURL? [Section titled “websocketBaseURL?”](#websocketbaseurl) ```ts optional websocketBaseURL?: string; ``` # OpenAIRawModelEventSource ```ts type OpenAIRawModelEventSource = | typeof OPENAI_RESPONSES_RAW_MODEL_EVENT_SOURCE | typeof OPENAI_CHAT_COMPLETIONS_RAW_MODEL_EVENT_SOURCE; ``` # OpenAIResponsesCompactionDecisionContext ```ts type OpenAIResponsesCompactionDecisionContext = object; ``` ## Properties [Section titled “Properties”](#properties) ### compactionCandidateItems [Section titled “compactionCandidateItems”](#compactioncandidateitems) ```ts compactionCandidateItems: AgentInputItem[]; ``` Items considered compaction candidates (excludes user and compaction items). The array must not be mutated. *** ### compactionMode [Section titled “compactionMode”](#compactionmode) ```ts compactionMode: OpenAIResponsesCompactionMode; ``` Resolved compaction mode used for this request. *** ### responseId [Section titled “responseId”](#responseid) ```ts responseId: string | undefined; ``` The `response.id` from a completed OpenAI Responses API turn, if available. When `compactionMode` is `input`, this may be undefined. *** ### sessionItems [Section titled “sessionItems”](#sessionitems) ```ts sessionItems: AgentInputItem[]; ``` All stored items retrieved from the underlying session, if available. The array must not be mutated. # OpenAIResponsesCompactionMode ```ts type OpenAIResponsesCompactionMode = "previous_response_id" | "input" | "auto"; ``` # OpenAIResponsesCompactionSessionOptions ```ts type OpenAIResponsesCompactionSessionOptions = object; ``` ## Properties [Section titled “Properties”](#properties) ### client? [Section titled “client?”](#client) ```ts optional client?: OpenAI; ``` OpenAI client used to call `responses.compact`. When omitted, the session will use `getDefaultOpenAIClient()` if configured. Otherwise it creates a new `OpenAI()` instance via `new OpenAI()`. *** ### compactionMode? [Section titled “compactionMode?”](#compactionmode) ```ts optional compactionMode?: OpenAIResponsesCompactionMode; ``` Controls how the compaction request is built. * `auto` (default): Uses `input` when the last response was not stored or no response id is available. * `previous_response_id`: Uses the server-managed response chain. * `input`: Sends the locally stored session items as input and does not require a response id. *** ### model? [Section titled “model?”](#model) ```ts optional model?: OpenAI.ResponsesModel; ``` The OpenAI model to use for `responses.compact`. Defaults to `DEFAULT_OPENAI_MODEL`. The value must resemble an OpenAI model name (for example `gpt-*`, `o*`, or a fine-tuned `ft:gpt-*` identifier), otherwise the constructor throws. *** ### shouldTriggerCompaction? [Section titled “shouldTriggerCompaction?”](#shouldtriggercompaction) ```ts optional shouldTriggerCompaction?: (context) => boolean | Promise; ``` Custom decision hook that determines whether to call `responses.compact`. The default implementation compares the length of [OpenAIResponsesCompactionDecisionContext.compactionCandidateItems](/openai-agents-js/openai/agents-openai/type-aliases/openairesponsescompactiondecisioncontext/#compactioncandidateitems) to an internal threshold (10). Override this to support token-based triggers or other heuristics using [OpenAIResponsesCompactionDecisionContext.compactionCandidateItems](/openai-agents-js/openai/agents-openai/type-aliases/openairesponsescompactiondecisioncontext/#compactioncandidateitems) or [OpenAIResponsesCompactionDecisionContext.sessionItems](/openai-agents-js/openai/agents-openai/type-aliases/openairesponsescompactiondecisioncontext/#sessionitems). #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ------------------------------------------------------------------------------------------------------------------------------------------- | | `context` | [`OpenAIResponsesCompactionDecisionContext`](/openai-agents-js/openai/agents-openai/type-aliases/openairesponsescompactiondecisioncontext/) | #### Returns [Section titled “Returns”](#returns) `boolean` | `Promise`<`boolean`> *** ### underlyingSession? [Section titled “underlyingSession?”](#underlyingsession) ```ts optional underlyingSession?: Session & object; ``` Session store that receives items and holds the compacted history. The underlying session is the source of truth for persisted items. Compaction clears the underlying session and writes the output items returned by `responses.compact`. This must not be an `OpenAIConversationsSession`, because compaction relies on locally stored items and replaces the underlying session history after `responses.compact`. Defaults to an in-memory session for demos. #### Type Declaration [Section titled “Type Declaration”](#type-declaration) | Name | Type | | ----------------------- | ------------- | | `[OPENAI_SESSION_API]?` | `"responses"` | # OpenAIResponsesRawModelStreamEvent ```ts type OpenAIResponsesRawModelStreamEvent = Omit & object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### data [Section titled “data”](#data) ```ts data: OpenAIRawModelEventData; ``` ### source [Section titled “source”](#source) ```ts source: typeof OPENAI_RESPONSES_RAW_MODEL_EVENT_SOURCE; ``` # OpenAIResponsesWebSocketOptions ```ts type OpenAIResponsesWebSocketOptions = ResponsesWebSocketKeepAliveOptions; ``` # OpenAITracingExporterOptions ```ts type OpenAITracingExporterOptions = object; ``` Options for OpenAITracingExporter. ## Properties [Section titled “Properties”](#properties) ### apiKey? [Section titled “apiKey?”](#apikey) ```ts optional apiKey?: string; ``` *** ### baseDelay [Section titled “baseDelay”](#basedelay) ```ts baseDelay: number; ``` *** ### endpoint [Section titled “endpoint”](#endpoint) ```ts endpoint: string; ``` *** ### maxDelay [Section titled “maxDelay”](#maxdelay) ```ts maxDelay: number; ``` *** ### maxRetries [Section titled “maxRetries”](#maxretries) ```ts maxRetries: number; ``` *** ### organization [Section titled “organization”](#organization) ```ts organization: string; ``` *** ### project [Section titled “project”](#project) ```ts project: string; ``` # ResponsesWebSocketSession ```ts type ResponsesWebSocketSession = object; ``` ## Properties [Section titled “Properties”](#properties) ### provider [Section titled “provider”](#provider) ```ts provider: OpenAIProvider; ``` *** ### run [Section titled “run”](#run) ```ts run: Runner["run"]; ``` *** ### runner [Section titled “runner”](#runner) ```ts runner: Runner; ``` # ResponsesWebSocketSessionOptions ```ts type ResponsesWebSocketSessionOptions = object; ``` ## Properties [Section titled “Properties”](#properties) ### providerOptions? [Section titled “providerOptions?”](#provideroptions) ```ts optional providerOptions?: OpenAIProviderOptions; ``` Options used to construct the session-scoped OpenAI provider. *** ### responsesWebSocketOptions? [Section titled “responsesWebSocketOptions?”](#responseswebsocketoptions) ```ts optional responsesWebSocketOptions?: OpenAIResponsesWebSocketOptions; ``` Low-level keepalive options for the session-scoped Responses WebSocket transport. *** ### runnerConfig? [Section titled “runnerConfig?”](#runnerconfig) ```ts optional runnerConfig?: Omit, "modelProvider">; ``` Runner configuration for the session. modelProvider is controlled by this helper. # ToolSearchTool ```ts type ToolSearchTool = object; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | ------------ | | `Context` | `unknown` | ## Properties [Section titled “Properties”](#properties) ### description? [Section titled “description?”](#description) ```ts optional description?: string | null; ``` *** ### execute? [Section titled “execute?”](#execute) ```ts optional execute?: ClientToolSearchExecutor; ``` *** ### execution? [Section titled “execution?”](#execution) ```ts optional execution?: OpenAI.Responses.ToolSearchTool["execution"]; ``` *** ### name? [Section titled “name?”](#name) ```ts optional name?: "tool_search"; ``` *** ### parameters? [Section titled “parameters?”](#parameters) ```ts optional parameters?: unknown | null; ``` *** ### type [Section titled “type”](#type) ```ts type: "tool_search"; ``` # OPENAI_CHAT_COMPLETIONS_RAW_MODEL_EVENT_SOURCE ```ts const OPENAI_CHAT_COMPLETIONS_RAW_MODEL_EVENT_SOURCE: "openai-chat-completions" = 'openai-chat-completions'; ``` # OPENAI_RESPONSES_RAW_MODEL_EVENT_SOURCE ```ts const OPENAI_RESPONSES_RAW_MODEL_EVENT_SOURCE: "openai-responses" = 'openai-responses'; ``` # ModelBehaviorError Error thrown when a model behavior is unexpected. ## Extends [Section titled “Extends”](#extends) * `AgentsError` ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new ModelBehaviorError(message, state?): ModelBehaviorError; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ---------------------------------------- | | `message` | `string` | | `state?` | `RunState`<`any`, `Agent`<`any`, `any`>> | #### Returns [Section titled “Returns”](#returns) `ModelBehaviorError` #### Inherited from [Section titled “Inherited from”](#inherited-from) ```ts AgentsError.constructor ``` ## Properties [Section titled “Properties”](#properties) ### message [Section titled “message”](#message) ```ts message: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-1) ```ts AgentsError.message ``` *** ### name [Section titled “name”](#name) ```ts name: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-2) ```ts AgentsError.name ``` *** ### stack? [Section titled “stack?”](#stack) ```ts optional stack?: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-3) ```ts AgentsError.stack ``` *** ### state? [Section titled “state?”](#state) ```ts optional state?: RunState>; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-4) ```ts AgentsError.state ``` *** ### stackTraceLimit [Section titled “stackTraceLimit”](#stacktracelimit) ```ts static stackTraceLimit: number; ``` The `Error.stackTraceLimit` property specifies the number of stack frames collected by a stack trace (whether generated by `new Error().stack` or `Error.captureStackTrace(obj)`). The default value is `10` but may be set to any valid JavaScript number. Changes will affect any stack trace captured *after* the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames. #### Inherited from [Section titled “Inherited from”](#inherited-from-5) ```ts AgentsError.stackTraceLimit ``` ## Methods [Section titled “Methods”](#methods) ### captureStackTrace() [Section titled “captureStackTrace()”](#capturestacktrace) ```ts static captureStackTrace(targetObject, constructorOpt?): void; ``` Creates a `.stack` property on `targetObject`, which when accessed returns a string representing the location in the code at which `Error.captureStackTrace()` was called. ```js const myObject = {}; Error.captureStackTrace(myObject); myObject.stack; // Similar to `new Error().stack` ``` The first line of the trace will be prefixed with `${myObject.name}: ${myObject.message}`. The optional `constructorOpt` argument accepts a function. If given, all frames above `constructorOpt`, including `constructorOpt`, will be omitted from the generated stack trace. The `constructorOpt` argument is useful for hiding implementation details of error generation from the user. For instance: ```js function a() { b(); } function b() { c(); } function c() { // Create an error without stack trace to avoid calculating the stack trace twice. const { stackTraceLimit } = Error; Error.stackTraceLimit = 0; const error = new Error(); Error.stackTraceLimit = stackTraceLimit; // Capture the stack trace above function b Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace throw error; } a(); ``` #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | ----------------- | ---------- | | `targetObject` | `object` | | `constructorOpt?` | `Function` | #### Returns [Section titled “Returns”](#returns-1) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-6) ```ts AgentsError.captureStackTrace ``` *** ### prepareStackTrace() [Section titled “prepareStackTrace()”](#preparestacktrace) ```ts static prepareStackTrace(err, stackTraces): any; ``` #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | ------------- | ------------- | | `err` | `Error` | | `stackTraces` | `CallSite`\[] | #### Returns [Section titled “Returns”](#returns-2) `any` #### See [Section titled “See”](#see) #### Inherited from [Section titled “Inherited from”](#inherited-from-7) ```ts AgentsError.prepareStackTrace ``` # OpenAIRealtimeBase The transport layer is the layer that handles the connection to the model and the communication with the model. ## Extends [Section titled “Extends”](#extends) * `EventEmitterDelegate`<[`OpenAIRealtimeEventTypes`](/openai-agents-js/openai/agents-realtime/type-aliases/openairealtimeeventtypes/)> ## Extended by [Section titled “Extended by”](#extended-by) * [`OpenAIRealtimeWebRTC`](/openai-agents-js/openai/agents-realtime/classes/openairealtimewebrtc/) * [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents-realtime/classes/openairealtimewebsocket/) ## Implements [Section titled “Implements”](#implements) * [`RealtimeTransportLayer`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/) ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new OpenAIRealtimeBase(options?): OpenAIRealtimeBase; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | --------------------------------------------------------------------------------------------------------------- | | `options` | [`OpenAIRealtimeBaseOptions`](/openai-agents-js/openai/agents-realtime/type-aliases/openairealtimebaseoptions/) | #### Returns [Section titled “Returns”](#returns) `OpenAIRealtimeBase` #### Overrides [Section titled “Overrides”](#overrides) ```ts EventEmitterDelegate.constructor ``` ## Properties [Section titled “Properties”](#properties) ### muted [Section titled “muted”](#muted) ```ts abstract readonly muted: boolean | null; ``` Whether the input audio track is currently muted null if the muting is not handled by the transport layer #### Implementation of [Section titled “Implementation of”](#implementation-of) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/).[`muted`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/#muted) ## Accessors [Section titled “Accessors”](#accessors) ### \_tracingConfig [Section titled “\_tracingConfig”](#_tracingconfig) #### Set Signature [Section titled “Set Signature”](#set-signature) ```ts set _tracingConfig(tracingConfig): void; ``` Sets the internal tracing config. This is used to track the tracing config that has been set during the session.create event. ##### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | --------------- | --------------------------------- | | `tracingConfig` | `RealtimeTracingConfig` \| `null` | ##### Returns [Section titled “Returns”](#returns-1) `void` *** ### currentModel [Section titled “currentModel”](#currentmodel) #### Get Signature [Section titled “Get Signature”](#get-signature) ```ts get currentModel(): OpenAIRealtimeModels; ``` The current model that is being used by the transport layer. ##### Returns [Section titled “Returns”](#returns-2) [`OpenAIRealtimeModels`](/openai-agents-js/openai/agents-realtime/type-aliases/openairealtimemodels/) #### Set Signature [Section titled “Set Signature”](#set-signature-1) ```ts set currentModel(model): void; ``` The current model that is being used by the transport layer. **Note**: The model cannot be changed mid conversation. ##### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | --------- | ----------------------------------------------------------------------------------------------------- | | `model` | [`OpenAIRealtimeModels`](/openai-agents-js/openai/agents-realtime/type-aliases/openairealtimemodels/) | ##### Returns [Section titled “Returns”](#returns-3) `void` *** ### status [Section titled “status”](#status) #### Get Signature [Section titled “Get Signature”](#get-signature-1) ```ts get abstract status(): "connecting" | "connected" | "disconnected" | "disconnecting"; ``` ##### Returns [Section titled “Returns”](#returns-4) `"connecting"` | `"connected"` | `"disconnected"` | `"disconnecting"` #### Implementation of [Section titled “Implementation of”](#implementation-of-1) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/).[`status`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/#status) ## Methods [Section titled “Methods”](#methods) ### addImage() [Section titled “addImage()”](#addimage) ```ts addImage(image, options?): void; ``` Sends an image to the model #### Parameters [Section titled “Parameters”](#parameters-3) | Parameter | Type | Description | | -------------------------- | ---------------------------------- | -------------------------------------------- | | `image` | `string` | The image to send | | `options` | { `triggerResponse?`: `boolean`; } | Additional options | | `options.triggerResponse?` | `boolean` | Whether to trigger a response from the model | #### Returns [Section titled “Returns”](#returns-5) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-2) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/).[`addImage`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/#addimage) *** ### buildSessionPayload() [Section titled “buildSessionPayload()”](#buildsessionpayload) ```ts buildSessionPayload(config): RealtimeSessionPayload; ``` Build the payload object expected by the Realtime API when creating or updating a session. The helper centralises the conversion from camelCase runtime config to the snake\_case payload required by the Realtime API so transports that need a one-off payload (for example SIP call acceptance) can reuse the same logic without duplicating private state. #### Parameters [Section titled “Parameters”](#parameters-4) | Parameter | Type | Description | | --------- | ------------------------------------------------------------------------------------------------------------------ | ------------------------------------------ | | `config` | `Partial`<[`RealtimeSessionConfig`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimesessionconfig/)> | The session config to merge with defaults. | #### Returns [Section titled “Returns”](#returns-6) [`RealtimeSessionPayload`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimesessionpayload/) *** ### close() [Section titled “close()”](#close) ```ts abstract close(): void; ``` Closes the connection to the model #### Returns [Section titled “Returns”](#returns-7) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-3) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/).[`close`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/#close) *** ### connect() [Section titled “connect()”](#connect) ```ts abstract connect(options): Promise; ``` Establishes the connection to the model and keeps the connection alive #### Parameters [Section titled “Parameters”](#parameters-5) | Parameter | Type | Description | | --------- | ------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------ | | `options` | [`RealtimeTransportLayerConnectOptions`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimetransportlayerconnectoptions/) | The options for the connection | #### Returns [Section titled “Returns”](#returns-8) `Promise`<`void`> #### Implementation of [Section titled “Implementation of”](#implementation-of-4) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/).[`connect`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/#connect) *** ### emit() [Section titled “emit()”](#emit) ```ts emit(type, ...args): boolean; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | --------------------------------------------------------------------------------------------------------------------------------------- | | `K` *extends* keyof [`RealtimeTransportEventTypes`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimetransporteventtypes/) | #### Parameters [Section titled “Parameters”](#parameters-6) | Parameter | Type | | --------- | ------------------------------------------------------------------------------------------------------------------- | | `type` | `K` | | …`args` | [`OpenAIRealtimeEventTypes`](/openai-agents-js/openai/agents-realtime/type-aliases/openairealtimeeventtypes/)\[`K`] | #### Returns [Section titled “Returns”](#returns-9) `boolean` #### Implementation of [Section titled “Implementation of”](#implementation-of-5) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/).[`emit`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/#emit) #### Inherited from [Section titled “Inherited from”](#inherited-from) ```ts EventEmitterDelegate.emit ``` *** ### interrupt() [Section titled “interrupt()”](#interrupt) ```ts abstract interrupt(): void; ``` Interrupts the current turn. Used for example when a guardrail is triggered #### Returns [Section titled “Returns”](#returns-10) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-6) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/).[`interrupt`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/#interrupt) *** ### mute() [Section titled “mute()”](#mute) ```ts abstract mute(muted): void; ``` Mutes the input audio track #### Parameters [Section titled “Parameters”](#parameters-7) | Parameter | Type | Description | | --------- | --------- | ------------------------------------- | | `muted` | `boolean` | Whether to mute the input audio track | #### Returns [Section titled “Returns”](#returns-11) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-7) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/).[`mute`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/#mute) *** ### off() [Section titled “off()”](#off) ```ts off(type, listener): EventEmitter; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-1) | Type Parameter | | --------------------------------------------------------------------------------------------------------------------------------------- | | `K` *extends* keyof [`RealtimeTransportEventTypes`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimetransporteventtypes/) | #### Parameters [Section titled “Parameters”](#parameters-8) | Parameter | Type | | ---------- | ------------------- | | `type` | `K` | | `listener` | (…`args`) => `void` | #### Returns [Section titled “Returns”](#returns-12) `EventEmitter`<`EventTypes`> #### Implementation of [Section titled “Implementation of”](#implementation-of-8) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/).[`off`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/#off) #### Inherited from [Section titled “Inherited from”](#inherited-from-1) ```ts EventEmitterDelegate.off ``` *** ### on() [Section titled “on()”](#on) ```ts on(type, listener): EventEmitter; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-2) | Type Parameter | | --------------------------------------------------------------------------------------------------------------------------------------- | | `K` *extends* keyof [`RealtimeTransportEventTypes`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimetransporteventtypes/) | #### Parameters [Section titled “Parameters”](#parameters-9) | Parameter | Type | | ---------- | ------------------- | | `type` | `K` | | `listener` | (…`args`) => `void` | #### Returns [Section titled “Returns”](#returns-13) `EventEmitter`<`EventTypes`> #### Implementation of [Section titled “Implementation of”](#implementation-of-9) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/).[`on`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/#on) #### Inherited from [Section titled “Inherited from”](#inherited-from-2) ```ts EventEmitterDelegate.on ``` *** ### once() [Section titled “once()”](#once) ```ts once(type, listener): EventEmitter; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-3) | Type Parameter | | --------------------------------------------------------------------------------------------------------------------------------------- | | `K` *extends* keyof [`RealtimeTransportEventTypes`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimetransporteventtypes/) | #### Parameters [Section titled “Parameters”](#parameters-10) | Parameter | Type | | ---------- | ------------------- | | `type` | `K` | | `listener` | (…`args`) => `void` | #### Returns [Section titled “Returns”](#returns-14) `EventEmitter`<`EventTypes`> #### Implementation of [Section titled “Implementation of”](#implementation-of-10) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/).[`once`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/#once) #### Inherited from [Section titled “Inherited from”](#inherited-from-3) ```ts EventEmitterDelegate.once ``` *** ### requestResponse() [Section titled “requestResponse()”](#requestresponse) ```ts requestResponse(response?): void; ``` Requests a new response for the current conversation turn. Implementations may defer the underlying `response.create` until the server has fully finished the prior response. #### Parameters [Section titled “Parameters”](#parameters-11) | Parameter | Type | Description | | ----------- | ------------------------- | ------------------------------------------- | | `response?` | `Record`<`string`, `any`> | Optional one-off response override payload. | #### Returns [Section titled “Returns”](#returns-15) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-11) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/).[`requestResponse`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/#requestresponse) *** ### resetHistory() [Section titled “resetHistory()”](#resethistory) ```ts resetHistory(oldHistory, newHistory): void; ``` Reset the history of the conversation. This will create a diff between the old and new history and send the necessary events to the Realtime API to update the history. #### Parameters [Section titled “Parameters”](#parameters-12) | Parameter | Type | Description | | ------------ | ---------------------------------------------------------------------------------------- | ------------------------------------ | | `oldHistory` | [`RealtimeItem`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimeitem/)\[] | The old history of the conversation. | | `newHistory` | [`RealtimeItem`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimeitem/)\[] | The new history of the conversation. | #### Returns [Section titled “Returns”](#returns-16) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-12) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/).[`resetHistory`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/#resethistory) *** ### sendAudio() [Section titled “sendAudio()”](#sendaudio) ```ts sendAudio(audio, options?): void; ``` Send an audio buffer to the Realtime API. If `{ commit: true }` is passed, the audio buffer will be committed and the model will start processing it. This is necessary if you have disabled turn detection / voice activity detection (VAD). #### Parameters [Section titled “Parameters”](#parameters-13) | Parameter | Type | Description | | ----------------- | ------------------------- | --------------------------------- | | `audio` | `ArrayBuffer` | The audio buffer to send. | | `options` | { `commit?`: `boolean`; } | The options for the audio buffer. | | `options.commit?` | `boolean` | ‐ | #### Returns [Section titled “Returns”](#returns-17) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-13) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/).[`sendAudio`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/#sendaudio) *** ### sendEvent() [Section titled “sendEvent()”](#sendevent) ```ts abstract sendEvent(event): void; ``` Sends a raw event to the model #### Parameters [Section titled “Parameters”](#parameters-14) | Parameter | Type | Description | | --------- | ------------------------------------------------------------------------------------------------------- | ----------------- | | `event` | [`RealtimeClientMessage`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimeclientmessage/) | The event to send | #### Returns [Section titled “Returns”](#returns-18) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-14) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/).[`sendEvent`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/#sendevent) *** ### sendFunctionCallOutput() [Section titled “sendFunctionCallOutput()”](#sendfunctioncalloutput) ```ts sendFunctionCallOutput( toolCall, output, startResponse?): void; ``` Send the output of a function call to the Realtime API. #### Parameters [Section titled “Parameters”](#parameters-15) | Parameter | Type | Default value | Description | | --------------- | --------------------------------------------------------------------------------------------------------- | ------------- | --------------------------------------------------------- | | `toolCall` | [`TransportToolCallEvent`](/openai-agents-js/openai/agents-realtime/type-aliases/transporttoolcallevent/) | `undefined` | The tool call to send the output for. | | `output` | `string` | `undefined` | The output of the function call. | | `startResponse` | `boolean` | `true` | Whether to start a new response after sending the output. | #### Returns [Section titled “Returns”](#returns-19) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-15) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/).[`sendFunctionCallOutput`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/#sendfunctioncalloutput) *** ### sendMcpResponse() [Section titled “sendMcpResponse()”](#sendmcpresponse) ```ts sendMcpResponse( approvalRequest, approved, reason?): void; ``` Sends a response for an MCP tool call #### Parameters [Section titled “Parameters”](#parameters-16) | Parameter | Type | Description | | ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------- | | `approvalRequest` | { `approved?`: `boolean` \| `null`; `arguments`: `Record`<`string`, `any`>; `itemId`: `string`; `name`: `string`; `serverLabel`: `string`; `type`: `"mcp_approval_request"`; } | The approval request to respond to | | `approvalRequest.approved?` | `boolean` \| `null` | ‐ | | `approvalRequest.arguments` | `Record`<`string`, `any`> | ‐ | | `approvalRequest.itemId?` | `string` | ‐ | | `approvalRequest.name?` | `string` | ‐ | | `approvalRequest.serverLabel?` | `string` | ‐ | | `approvalRequest.type?` | `"mcp_approval_request"` | ‐ | | `approved?` | `boolean` | Whether the tool call was approved or rejected | | `reason?` | `string` | Optional rejection text for the provider/model. | #### Returns [Section titled “Returns”](#returns-20) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-16) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/).[`sendMcpResponse`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/#sendmcpresponse) *** ### sendMessage() [Section titled “sendMessage()”](#sendmessage) ```ts sendMessage( message, otherEventData, __namedParameters?): void; ``` Send a message to the Realtime API. This will create a new item in the conversation and trigger a response. #### Parameters [Section titled “Parameters”](#parameters-17) | Parameter | Type | Description | | ------------------------------------ | ---------------------------------- | ------------------------------ | | `message` | `RealtimeUserInput` | The message to send. | | `otherEventData` | `Record`<`string`, `any`> | Additional event data to send. | | `__namedParameters` | { `triggerResponse?`: `boolean`; } | ‐ | | `__namedParameters.triggerResponse?` | `boolean` | ‐ | #### Returns [Section titled “Returns”](#returns-21) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-17) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/).[`sendMessage`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/#sendmessage) *** ### updateSessionConfig() [Section titled “updateSessionConfig()”](#updatesessionconfig) ```ts updateSessionConfig(config): void; ``` Updates the session config. This will merge it with the current session config with the default values and send it to the Realtime API. #### Parameters [Section titled “Parameters”](#parameters-18) | Parameter | Type | Description | | --------- | ------------------------------------------------------------------------------------------------------------------ | ----------------------------- | | `config` | `Partial`<[`RealtimeSessionConfig`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimesessionconfig/)> | The session config to update. | #### Returns [Section titled “Returns”](#returns-22) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-18) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/).[`updateSessionConfig`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/#updatesessionconfig) # OpenAIRealtimeSIP Transport layer that connects to an existing SIP-initiated Realtime call via call ID. ## Extends [Section titled “Extends”](#extends) * [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents-realtime/classes/openairealtimewebsocket/) ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new OpenAIRealtimeSIP(options?): OpenAIRealtimeSIP; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ------------------------------------------------------------------------------------------------------------------------- | | `options` | [`OpenAIRealtimeWebSocketOptions`](/openai-agents-js/openai/agents-realtime/type-aliases/openairealtimewebsocketoptions/) | #### Returns [Section titled “Returns”](#returns) `OpenAIRealtimeSIP` #### Overrides [Section titled “Overrides”](#overrides) [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents-realtime/classes/openairealtimewebsocket/).[`constructor`](/openai-agents-js/openai/agents-realtime/classes/openairealtimewebsocket/#constructor) ## Accessors [Section titled “Accessors”](#accessors) ### \_tracingConfig [Section titled “\_tracingConfig”](#_tracingconfig) #### Set Signature [Section titled “Set Signature”](#set-signature) ```ts set _tracingConfig(tracingConfig): void; ``` Sets the internal tracing config. This is used to track the tracing config that has been set during the session.create event. ##### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | --------------- | --------------------------------- | | `tracingConfig` | `RealtimeTracingConfig` \| `null` | ##### Returns [Section titled “Returns”](#returns-1) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from) [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents-realtime/classes/openairealtimewebsocket/).[`_tracingConfig`](/openai-agents-js/openai/agents-realtime/classes/openairealtimewebsocket/#_tracingconfig) *** ### connectionState [Section titled “connectionState”](#connectionstate) #### Get Signature [Section titled “Get Signature”](#get-signature) ```ts get connectionState(): WebSocketState; ``` The current connection state of the WebSocket connection. ##### Returns [Section titled “Returns”](#returns-2) [`WebSocketState`](/openai-agents-js/openai/agents-realtime/type-aliases/websocketstate/) #### Inherited from [Section titled “Inherited from”](#inherited-from-1) [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents-realtime/classes/openairealtimewebsocket/).[`connectionState`](/openai-agents-js/openai/agents-realtime/classes/openairealtimewebsocket/#connectionstate) *** ### currentModel [Section titled “currentModel”](#currentmodel) #### Get Signature [Section titled “Get Signature”](#get-signature-1) ```ts get currentModel(): OpenAIRealtimeModels; ``` The current model that is being used by the transport layer. ##### Returns [Section titled “Returns”](#returns-3) [`OpenAIRealtimeModels`](/openai-agents-js/openai/agents-realtime/type-aliases/openairealtimemodels/) #### Set Signature [Section titled “Set Signature”](#set-signature-1) ```ts set currentModel(model): void; ``` The current model that is being used by the transport layer. **Note**: The model cannot be changed mid conversation. ##### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | --------- | ----------------------------------------------------------------------------------------------------- | | `model` | [`OpenAIRealtimeModels`](/openai-agents-js/openai/agents-realtime/type-aliases/openairealtimemodels/) | ##### Returns [Section titled “Returns”](#returns-4) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-2) [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents-realtime/classes/openairealtimewebsocket/).[`currentModel`](/openai-agents-js/openai/agents-realtime/classes/openairealtimewebsocket/#currentmodel) *** ### muted [Section titled “muted”](#muted) #### Get Signature [Section titled “Get Signature”](#get-signature-2) ```ts get muted(): null; ``` Always returns `null` as the WebSocket transport layer does not handle muting. Instead, this should be handled by the client by not triggering the `sendAudio` method. ##### Returns [Section titled “Returns”](#returns-5) `null` Whether the input audio track is currently muted null if the muting is not handled by the transport layer #### Inherited from [Section titled “Inherited from”](#inherited-from-3) [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents-realtime/classes/openairealtimewebsocket/).[`muted`](/openai-agents-js/openai/agents-realtime/classes/openairealtimewebsocket/#muted) *** ### status [Section titled “status”](#status) #### Get Signature [Section titled “Get Signature”](#get-signature-3) ```ts get status(): "connecting" | "connected" | "disconnected"; ``` The current status of the WebSocket connection. ##### Returns [Section titled “Returns”](#returns-6) `"connecting"` | `"connected"` | `"disconnected"` #### Inherited from [Section titled “Inherited from”](#inherited-from-4) [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents-realtime/classes/openairealtimewebsocket/).[`status`](/openai-agents-js/openai/agents-realtime/classes/openairealtimewebsocket/#status) ## Methods [Section titled “Methods”](#methods) ### \_cancelResponse() [Section titled “\_cancelResponse()”](#_cancelresponse) ```ts _cancelResponse(): void; ``` Send a cancel response event to the Realtime API. This is used to cancel an ongoing response that the model is currently generating. #### Returns [Section titled “Returns”](#returns-7) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-5) [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents-realtime/classes/openairealtimewebsocket/).[`_cancelResponse`](/openai-agents-js/openai/agents-realtime/classes/openairealtimewebsocket/#_cancelresponse) *** ### \_interrupt() [Section titled “\_interrupt()”](#_interrupt) ```ts _interrupt(elapsedTime, cancelOngoingResponse?): void; ``` Do NOT call this method directly. Call `interrupt()` instead for proper interruption handling. This method is used to send the right events to the API to inform the model that the user has interrupted the response. It might be overridden/extended by an extended transport layer. See the `TwilioRealtimeTransportLayer` for an example. #### Parameters [Section titled “Parameters”](#parameters-3) | Parameter | Type | Default value | Description | | ----------------------- | --------- | ------------- | -------------------------------------------- | | `elapsedTime` | `number` | `undefined` | The elapsed time since the response started. | | `cancelOngoingResponse` | `boolean` | `true` | ‐ | #### Returns [Section titled “Returns”](#returns-8) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-6) [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents-realtime/classes/openairealtimewebsocket/).[`_interrupt`](/openai-agents-js/openai/agents-realtime/classes/openairealtimewebsocket/#_interrupt) *** ### addImage() [Section titled “addImage()”](#addimage) ```ts addImage(image, options?): void; ``` Sends an image to the model #### Parameters [Section titled “Parameters”](#parameters-4) | Parameter | Type | Description | | -------------------------- | ---------------------------------- | -------------------------------------------- | | `image` | `string` | The image to send | | `options` | { `triggerResponse?`: `boolean`; } | Additional options | | `options.triggerResponse?` | `boolean` | Whether to trigger a response from the model | #### Returns [Section titled “Returns”](#returns-9) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-7) [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents-realtime/classes/openairealtimewebsocket/).[`addImage`](/openai-agents-js/openai/agents-realtime/classes/openairealtimewebsocket/#addimage) *** ### buildSessionPayload() [Section titled “buildSessionPayload()”](#buildsessionpayload) ```ts buildSessionPayload(config): RealtimeSessionPayload; ``` Build the payload object expected by the Realtime API when creating or updating a session. The helper centralises the conversion from camelCase runtime config to the snake\_case payload required by the Realtime API so transports that need a one-off payload (for example SIP call acceptance) can reuse the same logic without duplicating private state. #### Parameters [Section titled “Parameters”](#parameters-5) | Parameter | Type | Description | | --------- | ------------------------------------------------------------------------------------------------------------------ | ------------------------------------------ | | `config` | `Partial`<[`RealtimeSessionConfig`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimesessionconfig/)> | The session config to merge with defaults. | #### Returns [Section titled “Returns”](#returns-10) [`RealtimeSessionPayload`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimesessionpayload/) #### Inherited from [Section titled “Inherited from”](#inherited-from-8) [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents-realtime/classes/openairealtimewebsocket/).[`buildSessionPayload`](/openai-agents-js/openai/agents-realtime/classes/openairealtimewebsocket/#buildsessionpayload) *** ### close() [Section titled “close()”](#close) ```ts close(): void; ``` Close the WebSocket connection. This will also reset any internal connection tracking used for interruption handling. #### Returns [Section titled “Returns”](#returns-11) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-9) [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents-realtime/classes/openairealtimewebsocket/).[`close`](/openai-agents-js/openai/agents-realtime/classes/openairealtimewebsocket/#close) *** ### connect() [Section titled “connect()”](#connect) ```ts connect(options): Promise; ``` Establishes the connection to the model and keeps the connection alive #### Parameters [Section titled “Parameters”](#parameters-6) | Parameter | Type | Description | | --------- | ------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------ | | `options` | [`RealtimeTransportLayerConnectOptions`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimetransportlayerconnectoptions/) | The options for the connection | #### Returns [Section titled “Returns”](#returns-12) `Promise`<`void`> #### Overrides [Section titled “Overrides”](#overrides-1) [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents-realtime/classes/openairealtimewebsocket/).[`connect`](/openai-agents-js/openai/agents-realtime/classes/openairealtimewebsocket/#connect) *** ### emit() [Section titled “emit()”](#emit) ```ts emit(type, ...args): boolean; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | --------------------------------------------------------------------------------------------------------------------------------------- | | `K` *extends* keyof [`RealtimeTransportEventTypes`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimetransporteventtypes/) | #### Parameters [Section titled “Parameters”](#parameters-7) | Parameter | Type | | --------- | ------------------------------------------------------------------------------------------------------------------- | | `type` | `K` | | …`args` | [`OpenAIRealtimeEventTypes`](/openai-agents-js/openai/agents-realtime/type-aliases/openairealtimeeventtypes/)\[`K`] | #### Returns [Section titled “Returns”](#returns-13) `boolean` #### Inherited from [Section titled “Inherited from”](#inherited-from-10) [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents-realtime/classes/openairealtimewebsocket/).[`emit`](/openai-agents-js/openai/agents-realtime/classes/openairealtimewebsocket/#emit) *** ### interrupt() [Section titled “interrupt()”](#interrupt) ```ts interrupt(cancelOngoingResponse?): void; ``` Interrupt the ongoing response. This method is triggered automatically by the client when voice activity detection (VAD) is enabled (default) as well as when an output guardrail got triggered. You can also call this method directly if you want to interrupt the conversation for example based on an event in the client. #### Parameters [Section titled “Parameters”](#parameters-8) | Parameter | Type | Default value | | ----------------------- | --------- | ------------- | | `cancelOngoingResponse` | `boolean` | `true` | #### Returns [Section titled “Returns”](#returns-14) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-11) [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents-realtime/classes/openairealtimewebsocket/).[`interrupt`](/openai-agents-js/openai/agents-realtime/classes/openairealtimewebsocket/#interrupt) *** ### mute() [Section titled “mute()”](#mute) ```ts mute(_muted): never; ``` Will throw an error as the WebSocket transport layer does not support muting. #### Parameters [Section titled “Parameters”](#parameters-9) | Parameter | Type | | --------- | --------- | | `_muted` | `boolean` | #### Returns [Section titled “Returns”](#returns-15) `never` #### Inherited from [Section titled “Inherited from”](#inherited-from-12) [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents-realtime/classes/openairealtimewebsocket/).[`mute`](/openai-agents-js/openai/agents-realtime/classes/openairealtimewebsocket/#mute) *** ### off() [Section titled “off()”](#off) ```ts off(type, listener): EventEmitter; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-1) | Type Parameter | | --------------------------------------------------------------------------------------------------------------------------------------- | | `K` *extends* keyof [`RealtimeTransportEventTypes`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimetransporteventtypes/) | #### Parameters [Section titled “Parameters”](#parameters-10) | Parameter | Type | | ---------- | ------------------- | | `type` | `K` | | `listener` | (…`args`) => `void` | #### Returns [Section titled “Returns”](#returns-16) `EventEmitter`<`EventTypes`> #### Inherited from [Section titled “Inherited from”](#inherited-from-13) [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents-realtime/classes/openairealtimewebsocket/).[`off`](/openai-agents-js/openai/agents-realtime/classes/openairealtimewebsocket/#off) *** ### on() [Section titled “on()”](#on) ```ts on(type, listener): EventEmitter; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-2) | Type Parameter | | --------------------------------------------------------------------------------------------------------------------------------------- | | `K` *extends* keyof [`RealtimeTransportEventTypes`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimetransporteventtypes/) | #### Parameters [Section titled “Parameters”](#parameters-11) | Parameter | Type | | ---------- | ------------------- | | `type` | `K` | | `listener` | (…`args`) => `void` | #### Returns [Section titled “Returns”](#returns-17) `EventEmitter`<`EventTypes`> #### Inherited from [Section titled “Inherited from”](#inherited-from-14) [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents-realtime/classes/openairealtimewebsocket/).[`on`](/openai-agents-js/openai/agents-realtime/classes/openairealtimewebsocket/#on) *** ### once() [Section titled “once()”](#once) ```ts once(type, listener): EventEmitter; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-3) | Type Parameter | | --------------------------------------------------------------------------------------------------------------------------------------- | | `K` *extends* keyof [`RealtimeTransportEventTypes`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimetransporteventtypes/) | #### Parameters [Section titled “Parameters”](#parameters-12) | Parameter | Type | | ---------- | ------------------- | | `type` | `K` | | `listener` | (…`args`) => `void` | #### Returns [Section titled “Returns”](#returns-18) `EventEmitter`<`EventTypes`> #### Inherited from [Section titled “Inherited from”](#inherited-from-15) [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents-realtime/classes/openairealtimewebsocket/).[`once`](/openai-agents-js/openai/agents-realtime/classes/openairealtimewebsocket/#once) *** ### requestResponse() [Section titled “requestResponse()”](#requestresponse) ```ts requestResponse(response?): void; ``` Requests a new response for the current conversation turn. Implementations may defer the underlying `response.create` until the server has fully finished the prior response. #### Parameters [Section titled “Parameters”](#parameters-13) | Parameter | Type | Description | | ----------- | ------------------------- | ------------------------------------------- | | `response?` | `Record`<`string`, `any`> | Optional one-off response override payload. | #### Returns [Section titled “Returns”](#returns-19) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-16) [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents-realtime/classes/openairealtimewebsocket/).[`requestResponse`](/openai-agents-js/openai/agents-realtime/classes/openairealtimewebsocket/#requestresponse) *** ### resetHistory() [Section titled “resetHistory()”](#resethistory) ```ts resetHistory(oldHistory, newHistory): void; ``` Reset the history of the conversation. This will create a diff between the old and new history and send the necessary events to the Realtime API to update the history. #### Parameters [Section titled “Parameters”](#parameters-14) | Parameter | Type | Description | | ------------ | ---------------------------------------------------------------------------------------- | ------------------------------------ | | `oldHistory` | [`RealtimeItem`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimeitem/)\[] | The old history of the conversation. | | `newHistory` | [`RealtimeItem`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimeitem/)\[] | The new history of the conversation. | #### Returns [Section titled “Returns”](#returns-20) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-17) [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents-realtime/classes/openairealtimewebsocket/).[`resetHistory`](/openai-agents-js/openai/agents-realtime/classes/openairealtimewebsocket/#resethistory) *** ### sendAudio() [Section titled “sendAudio()”](#sendaudio) ```ts sendAudio(_audio, _options?): never; ``` Send an audio buffer to the Realtime API. This is used for your client to send audio to the model to respond. #### Parameters [Section titled “Parameters”](#parameters-15) | Parameter | Type | | ------------------ | ------------------------- | | `_audio` | `ArrayBuffer` | | `_options` | { `commit?`: `boolean`; } | | `_options.commit?` | `boolean` | #### Returns [Section titled “Returns”](#returns-21) `never` #### Overrides [Section titled “Overrides”](#overrides-2) [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents-realtime/classes/openairealtimewebsocket/).[`sendAudio`](/openai-agents-js/openai/agents-realtime/classes/openairealtimewebsocket/#sendaudio) *** ### sendEvent() [Section titled “sendEvent()”](#sendevent) ```ts sendEvent(event): void; ``` Send an event to the Realtime API. This will stringify the event and send it directly to the API. This can be used if you want to take control over the connection and send events manually. #### Parameters [Section titled “Parameters”](#parameters-16) | Parameter | Type | Description | | --------- | ------------------------------------------------------------------------------------------------------- | ------------------ | | `event` | [`RealtimeClientMessage`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimeclientmessage/) | The event to send. | #### Returns [Section titled “Returns”](#returns-22) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-18) [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents-realtime/classes/openairealtimewebsocket/).[`sendEvent`](/openai-agents-js/openai/agents-realtime/classes/openairealtimewebsocket/#sendevent) *** ### sendFunctionCallOutput() [Section titled “sendFunctionCallOutput()”](#sendfunctioncalloutput) ```ts sendFunctionCallOutput( toolCall, output, startResponse?): void; ``` Send the output of a function call to the Realtime API. #### Parameters [Section titled “Parameters”](#parameters-17) | Parameter | Type | Default value | Description | | --------------- | --------------------------------------------------------------------------------------------------------- | ------------- | --------------------------------------------------------- | | `toolCall` | [`TransportToolCallEvent`](/openai-agents-js/openai/agents-realtime/type-aliases/transporttoolcallevent/) | `undefined` | The tool call to send the output for. | | `output` | `string` | `undefined` | The output of the function call. | | `startResponse` | `boolean` | `true` | Whether to start a new response after sending the output. | #### Returns [Section titled “Returns”](#returns-23) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-19) [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents-realtime/classes/openairealtimewebsocket/).[`sendFunctionCallOutput`](/openai-agents-js/openai/agents-realtime/classes/openairealtimewebsocket/#sendfunctioncalloutput) *** ### sendMcpResponse() [Section titled “sendMcpResponse()”](#sendmcpresponse) ```ts sendMcpResponse( approvalRequest, approved, reason?): void; ``` Sends a response for an MCP tool call #### Parameters [Section titled “Parameters”](#parameters-18) | Parameter | Type | Description | | ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------- | | `approvalRequest` | { `approved?`: `boolean` \| `null`; `arguments`: `Record`<`string`, `any`>; `itemId`: `string`; `name`: `string`; `serverLabel`: `string`; `type`: `"mcp_approval_request"`; } | The approval request to respond to | | `approvalRequest.approved?` | `boolean` \| `null` | ‐ | | `approvalRequest.arguments` | `Record`<`string`, `any`> | ‐ | | `approvalRequest.itemId?` | `string` | ‐ | | `approvalRequest.name?` | `string` | ‐ | | `approvalRequest.serverLabel?` | `string` | ‐ | | `approvalRequest.type?` | `"mcp_approval_request"` | ‐ | | `approved?` | `boolean` | Whether the tool call was approved or rejected | | `reason?` | `string` | Optional rejection text for the provider/model. | #### Returns [Section titled “Returns”](#returns-24) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-20) [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents-realtime/classes/openairealtimewebsocket/).[`sendMcpResponse`](/openai-agents-js/openai/agents-realtime/classes/openairealtimewebsocket/#sendmcpresponse) *** ### sendMessage() [Section titled “sendMessage()”](#sendmessage) ```ts sendMessage( message, otherEventData, __namedParameters?): void; ``` Send a message to the Realtime API. This will create a new item in the conversation and trigger a response. #### Parameters [Section titled “Parameters”](#parameters-19) | Parameter | Type | Description | | ------------------------------------ | ---------------------------------- | ------------------------------ | | `message` | `RealtimeUserInput` | The message to send. | | `otherEventData` | `Record`<`string`, `any`> | Additional event data to send. | | `__namedParameters` | { `triggerResponse?`: `boolean`; } | ‐ | | `__namedParameters.triggerResponse?` | `boolean` | ‐ | #### Returns [Section titled “Returns”](#returns-25) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-21) [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents-realtime/classes/openairealtimewebsocket/).[`sendMessage`](/openai-agents-js/openai/agents-realtime/classes/openairealtimewebsocket/#sendmessage) *** ### updateSessionConfig() [Section titled “updateSessionConfig()”](#updatesessionconfig) ```ts updateSessionConfig(config): void; ``` Updates the session config. This will merge it with the current session config with the default values and send it to the Realtime API. #### Parameters [Section titled “Parameters”](#parameters-20) | Parameter | Type | Description | | --------- | ------------------------------------------------------------------------------------------------------------------ | ----------------------------- | | `config` | `Partial`<[`RealtimeSessionConfig`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimesessionconfig/)> | The session config to update. | #### Returns [Section titled “Returns”](#returns-26) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-22) [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents-realtime/classes/openairealtimewebsocket/).[`updateSessionConfig`](/openai-agents-js/openai/agents-realtime/classes/openairealtimewebsocket/#updatesessionconfig) *** ### buildInitialConfig() [Section titled “buildInitialConfig()”](#buildinitialconfig) ```ts static buildInitialConfig( agent, options?, overrides?): Promise; ``` Build the initial session payload for a SIP-attached session, matching the config that a RealtimeSession would send on connect. This enables SIP deployments to accept an incoming call with a payload that already reflects the active agent’s instructions, tools, prompt, and tracing metadata without duplicating the session logic outside of the SDK. The returned object structurally matches the REST `CallAcceptParams` interface, so it can be forwarded directly to `openai.realtime.calls.accept(...)`. #### Type Parameters [Section titled “Type Parameters”](#type-parameters-4) | Type Parameter | Default type | | -------------- | ------------ | | `TBaseContext` | `unknown` | #### Parameters [Section titled “Parameters”](#parameters-21) | Parameter | Type | Description | | ----------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- | | `agent` | \| [`RealtimeAgent`](/openai-agents-js/openai/agents-realtime/classes/realtimeagent/)<`TBaseContext`> \| [`RealtimeAgent`](/openai-agents-js/openai/agents-realtime/classes/realtimeagent/)<[`RealtimeContextData`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimecontextdata/)<`TBaseContext`>> | The starting agent used to seed the session instructions, tools, and prompt. | | `options` | `Partial`<[`RealtimeSessionOptions`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimesessionoptions/)<`TBaseContext`>> | Optional session options that mirror the ones passed to the RealtimeSession constructor. | | `overrides` | `Partial`<[`RealtimeSessionConfig`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimesessionconfig/)> | Additional config overrides applied on top of the session options. | #### Returns [Section titled “Returns”](#returns-27) `Promise`<[`RealtimeSessionPayload`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimesessionpayload/)> # OpenAIRealtimeWebRTC Transport layer that’s handling the connection between the client and OpenAI’s Realtime API via WebRTC. While this transport layer is designed to be used within a RealtimeSession, it can also be used standalone if you want to have a direct connection to the Realtime API. Unless you specify a `mediaStream` or `audioElement` option, the transport layer will automatically configure the microphone and audio output to be used by the session. ## Extends [Section titled “Extends”](#extends) * [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/) ## Implements [Section titled “Implements”](#implements) * [`RealtimeTransportLayer`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/) ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new OpenAIRealtimeWebRTC(options?): OpenAIRealtimeWebRTC; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ------------------------------------------------------------------------------------------------------------------- | | `options` | [`OpenAIRealtimeWebRTCOptions`](/openai-agents-js/openai/agents-realtime/type-aliases/openairealtimewebrtcoptions/) | #### Returns [Section titled “Returns”](#returns) `OpenAIRealtimeWebRTC` #### Overrides [Section titled “Overrides”](#overrides) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/).[`constructor`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/#constructor) ## Accessors [Section titled “Accessors”](#accessors) ### \_tracingConfig [Section titled “\_tracingConfig”](#_tracingconfig) #### Set Signature [Section titled “Set Signature”](#set-signature) ```ts set _tracingConfig(tracingConfig): void; ``` Sets the internal tracing config. This is used to track the tracing config that has been set during the session.create event. ##### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | --------------- | --------------------------------- | | `tracingConfig` | `RealtimeTracingConfig` \| `null` | ##### Returns [Section titled “Returns”](#returns-1) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/).[`_tracingConfig`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/#_tracingconfig) *** ### callId [Section titled “callId”](#callid) #### Get Signature [Section titled “Get Signature”](#get-signature) ```ts get callId(): string | undefined; ``` The current call ID of the WebRTC connection. ##### Returns [Section titled “Returns”](#returns-2) `string` | `undefined` *** ### connectionState [Section titled “connectionState”](#connectionstate) #### Get Signature [Section titled “Get Signature”](#get-signature-1) ```ts get connectionState(): WebRTCState; ``` The current connection state of the WebRTC connection including the peer connection and data channel. ##### Returns [Section titled “Returns”](#returns-3) [`WebRTCState`](/openai-agents-js/openai/agents-realtime/type-aliases/webrtcstate/) *** ### currentModel [Section titled “currentModel”](#currentmodel) #### Get Signature [Section titled “Get Signature”](#get-signature-2) ```ts get currentModel(): OpenAIRealtimeModels; ``` The current model that is being used by the transport layer. ##### Returns [Section titled “Returns”](#returns-4) [`OpenAIRealtimeModels`](/openai-agents-js/openai/agents-realtime/type-aliases/openairealtimemodels/) #### Set Signature [Section titled “Set Signature”](#set-signature-1) ```ts set currentModel(model): void; ``` The current model that is being used by the transport layer. **Note**: The model cannot be changed mid conversation. ##### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | --------- | ----------------------------------------------------------------------------------------------------- | | `model` | [`OpenAIRealtimeModels`](/openai-agents-js/openai/agents-realtime/type-aliases/openairealtimemodels/) | ##### Returns [Section titled “Returns”](#returns-5) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-1) [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents-realtime/classes/openairealtimewebsocket/).[`currentModel`](/openai-agents-js/openai/agents-realtime/classes/openairealtimewebsocket/#currentmodel) *** ### muted [Section titled “muted”](#muted) #### Get Signature [Section titled “Get Signature”](#get-signature-3) ```ts get muted(): boolean; ``` Whether the session is muted. ##### Returns [Section titled “Returns”](#returns-6) `boolean` Whether the input audio track is currently muted null if the muting is not handled by the transport layer #### Implementation of [Section titled “Implementation of”](#implementation-of) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/).[`muted`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/#muted) #### Overrides [Section titled “Overrides”](#overrides-1) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/).[`muted`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/#muted) *** ### status [Section titled “status”](#status) #### Get Signature [Section titled “Get Signature”](#get-signature-4) ```ts get status(): "connecting" | "connected" | "disconnected"; ``` The current status of the WebRTC connection. ##### Returns [Section titled “Returns”](#returns-7) `"connecting"` | `"connected"` | `"disconnected"` #### Implementation of [Section titled “Implementation of”](#implementation-of-1) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/).[`status`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/#status) #### Overrides [Section titled “Overrides”](#overrides-2) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/).[`status`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/#status) ## Methods [Section titled “Methods”](#methods) ### addImage() [Section titled “addImage()”](#addimage) ```ts addImage(image, options?): void; ``` Sends an image to the model #### Parameters [Section titled “Parameters”](#parameters-3) | Parameter | Type | Description | | -------------------------- | ---------------------------------- | -------------------------------------------- | | `image` | `string` | The image to send | | `options` | { `triggerResponse?`: `boolean`; } | Additional options | | `options.triggerResponse?` | `boolean` | Whether to trigger a response from the model | #### Returns [Section titled “Returns”](#returns-8) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-2) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/).[`addImage`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/#addimage) #### Inherited from [Section titled “Inherited from”](#inherited-from-2) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/).[`addImage`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/#addimage) *** ### buildSessionPayload() [Section titled “buildSessionPayload()”](#buildsessionpayload) ```ts buildSessionPayload(config): RealtimeSessionPayload; ``` Build the payload object expected by the Realtime API when creating or updating a session. The helper centralises the conversion from camelCase runtime config to the snake\_case payload required by the Realtime API so transports that need a one-off payload (for example SIP call acceptance) can reuse the same logic without duplicating private state. #### Parameters [Section titled “Parameters”](#parameters-4) | Parameter | Type | Description | | --------- | ------------------------------------------------------------------------------------------------------------------ | ------------------------------------------ | | `config` | `Partial`<[`RealtimeSessionConfig`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimesessionconfig/)> | The session config to merge with defaults. | #### Returns [Section titled “Returns”](#returns-9) [`RealtimeSessionPayload`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimesessionpayload/) #### Inherited from [Section titled “Inherited from”](#inherited-from-3) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/).[`buildSessionPayload`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/#buildsessionpayload) *** ### close() [Section titled “close()”](#close) ```ts close(): void; ``` Close the connection to the Realtime API and disconnects the underlying WebRTC connection. #### Returns [Section titled “Returns”](#returns-10) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-3) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/).[`close`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/#close) #### Overrides [Section titled “Overrides”](#overrides-3) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/).[`close`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/#close) *** ### connect() [Section titled “connect()”](#connect) ```ts connect(options): Promise; ``` Connect to the Realtime API. This will establish the connection to the OpenAI Realtime API via WebRTC. If you are using a browser, the transport layer will also automatically configure the microphone and audio output to be used by the session. #### Parameters [Section titled “Parameters”](#parameters-5) | Parameter | Type | Description | | --------- | ------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------- | | `options` | [`RealtimeTransportLayerConnectOptions`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimetransportlayerconnectoptions/) | The options for the connection. | #### Returns [Section titled “Returns”](#returns-11) `Promise`<`void`> #### Implementation of [Section titled “Implementation of”](#implementation-of-4) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/).[`connect`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/#connect) #### Overrides [Section titled “Overrides”](#overrides-4) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/).[`connect`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/#connect) *** ### emit() [Section titled “emit()”](#emit) ```ts emit(type, ...args): boolean; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | --------------------------------------------------------------------------------------------------------------------------------------- | | `K` *extends* keyof [`RealtimeTransportEventTypes`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimetransporteventtypes/) | #### Parameters [Section titled “Parameters”](#parameters-6) | Parameter | Type | | --------- | ------------------------------------------------------------------------------------------------------------------- | | `type` | `K` | | …`args` | [`OpenAIRealtimeEventTypes`](/openai-agents-js/openai/agents-realtime/type-aliases/openairealtimeeventtypes/)\[`K`] | #### Returns [Section titled “Returns”](#returns-12) `boolean` #### Implementation of [Section titled “Implementation of”](#implementation-of-5) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/).[`emit`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/#emit) #### Inherited from [Section titled “Inherited from”](#inherited-from-4) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/).[`emit`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/#emit) *** ### interrupt() [Section titled “interrupt()”](#interrupt) ```ts interrupt(): void; ``` Interrupt the current response if one is ongoing and clear the audio buffer so that the agent stops talking. #### Returns [Section titled “Returns”](#returns-13) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-6) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/).[`interrupt`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/#interrupt) #### Overrides [Section titled “Overrides”](#overrides-5) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/).[`interrupt`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/#interrupt) *** ### mute() [Section titled “mute()”](#mute) ```ts mute(muted): void; ``` Mute or unmute the session. #### Parameters [Section titled “Parameters”](#parameters-7) | Parameter | Type | Description | | --------- | --------- | ---------------------------- | | `muted` | `boolean` | Whether to mute the session. | #### Returns [Section titled “Returns”](#returns-14) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-7) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/).[`mute`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/#mute) #### Overrides [Section titled “Overrides”](#overrides-6) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/).[`mute`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/#mute) *** ### off() [Section titled “off()”](#off) ```ts off(type, listener): EventEmitter; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-1) | Type Parameter | | --------------------------------------------------------------------------------------------------------------------------------------- | | `K` *extends* keyof [`RealtimeTransportEventTypes`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimetransporteventtypes/) | #### Parameters [Section titled “Parameters”](#parameters-8) | Parameter | Type | | ---------- | ------------------- | | `type` | `K` | | `listener` | (…`args`) => `void` | #### Returns [Section titled “Returns”](#returns-15) `EventEmitter`<`EventTypes`> #### Implementation of [Section titled “Implementation of”](#implementation-of-8) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/).[`off`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/#off) #### Inherited from [Section titled “Inherited from”](#inherited-from-5) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/).[`off`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/#off) *** ### on() [Section titled “on()”](#on) ```ts on(type, listener): EventEmitter; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-2) | Type Parameter | | --------------------------------------------------------------------------------------------------------------------------------------- | | `K` *extends* keyof [`RealtimeTransportEventTypes`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimetransporteventtypes/) | #### Parameters [Section titled “Parameters”](#parameters-9) | Parameter | Type | | ---------- | ------------------- | | `type` | `K` | | `listener` | (…`args`) => `void` | #### Returns [Section titled “Returns”](#returns-16) `EventEmitter`<`EventTypes`> #### Implementation of [Section titled “Implementation of”](#implementation-of-9) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/).[`on`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/#on) #### Inherited from [Section titled “Inherited from”](#inherited-from-6) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/).[`on`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/#on) *** ### once() [Section titled “once()”](#once) ```ts once(type, listener): EventEmitter; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-3) | Type Parameter | | --------------------------------------------------------------------------------------------------------------------------------------- | | `K` *extends* keyof [`RealtimeTransportEventTypes`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimetransporteventtypes/) | #### Parameters [Section titled “Parameters”](#parameters-10) | Parameter | Type | | ---------- | ------------------- | | `type` | `K` | | `listener` | (…`args`) => `void` | #### Returns [Section titled “Returns”](#returns-17) `EventEmitter`<`EventTypes`> #### Implementation of [Section titled “Implementation of”](#implementation-of-10) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/).[`once`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/#once) #### Inherited from [Section titled “Inherited from”](#inherited-from-7) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/).[`once`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/#once) *** ### requestResponse() [Section titled “requestResponse()”](#requestresponse) ```ts requestResponse(response?): void; ``` Requests a new response for the current conversation turn. Implementations may defer the underlying `response.create` until the server has fully finished the prior response. #### Parameters [Section titled “Parameters”](#parameters-11) | Parameter | Type | Description | | ----------- | ------------------------- | ------------------------------------------- | | `response?` | `Record`<`string`, `any`> | Optional one-off response override payload. | #### Returns [Section titled “Returns”](#returns-18) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-11) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/).[`requestResponse`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/#requestresponse) #### Overrides [Section titled “Overrides”](#overrides-7) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/).[`requestResponse`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/#requestresponse) *** ### resetHistory() [Section titled “resetHistory()”](#resethistory) ```ts resetHistory(oldHistory, newHistory): void; ``` Reset the history of the conversation. This will create a diff between the old and new history and send the necessary events to the Realtime API to update the history. #### Parameters [Section titled “Parameters”](#parameters-12) | Parameter | Type | Description | | ------------ | ---------------------------------------------------------------------------------------- | ------------------------------------ | | `oldHistory` | [`RealtimeItem`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimeitem/)\[] | The old history of the conversation. | | `newHistory` | [`RealtimeItem`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimeitem/)\[] | The new history of the conversation. | #### Returns [Section titled “Returns”](#returns-19) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-12) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/).[`resetHistory`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/#resethistory) #### Inherited from [Section titled “Inherited from”](#inherited-from-8) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/).[`resetHistory`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/#resethistory) *** ### sendAudio() [Section titled “sendAudio()”](#sendaudio) ```ts sendAudio(audio, options?): void; ``` Send an audio buffer to the Realtime API. If `{ commit: true }` is passed, the audio buffer will be committed and the model will start processing it. This is necessary if you have disabled turn detection / voice activity detection (VAD). #### Parameters [Section titled “Parameters”](#parameters-13) | Parameter | Type | Description | | ----------------- | ------------------------- | --------------------------------- | | `audio` | `ArrayBuffer` | The audio buffer to send. | | `options` | { `commit?`: `boolean`; } | The options for the audio buffer. | | `options.commit?` | `boolean` | ‐ | #### Returns [Section titled “Returns”](#returns-20) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-13) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/).[`sendAudio`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/#sendaudio) #### Inherited from [Section titled “Inherited from”](#inherited-from-9) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/).[`sendAudio`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/#sendaudio) *** ### sendEvent() [Section titled “sendEvent()”](#sendevent) ```ts sendEvent(event): void; ``` Send an event to the Realtime API. This will stringify the event and send it directly to the API. This can be used if you want to take control over the connection and send events manually. #### Parameters [Section titled “Parameters”](#parameters-14) | Parameter | Type | Description | | --------- | ------------------------------------------------------------------------------------------------------- | ------------------ | | `event` | [`RealtimeClientMessage`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimeclientmessage/) | The event to send. | #### Returns [Section titled “Returns”](#returns-21) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-14) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/).[`sendEvent`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/#sendevent) #### Overrides [Section titled “Overrides”](#overrides-8) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/).[`sendEvent`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/#sendevent) *** ### sendFunctionCallOutput() [Section titled “sendFunctionCallOutput()”](#sendfunctioncalloutput) ```ts sendFunctionCallOutput( toolCall, output, startResponse?): void; ``` Send the output of a function call to the Realtime API. #### Parameters [Section titled “Parameters”](#parameters-15) | Parameter | Type | Default value | Description | | --------------- | --------------------------------------------------------------------------------------------------------- | ------------- | --------------------------------------------------------- | | `toolCall` | [`TransportToolCallEvent`](/openai-agents-js/openai/agents-realtime/type-aliases/transporttoolcallevent/) | `undefined` | The tool call to send the output for. | | `output` | `string` | `undefined` | The output of the function call. | | `startResponse` | `boolean` | `true` | Whether to start a new response after sending the output. | #### Returns [Section titled “Returns”](#returns-22) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-15) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/).[`sendFunctionCallOutput`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/#sendfunctioncalloutput) #### Inherited from [Section titled “Inherited from”](#inherited-from-10) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/).[`sendFunctionCallOutput`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/#sendfunctioncalloutput) *** ### sendMcpResponse() [Section titled “sendMcpResponse()”](#sendmcpresponse) ```ts sendMcpResponse( approvalRequest, approved, reason?): void; ``` Sends a response for an MCP tool call #### Parameters [Section titled “Parameters”](#parameters-16) | Parameter | Type | Description | | ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------- | | `approvalRequest` | { `approved?`: `boolean` \| `null`; `arguments`: `Record`<`string`, `any`>; `itemId`: `string`; `name`: `string`; `serverLabel`: `string`; `type`: `"mcp_approval_request"`; } | The approval request to respond to | | `approvalRequest.approved?` | `boolean` \| `null` | ‐ | | `approvalRequest.arguments` | `Record`<`string`, `any`> | ‐ | | `approvalRequest.itemId?` | `string` | ‐ | | `approvalRequest.name?` | `string` | ‐ | | `approvalRequest.serverLabel?` | `string` | ‐ | | `approvalRequest.type?` | `"mcp_approval_request"` | ‐ | | `approved?` | `boolean` | Whether the tool call was approved or rejected | | `reason?` | `string` | Optional rejection text for the provider/model. | #### Returns [Section titled “Returns”](#returns-23) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-16) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/).[`sendMcpResponse`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/#sendmcpresponse) #### Inherited from [Section titled “Inherited from”](#inherited-from-11) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/).[`sendMcpResponse`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/#sendmcpresponse) *** ### sendMessage() [Section titled “sendMessage()”](#sendmessage) ```ts sendMessage( message, otherEventData, __namedParameters?): void; ``` Send a message to the Realtime API. This will create a new item in the conversation and trigger a response. #### Parameters [Section titled “Parameters”](#parameters-17) | Parameter | Type | Description | | ------------------------------------ | ---------------------------------- | ------------------------------ | | `message` | `RealtimeUserInput` | The message to send. | | `otherEventData` | `Record`<`string`, `any`> | Additional event data to send. | | `__namedParameters` | { `triggerResponse?`: `boolean`; } | ‐ | | `__namedParameters.triggerResponse?` | `boolean` | ‐ | #### Returns [Section titled “Returns”](#returns-24) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-17) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/).[`sendMessage`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/#sendmessage) #### Inherited from [Section titled “Inherited from”](#inherited-from-12) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/).[`sendMessage`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/#sendmessage) *** ### updateSessionConfig() [Section titled “updateSessionConfig()”](#updatesessionconfig) ```ts updateSessionConfig(config): void; ``` Updates the session config. This will merge it with the current session config with the default values and send it to the Realtime API. #### Parameters [Section titled “Parameters”](#parameters-18) | Parameter | Type | Description | | --------- | ------------------------------------------------------------------------------------------------------------------ | ----------------------------- | | `config` | `Partial`<[`RealtimeSessionConfig`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimesessionconfig/)> | The session config to update. | #### Returns [Section titled “Returns”](#returns-25) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-18) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/).[`updateSessionConfig`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/#updatesessionconfig) #### Inherited from [Section titled “Inherited from”](#inherited-from-13) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/).[`updateSessionConfig`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/#updatesessionconfig) # OpenAIRealtimeWebSocket Transport layer that’s handling the connection between the client and OpenAI’s Realtime API via WebSockets. While this transport layer is designed to be used within a RealtimeSession, it can also be used standalone if you want to have a direct connection to the Realtime API. ## Extends [Section titled “Extends”](#extends) * [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/) ## Extended by [Section titled “Extended by”](#extended-by) * [`OpenAIRealtimeSIP`](/openai-agents-js/openai/agents-realtime/classes/openairealtimesip/) ## Implements [Section titled “Implements”](#implements) * [`RealtimeTransportLayer`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/) ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new OpenAIRealtimeWebSocket(options?): OpenAIRealtimeWebSocket; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ------------------------------------------------------------------------------------------------------------------------- | | `options` | [`OpenAIRealtimeWebSocketOptions`](/openai-agents-js/openai/agents-realtime/type-aliases/openairealtimewebsocketoptions/) | #### Returns [Section titled “Returns”](#returns) `OpenAIRealtimeWebSocket` #### Overrides [Section titled “Overrides”](#overrides) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/).[`constructor`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/#constructor) ## Accessors [Section titled “Accessors”](#accessors) ### \_tracingConfig [Section titled “\_tracingConfig”](#_tracingconfig) #### Set Signature [Section titled “Set Signature”](#set-signature) ```ts set _tracingConfig(tracingConfig): void; ``` Sets the internal tracing config. This is used to track the tracing config that has been set during the session.create event. ##### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | --------------- | --------------------------------- | | `tracingConfig` | `RealtimeTracingConfig` \| `null` | ##### Returns [Section titled “Returns”](#returns-1) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/).[`_tracingConfig`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/#_tracingconfig) *** ### connectionState [Section titled “connectionState”](#connectionstate) #### Get Signature [Section titled “Get Signature”](#get-signature) ```ts get connectionState(): WebSocketState; ``` The current connection state of the WebSocket connection. ##### Returns [Section titled “Returns”](#returns-2) [`WebSocketState`](/openai-agents-js/openai/agents-realtime/type-aliases/websocketstate/) *** ### currentModel [Section titled “currentModel”](#currentmodel) #### Get Signature [Section titled “Get Signature”](#get-signature-1) ```ts get currentModel(): OpenAIRealtimeModels; ``` The current model that is being used by the transport layer. ##### Returns [Section titled “Returns”](#returns-3) [`OpenAIRealtimeModels`](/openai-agents-js/openai/agents-realtime/type-aliases/openairealtimemodels/) #### Set Signature [Section titled “Set Signature”](#set-signature-1) ```ts set currentModel(model): void; ``` The current model that is being used by the transport layer. **Note**: The model cannot be changed mid conversation. ##### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | --------- | ----------------------------------------------------------------------------------------------------- | | `model` | [`OpenAIRealtimeModels`](/openai-agents-js/openai/agents-realtime/type-aliases/openairealtimemodels/) | ##### Returns [Section titled “Returns”](#returns-4) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-1) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/).[`currentModel`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/#currentmodel) *** ### muted [Section titled “muted”](#muted) #### Get Signature [Section titled “Get Signature”](#get-signature-2) ```ts get muted(): null; ``` Always returns `null` as the WebSocket transport layer does not handle muting. Instead, this should be handled by the client by not triggering the `sendAudio` method. ##### Returns [Section titled “Returns”](#returns-5) `null` Whether the input audio track is currently muted null if the muting is not handled by the transport layer #### Implementation of [Section titled “Implementation of”](#implementation-of) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/).[`muted`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/#muted) #### Overrides [Section titled “Overrides”](#overrides-1) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/).[`muted`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/#muted) *** ### status [Section titled “status”](#status) #### Get Signature [Section titled “Get Signature”](#get-signature-3) ```ts get status(): "connecting" | "connected" | "disconnected"; ``` The current status of the WebSocket connection. ##### Returns [Section titled “Returns”](#returns-6) `"connecting"` | `"connected"` | `"disconnected"` #### Implementation of [Section titled “Implementation of”](#implementation-of-1) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/).[`status`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/#status) #### Overrides [Section titled “Overrides”](#overrides-2) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/).[`status`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/#status) ## Methods [Section titled “Methods”](#methods) ### \_cancelResponse() [Section titled “\_cancelResponse()”](#_cancelresponse) ```ts _cancelResponse(): void; ``` Send a cancel response event to the Realtime API. This is used to cancel an ongoing response that the model is currently generating. #### Returns [Section titled “Returns”](#returns-7) `void` *** ### \_interrupt() [Section titled “\_interrupt()”](#_interrupt) ```ts _interrupt(elapsedTime, cancelOngoingResponse?): void; ``` Do NOT call this method directly. Call `interrupt()` instead for proper interruption handling. This method is used to send the right events to the API to inform the model that the user has interrupted the response. It might be overridden/extended by an extended transport layer. See the `TwilioRealtimeTransportLayer` for an example. #### Parameters [Section titled “Parameters”](#parameters-3) | Parameter | Type | Default value | Description | | ----------------------- | --------- | ------------- | -------------------------------------------- | | `elapsedTime` | `number` | `undefined` | The elapsed time since the response started. | | `cancelOngoingResponse` | `boolean` | `true` | ‐ | #### Returns [Section titled “Returns”](#returns-8) `void` *** ### addImage() [Section titled “addImage()”](#addimage) ```ts addImage(image, options?): void; ``` Sends an image to the model #### Parameters [Section titled “Parameters”](#parameters-4) | Parameter | Type | Description | | -------------------------- | ---------------------------------- | -------------------------------------------- | | `image` | `string` | The image to send | | `options` | { `triggerResponse?`: `boolean`; } | Additional options | | `options.triggerResponse?` | `boolean` | Whether to trigger a response from the model | #### Returns [Section titled “Returns”](#returns-9) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-2) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/).[`addImage`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/#addimage) #### Inherited from [Section titled “Inherited from”](#inherited-from-2) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/).[`addImage`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/#addimage) *** ### buildSessionPayload() [Section titled “buildSessionPayload()”](#buildsessionpayload) ```ts buildSessionPayload(config): RealtimeSessionPayload; ``` Build the payload object expected by the Realtime API when creating or updating a session. The helper centralises the conversion from camelCase runtime config to the snake\_case payload required by the Realtime API so transports that need a one-off payload (for example SIP call acceptance) can reuse the same logic without duplicating private state. #### Parameters [Section titled “Parameters”](#parameters-5) | Parameter | Type | Description | | --------- | ------------------------------------------------------------------------------------------------------------------ | ------------------------------------------ | | `config` | `Partial`<[`RealtimeSessionConfig`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimesessionconfig/)> | The session config to merge with defaults. | #### Returns [Section titled “Returns”](#returns-10) [`RealtimeSessionPayload`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimesessionpayload/) #### Inherited from [Section titled “Inherited from”](#inherited-from-3) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/).[`buildSessionPayload`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/#buildsessionpayload) *** ### close() [Section titled “close()”](#close) ```ts close(): void; ``` Close the WebSocket connection. This will also reset any internal connection tracking used for interruption handling. #### Returns [Section titled “Returns”](#returns-11) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-3) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/).[`close`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/#close) #### Overrides [Section titled “Overrides”](#overrides-3) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/).[`close`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/#close) *** ### connect() [Section titled “connect()”](#connect) ```ts connect(options): Promise; ``` Establishes the connection to the model and keeps the connection alive #### Parameters [Section titled “Parameters”](#parameters-6) | Parameter | Type | Description | | --------- | ------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------ | | `options` | [`RealtimeTransportLayerConnectOptions`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimetransportlayerconnectoptions/) | The options for the connection | #### Returns [Section titled “Returns”](#returns-12) `Promise`<`void`> #### Implementation of [Section titled “Implementation of”](#implementation-of-4) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/).[`connect`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/#connect) #### Overrides [Section titled “Overrides”](#overrides-4) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/).[`connect`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/#connect) *** ### emit() [Section titled “emit()”](#emit) ```ts emit(type, ...args): boolean; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | --------------------------------------------------------------------------------------------------------------------------------------- | | `K` *extends* keyof [`RealtimeTransportEventTypes`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimetransporteventtypes/) | #### Parameters [Section titled “Parameters”](#parameters-7) | Parameter | Type | | --------- | ------------------------------------------------------------------------------------------------------------------- | | `type` | `K` | | …`args` | [`OpenAIRealtimeEventTypes`](/openai-agents-js/openai/agents-realtime/type-aliases/openairealtimeeventtypes/)\[`K`] | #### Returns [Section titled “Returns”](#returns-13) `boolean` #### Implementation of [Section titled “Implementation of”](#implementation-of-5) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/).[`emit`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/#emit) #### Inherited from [Section titled “Inherited from”](#inherited-from-4) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/).[`emit`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/#emit) *** ### interrupt() [Section titled “interrupt()”](#interrupt) ```ts interrupt(cancelOngoingResponse?): void; ``` Interrupt the ongoing response. This method is triggered automatically by the client when voice activity detection (VAD) is enabled (default) as well as when an output guardrail got triggered. You can also call this method directly if you want to interrupt the conversation for example based on an event in the client. #### Parameters [Section titled “Parameters”](#parameters-8) | Parameter | Type | Default value | | ----------------------- | --------- | ------------- | | `cancelOngoingResponse` | `boolean` | `true` | #### Returns [Section titled “Returns”](#returns-14) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-6) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/).[`interrupt`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/#interrupt) #### Overrides [Section titled “Overrides”](#overrides-5) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/).[`interrupt`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/#interrupt) *** ### mute() [Section titled “mute()”](#mute) ```ts mute(_muted): never; ``` Will throw an error as the WebSocket transport layer does not support muting. #### Parameters [Section titled “Parameters”](#parameters-9) | Parameter | Type | | --------- | --------- | | `_muted` | `boolean` | #### Returns [Section titled “Returns”](#returns-15) `never` #### Implementation of [Section titled “Implementation of”](#implementation-of-7) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/).[`mute`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/#mute) #### Overrides [Section titled “Overrides”](#overrides-6) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/).[`mute`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/#mute) *** ### off() [Section titled “off()”](#off) ```ts off(type, listener): EventEmitter; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-1) | Type Parameter | | --------------------------------------------------------------------------------------------------------------------------------------- | | `K` *extends* keyof [`RealtimeTransportEventTypes`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimetransporteventtypes/) | #### Parameters [Section titled “Parameters”](#parameters-10) | Parameter | Type | | ---------- | ------------------- | | `type` | `K` | | `listener` | (…`args`) => `void` | #### Returns [Section titled “Returns”](#returns-16) `EventEmitter`<`EventTypes`> #### Implementation of [Section titled “Implementation of”](#implementation-of-8) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/).[`off`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/#off) #### Inherited from [Section titled “Inherited from”](#inherited-from-5) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/).[`off`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/#off) *** ### on() [Section titled “on()”](#on) ```ts on(type, listener): EventEmitter; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-2) | Type Parameter | | --------------------------------------------------------------------------------------------------------------------------------------- | | `K` *extends* keyof [`RealtimeTransportEventTypes`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimetransporteventtypes/) | #### Parameters [Section titled “Parameters”](#parameters-11) | Parameter | Type | | ---------- | ------------------- | | `type` | `K` | | `listener` | (…`args`) => `void` | #### Returns [Section titled “Returns”](#returns-17) `EventEmitter`<`EventTypes`> #### Implementation of [Section titled “Implementation of”](#implementation-of-9) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/).[`on`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/#on) #### Inherited from [Section titled “Inherited from”](#inherited-from-6) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/).[`on`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/#on) *** ### once() [Section titled “once()”](#once) ```ts once(type, listener): EventEmitter; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-3) | Type Parameter | | --------------------------------------------------------------------------------------------------------------------------------------- | | `K` *extends* keyof [`RealtimeTransportEventTypes`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimetransporteventtypes/) | #### Parameters [Section titled “Parameters”](#parameters-12) | Parameter | Type | | ---------- | ------------------- | | `type` | `K` | | `listener` | (…`args`) => `void` | #### Returns [Section titled “Returns”](#returns-18) `EventEmitter`<`EventTypes`> #### Implementation of [Section titled “Implementation of”](#implementation-of-10) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/).[`once`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/#once) #### Inherited from [Section titled “Inherited from”](#inherited-from-7) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/).[`once`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/#once) *** ### requestResponse() [Section titled “requestResponse()”](#requestresponse) ```ts requestResponse(response?): void; ``` Requests a new response for the current conversation turn. Implementations may defer the underlying `response.create` until the server has fully finished the prior response. #### Parameters [Section titled “Parameters”](#parameters-13) | Parameter | Type | Description | | ----------- | ------------------------- | ------------------------------------------- | | `response?` | `Record`<`string`, `any`> | Optional one-off response override payload. | #### Returns [Section titled “Returns”](#returns-19) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-11) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/).[`requestResponse`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/#requestresponse) #### Overrides [Section titled “Overrides”](#overrides-7) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/).[`requestResponse`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/#requestresponse) *** ### resetHistory() [Section titled “resetHistory()”](#resethistory) ```ts resetHistory(oldHistory, newHistory): void; ``` Reset the history of the conversation. This will create a diff between the old and new history and send the necessary events to the Realtime API to update the history. #### Parameters [Section titled “Parameters”](#parameters-14) | Parameter | Type | Description | | ------------ | ---------------------------------------------------------------------------------------- | ------------------------------------ | | `oldHistory` | [`RealtimeItem`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimeitem/)\[] | The old history of the conversation. | | `newHistory` | [`RealtimeItem`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimeitem/)\[] | The new history of the conversation. | #### Returns [Section titled “Returns”](#returns-20) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-12) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/).[`resetHistory`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/#resethistory) #### Inherited from [Section titled “Inherited from”](#inherited-from-8) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/).[`resetHistory`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/#resethistory) *** ### sendAudio() [Section titled “sendAudio()”](#sendaudio) ```ts sendAudio(audio, options?): void; ``` Send an audio buffer to the Realtime API. This is used for your client to send audio to the model to respond. #### Parameters [Section titled “Parameters”](#parameters-15) | Parameter | Type | Description | | ----------------- | ------------------------- | --------------------------------- | | `audio` | `ArrayBuffer` | The audio buffer to send. | | `options` | { `commit?`: `boolean`; } | The options for the audio buffer. | | `options.commit?` | `boolean` | ‐ | #### Returns [Section titled “Returns”](#returns-21) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-13) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/).[`sendAudio`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/#sendaudio) #### Overrides [Section titled “Overrides”](#overrides-8) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/).[`sendAudio`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/#sendaudio) *** ### sendEvent() [Section titled “sendEvent()”](#sendevent) ```ts sendEvent(event): void; ``` Send an event to the Realtime API. This will stringify the event and send it directly to the API. This can be used if you want to take control over the connection and send events manually. #### Parameters [Section titled “Parameters”](#parameters-16) | Parameter | Type | Description | | --------- | ------------------------------------------------------------------------------------------------------- | ------------------ | | `event` | [`RealtimeClientMessage`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimeclientmessage/) | The event to send. | #### Returns [Section titled “Returns”](#returns-22) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-14) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/).[`sendEvent`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/#sendevent) #### Overrides [Section titled “Overrides”](#overrides-9) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/).[`sendEvent`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/#sendevent) *** ### sendFunctionCallOutput() [Section titled “sendFunctionCallOutput()”](#sendfunctioncalloutput) ```ts sendFunctionCallOutput( toolCall, output, startResponse?): void; ``` Send the output of a function call to the Realtime API. #### Parameters [Section titled “Parameters”](#parameters-17) | Parameter | Type | Default value | Description | | --------------- | --------------------------------------------------------------------------------------------------------- | ------------- | --------------------------------------------------------- | | `toolCall` | [`TransportToolCallEvent`](/openai-agents-js/openai/agents-realtime/type-aliases/transporttoolcallevent/) | `undefined` | The tool call to send the output for. | | `output` | `string` | `undefined` | The output of the function call. | | `startResponse` | `boolean` | `true` | Whether to start a new response after sending the output. | #### Returns [Section titled “Returns”](#returns-23) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-15) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/).[`sendFunctionCallOutput`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/#sendfunctioncalloutput) #### Inherited from [Section titled “Inherited from”](#inherited-from-9) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/).[`sendFunctionCallOutput`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/#sendfunctioncalloutput) *** ### sendMcpResponse() [Section titled “sendMcpResponse()”](#sendmcpresponse) ```ts sendMcpResponse( approvalRequest, approved, reason?): void; ``` Sends a response for an MCP tool call #### Parameters [Section titled “Parameters”](#parameters-18) | Parameter | Type | Description | | ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------- | | `approvalRequest` | { `approved?`: `boolean` \| `null`; `arguments`: `Record`<`string`, `any`>; `itemId`: `string`; `name`: `string`; `serverLabel`: `string`; `type`: `"mcp_approval_request"`; } | The approval request to respond to | | `approvalRequest.approved?` | `boolean` \| `null` | ‐ | | `approvalRequest.arguments` | `Record`<`string`, `any`> | ‐ | | `approvalRequest.itemId?` | `string` | ‐ | | `approvalRequest.name?` | `string` | ‐ | | `approvalRequest.serverLabel?` | `string` | ‐ | | `approvalRequest.type?` | `"mcp_approval_request"` | ‐ | | `approved?` | `boolean` | Whether the tool call was approved or rejected | | `reason?` | `string` | Optional rejection text for the provider/model. | #### Returns [Section titled “Returns”](#returns-24) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-16) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/).[`sendMcpResponse`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/#sendmcpresponse) #### Inherited from [Section titled “Inherited from”](#inherited-from-10) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/).[`sendMcpResponse`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/#sendmcpresponse) *** ### sendMessage() [Section titled “sendMessage()”](#sendmessage) ```ts sendMessage( message, otherEventData, __namedParameters?): void; ``` Send a message to the Realtime API. This will create a new item in the conversation and trigger a response. #### Parameters [Section titled “Parameters”](#parameters-19) | Parameter | Type | Description | | ------------------------------------ | ---------------------------------- | ------------------------------ | | `message` | `RealtimeUserInput` | The message to send. | | `otherEventData` | `Record`<`string`, `any`> | Additional event data to send. | | `__namedParameters` | { `triggerResponse?`: `boolean`; } | ‐ | | `__namedParameters.triggerResponse?` | `boolean` | ‐ | #### Returns [Section titled “Returns”](#returns-25) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-17) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/).[`sendMessage`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/#sendmessage) #### Inherited from [Section titled “Inherited from”](#inherited-from-11) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/).[`sendMessage`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/#sendmessage) *** ### updateSessionConfig() [Section titled “updateSessionConfig()”](#updatesessionconfig) ```ts updateSessionConfig(config): void; ``` Updates the session config. This will merge it with the current session config with the default values and send it to the Realtime API. #### Parameters [Section titled “Parameters”](#parameters-20) | Parameter | Type | Description | | --------- | ------------------------------------------------------------------------------------------------------------------ | ----------------------------- | | `config` | `Partial`<[`RealtimeSessionConfig`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimesessionconfig/)> | The session config to update. | #### Returns [Section titled “Returns”](#returns-26) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-18) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/).[`updateSessionConfig`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/#updatesessionconfig) #### Inherited from [Section titled “Inherited from”](#inherited-from-12) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/).[`updateSessionConfig`](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/#updatesessionconfig) # OutputGuardrailTripwireTriggered Error thrown when an output guardrail tripwire is triggered. ## Extends [Section titled “Extends”](#extends) * `AgentsError` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | ------------------------------------------- | ------------ | | `TMeta` *extends* `OutputGuardrailMetadata` | ‐ | | `TOutputType` *extends* `AgentOutputType` | `TextOutput` | ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new OutputGuardrailTripwireTriggered( message, result, state?): OutputGuardrailTripwireTriggered; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ----------------------------------------------- | | `message` | `string` | | `result` | `OutputGuardrailResult`<`TMeta`, `TOutputType`> | | `state?` | `RunState`<`any`, `any`> | #### Returns [Section titled “Returns”](#returns) `OutputGuardrailTripwireTriggered`<`TMeta`, `TOutputType`> #### Overrides [Section titled “Overrides”](#overrides) ```ts AgentsError.constructor ``` ## Properties [Section titled “Properties”](#properties) ### message [Section titled “message”](#message) ```ts message: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from) ```ts AgentsError.message ``` *** ### name [Section titled “name”](#name) ```ts name: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-1) ```ts AgentsError.name ``` *** ### result [Section titled “result”](#result) ```ts result: OutputGuardrailResult; ``` *** ### stack? [Section titled “stack?”](#stack) ```ts optional stack?: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-2) ```ts AgentsError.stack ``` *** ### state? [Section titled “state?”](#state) ```ts optional state?: RunState>; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-3) ```ts AgentsError.state ``` *** ### stackTraceLimit [Section titled “stackTraceLimit”](#stacktracelimit) ```ts static stackTraceLimit: number; ``` The `Error.stackTraceLimit` property specifies the number of stack frames collected by a stack trace (whether generated by `new Error().stack` or `Error.captureStackTrace(obj)`). The default value is `10` but may be set to any valid JavaScript number. Changes will affect any stack trace captured *after* the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames. #### Inherited from [Section titled “Inherited from”](#inherited-from-4) ```ts AgentsError.stackTraceLimit ``` ## Methods [Section titled “Methods”](#methods) ### captureStackTrace() [Section titled “captureStackTrace()”](#capturestacktrace) ```ts static captureStackTrace(targetObject, constructorOpt?): void; ``` Creates a `.stack` property on `targetObject`, which when accessed returns a string representing the location in the code at which `Error.captureStackTrace()` was called. ```js const myObject = {}; Error.captureStackTrace(myObject); myObject.stack; // Similar to `new Error().stack` ``` The first line of the trace will be prefixed with `${myObject.name}: ${myObject.message}`. The optional `constructorOpt` argument accepts a function. If given, all frames above `constructorOpt`, including `constructorOpt`, will be omitted from the generated stack trace. The `constructorOpt` argument is useful for hiding implementation details of error generation from the user. For instance: ```js function a() { b(); } function b() { c(); } function c() { // Create an error without stack trace to avoid calculating the stack trace twice. const { stackTraceLimit } = Error; Error.stackTraceLimit = 0; const error = new Error(); Error.stackTraceLimit = stackTraceLimit; // Capture the stack trace above function b Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace throw error; } a(); ``` #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | ----------------- | ---------- | | `targetObject` | `object` | | `constructorOpt?` | `Function` | #### Returns [Section titled “Returns”](#returns-1) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-5) ```ts AgentsError.captureStackTrace ``` *** ### prepareStackTrace() [Section titled “prepareStackTrace()”](#preparestacktrace) ```ts static prepareStackTrace(err, stackTraces): any; ``` #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | ------------- | ------------- | | `err` | `Error` | | `stackTraces` | `CallSite`\[] | #### Returns [Section titled “Returns”](#returns-2) `any` #### See [Section titled “See”](#see) #### Inherited from [Section titled “Inherited from”](#inherited-from-6) ```ts AgentsError.prepareStackTrace ``` # RealtimeAgent A specialized agent instance that is meant to be used within a `RealtimeSession` to build voice agents. Due to the nature of this agent, some configuration options are not supported that are supported by regular `Agent` instances. For example: * `model` choice is not supported as all RealtimeAgents will be handled by the same model within a `RealtimeSession` * `modelSettings` is not supported as all RealtimeAgents will be handled by the same model within a `RealtimeSession` * `outputType` is not supported as RealtimeAgents do not support structured outputs * `toolUseBehavior` is not supported as all RealtimeAgents will be handled by the same model within a `RealtimeSession` * `voice` can be configured on an `Agent` level however it cannot be changed after the first agent within a `RealtimeSession` spoke ## Example [Section titled “Example”](#example) ```ts const agent = new RealtimeAgent({ name: 'my-agent', instructions: 'You are a helpful assistant that can answer questions and help with tasks.', }) const session = new RealtimeSession(agent); ``` ## Extends [Section titled “Extends”](#extends) * `Agent`<[`RealtimeContextData`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimecontextdata/)<`TContext`>, `TextOutput`> ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | ---------------- | | `TContext` | `UnknownContext` | ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new RealtimeAgent(config): RealtimeAgent; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ----------------------------------------------------------------------------------------------------------------------------- | | `config` | [`RealtimeAgentConfiguration`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimeagentconfiguration/)<`TContext`> | #### Returns [Section titled “Returns”](#returns) `RealtimeAgent`<`TContext`> #### Overrides [Section titled “Overrides”](#overrides) ```ts Agent< RealtimeContextData, TextOutput >.constructor ``` ## Properties [Section titled “Properties”](#properties) ### handoffDescription [Section titled “handoffDescription”](#handoffdescription) ```ts handoffDescription: string; ``` A description of the agent. This is used when the agent is used as a handoff, so that an LLM knows what it does and when to invoke it. #### Inherited from [Section titled “Inherited from”](#inherited-from) ```ts Agent.handoffDescription ``` *** ### handoffs [Section titled “handoffs”](#handoffs) ```ts handoffs: (Handoff | Agent)[]; ``` Handoffs are sub-agents that the agent can delegate to. You can provide a list of handoffs, and the agent can choose to delegate to them if relevant. Allows for separation of concerns and modularity. #### Inherited from [Section titled “Inherited from”](#inherited-from-1) ```ts Agent.handoffs ``` *** ### inputGuardrails [Section titled “inputGuardrails”](#inputguardrails) ```ts inputGuardrails: InputGuardrail[]; ``` A list of checks that run in parallel to the agent by default; set `runInParallel` to false to block LLM/tool calls until the guardrail completes. Runs only if the agent is the first agent in the chain. #### Inherited from [Section titled “Inherited from”](#inherited-from-2) ```ts Agent.inputGuardrails ``` *** ### instructions [Section titled “instructions”](#instructions) ```ts instructions: string | ((runContext, agent) => string | Promise); ``` The instructions for the agent. Will be used as the “system prompt” when this agent is invoked. Describes what the agent should do, and how it responds. Can either be a string, or a function that dynamically generates instructions for the agent. If you provide a function, it will be called with the context and the agent instance. It must return a string. #### Inherited from [Section titled “Inherited from”](#inherited-from-3) ```ts Agent.instructions ``` *** ### mcpConfig [Section titled “mcpConfig”](#mcpconfig) ```ts mcpConfig: object; ``` Configuration for MCP servers used by this agent. | Name | Type | Description | | --------------------------- | -------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `convertSchemasToStrict?` | `boolean` | Try to convert MCP tool schemas to strict JSON schema. | | `errorFunction?` | `MCPToolErrorFunction` \| `null` | Optional function to convert MCP tool failures into model-visible messages. Set to null to rethrow errors instead of converting them. Server-level errorFunction values take precedence. | | `includeServerInToolNames?` | `boolean` | Prefix local MCP tool names with their server name before exposing them to the model. The SDK still invokes the original MCP tool name on the original server. | #### Inherited from [Section titled “Inherited from”](#inherited-from-4) ```ts Agent.mcpConfig ``` *** ### mcpServers [Section titled “mcpServers”](#mcpservers) ```ts mcpServers: MCPServer[]; ``` A list of [Model Context Protocol](https://modelcontextprotocol.io/) servers the agent can use. Every time the agent runs, it will include tools from these servers in the list of available tools. NOTE: You are expected to manage the lifecycle of these servers. Specifically, you must call `server.connect()` before passing it to the agent, and `server.close()` when the server is no longer needed. Consider using `connectMcpServers` or `MCPServers` to keep open/close in the same place. #### Inherited from [Section titled “Inherited from”](#inherited-from-5) ```ts Agent.mcpServers ``` *** ### model [Section titled “model”](#model) ```ts model: string | Model; ``` The model implementation to use when invoking the LLM. By default, if not set, the agent will use the default model returned by getDefaultModel (currently “gpt-5.4-mini”). #### Inherited from [Section titled “Inherited from”](#inherited-from-6) ```ts Agent.model ``` *** ### modelSettings [Section titled “modelSettings”](#modelsettings) ```ts modelSettings: ModelSettings; ``` Configures model-specific tuning parameters (e.g. temperature, top\_p, etc.) #### Inherited from [Section titled “Inherited from”](#inherited-from-7) ```ts Agent.modelSettings ``` *** ### name [Section titled “name”](#name) ```ts name: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-8) ```ts Agent.name ``` *** ### outputGuardrails [Section titled “outputGuardrails”](#outputguardrails) ```ts outputGuardrails: OutputGuardrail, RealtimeContextData>[]; ``` A list of checks that run on the final output of the agent, after generating a response. Runs only if the agent produces a final output. #### Inherited from [Section titled “Inherited from”](#inherited-from-9) ```ts Agent.outputGuardrails ``` *** ### outputType [Section titled “outputType”](#outputtype) ```ts outputType: "text"; ``` The type of the output object. If not provided, the output will be a string. #### Inherited from [Section titled “Inherited from”](#inherited-from-10) ```ts Agent.outputType ``` *** ### prompt? [Section titled “prompt?”](#prompt) ```ts optional prompt?: Prompt | ((runContext, agent) => Prompt | Promise); ``` The prompt template to use for the agent (OpenAI Responses API only). Can either be a prompt template object, or a function that returns a prompt template object. If a function is provided, it will be called with the run context and the agent instance. It must return a prompt template object. #### Inherited from [Section titled “Inherited from”](#inherited-from-11) ```ts Agent.prompt ``` *** ### resetToolChoice [Section titled “resetToolChoice”](#resettoolchoice) ```ts resetToolChoice: boolean; ``` Whether to reset the tool choice to the default value after a tool has been called. Defaults to `true`. This ensures that the agent doesn’t enter an infinite loop of tool usage. #### Inherited from [Section titled “Inherited from”](#inherited-from-12) ```ts Agent.resetToolChoice ``` *** ### tools [Section titled “tools”](#tools) ```ts tools: Tool>[]; ``` A list of tools the agent can use. #### Inherited from [Section titled “Inherited from”](#inherited-from-13) ```ts Agent.tools ``` *** ### toolUseBehavior [Section titled “toolUseBehavior”](#toolusebehavior) ```ts toolUseBehavior: ToolUseBehavior; ``` This lets you configure how tool use is handled. * run\_llm\_again: The default behavior. Tools are run, and then the LLM receives the results and gets to respond. * stop\_on\_first\_tool: The output of the first tool call is used as the final output. This means that the LLM does not process the result of the tool call. * A list of tool names: The agent will stop running if any of the tools in the list are called. The final output will be the output of the first matching tool call. The LLM does not process the result of the tool call. * A function: if you pass a function, it will be called with the run context and the list of tool results. It must return a `ToolsToFinalOutputResult`, which determines whether the tool call resulted in a final output. NOTE: This configuration is specific to `FunctionTools`. Hosted tools, such as file search, web search, etc. are always processed by the LLM #### Inherited from [Section titled “Inherited from”](#inherited-from-14) ```ts Agent.toolUseBehavior ``` *** ### voice? [Section titled “voice?”](#voice) ```ts readonly optional voice?: string; ``` The voice intended to be used by the agent. If another agent already spoke during the RealtimeSession, changing the voice during a handoff will fail. *** ### DEFAULT\_MODEL\_PLACEHOLDER [Section titled “DEFAULT\_MODEL\_PLACEHOLDER”](#default_model_placeholder) ```ts static DEFAULT_MODEL_PLACEHOLDER: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-15) ```ts Agent.DEFAULT_MODEL_PLACEHOLDER ``` ## Accessors [Section titled “Accessors”](#accessors) ### outputSchemaName [Section titled “outputSchemaName”](#outputschemaname) #### Get Signature [Section titled “Get Signature”](#get-signature) ```ts get outputSchemaName(): string; ``` Output schema name. ##### Returns [Section titled “Returns”](#returns-1) `string` #### Inherited from [Section titled “Inherited from”](#inherited-from-16) ```ts Agent.outputSchemaName ``` ## Methods [Section titled “Methods”](#methods) ### asTool() [Section titled “asTool()”](#astool) #### Call Signature [Section titled “Call Signature”](#call-signature) ```ts asTool(this, options): AgentTool, TAgent, ZodObject<{ input: ZodString; }, $strip>>; ``` Transform this agent into a tool, callable by other agents. This is different from handoffs in two ways: 1. In handoffs, the new agent receives the conversation history. In this tool, the new agent receives generated input. 2. In handoffs, the new agent takes over the conversation. In this tool, the new agent is called as a tool, and the conversation is continued by the original agent. ##### Type Parameters [Section titled “Type Parameters”](#type-parameters-1) | Type Parameter | Default type | | ----------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- | | `TAgent` *extends* `Agent`<[`RealtimeContextData`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimecontextdata/)<`TContext`>, `"text"`> | `Agent`<[`RealtimeContextData`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimecontextdata/)<`TContext`>, `"text"`> | ##### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | Description | | --------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------- | | `this` | `TAgent` | ‐ | | `options` | `AgentToolOptionsWithDefault`<[`RealtimeContextData`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimecontextdata/)<`TContext`>, `TAgent`> | Options for the tool. | ##### Returns [Section titled “Returns”](#returns-2) `AgentTool`<[`RealtimeContextData`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimecontextdata/)<`TContext`>, `TAgent`, `ZodObject`<{ `input`: `ZodString`; }, `$strip`>> A tool that runs the agent and returns the output text. ##### Inherited from [Section titled “Inherited from”](#inherited-from-17) ```ts Agent.asTool ``` #### Call Signature [Section titled “Call Signature”](#call-signature-1) ```ts asTool(this, options): AgentTool, TAgent, TParameters>; ``` Transform this agent into a tool, callable by other agents. This is different from handoffs in two ways: 1. In handoffs, the new agent receives the conversation history. In this tool, the new agent receives generated input. 2. In handoffs, the new agent takes over the conversation. In this tool, the new agent is called as a tool, and the conversation is continued by the original agent. ##### Type Parameters [Section titled “Type Parameters”](#type-parameters-2) | Type Parameter | Default type | | ----------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- | | `TAgent` *extends* `Agent`<[`RealtimeContextData`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimecontextdata/)<`TContext`>, `"text"`> | `Agent`<[`RealtimeContextData`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimecontextdata/)<`TContext`>, `"text"`> | | `TParameters` *extends* `AgentToolInputParameters` | `ZodObject`<{ `input`: `ZodString`; }, `$strip`> | ##### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | Description | | --------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------- | | `this` | `TAgent` | ‐ | | `options` | `AgentToolOptionsWithParameters`<[`RealtimeContextData`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimecontextdata/)<`TContext`>, `TAgent`, `TParameters`> | Options for the tool. | ##### Returns [Section titled “Returns”](#returns-3) `AgentTool`<[`RealtimeContextData`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimecontextdata/)<`TContext`>, `TAgent`, `TParameters`> A tool that runs the agent and returns the output text. ##### Inherited from [Section titled “Inherited from”](#inherited-from-18) ```ts Agent.asTool ``` *** ### clone() [Section titled “clone()”](#clone) ```ts clone(config): Agent, "text">; ``` Makes a copy of the agent, with the given arguments changed. For example, you could do: ```plaintext const newAgent = agent.clone({ instructions: 'New instructions' }) ``` #### Parameters [Section titled “Parameters”](#parameters-3) | Parameter | Type | Description | | --------- | ------------------------------------------------------ | ---------------------------------- | | `config` | `Partial`<`AgentConfiguration`<`TContext`, `TOutput`>> | A partial configuration to change. | #### Returns [Section titled “Returns”](#returns-4) `Agent`<[`RealtimeContextData`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimecontextdata/)<`TContext`>, `"text"`> A new agent with the given changes. #### Inherited from [Section titled “Inherited from”](#inherited-from-19) ```ts Agent.clone ``` *** ### emit() [Section titled “emit()”](#emit) ```ts emit(type, ...args): boolean; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-3) | Type Parameter | | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `K` *extends* keyof `AgentHookEvents`<[`RealtimeContextData`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimecontextdata/)<`TContext`>, `"text"`> | #### Parameters [Section titled “Parameters”](#parameters-4) | Parameter | Type | | --------- | -------------------------------------------------------------------------------------------------------------------------------------------------- | | `type` | `K` | | …`args` | `AgentHookEvents`<[`RealtimeContextData`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimecontextdata/)<`TContext`>, `"text"`>\[`K`] | #### Returns [Section titled “Returns”](#returns-5) `boolean` #### Inherited from [Section titled “Inherited from”](#inherited-from-20) ```ts Agent.emit ``` *** ### getAllTools() [Section titled “getAllTools()”](#getalltools) ```ts getAllTools(runContext): Promise>[]>; ``` ALl agent tools, including the MCPl and function tools. #### Parameters [Section titled “Parameters”](#parameters-5) | Parameter | Type | | ------------ | ----------------------------------------------------------------------------------------------------------------------------- | | `runContext` | `RunContext`<[`RealtimeContextData`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimecontextdata/)<`TContext`>> | #### Returns [Section titled “Returns”](#returns-6) `Promise`<`Tool`<[`RealtimeContextData`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimecontextdata/)<`TContext`>>\[]> all configured tools #### Inherited from [Section titled “Inherited from”](#inherited-from-21) ```ts Agent.getAllTools ``` *** ### getEnabledHandoffs() [Section titled “getEnabledHandoffs()”](#getenabledhandoffs) ```ts getEnabledHandoffs(runContext): Promise[]>; ``` Returns the handoffs that should be exposed to the model for the current run. Handoffs that provide an `isEnabled` function returning `false` are omitted. #### Parameters [Section titled “Parameters”](#parameters-6) | Parameter | Type | | ------------ | ----------------------------------------------------------------------------------------------------------------------------- | | `runContext` | `RunContext`<[`RealtimeContextData`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimecontextdata/)<`TContext`>> | #### Returns [Section titled “Returns”](#returns-7) `Promise`<`Handoff`<`any`, `any`>\[]> #### Inherited from [Section titled “Inherited from”](#inherited-from-22) ```ts Agent.getEnabledHandoffs ``` *** ### getMcpTools() [Section titled “getMcpTools()”](#getmcptools) ```ts getMcpTools(runContext): Promise>[]>; ``` Fetches the available tools from the MCP servers. #### Parameters [Section titled “Parameters”](#parameters-7) | Parameter | Type | | ------------ | ----------------------------------------------------------------------------------------------------------------------------- | | `runContext` | `RunContext`<[`RealtimeContextData`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimecontextdata/)<`TContext`>> | #### Returns [Section titled “Returns”](#returns-8) `Promise`<`Tool`<[`RealtimeContextData`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimecontextdata/)<`TContext`>>\[]> the MCP powered tools #### Inherited from [Section titled “Inherited from”](#inherited-from-23) ```ts Agent.getMcpTools ``` *** ### getPrompt() [Section titled “getPrompt()”](#getprompt) ```ts getPrompt(runContext): Promise; ``` Returns the prompt template for the agent, if defined. If the agent has a function as its prompt, this function will be called with the runContext and the agent instance. #### Parameters [Section titled “Parameters”](#parameters-8) | Parameter | Type | | ------------ | ----------------------------------------------------------------------------------------------------------------------------- | | `runContext` | `RunContext`<[`RealtimeContextData`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimecontextdata/)<`TContext`>> | #### Returns [Section titled “Returns”](#returns-9) `Promise`<`Prompt` | `undefined`> #### Inherited from [Section titled “Inherited from”](#inherited-from-24) ```ts Agent.getPrompt ``` *** ### getSystemPrompt() [Section titled “getSystemPrompt()”](#getsystemprompt) ```ts getSystemPrompt(runContext): Promise; ``` Returns the system prompt for the agent. If the agent has a function as its instructions, this function will be called with the runContext and the agent instance. #### Parameters [Section titled “Parameters”](#parameters-9) | Parameter | Type | | ------------ | ----------------------------------------------------------------------------------------------------------------------------- | | `runContext` | `RunContext`<[`RealtimeContextData`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimecontextdata/)<`TContext`>> | #### Returns [Section titled “Returns”](#returns-10) `Promise`<`string` | `undefined`> #### Inherited from [Section titled “Inherited from”](#inherited-from-25) ```ts Agent.getSystemPrompt ``` *** ### hasExplicitToolConfig() [Section titled “hasExplicitToolConfig()”](#hasexplicittoolconfig) ```ts hasExplicitToolConfig(): boolean; ``` #### Returns [Section titled “Returns”](#returns-11) `boolean` #### Inherited from [Section titled “Inherited from”](#inherited-from-26) ```ts Agent.hasExplicitToolConfig ``` *** ### off() [Section titled “off()”](#off) ```ts off(type, listener): EventEmitter; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-4) | Type Parameter | | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `K` *extends* keyof `AgentHookEvents`<[`RealtimeContextData`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimecontextdata/)<`TContext`>, `"text"`> | #### Parameters [Section titled “Parameters”](#parameters-10) | Parameter | Type | | ---------- | ------------------- | | `type` | `K` | | `listener` | (…`args`) => `void` | #### Returns [Section titled “Returns”](#returns-12) `EventEmitter`<`EventTypes`> #### Inherited from [Section titled “Inherited from”](#inherited-from-27) ```ts Agent.off ``` *** ### on() [Section titled “on()”](#on) ```ts on(type, listener): EventEmitter; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-5) | Type Parameter | | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `K` *extends* keyof `AgentHookEvents`<[`RealtimeContextData`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimecontextdata/)<`TContext`>, `"text"`> | #### Parameters [Section titled “Parameters”](#parameters-11) | Parameter | Type | | ---------- | ------------------- | | `type` | `K` | | `listener` | (…`args`) => `void` | #### Returns [Section titled “Returns”](#returns-13) `EventEmitter`<`EventTypes`> #### Inherited from [Section titled “Inherited from”](#inherited-from-28) ```ts Agent.on ``` *** ### once() [Section titled “once()”](#once) ```ts once(type, listener): EventEmitter; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-6) | Type Parameter | | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `K` *extends* keyof `AgentHookEvents`<[`RealtimeContextData`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimecontextdata/)<`TContext`>, `"text"`> | #### Parameters [Section titled “Parameters”](#parameters-12) | Parameter | Type | | ---------- | ------------------- | | `type` | `K` | | `listener` | (…`args`) => `void` | #### Returns [Section titled “Returns”](#returns-14) `EventEmitter`<`EventTypes`> #### Inherited from [Section titled “Inherited from”](#inherited-from-29) ```ts Agent.once ``` *** ### processFinalOutput() [Section titled “processFinalOutput()”](#processfinaloutput) ```ts processFinalOutput(output): string; ``` Processes the final output of the agent. #### Parameters [Section titled “Parameters”](#parameters-13) | Parameter | Type | Description | | --------- | -------- | ------------------------ | | `output` | `string` | The output of the agent. | #### Returns [Section titled “Returns”](#returns-15) `string` The parsed out. #### Inherited from [Section titled “Inherited from”](#inherited-from-30) ```ts Agent.processFinalOutput ``` *** ### toJSON() [Section titled “toJSON()”](#tojson) ```ts toJSON(): object; ``` Returns a JSON representation of the agent, which is serializable. #### Returns [Section titled “Returns”](#returns-16) `object` A JSON object containing the agent’s name. ##### name [Section titled “name”](#name-1) ```ts name: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-31) ```ts Agent.toJSON ``` *** ### create() [Section titled “create()”](#create) ```ts static create(config): Agent>; ``` Create an Agent with handoffs and automatically infer the union type for TOutput from the handoff agents’ output types. #### Type Parameters [Section titled “Type Parameters”](#type-parameters-7) | Type Parameter | Default type | | ----------------------------------------------------------------------------------- | ------------ | | `TOutput` *extends* `AgentOutputType`<`unknown`> | `"text"` | | `Handoffs` *extends* readonly (`Agent`<`any`, `any`> \| `Handoff`<`any`, `any`>)\[] | \[] | #### Parameters [Section titled “Parameters”](#parameters-14) | Parameter | Type | | --------- | ------------------------------------------------ | | `config` | `AgentConfigWithHandoffs`<`TOutput`, `Handoffs`> | #### Returns [Section titled “Returns”](#returns-17) `Agent`<`unknown`, `TOutput` | `HandoffsOutputUnion`<`Handoffs`>> #### Inherited from [Section titled “Inherited from”](#inherited-from-32) ```ts Agent.create ``` # RealtimeSession A `RealtimeSession` is the cornerstone of building Voice Agents. It’s the equivalent of a Runner in text-based agents except that it automatically handles multiple turns by maintaining a connection with the underlying transport layer. The session handles managing the local history copy, executes tools, runs output guardrails, and facilitates handoffs. The actual audio handling and generation of model responses is handled by the underlying transport layer. By default if you are using a browser with WebRTC support, the session will automatically use the WebRTC version of the OpenAI Realtime API. On the server or if you pass `websocket` as the transport layer, the session will establish a connection using WebSockets. In the case of WebRTC, in the browser, the transport layer will also automatically configure the microphone and audio output to be used by the session. You can also create a transport layer instance yourself and pass it in to have more control over the configuration or even extend the existing ones. Check out the `TwilioRealtimeTransportLayer` for an example of how to create a custom transport layer. ## Example [Section titled “Example”](#example) ```ts const agent = new RealtimeAgent({ name: 'my-agent', instructions: 'You are a helpful assistant that can answer questions and help with tasks.', }) const session = new RealtimeSession(agent); session.connect({ apiKey: 'your-api-key', }); ``` ## Extends [Section titled “Extends”](#extends) * `EventEmitter`<[`RealtimeSessionEventTypes`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimesessioneventtypes/)<`TBaseContext`>> ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | ------------ | | `TBaseContext` | `unknown` | ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new RealtimeSession(initialAgent, options?): RealtimeSession; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | -------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `initialAgent` | \| [`RealtimeAgent`](/openai-agents-js/openai/agents-realtime/classes/realtimeagent/)<`TBaseContext`> \| [`RealtimeAgent`](/openai-agents-js/openai/agents-realtime/classes/realtimeagent/)<[`RealtimeContextData`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimecontextdata/)<`TBaseContext`>> | | `options` | `Partial`<[`RealtimeSessionOptions`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimesessionoptions/)<`TBaseContext`>> | #### Returns [Section titled “Returns”](#returns) `RealtimeSession`<`TBaseContext`> #### Overrides [Section titled “Overrides”](#overrides) ```ts RuntimeEventEmitter>.constructor ``` ## Properties [Section titled “Properties”](#properties) ### initialAgent [Section titled “initialAgent”](#initialagent) ```ts readonly initialAgent: | RealtimeAgent | RealtimeAgent>; ``` *** ### options [Section titled “options”](#options) ```ts readonly options: Partial> = {}; ``` *** ### captureRejections [Section titled “captureRejections”](#capturerejections) ```ts static captureRejections: boolean; ``` Value: [boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type) Change the default `captureRejections` option on all new `EventEmitter` objects. #### Since [Section titled “Since”](#since) v13.4.0, v12.16.0 #### Inherited from [Section titled “Inherited from”](#inherited-from) ```ts RuntimeEventEmitter.captureRejections ``` *** ### captureRejectionSymbol [Section titled “captureRejectionSymbol”](#capturerejectionsymbol) ```ts readonly static captureRejectionSymbol: typeof captureRejectionSymbol; ``` Value: `Symbol.for('nodejs.rejection')` See how to write a custom `rejection handler`. #### Since [Section titled “Since”](#since-1) v13.4.0, v12.16.0 #### Inherited from [Section titled “Inherited from”](#inherited-from-1) ```ts RuntimeEventEmitter.captureRejectionSymbol ``` *** ### defaultMaxListeners [Section titled “defaultMaxListeners”](#defaultmaxlisteners) ```ts static defaultMaxListeners: number; ``` By default, a maximum of `10` listeners can be registered for any single event. This limit can be changed for individual `EventEmitter` instances using the `emitter.setMaxListeners(n)` method. To change the default for *all*`EventEmitter` instances, the `events.defaultMaxListeners` property can be used. If this value is not a positive number, a `RangeError` is thrown. Take caution when setting the `events.defaultMaxListeners` because the change affects *all* `EventEmitter` instances, including those created before the change is made. However, calling `emitter.setMaxListeners(n)` still has precedence over `events.defaultMaxListeners`. This is not a hard limit. The `EventEmitter` instance will allow more listeners to be added but will output a trace warning to stderr indicating that a “possible EventEmitter memory leak” has been detected. For any single `EventEmitter`, the `emitter.getMaxListeners()` and `emitter.setMaxListeners()` methods can be used to temporarily avoid this warning: ```js import { EventEmitter } from 'node:events'; const emitter = new EventEmitter(); emitter.setMaxListeners(emitter.getMaxListeners() + 1); emitter.once('event', () => { // do stuff emitter.setMaxListeners(Math.max(emitter.getMaxListeners() - 1, 0)); }); ``` The `--trace-warnings` command-line flag can be used to display the stack trace for such warnings. The emitted warning can be inspected with `process.on('warning')` and will have the additional `emitter`, `type`, and `count` properties, referring to the event emitter instance, the event’s name and the number of attached listeners, respectively. Its `name` property is set to `'MaxListenersExceededWarning'`. #### Since [Section titled “Since”](#since-2) v0.11.2 #### Inherited from [Section titled “Inherited from”](#inherited-from-2) ```ts RuntimeEventEmitter.defaultMaxListeners ``` *** ### errorMonitor [Section titled “errorMonitor”](#errormonitor) ```ts readonly static errorMonitor: typeof errorMonitor; ``` This symbol shall be used to install a listener for only monitoring `'error'` events. Listeners installed using this symbol are called before the regular `'error'` listeners are called. Installing a listener using this symbol does not change the behavior once an `'error'` event is emitted. Therefore, the process will still crash if no regular `'error'` listener is installed. #### Since [Section titled “Since”](#since-3) v13.6.0, v12.17.0 #### Inherited from [Section titled “Inherited from”](#inherited-from-3) ```ts RuntimeEventEmitter.errorMonitor ``` ## Accessors [Section titled “Accessors”](#accessors) ### availableMcpTools [Section titled “availableMcpTools”](#availablemcptools) #### Get Signature [Section titled “Get Signature”](#get-signature) ```ts get availableMcpTools(): RealtimeMcpToolInfo[]; ``` ##### Returns [Section titled “Returns”](#returns-1) `RealtimeMcpToolInfo`\[] *** ### context [Section titled “context”](#context) #### Get Signature [Section titled “Get Signature”](#get-signature-1) ```ts get context(): RunContext>; ``` The current context of the session. ##### Returns [Section titled “Returns”](#returns-2) `RunContext`<[`RealtimeContextData`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimecontextdata/)<`TBaseContext`>> *** ### currentAgent [Section titled “currentAgent”](#currentagent) #### Get Signature [Section titled “Get Signature”](#get-signature-2) ```ts get currentAgent(): | RealtimeAgent | RealtimeAgent>; ``` The current agent in the session. ##### Returns [Section titled “Returns”](#returns-3) \| [`RealtimeAgent`](/openai-agents-js/openai/agents-realtime/classes/realtimeagent/)<`TBaseContext`> | [`RealtimeAgent`](/openai-agents-js/openai/agents-realtime/classes/realtimeagent/)<[`RealtimeContextData`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimecontextdata/)<`TBaseContext`>> *** ### history [Section titled “history”](#history) #### Get Signature [Section titled “Get Signature”](#get-signature-3) ```ts get history(): RealtimeItem[]; ``` The history of the session. ##### Returns [Section titled “Returns”](#returns-4) [`RealtimeItem`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimeitem/)\[] *** ### muted [Section titled “muted”](#muted) #### Get Signature [Section titled “Get Signature”](#get-signature-4) ```ts get muted(): boolean | null; ``` Whether the session is muted. Might be `null` if the underlying transport layer does not support muting. ##### Returns [Section titled “Returns”](#returns-5) `boolean` | `null` *** ### transport [Section titled “transport”](#transport) #### Get Signature [Section titled “Get Signature”](#get-signature-5) ```ts get transport(): RealtimeTransportLayer; ``` The transport layer used by the session. ##### Returns [Section titled “Returns”](#returns-6) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/) *** ### usage [Section titled “usage”](#usage) #### Get Signature [Section titled “Get Signature”](#get-signature-6) ```ts get usage(): Usage; ``` The current usage of the session. ##### Returns [Section titled “Returns”](#returns-7) `Usage` ## Methods [Section titled “Methods”](#methods) ### \[captureRejectionSymbol]\()? [Section titled “\[captureRejectionSymbol\]()?”](#capturerejectionsymbol-1) ```ts optional [captureRejectionSymbol]( error, event, ... args): void; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-1) | Type Parameter | | -------------- | | `K` | #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `error` | `Error` | | `event` | keyof RealtimeSessionEventTypes\ \| `K` | | …`args` | `K` *extends* keyof [`RealtimeSessionEventTypes`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimesessioneventtypes/)<`TBaseContext`> ? [`RealtimeSessionEventTypes`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimesessioneventtypes/)<`TBaseContext`>\[`K`] : `never` | #### Returns [Section titled “Returns”](#returns-8) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-4) ```ts RuntimeEventEmitter.[captureRejectionSymbol] ``` *** ### addImage() [Section titled “addImage()”](#addimage) ```ts addImage(image, __namedParameters?): void; ``` Add image to the session #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | Description | | ------------------------------------ | ---------------------------------- | ----------------- | | `image` | `string` | The image to add. | | `__namedParameters` | { `triggerResponse?`: `boolean`; } | ‐ | | `__namedParameters.triggerResponse?` | `boolean` | ‐ | #### Returns [Section titled “Returns”](#returns-9) `void` *** ### addListener() [Section titled “addListener()”](#addlistener) ```ts addListener(eventName, listener): this; ``` Alias for `emitter.on(eventName, listener)`. #### Type Parameters [Section titled “Type Parameters”](#type-parameters-2) | Type Parameter | | -------------- | | `K` | #### Parameters [Section titled “Parameters”](#parameters-3) | Parameter | Type | | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | `eventName` | keyof RealtimeSessionEventTypes\ \| `K` | | `listener` | `K` *extends* keyof [`RealtimeSessionEventTypes`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimesessioneventtypes/)<`TBaseContext`> ? [`RealtimeSessionEventTypes`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimesessioneventtypes/)<`TBaseContext`>\[`K`] *extends* `unknown`\[] ? (…`args`) => `void` : `never` : `never` | #### Returns [Section titled “Returns”](#returns-10) `this` #### Since [Section titled “Since”](#since-4) v0.1.26 #### Inherited from [Section titled “Inherited from”](#inherited-from-5) ```ts RuntimeEventEmitter.addListener ``` *** ### approve() [Section titled “approve()”](#approve) ```ts approve(approvalItem, options?): Promise; ``` Approve a tool call. This will also trigger the tool call to the agent. #### Parameters [Section titled “Parameters”](#parameters-4) | Parameter | Type | Description | | ------------------------ | -------------------------------- | ---------------------------------------- | | `approvalItem` | `RunToolApprovalItem` | The approval item to approve. | | `options` | { `alwaysApprove?`: `boolean`; } | Additional options. | | `options.alwaysApprove?` | `boolean` | Whether to always approve the tool call. | #### Returns [Section titled “Returns”](#returns-11) `Promise`<`void`> *** ### close() [Section titled “close()”](#close) ```ts close(): void; ``` Disconnect from the session. #### Returns [Section titled “Returns”](#returns-12) `void` *** ### connect() [Section titled “connect()”](#connect) ```ts connect(options): Promise; ``` Connect to the session. This will establish the connection to the underlying transport layer and start the session. After connecting, the session will also emit a `history_updated` event with an empty history. #### Parameters [Section titled “Parameters”](#parameters-5) | Parameter | Type | Description | | --------- | ----------------------------------------------------------------------------------------------------------------------- | ------------------------------- | | `options` | [`RealtimeSessionConnectOptions`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimesessionconnectoptions/) | The options for the connection. | #### Returns [Section titled “Returns”](#returns-13) `Promise`<`void`> *** ### emit() [Section titled “emit()”](#emit) ```ts emit(eventName, ...args): boolean; ``` Synchronously calls each of the listeners registered for the event named `eventName`, in the order they were registered, passing the supplied arguments to each. Returns `true` if the event had listeners, `false` otherwise. ```js import { EventEmitter } from 'node:events'; const myEmitter = new EventEmitter(); // First listener myEmitter.on('event', function firstListener() { console.log('Helloooo! first listener'); }); // Second listener myEmitter.on('event', function secondListener(arg1, arg2) { console.log(`event with parameters ${arg1}, ${arg2} in second listener`); }); // Third listener myEmitter.on('event', function thirdListener(...args) { const parameters = args.join(', '); console.log(`event with parameters ${parameters} in third listener`); }); console.log(myEmitter.listeners('event')); myEmitter.emit('event', 1, 2, 3, 4, 5); // Prints: // [ // [Function: firstListener], // [Function: secondListener], // [Function: thirdListener] // ] // Helloooo! first listener // event with parameters 1, 2 in second listener // event with parameters 1, 2, 3, 4, 5 in third listener ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-3) | Type Parameter | | -------------- | | `K` | #### Parameters [Section titled “Parameters”](#parameters-6) | Parameter | Type | | ----------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `eventName` | keyof RealtimeSessionEventTypes\ \| `K` | | …`args` | `K` *extends* keyof [`RealtimeSessionEventTypes`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimesessioneventtypes/)<`TBaseContext`> ? [`RealtimeSessionEventTypes`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimesessioneventtypes/)<`TBaseContext`>\[`K`] : `never` | #### Returns [Section titled “Returns”](#returns-14) `boolean` #### Since [Section titled “Since”](#since-5) v0.1.26 #### Inherited from [Section titled “Inherited from”](#inherited-from-6) ```ts RuntimeEventEmitter.emit ``` *** ### eventNames() [Section titled “eventNames()”](#eventnames) ```ts eventNames(): ( | "audio" | "error" | "audio_interrupted" | "mcp_tool_call_completed" | "agent_start" | "agent_end" | "agent_handoff" | "agent_tool_start" | "agent_tool_end" | "transport_event" | "audio_start" | "audio_stopped" | "guardrail_tripped" | "history_updated" | "history_added" | "tool_approval_requested" | "mcp_tools_changed")[]; ``` Returns an array listing the events for which the emitter has registered listeners. The values in the array are strings or `Symbol`s. ```js import { EventEmitter } from 'node:events'; const myEE = new EventEmitter(); myEE.on('foo', () => {}); myEE.on('bar', () => {}); const sym = Symbol('symbol'); myEE.on(sym, () => {}); console.log(myEE.eventNames()); // Prints: [ 'foo', 'bar', Symbol(symbol) ] ``` #### Returns [Section titled “Returns”](#returns-15) ( | `"audio"` | `"error"` | `"audio_interrupted"` | `"mcp_tool_call_completed"` | `"agent_start"` | `"agent_end"` | `"agent_handoff"` | `"agent_tool_start"` | `"agent_tool_end"` | `"transport_event"` | `"audio_start"` | `"audio_stopped"` | `"guardrail_tripped"` | `"history_updated"` | `"history_added"` | `"tool_approval_requested"` | `"mcp_tools_changed"`)\[] #### Since [Section titled “Since”](#since-6) v6.0.0 #### Inherited from [Section titled “Inherited from”](#inherited-from-7) ```ts RuntimeEventEmitter.eventNames ``` *** ### getInitialSessionConfig() [Section titled “getInitialSessionConfig()”](#getinitialsessionconfig) ```ts getInitialSessionConfig(overrides?): Promise>; ``` Compute the initial session config that the current session will use when connecting. This mirrors the configuration payload we send during `connect`, including dynamic values such as the upstream agent instructions, tool definitions, and prompt content generated at runtime. Keeping this helper exposed allows transports or orchestration layers to precompute a CallAccept-compatible payload without opening a socket. #### Parameters [Section titled “Parameters”](#parameters-7) | Parameter | Type | Description | | ----------- | ------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------ | | `overrides` | `Partial`<[`RealtimeSessionConfig`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimesessionconfig/)> | Additional config overrides applied on top of the session options. | #### Returns [Section titled “Returns”](#returns-16) `Promise`<`Partial`<[`RealtimeSessionConfig`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimesessionconfig/)>> *** ### getMaxListeners() [Section titled “getMaxListeners()”](#getmaxlisteners) ```ts getMaxListeners(): number; ``` Returns the current max listener value for the `EventEmitter` which is either set by `emitter.setMaxListeners(n)` or defaults to [EventEmitter.defaultMaxListeners](/openai-agents-js/openai/agents-realtime/classes/realtimesession/#defaultmaxlisteners). #### Returns [Section titled “Returns”](#returns-17) `number` #### Since [Section titled “Since”](#since-7) v1.0.0 #### Inherited from [Section titled “Inherited from”](#inherited-from-8) ```ts RuntimeEventEmitter.getMaxListeners ``` *** ### interrupt() [Section titled “interrupt()”](#interrupt) ```ts interrupt(): void; ``` Interrupt the session artificially for example if you want to build a “stop talking” button. #### Returns [Section titled “Returns”](#returns-18) `void` *** ### listenerCount() [Section titled “listenerCount()”](#listenercount) ```ts listenerCount(eventName, listener?): number; ``` Returns the number of listeners listening for the event named `eventName`. If `listener` is provided, it will return how many times the listener is found in the list of the listeners of the event. #### Type Parameters [Section titled “Type Parameters”](#type-parameters-4) | Type Parameter | | -------------- | | `K` | #### Parameters [Section titled “Parameters”](#parameters-8) | Parameter | Type | Description | | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------- | | `eventName` | keyof RealtimeSessionEventTypes\ \| `K` | The name of the event being listened for | | `listener?` | `K` *extends* keyof [`RealtimeSessionEventTypes`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimesessioneventtypes/)<`TBaseContext`> ? [`RealtimeSessionEventTypes`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimesessioneventtypes/)<`TBaseContext`>\[`K`] *extends* `unknown`\[] ? (…`args`) => `void` : `never` : `never` | The event handler function | #### Returns [Section titled “Returns”](#returns-19) `number` #### Since [Section titled “Since”](#since-8) v3.2.0 #### Inherited from [Section titled “Inherited from”](#inherited-from-9) ```ts RuntimeEventEmitter.listenerCount ``` *** ### listeners() [Section titled “listeners()”](#listeners) ```ts listeners(eventName): K extends keyof RealtimeSessionEventTypes ? RealtimeSessionEventTypes[K] extends unknown[] ? (...args) => void : never : never[]; ``` Returns a copy of the array of listeners for the event named `eventName`. ```js server.on('connection', (stream) => { console.log('someone connected!'); }); console.log(util.inspect(server.listeners('connection'))); // Prints: [ [Function] ] ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-5) | Type Parameter | | -------------- | | `K` | #### Parameters [Section titled “Parameters”](#parameters-9) | Parameter | Type | | ----------- | ----------------------------------------------------- | | `eventName` | keyof RealtimeSessionEventTypes\ \| `K` | #### Returns [Section titled “Returns”](#returns-20) `K` *extends* keyof [`RealtimeSessionEventTypes`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimesessioneventtypes/)<`TBaseContext`> ? [`RealtimeSessionEventTypes`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimesessioneventtypes/)<`TBaseContext`>\[`K`] *extends* `unknown`\[] ? (…`args`) => `void` : `never` : `never`\[] #### Since [Section titled “Since”](#since-9) v0.1.26 #### Inherited from [Section titled “Inherited from”](#inherited-from-10) ```ts RuntimeEventEmitter.listeners ``` *** ### mute() [Section titled “mute()”](#mute) ```ts mute(muted): void; ``` Mute the session. #### Parameters [Section titled “Parameters”](#parameters-10) | Parameter | Type | Description | | --------- | --------- | ---------------------------- | | `muted` | `boolean` | Whether to mute the session. | #### Returns [Section titled “Returns”](#returns-21) `void` *** ### off() [Section titled “off()”](#off) ```ts off(eventName, listener): this; ``` Alias for `emitter.removeListener()`. #### Type Parameters [Section titled “Type Parameters”](#type-parameters-6) | Type Parameter | | -------------- | | `K` | #### Parameters [Section titled “Parameters”](#parameters-11) | Parameter | Type | | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | `eventName` | keyof RealtimeSessionEventTypes\ \| `K` | | `listener` | `K` *extends* keyof [`RealtimeSessionEventTypes`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimesessioneventtypes/)<`TBaseContext`> ? [`RealtimeSessionEventTypes`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimesessioneventtypes/)<`TBaseContext`>\[`K`] *extends* `unknown`\[] ? (…`args`) => `void` : `never` : `never` | #### Returns [Section titled “Returns”](#returns-22) `this` #### Since [Section titled “Since”](#since-10) v10.0.0 #### Inherited from [Section titled “Inherited from”](#inherited-from-11) ```ts RuntimeEventEmitter.off ``` *** ### on() [Section titled “on()”](#on) ```ts on(eventName, listener): this; ``` Adds the `listener` function to the end of the listeners array for the event named `eventName`. No checks are made to see if the `listener` has already been added. Multiple calls passing the same combination of `eventName` and `listener` will result in the `listener` being added, and called, multiple times. ```js server.on('connection', (stream) => { console.log('someone connected!'); }); ``` Returns a reference to the `EventEmitter`, so that calls can be chained. By default, event listeners are invoked in the order they are added. The `emitter.prependListener()` method can be used as an alternative to add the event listener to the beginning of the listeners array. ```js import { EventEmitter } from 'node:events'; const myEE = new EventEmitter(); myEE.on('foo', () => console.log('a')); myEE.prependListener('foo', () => console.log('b')); myEE.emit('foo'); // Prints: // b // a ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-7) | Type Parameter | | -------------- | | `K` | #### Parameters [Section titled “Parameters”](#parameters-12) | Parameter | Type | Description | | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------- | | `eventName` | keyof RealtimeSessionEventTypes\ \| `K` | The name of the event. | | `listener` | `K` *extends* keyof [`RealtimeSessionEventTypes`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimesessioneventtypes/)<`TBaseContext`> ? [`RealtimeSessionEventTypes`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimesessioneventtypes/)<`TBaseContext`>\[`K`] *extends* `unknown`\[] ? (…`args`) => `void` : `never` : `never` | The callback function | #### Returns [Section titled “Returns”](#returns-23) `this` #### Since [Section titled “Since”](#since-11) v0.1.101 #### Inherited from [Section titled “Inherited from”](#inherited-from-12) ```ts RuntimeEventEmitter.on ``` *** ### once() [Section titled “once()”](#once) ```ts once(eventName, listener): this; ``` Adds a **one-time** `listener` function for the event named `eventName`. The next time `eventName` is triggered, this listener is removed and then invoked. ```js server.once('connection', (stream) => { console.log('Ah, we have our first user!'); }); ``` Returns a reference to the `EventEmitter`, so that calls can be chained. By default, event listeners are invoked in the order they are added. The `emitter.prependOnceListener()` method can be used as an alternative to add the event listener to the beginning of the listeners array. ```js import { EventEmitter } from 'node:events'; const myEE = new EventEmitter(); myEE.once('foo', () => console.log('a')); myEE.prependOnceListener('foo', () => console.log('b')); myEE.emit('foo'); // Prints: // b // a ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-8) | Type Parameter | | -------------- | | `K` | #### Parameters [Section titled “Parameters”](#parameters-13) | Parameter | Type | Description | | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------- | | `eventName` | keyof RealtimeSessionEventTypes\ \| `K` | The name of the event. | | `listener` | `K` *extends* keyof [`RealtimeSessionEventTypes`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimesessioneventtypes/)<`TBaseContext`> ? [`RealtimeSessionEventTypes`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimesessioneventtypes/)<`TBaseContext`>\[`K`] *extends* `unknown`\[] ? (…`args`) => `void` : `never` : `never` | The callback function | #### Returns [Section titled “Returns”](#returns-24) `this` #### Since [Section titled “Since”](#since-12) v0.3.0 #### Inherited from [Section titled “Inherited from”](#inherited-from-13) ```ts RuntimeEventEmitter.once ``` *** ### prependListener() [Section titled “prependListener()”](#prependlistener) ```ts prependListener(eventName, listener): this; ``` Adds the `listener` function to the *beginning* of the listeners array for the event named `eventName`. No checks are made to see if the `listener` has already been added. Multiple calls passing the same combination of `eventName` and `listener` will result in the `listener` being added, and called, multiple times. ```js server.prependListener('connection', (stream) => { console.log('someone connected!'); }); ``` Returns a reference to the `EventEmitter`, so that calls can be chained. #### Type Parameters [Section titled “Type Parameters”](#type-parameters-9) | Type Parameter | | -------------- | | `K` | #### Parameters [Section titled “Parameters”](#parameters-14) | Parameter | Type | Description | | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------- | | `eventName` | keyof RealtimeSessionEventTypes\ \| `K` | The name of the event. | | `listener` | `K` *extends* keyof [`RealtimeSessionEventTypes`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimesessioneventtypes/)<`TBaseContext`> ? [`RealtimeSessionEventTypes`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimesessioneventtypes/)<`TBaseContext`>\[`K`] *extends* `unknown`\[] ? (…`args`) => `void` : `never` : `never` | The callback function | #### Returns [Section titled “Returns”](#returns-25) `this` #### Since [Section titled “Since”](#since-13) v6.0.0 #### Inherited from [Section titled “Inherited from”](#inherited-from-14) ```ts RuntimeEventEmitter.prependListener ``` *** ### prependOnceListener() [Section titled “prependOnceListener()”](#prependoncelistener) ```ts prependOnceListener(eventName, listener): this; ``` Adds a **one-time**`listener` function for the event named `eventName` to the *beginning* of the listeners array. The next time `eventName` is triggered, this listener is removed, and then invoked. ```js server.prependOnceListener('connection', (stream) => { console.log('Ah, we have our first user!'); }); ``` Returns a reference to the `EventEmitter`, so that calls can be chained. #### Type Parameters [Section titled “Type Parameters”](#type-parameters-10) | Type Parameter | | -------------- | | `K` | #### Parameters [Section titled “Parameters”](#parameters-15) | Parameter | Type | Description | | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------- | | `eventName` | keyof RealtimeSessionEventTypes\ \| `K` | The name of the event. | | `listener` | `K` *extends* keyof [`RealtimeSessionEventTypes`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimesessioneventtypes/)<`TBaseContext`> ? [`RealtimeSessionEventTypes`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimesessioneventtypes/)<`TBaseContext`>\[`K`] *extends* `unknown`\[] ? (…`args`) => `void` : `never` : `never` | The callback function | #### Returns [Section titled “Returns”](#returns-26) `this` #### Since [Section titled “Since”](#since-14) v6.0.0 #### Inherited from [Section titled “Inherited from”](#inherited-from-15) ```ts RuntimeEventEmitter.prependOnceListener ``` *** ### rawListeners() [Section titled “rawListeners()”](#rawlisteners) ```ts rawListeners(eventName): K extends keyof RealtimeSessionEventTypes ? RealtimeSessionEventTypes[K] extends unknown[] ? (...args) => void : never : never[]; ``` Returns a copy of the array of listeners for the event named `eventName`, including any wrappers (such as those created by `.once()`). ```js import { EventEmitter } from 'node:events'; const emitter = new EventEmitter(); emitter.once('log', () => console.log('log once')); // Returns a new Array with a function `onceWrapper` which has a property // `listener` which contains the original listener bound above const listeners = emitter.rawListeners('log'); const logFnWrapper = listeners[0]; // Logs "log once" to the console and does not unbind the `once` event logFnWrapper.listener(); // Logs "log once" to the console and removes the listener logFnWrapper(); emitter.on('log', () => console.log('log persistently')); // Will return a new Array with a single function bound by `.on()` above const newListeners = emitter.rawListeners('log'); // Logs "log persistently" twice newListeners[0](); emitter.emit('log'); ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-11) | Type Parameter | | -------------- | | `K` | #### Parameters [Section titled “Parameters”](#parameters-16) | Parameter | Type | | ----------- | ----------------------------------------------------- | | `eventName` | keyof RealtimeSessionEventTypes\ \| `K` | #### Returns [Section titled “Returns”](#returns-27) `K` *extends* keyof [`RealtimeSessionEventTypes`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimesessioneventtypes/)<`TBaseContext`> ? [`RealtimeSessionEventTypes`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimesessioneventtypes/)<`TBaseContext`>\[`K`] *extends* `unknown`\[] ? (…`args`) => `void` : `never` : `never`\[] #### Since [Section titled “Since”](#since-15) v9.4.0 #### Inherited from [Section titled “Inherited from”](#inherited-from-16) ```ts RuntimeEventEmitter.rawListeners ``` *** ### reject() [Section titled “reject()”](#reject) ```ts reject(approvalItem, options?): Promise; ``` Reject a tool call. This will also trigger the tool call to the agent. #### Parameters [Section titled “Parameters”](#parameters-17) | Parameter | Type | Description | | ----------------------- | ----------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------- | | `approvalItem` | `RunToolApprovalItem` | The approval item to reject. | | `options` | { `alwaysReject?`: `boolean`; `message?`: `string`; } | Additional options. | | `options.alwaysReject?` | `boolean` | Whether to always reject the tool call. | | `options.message?` | `string` | The rejection text sent to the model. If not provided, `toolErrorFormatter` (if configured) or the SDK default is used. | #### Returns [Section titled “Returns”](#returns-28) `Promise`<`void`> *** ### removeAllListeners() [Section titled “removeAllListeners()”](#removealllisteners) ```ts removeAllListeners(eventName?): this; ``` Removes all listeners, or those of the specified `eventName`. It is bad practice to remove listeners added elsewhere in the code, particularly when the `EventEmitter` instance was created by some other component or module (e.g. sockets or file streams). Returns a reference to the `EventEmitter`, so that calls can be chained. #### Parameters [Section titled “Parameters”](#parameters-18) | Parameter | Type | | ------------ | --------- | | `eventName?` | `unknown` | #### Returns [Section titled “Returns”](#returns-29) `this` #### Since [Section titled “Since”](#since-16) v0.1.26 #### Inherited from [Section titled “Inherited from”](#inherited-from-17) ```ts RuntimeEventEmitter.removeAllListeners ``` *** ### removeListener() [Section titled “removeListener()”](#removelistener) ```ts removeListener(eventName, listener): this; ``` Removes the specified `listener` from the listener array for the event named `eventName`. ```js const callback = (stream) => { console.log('someone connected!'); }; server.on('connection', callback); // ... server.removeListener('connection', callback); ``` `removeListener()` will remove, at most, one instance of a listener from the listener array. If any single listener has been added multiple times to the listener array for the specified `eventName`, then `removeListener()` must be called multiple times to remove each instance. Once an event is emitted, all listeners attached to it at the time of emitting are called in order. This implies that any `removeListener()` or `removeAllListeners()` calls *after* emitting and *before* the last listener finishes execution will not remove them from`emit()` in progress. Subsequent events behave as expected. ```js import { EventEmitter } from 'node:events'; class MyEmitter extends EventEmitter {} const myEmitter = new MyEmitter(); const callbackA = () => { console.log('A'); myEmitter.removeListener('event', callbackB); }; const callbackB = () => { console.log('B'); }; myEmitter.on('event', callbackA); myEmitter.on('event', callbackB); // callbackA removes listener callbackB but it will still be called. // Internal listener array at time of emit [callbackA, callbackB] myEmitter.emit('event'); // Prints: // A // B // callbackB is now removed. // Internal listener array [callbackA] myEmitter.emit('event'); // Prints: // A ``` Because listeners are managed using an internal array, calling this will change the position indices of any listener registered *after* the listener being removed. This will not impact the order in which listeners are called, but it means that any copies of the listener array as returned by the `emitter.listeners()` method will need to be recreated. When a single function has been added as a handler multiple times for a single event (as in the example below), `removeListener()` will remove the most recently added instance. In the example the `once('ping')` listener is removed: ```js import { EventEmitter } from 'node:events'; const ee = new EventEmitter(); function pong() { console.log('pong'); } ee.on('ping', pong); ee.once('ping', pong); ee.removeListener('ping', pong); ee.emit('ping'); ee.emit('ping'); ``` Returns a reference to the `EventEmitter`, so that calls can be chained. #### Type Parameters [Section titled “Type Parameters”](#type-parameters-12) | Type Parameter | | -------------- | | `K` | #### Parameters [Section titled “Parameters”](#parameters-19) | Parameter | Type | | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | `eventName` | keyof RealtimeSessionEventTypes\ \| `K` | | `listener` | `K` *extends* keyof [`RealtimeSessionEventTypes`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimesessioneventtypes/)<`TBaseContext`> ? [`RealtimeSessionEventTypes`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimesessioneventtypes/)<`TBaseContext`>\[`K`] *extends* `unknown`\[] ? (…`args`) => `void` : `never` : `never` | #### Returns [Section titled “Returns”](#returns-30) `this` #### Since [Section titled “Since”](#since-17) v0.1.26 #### Inherited from [Section titled “Inherited from”](#inherited-from-18) ```ts RuntimeEventEmitter.removeListener ``` *** ### sendAudio() [Section titled “sendAudio()”](#sendaudio) ```ts sendAudio(audio, options?): void; ``` Send audio to the session. #### Parameters [Section titled “Parameters”](#parameters-20) | Parameter | Type | Description | | ----------------- | ------------------------- | ------------------------------------------- | | `audio` | `ArrayBuffer` | The audio to send. | | `options` | { `commit?`: `boolean`; } | Additional options. | | `options.commit?` | `boolean` | Whether to finish the turn with this audio. | #### Returns [Section titled “Returns”](#returns-31) `void` *** ### sendMessage() [Section titled “sendMessage()”](#sendmessage) ```ts sendMessage(message, otherEventData?): void; ``` Send a message to the session. #### Parameters [Section titled “Parameters”](#parameters-21) | Parameter | Type | Description | | ---------------- | ------------------------- | ------------------------------ | | `message` | `RealtimeUserInput` | The message to send. | | `otherEventData` | `Record`<`string`, `any`> | Additional event data to send. | #### Returns [Section titled “Returns”](#returns-32) `void` *** ### setMaxListeners() [Section titled “setMaxListeners()”](#setmaxlisteners) ```ts setMaxListeners(n): this; ``` By default `EventEmitter`s will print a warning if more than `10` listeners are added for a particular event. This is a useful default that helps finding memory leaks. The `emitter.setMaxListeners()` method allows the limit to be modified for this specific `EventEmitter` instance. The value can be set to `Infinity` (or `0`) to indicate an unlimited number of listeners. Returns a reference to the `EventEmitter`, so that calls can be chained. #### Parameters [Section titled “Parameters”](#parameters-22) | Parameter | Type | | --------- | -------- | | `n` | `number` | #### Returns [Section titled “Returns”](#returns-33) `this` #### Since [Section titled “Since”](#since-18) v0.3.5 #### Inherited from [Section titled “Inherited from”](#inherited-from-19) ```ts RuntimeEventEmitter.setMaxListeners ``` *** ### updateAgent() [Section titled “updateAgent()”](#updateagent) ```ts updateAgent(newAgent): Promise>; ``` #### Parameters [Section titled “Parameters”](#parameters-23) | Parameter | Type | | ---------- | -------------------------------------------------------------------------------------------------- | | `newAgent` | [`RealtimeAgent`](/openai-agents-js/openai/agents-realtime/classes/realtimeagent/)<`TBaseContext`> | #### Returns [Section titled “Returns”](#returns-34) `Promise`<[`RealtimeAgent`](/openai-agents-js/openai/agents-realtime/classes/realtimeagent/)<`TBaseContext`>> *** ### updateHistory() [Section titled “updateHistory()”](#updatehistory) ```ts updateHistory(newHistory): void; ``` Update the history of the session. #### Parameters [Section titled “Parameters”](#parameters-24) | Parameter | Type | Description | | ------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------- | | `newHistory` | \| [`RealtimeItem`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimeitem/)\[] \| ((`history`) => [`RealtimeItem`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimeitem/)\[]) | The new history to set. | #### Returns [Section titled “Returns”](#returns-35) `void` *** ### addAbortListener() [Section titled “addAbortListener()”](#addabortlistener) ```ts static addAbortListener(signal, resource): Disposable; ``` Listens once to the `abort` event on the provided `signal`. Listening to the `abort` event on abort signals is unsafe and may lead to resource leaks since another third party with the signal can call `e.stopImmediatePropagation()`. Unfortunately Node.js cannot change this since it would violate the web standard. Additionally, the original API makes it easy to forget to remove listeners. This API allows safely using `AbortSignal`s in Node.js APIs by solving these two issues by listening to the event such that `stopImmediatePropagation` does not prevent the listener from running. Returns a disposable so that it may be unsubscribed from more easily. ```js import { addAbortListener } from 'node:events'; function example(signal) { let disposable; try { signal.addEventListener('abort', (e) => e.stopImmediatePropagation()); disposable = addAbortListener(signal, (e) => { // Do something when signal is aborted. }); } finally { disposable?.[Symbol.dispose](); } } ``` #### Parameters [Section titled “Parameters”](#parameters-25) | Parameter | Type | | ---------- | ------------------- | | `signal` | `AbortSignal` | | `resource` | (`event`) => `void` | #### Returns [Section titled “Returns”](#returns-36) `Disposable` Disposable that removes the `abort` listener. #### Since [Section titled “Since”](#since-19) v20.5.0 #### Inherited from [Section titled “Inherited from”](#inherited-from-20) ```ts RuntimeEventEmitter.addAbortListener ``` *** ### computeInitialSessionConfig() [Section titled “computeInitialSessionConfig()”](#computeinitialsessionconfig) ```ts static computeInitialSessionConfig( agent, options?, overrides?): Promise>; ``` Convenience helper to compute the initial session config without manually instantiating and connecting a session. This is primarily useful for integrations that must provide the session configuration to a third party (for example the SIP `calls.accept` endpoint) before the actual realtime session is attached. The helper instantiates a throwaway session so all agent-driven dynamic fields resolve in exactly the same way as the live session path. #### Type Parameters [Section titled “Type Parameters”](#type-parameters-13) | Type Parameter | Default type | | -------------- | ------------ | | `TBaseContext` | `unknown` | #### Parameters [Section titled “Parameters”](#parameters-26) | Parameter | Type | Description | | ----------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------- | | `agent` | \| [`RealtimeAgent`](/openai-agents-js/openai/agents-realtime/classes/realtimeagent/)<`TBaseContext`> \| [`RealtimeAgent`](/openai-agents-js/openai/agents-realtime/classes/realtimeagent/)<[`RealtimeContextData`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimecontextdata/)<`TBaseContext`>> | The starting agent for the session. | | `options` | `Partial`<[`RealtimeSessionOptions`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimesessionoptions/)<`TBaseContext`>> | Session options used to seed the config calculation. | | `overrides` | `Partial`<[`RealtimeSessionConfig`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimesessionconfig/)> | Additional config overrides applied on top of the provided options. | #### Returns [Section titled “Returns”](#returns-37) `Promise`<`Partial`<[`RealtimeSessionConfig`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimesessionconfig/)>> *** ### getEventListeners() [Section titled “getEventListeners()”](#geteventlisteners) ```ts static getEventListeners(emitter, name): Function[]; ``` Returns a copy of the array of listeners for the event named `eventName`. For `EventEmitter`s this behaves exactly the same as calling `.listeners` on the emitter. For `EventTarget`s this is the only way to get the event listeners for the event target. This is useful for debugging and diagnostic purposes. ```js import { getEventListeners, EventEmitter } from 'node:events'; { const ee = new EventEmitter(); const listener = () => console.log('Events are fun'); ee.on('foo', listener); console.log(getEventListeners(ee, 'foo')); // [ [Function: listener] ] } { const et = new EventTarget(); const listener = () => console.log('Events are fun'); et.addEventListener('foo', listener); console.log(getEventListeners(et, 'foo')); // [ [Function: listener] ] } ``` #### Parameters [Section titled “Parameters”](#parameters-27) | Parameter | Type | | --------- | -------------------------------------------------- | | `emitter` | `EventTarget` \| `EventEmitter`<`DefaultEventMap`> | | `name` | `string` \| `symbol` | #### Returns [Section titled “Returns”](#returns-38) `Function`\[] #### Since [Section titled “Since”](#since-20) v15.2.0, v14.17.0 #### Inherited from [Section titled “Inherited from”](#inherited-from-21) ```ts RuntimeEventEmitter.getEventListeners ``` *** ### getMaxListeners() [Section titled “getMaxListeners()”](#getmaxlisteners-1) ```ts static getMaxListeners(emitter): number; ``` Returns the currently set max amount of listeners. For `EventEmitter`s this behaves exactly the same as calling `.getMaxListeners` on the emitter. For `EventTarget`s this is the only way to get the max event listeners for the event target. If the number of event handlers on a single EventTarget exceeds the max set, the EventTarget will print a warning. ```js import { getMaxListeners, setMaxListeners, EventEmitter } from 'node:events'; { const ee = new EventEmitter(); console.log(getMaxListeners(ee)); // 10 setMaxListeners(11, ee); console.log(getMaxListeners(ee)); // 11 } { const et = new EventTarget(); console.log(getMaxListeners(et)); // 10 setMaxListeners(11, et); console.log(getMaxListeners(et)); // 11 } ``` #### Parameters [Section titled “Parameters”](#parameters-28) | Parameter | Type | | --------- | -------------------------------------------------- | | `emitter` | `EventTarget` \| `EventEmitter`<`DefaultEventMap`> | #### Returns [Section titled “Returns”](#returns-39) `number` #### Since [Section titled “Since”](#since-21) v19.9.0 #### Inherited from [Section titled “Inherited from”](#inherited-from-22) ```ts RuntimeEventEmitter.getMaxListeners ``` *** ### ~~listenerCount()~~ [Section titled “listenerCount()”](#listenercount-1) ```ts static listenerCount(emitter, eventName): number; ``` A class method that returns the number of listeners for the given `eventName` registered on the given `emitter`. ```js import { EventEmitter, listenerCount } from 'node:events'; const myEmitter = new EventEmitter(); myEmitter.on('event', () => {}); myEmitter.on('event', () => {}); console.log(listenerCount(myEmitter, 'event')); // Prints: 2 ``` Deprecated Since v3.2.0 - Use `listenerCount` instead. #### Parameters [Section titled “Parameters”](#parameters-29) | Parameter | Type | Description | | ----------- | -------------------- | -------------------- | | `emitter` | `EventEmitter` | The emitter to query | | `eventName` | `string` \| `symbol` | The event name | #### Returns [Section titled “Returns”](#returns-40) `number` #### Since [Section titled “Since”](#since-22) v0.9.12 #### Inherited from [Section titled “Inherited from”](#inherited-from-23) ```ts RuntimeEventEmitter.listenerCount ``` *** ### on() [Section titled “on()”](#on-1) #### Call Signature [Section titled “Call Signature”](#call-signature) ```ts static on( emitter, eventName, options?): AsyncIterator; ``` ```js import { on, EventEmitter } from 'node:events'; import process from 'node:process'; const ee = new EventEmitter(); // Emit later on process.nextTick(() => { ee.emit('foo', 'bar'); ee.emit('foo', 42); }); for await (const event of on(ee, 'foo')) { // The execution of this inner block is synchronous and it // processes one event at a time (even with await). Do not use // if concurrent execution is required. console.log(event); // prints ['bar'] [42] } // Unreachable here ``` Returns an `AsyncIterator` that iterates `eventName` events. It will throw if the `EventEmitter` emits `'error'`. It removes all listeners when exiting the loop. The `value` returned by each iteration is an array composed of the emitted event arguments. An `AbortSignal` can be used to cancel waiting on events: ```js import { on, EventEmitter } from 'node:events'; import process from 'node:process'; const ac = new AbortController(); (async () => { const ee = new EventEmitter(); // Emit later on process.nextTick(() => { ee.emit('foo', 'bar'); ee.emit('foo', 42); }); for await (const event of on(ee, 'foo', { signal: ac.signal })) { // The execution of this inner block is synchronous and it // processes one event at a time (even with await). Do not use // if concurrent execution is required. console.log(event); // prints ['bar'] [42] } // Unreachable here })(); process.nextTick(() => ac.abort()); ``` Use the `close` option to specify an array of event names that will end the iteration: ```js import { on, EventEmitter } from 'node:events'; import process from 'node:process'; const ee = new EventEmitter(); // Emit later on process.nextTick(() => { ee.emit('foo', 'bar'); ee.emit('foo', 42); ee.emit('close'); }); for await (const event of on(ee, 'foo', { close: ['close'] })) { console.log(event); // prints ['bar'] [42] } // the loop will exit after 'close' is emitted console.log('done'); // prints 'done' ``` ##### Parameters [Section titled “Parameters”](#parameters-30) | Parameter | Type | | ----------- | ----------------------------------- | | `emitter` | `EventEmitter` | | `eventName` | `string` \| `symbol` | | `options?` | `StaticEventEmitterIteratorOptions` | ##### Returns [Section titled “Returns”](#returns-41) `AsyncIterator`<`any`\[]> An `AsyncIterator` that iterates `eventName` events emitted by the `emitter` ##### Since [Section titled “Since”](#since-23) v13.6.0, v12.16.0 ##### Inherited from [Section titled “Inherited from”](#inherited-from-24) ```ts RuntimeEventEmitter.on ``` #### Call Signature [Section titled “Call Signature”](#call-signature-1) ```ts static on( emitter, eventName, options?): AsyncIterator; ``` ```js import { on, EventEmitter } from 'node:events'; import process from 'node:process'; const ee = new EventEmitter(); // Emit later on process.nextTick(() => { ee.emit('foo', 'bar'); ee.emit('foo', 42); }); for await (const event of on(ee, 'foo')) { // The execution of this inner block is synchronous and it // processes one event at a time (even with await). Do not use // if concurrent execution is required. console.log(event); // prints ['bar'] [42] } // Unreachable here ``` Returns an `AsyncIterator` that iterates `eventName` events. It will throw if the `EventEmitter` emits `'error'`. It removes all listeners when exiting the loop. The `value` returned by each iteration is an array composed of the emitted event arguments. An `AbortSignal` can be used to cancel waiting on events: ```js import { on, EventEmitter } from 'node:events'; import process from 'node:process'; const ac = new AbortController(); (async () => { const ee = new EventEmitter(); // Emit later on process.nextTick(() => { ee.emit('foo', 'bar'); ee.emit('foo', 42); }); for await (const event of on(ee, 'foo', { signal: ac.signal })) { // The execution of this inner block is synchronous and it // processes one event at a time (even with await). Do not use // if concurrent execution is required. console.log(event); // prints ['bar'] [42] } // Unreachable here })(); process.nextTick(() => ac.abort()); ``` Use the `close` option to specify an array of event names that will end the iteration: ```js import { on, EventEmitter } from 'node:events'; import process from 'node:process'; const ee = new EventEmitter(); // Emit later on process.nextTick(() => { ee.emit('foo', 'bar'); ee.emit('foo', 42); ee.emit('close'); }); for await (const event of on(ee, 'foo', { close: ['close'] })) { console.log(event); // prints ['bar'] [42] } // the loop will exit after 'close' is emitted console.log('done'); // prints 'done' ``` ##### Parameters [Section titled “Parameters”](#parameters-31) | Parameter | Type | | ----------- | ----------------------------------- | | `emitter` | `EventTarget` | | `eventName` | `string` | | `options?` | `StaticEventEmitterIteratorOptions` | ##### Returns [Section titled “Returns”](#returns-42) `AsyncIterator`<`any`\[]> An `AsyncIterator` that iterates `eventName` events emitted by the `emitter` ##### Since [Section titled “Since”](#since-24) v13.6.0, v12.16.0 ##### Inherited from [Section titled “Inherited from”](#inherited-from-25) ```ts RuntimeEventEmitter.on ``` *** ### once() [Section titled “once()”](#once-1) #### Call Signature [Section titled “Call Signature”](#call-signature-2) ```ts static once( emitter, eventName, options?): Promise; ``` Creates a `Promise` that is fulfilled when the `EventEmitter` emits the given event or that is rejected if the `EventEmitter` emits `'error'` while waiting. The `Promise` will resolve with an array of all the arguments emitted to the given event. This method is intentionally generic and works with the web platform [EventTarget](https://dom.spec.whatwg.org/#interface-eventtarget) interface, which has no special`'error'` event semantics and does not listen to the `'error'` event. ```js import { once, EventEmitter } from 'node:events'; import process from 'node:process'; const ee = new EventEmitter(); process.nextTick(() => { ee.emit('myevent', 42); }); const [value] = await once(ee, 'myevent'); console.log(value); const err = new Error('kaboom'); process.nextTick(() => { ee.emit('error', err); }); try { await once(ee, 'myevent'); } catch (err) { console.error('error happened', err); } ``` The special handling of the `'error'` event is only used when `events.once()` is used to wait for another event. If `events.once()` is used to wait for the ‘`error'` event itself, then it is treated as any other kind of event without special handling: ```js import { EventEmitter, once } from 'node:events'; const ee = new EventEmitter(); once(ee, 'error') .then(([err]) => console.log('ok', err.message)) .catch((err) => console.error('error', err.message)); ee.emit('error', new Error('boom')); // Prints: ok boom ``` An `AbortSignal` can be used to cancel waiting for the event: ```js import { EventEmitter, once } from 'node:events'; const ee = new EventEmitter(); const ac = new AbortController(); async function foo(emitter, event, signal) { try { await once(emitter, event, { signal }); console.log('event emitted!'); } catch (error) { if (error.name === 'AbortError') { console.error('Waiting for the event was canceled!'); } else { console.error('There was an error', error.message); } } } foo(ee, 'foo', ac.signal); ac.abort(); // Abort waiting for the event ee.emit('foo'); // Prints: Waiting for the event was canceled! ``` ##### Parameters [Section titled “Parameters”](#parameters-32) | Parameter | Type | | ----------- | --------------------------- | | `emitter` | `EventEmitter` | | `eventName` | `string` \| `symbol` | | `options?` | `StaticEventEmitterOptions` | ##### Returns [Section titled “Returns”](#returns-43) `Promise`<`any`\[]> ##### Since [Section titled “Since”](#since-25) v11.13.0, v10.16.0 ##### Inherited from [Section titled “Inherited from”](#inherited-from-26) ```ts RuntimeEventEmitter.once ``` #### Call Signature [Section titled “Call Signature”](#call-signature-3) ```ts static once( emitter, eventName, options?): Promise; ``` Creates a `Promise` that is fulfilled when the `EventEmitter` emits the given event or that is rejected if the `EventEmitter` emits `'error'` while waiting. The `Promise` will resolve with an array of all the arguments emitted to the given event. This method is intentionally generic and works with the web platform [EventTarget](https://dom.spec.whatwg.org/#interface-eventtarget) interface, which has no special`'error'` event semantics and does not listen to the `'error'` event. ```js import { once, EventEmitter } from 'node:events'; import process from 'node:process'; const ee = new EventEmitter(); process.nextTick(() => { ee.emit('myevent', 42); }); const [value] = await once(ee, 'myevent'); console.log(value); const err = new Error('kaboom'); process.nextTick(() => { ee.emit('error', err); }); try { await once(ee, 'myevent'); } catch (err) { console.error('error happened', err); } ``` The special handling of the `'error'` event is only used when `events.once()` is used to wait for another event. If `events.once()` is used to wait for the ‘`error'` event itself, then it is treated as any other kind of event without special handling: ```js import { EventEmitter, once } from 'node:events'; const ee = new EventEmitter(); once(ee, 'error') .then(([err]) => console.log('ok', err.message)) .catch((err) => console.error('error', err.message)); ee.emit('error', new Error('boom')); // Prints: ok boom ``` An `AbortSignal` can be used to cancel waiting for the event: ```js import { EventEmitter, once } from 'node:events'; const ee = new EventEmitter(); const ac = new AbortController(); async function foo(emitter, event, signal) { try { await once(emitter, event, { signal }); console.log('event emitted!'); } catch (error) { if (error.name === 'AbortError') { console.error('Waiting for the event was canceled!'); } else { console.error('There was an error', error.message); } } } foo(ee, 'foo', ac.signal); ac.abort(); // Abort waiting for the event ee.emit('foo'); // Prints: Waiting for the event was canceled! ``` ##### Parameters [Section titled “Parameters”](#parameters-33) | Parameter | Type | | ----------- | --------------------------- | | `emitter` | `EventTarget` | | `eventName` | `string` | | `options?` | `StaticEventEmitterOptions` | ##### Returns [Section titled “Returns”](#returns-44) `Promise`<`any`\[]> ##### Since [Section titled “Since”](#since-26) v11.13.0, v10.16.0 ##### Inherited from [Section titled “Inherited from”](#inherited-from-27) ```ts RuntimeEventEmitter.once ``` *** ### setMaxListeners() [Section titled “setMaxListeners()”](#setmaxlisteners-1) ```ts static setMaxListeners(n?, ...eventTargets): void; ``` ```js import { setMaxListeners, EventEmitter } from 'node:events'; const target = new EventTarget(); const emitter = new EventEmitter(); setMaxListeners(5, target, emitter); ``` #### Parameters [Section titled “Parameters”](#parameters-34) | Parameter | Type | Description | | ---------------- | ------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `n?` | `number` | A non-negative number. The maximum number of listeners per `EventTarget` event. | | …`eventTargets?` | (`EventTarget` \| `EventEmitter`<`DefaultEventMap`>)\[] | Zero or more {EventTarget} or {EventEmitter} instances. If none are specified, `n` is set as the default max for all newly created {EventTarget} and {EventEmitter} objects. | #### Returns [Section titled “Returns”](#returns-45) `void` #### Since [Section titled “Since”](#since-27) v15.4.0 #### Inherited from [Section titled “Inherited from”](#inherited-from-28) ```ts RuntimeEventEmitter.setMaxListeners ``` # UserError Error thrown when the error is caused by the library user’s misconfiguration. ## Extends [Section titled “Extends”](#extends) * `AgentsError` ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new UserError(message, state?): UserError; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ---------------------------------------- | | `message` | `string` | | `state?` | `RunState`<`any`, `Agent`<`any`, `any`>> | #### Returns [Section titled “Returns”](#returns) `UserError` #### Inherited from [Section titled “Inherited from”](#inherited-from) ```ts AgentsError.constructor ``` ## Properties [Section titled “Properties”](#properties) ### message [Section titled “message”](#message) ```ts message: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-1) ```ts AgentsError.message ``` *** ### name [Section titled “name”](#name) ```ts name: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-2) ```ts AgentsError.name ``` *** ### stack? [Section titled “stack?”](#stack) ```ts optional stack?: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-3) ```ts AgentsError.stack ``` *** ### state? [Section titled “state?”](#state) ```ts optional state?: RunState>; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-4) ```ts AgentsError.state ``` *** ### stackTraceLimit [Section titled “stackTraceLimit”](#stacktracelimit) ```ts static stackTraceLimit: number; ``` The `Error.stackTraceLimit` property specifies the number of stack frames collected by a stack trace (whether generated by `new Error().stack` or `Error.captureStackTrace(obj)`). The default value is `10` but may be set to any valid JavaScript number. Changes will affect any stack trace captured *after* the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames. #### Inherited from [Section titled “Inherited from”](#inherited-from-5) ```ts AgentsError.stackTraceLimit ``` ## Methods [Section titled “Methods”](#methods) ### captureStackTrace() [Section titled “captureStackTrace()”](#capturestacktrace) ```ts static captureStackTrace(targetObject, constructorOpt?): void; ``` Creates a `.stack` property on `targetObject`, which when accessed returns a string representing the location in the code at which `Error.captureStackTrace()` was called. ```js const myObject = {}; Error.captureStackTrace(myObject); myObject.stack; // Similar to `new Error().stack` ``` The first line of the trace will be prefixed with `${myObject.name}: ${myObject.message}`. The optional `constructorOpt` argument accepts a function. If given, all frames above `constructorOpt`, including `constructorOpt`, will be omitted from the generated stack trace. The `constructorOpt` argument is useful for hiding implementation details of error generation from the user. For instance: ```js function a() { b(); } function b() { c(); } function c() { // Create an error without stack trace to avoid calculating the stack trace twice. const { stackTraceLimit } = Error; Error.stackTraceLimit = 0; const error = new Error(); Error.stackTraceLimit = stackTraceLimit; // Capture the stack trace above function b Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace throw error; } a(); ``` #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | ----------------- | ---------- | | `targetObject` | `object` | | `constructorOpt?` | `Function` | #### Returns [Section titled “Returns”](#returns-1) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-6) ```ts AgentsError.captureStackTrace ``` *** ### prepareStackTrace() [Section titled “prepareStackTrace()”](#preparestacktrace) ```ts static prepareStackTrace(err, stackTraces): any; ``` #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | ------------- | ------------- | | `err` | `Error` | | `stackTraces` | `CallSite`\[] | #### Returns [Section titled “Returns”](#returns-2) `any` #### See [Section titled “See”](#see) #### Inherited from [Section titled “Inherited from”](#inherited-from-7) ```ts AgentsError.prepareStackTrace ``` # backgroundResult ```ts function backgroundResult(content): BackgroundResult; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | -------------- | | `T` | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ---- | | `content` | `T` | ## Returns [Section titled “Returns”](#returns) `BackgroundResult`<`T`> # isBackgroundResult ```ts function isBackgroundResult(result): result is BackgroundResult; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | -------------- | | `T` | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | --------- | | `result` | `unknown` | ## Returns [Section titled “Returns”](#returns) `result is BackgroundResult` # tool ```ts function tool(options): FunctionTool; ``` Exposes a function to the agent as a tool to be called ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | --------------------------------------------- | ------------ | | `TParameters` *extends* `ToolInputParameters` | `undefined` | | `Context` | `unknown` | | `Result` | `string` | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | --------- | --------------------------------------- | ------------------------ | | `options` | `ToolOptions`<`TParameters`, `Context`> | The options for the tool | ## Returns [Section titled “Returns”](#returns) [`FunctionTool`](/openai-agents-js/openai/agents-realtime/type-aliases/functiontool/)<`Context`, `TParameters`, `Result`> A new tool # RealtimeOutputGuardrail ## Extends [Section titled “Extends”](#extends) * `OutputGuardrail` ## Properties [Section titled “Properties”](#properties) ### execute [Section titled “execute”](#execute) ```ts execute: OutputGuardrailFunction<"text", unknown>; ``` The function that performs the guardrail check. #### Inherited from [Section titled “Inherited from”](#inherited-from) ```ts OutputGuardrail.execute ``` *** ### name [Section titled “name”](#name) ```ts name: string; ``` The name of the guardrail. #### Inherited from [Section titled “Inherited from”](#inherited-from-1) ```ts OutputGuardrail.name ``` *** ### policyHint? [Section titled “policyHint?”](#policyhint) ```ts optional policyHint?: string; ``` This will be passed to the model to inform it about why the guardrail was triggered and to correct the behavior. If it’s not specified the name of your guardrail will be passed instead. # RealtimeTransportLayer The transport layer is the layer that handles the connection to the model and the communication with the model. ## Extends [Section titled “Extends”](#extends) * `EventEmitter`<[`RealtimeTransportEventTypes`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimetransporteventtypes/)> ## Properties [Section titled “Properties”](#properties) ### muted [Section titled “muted”](#muted) ```ts readonly muted: boolean | null; ``` Whether the input audio track is currently muted null if the muting is not handled by the transport layer *** ### status [Section titled “status”](#status) ```ts status: "connecting" | "connected" | "disconnected" | "disconnecting"; ``` ## Methods [Section titled “Methods”](#methods) ### addImage() [Section titled “addImage()”](#addimage) ```ts addImage(image, options?): void; ``` Sends an image to the model #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | -------------------------- | ---------------------------------- | -------------------------------------------- | | `image` | `string` | The image to send | | `options?` | { `triggerResponse?`: `boolean`; } | Additional options | | `options.triggerResponse?` | `boolean` | Whether to trigger a response from the model | #### Returns [Section titled “Returns”](#returns) `void` *** ### close() [Section titled “close()”](#close) ```ts close(): void; ``` Closes the connection to the model #### Returns [Section titled “Returns”](#returns-1) `void` *** ### connect() [Section titled “connect()”](#connect) ```ts connect(options): Promise; ``` Establishes the connection to the model and keeps the connection alive #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | Description | | --------- | ------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------ | | `options` | [`RealtimeTransportLayerConnectOptions`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimetransportlayerconnectoptions/) | The options for the connection | #### Returns [Section titled “Returns”](#returns-2) `Promise`<`void`> *** ### emit() [Section titled “emit()”](#emit) ```ts emit(type, ...args): boolean; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | --------------------------------------------------------------------------------------------------------------------------------------- | | `K` *extends* keyof [`RealtimeTransportEventTypes`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimetransporteventtypes/) | #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | --------- | ------------------------------------------------------------------------------------------------------------------------- | | `type` | `K` | | …`args` | [`RealtimeTransportEventTypes`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimetransporteventtypes/)\[`K`] | #### Returns [Section titled “Returns”](#returns-3) `boolean` #### Inherited from [Section titled “Inherited from”](#inherited-from) ```ts EventEmitter.emit ``` *** ### interrupt() [Section titled “interrupt()”](#interrupt) ```ts interrupt(): void; ``` Interrupts the current turn. Used for example when a guardrail is triggered #### Returns [Section titled “Returns”](#returns-4) `void` *** ### mute() [Section titled “mute()”](#mute) ```ts mute(muted): void; ``` Mutes the input audio track #### Parameters [Section titled “Parameters”](#parameters-3) | Parameter | Type | Description | | --------- | --------- | ------------------------------------- | | `muted` | `boolean` | Whether to mute the input audio track | #### Returns [Section titled “Returns”](#returns-5) `void` *** ### off() [Section titled “off()”](#off) ```ts off(type, listener): EventEmitter; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-1) | Type Parameter | | --------------------------------------------------------------------------------------------------------------------------------------- | | `K` *extends* keyof [`RealtimeTransportEventTypes`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimetransporteventtypes/) | #### Parameters [Section titled “Parameters”](#parameters-4) | Parameter | Type | | ---------- | ------------------- | | `type` | `K` | | `listener` | (…`args`) => `void` | #### Returns [Section titled “Returns”](#returns-6) `EventEmitter`<[`RealtimeTransportEventTypes`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimetransporteventtypes/)> #### Inherited from [Section titled “Inherited from”](#inherited-from-1) ```ts EventEmitter.off ``` *** ### on() [Section titled “on()”](#on) ```ts on(type, listener): EventEmitter; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-2) | Type Parameter | | --------------------------------------------------------------------------------------------------------------------------------------- | | `K` *extends* keyof [`RealtimeTransportEventTypes`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimetransporteventtypes/) | #### Parameters [Section titled “Parameters”](#parameters-5) | Parameter | Type | | ---------- | ------------------- | | `type` | `K` | | `listener` | (…`args`) => `void` | #### Returns [Section titled “Returns”](#returns-7) `EventEmitter`<[`RealtimeTransportEventTypes`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimetransporteventtypes/)> #### Inherited from [Section titled “Inherited from”](#inherited-from-2) ```ts EventEmitter.on ``` *** ### once() [Section titled “once()”](#once) ```ts once(type, listener): EventEmitter; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-3) | Type Parameter | | --------------------------------------------------------------------------------------------------------------------------------------- | | `K` *extends* keyof [`RealtimeTransportEventTypes`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimetransporteventtypes/) | #### Parameters [Section titled “Parameters”](#parameters-6) | Parameter | Type | | ---------- | ------------------- | | `type` | `K` | | `listener` | (…`args`) => `void` | #### Returns [Section titled “Returns”](#returns-8) `EventEmitter`<[`RealtimeTransportEventTypes`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimetransporteventtypes/)> #### Inherited from [Section titled “Inherited from”](#inherited-from-3) ```ts EventEmitter.once ``` *** ### requestResponse()? [Section titled “requestResponse()?”](#requestresponse) ```ts optional requestResponse(response?): void; ``` Requests a new response for the current conversation turn. Implementations may defer the underlying `response.create` until the server has fully finished the prior response. #### Parameters [Section titled “Parameters”](#parameters-7) | Parameter | Type | Description | | ----------- | ------------------------- | ------------------------------------------- | | `response?` | `Record`<`string`, `any`> | Optional one-off response override payload. | #### Returns [Section titled “Returns”](#returns-9) `void` *** ### resetHistory() [Section titled “resetHistory()”](#resethistory) ```ts resetHistory(oldHistory, newHistory): void; ``` Resets the conversation history / context to a specific state #### Parameters [Section titled “Parameters”](#parameters-8) | Parameter | Type | Description | | ------------ | ---------------------------------------------------------------------------------------- | ------------------------------------------------------ | | `oldHistory` | [`RealtimeItem`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimeitem/)\[] | The history that is currently stored on the session. | | `newHistory` | [`RealtimeItem`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimeitem/)\[] | The history you want the session to use going forward. | #### Returns [Section titled “Returns”](#returns-10) `void` *** ### sendAudio() [Section titled “sendAudio()”](#sendaudio) ```ts sendAudio(audio, options): void; ``` Sends a raw audio buffer to the model #### Parameters [Section titled “Parameters”](#parameters-9) | Parameter | Type | Description | | ----------------- | ------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- | | `audio` | `ArrayBuffer` | The audio buffer to send | | `options` | { `commit?`: `boolean`; } | Additional options | | `options.commit?` | `boolean` | Whether to commit the audio buffer to the model. If the model does not do turn detection, this can be used to indicate the turn is completed. | #### Returns [Section titled “Returns”](#returns-11) `void` *** ### sendEvent() [Section titled “sendEvent()”](#sendevent) ```ts sendEvent(event): void; ``` Sends a raw event to the model #### Parameters [Section titled “Parameters”](#parameters-10) | Parameter | Type | Description | | --------- | ------------------------------------------------------------------------------------------------------- | ----------------- | | `event` | [`RealtimeClientMessage`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimeclientmessage/) | The event to send | #### Returns [Section titled “Returns”](#returns-12) `void` *** ### sendFunctionCallOutput() [Section titled “sendFunctionCallOutput()”](#sendfunctioncalloutput) ```ts sendFunctionCallOutput( toolCall, output, startResponse): void; ``` Sends a function call output to the model #### Parameters [Section titled “Parameters”](#parameters-11) | Parameter | Type | Description | | --------------- | --------------------------------------------------------------------------------------------------------- | --------------------------- | | `toolCall` | [`TransportToolCallEvent`](/openai-agents-js/openai/agents-realtime/type-aliases/transporttoolcallevent/) | The tool call to send | | `output` | `string` | The output of the tool call | | `startResponse` | `boolean` | ‐ | #### Returns [Section titled “Returns”](#returns-13) `void` *** ### sendMcpResponse() [Section titled “sendMcpResponse()”](#sendmcpresponse) ```ts sendMcpResponse( approvalRequest, approved, reason?): void; ``` Sends a response for an MCP tool call #### Parameters [Section titled “Parameters”](#parameters-12) | Parameter | Type | Description | | ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------- | | `approvalRequest` | { `approved?`: `boolean` \| `null`; `arguments`: `Record`<`string`, `any`>; `itemId`: `string`; `name`: `string`; `serverLabel`: `string`; `type`: `"mcp_approval_request"`; } | The approval request to respond to | | `approvalRequest.approved?` | `boolean` \| `null` | ‐ | | `approvalRequest.arguments` | `Record`<`string`, `any`> | ‐ | | `approvalRequest.itemId?` | `string` | ‐ | | `approvalRequest.name?` | `string` | ‐ | | `approvalRequest.serverLabel?` | `string` | ‐ | | `approvalRequest.type?` | `"mcp_approval_request"` | ‐ | | `approved?` | `boolean` | Whether the tool call was approved or rejected | | `reason?` | `string` | Optional rejection text for the provider/model. | #### Returns [Section titled “Returns”](#returns-14) `void` *** ### sendMessage() [Section titled “sendMessage()”](#sendmessage) ```ts sendMessage( message, otherEventData, options?): void; ``` Sends a text message to the model #### Parameters [Section titled “Parameters”](#parameters-13) | Parameter | Type | Description | | -------------------------- | ---------------------------------- | ---------------------------------------------------- | | `message` | `RealtimeUserInput` | The message to send | | `otherEventData` | `Record`<`string`, `any`> | Additional event data, will be merged into the event | | `options?` | { `triggerResponse?`: `boolean`; } | Additional options | | `options.triggerResponse?` | `boolean` | Whether to trigger a response from the model | #### Returns [Section titled “Returns”](#returns-15) `void` *** ### updateSessionConfig() [Section titled “updateSessionConfig()”](#updatesessionconfig) ```ts updateSessionConfig(config): void; ``` Sends an updated session configuration to the model. Used to update for example the model instructions during a handoff #### Parameters [Section titled “Parameters”](#parameters-14) | Parameter | Type | Description | | --------- | ------------------------------------------------------------------------------------------------------------------ | ---------------------- | | `config` | `Partial`<[`RealtimeSessionConfig`](/openai-agents-js/openai/agents-realtime/type-aliases/realtimesessionconfig/)> | The new session config | #### Returns [Section titled “Returns”](#returns-16) `void` # @openai/agents-realtime ## Classes [Section titled “Classes”](#classes) * [ModelBehaviorError](/openai-agents-js/openai/agents-realtime/classes/modelbehaviorerror/) * [OpenAIRealtimeBase](/openai-agents-js/openai/agents-realtime/classes/openairealtimebase/) * [OpenAIRealtimeSIP](/openai-agents-js/openai/agents-realtime/classes/openairealtimesip/) * [OpenAIRealtimeWebRTC](/openai-agents-js/openai/agents-realtime/classes/openairealtimewebrtc/) * [OpenAIRealtimeWebSocket](/openai-agents-js/openai/agents-realtime/classes/openairealtimewebsocket/) * [OutputGuardrailTripwireTriggered](/openai-agents-js/openai/agents-realtime/classes/outputguardrailtripwiretriggered/) * [RealtimeAgent](/openai-agents-js/openai/agents-realtime/classes/realtimeagent/) * [RealtimeSession](/openai-agents-js/openai/agents-realtime/classes/realtimesession/) * [UserError](/openai-agents-js/openai/agents-realtime/classes/usererror/) ## Interfaces [Section titled “Interfaces”](#interfaces) * [RealtimeOutputGuardrail](/openai-agents-js/openai/agents-realtime/interfaces/realtimeoutputguardrail/) * [RealtimeTransportLayer](/openai-agents-js/openai/agents-realtime/interfaces/realtimetransportlayer/) ## Type Aliases [Section titled “Type Aliases”](#type-aliases) * [ApiKey](/openai-agents-js/openai/agents-realtime/type-aliases/apikey/) * [FunctionTool](/openai-agents-js/openai/agents-realtime/type-aliases/functiontool/) * [OpenAIRealtimeBaseOptions](/openai-agents-js/openai/agents-realtime/type-aliases/openairealtimebaseoptions/) * [OpenAIRealtimeEventTypes](/openai-agents-js/openai/agents-realtime/type-aliases/openairealtimeeventtypes/) * [OpenAIRealtimeModels](/openai-agents-js/openai/agents-realtime/type-aliases/openairealtimemodels/) * [OpenAIRealtimeWebRTCOptions](/openai-agents-js/openai/agents-realtime/type-aliases/openairealtimewebrtcoptions/) * [OpenAIRealtimeWebSocketOptions](/openai-agents-js/openai/agents-realtime/type-aliases/openairealtimewebsocketoptions/) * [RealtimeAgentConfiguration](/openai-agents-js/openai/agents-realtime/type-aliases/realtimeagentconfiguration/) * [RealtimeAudioFormat](/openai-agents-js/openai/agents-realtime/type-aliases/realtimeaudioformat/) * [RealtimeBaseItem](/openai-agents-js/openai/agents-realtime/type-aliases/realtimebaseitem/) * [RealtimeClientMessage](/openai-agents-js/openai/agents-realtime/type-aliases/realtimeclientmessage/) * [RealtimeContextData](/openai-agents-js/openai/agents-realtime/type-aliases/realtimecontextdata/) * [RealtimeItem](/openai-agents-js/openai/agents-realtime/type-aliases/realtimeitem/) * [RealtimeMcpCallItem](/openai-agents-js/openai/agents-realtime/type-aliases/realtimemcpcallitem/) * [RealtimeMessageItem](/openai-agents-js/openai/agents-realtime/type-aliases/realtimemessageitem/) * [RealtimeReasoningConfig](/openai-agents-js/openai/agents-realtime/type-aliases/realtimereasoningconfig/) * [RealtimeReasoningEffort](/openai-agents-js/openai/agents-realtime/type-aliases/realtimereasoningeffort/) * [RealtimeSessionConfig](/openai-agents-js/openai/agents-realtime/type-aliases/realtimesessionconfig/) * [RealtimeSessionConnectOptions](/openai-agents-js/openai/agents-realtime/type-aliases/realtimesessionconnectoptions/) * [RealtimeSessionEventTypes](/openai-agents-js/openai/agents-realtime/type-aliases/realtimesessioneventtypes/) * [RealtimeSessionOptions](/openai-agents-js/openai/agents-realtime/type-aliases/realtimesessionoptions/) * [RealtimeSessionPayload](/openai-agents-js/openai/agents-realtime/type-aliases/realtimesessionpayload/) * [RealtimeToolCallItem](/openai-agents-js/openai/agents-realtime/type-aliases/realtimetoolcallitem/) * [RealtimeTransportEventTypes](/openai-agents-js/openai/agents-realtime/type-aliases/realtimetransporteventtypes/) * [RealtimeTransportLayerConnectOptions](/openai-agents-js/openai/agents-realtime/type-aliases/realtimetransportlayerconnectoptions/) * [TransportError](/openai-agents-js/openai/agents-realtime/type-aliases/transporterror/) * [TransportEvent](/openai-agents-js/openai/agents-realtime/type-aliases/transportevent/) * [TransportLayerAudio](/openai-agents-js/openai/agents-realtime/type-aliases/transportlayeraudio/) * [TransportLayerResponseCompleted](/openai-agents-js/openai/agents-realtime/type-aliases/transportlayerresponsecompleted/) * [TransportLayerResponseStarted](/openai-agents-js/openai/agents-realtime/type-aliases/transportlayerresponsestarted/) * [TransportLayerTranscriptDelta](/openai-agents-js/openai/agents-realtime/type-aliases/transportlayertranscriptdelta/) * [TransportToolCallEvent](/openai-agents-js/openai/agents-realtime/type-aliases/transporttoolcallevent/) * [WebRTCState](/openai-agents-js/openai/agents-realtime/type-aliases/webrtcstate/) * [WebSocketState](/openai-agents-js/openai/agents-realtime/type-aliases/websocketstate/) ## Variables [Section titled “Variables”](#variables) * [DEFAULT\_OPENAI\_REALTIME\_MODEL](/openai-agents-js/openai/agents-realtime/variables/default_openai_realtime_model/) * [DEFAULT\_OPENAI\_REALTIME\_SESSION\_CONFIG](/openai-agents-js/openai/agents-realtime/variables/default_openai_realtime_session_config/) * [utils](/openai-agents-js/openai/agents-realtime/variables/utils/) ## Functions [Section titled “Functions”](#functions) * [backgroundResult](/openai-agents-js/openai/agents-realtime/functions/backgroundresult/) * [isBackgroundResult](/openai-agents-js/openai/agents-realtime/functions/isbackgroundresult/) * [tool](/openai-agents-js/openai/agents-realtime/functions/tool/) # ApiKey ```ts type ApiKey = string | (() => string | Promise); ``` The type of the API key. Can be a string or a function that returns a string or a promise that resolves to a string. # FunctionTool ```ts type FunctionTool = object; ``` Exposes a function to the agent as a tool to be called ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | Description | | --------------------------------------------- | ---------------- | ----------------------- | | `Context` | `UnknownContext` | The context of the tool | | `TParameters` *extends* `ToolInputParameters` | `undefined` | ‐ | | `Result` | `unknown` | The result of the tool | ## Properties [Section titled “Properties”](#properties) ### deferLoading? [Section titled “deferLoading?”](#deferloading) ```ts optional deferLoading?: boolean; ``` Responses API only. Hides a top-level function tool definition until tool search loads it. *** ### description [Section titled “description”](#description) ```ts description: string; ``` The description of the tool that helps the model to understand when to use the tool *** ### inputGuardrails? [Section titled “inputGuardrails?”](#inputguardrails) ```ts optional inputGuardrails?: ToolInputGuardrailDefinition[]; ``` Guardrails that run before the tool executes. *** ### invoke [Section titled “invoke”](#invoke) ```ts invoke: (runContext, input, details?) => Promise; ``` The function to invoke when the tool is called. #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ------------ | ----------------------- | | `runContext` | `RunContext`<`Context`> | | `input` | `string` | | `details?` | `ToolCallDetails` | #### Returns [Section titled “Returns”](#returns) `Promise`<`string` | `Result`> *** ### isEnabled [Section titled “isEnabled”](#isenabled) ```ts isEnabled: ToolEnabledFunction; ``` Determines whether the tool should be made available to the model for the current run. *** ### name [Section titled “name”](#name) ```ts name: string; ``` The name of the tool. *** ### needsApproval [Section titled “needsApproval”](#needsapproval) ```ts needsApproval: ToolApprovalFunction; ``` Whether the tool needs human approval before it can be called. If this is true, the run will result in an `interruption` that the program has to resolve by approving or rejecting the tool call. *** ### outputGuardrails? [Section titled “outputGuardrails?”](#outputguardrails) ```ts optional outputGuardrails?: ToolOutputGuardrailDefinition[]; ``` Guardrails that run after the tool executes. *** ### parameters [Section titled “parameters”](#parameters-1) ```ts parameters: JsonObjectSchema; ``` A JSON schema describing the parameters of the tool. *** ### strict [Section titled “strict”](#strict) ```ts strict: boolean; ``` Whether the tool is strict. If true, the model must try to strictly follow the schema (might result in slower response times). *** ### timeoutBehavior? [Section titled “timeoutBehavior?”](#timeoutbehavior) ```ts optional timeoutBehavior?: FunctionToolTimeoutBehavior; ``` Defines how timeout errors are handled. * `error_as_result`: return a model-visible timeout message. * `raise_exception`: raise `ToolTimeoutError` and fail the run. *** ### timeoutErrorFunction? [Section titled “timeoutErrorFunction?”](#timeouterrorfunction) ```ts optional timeoutErrorFunction?: ToolTimeoutErrorFunction; ``` Optional formatter for timeout errors when timeoutBehavior is `error_as_result`. *** ### timeoutMs? [Section titled “timeoutMs?”](#timeoutms) ```ts optional timeoutMs?: number; ``` Optional timeout in milliseconds for each tool invocation. *** ### type [Section titled “type”](#type) ```ts type: "function"; ``` # OpenAIRealtimeBaseOptions ```ts type OpenAIRealtimeBaseOptions = object; ``` The options for the OpenAI Realtime transport layer. ## Properties [Section titled “Properties”](#properties) ### apiKey? [Section titled “apiKey?”](#apikey) ```ts optional apiKey?: ApiKey; ``` The API key to use for the connection. *** ### model? [Section titled “model?”](#model) ```ts optional model?: OpenAIRealtimeModels; ``` The model to used during the connection. # OpenAIRealtimeEventTypes ```ts type OpenAIRealtimeEventTypes = object & RealtimeTransportEventTypes; ``` The events that are emitted by the OpenAI Realtime transport layer. ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### connected [Section titled “connected”](#connected) ```ts connected: []; ``` Triggered when the connection is established. ### disconnected [Section titled “disconnected”](#disconnected) ```ts disconnected: []; ``` Triggered when the connection is closed. # OpenAIRealtimeModels ```ts type OpenAIRealtimeModels = | "gpt-realtime" | "gpt-realtime-1.5" | "gpt-realtime-2" | "gpt-realtime-2025-08-28" | "gpt-4o-realtime-preview" | "gpt-4o-realtime-preview-2024-10-01" | "gpt-4o-realtime-preview-2024-12-17" | "gpt-4o-realtime-preview-2025-06-03" | "gpt-4o-mini-realtime-preview" | "gpt-4o-mini-realtime-preview-2024-12-17" | "gpt-realtime-mini" | "gpt-realtime-mini-2025-10-06" | "gpt-realtime-mini-2025-12-15" | string & object; ``` The models that are supported by the OpenAI Realtime API. # OpenAIRealtimeWebRTCOptions ```ts type OpenAIRealtimeWebRTCOptions = object & OpenAIRealtimeBaseOptions; ``` The options for the OpenAI Realtime WebRTC transport layer. ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### audioElement? [Section titled “audioElement?”](#audioelement) ```ts optional audioElement?: HTMLAudioElement; ``` The audio element to use for audio playback. If not provided, a new audio element will be created. ### baseUrl? [Section titled “baseUrl?”](#baseurl) ```ts optional baseUrl?: string; ``` Override of the base URL for the Realtime API ### changePeerConnection? [Section titled “changePeerConnection?”](#changepeerconnection) ```ts optional changePeerConnection?: (peerConnection) => RTCPeerConnection | Promise; ``` Optional hook invoked with the freshly created peer connection. Returning a different connection will override the one created by the transport layer. This is called right before the offer is created and can be asynchronous. #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ---------------- | ------------------- | | `peerConnection` | `RTCPeerConnection` | #### Returns [Section titled “Returns”](#returns) `RTCPeerConnection` | `Promise`<`RTCPeerConnection`> ### mediaStream? [Section titled “mediaStream?”](#mediastream) ```ts optional mediaStream?: MediaStream; ``` The media stream to use for audio input. If not provided, the default microphone will be used. ### useInsecureApiKey? [Section titled “useInsecureApiKey?”](#useinsecureapikey) ```ts optional useInsecureApiKey?: boolean; ``` **Important**: Do not use this option unless you know what you are doing. Whether to use an insecure API key. This has to be set if you are trying to use a regular OpenAI API key instead of a client ephemeral key. #### See [Section titled “See”](#see) # OpenAIRealtimeWebSocketOptions ```ts type OpenAIRealtimeWebSocketOptions = object & OpenAIRealtimeBaseOptions; ``` The options for the OpenAI Realtime WebSocket transport layer. ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### createWebSocket? [Section titled “createWebSocket?”](#createwebsocket) ```ts optional createWebSocket?: (options) => Promise; ``` Builds a new WebSocket connection. #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | --------- | ------------------------ | ----------------------------------------- | | `options` | `CreateWebSocketOptions` | The options for the WebSocket connection. | #### Returns [Section titled “Returns”](#returns) `Promise`<`WebSocket`> The WebSocket connection. ### skipOpenEventListeners? [Section titled “skipOpenEventListeners?”](#skipopeneventlisteners) ```ts optional skipOpenEventListeners?: boolean; ``` When you pass your own createWebSocket function, which completes the connection state transition, you can set this to true to skip registering the `open` event listener for the same purpose. If this flag is set to true, the constructor will immediately call the internal operation to mark the internal connection state to `connected`. Otherwise, the constructor will register the `open` event listener and wait for it to be triggered. By default (meaning if this property is absent), this is set to false. ### url? [Section titled “url?”](#url) ```ts optional url?: string; ``` The URL to use for the WebSocket connection. ### useInsecureApiKey? [Section titled “useInsecureApiKey?”](#useinsecureapikey) ```ts optional useInsecureApiKey?: boolean; ``` **Important**: Do not use this option unless you know what you are doing. Whether to use an insecure API key. This has to be set if you are trying to use a regular OpenAI API key instead of a client ephemeral key. #### See [Section titled “See”](#see) # RealtimeAgentConfiguration ```ts type RealtimeAgentConfiguration = Partial, TextOutput>, | "model" | "handoffs" | "modelSettings" | "outputType" | "toolUseBehavior" | "resetToolChoice" | "outputGuardrails" | "inputGuardrails" | "model">> & object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### handoffs? [Section titled “handoffs?”](#handoffs) ```ts optional handoffs?: ( | RealtimeAgent | Handoff, TextOutput>)[]; ``` Any other `RealtimeAgent` instances the agent is able to hand off to. ### name [Section titled “name”](#name) ```ts name: string; ``` The name of your realtime agent. ### voice? [Section titled “voice?”](#voice) ```ts optional voice?: string; ``` The voice intended to be used by the agent. If another agent already spoke during the RealtimeSession, changing the voice during a handoff will fail. ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | ---------------- | | `TContext` | `UnknownContext` | # RealtimeAudioFormat ```ts type RealtimeAudioFormat = RealtimeAudioFormatLegacy | RealtimeAudioFormatDefinition; ``` # RealtimeBaseItem ```ts type RealtimeBaseItem = object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### itemId [Section titled “itemId”](#itemid) ```ts itemId: string; ``` # RealtimeClientMessage ```ts type RealtimeClientMessage = object; ``` ## Indexable [Section titled “Indexable”](#indexable) ```ts [key: string]: any ``` ## Properties [Section titled “Properties”](#properties) ### type [Section titled “type”](#type) ```ts type: string; ``` # RealtimeContextData ```ts type RealtimeContextData = TContext & object; ``` The context data for a realtime session. This is the context data that is passed to the agent. The RealtimeSession will automatically add the current snapshot of the history to the context. ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### history [Section titled “history”](#history) ```ts history: RealtimeItem[]; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | ------------ | | `TContext` | `unknown` | # RealtimeItem ```ts type RealtimeItem = | RealtimeMessageItem | RealtimeToolCallItem | RealtimeMcpCallItem | RealtimeMcpCallApprovalRequestItem; ``` # RealtimeMcpCallItem ```ts type RealtimeMcpCallItem = object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### arguments [Section titled “arguments”](#arguments) ```ts arguments: string; ``` ### itemId [Section titled “itemId”](#itemid) ```ts itemId: string; ``` ### name [Section titled “name”](#name) ```ts name: string; ``` ### output [Section titled “output”](#output) ```ts output: string | null; ``` ### previousItemId? [Section titled “previousItemId?”](#previousitemid) ```ts optional previousItemId?: string | null; ``` ### status [Section titled “status”](#status) ```ts status: "in_progress" | "completed" | "incomplete"; ``` ### type [Section titled “type”](#type) ```ts type: "mcp_call" | "mcp_tool_call"; ``` # RealtimeMessageItem ```ts type RealtimeMessageItem = | { content: object[]; itemId: string; previousItemId?: string | null; role: "system"; type: "message"; } | { content: ( | { text: string; type: "input_text"; } | { audio?: string | null; transcript: string | null; type: "input_audio"; })[]; itemId: string; previousItemId?: string | null; role: "user"; status: "in_progress" | "completed"; type: "message"; } | { content: ( | { text: string; type: "output_text"; } | { audio?: string | null; transcript?: string | null; type: "output_audio"; })[]; itemId: string; previousItemId?: string | null; role: "assistant"; status: "in_progress" | "completed" | "incomplete"; type: "message"; }; ``` # RealtimeReasoningConfig ```ts type RealtimeReasoningConfig = object; ``` ## Properties [Section titled “Properties”](#properties) ### effort? [Section titled “effort?”](#effort) ```ts optional effort?: RealtimeReasoningEffort; ``` # RealtimeReasoningEffort ```ts type RealtimeReasoningEffort = "minimal" | "low" | "medium" | "high" | "xhigh"; ``` # RealtimeSessionConfig ```ts type RealtimeSessionConfig = RealtimeSessionConfigDefinition | RealtimeSessionConfigDeprecated; ``` # RealtimeSessionConnectOptions ```ts type RealtimeSessionConnectOptions = object; ``` ## Properties [Section titled “Properties”](#properties) ### apiKey [Section titled “apiKey”](#apikey) ```ts apiKey: string | (() => string | Promise); ``` The API key to use for the connection. Pass a function to lazily load the API key. Overrides default client options. *** ### callId? [Section titled “callId?”](#callid) ```ts optional callId?: string; ``` The call ID to attach to when connecting to a SIP-initiated session. *** ### model? [Section titled “model?”](#model) ```ts optional model?: | OpenAIRealtimeModels | string & object; ``` The model to use for the connection. *** ### url? [Section titled “url?”](#url) ```ts optional url?: string; ``` The URL to use for the connection. # RealtimeSessionEventTypes ```ts type RealtimeSessionEventTypes = object; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | ------------ | | `TContext` | `unknown` | ## Properties [Section titled “Properties”](#properties) ### agent\_end [Section titled “agent\_end”](#agent_end) ```ts agent_end: [RunContext>, AgentWithOrWithoutHistory, string]; ``` Triggered when an agent ends its work on a response. *** ### agent\_handoff [Section titled “agent\_handoff”](#agent_handoff) ```ts agent_handoff: [RunContext>, AgentWithOrWithoutHistory, AgentWithOrWithoutHistory]; ``` Triggered when an agent hands off to another agent. *** ### agent\_start [Section titled “agent\_start”](#agent_start) ```ts agent_start: [RunContext>, AgentWithOrWithoutHistory, AgentInputItem[]]; ``` Triggered when an agent starts its work on a response. *** ### agent\_tool\_end [Section titled “agent\_tool\_end”](#agent_tool_end) ```ts agent_tool_end: [RunContext>, AgentWithOrWithoutHistory, FunctionTool>, string, object]; ``` Triggered when an agent ends a tool call. *** ### agent\_tool\_start [Section titled “agent\_tool\_start”](#agent_tool_start) ```ts agent_tool_start: [RunContext>, AgentWithOrWithoutHistory, FunctionTool>, object]; ``` Triggered when an agent starts a tool call. *** ### audio [Section titled “audio”](#audio) ```ts audio: [TransportLayerAudio]; ``` Triggered when there is new audio data available for playing to the user. *** ### audio\_interrupted [Section titled “audio\_interrupted”](#audio_interrupted) ```ts audio_interrupted: [RunContext>, AgentWithOrWithoutHistory]; ``` Triggered when the agent is interrupted. Can be listened to by the user to stop audio playback or give visual indicators to the user. *** ### audio\_start [Section titled “audio\_start”](#audio_start) ```ts audio_start: [RunContext>, AgentWithOrWithoutHistory]; ``` Triggered when the agent starts generating audio. *** ### audio\_stopped [Section titled “audio\_stopped”](#audio_stopped) ```ts audio_stopped: [RunContext>, AgentWithOrWithoutHistory]; ``` Triggered when the agent stops generating audio. *** ### error [Section titled “error”](#error) ```ts error: [RealtimeSessionError]; ``` Triggered when an error occurs. *** ### guardrail\_tripped [Section titled “guardrail\_tripped”](#guardrail_tripped) ```ts guardrail_tripped: [RunContext>, AgentWithOrWithoutHistory, OutputGuardrailTripwireTriggered, object]; ``` Triggered when an output guardrail is tripped. *** ### history\_added [Section titled “history\_added”](#history_added) ```ts history_added: [RealtimeItem]; ``` Triggered when a new item is added to the history. At this point the transcript/response might still be in progress. *** ### history\_updated [Section titled “history\_updated”](#history_updated) ```ts history_updated: [RealtimeItem[]]; ``` Triggered when the history got updated. Contains the full history of the conversation. *** ### mcp\_tool\_call\_completed [Section titled “mcp\_tool\_call\_completed”](#mcp_tool_call_completed) ```ts mcp_tool_call_completed: [RunContext>, AgentWithOrWithoutHistory, RealtimeMcpCallItem]; ``` Triggered when an MCP tool call is completed. *** ### mcp\_tools\_changed [Section titled “mcp\_tools\_changed”](#mcp_tools_changed) ```ts mcp_tools_changed: [RealtimeMcpToolInfo[]]; ``` Triggered when the set of currently available MCP tools changes (e.g. after a list-tools result arrives, or when the active agent changes). Carries the list of available tools filtered by the active agent’s server\_labels. *** ### tool\_approval\_requested [Section titled “tool\_approval\_requested”](#tool_approval_requested) ```ts tool_approval_requested: [RunContext>, AgentWithOrWithoutHistory, RealtimeToolApprovalRequest | RealtimeMcpApprovalRequest]; ``` Triggered when a tool approval is requested. *** ### transport\_event [Section titled “transport\_event”](#transport_event) ```ts transport_event: [TransportEvent]; ``` Emits all the raw events from the transport layer. # RealtimeSessionOptions ```ts type RealtimeSessionOptions = object; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | ------------ | | `TContext` | `unknown` | ## Properties [Section titled “Properties”](#properties) ### apiKey [Section titled “apiKey”](#apikey) ```ts apiKey: ApiKey; ``` The API key to use for the connection. Pass a function to lazily load the API key *** ### automaticallyTriggerResponseForMcpToolCalls? [Section titled “automaticallyTriggerResponseForMcpToolCalls?”](#automaticallytriggerresponseformcptoolcalls) ```ts optional automaticallyTriggerResponseForMcpToolCalls?: boolean; ``` Whether to automatically trigger a response for MCP tool calls. *** ### config? [Section titled “config?”](#config) ```ts optional config?: Partial; ``` Additional session config options. Overrides default client options. *** ### context? [Section titled “context?”](#context) ```ts optional context?: TContext; ``` Additional context to pass to the agent *** ### groupId? [Section titled “groupId?”](#groupid) ```ts optional groupId?: string; ``` A group identifier to use for tracing, to link multiple traces together. For example, if you want to connect your RealtimeSession traces with those of a backend text-based agent run. *** ### historyStoreAudio? [Section titled “historyStoreAudio?”](#historystoreaudio) ```ts optional historyStoreAudio?: boolean; ``` Whether the history copy should include a local copy of the audio data. By default it is not included in the history to save runtime memory on the client. If you wish to keep this data you can enable this option. *** ### model? [Section titled “model?”](#model) ```ts optional model?: | OpenAIRealtimeModels | string & object; ``` The model to use. *** ### outputGuardrails? [Section titled “outputGuardrails?”](#outputguardrails) ```ts optional outputGuardrails?: RealtimeOutputGuardrail[]; ``` Any output guardrails to apply to agent output in parallel *** ### outputGuardrailSettings? [Section titled “outputGuardrailSettings?”](#outputguardrailsettings) ```ts optional outputGuardrailSettings?: RealtimeOutputGuardrailSettings; ``` Configure the behavior of your guardrails *** ### toolErrorFormatter? [Section titled “toolErrorFormatter?”](#toolerrorformatter) ```ts optional toolErrorFormatter?: ToolErrorFormatter>; ``` Formats tool error messages that are returned to the model. Returning `undefined` falls back to the SDK default message. *** ### traceMetadata? [Section titled “traceMetadata?”](#tracemetadata) ```ts optional traceMetadata?: Record; ``` An optional dictionary of additional metadata to include with the trace. *** ### tracingDisabled? [Section titled “tracingDisabled?”](#tracingdisabled) ```ts optional tracingDisabled?: boolean; ``` Whether tracing is disabled for this session. If disabled, we will not trace the agent run. *** ### transport [Section titled “transport”](#transport) ```ts transport: | "webrtc" | "websocket" | RealtimeTransportLayer; ``` The transport layer to use. *** ### workflowName? [Section titled “workflowName?”](#workflowname) ```ts optional workflowName?: string; ``` The workflow name to use for tracing. # RealtimeSessionPayload ```ts type RealtimeSessionPayload = object & Record; ``` Shape of the payload that the Realtime API expects for session.create/update operations. This closely mirrors the REST `CallAcceptParams` type so that callers can feed the payload directly into the `openai.realtime.calls.accept` helper without casts. ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### type [Section titled “type”](#type) ```ts type: "realtime"; ``` # RealtimeToolCallItem ```ts type RealtimeToolCallItem = object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### arguments [Section titled “arguments”](#arguments) ```ts arguments: string; ``` ### itemId [Section titled “itemId”](#itemid) ```ts itemId: string; ``` ### name [Section titled “name”](#name) ```ts name: string; ``` ### output [Section titled “output”](#output) ```ts output: string | null; ``` ### previousItemId? [Section titled “previousItemId?”](#previousitemid) ```ts optional previousItemId?: string | null; ``` ### status [Section titled “status”](#status) ```ts status: "in_progress" | "completed" | "incomplete"; ``` ### type [Section titled “type”](#type) ```ts type: "function_call"; ``` # RealtimeTransportEventTypes ```ts type RealtimeTransportEventTypes = object; ``` ## Indexable [Section titled “Indexable”](#indexable) ```ts [key: string]: any[] ``` ## Properties [Section titled “Properties”](#properties) ### \* ```ts *: [TransportEvent]; ``` A raw event from the transport layer. Allows a user to tap directly into the events of the transport layer. *** ### audio [Section titled “audio”](#audio) ```ts audio: [TransportLayerAudio]; ``` Triggered when there is new audio data available. Might not be triggered if the transport layer handles the audio internally (WebRTC). *** ### audio\_done [Section titled “audio\_done”](#audio_done) ```ts audio_done: []; ``` Triggered when the audio generation is done. *** ### audio\_interrupted [Section titled “audio\_interrupted”](#audio_interrupted) ```ts audio_interrupted: []; ``` Triggered when the model detected that it was interrupted. This can be used by the client to stop audio playback. *** ### audio\_transcript\_delta [Section titled “audio\_transcript\_delta”](#audio_transcript_delta) ```ts audio_transcript_delta: [TransportLayerTranscriptDelta]; ``` Triggered when there is a new text delta of the transcript available. *** ### connection\_change [Section titled “connection\_change”](#connection_change) ```ts connection_change: [ConnectionStatus]; ``` Triggered whenever the connection status of the transport changes. Emits the new status after the change. *** ### error [Section titled “error”](#error) ```ts error: [TransportError]; ``` Triggered if the model / transport layer encountered an error *** ### function\_call [Section titled “function\_call”](#function_call) ```ts function_call: [TransportToolCallEvent]; ``` Triggered when the model is trying to call a function. *** ### item\_deleted [Section titled “item\_deleted”](#item_deleted) ```ts item_deleted: [RealtimeBaseItem]; ``` Triggered when an item is deleted. *** ### item\_update [Section titled “item\_update”](#item_update) ```ts item_update: [RealtimeItem]; ``` Triggered when the history is added or updated. *** ### mcp\_approval\_request [Section titled “mcp\_approval\_request”](#mcp_approval_request) ```ts mcp_approval_request: [RealtimeMcpCallApprovalRequestItem]; ``` Triggered when a remote MCP tool requires approval. *** ### mcp\_tool\_call\_completed [Section titled “mcp\_tool\_call\_completed”](#mcp_tool_call_completed) ```ts mcp_tool_call_completed: [RealtimeMcpCallItem]; ``` Triggered when an MCP tool call is completed. *** ### mcp\_tools\_listed [Section titled “mcp\_tools\_listed”](#mcp_tools_listed) ```ts mcp_tools_listed: [object]; ``` Triggered when a remote MCP server lists its tools (via mcp\_list\_tools). *** ### turn\_done [Section titled “turn\_done”](#turn_done) ```ts turn_done: [TransportLayerResponseCompleted]; ``` Triggered when the model is done generating a response for a turn. *** ### turn\_started [Section titled “turn\_started”](#turn_started) ```ts turn_started: [TransportLayerResponseStarted]; ``` Triggered when the model starts generating a response for a turn. *** ### usage\_update [Section titled “usage\_update”](#usage_update) ```ts usage_update: [Usage]; ``` Triggered when the usage update is available. # RealtimeTransportLayerConnectOptions ```ts type RealtimeTransportLayerConnectOptions = object; ``` The options for the connection to the model. ## Properties [Section titled “Properties”](#properties) ### apiKey [Section titled “apiKey”](#apikey) ```ts apiKey: ApiKey; ``` The API key to use for the connection. *** ### callId? [Section titled “callId?”](#callid) ```ts optional callId?: string; ``` The call ID to attach to instead of starting a new session. *** ### initialSessionConfig? [Section titled “initialSessionConfig?”](#initialsessionconfig) ```ts optional initialSessionConfig?: Partial; ``` The initial session config to use for the session. *** ### model? [Section titled “model?”](#model) ```ts optional model?: string; ``` The model to use for the connection. *** ### url? [Section titled “url?”](#url) ```ts optional url?: string; ``` The URL to use for the connection. # TransportError ```ts type TransportError = object; ``` Represents an error that occurred on the transport layer. ## Properties [Section titled “Properties”](#properties) ### error [Section titled “error”](#error) ```ts error: unknown; ``` *** ### type [Section titled “type”](#type) ```ts type: "error"; ``` # TransportEvent ```ts type TransportEvent = | TransportError | TransportToolCallEvent | InputAudioTranscriptionCompletedEvent | { [key: string]: any; type: string; }; ``` # TransportLayerAudio ```ts type TransportLayerAudio = object; ``` Event representing audio data from the model on the transport layer. ## Properties [Section titled “Properties”](#properties) ### data [Section titled “data”](#data) ```ts data: ArrayBuffer; ``` *** ### responseId [Section titled “responseId”](#responseid) ```ts responseId: string; ``` *** ### type [Section titled “type”](#type) ```ts type: "audio"; ``` # TransportLayerResponseCompleted ```ts type TransportLayerResponseCompleted = protocol.StreamEventResponseCompleted; ``` # TransportLayerResponseStarted ```ts type TransportLayerResponseStarted = protocol.StreamEventResponseStarted; ``` # TransportLayerTranscriptDelta ```ts type TransportLayerTranscriptDelta = object; ``` ## Properties [Section titled “Properties”](#properties) ### delta [Section titled “delta”](#delta) ```ts delta: string; ``` *** ### itemId [Section titled “itemId”](#itemid) ```ts itemId: string; ``` *** ### responseId [Section titled “responseId”](#responseid) ```ts responseId: string; ``` *** ### type [Section titled “type”](#type) ```ts type: "transcript_delta"; ``` # TransportToolCallEvent ```ts type TransportToolCallEvent = object; ``` Event representing an attempted tool call by the model on the transport layer. ## Properties [Section titled “Properties”](#properties) ### arguments [Section titled “arguments”](#arguments) ```ts arguments: string; ``` *** ### callId [Section titled “callId”](#callid) ```ts callId: string; ``` *** ### id? [Section titled “id?”](#id) ```ts optional id?: string; ``` *** ### name [Section titled “name”](#name) ```ts name: string; ``` *** ### previousItemId? [Section titled “previousItemId?”](#previousitemid) ```ts optional previousItemId?: string; ``` *** ### type [Section titled “type”](#type) ```ts type: "function_call"; ``` # WebRTCState ```ts type WebRTCState = | { callId: string | undefined; dataChannel: undefined; peerConnection: undefined; status: "disconnected"; } | { callId: string | undefined; dataChannel: RTCDataChannel; peerConnection: RTCPeerConnection; status: "connecting"; } | { callId: string | undefined; dataChannel: RTCDataChannel; peerConnection: RTCPeerConnection; status: "connected"; }; ``` The connection state of the WebRTC connection. # WebSocketState ```ts type WebSocketState = | { status: "disconnected"; websocket: undefined; } | { status: "connecting"; websocket: WebSocket; } | { status: "connected"; websocket: WebSocket; }; ``` The connection state of the WebSocket connection. # DEFAULT_OPENAI_REALTIME_MODEL ```ts const DEFAULT_OPENAI_REALTIME_MODEL: OpenAIRealtimeModels = 'gpt-realtime-2'; ``` The default model that is used during the connection if no model is provided. # DEFAULT_OPENAI_REALTIME_SESSION_CONFIG ```ts const DEFAULT_OPENAI_REALTIME_SESSION_CONFIG: Partial; ``` The default session config that gets send over during session connection unless overridden by the user. # utils ```ts const utils: object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### arrayBufferToBase64 [Section titled “arrayBufferToBase64”](#arraybuffertobase64) ```ts arrayBufferToBase64: (arrayBuffer) => string = utilImport.arrayBufferToBase64; ``` Converts an ArrayBuffer to a base64 string #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | ------------- | ------------- | ----------- | | `arrayBuffer` | `ArrayBuffer` | ‐ | #### Returns [Section titled “Returns”](#returns) `string` ### base64ToArrayBuffer [Section titled “base64ToArrayBuffer”](#base64toarraybuffer) ```ts base64ToArrayBuffer: (base64) => ArrayBuffer = utilImport.base64ToArrayBuffer; ``` Converts a base64 string to an ArrayBuffer #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | Description | | --------- | -------- | ----------- | | `base64` | `string` | ‐ | #### Returns [Section titled “Returns”](#returns-1) `ArrayBuffer` ### getLastTextFromAudioOutputMessage [Section titled “getLastTextFromAudioOutputMessage”](#getlasttextfromaudiooutputmessage) ```ts getLastTextFromAudioOutputMessage: (item) => string | undefined = utilImport.getLastTextFromAudioOutputMessage; ``` Get the last text from an audio output message #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | Description | | --------- | --------- | ----------- | | `item` | `unknown` | ‐ | #### Returns [Section titled “Returns”](#returns-2) `string` | `undefined` # Agent The class representing an AI agent configured with instructions, tools, guardrails, handoffs and more. We strongly recommend passing `instructions`, which is the “system prompt” for the agent. In addition, you can pass `handoffDescription`, which is a human-readable description of the agent, used when the agent is used inside tools/handoffs. Agents are generic on the context type. The context is a (mutable) object you create. It is passed to tool functions, handoffs, guardrails, etc. ## Extends [Section titled “Extends”](#extends) * [`AgentHooks`](/openai-agents-js/openai/agents/classes/agenthooks/)<`TContext`, `TOutput`> ## Extended by [Section titled “Extended by”](#extended-by) * [`RealtimeAgent`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/realtimeagent/) ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | ------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------- | | `TContext` | [`UnknownContext`](/openai-agents-js/openai/agents/type-aliases/unknowncontext/) | | `TOutput` *extends* [`AgentOutputType`](/openai-agents-js/openai/agents/type-aliases/agentoutputtype/) | [`TextOutput`](/openai-agents-js/openai/agents/type-aliases/textoutput/) | ## Implements [Section titled “Implements”](#implements) * [`AgentConfiguration`](/openai-agents-js/openai/agents/interfaces/agentconfiguration/)<`TContext`, `TOutput`> ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new Agent(config): Agent; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | -------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `config` | { `handoffDescription?`: `string`; `handoffOutputTypeWarningEnabled?`: `boolean`; `handoffs?`: ( \| `Agent`<`any`, `any`> \| [`Handoff`](/openai-agents-js/openai/agents/classes/handoff/)<`any`, `TOutput`>)\[]; `inputGuardrails?`: [`InputGuardrail`](/openai-agents-js/openai/agents/interfaces/inputguardrail/)\[]; `instructions?`: `string` \| ((`runContext`, `agent`) => `string` \| `Promise`<`string`>); `mcpConfig?`: { `convertSchemasToStrict?`: `boolean`; `errorFunction?`: \| [`MCPToolErrorFunction`](/openai-agents-js/openai/agents/type-aliases/mcptoolerrorfunction/) \| `null`; `includeServerInToolNames?`: `boolean`; }; `mcpServers?`: [`MCPServer`](/openai-agents-js/openai/agents/interfaces/mcpserver/)\[]; `model?`: `string` \| [`Model`](/openai-agents-js/openai/agents/interfaces/model/); `modelSettings?`: [`ModelSettings`](/openai-agents-js/openai/agents/type-aliases/modelsettings/); `name`: `string`; `outputGuardrails?`: [`OutputGuardrail`](/openai-agents-js/openai/agents/interfaces/outputguardrail/)<`TOutput`, `TContext`>\[]; `outputType?`: `TOutput`; `prompt?`: `Prompt` \| ((`runContext`, `agent`) => `Prompt` \| `Promise`<`Prompt`>); `resetToolChoice?`: `boolean`; `tools?`: [`Tool`](/openai-agents-js/openai/agents/type-aliases/tool/)<`TContext`>\[]; `toolUseBehavior?`: [`ToolUseBehavior`](/openai-agents-js/openai/agents/type-aliases/toolusebehavior/); } | ‐ | | `config.handoffDescription?` | `string` | A description of the agent. This is used when the agent is used as a handoff, so that an LLM knows what it does and when to invoke it. | | `config.handoffOutputTypeWarningEnabled?` | `boolean` | The warning log would be enabled when multiple output types by handoff agents are detected. | | `config.handoffs?` | ( \| `Agent`<`any`, `any`> \| [`Handoff`](/openai-agents-js/openai/agents/classes/handoff/)<`any`, `TOutput`>)\[] | Handoffs are sub-agents that the agent can delegate to. You can provide a list of handoffs, and the agent can choose to delegate to them if relevant. Allows for separation of concerns and modularity. | | `config.inputGuardrails?` | [`InputGuardrail`](/openai-agents-js/openai/agents/interfaces/inputguardrail/)\[] | A list of checks that run in parallel to the agent by default; set `runInParallel` to false to block LLM/tool calls until the guardrail completes. Runs only if the agent is the first agent in the chain. | | `config.instructions?` | `string` \| ((`runContext`, `agent`) => `string` \| `Promise`<`string`>) | The instructions for the agent. Will be used as the “system prompt” when this agent is invoked. Describes what the agent should do, and how it responds.Can either be a string, or a function that dynamically generates instructions for the agent. If you provide a function, it will be called with the context and the agent instance. It must return a string. | | `config.mcpConfig?` | { `convertSchemasToStrict?`: `boolean`; `errorFunction?`: \| [`MCPToolErrorFunction`](/openai-agents-js/openai/agents/type-aliases/mcptoolerrorfunction/) \| `null`; `includeServerInToolNames?`: `boolean`; } | Configuration for MCP servers used by this agent. | | `config.mcpConfig.convertSchemasToStrict?` | `boolean` | Try to convert MCP tool schemas to strict JSON schema. | | `config.mcpConfig.errorFunction?` | \| [`MCPToolErrorFunction`](/openai-agents-js/openai/agents/type-aliases/mcptoolerrorfunction/) \| `null` | Optional function to convert MCP tool failures into model-visible messages. Set to null to rethrow errors instead of converting them. Server-level errorFunction values take precedence. | | `config.mcpConfig.includeServerInToolNames?` | `boolean` | Prefix local MCP tool names with their server name before exposing them to the model. The SDK still invokes the original MCP tool name on the original server. | | `config.mcpServers?` | [`MCPServer`](/openai-agents-js/openai/agents/interfaces/mcpserver/)\[] | A list of [Model Context Protocol](https://modelcontextprotocol.io/) servers the agent can use. Every time the agent runs, it will include tools from these servers in the list of available tools.NOTE: You are expected to manage the lifecycle of these servers. Specifically, you must call `server.connect()` before passing it to the agent, and `server.close()` when the server is no longer needed. Consider using `connectMcpServers` or `MCPServers` to keep open/close in the same place. | | `config.model?` | `string` \| [`Model`](/openai-agents-js/openai/agents/interfaces/model/) | The model implementation to use when invoking the LLM.By default, if not set, the agent will use the default model returned by getDefaultModel (currently “gpt-5.4-mini”). | | `config.modelSettings?` | [`ModelSettings`](/openai-agents-js/openai/agents/type-aliases/modelsettings/) | Configures model-specific tuning parameters (e.g. temperature, top\_p, etc.) | | `config.name` | `string` | ‐ | | `config.outputGuardrails?` | [`OutputGuardrail`](/openai-agents-js/openai/agents/interfaces/outputguardrail/)<`TOutput`, `TContext`>\[] | A list of checks that run on the final output of the agent, after generating a response. Runs only if the agent produces a final output. | | `config.outputType?` | `TOutput` | The type of the output object. If not provided, the output will be a string. | | `config.prompt?` | `Prompt` \| ((`runContext`, `agent`) => `Prompt` \| `Promise`<`Prompt`>) | The prompt template to use for the agent (OpenAI Responses API only).Can either be a prompt template object, or a function that returns a prompt template object. If a function is provided, it will be called with the run context and the agent instance. It must return a prompt template object. | | `config.resetToolChoice?` | `boolean` | Whether to reset the tool choice to the default value after a tool has been called. Defaults to `true`. This ensures that the agent doesn’t enter an infinite loop of tool usage. | | `config.tools?` | [`Tool`](/openai-agents-js/openai/agents/type-aliases/tool/)<`TContext`>\[] | A list of tools the agent can use. | | `config.toolUseBehavior?` | [`ToolUseBehavior`](/openai-agents-js/openai/agents/type-aliases/toolusebehavior/) | This lets you configure how tool use is handled.- run\_llm\_again: The default behavior. Tools are run, and then the LLM receives the results and gets to respond. - stop\_on\_first\_tool: The output of the first tool call is used as the final output. This means that the LLM does not process the result of the tool call. - A list of tool names: The agent will stop running if any of the tools in the list are called. The final output will be the output of the first matching tool call. The LLM does not process the result of the tool call. - A function: if you pass a function, it will be called with the run context and the list of tool results. It must return a `ToolsToFinalOutputResult`, which determines whether the tool call resulted in a final output.NOTE: This configuration is specific to `FunctionTools`. Hosted tools, such as file search, web search, etc. are always processed by the LLM | #### Returns [Section titled “Returns”](#returns) `Agent`<`TContext`, `TOutput`> #### Overrides [Section titled “Overrides”](#overrides) [`AgentHooks`](/openai-agents-js/openai/agents/classes/agenthooks/).[`constructor`](/openai-agents-js/openai/agents/classes/agenthooks/#constructor) ## Properties [Section titled “Properties”](#properties) ### handoffDescription [Section titled “handoffDescription”](#handoffdescription) ```ts handoffDescription: string; ``` A description of the agent. This is used when the agent is used as a handoff, so that an LLM knows what it does and when to invoke it. #### Implementation of [Section titled “Implementation of”](#implementation-of) [`AgentConfiguration`](/openai-agents-js/openai/agents/interfaces/agentconfiguration/).[`handoffDescription`](/openai-agents-js/openai/agents/interfaces/agentconfiguration/#handoffdescription) *** ### handoffs [Section titled “handoffs”](#handoffs) ```ts handoffs: ( | Handoff | Agent)[]; ``` Handoffs are sub-agents that the agent can delegate to. You can provide a list of handoffs, and the agent can choose to delegate to them if relevant. Allows for separation of concerns and modularity. #### Implementation of [Section titled “Implementation of”](#implementation-of-1) [`AgentConfiguration`](/openai-agents-js/openai/agents/interfaces/agentconfiguration/).[`handoffs`](/openai-agents-js/openai/agents/interfaces/agentconfiguration/#handoffs) *** ### inputGuardrails [Section titled “inputGuardrails”](#inputguardrails) ```ts inputGuardrails: InputGuardrail[]; ``` A list of checks that run in parallel to the agent by default; set `runInParallel` to false to block LLM/tool calls until the guardrail completes. Runs only if the agent is the first agent in the chain. #### Implementation of [Section titled “Implementation of”](#implementation-of-2) [`AgentConfiguration`](/openai-agents-js/openai/agents/interfaces/agentconfiguration/).[`inputGuardrails`](/openai-agents-js/openai/agents/interfaces/agentconfiguration/#inputguardrails) *** ### instructions [Section titled “instructions”](#instructions) ```ts instructions: string | ((runContext, agent) => string | Promise); ``` The instructions for the agent. Will be used as the “system prompt” when this agent is invoked. Describes what the agent should do, and how it responds. Can either be a string, or a function that dynamically generates instructions for the agent. If you provide a function, it will be called with the context and the agent instance. It must return a string. #### Implementation of [Section titled “Implementation of”](#implementation-of-3) [`AgentConfiguration`](/openai-agents-js/openai/agents/interfaces/agentconfiguration/).[`instructions`](/openai-agents-js/openai/agents/interfaces/agentconfiguration/#instructions) *** ### mcpConfig [Section titled “mcpConfig”](#mcpconfig) ```ts mcpConfig: object; ``` Configuration for MCP servers used by this agent. | Name | Type | Description | | --------------------------- | --------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `convertSchemasToStrict?` | `boolean` | Try to convert MCP tool schemas to strict JSON schema. | | `errorFunction?` | \| [`MCPToolErrorFunction`](/openai-agents-js/openai/agents/type-aliases/mcptoolerrorfunction/) \| `null` | Optional function to convert MCP tool failures into model-visible messages. Set to null to rethrow errors instead of converting them. Server-level errorFunction values take precedence. | | `includeServerInToolNames?` | `boolean` | Prefix local MCP tool names with their server name before exposing them to the model. The SDK still invokes the original MCP tool name on the original server. | #### Implementation of [Section titled “Implementation of”](#implementation-of-4) [`AgentConfiguration`](/openai-agents-js/openai/agents/interfaces/agentconfiguration/).[`mcpConfig`](/openai-agents-js/openai/agents/interfaces/agentconfiguration/#mcpconfig) *** ### mcpServers [Section titled “mcpServers”](#mcpservers) ```ts mcpServers: MCPServer[]; ``` A list of [Model Context Protocol](https://modelcontextprotocol.io/) servers the agent can use. Every time the agent runs, it will include tools from these servers in the list of available tools. NOTE: You are expected to manage the lifecycle of these servers. Specifically, you must call `server.connect()` before passing it to the agent, and `server.close()` when the server is no longer needed. Consider using `connectMcpServers` or `MCPServers` to keep open/close in the same place. #### Implementation of [Section titled “Implementation of”](#implementation-of-5) [`AgentConfiguration`](/openai-agents-js/openai/agents/interfaces/agentconfiguration/).[`mcpServers`](/openai-agents-js/openai/agents/interfaces/agentconfiguration/#mcpservers) *** ### model [Section titled “model”](#model) ```ts model: string | Model; ``` The model implementation to use when invoking the LLM. By default, if not set, the agent will use the default model returned by getDefaultModel (currently “gpt-5.4-mini”). #### Implementation of [Section titled “Implementation of”](#implementation-of-6) [`AgentConfiguration`](/openai-agents-js/openai/agents/interfaces/agentconfiguration/).[`model`](/openai-agents-js/openai/agents/interfaces/agentconfiguration/#model) *** ### modelSettings [Section titled “modelSettings”](#modelsettings) ```ts modelSettings: ModelSettings; ``` Configures model-specific tuning parameters (e.g. temperature, top\_p, etc.) #### Implementation of [Section titled “Implementation of”](#implementation-of-7) [`AgentConfiguration`](/openai-agents-js/openai/agents/interfaces/agentconfiguration/).[`modelSettings`](/openai-agents-js/openai/agents/interfaces/agentconfiguration/#modelsettings) *** ### name [Section titled “name”](#name) ```ts name: string; ``` #### Implementation of [Section titled “Implementation of”](#implementation-of-8) [`AgentConfiguration`](/openai-agents-js/openai/agents/interfaces/agentconfiguration/).[`name`](/openai-agents-js/openai/agents/interfaces/agentconfiguration/#name) *** ### outputGuardrails [Section titled “outputGuardrails”](#outputguardrails) ```ts outputGuardrails: OutputGuardrail, TContext>[]; ``` A list of checks that run on the final output of the agent, after generating a response. Runs only if the agent produces a final output. #### Implementation of [Section titled “Implementation of”](#implementation-of-9) [`AgentConfiguration`](/openai-agents-js/openai/agents/interfaces/agentconfiguration/).[`outputGuardrails`](/openai-agents-js/openai/agents/interfaces/agentconfiguration/#outputguardrails) *** ### outputType [Section titled “outputType”](#outputtype) ```ts outputType: TOutput; ``` The type of the output object. If not provided, the output will be a string. #### Implementation of [Section titled “Implementation of”](#implementation-of-10) [`AgentConfiguration`](/openai-agents-js/openai/agents/interfaces/agentconfiguration/).[`outputType`](/openai-agents-js/openai/agents/interfaces/agentconfiguration/#outputtype) *** ### prompt? [Section titled “prompt?”](#prompt) ```ts optional prompt?: Prompt | ((runContext, agent) => Prompt | Promise); ``` The prompt template to use for the agent (OpenAI Responses API only). Can either be a prompt template object, or a function that returns a prompt template object. If a function is provided, it will be called with the run context and the agent instance. It must return a prompt template object. #### Implementation of [Section titled “Implementation of”](#implementation-of-11) [`AgentConfiguration`](/openai-agents-js/openai/agents/interfaces/agentconfiguration/).[`prompt`](/openai-agents-js/openai/agents/interfaces/agentconfiguration/#prompt) *** ### resetToolChoice [Section titled “resetToolChoice”](#resettoolchoice) ```ts resetToolChoice: boolean; ``` Whether to reset the tool choice to the default value after a tool has been called. Defaults to `true`. This ensures that the agent doesn’t enter an infinite loop of tool usage. #### Implementation of [Section titled “Implementation of”](#implementation-of-12) [`AgentConfiguration`](/openai-agents-js/openai/agents/interfaces/agentconfiguration/).[`resetToolChoice`](/openai-agents-js/openai/agents/interfaces/agentconfiguration/#resettoolchoice) *** ### tools [Section titled “tools”](#tools) ```ts tools: Tool[]; ``` A list of tools the agent can use. #### Implementation of [Section titled “Implementation of”](#implementation-of-13) [`AgentConfiguration`](/openai-agents-js/openai/agents/interfaces/agentconfiguration/).[`tools`](/openai-agents-js/openai/agents/interfaces/agentconfiguration/#tools) *** ### toolUseBehavior [Section titled “toolUseBehavior”](#toolusebehavior) ```ts toolUseBehavior: ToolUseBehavior; ``` This lets you configure how tool use is handled. * run\_llm\_again: The default behavior. Tools are run, and then the LLM receives the results and gets to respond. * stop\_on\_first\_tool: The output of the first tool call is used as the final output. This means that the LLM does not process the result of the tool call. * A list of tool names: The agent will stop running if any of the tools in the list are called. The final output will be the output of the first matching tool call. The LLM does not process the result of the tool call. * A function: if you pass a function, it will be called with the run context and the list of tool results. It must return a `ToolsToFinalOutputResult`, which determines whether the tool call resulted in a final output. NOTE: This configuration is specific to `FunctionTools`. Hosted tools, such as file search, web search, etc. are always processed by the LLM #### Implementation of [Section titled “Implementation of”](#implementation-of-14) [`AgentConfiguration`](/openai-agents-js/openai/agents/interfaces/agentconfiguration/).[`toolUseBehavior`](/openai-agents-js/openai/agents/interfaces/agentconfiguration/#toolusebehavior) *** ### DEFAULT\_MODEL\_PLACEHOLDER [Section titled “DEFAULT\_MODEL\_PLACEHOLDER”](#default_model_placeholder) ```ts static DEFAULT_MODEL_PLACEHOLDER: string; ``` ## Accessors [Section titled “Accessors”](#accessors) ### outputSchemaName [Section titled “outputSchemaName”](#outputschemaname) #### Get Signature [Section titled “Get Signature”](#get-signature) ```ts get outputSchemaName(): string; ``` Output schema name. ##### Returns [Section titled “Returns”](#returns-1) `string` ## Methods [Section titled “Methods”](#methods) ### asTool() [Section titled “asTool()”](#astool) #### Call Signature [Section titled “Call Signature”](#call-signature) ```ts asTool(this, options): AgentTool>; ``` Transform this agent into a tool, callable by other agents. This is different from handoffs in two ways: 1. In handoffs, the new agent receives the conversation history. In this tool, the new agent receives generated input. 2. In handoffs, the new agent takes over the conversation. In this tool, the new agent is called as a tool, and the conversation is continued by the original agent. ##### Type Parameters [Section titled “Type Parameters”](#type-parameters-1) | Type Parameter | Default type | | ------------------------------------------------- | ------------------------------ | | `TAgent` *extends* `Agent`<`TContext`, `TOutput`> | `Agent`<`TContext`, `TOutput`> | ##### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | Description | | --------- | --------------------------------------------------- | --------------------- | | `this` | `TAgent` | ‐ | | `options` | `AgentToolOptionsWithDefault`<`TContext`, `TAgent`> | Options for the tool. | ##### Returns [Section titled “Returns”](#returns-2) `AgentTool`<`TContext`, `TAgent`, `ZodObject`<{ `input`: `ZodString`; }, `$strip`>> A tool that runs the agent and returns the output text. #### Call Signature [Section titled “Call Signature”](#call-signature-1) ```ts asTool(this, options): AgentTool; ``` Transform this agent into a tool, callable by other agents. This is different from handoffs in two ways: 1. In handoffs, the new agent receives the conversation history. In this tool, the new agent receives generated input. 2. In handoffs, the new agent takes over the conversation. In this tool, the new agent is called as a tool, and the conversation is continued by the original agent. ##### Type Parameters [Section titled “Type Parameters”](#type-parameters-2) | Type Parameter | Default type | | -------------------------------------------------- | ------------------------------------------------ | | `TAgent` *extends* `Agent`<`TContext`, `TOutput`> | `Agent`<`TContext`, `TOutput`> | | `TParameters` *extends* `AgentToolInputParameters` | `ZodObject`<{ `input`: `ZodString`; }, `$strip`> | ##### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | Description | | --------- | --------------------------------------------------------------------- | --------------------- | | `this` | `TAgent` | ‐ | | `options` | `AgentToolOptionsWithParameters`<`TContext`, `TAgent`, `TParameters`> | Options for the tool. | ##### Returns [Section titled “Returns”](#returns-3) `AgentTool`<`TContext`, `TAgent`, `TParameters`> A tool that runs the agent and returns the output text. *** ### clone() [Section titled “clone()”](#clone) ```ts clone(config): Agent; ``` Makes a copy of the agent, with the given arguments changed. For example, you could do: ```plaintext const newAgent = agent.clone({ instructions: 'New instructions' }) ``` #### Parameters [Section titled “Parameters”](#parameters-3) | Parameter | Type | Description | | --------- | ------------------------------------------------------------------------------------------------------------------------ | ---------------------------------- | | `config` | `Partial`<[`AgentConfiguration`](/openai-agents-js/openai/agents/interfaces/agentconfiguration/)<`TContext`, `TOutput`>> | A partial configuration to change. | #### Returns [Section titled “Returns”](#returns-4) `Agent`<`TContext`, `TOutput`> A new agent with the given changes. *** ### emit() [Section titled “emit()”](#emit) ```ts emit(type, ...args): boolean; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-3) | Type Parameter | | ------------------------------------------------------------ | | `K` *extends* keyof `AgentHookEvents`<`TContext`, `TOutput`> | #### Parameters [Section titled “Parameters”](#parameters-4) | Parameter | Type | | --------- | ---------------------------------------------- | | `type` | `K` | | …`args` | `AgentHookEvents`<`TContext`, `TOutput`>\[`K`] | #### Returns [Section titled “Returns”](#returns-5) `boolean` #### Inherited from [Section titled “Inherited from”](#inherited-from) [`AgentHooks`](/openai-agents-js/openai/agents/classes/agenthooks/).[`emit`](/openai-agents-js/openai/agents/classes/agenthooks/#emit) *** ### getAllTools() [Section titled “getAllTools()”](#getalltools) ```ts getAllTools(runContext): Promise[]>; ``` ALl agent tools, including the MCPl and function tools. #### Parameters [Section titled “Parameters”](#parameters-5) | Parameter | Type | | ------------ | ------------------------------------------------------------------------------- | | `runContext` | [`RunContext`](/openai-agents-js/openai/agents/classes/runcontext/)<`TContext`> | #### Returns [Section titled “Returns”](#returns-6) `Promise`<[`Tool`](/openai-agents-js/openai/agents/type-aliases/tool/)<`TContext`>\[]> all configured tools *** ### getEnabledHandoffs() [Section titled “getEnabledHandoffs()”](#getenabledhandoffs) ```ts getEnabledHandoffs(runContext): Promise[]>; ``` Returns the handoffs that should be exposed to the model for the current run. Handoffs that provide an `isEnabled` function returning `false` are omitted. #### Parameters [Section titled “Parameters”](#parameters-6) | Parameter | Type | | ------------ | ------------------------------------------------------------------------------- | | `runContext` | [`RunContext`](/openai-agents-js/openai/agents/classes/runcontext/)<`TContext`> | #### Returns [Section titled “Returns”](#returns-7) `Promise`<[`Handoff`](/openai-agents-js/openai/agents/classes/handoff/)<`any`, `any`>\[]> *** ### getMcpTools() [Section titled “getMcpTools()”](#getmcptools) ```ts getMcpTools(runContext): Promise[]>; ``` Fetches the available tools from the MCP servers. #### Parameters [Section titled “Parameters”](#parameters-7) | Parameter | Type | | ------------ | ------------------------------------------------------------------------------- | | `runContext` | [`RunContext`](/openai-agents-js/openai/agents/classes/runcontext/)<`TContext`> | #### Returns [Section titled “Returns”](#returns-8) `Promise`<[`Tool`](/openai-agents-js/openai/agents/type-aliases/tool/)<`TContext`>\[]> the MCP powered tools *** ### getPrompt() [Section titled “getPrompt()”](#getprompt) ```ts getPrompt(runContext): Promise; ``` Returns the prompt template for the agent, if defined. If the agent has a function as its prompt, this function will be called with the runContext and the agent instance. #### Parameters [Section titled “Parameters”](#parameters-8) | Parameter | Type | | ------------ | ------------------------------------------------------------------------------- | | `runContext` | [`RunContext`](/openai-agents-js/openai/agents/classes/runcontext/)<`TContext`> | #### Returns [Section titled “Returns”](#returns-9) `Promise`<`Prompt` | `undefined`> *** ### getSystemPrompt() [Section titled “getSystemPrompt()”](#getsystemprompt) ```ts getSystemPrompt(runContext): Promise; ``` Returns the system prompt for the agent. If the agent has a function as its instructions, this function will be called with the runContext and the agent instance. #### Parameters [Section titled “Parameters”](#parameters-9) | Parameter | Type | | ------------ | ------------------------------------------------------------------------------- | | `runContext` | [`RunContext`](/openai-agents-js/openai/agents/classes/runcontext/)<`TContext`> | #### Returns [Section titled “Returns”](#returns-10) `Promise`<`string` | `undefined`> *** ### hasExplicitToolConfig() [Section titled “hasExplicitToolConfig()”](#hasexplicittoolconfig) ```ts hasExplicitToolConfig(): boolean; ``` #### Returns [Section titled “Returns”](#returns-11) `boolean` *** ### off() [Section titled “off()”](#off) ```ts off(type, listener): EventEmitter; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-4) | Type Parameter | | ------------------------------------------------------------ | | `K` *extends* keyof `AgentHookEvents`<`TContext`, `TOutput`> | #### Parameters [Section titled “Parameters”](#parameters-10) | Parameter | Type | | ---------- | ------------------- | | `type` | `K` | | `listener` | (…`args`) => `void` | #### Returns [Section titled “Returns”](#returns-12) `EventEmitter`<`EventTypes`> #### Inherited from [Section titled “Inherited from”](#inherited-from-1) [`AgentHooks`](/openai-agents-js/openai/agents/classes/agenthooks/).[`off`](/openai-agents-js/openai/agents/classes/agenthooks/#off) *** ### on() [Section titled “on()”](#on) ```ts on(type, listener): EventEmitter; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-5) | Type Parameter | | ------------------------------------------------------------ | | `K` *extends* keyof `AgentHookEvents`<`TContext`, `TOutput`> | #### Parameters [Section titled “Parameters”](#parameters-11) | Parameter | Type | | ---------- | ------------------- | | `type` | `K` | | `listener` | (…`args`) => `void` | #### Returns [Section titled “Returns”](#returns-13) `EventEmitter`<`EventTypes`> #### Inherited from [Section titled “Inherited from”](#inherited-from-2) [`AgentHooks`](/openai-agents-js/openai/agents/classes/agenthooks/).[`on`](/openai-agents-js/openai/agents/classes/agenthooks/#on) *** ### once() [Section titled “once()”](#once) ```ts once(type, listener): EventEmitter; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-6) | Type Parameter | | ------------------------------------------------------------ | | `K` *extends* keyof `AgentHookEvents`<`TContext`, `TOutput`> | #### Parameters [Section titled “Parameters”](#parameters-12) | Parameter | Type | | ---------- | ------------------- | | `type` | `K` | | `listener` | (…`args`) => `void` | #### Returns [Section titled “Returns”](#returns-14) `EventEmitter`<`EventTypes`> #### Inherited from [Section titled “Inherited from”](#inherited-from-3) [`AgentHooks`](/openai-agents-js/openai/agents/classes/agenthooks/).[`once`](/openai-agents-js/openai/agents/classes/agenthooks/#once) *** ### processFinalOutput() [Section titled “processFinalOutput()”](#processfinaloutput) ```ts processFinalOutput(output): ResolvedAgentOutput; ``` Processes the final output of the agent. #### Parameters [Section titled “Parameters”](#parameters-13) | Parameter | Type | Description | | --------- | -------- | ------------------------ | | `output` | `string` | The output of the agent. | #### Returns [Section titled “Returns”](#returns-15) `ResolvedAgentOutput`<`TOutput`> The parsed out. *** ### toJSON() [Section titled “toJSON()”](#tojson) ```ts toJSON(): object; ``` Returns a JSON representation of the agent, which is serializable. #### Returns [Section titled “Returns”](#returns-16) `object` A JSON object containing the agent’s name. ##### name [Section titled “name”](#name-1) ```ts name: string; ``` *** ### create() [Section titled “create()”](#create) ```ts static create(config): Agent>; ``` Create an Agent with handoffs and automatically infer the union type for TOutput from the handoff agents’ output types. #### Type Parameters [Section titled “Type Parameters”](#type-parameters-7) | Type Parameter | Default type | | ------------------------------------------------------------------------------------------------------------------------------------------- | ------------ | | `TOutput` *extends* [`AgentOutputType`](/openai-agents-js/openai/agents/type-aliases/agentoutputtype/)<`unknown`> | `"text"` | | `Handoffs` *extends* readonly ( \| `Agent`<`any`, `any`> \| [`Handoff`](/openai-agents-js/openai/agents/classes/handoff/)<`any`, `any`>)\[] | \[] | #### Parameters [Section titled “Parameters”](#parameters-14) | Parameter | Type | | --------- | ------------------------------------------------------------------------------------------------------------------------- | | `config` | [`AgentConfigWithHandoffs`](/openai-agents-js/openai/agents/type-aliases/agentconfigwithhandoffs/)<`TOutput`, `Handoffs`> | #### Returns [Section titled “Returns”](#returns-17) `Agent`<`unknown`, `TOutput` | `HandoffsOutputUnion`<`Handoffs`>> # AgentHooks Event emitter that every Agent instance inherits from and that emits events for the lifecycle of the agent. ## Extends [Section titled “Extends”](#extends) * `EventEmitterDelegate`<`AgentHookEvents`<`TContext`, `TOutput`>> ## Extended by [Section titled “Extended by”](#extended-by) * [`Agent`](/openai-agents-js/openai/agents/classes/agent/) ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | ------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------- | | `TContext` | [`UnknownContext`](/openai-agents-js/openai/agents/type-aliases/unknowncontext/) | | `TOutput` *extends* [`AgentOutputType`](/openai-agents-js/openai/agents/type-aliases/agentoutputtype/) | [`TextOutput`](/openai-agents-js/openai/agents/type-aliases/textoutput/) | ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new AgentHooks(): AgentHooks; ``` #### Returns [Section titled “Returns”](#returns) `AgentHooks`<`TContext`, `TOutput`> #### Inherited from [Section titled “Inherited from”](#inherited-from) ```ts EventEmitterDelegate>.constructor ``` ## Methods [Section titled “Methods”](#methods) ### emit() [Section titled “emit()”](#emit) ```ts emit(type, ...args): boolean; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-1) | Type Parameter | | ------------------------------------------------------------ | | `K` *extends* keyof `AgentHookEvents`<`TContext`, `TOutput`> | #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ---------------------------------------------- | | `type` | `K` | | …`args` | `AgentHookEvents`<`TContext`, `TOutput`>\[`K`] | #### Returns [Section titled “Returns”](#returns-1) `boolean` #### Inherited from [Section titled “Inherited from”](#inherited-from-1) ```ts EventEmitterDelegate.emit ``` *** ### off() [Section titled “off()”](#off) ```ts off(type, listener): EventEmitter; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-2) | Type Parameter | | ------------------------------------------------------------ | | `K` *extends* keyof `AgentHookEvents`<`TContext`, `TOutput`> | #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | ---------- | ------------------- | | `type` | `K` | | `listener` | (…`args`) => `void` | #### Returns [Section titled “Returns”](#returns-2) `EventEmitter`<`EventTypes`> #### Inherited from [Section titled “Inherited from”](#inherited-from-2) ```ts EventEmitterDelegate.off ``` *** ### on() [Section titled “on()”](#on) ```ts on(type, listener): EventEmitter; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-3) | Type Parameter | | ------------------------------------------------------------ | | `K` *extends* keyof `AgentHookEvents`<`TContext`, `TOutput`> | #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | ---------- | ------------------- | | `type` | `K` | | `listener` | (…`args`) => `void` | #### Returns [Section titled “Returns”](#returns-3) `EventEmitter`<`EventTypes`> #### Inherited from [Section titled “Inherited from”](#inherited-from-3) ```ts EventEmitterDelegate.on ``` *** ### once() [Section titled “once()”](#once) ```ts once(type, listener): EventEmitter; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-4) | Type Parameter | | ------------------------------------------------------------ | | `K` *extends* keyof `AgentHookEvents`<`TContext`, `TOutput`> | #### Parameters [Section titled “Parameters”](#parameters-3) | Parameter | Type | | ---------- | ------------------- | | `type` | `K` | | `listener` | (…`args`) => `void` | #### Returns [Section titled “Returns”](#returns-4) `EventEmitter`<`EventTypes`> #### Inherited from [Section titled “Inherited from”](#inherited-from-4) ```ts EventEmitterDelegate.once ``` # AgentsError Base class for all errors thrown by the library. ## Extends [Section titled “Extends”](#extends) * `Error` ## Extended by [Section titled “Extended by”](#extended-by) * [`GuardrailExecutionError`](/openai-agents-js/openai/agents/classes/guardrailexecutionerror/) * [`InputGuardrailTripwireTriggered`](/openai-agents-js/openai/agents/classes/inputguardrailtripwiretriggered/) * [`MaxTurnsExceededError`](/openai-agents-js/openai/agents/classes/maxturnsexceedederror/) * [`ModelBehaviorError`](/openai-agents-js/openai/agents/classes/modelbehaviorerror/) * [`ModelRefusalError`](/openai-agents-js/openai/agents/classes/modelrefusalerror/) * [`OutputGuardrailTripwireTriggered`](/openai-agents-js/openai/agents/classes/outputguardrailtripwiretriggered/) * [`ToolInputGuardrailTripwireTriggered`](/openai-agents-js/openai/agents/classes/toolinputguardrailtripwiretriggered/) * [`ToolOutputGuardrailTripwireTriggered`](/openai-agents-js/openai/agents/classes/tooloutputguardrailtripwiretriggered/) * [`ToolCallError`](/openai-agents-js/openai/agents/classes/toolcallerror/) * [`ToolTimeoutError`](/openai-agents-js/openai/agents/classes/tooltimeouterror/) * [`UserError`](/openai-agents-js/openai/agents/classes/usererror/) * [`SystemError`](/openai-agents-js/openai/agents/classes/systemerror/) ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new AgentsError(message, state?): AgentsError; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | | `message` | `string` | | `state?` | [`RunState`](/openai-agents-js/openai/agents/classes/runstate/)<`any`, [`Agent`](/openai-agents-js/openai/agents/classes/agent/)<`any`, `any`>> | #### Returns [Section titled “Returns”](#returns) `AgentsError` #### Overrides [Section titled “Overrides”](#overrides) ```ts Error.constructor ``` ## Properties [Section titled “Properties”](#properties) ### message [Section titled “message”](#message) ```ts message: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from) ```ts Error.message ``` *** ### name [Section titled “name”](#name) ```ts name: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-1) ```ts Error.name ``` *** ### stack? [Section titled “stack?”](#stack) ```ts optional stack?: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-2) ```ts Error.stack ``` *** ### state? [Section titled “state?”](#state) ```ts optional state?: RunState>; ``` *** ### stackTraceLimit [Section titled “stackTraceLimit”](#stacktracelimit) ```ts static stackTraceLimit: number; ``` The `Error.stackTraceLimit` property specifies the number of stack frames collected by a stack trace (whether generated by `new Error().stack` or `Error.captureStackTrace(obj)`). The default value is `10` but may be set to any valid JavaScript number. Changes will affect any stack trace captured *after* the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames. #### Inherited from [Section titled “Inherited from”](#inherited-from-3) ```ts Error.stackTraceLimit ``` ## Methods [Section titled “Methods”](#methods) ### captureStackTrace() [Section titled “captureStackTrace()”](#capturestacktrace) ```ts static captureStackTrace(targetObject, constructorOpt?): void; ``` Creates a `.stack` property on `targetObject`, which when accessed returns a string representing the location in the code at which `Error.captureStackTrace()` was called. ```js const myObject = {}; Error.captureStackTrace(myObject); myObject.stack; // Similar to `new Error().stack` ``` The first line of the trace will be prefixed with `${myObject.name}: ${myObject.message}`. The optional `constructorOpt` argument accepts a function. If given, all frames above `constructorOpt`, including `constructorOpt`, will be omitted from the generated stack trace. The `constructorOpt` argument is useful for hiding implementation details of error generation from the user. For instance: ```js function a() { b(); } function b() { c(); } function c() { // Create an error without stack trace to avoid calculating the stack trace twice. const { stackTraceLimit } = Error; Error.stackTraceLimit = 0; const error = new Error(); Error.stackTraceLimit = stackTraceLimit; // Capture the stack trace above function b Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace throw error; } a(); ``` #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | ----------------- | ---------- | | `targetObject` | `object` | | `constructorOpt?` | `Function` | #### Returns [Section titled “Returns”](#returns-1) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-4) ```ts Error.captureStackTrace ``` *** ### prepareStackTrace() [Section titled “prepareStackTrace()”](#preparestacktrace) ```ts static prepareStackTrace(err, stackTraces): any; ``` #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | ------------- | ------------- | | `err` | `Error` | | `stackTraces` | `CallSite`\[] | #### Returns [Section titled “Returns”](#returns-2) `any` #### See [Section titled “See”](#see) #### Inherited from [Section titled “Inherited from”](#inherited-from-5) ```ts Error.prepareStackTrace ``` # BatchTraceProcessor Interface for processing traces ## Implements [Section titled “Implements”](#implements) * [`TracingProcessor`](/openai-agents-js/openai/agents/interfaces/tracingprocessor/) ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new BatchTraceProcessor(exporter, __namedParameters?): BatchTraceProcessor; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | -------------------- | -------------------------------------------------------------------------------- | | `exporter` | [`TracingExporter`](/openai-agents-js/openai/agents/interfaces/tracingexporter/) | | `__namedParameters?` | `BatchTraceProcessorOptions` | #### Returns [Section titled “Returns”](#returns) `BatchTraceProcessor` ## Methods [Section titled “Methods”](#methods) ### forceFlush() [Section titled “forceFlush()”](#forceflush) ```ts forceFlush(): Promise; ``` Called when a trace is being flushed #### Returns [Section titled “Returns”](#returns-1) `Promise`<`void`> #### Implementation of [Section titled “Implementation of”](#implementation-of) [`TracingProcessor`](/openai-agents-js/openai/agents/interfaces/tracingprocessor/).[`forceFlush`](/openai-agents-js/openai/agents/interfaces/tracingprocessor/#forceflush) *** ### onSpanEnd() [Section titled “onSpanEnd()”](#onspanend) ```ts onSpanEnd(span): Promise; ``` Called when a span is ended #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | --------- | ------ | | `span` | `Span` | #### Returns [Section titled “Returns”](#returns-2) `Promise`<`void`> #### Implementation of [Section titled “Implementation of”](#implementation-of-1) [`TracingProcessor`](/openai-agents-js/openai/agents/interfaces/tracingprocessor/).[`onSpanEnd`](/openai-agents-js/openai/agents/interfaces/tracingprocessor/#onspanend) *** ### onSpanStart() [Section titled “onSpanStart()”](#onspanstart) ```ts onSpanStart(_span): Promise; ``` Called when a span is started #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | --------- | ------ | | `_span` | `Span` | #### Returns [Section titled “Returns”](#returns-3) `Promise`<`void`> #### Implementation of [Section titled “Implementation of”](#implementation-of-2) [`TracingProcessor`](/openai-agents-js/openai/agents/interfaces/tracingprocessor/).[`onSpanStart`](/openai-agents-js/openai/agents/interfaces/tracingprocessor/#onspanstart) *** ### onTraceEnd() [Section titled “onTraceEnd()”](#ontraceend) ```ts onTraceEnd(_trace): Promise; ``` Called when a trace is ended #### Parameters [Section titled “Parameters”](#parameters-3) | Parameter | Type | | --------- | --------------------------------------------------------- | | `_trace` | [`Trace`](/openai-agents-js/openai/agents/classes/trace/) | #### Returns [Section titled “Returns”](#returns-4) `Promise`<`void`> #### Implementation of [Section titled “Implementation of”](#implementation-of-3) [`TracingProcessor`](/openai-agents-js/openai/agents/interfaces/tracingprocessor/).[`onTraceEnd`](/openai-agents-js/openai/agents/interfaces/tracingprocessor/#ontraceend) *** ### onTraceStart() [Section titled “onTraceStart()”](#ontracestart) ```ts onTraceStart(trace): Promise; ``` Called when a trace is started #### Parameters [Section titled “Parameters”](#parameters-4) | Parameter | Type | | --------- | --------------------------------------------------------- | | `trace` | [`Trace`](/openai-agents-js/openai/agents/classes/trace/) | #### Returns [Section titled “Returns”](#returns-5) `Promise`<`void`> #### Implementation of [Section titled “Implementation of”](#implementation-of-4) [`TracingProcessor`](/openai-agents-js/openai/agents/interfaces/tracingprocessor/).[`onTraceStart`](/openai-agents-js/openai/agents/interfaces/tracingprocessor/#ontracestart) *** ### shutdown() [Section titled “shutdown()”](#shutdown) ```ts shutdown(timeout?): Promise; ``` Called when the trace processor is shutting down #### Parameters [Section titled “Parameters”](#parameters-5) | Parameter | Type | | ---------- | -------- | | `timeout?` | `number` | #### Returns [Section titled “Returns”](#returns-6) `Promise`<`void`> #### Implementation of [Section titled “Implementation of”](#implementation-of-5) [`TracingProcessor`](/openai-agents-js/openai/agents/interfaces/tracingprocessor/).[`shutdown`](/openai-agents-js/openai/agents/interfaces/tracingprocessor/#shutdown) *** ### start() [Section titled “start()”](#start) ```ts start(): void; ``` Called when the trace processor should start processing traces. Only available if the processor is performing tasks like exporting traces in a loop to start the loop #### Returns [Section titled “Returns”](#returns-7) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-6) [`TracingProcessor`](/openai-agents-js/openai/agents/interfaces/tracingprocessor/).[`start`](/openai-agents-js/openai/agents/interfaces/tracingprocessor/#start) # ConsoleSpanExporter Prints the traces and spans to the console ## Implements [Section titled “Implements”](#implements) * [`TracingExporter`](/openai-agents-js/openai/agents/interfaces/tracingexporter/) ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new ConsoleSpanExporter(): ConsoleSpanExporter; ``` #### Returns [Section titled “Returns”](#returns) `ConsoleSpanExporter` ## Methods [Section titled “Methods”](#methods) ### export() [Section titled “export()”](#export) ```ts export(items): Promise; ``` Export the given traces and spans #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | --------- | ------------------------------------------------------------------------ | ------------------------------ | | `items` | ([`Trace`](/openai-agents-js/openai/agents/classes/trace/) \| `Span`)\[] | The traces and spans to export | #### Returns [Section titled “Returns”](#returns-1) `Promise`<`void`> #### Implementation of [Section titled “Implementation of”](#implementation-of) [`TracingExporter`](/openai-agents-js/openai/agents/interfaces/tracingexporter/).[`export`](/openai-agents-js/openai/agents/interfaces/tracingexporter/#export) # GuardrailExecutionError Error thrown when a guardrail execution fails. ## Extends [Section titled “Extends”](#extends) * [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/) ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new GuardrailExecutionError( message, error, state?): GuardrailExecutionError; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | | `message` | `string` | | `error` | `Error` | | `state?` | [`RunState`](/openai-agents-js/openai/agents/classes/runstate/)<`any`, [`Agent`](/openai-agents-js/openai/agents/classes/agent/)<`any`, `any`>> | #### Returns [Section titled “Returns”](#returns) `GuardrailExecutionError` #### Overrides [Section titled “Overrides”](#overrides) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`constructor`](/openai-agents-js/openai/agents/classes/agentserror/#constructor) ## Properties [Section titled “Properties”](#properties) ### error [Section titled “error”](#error) ```ts error: Error; ``` *** ### message [Section titled “message”](#message) ```ts message: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`message`](/openai-agents-js/openai/agents/classes/agentserror/#message) *** ### name [Section titled “name”](#name) ```ts name: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-1) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`name`](/openai-agents-js/openai/agents/classes/agentserror/#name) *** ### stack? [Section titled “stack?”](#stack) ```ts optional stack?: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-2) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`stack`](/openai-agents-js/openai/agents/classes/agentserror/#stack) *** ### state? [Section titled “state?”](#state) ```ts optional state?: RunState>; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-3) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`state`](/openai-agents-js/openai/agents/classes/agentserror/#state) *** ### stackTraceLimit [Section titled “stackTraceLimit”](#stacktracelimit) ```ts static stackTraceLimit: number; ``` The `Error.stackTraceLimit` property specifies the number of stack frames collected by a stack trace (whether generated by `new Error().stack` or `Error.captureStackTrace(obj)`). The default value is `10` but may be set to any valid JavaScript number. Changes will affect any stack trace captured *after* the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames. #### Inherited from [Section titled “Inherited from”](#inherited-from-4) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`stackTraceLimit`](/openai-agents-js/openai/agents/classes/agentserror/#stacktracelimit) ## Methods [Section titled “Methods”](#methods) ### captureStackTrace() [Section titled “captureStackTrace()”](#capturestacktrace) ```ts static captureStackTrace(targetObject, constructorOpt?): void; ``` Creates a `.stack` property on `targetObject`, which when accessed returns a string representing the location in the code at which `Error.captureStackTrace()` was called. ```js const myObject = {}; Error.captureStackTrace(myObject); myObject.stack; // Similar to `new Error().stack` ``` The first line of the trace will be prefixed with `${myObject.name}: ${myObject.message}`. The optional `constructorOpt` argument accepts a function. If given, all frames above `constructorOpt`, including `constructorOpt`, will be omitted from the generated stack trace. The `constructorOpt` argument is useful for hiding implementation details of error generation from the user. For instance: ```js function a() { b(); } function b() { c(); } function c() { // Create an error without stack trace to avoid calculating the stack trace twice. const { stackTraceLimit } = Error; Error.stackTraceLimit = 0; const error = new Error(); Error.stackTraceLimit = stackTraceLimit; // Capture the stack trace above function b Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace throw error; } a(); ``` #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | ----------------- | ---------- | | `targetObject` | `object` | | `constructorOpt?` | `Function` | #### Returns [Section titled “Returns”](#returns-1) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-5) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`captureStackTrace`](/openai-agents-js/openai/agents/classes/agentserror/#capturestacktrace) *** ### prepareStackTrace() [Section titled “prepareStackTrace()”](#preparestacktrace) ```ts static prepareStackTrace(err, stackTraces): any; ``` #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | ------------- | ------------- | | `err` | `Error` | | `stackTraces` | `CallSite`\[] | #### Returns [Section titled “Returns”](#returns-2) `any` #### See [Section titled “See”](#see) #### Inherited from [Section titled “Inherited from”](#inherited-from-6) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`prepareStackTrace`](/openai-agents-js/openai/agents/classes/agentserror/#preparestacktrace) # Handoff ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | ------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------- | | `TContext` | [`UnknownContext`](/openai-agents-js/openai/agents/type-aliases/unknowncontext/) | | `TOutput` *extends* [`AgentOutputType`](/openai-agents-js/openai/agents/type-aliases/agentoutputtype/) | [`TextOutput`](/openai-agents-js/openai/agents/type-aliases/textoutput/) | ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new Handoff(agent, onInvokeHandoff): Handoff; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ----------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `agent` | [`Agent`](/openai-agents-js/openai/agents/classes/agent/)<`TContext`, `TOutput`> | | `onInvokeHandoff` | (`context`, `args`) => \| [`Agent`](/openai-agents-js/openai/agents/classes/agent/)<`TContext`, `TOutput`> \| `Promise`<[`Agent`](/openai-agents-js/openai/agents/classes/agent/)<`TContext`, `TOutput`>> | #### Returns [Section titled “Returns”](#returns) `Handoff`<`TContext`, `TOutput`> ## Properties [Section titled “Properties”](#properties) ### agent [Section titled “agent”](#agent) ```ts agent: Agent; ``` The agent that is being handed off to. *** ### agentName [Section titled “agentName”](#agentname) ```ts agentName: string; ``` The name of the agent that is being handed off to. *** ### inputFilter? [Section titled “inputFilter?”](#inputfilter) ```ts optional inputFilter?: HandoffInputFilter; ``` A function that filters the inputs that are passed to the next agent. By default, the new agent sees the entire conversation history. In some cases, you may want to filter inputs e.g. to remove older inputs, or remove tools from existing inputs. The function will receive the entire conversation hisstory so far, including the input item that triggered the handoff and a tool call output item representing the handoff tool’s output. You are free to modify the input history or new items as you see fit. The next agent that runs will receive \`handoffInputData.allItems *** ### inputJsonSchema [Section titled “inputJsonSchema”](#inputjsonschema) ```ts inputJsonSchema: JsonObjectSchema; ``` The JSON schema for the handoff input. Can be empty if the handoff does not take an input *** ### isEnabled [Section titled “isEnabled”](#isenabled) ```ts isEnabled: HandoffEnabledFunction; ``` *** ### onInvokeHandoff [Section titled “onInvokeHandoff”](#oninvokehandoff) ```ts onInvokeHandoff: (context, args) => | Agent | Promise>; ``` The function that invokes the handoff. The parameters passed are: 1. The handoff run context 2. The arguments from the LLM, as a JSON string. Empty string if inputJsonSchema is empty. Must return an agent #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | --------- | ------------------------------------------------------------------------------- | | `context` | [`RunContext`](/openai-agents-js/openai/agents/classes/runcontext/)<`TContext`> | | `args` | `string` | #### Returns [Section titled “Returns”](#returns-1) \| [`Agent`](/openai-agents-js/openai/agents/classes/agent/)<`TContext`, `TOutput`> | `Promise`<[`Agent`](/openai-agents-js/openai/agents/classes/agent/)<`TContext`, `TOutput`>> *** ### strictJsonSchema [Section titled “strictJsonSchema”](#strictjsonschema) ```ts strictJsonSchema: boolean; ``` Whether the input JSON schema is in strict mode. We **strongly** recommend setting this to true, as it increases the likelihood of correct JSON input. *** ### toolDescription [Section titled “toolDescription”](#tooldescription) ```ts toolDescription: string; ``` The description of the tool that represents the handoff. *** ### toolName [Section titled “toolName”](#toolname) ```ts toolName: string; ``` The name of the tool that represents the handoff. ## Methods [Section titled “Methods”](#methods) ### getHandoffAsFunctionTool() [Section titled “getHandoffAsFunctionTool()”](#gethandoffasfunctiontool) ```ts getHandoffAsFunctionTool(): object; ``` Returns a function tool definition that can be used to invoke the handoff. #### Returns [Section titled “Returns”](#returns-2) `object` ##### description [Section titled “description”](#description) ```ts description: string; ``` ##### name [Section titled “name”](#name) ```ts name: string; ``` ##### parameters [Section titled “parameters”](#parameters-2) ```ts parameters: JsonObjectSchema; ``` ##### strict [Section titled “strict”](#strict) ```ts strict: boolean; ``` ##### type [Section titled “type”](#type) ```ts type: "function"; ``` # InputGuardrailTripwireTriggered Error thrown when an input guardrail tripwire is triggered. ## Extends [Section titled “Extends”](#extends) * [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/) ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new InputGuardrailTripwireTriggered( message, result, state?): InputGuardrailTripwireTriggered; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ------------------------------------------------------------------------------------------ | | `message` | `string` | | `result` | [`InputGuardrailResult`](/openai-agents-js/openai/agents/interfaces/inputguardrailresult/) | | `state?` | [`RunState`](/openai-agents-js/openai/agents/classes/runstate/)<`any`, `any`> | #### Returns [Section titled “Returns”](#returns) `InputGuardrailTripwireTriggered` #### Overrides [Section titled “Overrides”](#overrides) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`constructor`](/openai-agents-js/openai/agents/classes/agentserror/#constructor) ## Properties [Section titled “Properties”](#properties) ### message [Section titled “message”](#message) ```ts message: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`message`](/openai-agents-js/openai/agents/classes/agentserror/#message) *** ### name [Section titled “name”](#name) ```ts name: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-1) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`name`](/openai-agents-js/openai/agents/classes/agentserror/#name) *** ### result [Section titled “result”](#result) ```ts result: InputGuardrailResult; ``` *** ### stack? [Section titled “stack?”](#stack) ```ts optional stack?: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-2) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`stack`](/openai-agents-js/openai/agents/classes/agentserror/#stack) *** ### state? [Section titled “state?”](#state) ```ts optional state?: RunState>; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-3) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`state`](/openai-agents-js/openai/agents/classes/agentserror/#state) *** ### stackTraceLimit [Section titled “stackTraceLimit”](#stacktracelimit) ```ts static stackTraceLimit: number; ``` The `Error.stackTraceLimit` property specifies the number of stack frames collected by a stack trace (whether generated by `new Error().stack` or `Error.captureStackTrace(obj)`). The default value is `10` but may be set to any valid JavaScript number. Changes will affect any stack trace captured *after* the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames. #### Inherited from [Section titled “Inherited from”](#inherited-from-4) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`stackTraceLimit`](/openai-agents-js/openai/agents/classes/agentserror/#stacktracelimit) ## Methods [Section titled “Methods”](#methods) ### captureStackTrace() [Section titled “captureStackTrace()”](#capturestacktrace) ```ts static captureStackTrace(targetObject, constructorOpt?): void; ``` Creates a `.stack` property on `targetObject`, which when accessed returns a string representing the location in the code at which `Error.captureStackTrace()` was called. ```js const myObject = {}; Error.captureStackTrace(myObject); myObject.stack; // Similar to `new Error().stack` ``` The first line of the trace will be prefixed with `${myObject.name}: ${myObject.message}`. The optional `constructorOpt` argument accepts a function. If given, all frames above `constructorOpt`, including `constructorOpt`, will be omitted from the generated stack trace. The `constructorOpt` argument is useful for hiding implementation details of error generation from the user. For instance: ```js function a() { b(); } function b() { c(); } function c() { // Create an error without stack trace to avoid calculating the stack trace twice. const { stackTraceLimit } = Error; Error.stackTraceLimit = 0; const error = new Error(); Error.stackTraceLimit = stackTraceLimit; // Capture the stack trace above function b Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace throw error; } a(); ``` #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | ----------------- | ---------- | | `targetObject` | `object` | | `constructorOpt?` | `Function` | #### Returns [Section titled “Returns”](#returns-1) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-5) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`captureStackTrace`](/openai-agents-js/openai/agents/classes/agentserror/#capturestacktrace) *** ### prepareStackTrace() [Section titled “prepareStackTrace()”](#preparestacktrace) ```ts static prepareStackTrace(err, stackTraces): any; ``` #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | ------------- | ------------- | | `err` | `Error` | | `stackTraces` | `CallSite`\[] | #### Returns [Section titled “Returns”](#returns-2) `any` #### See [Section titled “See”](#see) #### Inherited from [Section titled “Inherited from”](#inherited-from-6) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`prepareStackTrace`](/openai-agents-js/openai/agents/classes/agentserror/#preparestacktrace) # MaxTurnsExceededError Error thrown when the maximum number of turns is exceeded. ## Extends [Section titled “Extends”](#extends) * [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/) ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new MaxTurnsExceededError(message, state?): MaxTurnsExceededError; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | | `message` | `string` | | `state?` | [`RunState`](/openai-agents-js/openai/agents/classes/runstate/)<`any`, [`Agent`](/openai-agents-js/openai/agents/classes/agent/)<`any`, `any`>> | #### Returns [Section titled “Returns”](#returns) `MaxTurnsExceededError` #### Inherited from [Section titled “Inherited from”](#inherited-from) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`constructor`](/openai-agents-js/openai/agents/classes/agentserror/#constructor) ## Properties [Section titled “Properties”](#properties) ### message [Section titled “message”](#message) ```ts message: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-1) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`message`](/openai-agents-js/openai/agents/classes/agentserror/#message) *** ### name [Section titled “name”](#name) ```ts name: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-2) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`name`](/openai-agents-js/openai/agents/classes/agentserror/#name) *** ### stack? [Section titled “stack?”](#stack) ```ts optional stack?: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-3) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`stack`](/openai-agents-js/openai/agents/classes/agentserror/#stack) *** ### state? [Section titled “state?”](#state) ```ts optional state?: RunState>; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-4) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`state`](/openai-agents-js/openai/agents/classes/agentserror/#state) *** ### stackTraceLimit [Section titled “stackTraceLimit”](#stacktracelimit) ```ts static stackTraceLimit: number; ``` The `Error.stackTraceLimit` property specifies the number of stack frames collected by a stack trace (whether generated by `new Error().stack` or `Error.captureStackTrace(obj)`). The default value is `10` but may be set to any valid JavaScript number. Changes will affect any stack trace captured *after* the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames. #### Inherited from [Section titled “Inherited from”](#inherited-from-5) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`stackTraceLimit`](/openai-agents-js/openai/agents/classes/agentserror/#stacktracelimit) ## Methods [Section titled “Methods”](#methods) ### captureStackTrace() [Section titled “captureStackTrace()”](#capturestacktrace) ```ts static captureStackTrace(targetObject, constructorOpt?): void; ``` Creates a `.stack` property on `targetObject`, which when accessed returns a string representing the location in the code at which `Error.captureStackTrace()` was called. ```js const myObject = {}; Error.captureStackTrace(myObject); myObject.stack; // Similar to `new Error().stack` ``` The first line of the trace will be prefixed with `${myObject.name}: ${myObject.message}`. The optional `constructorOpt` argument accepts a function. If given, all frames above `constructorOpt`, including `constructorOpt`, will be omitted from the generated stack trace. The `constructorOpt` argument is useful for hiding implementation details of error generation from the user. For instance: ```js function a() { b(); } function b() { c(); } function c() { // Create an error without stack trace to avoid calculating the stack trace twice. const { stackTraceLimit } = Error; Error.stackTraceLimit = 0; const error = new Error(); Error.stackTraceLimit = stackTraceLimit; // Capture the stack trace above function b Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace throw error; } a(); ``` #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | ----------------- | ---------- | | `targetObject` | `object` | | `constructorOpt?` | `Function` | #### Returns [Section titled “Returns”](#returns-1) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-6) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`captureStackTrace`](/openai-agents-js/openai/agents/classes/agentserror/#capturestacktrace) *** ### prepareStackTrace() [Section titled “prepareStackTrace()”](#preparestacktrace) ```ts static prepareStackTrace(err, stackTraces): any; ``` #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | ------------- | ------------- | | `err` | `Error` | | `stackTraces` | `CallSite`\[] | #### Returns [Section titled “Returns”](#returns-2) `any` #### See [Section titled “See”](#see) #### Inherited from [Section titled “Inherited from”](#inherited-from-7) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`prepareStackTrace`](/openai-agents-js/openai/agents/classes/agentserror/#preparestacktrace) # MCPServers Manages MCP server lifecycle and exposes only connected servers. ## Properties [Section titled “Properties”](#properties) ### \[asyncDispose] [Section titled “\[asyncDispose\]”](#asyncdispose) ```ts [asyncDispose]: () => Promise; ``` #### Returns [Section titled “Returns”](#returns) `Promise`<`void`> ## Accessors [Section titled “Accessors”](#accessors) ### active [Section titled “active”](#active) #### Get Signature [Section titled “Get Signature”](#get-signature) ```ts get active(): MCPServer[]; ``` ##### Returns [Section titled “Returns”](#returns-1) [`MCPServer`](/openai-agents-js/openai/agents/interfaces/mcpserver/)\[] *** ### all [Section titled “all”](#all) #### Get Signature [Section titled “Get Signature”](#get-signature-1) ```ts get all(): MCPServer[]; ``` ##### Returns [Section titled “Returns”](#returns-2) [`MCPServer`](/openai-agents-js/openai/agents/interfaces/mcpserver/)\[] *** ### errors [Section titled “errors”](#errors) #### Get Signature [Section titled “Get Signature”](#get-signature-2) ```ts get errors(): ReadonlyMap; ``` ##### Returns [Section titled “Returns”](#returns-3) `ReadonlyMap`<[`MCPServer`](/openai-agents-js/openai/agents/interfaces/mcpserver/), `Error`> *** ### failed [Section titled “failed”](#failed) #### Get Signature [Section titled “Get Signature”](#get-signature-3) ```ts get failed(): MCPServer[]; ``` ##### Returns [Section titled “Returns”](#returns-4) [`MCPServer`](/openai-agents-js/openai/agents/interfaces/mcpserver/)\[] ## Methods [Section titled “Methods”](#methods) ### close() [Section titled “close()”](#close) ```ts close(): Promise; ``` #### Returns [Section titled “Returns”](#returns-5) `Promise`<`void`> *** ### reconnect() [Section titled “reconnect()”](#reconnect) ```ts reconnect(options?): Promise; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ---------- | -------------------------------------------------------------------------------------------------------- | | `options?` | [`MCPServersReconnectOptions`](/openai-agents-js/openai/agents/type-aliases/mcpserversreconnectoptions/) | #### Returns [Section titled “Returns”](#returns-6) `Promise`<[`MCPServer`](/openai-agents-js/openai/agents/interfaces/mcpserver/)\[]> *** ### open() [Section titled “open()”](#open) ```ts static open(servers, options?): Promise; ``` #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | ---------- | -------------------------------------------------------------------------------------- | | `servers` | [`MCPServer`](/openai-agents-js/openai/agents/interfaces/mcpserver/)\[] | | `options?` | [`MCPServersOptions`](/openai-agents-js/openai/agents/type-aliases/mcpserversoptions/) | #### Returns [Section titled “Returns”](#returns-7) `Promise`<`MCPServers`> # MCPServerSSE Extended MCP server surface for servers that expose resources. ## Extends [Section titled “Extends”](#extends) * `BaseMCPServerSSE` ## Implements [Section titled “Implements”](#implements) * [`MCPServerWithResources`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/) ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new MCPServerSSE(options): MCPServerSSE; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | --------------------- | | `options` | `MCPServerSSEOptions` | #### Returns [Section titled “Returns”](#returns) `MCPServerSSE` #### Overrides [Section titled “Overrides”](#overrides) ```ts BaseMCPServerSSE.constructor ``` ## Properties [Section titled “Properties”](#properties) ### cacheToolsList [Section titled “cacheToolsList”](#cachetoolslist) ```ts cacheToolsList: boolean; ``` #### Implementation of [Section titled “Implementation of”](#implementation-of) [`MCPServerWithResources`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/).[`cacheToolsList`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/#cachetoolslist) #### Inherited from [Section titled “Inherited from”](#inherited-from) ```ts BaseMCPServerSSE.cacheToolsList ``` *** ### errorFunction? [Section titled “errorFunction?”](#errorfunction) ```ts optional errorFunction?: | MCPToolErrorFunction | null; ``` Optional function to convert MCP tool failures into model-visible messages. Set to null to rethrow errors instead of converting them. #### Implementation of [Section titled “Implementation of”](#implementation-of-1) [`MCPServerWithResources`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/).[`errorFunction`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/#errorfunction) #### Inherited from [Section titled “Inherited from”](#inherited-from-1) ```ts BaseMCPServerSSE.errorFunction ``` *** ### toolFilter? [Section titled “toolFilter?”](#toolfilter) ```ts optional toolFilter?: | MCPToolFilterCallable | MCPToolFilterStatic; ``` #### Implementation of [Section titled “Implementation of”](#implementation-of-2) [`MCPServerWithResources`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/).[`toolFilter`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/#toolfilter) #### Inherited from [Section titled “Inherited from”](#inherited-from-2) ```ts BaseMCPServerSSE.toolFilter ``` *** ### toolMetaResolver? [Section titled “toolMetaResolver?”](#toolmetaresolver) ```ts optional toolMetaResolver?: MCPToolMetaResolver; ``` #### Implementation of [Section titled “Implementation of”](#implementation-of-3) [`MCPServerWithResources`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/).[`toolMetaResolver`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/#toolmetaresolver) #### Inherited from [Section titled “Inherited from”](#inherited-from-3) ```ts BaseMCPServerSSE.toolMetaResolver ``` ## Accessors [Section titled “Accessors”](#accessors) ### name [Section titled “name”](#name) #### Get Signature [Section titled “Get Signature”](#get-signature) ```ts get name(): string; ``` ##### Returns [Section titled “Returns”](#returns-1) `string` #### Implementation of [Section titled “Implementation of”](#implementation-of-4) [`MCPServerWithResources`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/).[`name`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/#name) #### Overrides [Section titled “Overrides”](#overrides-1) ```ts BaseMCPServerSSE.name ``` ## Methods [Section titled “Methods”](#methods) ### callTool() [Section titled “callTool()”](#calltool) ```ts callTool( toolName, args, meta?): Promise; ``` #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | ---------- | --------------------------------------- | | `toolName` | `string` | | `args` | `Record`<`string`, `unknown`> \| `null` | | `meta?` | `Record`<`string`, `unknown`> \| `null` | #### Returns [Section titled “Returns”](#returns-2) `Promise`<`object`\[]> #### Implementation of [Section titled “Implementation of”](#implementation-of-5) [`MCPServerWithResources`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/).[`callTool`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/#calltool) #### Overrides [Section titled “Overrides”](#overrides-2) ```ts BaseMCPServerSSE.callTool ``` *** ### close() [Section titled “close()”](#close) ```ts close(): Promise; ``` #### Returns [Section titled “Returns”](#returns-3) `Promise`<`void`> #### Implementation of [Section titled “Implementation of”](#implementation-of-6) [`MCPServerWithResources`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/).[`close`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/#close) #### Overrides [Section titled “Overrides”](#overrides-3) ```ts BaseMCPServerSSE.close ``` *** ### connect() [Section titled “connect()”](#connect) ```ts connect(): Promise; ``` #### Returns [Section titled “Returns”](#returns-4) `Promise`<`void`> #### Implementation of [Section titled “Implementation of”](#implementation-of-7) [`MCPServerWithResources`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/).[`connect`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/#connect) #### Overrides [Section titled “Overrides”](#overrides-4) ```ts BaseMCPServerSSE.connect ``` *** ### invalidateToolsCache() [Section titled “invalidateToolsCache()”](#invalidatetoolscache) ```ts invalidateToolsCache(): Promise; ``` #### Returns [Section titled “Returns”](#returns-5) `Promise`<`void`> #### Implementation of [Section titled “Implementation of”](#implementation-of-8) [`MCPServerWithResources`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/).[`invalidateToolsCache`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/#invalidatetoolscache) #### Overrides [Section titled “Overrides”](#overrides-5) ```ts BaseMCPServerSSE.invalidateToolsCache ``` *** ### listResources() [Section titled “listResources()”](#listresources) ```ts listResources(params?): Promise; ``` #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | --------- | ---------------------------------------------------------------------------------------------- | | `params?` | [`MCPListResourcesParams`](/openai-agents-js/openai/agents/interfaces/mcplistresourcesparams/) | #### Returns [Section titled “Returns”](#returns-6) `Promise`<[`MCPListResourcesResult`](/openai-agents-js/openai/agents/interfaces/mcplistresourcesresult/)> #### Implementation of [Section titled “Implementation of”](#implementation-of-9) [`MCPServerWithResources`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/).[`listResources`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/#listresources) #### Overrides [Section titled “Overrides”](#overrides-6) ```ts BaseMCPServerSSE.listResources ``` *** ### listResourceTemplates() [Section titled “listResourceTemplates()”](#listresourcetemplates) ```ts listResourceTemplates(params?): Promise; ``` #### Parameters [Section titled “Parameters”](#parameters-3) | Parameter | Type | | --------- | ---------------------------------------------------------------------------------------------- | | `params?` | [`MCPListResourcesParams`](/openai-agents-js/openai/agents/interfaces/mcplistresourcesparams/) | #### Returns [Section titled “Returns”](#returns-7) `Promise`<[`MCPListResourceTemplatesResult`](/openai-agents-js/openai/agents/interfaces/mcplistresourcetemplatesresult/)> #### Implementation of [Section titled “Implementation of”](#implementation-of-10) [`MCPServerWithResources`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/).[`listResourceTemplates`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/#listresourcetemplates) #### Overrides [Section titled “Overrides”](#overrides-7) ```ts BaseMCPServerSSE.listResourceTemplates ``` *** ### listTools() [Section titled “listTools()”](#listtools) ```ts listTools(): Promise; ``` #### Returns [Section titled “Returns”](#returns-8) `Promise`<`object`\[]> #### Implementation of [Section titled “Implementation of”](#implementation-of-11) [`MCPServerWithResources`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/).[`listTools`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/#listtools) #### Overrides [Section titled “Overrides”](#overrides-8) ```ts BaseMCPServerSSE.listTools ``` *** ### readResource() [Section titled “readResource()”](#readresource) ```ts readResource(uri): Promise; ``` #### Parameters [Section titled “Parameters”](#parameters-4) | Parameter | Type | | --------- | -------- | | `uri` | `string` | #### Returns [Section titled “Returns”](#returns-9) `Promise`<[`MCPReadResourceResult`](/openai-agents-js/openai/agents/interfaces/mcpreadresourceresult/)> #### Implementation of [Section titled “Implementation of”](#implementation-of-12) [`MCPServerWithResources`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/).[`readResource`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/#readresource) #### Overrides [Section titled “Overrides”](#overrides-9) ```ts BaseMCPServerSSE.readResource ``` # MCPServerStdio Public interface of an MCP server that provides tools. You can use this class to pass MCP server settings to your agent. ## Extends [Section titled “Extends”](#extends) * `BaseMCPServerStdio` ## Implements [Section titled “Implements”](#implements) * [`MCPServerWithResources`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/) ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new MCPServerStdio(options): MCPServerStdio; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ----------------------- | | `options` | `MCPServerStdioOptions` | #### Returns [Section titled “Returns”](#returns) `MCPServerStdio` #### Overrides [Section titled “Overrides”](#overrides) ```ts BaseMCPServerStdio.constructor ``` ## Properties [Section titled “Properties”](#properties) ### cacheToolsList [Section titled “cacheToolsList”](#cachetoolslist) ```ts cacheToolsList: boolean; ``` #### Implementation of [Section titled “Implementation of”](#implementation-of) [`MCPServerWithResources`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/).[`cacheToolsList`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/#cachetoolslist) #### Inherited from [Section titled “Inherited from”](#inherited-from) ```ts BaseMCPServerStdio.cacheToolsList ``` *** ### errorFunction? [Section titled “errorFunction?”](#errorfunction) ```ts optional errorFunction?: | MCPToolErrorFunction | null; ``` Optional function to convert MCP tool failures into model-visible messages. Set to null to rethrow errors instead of converting them. #### Implementation of [Section titled “Implementation of”](#implementation-of-1) [`MCPServerWithResources`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/).[`errorFunction`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/#errorfunction) #### Inherited from [Section titled “Inherited from”](#inherited-from-1) ```ts BaseMCPServerStdio.errorFunction ``` *** ### toolFilter? [Section titled “toolFilter?”](#toolfilter) ```ts optional toolFilter?: | MCPToolFilterCallable | MCPToolFilterStatic; ``` #### Implementation of [Section titled “Implementation of”](#implementation-of-2) [`MCPServerWithResources`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/).[`toolFilter`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/#toolfilter) #### Inherited from [Section titled “Inherited from”](#inherited-from-2) ```ts BaseMCPServerStdio.toolFilter ``` *** ### toolMetaResolver? [Section titled “toolMetaResolver?”](#toolmetaresolver) ```ts optional toolMetaResolver?: MCPToolMetaResolver; ``` #### Implementation of [Section titled “Implementation of”](#implementation-of-3) [`MCPServerWithResources`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/).[`toolMetaResolver`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/#toolmetaresolver) #### Inherited from [Section titled “Inherited from”](#inherited-from-3) ```ts BaseMCPServerStdio.toolMetaResolver ``` ## Accessors [Section titled “Accessors”](#accessors) ### name [Section titled “name”](#name) #### Get Signature [Section titled “Get Signature”](#get-signature) ```ts get name(): string; ``` ##### Returns [Section titled “Returns”](#returns-1) `string` #### Implementation of [Section titled “Implementation of”](#implementation-of-4) [`MCPServerWithResources`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/).[`name`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/#name) #### Overrides [Section titled “Overrides”](#overrides-1) ```ts BaseMCPServerStdio.name ``` ## Methods [Section titled “Methods”](#methods) ### callTool() [Section titled “callTool()”](#calltool) ```ts callTool( toolName, args, meta?): Promise; ``` #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | ---------- | --------------------------------------- | | `toolName` | `string` | | `args` | `Record`<`string`, `unknown`> \| `null` | | `meta?` | `Record`<`string`, `unknown`> \| `null` | #### Returns [Section titled “Returns”](#returns-2) `Promise`<`object`\[]> #### Implementation of [Section titled “Implementation of”](#implementation-of-5) [`MCPServerWithResources`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/).[`callTool`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/#calltool) #### Overrides [Section titled “Overrides”](#overrides-2) ```ts BaseMCPServerStdio.callTool ``` *** ### close() [Section titled “close()”](#close) ```ts close(): Promise; ``` #### Returns [Section titled “Returns”](#returns-3) `Promise`<`void`> #### Implementation of [Section titled “Implementation of”](#implementation-of-6) [`MCPServerWithResources`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/).[`close`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/#close) #### Overrides [Section titled “Overrides”](#overrides-3) ```ts BaseMCPServerStdio.close ``` *** ### connect() [Section titled “connect()”](#connect) ```ts connect(): Promise; ``` #### Returns [Section titled “Returns”](#returns-4) `Promise`<`void`> #### Implementation of [Section titled “Implementation of”](#implementation-of-7) [`MCPServerWithResources`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/).[`connect`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/#connect) #### Overrides [Section titled “Overrides”](#overrides-4) ```ts BaseMCPServerStdio.connect ``` *** ### invalidateToolsCache() [Section titled “invalidateToolsCache()”](#invalidatetoolscache) ```ts invalidateToolsCache(): Promise; ``` #### Returns [Section titled “Returns”](#returns-5) `Promise`<`void`> #### Implementation of [Section titled “Implementation of”](#implementation-of-8) [`MCPServerWithResources`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/).[`invalidateToolsCache`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/#invalidatetoolscache) #### Overrides [Section titled “Overrides”](#overrides-5) ```ts BaseMCPServerStdio.invalidateToolsCache ``` *** ### listResources() [Section titled “listResources()”](#listresources) ```ts listResources(params?): Promise; ``` #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | --------- | ---------------------------------------------------------------------------------------------- | | `params?` | [`MCPListResourcesParams`](/openai-agents-js/openai/agents/interfaces/mcplistresourcesparams/) | #### Returns [Section titled “Returns”](#returns-6) `Promise`<[`MCPListResourcesResult`](/openai-agents-js/openai/agents/interfaces/mcplistresourcesresult/)> #### Implementation of [Section titled “Implementation of”](#implementation-of-9) [`MCPServerWithResources`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/).[`listResources`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/#listresources) #### Overrides [Section titled “Overrides”](#overrides-6) ```ts BaseMCPServerStdio.listResources ``` *** ### listResourceTemplates() [Section titled “listResourceTemplates()”](#listresourcetemplates) ```ts listResourceTemplates(params?): Promise; ``` #### Parameters [Section titled “Parameters”](#parameters-3) | Parameter | Type | | --------- | ---------------------------------------------------------------------------------------------- | | `params?` | [`MCPListResourcesParams`](/openai-agents-js/openai/agents/interfaces/mcplistresourcesparams/) | #### Returns [Section titled “Returns”](#returns-7) `Promise`<[`MCPListResourceTemplatesResult`](/openai-agents-js/openai/agents/interfaces/mcplistresourcetemplatesresult/)> #### Implementation of [Section titled “Implementation of”](#implementation-of-10) [`MCPServerWithResources`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/).[`listResourceTemplates`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/#listresourcetemplates) #### Overrides [Section titled “Overrides”](#overrides-7) ```ts BaseMCPServerStdio.listResourceTemplates ``` *** ### listTools() [Section titled “listTools()”](#listtools) ```ts listTools(): Promise; ``` #### Returns [Section titled “Returns”](#returns-8) `Promise`<`object`\[]> #### Implementation of [Section titled “Implementation of”](#implementation-of-11) [`MCPServerWithResources`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/).[`listTools`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/#listtools) #### Overrides [Section titled “Overrides”](#overrides-8) ```ts BaseMCPServerStdio.listTools ``` *** ### readResource() [Section titled “readResource()”](#readresource) ```ts readResource(uri): Promise; ``` #### Parameters [Section titled “Parameters”](#parameters-4) | Parameter | Type | | --------- | -------- | | `uri` | `string` | #### Returns [Section titled “Returns”](#returns-9) `Promise`<[`MCPReadResourceResult`](/openai-agents-js/openai/agents/interfaces/mcpreadresourceresult/)> #### Implementation of [Section titled “Implementation of”](#implementation-of-12) [`MCPServerWithResources`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/).[`readResource`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/#readresource) #### Overrides [Section titled “Overrides”](#overrides-9) ```ts BaseMCPServerStdio.readResource ``` # MCPServerStreamableHttp Extended MCP server surface for servers that expose resources. ## Extends [Section titled “Extends”](#extends) * `BaseMCPServerStreamableHttp` ## Implements [Section titled “Implements”](#implements) * [`MCPServerWithResources`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/) ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new MCPServerStreamableHttp(options): MCPServerStreamableHttp; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | -------------------------------- | | `options` | `MCPServerStreamableHttpOptions` | #### Returns [Section titled “Returns”](#returns) `MCPServerStreamableHttp` #### Overrides [Section titled “Overrides”](#overrides) ```ts BaseMCPServerStreamableHttp.constructor ``` ## Properties [Section titled “Properties”](#properties) ### cacheToolsList [Section titled “cacheToolsList”](#cachetoolslist) ```ts cacheToolsList: boolean; ``` #### Implementation of [Section titled “Implementation of”](#implementation-of) [`MCPServerWithResources`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/).[`cacheToolsList`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/#cachetoolslist) #### Inherited from [Section titled “Inherited from”](#inherited-from) ```ts BaseMCPServerStreamableHttp.cacheToolsList ``` *** ### errorFunction? [Section titled “errorFunction?”](#errorfunction) ```ts optional errorFunction?: | MCPToolErrorFunction | null; ``` Optional function to convert MCP tool failures into model-visible messages. Set to null to rethrow errors instead of converting them. #### Implementation of [Section titled “Implementation of”](#implementation-of-1) [`MCPServerWithResources`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/).[`errorFunction`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/#errorfunction) #### Inherited from [Section titled “Inherited from”](#inherited-from-1) ```ts BaseMCPServerStreamableHttp.errorFunction ``` *** ### toolFilter? [Section titled “toolFilter?”](#toolfilter) ```ts optional toolFilter?: | MCPToolFilterCallable | MCPToolFilterStatic; ``` #### Implementation of [Section titled “Implementation of”](#implementation-of-2) [`MCPServerWithResources`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/).[`toolFilter`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/#toolfilter) #### Inherited from [Section titled “Inherited from”](#inherited-from-2) ```ts BaseMCPServerStreamableHttp.toolFilter ``` *** ### toolMetaResolver? [Section titled “toolMetaResolver?”](#toolmetaresolver) ```ts optional toolMetaResolver?: MCPToolMetaResolver; ``` #### Implementation of [Section titled “Implementation of”](#implementation-of-3) [`MCPServerWithResources`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/).[`toolMetaResolver`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/#toolmetaresolver) #### Inherited from [Section titled “Inherited from”](#inherited-from-3) ```ts BaseMCPServerStreamableHttp.toolMetaResolver ``` ## Accessors [Section titled “Accessors”](#accessors) ### name [Section titled “name”](#name) #### Get Signature [Section titled “Get Signature”](#get-signature) ```ts get name(): string; ``` ##### Returns [Section titled “Returns”](#returns-1) `string` #### Implementation of [Section titled “Implementation of”](#implementation-of-4) [`MCPServerWithResources`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/).[`name`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/#name) #### Overrides [Section titled “Overrides”](#overrides-1) ```ts BaseMCPServerStreamableHttp.name ``` *** ### sessionId [Section titled “sessionId”](#sessionid) #### Get Signature [Section titled “Get Signature”](#get-signature-1) ```ts get sessionId(): string | undefined; ``` ##### Returns [Section titled “Returns”](#returns-2) `string` | `undefined` #### Overrides [Section titled “Overrides”](#overrides-2) ```ts BaseMCPServerStreamableHttp.sessionId ``` ## Methods [Section titled “Methods”](#methods) ### callTool() [Section titled “callTool()”](#calltool) ```ts callTool( toolName, args, meta?): Promise; ``` #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | ---------- | --------------------------------------- | | `toolName` | `string` | | `args` | `Record`<`string`, `unknown`> \| `null` | | `meta?` | `Record`<`string`, `unknown`> \| `null` | #### Returns [Section titled “Returns”](#returns-3) `Promise`<`object`\[]> #### Implementation of [Section titled “Implementation of”](#implementation-of-5) [`MCPServerWithResources`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/).[`callTool`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/#calltool) #### Overrides [Section titled “Overrides”](#overrides-3) ```ts BaseMCPServerStreamableHttp.callTool ``` *** ### close() [Section titled “close()”](#close) ```ts close(): Promise; ``` #### Returns [Section titled “Returns”](#returns-4) `Promise`<`void`> #### Implementation of [Section titled “Implementation of”](#implementation-of-6) [`MCPServerWithResources`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/).[`close`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/#close) #### Overrides [Section titled “Overrides”](#overrides-4) ```ts BaseMCPServerStreamableHttp.close ``` *** ### connect() [Section titled “connect()”](#connect) ```ts connect(): Promise; ``` #### Returns [Section titled “Returns”](#returns-5) `Promise`<`void`> #### Implementation of [Section titled “Implementation of”](#implementation-of-7) [`MCPServerWithResources`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/).[`connect`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/#connect) #### Overrides [Section titled “Overrides”](#overrides-5) ```ts BaseMCPServerStreamableHttp.connect ``` *** ### invalidateToolsCache() [Section titled “invalidateToolsCache()”](#invalidatetoolscache) ```ts invalidateToolsCache(): Promise; ``` #### Returns [Section titled “Returns”](#returns-6) `Promise`<`void`> #### Implementation of [Section titled “Implementation of”](#implementation-of-8) [`MCPServerWithResources`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/).[`invalidateToolsCache`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/#invalidatetoolscache) #### Overrides [Section titled “Overrides”](#overrides-6) ```ts BaseMCPServerStreamableHttp.invalidateToolsCache ``` *** ### listResources() [Section titled “listResources()”](#listresources) ```ts listResources(params?): Promise; ``` #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | --------- | ---------------------------------------------------------------------------------------------- | | `params?` | [`MCPListResourcesParams`](/openai-agents-js/openai/agents/interfaces/mcplistresourcesparams/) | #### Returns [Section titled “Returns”](#returns-7) `Promise`<[`MCPListResourcesResult`](/openai-agents-js/openai/agents/interfaces/mcplistresourcesresult/)> #### Implementation of [Section titled “Implementation of”](#implementation-of-9) [`MCPServerWithResources`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/).[`listResources`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/#listresources) #### Overrides [Section titled “Overrides”](#overrides-7) ```ts BaseMCPServerStreamableHttp.listResources ``` *** ### listResourceTemplates() [Section titled “listResourceTemplates()”](#listresourcetemplates) ```ts listResourceTemplates(params?): Promise; ``` #### Parameters [Section titled “Parameters”](#parameters-3) | Parameter | Type | | --------- | ---------------------------------------------------------------------------------------------- | | `params?` | [`MCPListResourcesParams`](/openai-agents-js/openai/agents/interfaces/mcplistresourcesparams/) | #### Returns [Section titled “Returns”](#returns-8) `Promise`<[`MCPListResourceTemplatesResult`](/openai-agents-js/openai/agents/interfaces/mcplistresourcetemplatesresult/)> #### Implementation of [Section titled “Implementation of”](#implementation-of-10) [`MCPServerWithResources`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/).[`listResourceTemplates`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/#listresourcetemplates) #### Overrides [Section titled “Overrides”](#overrides-8) ```ts BaseMCPServerStreamableHttp.listResourceTemplates ``` *** ### listTools() [Section titled “listTools()”](#listtools) ```ts listTools(): Promise; ``` #### Returns [Section titled “Returns”](#returns-9) `Promise`<`object`\[]> #### Implementation of [Section titled “Implementation of”](#implementation-of-11) [`MCPServerWithResources`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/).[`listTools`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/#listtools) #### Overrides [Section titled “Overrides”](#overrides-9) ```ts BaseMCPServerStreamableHttp.listTools ``` *** ### readResource() [Section titled “readResource()”](#readresource) ```ts readResource(uri): Promise; ``` #### Parameters [Section titled “Parameters”](#parameters-4) | Parameter | Type | | --------- | -------- | | `uri` | `string` | #### Returns [Section titled “Returns”](#returns-10) `Promise`<[`MCPReadResourceResult`](/openai-agents-js/openai/agents/interfaces/mcpreadresourceresult/)> #### Implementation of [Section titled “Implementation of”](#implementation-of-12) [`MCPServerWithResources`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/).[`readResource`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/#readresource) #### Overrides [Section titled “Overrides”](#overrides-10) ```ts BaseMCPServerStreamableHttp.readResource ``` # MemorySession Simple in-memory session store intended for demos or tests. Not recommended for production use. ## Implements [Section titled “Implements”](#implements) * [`SessionHistoryRewriteAwareSession`](/openai-agents-js/openai/agents/interfaces/sessionhistoryrewriteawaresession/) ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new MemorySession(options?): MemorySession; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ---------- | ---------------------- | | `options?` | `MemorySessionOptions` | #### Returns [Section titled “Returns”](#returns) `MemorySession` ## Methods [Section titled “Methods”](#methods) ### addItems() [Section titled “addItems()”](#additems) ```ts addItems(items): Promise; ``` Append new items to the conversation history. #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | Description | | --------- | ----------------------------------------------------------------------------------- | ------------------------------------ | | `items` | [`AgentInputItem`](/openai-agents-js/openai/agents/type-aliases/agentinputitem/)\[] | Items to add to the session history. | #### Returns [Section titled “Returns”](#returns-1) `Promise`<`void`> #### Implementation of [Section titled “Implementation of”](#implementation-of) [`SessionHistoryRewriteAwareSession`](/openai-agents-js/openai/agents/interfaces/sessionhistoryrewriteawaresession/).[`addItems`](/openai-agents-js/openai/agents/interfaces/sessionhistoryrewriteawaresession/#additems) *** ### applyHistoryMutations() [Section titled “applyHistoryMutations()”](#applyhistorymutations) ```ts applyHistoryMutations(args): Promise; ``` #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | --------- | ------------------------------------------------------------------------------------------------------ | | `args` | [`SessionHistoryRewriteArgs`](/openai-agents-js/openai/agents/type-aliases/sessionhistoryrewriteargs/) | #### Returns [Section titled “Returns”](#returns-2) `Promise`<`void`> #### Implementation of [Section titled “Implementation of”](#implementation-of-1) [`SessionHistoryRewriteAwareSession`](/openai-agents-js/openai/agents/interfaces/sessionhistoryrewriteawaresession/).[`applyHistoryMutations`](/openai-agents-js/openai/agents/interfaces/sessionhistoryrewriteawaresession/#applyhistorymutations) *** ### clearSession() [Section titled “clearSession()”](#clearsession) ```ts clearSession(): Promise; ``` Remove all items that belong to the session and reset its state. #### Returns [Section titled “Returns”](#returns-3) `Promise`<`void`> #### Implementation of [Section titled “Implementation of”](#implementation-of-2) [`SessionHistoryRewriteAwareSession`](/openai-agents-js/openai/agents/interfaces/sessionhistoryrewriteawaresession/).[`clearSession`](/openai-agents-js/openai/agents/interfaces/sessionhistoryrewriteawaresession/#clearsession) *** ### getItems() [Section titled “getItems()”](#getitems) ```ts getItems(limit?): Promise; ``` Retrieve items from the conversation history. #### Parameters [Section titled “Parameters”](#parameters-3) | Parameter | Type | Description | | --------- | -------- | --------------------------------------------------------------------------------------------------------------------------- | | `limit?` | `number` | The maximum number of items to return. When provided the most recent limit items should be returned in chronological order. | #### Returns [Section titled “Returns”](#returns-4) `Promise`<[`AgentInputItem`](/openai-agents-js/openai/agents/type-aliases/agentinputitem/)\[]> #### Implementation of [Section titled “Implementation of”](#implementation-of-3) [`SessionHistoryRewriteAwareSession`](/openai-agents-js/openai/agents/interfaces/sessionhistoryrewriteawaresession/).[`getItems`](/openai-agents-js/openai/agents/interfaces/sessionhistoryrewriteawaresession/#getitems) *** ### getSessionId() [Section titled “getSessionId()”](#getsessionid) ```ts getSessionId(): Promise; ``` Ensure and return the identifier for this session. #### Returns [Section titled “Returns”](#returns-5) `Promise`<`string`> #### Implementation of [Section titled “Implementation of”](#implementation-of-4) [`SessionHistoryRewriteAwareSession`](/openai-agents-js/openai/agents/interfaces/sessionhistoryrewriteawaresession/).[`getSessionId`](/openai-agents-js/openai/agents/interfaces/sessionhistoryrewriteawaresession/#getsessionid) *** ### popItem() [Section titled “popItem()”](#popitem) ```ts popItem(): Promise< | AgentInputItem | undefined>; ``` Remove and return the most recent item from the conversation history if it exists. #### Returns [Section titled “Returns”](#returns-6) `Promise`< | [`AgentInputItem`](/openai-agents-js/openai/agents/type-aliases/agentinputitem/) | `undefined`> #### Implementation of [Section titled “Implementation of”](#implementation-of-5) [`SessionHistoryRewriteAwareSession`](/openai-agents-js/openai/agents/interfaces/sessionhistoryrewriteawaresession/).[`popItem`](/openai-agents-js/openai/agents/interfaces/sessionhistoryrewriteawaresession/#popitem) # ModelBehaviorError Error thrown when a model behavior is unexpected. ## Extends [Section titled “Extends”](#extends) * [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/) ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new ModelBehaviorError(message, state?): ModelBehaviorError; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | | `message` | `string` | | `state?` | [`RunState`](/openai-agents-js/openai/agents/classes/runstate/)<`any`, [`Agent`](/openai-agents-js/openai/agents/classes/agent/)<`any`, `any`>> | #### Returns [Section titled “Returns”](#returns) `ModelBehaviorError` #### Inherited from [Section titled “Inherited from”](#inherited-from) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`constructor`](/openai-agents-js/openai/agents/classes/agentserror/#constructor) ## Properties [Section titled “Properties”](#properties) ### message [Section titled “message”](#message) ```ts message: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-1) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`message`](/openai-agents-js/openai/agents/classes/agentserror/#message) *** ### name [Section titled “name”](#name) ```ts name: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-2) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`name`](/openai-agents-js/openai/agents/classes/agentserror/#name) *** ### stack? [Section titled “stack?”](#stack) ```ts optional stack?: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-3) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`stack`](/openai-agents-js/openai/agents/classes/agentserror/#stack) *** ### state? [Section titled “state?”](#state) ```ts optional state?: RunState>; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-4) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`state`](/openai-agents-js/openai/agents/classes/agentserror/#state) *** ### stackTraceLimit [Section titled “stackTraceLimit”](#stacktracelimit) ```ts static stackTraceLimit: number; ``` The `Error.stackTraceLimit` property specifies the number of stack frames collected by a stack trace (whether generated by `new Error().stack` or `Error.captureStackTrace(obj)`). The default value is `10` but may be set to any valid JavaScript number. Changes will affect any stack trace captured *after* the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames. #### Inherited from [Section titled “Inherited from”](#inherited-from-5) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`stackTraceLimit`](/openai-agents-js/openai/agents/classes/agentserror/#stacktracelimit) ## Methods [Section titled “Methods”](#methods) ### captureStackTrace() [Section titled “captureStackTrace()”](#capturestacktrace) ```ts static captureStackTrace(targetObject, constructorOpt?): void; ``` Creates a `.stack` property on `targetObject`, which when accessed returns a string representing the location in the code at which `Error.captureStackTrace()` was called. ```js const myObject = {}; Error.captureStackTrace(myObject); myObject.stack; // Similar to `new Error().stack` ``` The first line of the trace will be prefixed with `${myObject.name}: ${myObject.message}`. The optional `constructorOpt` argument accepts a function. If given, all frames above `constructorOpt`, including `constructorOpt`, will be omitted from the generated stack trace. The `constructorOpt` argument is useful for hiding implementation details of error generation from the user. For instance: ```js function a() { b(); } function b() { c(); } function c() { // Create an error without stack trace to avoid calculating the stack trace twice. const { stackTraceLimit } = Error; Error.stackTraceLimit = 0; const error = new Error(); Error.stackTraceLimit = stackTraceLimit; // Capture the stack trace above function b Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace throw error; } a(); ``` #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | ----------------- | ---------- | | `targetObject` | `object` | | `constructorOpt?` | `Function` | #### Returns [Section titled “Returns”](#returns-1) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-6) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`captureStackTrace`](/openai-agents-js/openai/agents/classes/agentserror/#capturestacktrace) *** ### prepareStackTrace() [Section titled “prepareStackTrace()”](#preparestacktrace) ```ts static prepareStackTrace(err, stackTraces): any; ``` #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | ------------- | ------------- | | `err` | `Error` | | `stackTraces` | `CallSite`\[] | #### Returns [Section titled “Returns”](#returns-2) `any` #### See [Section titled “See”](#see) #### Inherited from [Section titled “Inherited from”](#inherited-from-7) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`prepareStackTrace`](/openai-agents-js/openai/agents/classes/agentserror/#preparestacktrace) # ModelRefusalError Error thrown when the model refuses to produce output. ## Extends [Section titled “Extends”](#extends) * [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/) ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new ModelRefusalError(refusal, state?): ModelRefusalError; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | | `refusal` | `string` | | `state?` | [`RunState`](/openai-agents-js/openai/agents/classes/runstate/)<`any`, [`Agent`](/openai-agents-js/openai/agents/classes/agent/)<`any`, `any`>> | #### Returns [Section titled “Returns”](#returns) `ModelRefusalError` #### Overrides [Section titled “Overrides”](#overrides) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`constructor`](/openai-agents-js/openai/agents/classes/agentserror/#constructor) ## Properties [Section titled “Properties”](#properties) ### message [Section titled “message”](#message) ```ts message: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`message`](/openai-agents-js/openai/agents/classes/agentserror/#message) *** ### name [Section titled “name”](#name) ```ts name: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-1) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`name`](/openai-agents-js/openai/agents/classes/agentserror/#name) *** ### refusal [Section titled “refusal”](#refusal) ```ts refusal: string; ``` The refusal text returned by the model. *** ### stack? [Section titled “stack?”](#stack) ```ts optional stack?: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-2) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`stack`](/openai-agents-js/openai/agents/classes/agentserror/#stack) *** ### state? [Section titled “state?”](#state) ```ts optional state?: RunState>; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-3) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`state`](/openai-agents-js/openai/agents/classes/agentserror/#state) *** ### stackTraceLimit [Section titled “stackTraceLimit”](#stacktracelimit) ```ts static stackTraceLimit: number; ``` The `Error.stackTraceLimit` property specifies the number of stack frames collected by a stack trace (whether generated by `new Error().stack` or `Error.captureStackTrace(obj)`). The default value is `10` but may be set to any valid JavaScript number. Changes will affect any stack trace captured *after* the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames. #### Inherited from [Section titled “Inherited from”](#inherited-from-4) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`stackTraceLimit`](/openai-agents-js/openai/agents/classes/agentserror/#stacktracelimit) ## Methods [Section titled “Methods”](#methods) ### captureStackTrace() [Section titled “captureStackTrace()”](#capturestacktrace) ```ts static captureStackTrace(targetObject, constructorOpt?): void; ``` Creates a `.stack` property on `targetObject`, which when accessed returns a string representing the location in the code at which `Error.captureStackTrace()` was called. ```js const myObject = {}; Error.captureStackTrace(myObject); myObject.stack; // Similar to `new Error().stack` ``` The first line of the trace will be prefixed with `${myObject.name}: ${myObject.message}`. The optional `constructorOpt` argument accepts a function. If given, all frames above `constructorOpt`, including `constructorOpt`, will be omitted from the generated stack trace. The `constructorOpt` argument is useful for hiding implementation details of error generation from the user. For instance: ```js function a() { b(); } function b() { c(); } function c() { // Create an error without stack trace to avoid calculating the stack trace twice. const { stackTraceLimit } = Error; Error.stackTraceLimit = 0; const error = new Error(); Error.stackTraceLimit = stackTraceLimit; // Capture the stack trace above function b Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace throw error; } a(); ``` #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | ----------------- | ---------- | | `targetObject` | `object` | | `constructorOpt?` | `Function` | #### Returns [Section titled “Returns”](#returns-1) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-5) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`captureStackTrace`](/openai-agents-js/openai/agents/classes/agentserror/#capturestacktrace) *** ### prepareStackTrace() [Section titled “prepareStackTrace()”](#preparestacktrace) ```ts static prepareStackTrace(err, stackTraces): any; ``` #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | ------------- | ------------- | | `err` | `Error` | | `stackTraces` | `CallSite`\[] | #### Returns [Section titled “Returns”](#returns-2) `any` #### See [Section titled “See”](#see) #### Inherited from [Section titled “Inherited from”](#inherited-from-6) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`prepareStackTrace`](/openai-agents-js/openai/agents/classes/agentserror/#preparestacktrace) # NoopSpan ## Extends [Section titled “Extends”](#extends) * [`Span`](/openai-agents-js/openai/agents/classes/span/)<`TSpanData`> ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | ------------------------------------------------------------------------------------------ | | `TSpanData` *extends* [`SpanData`](/openai-agents-js/openai/agents/type-aliases/spandata/) | ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new NoopSpan(data, processor): NoopSpan; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ----------- | ---------------------------------------------------------------------------------- | | `data` | `TSpanData` | | `processor` | [`TracingProcessor`](/openai-agents-js/openai/agents/interfaces/tracingprocessor/) | #### Returns [Section titled “Returns”](#returns) `NoopSpan`<`TSpanData`> #### Overrides [Section titled “Overrides”](#overrides) [`Span`](/openai-agents-js/openai/agents/classes/span/).[`constructor`](/openai-agents-js/openai/agents/classes/span/#constructor) ## Properties [Section titled “Properties”](#properties) ### type [Section titled “type”](#type) ```ts type: "trace.span"; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from) [`Span`](/openai-agents-js/openai/agents/classes/span/).[`type`](/openai-agents-js/openai/agents/classes/span/#type) ## Accessors [Section titled “Accessors”](#accessors) ### endedAt [Section titled “endedAt”](#endedat) #### Get Signature [Section titled “Get Signature”](#get-signature) ```ts get endedAt(): string | null; ``` ##### Returns [Section titled “Returns”](#returns-1) `string` | `null` #### Inherited from [Section titled “Inherited from”](#inherited-from-1) [`Span`](/openai-agents-js/openai/agents/classes/span/).[`endedAt`](/openai-agents-js/openai/agents/classes/span/#endedat) *** ### error [Section titled “error”](#error) #### Get Signature [Section titled “Get Signature”](#get-signature-1) ```ts get error(): | SpanError | null; ``` ##### Returns [Section titled “Returns”](#returns-2) \| [`SpanError`](/openai-agents-js/openai/agents/type-aliases/spanerror/) | `null` #### Inherited from [Section titled “Inherited from”](#inherited-from-2) [`Span`](/openai-agents-js/openai/agents/classes/span/).[`error`](/openai-agents-js/openai/agents/classes/span/#error) *** ### parentId [Section titled “parentId”](#parentid) #### Get Signature [Section titled “Get Signature”](#get-signature-2) ```ts get parentId(): string | null; ``` ##### Returns [Section titled “Returns”](#returns-3) `string` | `null` #### Inherited from [Section titled “Inherited from”](#inherited-from-3) [`Span`](/openai-agents-js/openai/agents/classes/span/).[`parentId`](/openai-agents-js/openai/agents/classes/span/#parentid) *** ### previousSpan [Section titled “previousSpan”](#previousspan) #### Get Signature [Section titled “Get Signature”](#get-signature-3) ```ts get previousSpan(): | Span | undefined; ``` ##### Returns [Section titled “Returns”](#returns-4) \| [`Span`](/openai-agents-js/openai/agents/classes/span/)<`any`> | `undefined` #### Set Signature [Section titled “Set Signature”](#set-signature) ```ts set previousSpan(span): void; ``` ##### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | --------- | -------------------------------------------------------------------------------- | | `span` | \| [`Span`](/openai-agents-js/openai/agents/classes/span/)<`any`> \| `undefined` | ##### Returns [Section titled “Returns”](#returns-5) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-4) [`Span`](/openai-agents-js/openai/agents/classes/span/).[`previousSpan`](/openai-agents-js/openai/agents/classes/span/#previousspan) *** ### spanData [Section titled “spanData”](#spandata) #### Get Signature [Section titled “Get Signature”](#get-signature-4) ```ts get spanData(): TData; ``` ##### Returns [Section titled “Returns”](#returns-6) `TData` #### Inherited from [Section titled “Inherited from”](#inherited-from-5) [`Span`](/openai-agents-js/openai/agents/classes/span/).[`spanData`](/openai-agents-js/openai/agents/classes/span/#spandata) *** ### spanId [Section titled “spanId”](#spanid) #### Get Signature [Section titled “Get Signature”](#get-signature-5) ```ts get spanId(): string; ``` ##### Returns [Section titled “Returns”](#returns-7) `string` #### Inherited from [Section titled “Inherited from”](#inherited-from-6) [`Span`](/openai-agents-js/openai/agents/classes/span/).[`spanId`](/openai-agents-js/openai/agents/classes/span/#spanid) *** ### startedAt [Section titled “startedAt”](#startedat) #### Get Signature [Section titled “Get Signature”](#get-signature-6) ```ts get startedAt(): string | null; ``` ##### Returns [Section titled “Returns”](#returns-8) `string` | `null` #### Inherited from [Section titled “Inherited from”](#inherited-from-7) [`Span`](/openai-agents-js/openai/agents/classes/span/).[`startedAt`](/openai-agents-js/openai/agents/classes/span/#startedat) *** ### traceId [Section titled “traceId”](#traceid) #### Get Signature [Section titled “Get Signature”](#get-signature-7) ```ts get traceId(): string; ``` ##### Returns [Section titled “Returns”](#returns-9) `string` #### Inherited from [Section titled “Inherited from”](#inherited-from-8) [`Span`](/openai-agents-js/openai/agents/classes/span/).[`traceId`](/openai-agents-js/openai/agents/classes/span/#traceid) *** ### traceMetadata [Section titled “traceMetadata”](#tracemetadata) #### Get Signature [Section titled “Get Signature”](#get-signature-8) ```ts get traceMetadata(): Record | undefined; ``` ##### Returns [Section titled “Returns”](#returns-10) `Record`<`string`, `any`> | `undefined` #### Inherited from [Section titled “Inherited from”](#inherited-from-9) [`Span`](/openai-agents-js/openai/agents/classes/span/).[`traceMetadata`](/openai-agents-js/openai/agents/classes/span/#tracemetadata) *** ### tracingApiKey [Section titled “tracingApiKey”](#tracingapikey) #### Get Signature [Section titled “Get Signature”](#get-signature-9) ```ts get tracingApiKey(): string | undefined; ``` ##### Returns [Section titled “Returns”](#returns-11) `string` | `undefined` #### Inherited from [Section titled “Inherited from”](#inherited-from-10) [`Span`](/openai-agents-js/openai/agents/classes/span/).[`tracingApiKey`](/openai-agents-js/openai/agents/classes/span/#tracingapikey) ## Methods [Section titled “Methods”](#methods) ### clone() [Section titled “clone()”](#clone) ```ts clone(): Span; ``` #### Returns [Section titled “Returns”](#returns-12) [`Span`](/openai-agents-js/openai/agents/classes/span/)<`TSpanData`> #### Inherited from [Section titled “Inherited from”](#inherited-from-11) [`Span`](/openai-agents-js/openai/agents/classes/span/).[`clone`](/openai-agents-js/openai/agents/classes/span/#clone) *** ### end() [Section titled “end()”](#end) ```ts end(): void; ``` #### Returns [Section titled “Returns”](#returns-13) `void` #### Overrides [Section titled “Overrides”](#overrides-1) [`Span`](/openai-agents-js/openai/agents/classes/span/).[`end`](/openai-agents-js/openai/agents/classes/span/#end) *** ### setError() [Section titled “setError()”](#seterror) ```ts setError(): void; ``` #### Returns [Section titled “Returns”](#returns-14) `void` #### Overrides [Section titled “Overrides”](#overrides-2) [`Span`](/openai-agents-js/openai/agents/classes/span/).[`setError`](/openai-agents-js/openai/agents/classes/span/#seterror) *** ### start() [Section titled “start()”](#start) ```ts start(): void; ``` #### Returns [Section titled “Returns”](#returns-15) `void` #### Overrides [Section titled “Overrides”](#overrides-3) [`Span`](/openai-agents-js/openai/agents/classes/span/).[`start`](/openai-agents-js/openai/agents/classes/span/#start) *** ### toJSON() [Section titled “toJSON()”](#tojson) ```ts toJSON(): null; ``` #### Returns [Section titled “Returns”](#returns-16) `null` #### Overrides [Section titled “Overrides”](#overrides-4) [`Span`](/openai-agents-js/openai/agents/classes/span/).[`toJSON`](/openai-agents-js/openai/agents/classes/span/#tojson) # NoopTrace ## Extends [Section titled “Extends”](#extends) * [`Trace`](/openai-agents-js/openai/agents/classes/trace/) ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new NoopTrace(): NoopTrace; ``` #### Returns [Section titled “Returns”](#returns) `NoopTrace` #### Overrides [Section titled “Overrides”](#overrides) [`Trace`](/openai-agents-js/openai/agents/classes/trace/).[`constructor`](/openai-agents-js/openai/agents/classes/trace/#constructor) ## Properties [Section titled “Properties”](#properties) ### groupId [Section titled “groupId”](#groupid) ```ts groupId: string | null; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from) [`Trace`](/openai-agents-js/openai/agents/classes/trace/).[`groupId`](/openai-agents-js/openai/agents/classes/trace/#groupid) *** ### metadata? [Section titled “metadata?”](#metadata) ```ts optional metadata?: Record; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-1) [`Trace`](/openai-agents-js/openai/agents/classes/trace/).[`metadata`](/openai-agents-js/openai/agents/classes/trace/#metadata) *** ### name [Section titled “name”](#name) ```ts name: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-2) [`Trace`](/openai-agents-js/openai/agents/classes/trace/).[`name`](/openai-agents-js/openai/agents/classes/trace/#name) *** ### traceId [Section titled “traceId”](#traceid) ```ts traceId: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-3) [`Trace`](/openai-agents-js/openai/agents/classes/trace/).[`traceId`](/openai-agents-js/openai/agents/classes/trace/#traceid) *** ### tracingApiKey? [Section titled “tracingApiKey?”](#tracingapikey) ```ts optional tracingApiKey?: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-4) [`Trace`](/openai-agents-js/openai/agents/classes/trace/).[`tracingApiKey`](/openai-agents-js/openai/agents/classes/trace/#tracingapikey) *** ### type [Section titled “type”](#type) ```ts type: "trace"; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-5) [`Trace`](/openai-agents-js/openai/agents/classes/trace/).[`type`](/openai-agents-js/openai/agents/classes/trace/#type) ## Methods [Section titled “Methods”](#methods) ### clone() [Section titled “clone()”](#clone) ```ts clone(): Trace; ``` #### Returns [Section titled “Returns”](#returns-1) [`Trace`](/openai-agents-js/openai/agents/classes/trace/) #### Inherited from [Section titled “Inherited from”](#inherited-from-6) [`Trace`](/openai-agents-js/openai/agents/classes/trace/).[`clone`](/openai-agents-js/openai/agents/classes/trace/#clone) *** ### end() [Section titled “end()”](#end) ```ts end(): Promise; ``` #### Returns [Section titled “Returns”](#returns-2) `Promise`<`void`> #### Overrides [Section titled “Overrides”](#overrides-1) [`Trace`](/openai-agents-js/openai/agents/classes/trace/).[`end`](/openai-agents-js/openai/agents/classes/trace/#end) *** ### start() [Section titled “start()”](#start) ```ts start(): Promise; ``` #### Returns [Section titled “Returns”](#returns-3) `Promise`<`void`> #### Overrides [Section titled “Overrides”](#overrides-2) [`Trace`](/openai-agents-js/openai/agents/classes/trace/).[`start`](/openai-agents-js/openai/agents/classes/trace/#start) *** ### toJSON() [Section titled “toJSON()”](#tojson) ```ts toJSON(): object | null; ``` Serializes the trace for export or persistence. Set `includeTracingApiKey` to true only when you intentionally need to persist the exporter credentials (for example, when handing off a run to another process that cannot access the original environment). Defaults to false to avoid leaking secrets. #### Returns [Section titled “Returns”](#returns-4) `object` | `null` #### Overrides [Section titled “Overrides”](#overrides-3) [`Trace`](/openai-agents-js/openai/agents/classes/trace/).[`toJSON`](/openai-agents-js/openai/agents/classes/trace/#tojson) # OpenAIChatCompletionsModel The base interface for calling an LLM. ## Implements [Section titled “Implements”](#implements) * [`Model`](/openai-agents-js/openai/agents/interfaces/model/) ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new OpenAIChatCompletionsModel( client, model, options?): OpenAIChatCompletionsModel; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ---------- | ---------------------------------------------------------------------------------------------------------------------- | | `client` | `OpenAI` | | `model` | `string` | | `options?` | [`OpenAIChatCompletionsModelOptions`](/openai-agents-js/openai/agents/type-aliases/openaichatcompletionsmodeloptions/) | #### Returns [Section titled “Returns”](#returns) `OpenAIChatCompletionsModel` ## Methods [Section titled “Methods”](#methods) ### getResponse() [Section titled “getResponse()”](#getresponse) ```ts getResponse(request): Promise; ``` Get a response from the model. #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | Description | | --------- | ---------------------------------------------------------------------------- | ---------------------------------- | | `request` | [`ModelRequest`](/openai-agents-js/openai/agents/type-aliases/modelrequest/) | The request to get a response for. | #### Returns [Section titled “Returns”](#returns-1) `Promise`<[`ModelResponse`](/openai-agents-js/openai/agents/type-aliases/modelresponse/)> #### Implementation of [Section titled “Implementation of”](#implementation-of) [`Model`](/openai-agents-js/openai/agents/interfaces/model/).[`getResponse`](/openai-agents-js/openai/agents/interfaces/model/#getresponse) *** ### getRetryAdvice() [Section titled “getRetryAdvice()”](#getretryadvice) ```ts getRetryAdvice(args): | ModelRetryAdvice | undefined; ``` Provide optional retry advice for a failed request. #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | --------- | -------------------------------------------------------------------------------------------------- | | `args` | [`ModelRetryAdviceRequest`](/openai-agents-js/openai/agents/type-aliases/modelretryadvicerequest/) | #### Returns [Section titled “Returns”](#returns-2) \| [`ModelRetryAdvice`](/openai-agents-js/openai/agents/type-aliases/modelretryadvice/) | `undefined` #### Implementation of [Section titled “Implementation of”](#implementation-of-1) [`Model`](/openai-agents-js/openai/agents/interfaces/model/).[`getRetryAdvice`](/openai-agents-js/openai/agents/interfaces/model/#getretryadvice) *** ### getStreamedResponse() [Section titled “getStreamedResponse()”](#getstreamedresponse) ```ts getStreamedResponse(request): AsyncIterable; ``` Get a streamed response from the model. #### Parameters [Section titled “Parameters”](#parameters-3) | Parameter | Type | | --------- | ---------------------------------------------------------------------------- | | `request` | [`ModelRequest`](/openai-agents-js/openai/agents/type-aliases/modelrequest/) | #### Returns [Section titled “Returns”](#returns-3) `AsyncIterable`<[`StreamEvent`](/openai-agents-js/openai/agents/type-aliases/streamevent/)> #### Implementation of [Section titled “Implementation of”](#implementation-of-2) [`Model`](/openai-agents-js/openai/agents/interfaces/model/).[`getStreamedResponse`](/openai-agents-js/openai/agents/interfaces/model/#getstreamedresponse) # OpenAIConversationsSession Interface representing a persistent session store for conversation history. ## Implements [Section titled “Implements”](#implements) * [`Session`](/openai-agents-js/openai/agents/interfaces/session/) * `OpenAISessionApiTagged`<`"conversations"`> ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new OpenAIConversationsSession(options?): OpenAIConversationsSession; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ---------- | ---------------------------------------------------------------------------------------------------------------------- | | `options?` | [`OpenAIConversationsSessionOptions`](/openai-agents-js/openai/agents/type-aliases/openaiconversationssessionoptions/) | #### Returns [Section titled “Returns”](#returns) `OpenAIConversationsSession` ## Properties [Section titled “Properties”](#properties) ### \[OPENAI\_SESSION\_API] [Section titled “\[OPENAI\_SESSION\_API\]”](#openai_session_api) ```ts readonly [OPENAI_SESSION_API]: "conversations"; ``` #### Implementation of [Section titled “Implementation of”](#implementation-of) ```ts OpenAISessionApiTagged.[OPENAI_SESSION_API] ``` ## Accessors [Section titled “Accessors”](#accessors) ### sessionId [Section titled “sessionId”](#sessionid) #### Get Signature [Section titled “Get Signature”](#get-signature) ```ts get sessionId(): string | undefined; ``` ##### Returns [Section titled “Returns”](#returns-1) `string` | `undefined` ## Methods [Section titled “Methods”](#methods) ### addItems() [Section titled “addItems()”](#additems) ```ts addItems(items): Promise; ``` Append new items to the conversation history. #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | Description | | --------- | ----------------------------------------------------------------------------------- | ------------------------------------ | | `items` | [`AgentInputItem`](/openai-agents-js/openai/agents/type-aliases/agentinputitem/)\[] | Items to add to the session history. | #### Returns [Section titled “Returns”](#returns-2) `Promise`<`void`> #### Implementation of [Section titled “Implementation of”](#implementation-of-1) [`Session`](/openai-agents-js/openai/agents/interfaces/session/).[`addItems`](/openai-agents-js/openai/agents/interfaces/session/#additems) *** ### clearSession() [Section titled “clearSession()”](#clearsession) ```ts clearSession(): Promise; ``` Remove all items that belong to the session and reset its state. #### Returns [Section titled “Returns”](#returns-3) `Promise`<`void`> #### Implementation of [Section titled “Implementation of”](#implementation-of-2) [`Session`](/openai-agents-js/openai/agents/interfaces/session/).[`clearSession`](/openai-agents-js/openai/agents/interfaces/session/#clearsession) *** ### getItems() [Section titled “getItems()”](#getitems) ```ts getItems(limit?): Promise; ``` Retrieve items from the conversation history. #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | Description | | --------- | -------- | --------------------------------------------------------------------------------------------------------------------------- | | `limit?` | `number` | The maximum number of items to return. When provided the most recent limit items should be returned in chronological order. | #### Returns [Section titled “Returns”](#returns-4) `Promise`<[`AgentInputItem`](/openai-agents-js/openai/agents/type-aliases/agentinputitem/)\[]> #### Implementation of [Section titled “Implementation of”](#implementation-of-3) [`Session`](/openai-agents-js/openai/agents/interfaces/session/).[`getItems`](/openai-agents-js/openai/agents/interfaces/session/#getitems) *** ### getSessionId() [Section titled “getSessionId()”](#getsessionid) ```ts getSessionId(): Promise; ``` Ensure and return the identifier for this session. #### Returns [Section titled “Returns”](#returns-5) `Promise`<`string`> #### Implementation of [Section titled “Implementation of”](#implementation-of-4) [`Session`](/openai-agents-js/openai/agents/interfaces/session/).[`getSessionId`](/openai-agents-js/openai/agents/interfaces/session/#getsessionid) *** ### popItem() [Section titled “popItem()”](#popitem) ```ts popItem(): Promise< | AgentInputItem | undefined>; ``` Remove and return the most recent item from the conversation history if it exists. #### Returns [Section titled “Returns”](#returns-6) `Promise`< | [`AgentInputItem`](/openai-agents-js/openai/agents/type-aliases/agentinputitem/) | `undefined`> #### Implementation of [Section titled “Implementation of”](#implementation-of-5) [`Session`](/openai-agents-js/openai/agents/interfaces/session/).[`popItem`](/openai-agents-js/openai/agents/interfaces/session/#popitem) *** ### prepareHistoryItemForModelInput() [Section titled “prepareHistoryItemForModelInput()”](#preparehistoryitemformodelinput) ```ts prepareHistoryItemForModelInput(item): AgentInputItem; ``` Optionally rewrite a stored history item before it is sent back to the model. Session implementations can use this to strip provider-managed replay metadata while preserving their public `getItems()` shape for UI and deletion workflows. #### Parameters [Section titled “Parameters”](#parameters-3) | Parameter | Type | | --------- | -------------------------------------------------------------------------------- | | `item` | [`AgentInputItem`](/openai-agents-js/openai/agents/type-aliases/agentinputitem/) | #### Returns [Section titled “Returns”](#returns-7) [`AgentInputItem`](/openai-agents-js/openai/agents/type-aliases/agentinputitem/) #### Implementation of [Section titled “Implementation of”](#implementation-of-6) [`Session`](/openai-agents-js/openai/agents/interfaces/session/).[`prepareHistoryItemForModelInput`](/openai-agents-js/openai/agents/interfaces/session/#preparehistoryitemformodelinput) *** ### preserveReasoningItemIdsForPersistence() [Section titled “preserveReasoningItemIdsForPersistence()”](#preservereasoningitemidsforpersistence) ```ts preserveReasoningItemIdsForPersistence(): boolean; ``` Optionally preserve reasoning item IDs when persisting generated output. Some remote session stores require provider-assigned reasoning identities to accept stored reasoning items, even when model replay should omit those IDs. #### Returns [Section titled “Returns”](#returns-8) `boolean` #### Implementation of [Section titled “Implementation of”](#implementation-of-7) [`Session`](/openai-agents-js/openai/agents/interfaces/session/).[`preserveReasoningItemIdsForPersistence`](/openai-agents-js/openai/agents/interfaces/session/#preservereasoningitemidsforpersistence) # OpenAIProvider The provider of OpenAI’s models (or Chat Completions compatible ones) ## Implements [Section titled “Implements”](#implements) * [`ModelProvider`](/openai-agents-js/openai/agents/interfaces/modelprovider/) ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new OpenAIProvider(options?): OpenAIProvider; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ---------- | ---------------------------------------------------------------------------------------------- | | `options?` | [`OpenAIProviderOptions`](/openai-agents-js/openai/agents/type-aliases/openaiprovideroptions/) | #### Returns [Section titled “Returns”](#returns) `OpenAIProvider` ## Methods [Section titled “Methods”](#methods) ### close() [Section titled “close()”](#close) ```ts close(): Promise; ``` Closes cached model wrappers (for example websocket-backed responses models) and clears cache. #### Returns [Section titled “Returns”](#returns-1) `Promise`<`void`> *** ### getModel() [Section titled “getModel()”](#getmodel) ```ts getModel(modelName?): Promise; ``` Get a model by name #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | Description | | ------------ | -------- | ----------------------------- | | `modelName?` | `string` | The name of the model to get. | #### Returns [Section titled “Returns”](#returns-2) `Promise`<[`Model`](/openai-agents-js/openai/agents/interfaces/model/)> #### Implementation of [Section titled “Implementation of”](#implementation-of) [`ModelProvider`](/openai-agents-js/openai/agents/interfaces/modelprovider/).[`getModel`](/openai-agents-js/openai/agents/interfaces/modelprovider/#getmodel) # OpenAIResponsesCompactionSession Session decorator that triggers `responses.compact` when the stored history grows. This session is intended to be passed to `run()` so the runner can automatically supply the latest `responseId` and invoke compaction after each completed turn is persisted. To debug compaction decisions, enable the `debug` logger for `openai-agents:openai:compaction` (for example, `DEBUG=openai-agents:openai:compaction`). ## Implements [Section titled “Implements”](#implements) * [`OpenAIResponsesCompactionAwareSession`](/openai-agents-js/openai/agents/interfaces/openairesponsescompactionawaresession/) * `OpenAISessionApiTagged`<`"responses"`> ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new OpenAIResponsesCompactionSession(options): OpenAIResponsesCompactionSession; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ---------------------------------------------------------------------------------------------------------------------------------- | | `options` | [`OpenAIResponsesCompactionSessionOptions`](/openai-agents-js/openai/agents/type-aliases/openairesponsescompactionsessionoptions/) | #### Returns [Section titled “Returns”](#returns) `OpenAIResponsesCompactionSession` ## Properties [Section titled “Properties”](#properties) ### \[OPENAI\_SESSION\_API] [Section titled “\[OPENAI\_SESSION\_API\]”](#openai_session_api) ```ts readonly [OPENAI_SESSION_API]: "responses"; ``` #### Implementation of [Section titled “Implementation of”](#implementation-of) ```ts OpenAISessionApiTagged.[OPENAI_SESSION_API] ``` ## Methods [Section titled “Methods”](#methods) ### addItems() [Section titled “addItems()”](#additems) ```ts addItems(items): Promise; ``` Append new items to the conversation history. #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | Description | | --------- | ----------------------------------------------------------------------------------- | ------------------------------------ | | `items` | [`AgentInputItem`](/openai-agents-js/openai/agents/type-aliases/agentinputitem/)\[] | Items to add to the session history. | #### Returns [Section titled “Returns”](#returns-1) `Promise`<`void`> #### Implementation of [Section titled “Implementation of”](#implementation-of-1) [`OpenAIResponsesCompactionAwareSession`](/openai-agents-js/openai/agents/interfaces/openairesponsescompactionawaresession/).[`addItems`](/openai-agents-js/openai/agents/interfaces/openairesponsescompactionawaresession/#additems) *** ### clearSession() [Section titled “clearSession()”](#clearsession) ```ts clearSession(): Promise; ``` Remove all items that belong to the session and reset its state. #### Returns [Section titled “Returns”](#returns-2) `Promise`<`void`> #### Implementation of [Section titled “Implementation of”](#implementation-of-2) [`OpenAIResponsesCompactionAwareSession`](/openai-agents-js/openai/agents/interfaces/openairesponsescompactionawaresession/).[`clearSession`](/openai-agents-js/openai/agents/interfaces/openairesponsescompactionawaresession/#clearsession) *** ### getItems() [Section titled “getItems()”](#getitems) ```ts getItems(limit?): Promise; ``` Retrieve items from the conversation history. #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | Description | | --------- | -------- | --------------------------------------------------------------------------------------------------------------------------- | | `limit?` | `number` | The maximum number of items to return. When provided the most recent limit items should be returned in chronological order. | #### Returns [Section titled “Returns”](#returns-3) `Promise`<[`AgentInputItem`](/openai-agents-js/openai/agents/type-aliases/agentinputitem/)\[]> #### Implementation of [Section titled “Implementation of”](#implementation-of-3) [`OpenAIResponsesCompactionAwareSession`](/openai-agents-js/openai/agents/interfaces/openairesponsescompactionawaresession/).[`getItems`](/openai-agents-js/openai/agents/interfaces/openairesponsescompactionawaresession/#getitems) *** ### getSessionId() [Section titled “getSessionId()”](#getsessionid) ```ts getSessionId(): Promise; ``` Ensure and return the identifier for this session. #### Returns [Section titled “Returns”](#returns-4) `Promise`<`string`> #### Implementation of [Section titled “Implementation of”](#implementation-of-4) [`OpenAIResponsesCompactionAwareSession`](/openai-agents-js/openai/agents/interfaces/openairesponsescompactionawaresession/).[`getSessionId`](/openai-agents-js/openai/agents/interfaces/openairesponsescompactionawaresession/#getsessionid) *** ### popItem() [Section titled “popItem()”](#popitem) ```ts popItem(): Promise< | AgentInputItem | undefined>; ``` Remove and return the most recent item from the conversation history if it exists. #### Returns [Section titled “Returns”](#returns-5) `Promise`< | [`AgentInputItem`](/openai-agents-js/openai/agents/type-aliases/agentinputitem/) | `undefined`> #### Implementation of [Section titled “Implementation of”](#implementation-of-5) [`OpenAIResponsesCompactionAwareSession`](/openai-agents-js/openai/agents/interfaces/openairesponsescompactionawaresession/).[`popItem`](/openai-agents-js/openai/agents/interfaces/openairesponsescompactionawaresession/#popitem) *** ### runCompaction() [Section titled “runCompaction()”](#runcompaction) ```ts runCompaction(args?): Promise< | OpenAIResponsesCompactionResult | null>; ``` Invoked by the runner after it persists a completed turn into the session. Implementations may decide to call `responses.compact` (or an equivalent API) and replace the stored history. This hook is best-effort. Implementations should consider handling transient failures and deciding whether to retry or skip compaction for the current turn. #### Parameters [Section titled “Parameters”](#parameters-3) | Parameter | Type | | --------- | -------------------------------------------------------------------------------------------------------------- | | `args?` | [`OpenAIResponsesCompactionArgs`](/openai-agents-js/openai/agents/type-aliases/openairesponsescompactionargs/) | #### Returns [Section titled “Returns”](#returns-6) `Promise`< | [`OpenAIResponsesCompactionResult`](/openai-agents-js/openai/agents/type-aliases/openairesponsescompactionresult/) | `null`> #### Implementation of [Section titled “Implementation of”](#implementation-of-6) [`OpenAIResponsesCompactionAwareSession`](/openai-agents-js/openai/agents/interfaces/openairesponsescompactionawaresession/).[`runCompaction`](/openai-agents-js/openai/agents/interfaces/openairesponsescompactionawaresession/#runcompaction) # OpenAIResponsesModel Model implementation that uses OpenAI’s Responses API to generate responses. ## Extended by [Section titled “Extended by”](#extended-by) * [`OpenAIResponsesWSModel`](/openai-agents-js/openai/agents/classes/openairesponseswsmodel/) ## Implements [Section titled “Implements”](#implements) * [`Model`](/openai-agents-js/openai/agents/interfaces/model/) ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new OpenAIResponsesModel(client, model): OpenAIResponsesModel; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | -------- | | `client` | `OpenAI` | | `model` | `string` | #### Returns [Section titled “Returns”](#returns) `OpenAIResponsesModel` ## Methods [Section titled “Methods”](#methods) ### getResponse() [Section titled “getResponse()”](#getresponse) ```ts getResponse(request): Promise; ``` Get a response from the OpenAI model using the Responses API. #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | Description | | --------- | ---------------------------------------------------------------------------- | --------------------------------- | | `request` | [`ModelRequest`](/openai-agents-js/openai/agents/type-aliases/modelrequest/) | The request to send to the model. | #### Returns [Section titled “Returns”](#returns-1) `Promise`<[`ModelResponse`](/openai-agents-js/openai/agents/type-aliases/modelresponse/)> A promise that resolves to the response from the model. #### Implementation of [Section titled “Implementation of”](#implementation-of) [`Model`](/openai-agents-js/openai/agents/interfaces/model/).[`getResponse`](/openai-agents-js/openai/agents/interfaces/model/#getresponse) *** ### getRetryAdvice() [Section titled “getRetryAdvice()”](#getretryadvice) ```ts getRetryAdvice(args): | ModelRetryAdvice | undefined; ``` Provide optional retry advice for a failed request. #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | --------- | -------------------------------------------------------------------------------------------------- | | `args` | [`ModelRetryAdviceRequest`](/openai-agents-js/openai/agents/type-aliases/modelretryadvicerequest/) | #### Returns [Section titled “Returns”](#returns-2) \| [`ModelRetryAdvice`](/openai-agents-js/openai/agents/type-aliases/modelretryadvice/) | `undefined` #### Implementation of [Section titled “Implementation of”](#implementation-of-1) [`Model`](/openai-agents-js/openai/agents/interfaces/model/).[`getRetryAdvice`](/openai-agents-js/openai/agents/interfaces/model/#getretryadvice) *** ### getStreamedResponse() [Section titled “getStreamedResponse()”](#getstreamedresponse) ```ts getStreamedResponse(request): AsyncIterable; ``` Get a streamed response from the OpenAI model using the Responses API. #### Parameters [Section titled “Parameters”](#parameters-3) | Parameter | Type | Description | | --------- | ---------------------------------------------------------------------------- | --------------------------------- | | `request` | [`ModelRequest`](/openai-agents-js/openai/agents/type-aliases/modelrequest/) | The request to send to the model. | #### Returns [Section titled “Returns”](#returns-3) `AsyncIterable`<[`StreamEvent`](/openai-agents-js/openai/agents/type-aliases/streamevent/)> An async iterable of the response from the model. #### Implementation of [Section titled “Implementation of”](#implementation-of-2) [`Model`](/openai-agents-js/openai/agents/interfaces/model/).[`getStreamedResponse`](/openai-agents-js/openai/agents/interfaces/model/#getstreamedresponse) # OpenAIResponsesWSModel Model implementation that uses the OpenAI Responses API over a websocket transport. ## See [Section titled “See”](#see) ## Extends [Section titled “Extends”](#extends) * [`OpenAIResponsesModel`](/openai-agents-js/openai/agents/classes/openairesponsesmodel/) ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new OpenAIResponsesWSModel( client, model, options?): OpenAIResponsesWSModel; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ---------- | ------------------------------- | | `client` | `OpenAI` | | `model` | `string` | | `options?` | `OpenAIResponsesWSModelOptions` | #### Returns [Section titled “Returns”](#returns) `OpenAIResponsesWSModel` #### Overrides [Section titled “Overrides”](#overrides) [`OpenAIResponsesModel`](/openai-agents-js/openai/agents/classes/openairesponsesmodel/).[`constructor`](/openai-agents-js/openai/agents/classes/openairesponsesmodel/#constructor) ## Methods [Section titled “Methods”](#methods) ### close() [Section titled “close()”](#close) ```ts close(): Promise; ``` #### Returns [Section titled “Returns”](#returns-1) `Promise`<`void`> *** ### getResponse() [Section titled “getResponse()”](#getresponse) ```ts getResponse(request): Promise; ``` Get a response from the OpenAI model using the Responses API. #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | Description | | --------- | ---------------------------------------------------------------------------- | --------------------------------- | | `request` | [`ModelRequest`](/openai-agents-js/openai/agents/type-aliases/modelrequest/) | The request to send to the model. | #### Returns [Section titled “Returns”](#returns-2) `Promise`<[`ModelResponse`](/openai-agents-js/openai/agents/type-aliases/modelresponse/)> A promise that resolves to the response from the model. #### Inherited from [Section titled “Inherited from”](#inherited-from) [`OpenAIResponsesModel`](/openai-agents-js/openai/agents/classes/openairesponsesmodel/).[`getResponse`](/openai-agents-js/openai/agents/classes/openairesponsesmodel/#getresponse) *** ### getRetryAdvice() [Section titled “getRetryAdvice()”](#getretryadvice) ```ts getRetryAdvice(args): | ModelRetryAdvice | undefined; ``` Provide optional retry advice for a failed request. #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | --------- | -------------------------------------------------------------------------------------------------- | | `args` | [`ModelRetryAdviceRequest`](/openai-agents-js/openai/agents/type-aliases/modelretryadvicerequest/) | #### Returns [Section titled “Returns”](#returns-3) \| [`ModelRetryAdvice`](/openai-agents-js/openai/agents/type-aliases/modelretryadvice/) | `undefined` #### Overrides [Section titled “Overrides”](#overrides-1) [`OpenAIResponsesModel`](/openai-agents-js/openai/agents/classes/openairesponsesmodel/).[`getRetryAdvice`](/openai-agents-js/openai/agents/classes/openairesponsesmodel/#getretryadvice) *** ### getStreamedResponse() [Section titled “getStreamedResponse()”](#getstreamedresponse) ```ts getStreamedResponse(request): AsyncIterable; ``` Get a streamed response from the OpenAI model using the Responses API. #### Parameters [Section titled “Parameters”](#parameters-3) | Parameter | Type | Description | | --------- | ---------------------------------------------------------------------------- | --------------------------------- | | `request` | [`ModelRequest`](/openai-agents-js/openai/agents/type-aliases/modelrequest/) | The request to send to the model. | #### Returns [Section titled “Returns”](#returns-4) `AsyncIterable`<[`StreamEvent`](/openai-agents-js/openai/agents/type-aliases/streamevent/)> An async iterable of the response from the model. #### Inherited from [Section titled “Inherited from”](#inherited-from-1) [`OpenAIResponsesModel`](/openai-agents-js/openai/agents/classes/openairesponsesmodel/).[`getStreamedResponse`](/openai-agents-js/openai/agents/classes/openairesponsesmodel/#getstreamedresponse) # OpenAITracingExporter A tracing exporter that exports traces to OpenAI’s tracing API. ## Implements [Section titled “Implements”](#implements) * [`TracingExporter`](/openai-agents-js/openai/agents/interfaces/tracingexporter/) ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new OpenAITracingExporter(options?): OpenAITracingExporter; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ---------- | ----------------------------------------------------------------------------------------------------------------------- | | `options?` | `Partial`<[`OpenAITracingExporterOptions`](/openai-agents-js/openai/agents/type-aliases/openaitracingexporteroptions/)> | #### Returns [Section titled “Returns”](#returns) `OpenAITracingExporter` ## Methods [Section titled “Methods”](#methods) ### export() [Section titled “export()”](#export) ```ts export(items, signal?): Promise; ``` Export the given traces and spans #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | Description | | --------- | ------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------ | | `items` | ( \| [`Span`](/openai-agents-js/openai/agents/classes/span/)<`any`> \| [`Trace`](/openai-agents-js/openai/agents/classes/trace/))\[] | The traces and spans to export | | `signal?` | `AbortSignal` | ‐ | #### Returns [Section titled “Returns”](#returns-1) `Promise`<`void`> #### Implementation of [Section titled “Implementation of”](#implementation-of) [`TracingExporter`](/openai-agents-js/openai/agents/interfaces/tracingexporter/).[`export`](/openai-agents-js/openai/agents/interfaces/tracingexporter/#export) # OutputGuardrailTripwireTriggered Error thrown when an output guardrail tripwire is triggered. ## Extends [Section titled “Extends”](#extends) * [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/) ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | ------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------ | | `TMeta` *extends* [`OutputGuardrailMetadata`](/openai-agents-js/openai/agents/interfaces/outputguardrailmetadata/) | ‐ | | `TOutputType` *extends* [`AgentOutputType`](/openai-agents-js/openai/agents/type-aliases/agentoutputtype/) | [`TextOutput`](/openai-agents-js/openai/agents/type-aliases/textoutput/) | ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new OutputGuardrailTripwireTriggered( message, result, state?): OutputGuardrailTripwireTriggered; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | -------------------------------------------------------------------------------------------------------------------- | | `message` | `string` | | `result` | [`OutputGuardrailResult`](/openai-agents-js/openai/agents/interfaces/outputguardrailresult/)<`TMeta`, `TOutputType`> | | `state?` | [`RunState`](/openai-agents-js/openai/agents/classes/runstate/)<`any`, `any`> | #### Returns [Section titled “Returns”](#returns) `OutputGuardrailTripwireTriggered`<`TMeta`, `TOutputType`> #### Overrides [Section titled “Overrides”](#overrides) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`constructor`](/openai-agents-js/openai/agents/classes/agentserror/#constructor) ## Properties [Section titled “Properties”](#properties) ### message [Section titled “message”](#message) ```ts message: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`message`](/openai-agents-js/openai/agents/classes/agentserror/#message) *** ### name [Section titled “name”](#name) ```ts name: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-1) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`name`](/openai-agents-js/openai/agents/classes/agentserror/#name) *** ### result [Section titled “result”](#result) ```ts result: OutputGuardrailResult; ``` *** ### stack? [Section titled “stack?”](#stack) ```ts optional stack?: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-2) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`stack`](/openai-agents-js/openai/agents/classes/agentserror/#stack) *** ### state? [Section titled “state?”](#state) ```ts optional state?: RunState>; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-3) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`state`](/openai-agents-js/openai/agents/classes/agentserror/#state) *** ### stackTraceLimit [Section titled “stackTraceLimit”](#stacktracelimit) ```ts static stackTraceLimit: number; ``` The `Error.stackTraceLimit` property specifies the number of stack frames collected by a stack trace (whether generated by `new Error().stack` or `Error.captureStackTrace(obj)`). The default value is `10` but may be set to any valid JavaScript number. Changes will affect any stack trace captured *after* the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames. #### Inherited from [Section titled “Inherited from”](#inherited-from-4) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`stackTraceLimit`](/openai-agents-js/openai/agents/classes/agentserror/#stacktracelimit) ## Methods [Section titled “Methods”](#methods) ### captureStackTrace() [Section titled “captureStackTrace()”](#capturestacktrace) ```ts static captureStackTrace(targetObject, constructorOpt?): void; ``` Creates a `.stack` property on `targetObject`, which when accessed returns a string representing the location in the code at which `Error.captureStackTrace()` was called. ```js const myObject = {}; Error.captureStackTrace(myObject); myObject.stack; // Similar to `new Error().stack` ``` The first line of the trace will be prefixed with `${myObject.name}: ${myObject.message}`. The optional `constructorOpt` argument accepts a function. If given, all frames above `constructorOpt`, including `constructorOpt`, will be omitted from the generated stack trace. The `constructorOpt` argument is useful for hiding implementation details of error generation from the user. For instance: ```js function a() { b(); } function b() { c(); } function c() { // Create an error without stack trace to avoid calculating the stack trace twice. const { stackTraceLimit } = Error; Error.stackTraceLimit = 0; const error = new Error(); Error.stackTraceLimit = stackTraceLimit; // Capture the stack trace above function b Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace throw error; } a(); ``` #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | ----------------- | ---------- | | `targetObject` | `object` | | `constructorOpt?` | `Function` | #### Returns [Section titled “Returns”](#returns-1) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-5) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`captureStackTrace`](/openai-agents-js/openai/agents/classes/agentserror/#capturestacktrace) *** ### prepareStackTrace() [Section titled “prepareStackTrace()”](#preparestacktrace) ```ts static prepareStackTrace(err, stackTraces): any; ``` #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | ------------- | ------------- | | `err` | `Error` | | `stackTraces` | `CallSite`\[] | #### Returns [Section titled “Returns”](#returns-2) `any` #### See [Section titled “See”](#see) #### Inherited from [Section titled “Inherited from”](#inherited-from-6) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`prepareStackTrace`](/openai-agents-js/openai/agents/classes/agentserror/#preparestacktrace) # RequestUsage Usage details for a single API request. ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new RequestUsage(input?): RequestUsage; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ------------------------------ | | `input?` | `Partial`<`object` & `object`> | #### Returns [Section titled “Returns”](#returns) `RequestUsage` ## Properties [Section titled “Properties”](#properties) ### endpoint? [Section titled “endpoint?”](#endpoint) ```ts optional endpoint?: string & object | "responses.create" | "responses.compact"; ``` The endpoint that produced this usage entry (e.g., responses.create, responses.compact). *** ### inputTokens [Section titled “inputTokens”](#inputtokens) ```ts inputTokens: number; ``` The number of input tokens used for this request. *** ### inputTokensDetails [Section titled “inputTokensDetails”](#inputtokensdetails) ```ts inputTokensDetails: Record; ``` Details about the input tokens used for this request. *** ### outputTokens [Section titled “outputTokens”](#outputtokens) ```ts outputTokens: number; ``` The number of output tokens used for this request. *** ### outputTokensDetails [Section titled “outputTokensDetails”](#outputtokensdetails) ```ts outputTokensDetails: Record; ``` Details about the output tokens used for this request. *** ### totalTokens [Section titled “totalTokens”](#totaltokens) ```ts totalTokens: number; ``` The total number of tokens sent and received for this request. # RunAgentUpdatedStreamEvent Event that notifies that there is a new agent running. ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new RunAgentUpdatedStreamEvent(agent): RunAgentUpdatedStreamEvent; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | --------- | ----------------------------------------------------------------------- | ------------- | | `agent` | [`Agent`](/openai-agents-js/openai/agents/classes/agent/)<`any`, `any`> | The new agent | #### Returns [Section titled “Returns”](#returns) `RunAgentUpdatedStreamEvent` ## Properties [Section titled “Properties”](#properties) ### agent [Section titled “agent”](#agent) ```ts agent: Agent; ``` *** ### type [Section titled “type”](#type) ```ts readonly type: "agent_updated_stream_event" = "agent_updated_stream_event"; ``` # RunContext A context object that is passed to the `Runner.run()` method. ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | -------------------------------------------------------------------------------- | | `TContext` | [`UnknownContext`](/openai-agents-js/openai/agents/type-aliases/unknowncontext/) | ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new RunContext(context?): RunContext; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ---------- | ---------- | | `context?` | `TContext` | #### Returns [Section titled “Returns”](#returns) `RunContext`<`TContext`> ## Properties [Section titled “Properties”](#properties) ### context [Section titled “context”](#context) ```ts context: TContext; ``` The context object you passed to the `Runner.run()` method. *** ### toolInput? [Section titled “toolInput?”](#toolinput) ```ts optional toolInput?: unknown; ``` Structured input for the current agent tool run, when available. *** ### usage [Section titled “usage”](#usage) ```ts usage: Usage; ``` The usage of the agent run so far. For streamed responses, the usage will be updated in real-time ## Methods [Section titled “Methods”](#methods) ### approveTool() [Section titled “approveTool()”](#approvetool) ```ts approveTool(approvalItem, options?): void; ``` Approve a tool call. #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | Description | | ------------------------ | ------------------------------------------------------------------------------------- | ------------------------------------- | | `approvalItem` | [`RunToolApprovalItem`](/openai-agents-js/openai/agents/classes/runtoolapprovalitem/) | The tool approval item to approve. | | `options?` | { `alwaysApprove?`: `boolean`; } | Additional approval behavior options. | | `options.alwaysApprove?` | `boolean` | ‐ | #### Returns [Section titled “Returns”](#returns-1) `void` *** ### getRejectionMessage() [Section titled “getRejectionMessage()”](#getrejectionmessage) ```ts getRejectionMessage(toolName, callId): string | undefined; ``` Retrieve the caller-provided rejection message for a specific tool call. #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | Description | | ---------- | -------- | ----------------------------------- | | `toolName` | `string` | The name of the tool. | | `callId` | `string` | The call ID of the tool invocation. | #### Returns [Section titled “Returns”](#returns-2) `string` | `undefined` The message string if one was provided, `undefined` otherwise. *** ### isToolApproved() [Section titled “isToolApproved()”](#istoolapproved) ```ts isToolApproved(approval): boolean | undefined; ``` Check if a tool call has been approved. #### Parameters [Section titled “Parameters”](#parameters-3) | Parameter | Type | Description | | ------------------- | --------------------------------------------- | -------------------------------------------- | | `approval` | { `callId`: `string`; `toolName`: `string`; } | Details about the tool call being evaluated. | | `approval.callId` | `string` | ‐ | | `approval.toolName` | `string` | ‐ | #### Returns [Section titled “Returns”](#returns-3) `boolean` | `undefined` `true` if the tool call has been approved, `false` if blocked and `undefined` if not yet approved or rejected. *** ### rejectTool() [Section titled “rejectTool()”](#rejecttool) ```ts rejectTool(approvalItem, __namedParameters?): void; ``` Reject a tool call. #### Parameters [Section titled “Parameters”](#parameters-4) | Parameter | Type | Description | | --------------------------------- | ------------------------------------------------------------------------------------- | --------------------------------- | | `approvalItem` | [`RunToolApprovalItem`](/openai-agents-js/openai/agents/classes/runtoolapprovalitem/) | The tool approval item to reject. | | `__namedParameters?` | { `alwaysReject?`: `boolean`; `message?`: `string`; } | ‐ | | `__namedParameters.alwaysReject?` | `boolean` | ‐ | | `__namedParameters.message?` | `string` | ‐ | #### Returns [Section titled “Returns”](#returns-4) `void` *** ### toJSON() [Section titled “toJSON()”](#tojson) ```ts toJSON(): RunContextJson; ``` #### Returns [Section titled “Returns”](#returns-5) `RunContextJson` # RunHandoffCallItem ## Extends [Section titled “Extends”](#extends) * `RunItemBase` ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new RunHandoffCallItem(rawItem, agent): RunHandoffCallItem; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ----------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `rawItem` | { `arguments`: `string`; `callId`: `string`; `id?`: `string`; `name`: `string`; `namespace?`: `string`; `providerData?`: `Record`<`string`, `any`>; `status?`: `"completed"` \| `"in_progress"` \| `"incomplete"`; `type`: `"function_call"`; } | | `rawItem.arguments` | `string` | | `rawItem.callId` | `string` | | `rawItem.id?` | `string` | | `rawItem.name` | `string` | | `rawItem.namespace?` | `string` | | `rawItem.providerData?` | `Record`<`string`, `any`> | | `rawItem.status?` | `"completed"` \| `"in_progress"` \| `"incomplete"` | | `rawItem.type` | `"function_call"` | | `agent` | [`Agent`](/openai-agents-js/openai/agents/classes/agent/) | #### Returns [Section titled “Returns”](#returns) `RunHandoffCallItem` #### Overrides [Section titled “Overrides”](#overrides) ```ts RunItemBase.constructor ``` ## Properties [Section titled “Properties”](#properties) ### agent [Section titled “agent”](#agent) ```ts agent: Agent; ``` *** ### rawItem [Section titled “rawItem”](#rawitem) ```ts rawItem: object; ``` | Name | Type | | --------------- | -------------------------------------------------- | | `arguments` | `string` | | `callId` | `string` | | `id?` | `string` | | `name` | `string` | | `namespace?` | `string` | | `providerData?` | `Record`<`string`, `any`> | | `status?` | `"completed"` \| `"in_progress"` \| `"incomplete"` | | `type` | `"function_call"` | #### Overrides [Section titled “Overrides”](#overrides-1) ```ts RunItemBase.rawItem ``` *** ### type [Section titled “type”](#type) ```ts readonly type: "handoff_call_item"; ``` #### Overrides [Section titled “Overrides”](#overrides-2) ```ts RunItemBase.type ``` ## Methods [Section titled “Methods”](#methods) ### toJSON() [Section titled “toJSON()”](#tojson) ```ts toJSON(): object; ``` #### Returns [Section titled “Returns”](#returns-1) `object` ##### agent [Section titled “agent”](#agent-1) ```ts agent: object; ``` ###### agent.name [Section titled “agent.name”](#agentname) ```ts name: string; ``` ##### rawItem [Section titled “rawItem”](#rawitem-1) ```ts rawItem: | { content: ( | { providerData?: Record; refusal: string; type: "refusal"; } | { providerData?: Record; text: string; type: "output_text"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; } | { image: string; providerData?: Record; type: "image"; })[]; id?: string; providerData?: Record; role: "assistant"; status: "completed" | "in_progress" | "incomplete"; type?: "message"; } | { content: | string | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; })[]; id?: string; providerData?: Record; role: "user"; type?: "message"; } | { content: string; id?: string; providerData?: Record; role: "system"; type?: "message"; } | { arguments?: string; id?: string; name: string; output?: string; providerData?: Record; status?: string; type: "hosted_tool_call"; } | { arguments: string; callId: string; id?: string; name: string; namespace?: string; providerData?: Record; status?: "completed" | "in_progress" | "incomplete"; type: "function_call"; } | { arguments: unknown; call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; type: "tool_search_call"; } | { call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; tools: Record[]; type: "tool_search_output"; } | { callId: string; id?: string; name: string; namespace?: string; output: | string | { providerData?: Record; text: string; type: "text"; } | { detail?: string & object | "low" | "high" | "auto"; image?: | string | { data: string | Uint8Array; mediaType?: string; } | { url: string; } | { fileId: string; }; providerData?: Record; type: "image"; } | { file: | string | { data: string | Uint8Array; filename: string; mediaType: string; } | { filename?: string; url: string; } | { filename?: string; id: string; }; providerData?: Record; type: "file"; } | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; })[]; providerData?: Record; status: "completed" | "in_progress" | "incomplete"; type: "function_call_result"; } | { action?: | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; }; actions?: ( | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; })[]; callId: string; id?: string; providerData?: Record; status: "completed" | "in_progress" | "incomplete"; type: "computer_call"; } | { callId: string; id?: string; output: { data: string; providerData?: Record; type: "computer_screenshot"; }; providerData?: Record; type: "computer_call_result"; } | { action: { commands: string[]; maxOutputLength?: number; timeoutMs?: number; }; callId: string; id?: string; providerData?: Record; status?: "completed" | "in_progress" | "incomplete"; type: "shell_call"; } | { callId: string; id?: string; maxOutputLength?: number; output: object[]; providerData?: Record; type: "shell_call_output"; } | { callId: string; id?: string; operation: | { diff: string; path: string; type: "create_file"; } | { diff: string; moveTo?: string; path: string; type: "update_file"; } | { path: string; type: "delete_file"; }; providerData?: Record; status: "completed" | "in_progress"; type: "apply_patch_call"; } | { callId: string; id?: string; output?: string; providerData?: Record; status: "completed" | "failed"; type: "apply_patch_call_output"; } | { content: object[]; id?: string; providerData?: Record; rawContent?: object[]; type: "reasoning"; } | { created_by?: string; encrypted_content: string; id?: string; providerData?: Record; type: "compaction"; } | { id?: string; providerData?: Record; type: "unknown"; } | undefined; ``` ##### type [Section titled “type”](#type-1) ```ts type: string; ``` #### Overrides [Section titled “Overrides”](#overrides-3) ```ts RunItemBase.toJSON ``` # RunHandoffOutputItem ## Extends [Section titled “Extends”](#extends) * `RunItemBase` ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new RunHandoffOutputItem( rawItem, sourceAgent, targetAgent): RunHandoffOutputItem; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ----------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `rawItem` | { `callId`: `string`; `id?`: `string`; `name`: `string`; `namespace?`: `string`; `output`: \| `string` \| { `providerData?`: `Record`<`string`, `any`>; `text`: `string`; `type`: `"text"`; } \| { `detail?`: `string` & `object` \| `"low"` \| `"high"` \| `"auto"`; `image?`: \| `string` \| { `data`: `string` \| `Uint8Array`<`ArrayBuffer`>; `mediaType?`: `string`; } \| { `url`: `string`; } \| { `fileId`: `string`; }; `providerData?`: `Record`<`string`, `any`>; `type`: `"image"`; } \| { `file`: \| `string` \| { `data`: `string` \| `Uint8Array`<`ArrayBuffer`>; `filename`: `string`; `mediaType`: `string`; } \| { `filename?`: `string`; `url`: `string`; } \| { `filename?`: `string`; `id`: `string`; }; `providerData?`: `Record`<`string`, `any`>; `type`: `"file"`; } \| ( \| { `providerData?`: `Record`<`string`, `any`>; `text`: `string`; `type`: `"input_text"`; } \| { `detail?`: `string`; `image?`: \| `string` \| { `id`: `string`; }; `providerData?`: `Record`<`string`, `any`>; `type`: `"input_image"`; } \| { `file?`: \| `string` \| { `id`: `string`; } \| { `url`: `string`; }; `filename?`: `string`; `providerData?`: `Record`<`string`, `any`>; `type`: `"input_file"`; })\[]; `providerData?`: `Record`<`string`, `any`>; `status`: `"completed"` \| `"in_progress"` \| `"incomplete"`; `type`: `"function_call_result"`; } | | `rawItem.callId` | `string` | | `rawItem.id?` | `string` | | `rawItem.name` | `string` | | `rawItem.namespace?` | `string` | | `rawItem.output` | \| `string` \| { `providerData?`: `Record`<`string`, `any`>; `text`: `string`; `type`: `"text"`; } \| { `detail?`: `string` & `object` \| `"low"` \| `"high"` \| `"auto"`; `image?`: \| `string` \| { `data`: `string` \| `Uint8Array`<`ArrayBuffer`>; `mediaType?`: `string`; } \| { `url`: `string`; } \| { `fileId`: `string`; }; `providerData?`: `Record`<`string`, `any`>; `type`: `"image"`; } \| { `file`: \| `string` \| { `data`: `string` \| `Uint8Array`<`ArrayBuffer`>; `filename`: `string`; `mediaType`: `string`; } \| { `filename?`: `string`; `url`: `string`; } \| { `filename?`: `string`; `id`: `string`; }; `providerData?`: `Record`<`string`, `any`>; `type`: `"file"`; } \| ( \| { `providerData?`: `Record`<`string`, `any`>; `text`: `string`; `type`: `"input_text"`; } \| { `detail?`: `string`; `image?`: \| `string` \| { `id`: `string`; }; `providerData?`: `Record`<`string`, `any`>; `type`: `"input_image"`; } \| { `file?`: \| `string` \| { `id`: `string`; } \| { `url`: `string`; }; `filename?`: `string`; `providerData?`: `Record`<`string`, `any`>; `type`: `"input_file"`; })\[] | | `rawItem.providerData?` | `Record`<`string`, `any`> | | `rawItem.status` | `"completed"` \| `"in_progress"` \| `"incomplete"` | | `rawItem.type` | `"function_call_result"` | | `sourceAgent` | [`Agent`](/openai-agents-js/openai/agents/classes/agent/)<`any`, `any`> | | `targetAgent` | [`Agent`](/openai-agents-js/openai/agents/classes/agent/)<`any`, `any`> | #### Returns [Section titled “Returns”](#returns) `RunHandoffOutputItem` #### Overrides [Section titled “Overrides”](#overrides) ```ts RunItemBase.constructor ``` ## Properties [Section titled “Properties”](#properties) ### rawItem [Section titled “rawItem”](#rawitem) ```ts rawItem: object; ``` | Name | Type | | --------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `callId` | `string` | | `id?` | `string` | | `name` | `string` | | `namespace?` | `string` | | `output` | \| `string` \| { `providerData?`: `Record`<`string`, `any`>; `text`: `string`; `type`: `"text"`; } \| { `detail?`: `string` & `object` \| `"low"` \| `"high"` \| `"auto"`; `image?`: \| `string` \| { `data`: `string` \| `Uint8Array`<`ArrayBuffer`>; `mediaType?`: `string`; } \| { `url`: `string`; } \| { `fileId`: `string`; }; `providerData?`: `Record`<`string`, `any`>; `type`: `"image"`; } \| { `file`: \| `string` \| { `data`: `string` \| `Uint8Array`<`ArrayBuffer`>; `filename`: `string`; `mediaType`: `string`; } \| { `filename?`: `string`; `url`: `string`; } \| { `filename?`: `string`; `id`: `string`; }; `providerData?`: `Record`<`string`, `any`>; `type`: `"file"`; } \| ( \| { `providerData?`: `Record`<`string`, `any`>; `text`: `string`; `type`: `"input_text"`; } \| { `detail?`: `string`; `image?`: \| `string` \| { `id`: `string`; }; `providerData?`: `Record`<`string`, `any`>; `type`: `"input_image"`; } \| { `file?`: \| `string` \| { `id`: `string`; } \| { `url`: `string`; }; `filename?`: `string`; `providerData?`: `Record`<`string`, `any`>; `type`: `"input_file"`; })\[] | | `providerData?` | `Record`<`string`, `any`> | | `status` | `"completed"` \| `"in_progress"` \| `"incomplete"` | | `type` | `"function_call_result"` | #### Overrides [Section titled “Overrides”](#overrides-1) ```ts RunItemBase.rawItem ``` *** ### sourceAgent [Section titled “sourceAgent”](#sourceagent) ```ts sourceAgent: Agent; ``` *** ### targetAgent [Section titled “targetAgent”](#targetagent) ```ts targetAgent: Agent; ``` *** ### type [Section titled “type”](#type) ```ts readonly type: "handoff_output_item"; ``` #### Overrides [Section titled “Overrides”](#overrides-2) ```ts RunItemBase.type ``` ## Methods [Section titled “Methods”](#methods) ### toJSON() [Section titled “toJSON()”](#tojson) ```ts toJSON(): object; ``` #### Returns [Section titled “Returns”](#returns-1) `object` ##### rawItem [Section titled “rawItem”](#rawitem-1) ```ts rawItem: | { content: ( | { providerData?: Record; refusal: string; type: "refusal"; } | { providerData?: Record; text: string; type: "output_text"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; } | { image: string; providerData?: Record; type: "image"; })[]; id?: string; providerData?: Record; role: "assistant"; status: "completed" | "in_progress" | "incomplete"; type?: "message"; } | { content: | string | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; })[]; id?: string; providerData?: Record; role: "user"; type?: "message"; } | { content: string; id?: string; providerData?: Record; role: "system"; type?: "message"; } | { arguments?: string; id?: string; name: string; output?: string; providerData?: Record; status?: string; type: "hosted_tool_call"; } | { arguments: string; callId: string; id?: string; name: string; namespace?: string; providerData?: Record; status?: "completed" | "in_progress" | "incomplete"; type: "function_call"; } | { arguments: unknown; call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; type: "tool_search_call"; } | { call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; tools: Record[]; type: "tool_search_output"; } | { callId: string; id?: string; name: string; namespace?: string; output: | string | { providerData?: Record; text: string; type: "text"; } | { detail?: string & object | "low" | "high" | "auto"; image?: | string | { data: string | Uint8Array; mediaType?: string; } | { url: string; } | { fileId: string; }; providerData?: Record; type: "image"; } | { file: | string | { data: string | Uint8Array; filename: string; mediaType: string; } | { filename?: string; url: string; } | { filename?: string; id: string; }; providerData?: Record; type: "file"; } | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; })[]; providerData?: Record; status: "completed" | "in_progress" | "incomplete"; type: "function_call_result"; } | { action?: | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; }; actions?: ( | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; })[]; callId: string; id?: string; providerData?: Record; status: "completed" | "in_progress" | "incomplete"; type: "computer_call"; } | { callId: string; id?: string; output: { data: string; providerData?: Record; type: "computer_screenshot"; }; providerData?: Record; type: "computer_call_result"; } | { action: { commands: string[]; maxOutputLength?: number; timeoutMs?: number; }; callId: string; id?: string; providerData?: Record; status?: "completed" | "in_progress" | "incomplete"; type: "shell_call"; } | { callId: string; id?: string; maxOutputLength?: number; output: object[]; providerData?: Record; type: "shell_call_output"; } | { callId: string; id?: string; operation: | { diff: string; path: string; type: "create_file"; } | { diff: string; moveTo?: string; path: string; type: "update_file"; } | { path: string; type: "delete_file"; }; providerData?: Record; status: "completed" | "in_progress"; type: "apply_patch_call"; } | { callId: string; id?: string; output?: string; providerData?: Record; status: "completed" | "failed"; type: "apply_patch_call_output"; } | { content: object[]; id?: string; providerData?: Record; rawContent?: object[]; type: "reasoning"; } | { created_by?: string; encrypted_content: string; id?: string; providerData?: Record; type: "compaction"; } | { id?: string; providerData?: Record; type: "unknown"; } | undefined; ``` ##### sourceAgent [Section titled “sourceAgent”](#sourceagent-1) ```ts sourceAgent: object; ``` ###### sourceAgent.name [Section titled “sourceAgent.name”](#sourceagentname) ```ts name: string; ``` ##### targetAgent [Section titled “targetAgent”](#targetagent-1) ```ts targetAgent: object; ``` ###### targetAgent.name [Section titled “targetAgent.name”](#targetagentname) ```ts name: string; ``` ##### type [Section titled “type”](#type-1) ```ts type: string; ``` #### Overrides [Section titled “Overrides”](#overrides-3) ```ts RunItemBase.toJSON ``` # RunItemStreamEvent Streaming events that wrap a `RunItem`. As the agent processes the LLM response, it will generate these events from new messages, tool calls, tool outputs, handoffs, etc. ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new RunItemStreamEvent(name, item): RunItemStreamEvent; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | --------- | ------------------------------------------------------------------ | -------------------------- | | `name` | `RunItemStreamEventName` | The name of the event. | | `item` | [`RunItem`](/openai-agents-js/openai/agents/type-aliases/runitem/) | The item that was created. | #### Returns [Section titled “Returns”](#returns) `RunItemStreamEvent` ## Properties [Section titled “Properties”](#properties) ### item [Section titled “item”](#item) ```ts item: RunItem; ``` *** ### name [Section titled “name”](#name) ```ts name: RunItemStreamEventName; ``` *** ### type [Section titled “type”](#type) ```ts readonly type: "run_item_stream_event" = "run_item_stream_event"; ``` # RunMessageOutputItem ## Extends [Section titled “Extends”](#extends) * `RunItemBase` ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new RunMessageOutputItem(rawItem, agent): RunMessageOutputItem; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ----------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `rawItem` | { `content`: ( \| { `providerData?`: `Record`<`string`, `any`>; `text`: `string`; `type`: `"output_text"`; } \| { `providerData?`: `Record`<`string`, `any`>; `refusal`: `string`; `type`: `"refusal"`; } \| { `audio`: \| `string` \| { `id`: `string`; }; `format?`: `string` \| `null`; `providerData?`: `Record`<`string`, `any`>; `transcript?`: `string` \| `null`; `type`: `"audio"`; } \| { `image`: `string`; `providerData?`: `Record`<`string`, `any`>; `type`: `"image"`; })\[]; `id?`: `string`; `providerData?`: `Record`<`string`, `any`>; `role`: `"assistant"`; `status`: `"completed"` \| `"in_progress"` \| `"incomplete"`; `type?`: `"message"`; } | | `rawItem.content` | ( \| { `providerData?`: `Record`<`string`, `any`>; `text`: `string`; `type`: `"output_text"`; } \| { `providerData?`: `Record`<`string`, `any`>; `refusal`: `string`; `type`: `"refusal"`; } \| { `audio`: \| `string` \| { `id`: `string`; }; `format?`: `string` \| `null`; `providerData?`: `Record`<`string`, `any`>; `transcript?`: `string` \| `null`; `type`: `"audio"`; } \| { `image`: `string`; `providerData?`: `Record`<`string`, `any`>; `type`: `"image"`; })\[] | | `rawItem.id?` | `string` | | `rawItem.providerData?` | `Record`<`string`, `any`> | | `rawItem.role` | `"assistant"` | | `rawItem.status` | `"completed"` \| `"in_progress"` \| `"incomplete"` | | `rawItem.type?` | `"message"` | | `agent` | [`Agent`](/openai-agents-js/openai/agents/classes/agent/) | #### Returns [Section titled “Returns”](#returns) `RunMessageOutputItem` #### Overrides [Section titled “Overrides”](#overrides) ```ts RunItemBase.constructor ``` ## Properties [Section titled “Properties”](#properties) ### agent [Section titled “agent”](#agent) ```ts agent: Agent; ``` *** ### rawItem [Section titled “rawItem”](#rawitem) ```ts rawItem: object; ``` | Name | Type | | --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | `content` | ( \| { `providerData?`: `Record`<`string`, `any`>; `text`: `string`; `type`: `"output_text"`; } \| { `providerData?`: `Record`<`string`, `any`>; `refusal`: `string`; `type`: `"refusal"`; } \| { `audio`: \| `string` \| { `id`: `string`; }; `format?`: `string` \| `null`; `providerData?`: `Record`<`string`, `any`>; `transcript?`: `string` \| `null`; `type`: `"audio"`; } \| { `image`: `string`; `providerData?`: `Record`<`string`, `any`>; `type`: `"image"`; })\[] | | `id?` | `string` | | `providerData?` | `Record`<`string`, `any`> | | `role` | `"assistant"` | | `status` | `"completed"` \| `"in_progress"` \| `"incomplete"` | | `type?` | `"message"` | #### Overrides [Section titled “Overrides”](#overrides-1) ```ts RunItemBase.rawItem ``` *** ### type [Section titled “type”](#type) ```ts readonly type: "message_output_item"; ``` #### Overrides [Section titled “Overrides”](#overrides-2) ```ts RunItemBase.type ``` ## Accessors [Section titled “Accessors”](#accessors) ### content [Section titled “content”](#content) #### Get Signature [Section titled “Get Signature”](#get-signature) ```ts get content(): string; ``` ##### Returns [Section titled “Returns”](#returns-1) `string` ## Methods [Section titled “Methods”](#methods) ### toJSON() [Section titled “toJSON()”](#tojson) ```ts toJSON(): object; ``` #### Returns [Section titled “Returns”](#returns-2) `object` ##### agent [Section titled “agent”](#agent-1) ```ts agent: object; ``` ###### agent.name [Section titled “agent.name”](#agentname) ```ts name: string; ``` ##### rawItem [Section titled “rawItem”](#rawitem-1) ```ts rawItem: | { content: ( | { providerData?: Record; refusal: string; type: "refusal"; } | { providerData?: Record; text: string; type: "output_text"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; } | { image: string; providerData?: Record; type: "image"; })[]; id?: string; providerData?: Record; role: "assistant"; status: "completed" | "in_progress" | "incomplete"; type?: "message"; } | { content: | string | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; })[]; id?: string; providerData?: Record; role: "user"; type?: "message"; } | { content: string; id?: string; providerData?: Record; role: "system"; type?: "message"; } | { arguments?: string; id?: string; name: string; output?: string; providerData?: Record; status?: string; type: "hosted_tool_call"; } | { arguments: string; callId: string; id?: string; name: string; namespace?: string; providerData?: Record; status?: "completed" | "in_progress" | "incomplete"; type: "function_call"; } | { arguments: unknown; call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; type: "tool_search_call"; } | { call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; tools: Record[]; type: "tool_search_output"; } | { callId: string; id?: string; name: string; namespace?: string; output: | string | { providerData?: Record; text: string; type: "text"; } | { detail?: string & object | "low" | "high" | "auto"; image?: | string | { data: string | Uint8Array; mediaType?: string; } | { url: string; } | { fileId: string; }; providerData?: Record; type: "image"; } | { file: | string | { data: string | Uint8Array; filename: string; mediaType: string; } | { filename?: string; url: string; } | { filename?: string; id: string; }; providerData?: Record; type: "file"; } | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; })[]; providerData?: Record; status: "completed" | "in_progress" | "incomplete"; type: "function_call_result"; } | { action?: | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; }; actions?: ( | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; })[]; callId: string; id?: string; providerData?: Record; status: "completed" | "in_progress" | "incomplete"; type: "computer_call"; } | { callId: string; id?: string; output: { data: string; providerData?: Record; type: "computer_screenshot"; }; providerData?: Record; type: "computer_call_result"; } | { action: { commands: string[]; maxOutputLength?: number; timeoutMs?: number; }; callId: string; id?: string; providerData?: Record; status?: "completed" | "in_progress" | "incomplete"; type: "shell_call"; } | { callId: string; id?: string; maxOutputLength?: number; output: object[]; providerData?: Record; type: "shell_call_output"; } | { callId: string; id?: string; operation: | { diff: string; path: string; type: "create_file"; } | { diff: string; moveTo?: string; path: string; type: "update_file"; } | { path: string; type: "delete_file"; }; providerData?: Record; status: "completed" | "in_progress"; type: "apply_patch_call"; } | { callId: string; id?: string; output?: string; providerData?: Record; status: "completed" | "failed"; type: "apply_patch_call_output"; } | { content: object[]; id?: string; providerData?: Record; rawContent?: object[]; type: "reasoning"; } | { created_by?: string; encrypted_content: string; id?: string; providerData?: Record; type: "compaction"; } | { id?: string; providerData?: Record; type: "unknown"; } | undefined; ``` ##### type [Section titled “type”](#type-1) ```ts type: string; ``` #### Overrides [Section titled “Overrides”](#overrides-3) ```ts RunItemBase.toJSON ``` # Runner Orchestrates agent execution, including guardrails, tool calls, session persistence, and tracing. Reuse a `Runner` instance when you want consistent configuration across multiple runs. ## Extends [Section titled “Extends”](#extends) * `RunHooks`<`any`, [`AgentOutputType`](/openai-agents-js/openai/agents/type-aliases/agentoutputtype/)<`unknown`>> ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new Runner(config?): Runner; ``` Creates a runner with optional defaults that apply to every subsequent run invocation. #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | --------- | --------------------------------------------------------------------------------- | --------------------------------------------------------------- | | `config?` | `Partial`<[`RunConfig`](/openai-agents-js/openai/agents/type-aliases/runconfig/)> | Overrides for models, guardrails, tracing, or session behavior. | #### Returns [Section titled “Returns”](#returns) `Runner` #### Overrides [Section titled “Overrides”](#overrides) ```ts RunHooks>.constructor ``` ## Properties [Section titled “Properties”](#properties) ### config [Section titled “config”](#config) ```ts readonly config: RunConfig; ``` ## Methods [Section titled “Methods”](#methods) ### emit() [Section titled “emit()”](#emit) ```ts emit(type, ...args): boolean; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | ----------------------------------------------------------------------------------------------------------------------------------------- | | `K` *extends* keyof `RunHookEvents`<`any`, [`AgentOutputType`](/openai-agents-js/openai/agents/type-aliases/agentoutputtype/)<`unknown`>> | #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | --------- | --------------------------------------------------------------------------------------------------------------------------- | | `type` | `K` | | …`args` | `RunHookEvents`<`any`, [`AgentOutputType`](/openai-agents-js/openai/agents/type-aliases/agentoutputtype/)<`unknown`>>\[`K`] | #### Returns [Section titled “Returns”](#returns-1) `boolean` #### Inherited from [Section titled “Inherited from”](#inherited-from) ```ts RunHooks.emit ``` *** ### off() [Section titled “off()”](#off) ```ts off(type, listener): EventEmitter; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-1) | Type Parameter | | ----------------------------------------------------------------------------------------------------------------------------------------- | | `K` *extends* keyof `RunHookEvents`<`any`, [`AgentOutputType`](/openai-agents-js/openai/agents/type-aliases/agentoutputtype/)<`unknown`>> | #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | ---------- | ------------------- | | `type` | `K` | | `listener` | (…`args`) => `void` | #### Returns [Section titled “Returns”](#returns-2) `EventEmitter`<`EventTypes`> #### Inherited from [Section titled “Inherited from”](#inherited-from-1) ```ts RunHooks.off ``` *** ### on() [Section titled “on()”](#on) ```ts on(type, listener): EventEmitter; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-2) | Type Parameter | | ----------------------------------------------------------------------------------------------------------------------------------------- | | `K` *extends* keyof `RunHookEvents`<`any`, [`AgentOutputType`](/openai-agents-js/openai/agents/type-aliases/agentoutputtype/)<`unknown`>> | #### Parameters [Section titled “Parameters”](#parameters-3) | Parameter | Type | | ---------- | ------------------- | | `type` | `K` | | `listener` | (…`args`) => `void` | #### Returns [Section titled “Returns”](#returns-3) `EventEmitter`<`EventTypes`> #### Inherited from [Section titled “Inherited from”](#inherited-from-2) ```ts RunHooks.on ``` *** ### once() [Section titled “once()”](#once) ```ts once(type, listener): EventEmitter; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-3) | Type Parameter | | ----------------------------------------------------------------------------------------------------------------------------------------- | | `K` *extends* keyof `RunHookEvents`<`any`, [`AgentOutputType`](/openai-agents-js/openai/agents/type-aliases/agentoutputtype/)<`unknown`>> | #### Parameters [Section titled “Parameters”](#parameters-4) | Parameter | Type | | ---------- | ------------------- | | `type` | `K` | | `listener` | (…`args`) => `void` | #### Returns [Section titled “Returns”](#returns-4) `EventEmitter`<`EventTypes`> #### Inherited from [Section titled “Inherited from”](#inherited-from-3) ```ts RunHooks.once ``` *** ### run() [Section titled “run()”](#run) #### Call Signature [Section titled “Call Signature”](#call-signature) ```ts run( agent, input, options?): Promise>; ``` Run a workflow starting at the given agent. The agent will run in a loop until a final output is generated. The loop runs like so: 1. The agent is invoked with the given input. 2. If there is a final output (i.e. the agent produces something of type `agent.outputType`, the loop terminates. 3. If there’s a handoff, we run the loop again, with the new agent. 4. Else, we run tool calls (if any), and re-run the loop. In two cases, the agent may raise an exception: 1. If the maxTurns is exceeded, a MaxTurnsExceeded exception is raised unless handled. 2. If a guardrail tripwire is triggered, a GuardrailTripwireTriggered exception is raised. Note that only the first agent’s input guardrails are run. ##### Type Parameters [Section titled “Type Parameters”](#type-parameters-4) | Type Parameter | Default type | | ------------------------------------------------------------------------------------------ | ------------ | | `TAgent` *extends* [`Agent`](/openai-agents-js/openai/agents/classes/agent/)<`any`, `any`> | ‐ | | `TContext` | `undefined` | ##### Parameters [Section titled “Parameters”](#parameters-5) | Parameter | Type | Description | | ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------ | | `agent` | `TAgent` | The starting agent to run. | | `input` | \| `string` \| [`AgentInputItem`](/openai-agents-js/openai/agents/type-aliases/agentinputitem/)\[] \| [`RunState`](/openai-agents-js/openai/agents/classes/runstate/)<`TContext`, `TAgent`> | The initial input to the agent. You can pass a string or an array of `AgentInputItem`. | | `options?` | [`NonStreamRunOptions`](/openai-agents-js/openai/agents/type-aliases/nonstreamrunoptions/)<`TContext`, `TAgent`> | Options for the run, including streaming behavior, execution context, and the maximum number of turns. | ##### Returns [Section titled “Returns”](#returns-5) `Promise`<[`RunResult`](/openai-agents-js/openai/agents/classes/runresult/)<`TContext`, `TAgent`>> The result of the run. #### Call Signature [Section titled “Call Signature”](#call-signature-1) ```ts run( agent, input, options?): Promise>; ``` Run a workflow starting at the given agent. The agent will run in a loop until a final output is generated. The loop runs like so: 1. The agent is invoked with the given input. 2. If there is a final output (i.e. the agent produces something of type `agent.outputType`, the loop terminates. 3. If there’s a handoff, we run the loop again, with the new agent. 4. Else, we run tool calls (if any), and re-run the loop. In two cases, the agent may raise an exception: 1. If the maxTurns is exceeded, a MaxTurnsExceeded exception is raised unless handled. 2. If a guardrail tripwire is triggered, a GuardrailTripwireTriggered exception is raised. Note that only the first agent’s input guardrails are run. ##### Type Parameters [Section titled “Type Parameters”](#type-parameters-5) | Type Parameter | Default type | | ------------------------------------------------------------------------------------------ | ------------ | | `TAgent` *extends* [`Agent`](/openai-agents-js/openai/agents/classes/agent/)<`any`, `any`> | ‐ | | `TContext` | `undefined` | ##### Parameters [Section titled “Parameters”](#parameters-6) | Parameter | Type | Description | | ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------ | | `agent` | `TAgent` | The starting agent to run. | | `input` | \| `string` \| [`AgentInputItem`](/openai-agents-js/openai/agents/type-aliases/agentinputitem/)\[] \| [`RunState`](/openai-agents-js/openai/agents/classes/runstate/)<`TContext`, `TAgent`> | The initial input to the agent. You can pass a string or an array of `AgentInputItem`. | | `options?` | [`StreamRunOptions`](/openai-agents-js/openai/agents/type-aliases/streamrunoptions/)<`TContext`, `TAgent`> | Options for the run, including streaming behavior, execution context, and the maximum number of turns. | ##### Returns [Section titled “Returns”](#returns-6) `Promise`<[`StreamedRunResult`](/openai-agents-js/openai/agents/classes/streamedrunresult/)<`TContext`, `TAgent`>> The result of the run. # RunRawModelStreamEvent Streaming event from the LLM. These are `raw` events, i.e. they are directly passed through from the LLM. ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new RunRawModelStreamEvent(data, source?): RunRawModelStreamEvent; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | --------- | -------------------------------------------------------------------------- | --------------------------------------------- | | `data` | [`StreamEvent`](/openai-agents-js/openai/agents/type-aliases/streamevent/) | The raw responses stream events from the LLM. | | `source?` | `string` | ‐ | #### Returns [Section titled “Returns”](#returns) `RunRawModelStreamEvent` ## Properties [Section titled “Properties”](#properties) ### data [Section titled “data”](#data) ```ts data: StreamEvent; ``` *** ### source [Section titled “source”](#source) ```ts readonly source: string | undefined; ``` *** ### type [Section titled “type”](#type) ```ts readonly type: "raw_model_stream_event" = "raw_model_stream_event"; ``` The type of the event. # RunReasoningItem ## Extends [Section titled “Extends”](#extends) * `RunItemBase` ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new RunReasoningItem(rawItem, agent): RunReasoningItem; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- | | `rawItem` | { `content`: `object`\[]; `id?`: `string`; `providerData?`: `Record`<`string`, `any`>; `rawContent?`: `object`\[]; `type`: `"reasoning"`; } | | `rawItem.content` | `object`\[] | | `rawItem.id?` | `string` | | `rawItem.providerData?` | `Record`<`string`, `any`> | | `rawItem.rawContent?` | `object`\[] | | `rawItem.type` | `"reasoning"` | | `agent` | [`Agent`](/openai-agents-js/openai/agents/classes/agent/) | #### Returns [Section titled “Returns”](#returns) `RunReasoningItem` #### Overrides [Section titled “Overrides”](#overrides) ```ts RunItemBase.constructor ``` ## Properties [Section titled “Properties”](#properties) ### agent [Section titled “agent”](#agent) ```ts agent: Agent; ``` *** ### rawItem [Section titled “rawItem”](#rawitem) ```ts rawItem: object; ``` | Name | Type | | --------------- | ------------------------- | | `content` | `object`\[] | | `id?` | `string` | | `providerData?` | `Record`<`string`, `any`> | | `rawContent?` | `object`\[] | | `type` | `"reasoning"` | #### Overrides [Section titled “Overrides”](#overrides-1) ```ts RunItemBase.rawItem ``` *** ### type [Section titled “type”](#type) ```ts readonly type: "reasoning_item"; ``` #### Overrides [Section titled “Overrides”](#overrides-2) ```ts RunItemBase.type ``` ## Methods [Section titled “Methods”](#methods) ### toJSON() [Section titled “toJSON()”](#tojson) ```ts toJSON(): object; ``` #### Returns [Section titled “Returns”](#returns-1) `object` ##### agent [Section titled “agent”](#agent-1) ```ts agent: object; ``` ###### agent.name [Section titled “agent.name”](#agentname) ```ts name: string; ``` ##### rawItem [Section titled “rawItem”](#rawitem-1) ```ts rawItem: | { content: ( | { providerData?: Record; refusal: string; type: "refusal"; } | { providerData?: Record; text: string; type: "output_text"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; } | { image: string; providerData?: Record; type: "image"; })[]; id?: string; providerData?: Record; role: "assistant"; status: "completed" | "in_progress" | "incomplete"; type?: "message"; } | { content: | string | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; })[]; id?: string; providerData?: Record; role: "user"; type?: "message"; } | { content: string; id?: string; providerData?: Record; role: "system"; type?: "message"; } | { arguments?: string; id?: string; name: string; output?: string; providerData?: Record; status?: string; type: "hosted_tool_call"; } | { arguments: string; callId: string; id?: string; name: string; namespace?: string; providerData?: Record; status?: "completed" | "in_progress" | "incomplete"; type: "function_call"; } | { arguments: unknown; call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; type: "tool_search_call"; } | { call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; tools: Record[]; type: "tool_search_output"; } | { callId: string; id?: string; name: string; namespace?: string; output: | string | { providerData?: Record; text: string; type: "text"; } | { detail?: string & object | "low" | "high" | "auto"; image?: | string | { data: string | Uint8Array; mediaType?: string; } | { url: string; } | { fileId: string; }; providerData?: Record; type: "image"; } | { file: | string | { data: string | Uint8Array; filename: string; mediaType: string; } | { filename?: string; url: string; } | { filename?: string; id: string; }; providerData?: Record; type: "file"; } | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; })[]; providerData?: Record; status: "completed" | "in_progress" | "incomplete"; type: "function_call_result"; } | { action?: | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; }; actions?: ( | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; })[]; callId: string; id?: string; providerData?: Record; status: "completed" | "in_progress" | "incomplete"; type: "computer_call"; } | { callId: string; id?: string; output: { data: string; providerData?: Record; type: "computer_screenshot"; }; providerData?: Record; type: "computer_call_result"; } | { action: { commands: string[]; maxOutputLength?: number; timeoutMs?: number; }; callId: string; id?: string; providerData?: Record; status?: "completed" | "in_progress" | "incomplete"; type: "shell_call"; } | { callId: string; id?: string; maxOutputLength?: number; output: object[]; providerData?: Record; type: "shell_call_output"; } | { callId: string; id?: string; operation: | { diff: string; path: string; type: "create_file"; } | { diff: string; moveTo?: string; path: string; type: "update_file"; } | { path: string; type: "delete_file"; }; providerData?: Record; status: "completed" | "in_progress"; type: "apply_patch_call"; } | { callId: string; id?: string; output?: string; providerData?: Record; status: "completed" | "failed"; type: "apply_patch_call_output"; } | { content: object[]; id?: string; providerData?: Record; rawContent?: object[]; type: "reasoning"; } | { created_by?: string; encrypted_content: string; id?: string; providerData?: Record; type: "compaction"; } | { id?: string; providerData?: Record; type: "unknown"; } | undefined; ``` ##### type [Section titled “type”](#type-1) ```ts type: string; ``` #### Overrides [Section titled “Overrides”](#overrides-3) ```ts RunItemBase.toJSON ``` # RunResult The result of an agent run. ## Extends [Section titled “Extends”](#extends) * `RunResultBase`<`TContext`, `TAgent`> ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `TContext` | | `TAgent` *extends* [`Agent`](/openai-agents-js/openai/agents/classes/agent/)<`TContext`, [`AgentOutputType`](/openai-agents-js/openai/agents/type-aliases/agentoutputtype/)> | ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new RunResult(state): RunResult; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ------------------------------------------------------------------------------------- | | `state` | [`RunState`](/openai-agents-js/openai/agents/classes/runstate/)<`TContext`, `TAgent`> | #### Returns [Section titled “Returns”](#returns) `RunResult`<`TContext`, `TAgent`> #### Overrides [Section titled “Overrides”](#overrides) ```ts RunResultBase.constructor ``` ## Properties [Section titled “Properties”](#properties) ### state [Section titled “state”](#state) ```ts readonly state: RunState; ``` The state of the run. #### Inherited from [Section titled “Inherited from”](#inherited-from) ```ts RunResultBase.state ``` ## Accessors [Section titled “Accessors”](#accessors) ### activeAgent [Section titled “activeAgent”](#activeagent) #### Get Signature [Section titled “Get Signature”](#get-signature) ```ts get activeAgent(): TAgent | undefined; ``` The agent that should handle the next turn. This is an alias for the last agent that completed a turn. ##### Returns [Section titled “Returns”](#returns-1) `TAgent` | `undefined` #### Inherited from [Section titled “Inherited from”](#inherited-from-1) ```ts RunResultBase.activeAgent ``` *** ### agentToolInvocation [Section titled “agentToolInvocation”](#agenttoolinvocation) #### Get Signature [Section titled “Get Signature”](#get-signature-1) ```ts get agentToolInvocation(): | Readonly<{ toolArguments?: string; toolCallId?: string; toolName: string; }> | undefined; ``` Metadata about the nested `Agent.asTool()` invocation that produced this result, when applicable. ##### Returns [Section titled “Returns”](#returns-2) \| `Readonly`<{ `toolArguments?`: `string`; `toolCallId?`: `string`; `toolName`: `string`; }> | `undefined` #### Inherited from [Section titled “Inherited from”](#inherited-from-2) ```ts RunResultBase.agentToolInvocation ``` *** ### finalOutput [Section titled “finalOutput”](#finaloutput) #### Get Signature [Section titled “Get Signature”](#get-signature-2) ```ts get finalOutput(): ResolvedAgentOutput | undefined; ``` The final output of the agent. If the output type was set to anything other than `text`, this will be parsed either as JSON or using the Zod schema you provided. ##### Returns [Section titled “Returns”](#returns-3) `ResolvedAgentOutput`<`TAgent`\[`"outputType"`]> | `undefined` #### Inherited from [Section titled “Inherited from”](#inherited-from-3) ```ts RunResultBase.finalOutput ``` *** ### history [Section titled “history”](#history) #### Get Signature [Section titled “Get Signature”](#get-signature-3) ```ts get history(): AgentInputItem[]; ``` The history of the agent run. This includes the input items and the new items generated during the agent run. This can be used as inputs for the next agent run. ##### Returns [Section titled “Returns”](#returns-4) [`AgentInputItem`](/openai-agents-js/openai/agents/type-aliases/agentinputitem/)\[] #### Inherited from [Section titled “Inherited from”](#inherited-from-4) ```ts RunResultBase.history ``` *** ### input [Section titled “input”](#input) #### Get Signature [Section titled “Get Signature”](#get-signature-4) ```ts get input(): | string | AgentInputItem[]; ``` A copy of the original input items. ##### Returns [Section titled “Returns”](#returns-5) \| `string` | [`AgentInputItem`](/openai-agents-js/openai/agents/type-aliases/agentinputitem/)\[] #### Inherited from [Section titled “Inherited from”](#inherited-from-5) ```ts RunResultBase.input ``` *** ### inputGuardrailResults [Section titled “inputGuardrailResults”](#inputguardrailresults) #### Get Signature [Section titled “Get Signature”](#get-signature-5) ```ts get inputGuardrailResults(): InputGuardrailResult[]; ``` Guardrail results for the input messages. ##### Returns [Section titled “Returns”](#returns-6) [`InputGuardrailResult`](/openai-agents-js/openai/agents/interfaces/inputguardrailresult/)\[] #### Inherited from [Section titled “Inherited from”](#inherited-from-6) ```ts RunResultBase.inputGuardrailResults ``` *** ### interruptions [Section titled “interruptions”](#interruptions) #### Get Signature [Section titled “Get Signature”](#get-signature-6) ```ts get interruptions(): RunToolApprovalItem[]; ``` Any interruptions that occurred during the agent run for example for tool approvals. ##### Returns [Section titled “Returns”](#returns-7) [`RunToolApprovalItem`](/openai-agents-js/openai/agents/classes/runtoolapprovalitem/)\[] #### Inherited from [Section titled “Inherited from”](#inherited-from-7) ```ts RunResultBase.interruptions ``` *** ### lastAgent [Section titled “lastAgent”](#lastagent) #### Get Signature [Section titled “Get Signature”](#get-signature-7) ```ts get lastAgent(): TAgent | undefined; ``` The last agent that was run ##### Returns [Section titled “Returns”](#returns-8) `TAgent` | `undefined` #### Inherited from [Section titled “Inherited from”](#inherited-from-8) ```ts RunResultBase.lastAgent ``` *** ### lastResponseId [Section titled “lastResponseId”](#lastresponseid) #### Get Signature [Section titled “Get Signature”](#get-signature-8) ```ts get lastResponseId(): string | undefined; ``` The last response ID generated by the model during the agent run. ##### Returns [Section titled “Returns”](#returns-9) `string` | `undefined` #### Inherited from [Section titled “Inherited from”](#inherited-from-9) ```ts RunResultBase.lastResponseId ``` *** ### newItems [Section titled “newItems”](#newitems) #### Get Signature [Section titled “Get Signature”](#get-signature-9) ```ts get newItems(): RunItem[]; ``` The run items generated during the agent run. This associates the model data with the agents. For the model data that can be used as inputs for the next agent run, use the `output` property. ##### Returns [Section titled “Returns”](#returns-10) [`RunItem`](/openai-agents-js/openai/agents/type-aliases/runitem/)\[] #### Inherited from [Section titled “Inherited from”](#inherited-from-10) ```ts RunResultBase.newItems ``` *** ### output [Section titled “output”](#output) #### Get Signature [Section titled “Get Signature”](#get-signature-10) ```ts get output(): AgentOutputItem[]; ``` The new items generated during the agent run. These include things like new messages, tool calls and their outputs, etc. It does not include information about the agents and instead represents the model data. For the output including the agents, use the `newItems` property. ##### Returns [Section titled “Returns”](#returns-11) [`AgentOutputItem`](/openai-agents-js/openai/agents/type-aliases/agentoutputitem/)\[] #### Inherited from [Section titled “Inherited from”](#inherited-from-11) ```ts RunResultBase.output ``` *** ### outputGuardrailResults [Section titled “outputGuardrailResults”](#outputguardrailresults) #### Get Signature [Section titled “Get Signature”](#get-signature-11) ```ts get outputGuardrailResults(): OutputGuardrailResult[]; ``` Guardrail results for the final output of the agent. ##### Returns [Section titled “Returns”](#returns-12) [`OutputGuardrailResult`](/openai-agents-js/openai/agents/interfaces/outputguardrailresult/)<[`OutputGuardrailMetadata`](/openai-agents-js/openai/agents/interfaces/outputguardrailmetadata/), `"text"`>\[] #### Inherited from [Section titled “Inherited from”](#inherited-from-12) ```ts RunResultBase.outputGuardrailResults ``` *** ### rawResponses [Section titled “rawResponses”](#rawresponses) #### Get Signature [Section titled “Get Signature”](#get-signature-12) ```ts get rawResponses(): ModelResponse[]; ``` The raw LLM responses generated by the model during the agent run. ##### Returns [Section titled “Returns”](#returns-13) [`ModelResponse`](/openai-agents-js/openai/agents/type-aliases/modelresponse/)\[] #### Inherited from [Section titled “Inherited from”](#inherited-from-13) ```ts RunResultBase.rawResponses ``` *** ### runContext [Section titled “runContext”](#runcontext) #### Get Signature [Section titled “Get Signature”](#get-signature-13) ```ts get runContext(): RunContext; ``` The public run context for this run. ##### Returns [Section titled “Returns”](#returns-14) [`RunContext`](/openai-agents-js/openai/agents/classes/runcontext/)<`TContext`> #### Inherited from [Section titled “Inherited from”](#inherited-from-14) ```ts RunResultBase.runContext ``` *** ### toolInputGuardrailResults [Section titled “toolInputGuardrailResults”](#toolinputguardrailresults) #### Get Signature [Section titled “Get Signature”](#get-signature-14) ```ts get toolInputGuardrailResults(): ToolInputGuardrailResult[]; ``` Guardrail results for tool inputs. ##### Returns [Section titled “Returns”](#returns-15) [`ToolInputGuardrailResult`](/openai-agents-js/openai/agents/interfaces/toolinputguardrailresult/)\[] #### Inherited from [Section titled “Inherited from”](#inherited-from-15) ```ts RunResultBase.toolInputGuardrailResults ``` *** ### toolOutputGuardrailResults [Section titled “toolOutputGuardrailResults”](#tooloutputguardrailresults) #### Get Signature [Section titled “Get Signature”](#get-signature-15) ```ts get toolOutputGuardrailResults(): ToolOutputGuardrailResult[]; ``` Guardrail results for tool outputs. ##### Returns [Section titled “Returns”](#returns-16) [`ToolOutputGuardrailResult`](/openai-agents-js/openai/agents/interfaces/tooloutputguardrailresult/)\[] #### Inherited from [Section titled “Inherited from”](#inherited-from-16) ```ts RunResultBase.toolOutputGuardrailResults ``` # RunState Serializable snapshot of an agent’s run, including context, usage and trace. While this class has publicly writable properties (prefixed with `_`), they are not meant to be used directly. To read these properties, use the `RunResult` instead. Manipulation of the state directly can lead to unexpected behavior and should be avoided. Instead, use the `approve` and `reject` methods to interact with the state. ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | ------------------------------------------------------------------------------------------ | | `TContext` | | `TAgent` *extends* [`Agent`](/openai-agents-js/openai/agents/classes/agent/)<`any`, `any`> | ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new RunState( context, originalInput, startingAgent, maxTurns): RunState; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------------- | -------------------------------------------------------------------------------------------------- | | `context` | [`RunContext`](/openai-agents-js/openai/agents/classes/runcontext/)<`TContext`> | | `originalInput` | \| `string` \| [`AgentInputItem`](/openai-agents-js/openai/agents/type-aliases/agentinputitem/)\[] | | `startingAgent` | `TAgent` | | `maxTurns` | `number` \| `null` | #### Returns [Section titled “Returns”](#returns) `RunState`<`TContext`, `TAgent`> ## Properties [Section titled “Properties”](#properties) ### \_agentToolInvocation [Section titled “\_agentToolInvocation”](#_agenttoolinvocation) ```ts _agentToolInvocation: | Readonly<{ toolArguments?: string; toolCallId?: string; toolName: string; }> | undefined; ``` Runtime-only metadata for the current nested agent-tool invocation. *** ### \_context [Section titled “\_context”](#_context) ```ts _context: RunContext; ``` Run context tracking approvals, usage, and other metadata. *** ### \_conversationId [Section titled “\_conversationId”](#_conversationid) ```ts _conversationId: string | undefined; ``` Conversation identifier when the server manages conversation history. *** ### \_currentAgent [Section titled “\_currentAgent”](#_currentagent) ```ts _currentAgent: TAgent; ``` The agent currently handling the conversation. *** ### \_currentAgentSpan [Section titled “\_currentAgentSpan”](#_currentagentspan) ```ts _currentAgentSpan: | Span | undefined; ``` Active tracing span for the current agent if tracing is enabled. *** ### \_currentStep [Section titled “\_currentStep”](#_currentstep) ```ts _currentStep: | { newAgent: any; type: "next_step_handoff"; } | { output: string; type: "next_step_final_output"; } | { type: "next_step_run_again"; } | { data: z.ZodRecord; type: "next_step_interruption"; } | undefined; ``` Next step computed for the agent to take. *** ### \_currentTurn [Section titled “\_currentTurn”](#_currentturn) ```ts _currentTurn: number; ``` Current turn number in the conversation. *** ### \_currentTurnInProgress [Section titled “\_currentTurnInProgress”](#_currentturninprogress) ```ts _currentTurnInProgress: boolean; ``` Whether the current turn has already been counted (useful when resuming mid-turn). *** ### \_currentTurnPersistedItemCount [Section titled “\_currentTurnPersistedItemCount”](#_currentturnpersisteditemcount) ```ts _currentTurnPersistedItemCount: number; ``` Number of `_generatedItems` already flushed to session storage for the current turn. Persisting the entire turn on every save would duplicate responses and tool outputs. Instead, `saveToSession` appends only the delta since the previous write. This counter tracks how many generated run items from *this turn* were already written so the next save can slice off only the new entries. When a turn is interrupted (e.g., awaiting tool approval) and later resumed, we rewind the counter before continuing so the pending tool output still gets stored. *** ### \_finalOutputSource [Section titled “\_finalOutputSource”](#_finaloutputsource) ```ts _finalOutputSource: FinalOutputSource | undefined; ``` Indicates how the final output was produced for the current run. This value is not serialized. *** ### \_generatedItems [Section titled “\_generatedItems”](#_generateditems) ```ts _generatedItems: RunItem[]; ``` Items generated by the agent during the run. *** ### \_inputGuardrailResults [Section titled “\_inputGuardrailResults”](#_inputguardrailresults) ```ts _inputGuardrailResults: InputGuardrailResult[]; ``` Results from input guardrails applied to the run. *** ### \_lastModelSettings [Section titled “\_lastModelSettings”](#_lastmodelsettings) ```ts _lastModelSettings: | ModelSettings | undefined; ``` Effective model settings used for the most recent model call. *** ### \_lastProcessedResponse [Section titled “\_lastProcessedResponse”](#_lastprocessedresponse) ```ts _lastProcessedResponse: ProcessedResponse | undefined; ``` Parsed model response after applying guardrails and tools. *** ### \_lastTurnResponse [Section titled “\_lastTurnResponse”](#_lastturnresponse) ```ts _lastTurnResponse: | ModelResponse | undefined; ``` Last model response for the previous turn. *** ### \_maxTurns [Section titled “\_maxTurns”](#_maxturns) ```ts _maxTurns: number | null; ``` Maximum allowed turns before forcing termination. *** ### \_modelResponses [Section titled “\_modelResponses”](#_modelresponses) ```ts _modelResponses: ModelResponse[]; ``` Responses from the model so far. *** ### \_noActiveAgentRun [Section titled “\_noActiveAgentRun”](#_noactiveagentrun) ```ts _noActiveAgentRun: boolean; ``` Whether the run has an active agent step in progress. *** ### \_originalInput [Section titled “\_originalInput”](#_originalinput) ```ts _originalInput: | string | AgentInputItem[]; ``` Original user input prior to any processing. *** ### \_outputGuardrailResults [Section titled “\_outputGuardrailResults”](#_outputguardrailresults) ```ts _outputGuardrailResults: OutputGuardrailResult[]; ``` Results from output guardrails applied to the run. *** ### \_pendingAgentToolRuns [Section titled “\_pendingAgentToolRuns”](#_pendingagenttoolruns) ```ts _pendingAgentToolRuns: Map; ``` Serialized pending nested agent runs keyed by tool name and call id. *** ### \_previousResponseId [Section titled “\_previousResponseId”](#_previousresponseid) ```ts _previousResponseId: string | undefined; ``` Latest response identifier returned by the server for server-managed conversations. *** ### \_reasoningItemIdPolicy [Section titled “\_reasoningItemIdPolicy”](#_reasoningitemidpolicy) ```ts _reasoningItemIdPolicy: | ReasoningItemIdPolicy | undefined; ``` Runtime options that control how run items are converted into model turn input. This value is serialized so resumed runs keep the same turn-input behavior. *** ### \_sandbox [Section titled “\_sandbox”](#_sandbox) ```ts _sandbox: | { backendId: string; currentAgentKey: string; currentAgentName: string; sessionsByAgent: z.ZodRecord; reuseLiveSession: z.ZodOptional; sessionState: z.ZodObject<{ backendId: z.ZodString; exposedPorts: z.ZodOptional>; manifest: z.ZodRecord; providerState: z.ZodRecord; snapshot: z.ZodOptional>>; snapshotFingerprint: z.ZodOptional>; snapshotFingerprintVersion: z.ZodOptional>; version: z.ZodLiteral<1>; workspaceReady: z.ZodBoolean; }, z.core.$strip>; }, z.core.$strip>>; sessionState: { backendId: string; exposedPorts?: Record; manifest: z.ZodRecord; providerState: z.ZodRecord; snapshot?: Record | null; snapshotFingerprint?: string | null; snapshotFingerprintVersion?: string | null; version: 1; workspaceReady: boolean; }; } | undefined; ``` Persisted sandbox session metadata for sandbox-agent resume. *** ### \_toolInputGuardrailResults [Section titled “\_toolInputGuardrailResults”](#_toolinputguardrailresults) ```ts _toolInputGuardrailResults: ToolInputGuardrailResult[]; ``` Results from tool input guardrails applied during tool execution. *** ### \_toolOutputGuardrailResults [Section titled “\_toolOutputGuardrailResults”](#_tooloutputguardrailresults) ```ts _toolOutputGuardrailResults: ToolOutputGuardrailResult[]; ``` Results from tool output guardrails applied during tool execution. *** ### \_toolSearchRuntimeToolsByAgent [Section titled “\_toolSearchRuntimeToolsByAgent”](#_toolsearchruntimetoolsbyagent) ```ts _toolSearchRuntimeToolsByAgent: Map, ToolSearchRuntimeToolState>; ``` Runtime-only tool\_search-loaded tools, scoped by agent object and preserved across turns for the lifetime of this in-memory run. *** ### \_toolUseTracker [Section titled “\_toolUseTracker”](#_toolusetracker) ```ts _toolUseTracker: AgentToolUseTracker; ``` Tracks what tools each agent has used. *** ### \_trace [Section titled “\_trace”](#_trace) ```ts _trace: Trace | null; ``` Trace associated with this run if tracing is enabled. ## Accessors [Section titled “Accessors”](#accessors) ### currentAgent [Section titled “currentAgent”](#currentagent) #### Get Signature [Section titled “Get Signature”](#get-signature) ```ts get currentAgent(): TAgent; ``` Returns the agent currently handling the run. ##### Returns [Section titled “Returns”](#returns-1) `TAgent` *** ### history [Section titled “history”](#history) #### Get Signature [Section titled “Get Signature”](#get-signature-1) ```ts get history(): AgentInputItem[]; ``` The history of the agent run. This includes the input items and the new items generated during the run. This can be used as inputs for the next agent run. ##### Returns [Section titled “Returns”](#returns-2) [`AgentInputItem`](/openai-agents-js/openai/agents/type-aliases/agentinputitem/)\[] *** ### usage [Section titled “usage”](#usage) #### Get Signature [Section titled “Get Signature”](#get-signature-2) ```ts get usage(): Usage; ``` The usage aggregated for this run. This includes per-request breakdowns when available. ##### Returns [Section titled “Returns”](#returns-3) [`Usage`](/openai-agents-js/openai/agents/classes/usage/) ## Methods [Section titled “Methods”](#methods) ### approve() [Section titled “approve()”](#approve) ```ts approve(approvalItem, options?): void; ``` Approves a tool call requested by the agent through an interruption and approval item request. To approve the request use this method and then run the agent again with the same state object to continue the execution. By default it will only approve the current tool call. To allow the tool to be used multiple times throughout the run, set the `alwaysApprove` option to `true`. #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | Description | | ------------------------ | ------------------------------------------------------------------------------------- | --------------------------------------------------- | | `approvalItem` | [`RunToolApprovalItem`](/openai-agents-js/openai/agents/classes/runtoolapprovalitem/) | The tool call approval item to approve. | | `options?` | { `alwaysApprove?`: `boolean`; } | Options for the approval. | | `options.alwaysApprove?` | `boolean` | Approve this tool for all future calls in this run. | #### Returns [Section titled “Returns”](#returns-4) `void` *** ### clearPendingAgentToolRun() [Section titled “clearPendingAgentToolRun()”](#clearpendingagenttoolrun) ```ts clearPendingAgentToolRun(toolName, callId): void; ``` #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | ---------- | -------- | | `toolName` | `string` | | `callId` | `string` | #### Returns [Section titled “Returns”](#returns-5) `void` *** ### getInterruptions() [Section titled “getInterruptions()”](#getinterruptions) ```ts getInterruptions(): RunToolApprovalItem[]; ``` Returns all interruptions if the current step is an interruption otherwise returns an empty array. #### Returns [Section titled “Returns”](#returns-6) [`RunToolApprovalItem`](/openai-agents-js/openai/agents/classes/runtoolapprovalitem/)\[] *** ### getPendingAgentToolRun() [Section titled “getPendingAgentToolRun()”](#getpendingagenttoolrun) ```ts getPendingAgentToolRun(toolName, callId): string | undefined; ``` #### Parameters [Section titled “Parameters”](#parameters-3) | Parameter | Type | | ---------- | -------- | | `toolName` | `string` | | `callId` | `string` | #### Returns [Section titled “Returns”](#returns-7) `string` | `undefined` *** ### getToolSearchRuntimeTools() [Section titled “getToolSearchRuntimeTools()”](#gettoolsearchruntimetools) ```ts getToolSearchRuntimeTools(agent): Tool[]; ``` #### Parameters [Section titled “Parameters”](#parameters-4) | Parameter | Type | | --------- | ----------------------------------------------------------------------- | | `agent` | [`Agent`](/openai-agents-js/openai/agents/classes/agent/)<`any`, `any`> | #### Returns [Section titled “Returns”](#returns-8) [`Tool`](/openai-agents-js/openai/agents/type-aliases/tool/)<`TContext`>\[] *** ### hasPendingAgentToolRun() [Section titled “hasPendingAgentToolRun()”](#haspendingagenttoolrun) ```ts hasPendingAgentToolRun(toolName, callId): boolean; ``` #### Parameters [Section titled “Parameters”](#parameters-5) | Parameter | Type | | ---------- | -------- | | `toolName` | `string` | | `callId` | `string` | #### Returns [Section titled “Returns”](#returns-9) `boolean` *** ### recordToolSearchRuntimeTools() [Section titled “recordToolSearchRuntimeTools()”](#recordtoolsearchruntimetools) ```ts recordToolSearchRuntimeTools( agent, toolSearchOutput, tools): void; ``` #### Parameters [Section titled “Parameters”](#parameters-6) | Parameter | Type | | -------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `agent` | [`Agent`](/openai-agents-js/openai/agents/classes/agent/)<`any`, `any`> | | `toolSearchOutput` | { `call_id?`: `string` \| `null`; `callId?`: `string` \| `null`; `execution?`: `"client"` \| `"server"`; `id?`: `string`; `providerData?`: `Record`<`string`, `any`>; `status?`: `string`; `tools`: `Record`<`string`, `any`>\[]; `type`: `"tool_search_output"`; } | | `toolSearchOutput.call_id?` | `string` \| `null` | | `toolSearchOutput.callId?` | `string` \| `null` | | `toolSearchOutput.execution?` | `"client"` \| `"server"` | | `toolSearchOutput.id?` | `string` | | `toolSearchOutput.providerData?` | `Record`<`string`, `any`> | | `toolSearchOutput.status?` | `string` | | `toolSearchOutput.tools` | `Record`<`string`, `any`>\[] | | `toolSearchOutput.type` | `"tool_search_output"` | | `tools` | [`Tool`](/openai-agents-js/openai/agents/type-aliases/tool/)<`TContext`>\[] | #### Returns [Section titled “Returns”](#returns-10) `void` *** ### reject() [Section titled “reject()”](#reject) ```ts reject(approvalItem, options?): void; ``` Rejects a tool call requested by the agent through an interruption and approval item request. To reject the request use this method and then run the agent again with the same state object to continue the execution. By default it will only reject the current tool call. To reject the tool for all future calls throughout the run, set the `alwaysReject` option to `true`. When `message` is provided, it is used as the rejection text sent to the model. Otherwise, `toolErrorFormatter` (if configured) or the SDK default is used. #### Parameters [Section titled “Parameters”](#parameters-7) | Parameter | Type | Description | | ----------------------- | ------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------- | | `approvalItem` | [`RunToolApprovalItem`](/openai-agents-js/openai/agents/classes/runtoolapprovalitem/) | The tool call approval item to reject. | | `options?` | { `alwaysReject?`: `boolean`; `message?`: `string`; } | Options for the rejection. | | `options.alwaysReject?` | `boolean` | Reject this tool for all future calls in this run. | | `options.message?` | `string` | The rejection text sent to the model. If not provided, `toolErrorFormatter` (if configured) or the SDK default is used. | #### Returns [Section titled “Returns”](#returns-11) `void` *** ### resetTurnPersistence() [Section titled “resetTurnPersistence()”](#resetturnpersistence) ```ts resetTurnPersistence(): void; ``` Resets the counter that tracks how many items were persisted for the current turn. #### Returns [Section titled “Returns”](#returns-12) `void` *** ### rewindTurnPersistence() [Section titled “rewindTurnPersistence()”](#rewindturnpersistence) ```ts rewindTurnPersistence(count): void; ``` Rewinds the persisted item counter when pending approvals require re-writing outputs. #### Parameters [Section titled “Parameters”](#parameters-8) | Parameter | Type | | --------- | -------- | | `count` | `number` | #### Returns [Section titled “Returns”](#returns-13) `void` *** ### setConversationContext() [Section titled “setConversationContext()”](#setconversationcontext) ```ts setConversationContext(conversationId?, previousResponseId?): void; ``` Updates server-managed conversation identifiers as a single operation. #### Parameters [Section titled “Parameters”](#parameters-9) | Parameter | Type | | --------------------- | -------- | | `conversationId?` | `string` | | `previousResponseId?` | `string` | #### Returns [Section titled “Returns”](#returns-14) `void` *** ### setCurrentAgent() [Section titled “setCurrentAgent()”](#setcurrentagent) ```ts setCurrentAgent(agent): void; ``` Switches the active agent handling the run. #### Parameters [Section titled “Parameters”](#parameters-10) | Parameter | Type | | --------- | -------- | | `agent` | `TAgent` | #### Returns [Section titled “Returns”](#returns-15) `void` *** ### setCurrentAgentSpan() [Section titled “setCurrentAgentSpan()”](#setcurrentagentspan) ```ts setCurrentAgentSpan(span?): void; ``` Updates the agent span associated with the current run. #### Parameters [Section titled “Parameters”](#parameters-11) | Parameter | Type | | --------- | --------------------------------------------------------------------------------------------------------------------------------------- | | `span?` | [`Span`](/openai-agents-js/openai/agents/classes/span/)<[`AgentSpanData`](/openai-agents-js/openai/agents/type-aliases/agentspandata/)> | #### Returns [Section titled “Returns”](#returns-16) `void` *** ### setPendingAgentToolRun() [Section titled “setPendingAgentToolRun()”](#setpendingagenttoolrun) ```ts setPendingAgentToolRun( toolName, callId, serializedState): void; ``` #### Parameters [Section titled “Parameters”](#parameters-12) | Parameter | Type | | ----------------- | -------- | | `toolName` | `string` | | `callId` | `string` | | `serializedState` | `string` | #### Returns [Section titled “Returns”](#returns-17) `void` *** ### setReasoningItemIdPolicy() [Section titled “setReasoningItemIdPolicy()”](#setreasoningitemidpolicy) ```ts setReasoningItemIdPolicy(policy?): void; ``` Updates runtime options for converting run items into turn input. #### Parameters [Section titled “Parameters”](#parameters-13) | Parameter | Type | | --------- | ---------------------------------------------------------------------------------------------- | | `policy?` | [`ReasoningItemIdPolicy`](/openai-agents-js/openai/agents/type-aliases/reasoningitemidpolicy/) | #### Returns [Section titled “Returns”](#returns-18) `void` *** ### toJSON() [Section titled “toJSON()”](#tojson) ```ts toJSON(options?): object; ``` Serializes the run state. By default, tracing API keys are omitted to prevent accidental persistence of secrets. Pass `includeTracingApiKey: true` only when you intentionally need to migrate a run along with its tracing credentials (e.g., to rehydrate in a separate process that lacks the original environment variables). #### Parameters [Section titled “Parameters”](#parameters-14) | Parameter | Type | | ------------------------------- | --------------------------------------- | | `options?` | { `includeTracingApiKey?`: `boolean`; } | | `options.includeTracingApiKey?` | `boolean` | #### Returns [Section titled “Returns”](#returns-19) `object` ##### $schemaVersion [Section titled “$schemaVersion”](#schemaversion) ```ts $schemaVersion: | "1.0" | "1.10" | "1.1" | "1.2" | "1.3" | "1.4" | "1.5" | "1.6" | "1.7" | "1.8" | "1.9" | "1.11"; ``` ##### context [Section titled “context”](#context) ```ts context: object; ``` ###### context.approvals [Section titled “context.approvals”](#contextapprovals) ```ts approvals: z.ZodRecord, z.ZodBoolean]>; messages: z.ZodOptional>; rejected: z.ZodUnion<[z.ZodArray, z.ZodBoolean]>; stickyRejectMessage: z.ZodOptional; }, z.core.$strip>>; ``` ###### context.context [Section titled “context.context”](#contextcontext) ```ts context: z.ZodRecord; ``` ###### context.toolInput? [Section titled “context.toolInput?”](#contexttoolinput) ```ts optional toolInput?: any; ``` ###### context.usage [Section titled “context.usage”](#contextusage) ```ts usage: object; ``` ###### context.usage.inputTokens [Section titled “context.usage.inputTokens”](#contextusageinputtokens) ```ts inputTokens: number; ``` ###### context.usage.inputTokensDetails? [Section titled “context.usage.inputTokensDetails?”](#contextusageinputtokensdetails) ```ts optional inputTokensDetails?: Record[]; ``` ###### context.usage.outputTokens [Section titled “context.usage.outputTokens”](#contextusageoutputtokens) ```ts outputTokens: number; ``` ###### context.usage.outputTokensDetails? [Section titled “context.usage.outputTokensDetails?”](#contextusageoutputtokensdetails) ```ts optional outputTokensDetails?: Record[]; ``` ###### context.usage.requests [Section titled “context.usage.requests”](#contextusagerequests) ```ts requests: number; ``` ###### context.usage.requestUsageEntries? [Section titled “context.usage.requestUsageEntries?”](#contextusagerequestusageentries) ```ts optional requestUsageEntries?: object[]; ``` ###### context.usage.totalTokens [Section titled “context.usage.totalTokens”](#contextusagetotaltokens) ```ts totalTokens: number; ``` ##### conversationId? [Section titled “conversationId?”](#conversationid) ```ts optional conversationId?: string; ``` ##### currentAgent [Section titled “currentAgent”](#currentagent-1) ```ts currentAgent: object; ``` ###### currentAgent.identity? [Section titled “currentAgent.identity?”](#currentagentidentity) ```ts optional identity?: string; ``` ###### currentAgent.name [Section titled “currentAgent.name”](#currentagentname) ```ts name: string; ``` ##### currentAgentSpan? [Section titled “currentAgentSpan?”](#currentagentspan) ```ts optional currentAgentSpan?: SerializedSpanType | null; ``` ##### currentStep? [Section titled “currentStep?”](#currentstep) ```ts optional currentStep?: | { newAgent: any; type: "next_step_handoff"; } | { output: string; type: "next_step_final_output"; } | { type: "next_step_run_again"; } | { data: z.ZodRecord; type: "next_step_interruption"; }; ``` ##### currentTurn [Section titled “currentTurn”](#currentturn) ```ts currentTurn: number; ``` ##### currentTurnInProgress? [Section titled “currentTurnInProgress?”](#currentturninprogress) ```ts optional currentTurnInProgress?: boolean; ``` ##### currentTurnPersistedItemCount? [Section titled “currentTurnPersistedItemCount?”](#currentturnpersisteditemcount) ```ts optional currentTurnPersistedItemCount?: number; ``` ##### generatedItems [Section titled “generatedItems”](#generateditems) ```ts generatedItems: ( | { agent: { identity?: string; name: string; }; rawItem: { content: ( | { providerData?: Record; text: string; type: "output_text"; } | { providerData?: Record; refusal: string; type: "refusal"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; } | { image: string; providerData?: Record; type: "image"; })[]; id?: string; providerData?: Record; role: "assistant"; status: "completed" | "in_progress" | "incomplete"; type?: "message"; }; type: "message_output_item"; } | { agent: { identity?: string; name: string; }; rawItem: { arguments: unknown; call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; type: "tool_search_call"; }; type: "tool_search_call_item"; } | { agent: { identity?: string; name: string; }; rawItem: { call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; tools: Record[]; type: "tool_search_output"; }; type: "tool_search_output_item"; } | { agent: { identity?: string; name: string; }; rawItem: | { action?: | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; }; actions?: ( | { type: "screenshot"; } | { button: ... | ... | ... | ... | ...; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: ...[]; type: "keypress"; } | { path: ...[]; type: "drag"; })[]; callId: string; id?: string; providerData?: Record; status: "completed" | "in_progress" | "incomplete"; type: "computer_call"; } | { action: { commands: string[]; maxOutputLength?: number; timeoutMs?: number; }; callId: string; id?: string; providerData?: Record; status?: "completed" | "in_progress" | "incomplete"; type: "shell_call"; } | { callId: string; id?: string; operation: | { diff: string; path: string; type: "create_file"; } | { diff: string; moveTo?: string; path: string; type: "update_file"; } | { path: string; type: "delete_file"; }; providerData?: Record; status: "completed" | "in_progress"; type: "apply_patch_call"; } | { arguments: string; callId: string; id?: string; name: string; namespace?: string; providerData?: Record; status?: "completed" | "in_progress" | "incomplete"; type: "function_call"; } | { arguments?: string; id?: string; name: string; output?: string; providerData?: Record; status?: string; type: "hosted_tool_call"; } | { arguments?: string; id?: string; name: string; output?: string; providerData?: Record; status?: string; type: "hosted_tool_call"; }; type: "tool_call_item"; } | { agent: { identity?: string; name: string; }; output: string; rawItem: | { callId: string; id?: string; name: string; namespace?: string; output: | string | { providerData?: Record; text: string; type: "text"; } | { detail?: string & object | "low" | "high" | "auto"; image?: | string | { data: ... | ...; mediaType?: ... | ...; } | { url: string; } | { fileId: string; }; providerData?: Record; type: "image"; } | { file: | string | { data: ... | ...; filename: string; mediaType: string; } | { filename?: ... | ...; url: string; } | { filename?: ... | ...; id: string; }; providerData?: Record; type: "file"; } | ( | { providerData?: ... | ...; text: string; type: "input_text"; } | { detail?: ... | ...; image?: ... | ... | ...; providerData?: ... | ...; type: "input_image"; } | { file?: ... | ... | ... | ...; filename?: ... | ...; providerData?: ... | ...; type: "input_file"; })[]; providerData?: Record; status: "completed" | "in_progress" | "incomplete"; type: "function_call_result"; } | { callId: string; id?: string; output: { data: string; providerData?: Record; type: "computer_screenshot"; }; providerData?: Record; type: "computer_call_result"; } | { callId: string; id?: string; maxOutputLength?: number; output: object[]; providerData?: Record; type: "shell_call_output"; } | { callId: string; id?: string; output?: string; providerData?: Record; status: "completed" | "failed"; type: "apply_patch_call_output"; }; type: "tool_call_output_item"; } | { agent: { identity?: string; name: string; }; rawItem: { content: object[]; id?: string; providerData?: Record; rawContent?: object[]; type: "reasoning"; }; type: "reasoning_item"; } | { agent: { identity?: string; name: string; }; rawItem: { arguments: string; callId: string; id?: string; name: string; namespace?: string; providerData?: Record; status?: "completed" | "in_progress" | "incomplete"; type: "function_call"; }; type: "handoff_call_item"; } | { rawItem: { callId: string; id?: string; name: string; namespace?: string; output: | string | { providerData?: Record; text: string; type: "text"; } | { detail?: string & object | "low" | "high" | "auto"; image?: | string | { data: string | Uint8Array<...>; mediaType?: string; } | { url: string; } | { fileId: string; }; providerData?: Record; type: "image"; } | { file: | string | { data: string | Uint8Array<...>; filename: string; mediaType: string; } | { filename?: string; url: string; } | { filename?: string; id: string; }; providerData?: Record; type: "file"; } | ( | { providerData?: Record<..., ...>; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: ...; }; providerData?: Record<..., ...>; type: "input_image"; } | { file?: | string | { id: ...; } | { url: ...; }; filename?: string; providerData?: Record<..., ...>; type: "input_file"; })[]; providerData?: Record; status: "completed" | "in_progress" | "incomplete"; type: "function_call_result"; }; sourceAgent: { identity?: string; name: string; }; targetAgent: { identity?: string; name: string; }; type: "handoff_output_item"; } | { agent: { identity?: string; name: string; }; rawItem: | { arguments: string; callId: string; id?: string; name: string; namespace?: string; providerData?: Record; status?: "completed" | "in_progress" | "incomplete"; type: "function_call"; } | { arguments?: string; id?: string; name: string; output?: string; providerData?: Record; status?: string; type: "hosted_tool_call"; } | { action?: | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; }; actions?: ( | { type: "screenshot"; } | { button: ... | ... | ... | ... | ...; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: ...[]; type: "keypress"; } | { path: ...[]; type: "drag"; })[]; callId: string; id?: string; providerData?: Record; status: "completed" | "in_progress" | "incomplete"; type: "computer_call"; } | { action: { commands: string[]; maxOutputLength?: number; timeoutMs?: number; }; callId: string; id?: string; providerData?: Record; status?: "completed" | "in_progress" | "incomplete"; type: "shell_call"; } | { callId: string; id?: string; operation: | { diff: string; path: string; type: "create_file"; } | { diff: string; moveTo?: string; path: string; type: "update_file"; } | { path: string; type: "delete_file"; }; providerData?: Record; status: "completed" | "in_progress"; type: "apply_patch_call"; }; toolName?: string; type: "tool_approval_item"; })[]; ``` ##### inputGuardrailResults [Section titled “inputGuardrailResults”](#inputguardrailresults) ```ts inputGuardrailResults: object[]; ``` ##### lastModelResponse? [Section titled “lastModelResponse?”](#lastmodelresponse) ```ts optional lastModelResponse?: object; ``` ###### lastModelResponse.output [Section titled “lastModelResponse.output”](#lastmodelresponseoutput) ```ts output: ( | { content: ( | { providerData?: Record<..., ...>; text: string; type: "output_text"; } | { providerData?: Record<..., ...>; refusal: string; type: "refusal"; } | { audio: | string | { id: ...; }; format?: string | null; providerData?: Record<..., ...>; transcript?: string | null; type: "audio"; } | { image: string; providerData?: Record<..., ...>; type: "image"; })[]; id?: string; providerData?: Record; role: "assistant"; status: "completed" | "in_progress" | "incomplete"; type?: "message"; } | { arguments: unknown; call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; type: "tool_search_call"; } | { call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; tools: Record[]; type: "tool_search_output"; } | { arguments?: string; id?: string; name: string; output?: string; providerData?: Record; status?: string; type: "hosted_tool_call"; } | { arguments: string; callId: string; id?: string; name: string; namespace?: string; providerData?: Record; status?: "completed" | "in_progress" | "incomplete"; type: "function_call"; } | { action?: | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; }; actions?: ( | { type: "screenshot"; } | { button: ... | ... | ... | ... | ...; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: ...[]; type: "keypress"; } | { path: ...[]; type: "drag"; })[]; callId: string; id?: string; providerData?: Record; status: "completed" | "in_progress" | "incomplete"; type: "computer_call"; } | { action: { commands: string[]; maxOutputLength?: number; timeoutMs?: number; }; callId: string; id?: string; providerData?: Record; status?: "completed" | "in_progress" | "incomplete"; type: "shell_call"; } | { callId: string; id?: string; operation: | { diff: string; path: string; type: "create_file"; } | { diff: string; moveTo?: string; path: string; type: "update_file"; } | { path: string; type: "delete_file"; }; providerData?: Record; status: "completed" | "in_progress"; type: "apply_patch_call"; } | { callId: string; id?: string; name: string; namespace?: string; output: | string | { providerData?: Record; text: string; type: "text"; } | { detail?: string & object | "low" | "high" | "auto"; image?: | string | { data: ... | ...; mediaType?: ... | ...; } | { url: string; } | { fileId: string; }; providerData?: Record; type: "image"; } | { file: | string | { data: ... | ...; filename: string; mediaType: string; } | { filename?: ... | ...; url: string; } | { filename?: ... | ...; id: string; }; providerData?: Record; type: "file"; } | ( | { providerData?: ... | ...; text: string; type: "input_text"; } | { detail?: ... | ...; image?: ... | ... | ...; providerData?: ... | ...; type: "input_image"; } | { file?: ... | ... | ... | ...; filename?: ... | ...; providerData?: ... | ...; type: "input_file"; })[]; providerData?: Record; status: "completed" | "in_progress" | "incomplete"; type: "function_call_result"; } | { callId: string; id?: string; maxOutputLength?: number; output: object[]; providerData?: Record; type: "shell_call_output"; } | { callId: string; id?: string; output?: string; providerData?: Record; status: "completed" | "failed"; type: "apply_patch_call_output"; } | { content: object[]; id?: string; providerData?: Record; rawContent?: object[]; type: "reasoning"; } | { created_by?: string; encrypted_content: string; id?: string; providerData?: Record; type: "compaction"; } | { id?: string; providerData?: Record; type: "unknown"; })[]; ``` ###### lastModelResponse.providerData? [Section titled “lastModelResponse.providerData?”](#lastmodelresponseproviderdata) ```ts optional providerData?: Record; ``` ###### lastModelResponse.requestId? [Section titled “lastModelResponse.requestId?”](#lastmodelresponserequestid) ```ts optional requestId?: string; ``` ###### lastModelResponse.responseId? [Section titled “lastModelResponse.responseId?”](#lastmodelresponseresponseid) ```ts optional responseId?: string; ``` ###### lastModelResponse.usage [Section titled “lastModelResponse.usage”](#lastmodelresponseusage) ```ts usage: object; ``` ###### lastModelResponse.usage.inputTokens [Section titled “lastModelResponse.usage.inputTokens”](#lastmodelresponseusageinputtokens) ```ts inputTokens: number; ``` ###### lastModelResponse.usage.inputTokensDetails? [Section titled “lastModelResponse.usage.inputTokensDetails?”](#lastmodelresponseusageinputtokensdetails) ```ts optional inputTokensDetails?: Record[]; ``` ###### lastModelResponse.usage.outputTokens [Section titled “lastModelResponse.usage.outputTokens”](#lastmodelresponseusageoutputtokens) ```ts outputTokens: number; ``` ###### lastModelResponse.usage.outputTokensDetails? [Section titled “lastModelResponse.usage.outputTokensDetails?”](#lastmodelresponseusageoutputtokensdetails) ```ts optional outputTokensDetails?: Record[]; ``` ###### lastModelResponse.usage.requests [Section titled “lastModelResponse.usage.requests”](#lastmodelresponseusagerequests) ```ts requests: number; ``` ###### lastModelResponse.usage.requestUsageEntries? [Section titled “lastModelResponse.usage.requestUsageEntries?”](#lastmodelresponseusagerequestusageentries) ```ts optional requestUsageEntries?: object[]; ``` ###### lastModelResponse.usage.totalTokens [Section titled “lastModelResponse.usage.totalTokens”](#lastmodelresponseusagetotaltokens) ```ts totalTokens: number; ``` ##### lastProcessedResponse? [Section titled “lastProcessedResponse?”](#lastprocessedresponse) ```ts optional lastProcessedResponse?: object; ``` ###### lastProcessedResponse.applyPatchActions? [Section titled “lastProcessedResponse.applyPatchActions?”](#lastprocessedresponseapplypatchactions) ```ts optional applyPatchActions?: object[]; ``` ###### lastProcessedResponse.computerActions [Section titled “lastProcessedResponse.computerActions”](#lastprocessedresponsecomputeractions) ```ts computerActions: object[]; ``` ###### lastProcessedResponse.functions [Section titled “lastProcessedResponse.functions”](#lastprocessedresponsefunctions) ```ts functions: object[]; ``` ###### lastProcessedResponse.handoffs [Section titled “lastProcessedResponse.handoffs”](#lastprocessedresponsehandoffs) ```ts handoffs: object[]; ``` ###### lastProcessedResponse.mcpApprovalRequests? [Section titled “lastProcessedResponse.mcpApprovalRequests?”](#lastprocessedresponsemcpapprovalrequests) ```ts optional mcpApprovalRequests?: object[]; ``` ###### lastProcessedResponse.newItems [Section titled “lastProcessedResponse.newItems”](#lastprocessedresponsenewitems) ```ts newItems: ( | { agent: { identity?: string; name: string; }; rawItem: { content: ( | { providerData?: ... | ...; text: string; type: "output_text"; } | { providerData?: ... | ...; refusal: string; type: "refusal"; } | { audio: ... | ...; format?: ... | ... | ...; providerData?: ... | ...; transcript?: ... | ... | ...; type: "audio"; } | { image: string; providerData?: ... | ...; type: "image"; })[]; id?: string; providerData?: Record; role: "assistant"; status: "completed" | "in_progress" | "incomplete"; type?: "message"; }; type: "message_output_item"; } | { agent: { identity?: string; name: string; }; rawItem: { arguments: unknown; call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; type: "tool_search_call"; }; type: "tool_search_call_item"; } | { agent: { identity?: string; name: string; }; rawItem: { call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; tools: Record[]; type: "tool_search_output"; }; type: "tool_search_output_item"; } | { agent: { identity?: string; name: string; }; rawItem: | { action?: | { type: "screenshot"; } | { button: ... | ... | ... | ... | ...; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: ...[]; type: "keypress"; } | { path: ...[]; type: "drag"; }; actions?: (... | ... | ... | ... | ... | ... | ... | ... | ...)[]; callId: string; id?: string; providerData?: Record; status: "completed" | "in_progress" | "incomplete"; type: "computer_call"; } | { action: { commands: string[]; maxOutputLength?: number; timeoutMs?: number; }; callId: string; id?: string; providerData?: Record; status?: "completed" | "in_progress" | "incomplete"; type: "shell_call"; } | { callId: string; id?: string; operation: | { diff: string; path: string; type: "create_file"; } | { diff: string; moveTo?: ... | ...; path: string; type: "update_file"; } | { path: string; type: "delete_file"; }; providerData?: Record; status: "completed" | "in_progress"; type: "apply_patch_call"; } | { arguments: string; callId: string; id?: string; name: string; namespace?: string; providerData?: Record; status?: "completed" | "in_progress" | "incomplete"; type: "function_call"; } | { arguments?: string; id?: string; name: string; output?: string; providerData?: Record; status?: string; type: "hosted_tool_call"; } | { arguments?: string; id?: string; name: string; output?: string; providerData?: Record; status?: string; type: "hosted_tool_call"; }; type: "tool_call_item"; } | { agent: { identity?: string; name: string; }; output: string; rawItem: | { callId: string; id?: string; name: string; namespace?: string; output: | string | { providerData?: ... | ...; text: string; type: "text"; } | { detail?: ... | ... | ... | ... | ...; image?: ... | ... | ... | ... | ...; providerData?: ... | ...; type: "image"; } | { file: ... | ... | ... | ...; providerData?: ... | ...; type: "file"; } | (... | ... | ...)[]; providerData?: Record; status: "completed" | "in_progress" | "incomplete"; type: "function_call_result"; } | { callId: string; id?: string; output: { data: string; providerData?: Record<..., ...>; type: "computer_screenshot"; }; providerData?: Record; type: "computer_call_result"; } | { callId: string; id?: string; maxOutputLength?: number; output: object[]; providerData?: Record; type: "shell_call_output"; } | { callId: string; id?: string; output?: string; providerData?: Record; status: "completed" | "failed"; type: "apply_patch_call_output"; }; type: "tool_call_output_item"; } | { agent: { identity?: string; name: string; }; rawItem: { content: object[]; id?: string; providerData?: Record; rawContent?: object[]; type: "reasoning"; }; type: "reasoning_item"; } | { agent: { identity?: string; name: string; }; rawItem: { arguments: string; callId: string; id?: string; name: string; namespace?: string; providerData?: Record; status?: "completed" | "in_progress" | "incomplete"; type: "function_call"; }; type: "handoff_call_item"; } | { rawItem: { callId: string; id?: string; name: string; namespace?: string; output: | string | { providerData?: Record<..., ...>; text: string; type: "text"; } | { detail?: ... & ... | "low" | "high" | "auto"; image?: | string | { data: ...; mediaType?: ...; } | { url: ...; } | { fileId: ...; }; providerData?: Record<..., ...>; type: "image"; } | { file: | string | { data: ...; filename: ...; mediaType: ...; } | { filename?: ...; url: ...; } | { filename?: ...; id: ...; }; providerData?: Record<..., ...>; type: "file"; } | ( | { providerData?: ...; text: ...; type: ...; } | { detail?: ...; image?: ...; providerData?: ...; type: ...; } | { file?: ...; filename?: ...; providerData?: ...; type: ...; })[]; providerData?: Record; status: "completed" | "in_progress" | "incomplete"; type: "function_call_result"; }; sourceAgent: { identity?: string; name: string; }; targetAgent: { identity?: string; name: string; }; type: "handoff_output_item"; } | { agent: { identity?: string; name: string; }; rawItem: | { arguments: string; callId: string; id?: string; name: string; namespace?: string; providerData?: Record; status?: "completed" | "in_progress" | "incomplete"; type: "function_call"; } | { arguments?: string; id?: string; name: string; output?: string; providerData?: Record; status?: string; type: "hosted_tool_call"; } | { action?: | { type: "screenshot"; } | { button: ... | ... | ... | ... | ...; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: ...[]; type: "keypress"; } | { path: ...[]; type: "drag"; }; actions?: (... | ... | ... | ... | ... | ... | ... | ... | ...)[]; callId: string; id?: string; providerData?: Record; status: "completed" | "in_progress" | "incomplete"; type: "computer_call"; } | { action: { commands: string[]; maxOutputLength?: number; timeoutMs?: number; }; callId: string; id?: string; providerData?: Record; status?: "completed" | "in_progress" | "incomplete"; type: "shell_call"; } | { callId: string; id?: string; operation: | { diff: string; path: string; type: "create_file"; } | { diff: string; moveTo?: ... | ...; path: string; type: "update_file"; } | { path: string; type: "delete_file"; }; providerData?: Record; status: "completed" | "in_progress"; type: "apply_patch_call"; }; toolName?: string; type: "tool_approval_item"; })[]; ``` ###### lastProcessedResponse.shellActions? [Section titled “lastProcessedResponse.shellActions?”](#lastprocessedresponseshellactions) ```ts optional shellActions?: object[]; ``` ###### lastProcessedResponse.toolsUsed [Section titled “lastProcessedResponse.toolsUsed”](#lastprocessedresponsetoolsused) ```ts toolsUsed: string[]; ``` ##### maxTurns [Section titled “maxTurns”](#maxturns) ```ts maxTurns: number | null; ``` ##### modelResponses [Section titled “modelResponses”](#modelresponses) ```ts modelResponses: object[]; ``` ##### noActiveAgentRun [Section titled “noActiveAgentRun”](#noactiveagentrun) ```ts noActiveAgentRun: boolean; ``` ##### originalInput [Section titled “originalInput”](#originalinput) ```ts originalInput: | string | ( | { content: | string | ( | { providerData?: Record<..., ...>; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: ...; }; providerData?: Record<..., ...>; type: "input_image"; } | { file?: | string | { id: ...; } | { url: ...; }; filename?: string; providerData?: Record<..., ...>; type: "input_file"; } | { audio: | string | { id: ...; }; format?: string | null; providerData?: Record<..., ...>; transcript?: string | null; type: "audio"; })[]; id?: string; providerData?: Record; role: "user"; type?: "message"; } | { content: ( | { providerData?: Record; text: string; type: "output_text"; } | { providerData?: Record; refusal: string; type: "refusal"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; } | { image: string; providerData?: Record; type: "image"; })[]; id?: string; providerData?: Record; role: "assistant"; status: "completed" | "in_progress" | "incomplete"; type?: "message"; } | { content: string; id?: string; providerData?: Record; role: "system"; type?: "message"; } | { arguments: unknown; call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; type: "tool_search_call"; } | { call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; tools: Record[]; type: "tool_search_output"; } | { arguments?: string; id?: string; name: string; output?: string; providerData?: Record; status?: string; type: "hosted_tool_call"; } | { arguments: string; callId: string; id?: string; name: string; namespace?: string; providerData?: Record; status?: "completed" | "in_progress" | "incomplete"; type: "function_call"; } | { action?: | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; }; actions?: ( | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; })[]; callId: string; id?: string; providerData?: Record; status: "completed" | "in_progress" | "incomplete"; type: "computer_call"; } | { action: { commands: string[]; maxOutputLength?: number; timeoutMs?: number; }; callId: string; id?: string; providerData?: Record; status?: "completed" | "in_progress" | "incomplete"; type: "shell_call"; } | { callId: string; id?: string; operation: | { diff: string; path: string; type: "create_file"; } | { diff: string; moveTo?: string; path: string; type: "update_file"; } | { path: string; type: "delete_file"; }; providerData?: Record; status: "completed" | "in_progress"; type: "apply_patch_call"; } | { callId: string; id?: string; name: string; namespace?: string; output: | string | { providerData?: Record; text: string; type: "text"; } | { detail?: string & object | "low" | "high" | "auto"; image?: | string | { data: string | Uint8Array<...>; mediaType?: string; } | { url: string; } | { fileId: string; }; providerData?: Record; type: "image"; } | { file: | string | { data: string | Uint8Array<...>; filename: string; mediaType: string; } | { filename?: string; url: string; } | { filename?: string; id: string; }; providerData?: Record; type: "file"; } | ( | { providerData?: Record<..., ...>; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: ...; }; providerData?: Record<..., ...>; type: "input_image"; } | { file?: | string | { id: ...; } | { url: ...; }; filename?: string; providerData?: Record<..., ...>; type: "input_file"; })[]; providerData?: Record; status: "completed" | "in_progress" | "incomplete"; type: "function_call_result"; } | { callId: string; id?: string; output: { data: string; providerData?: Record; type: "computer_screenshot"; }; providerData?: Record; type: "computer_call_result"; } | { callId: string; id?: string; maxOutputLength?: number; output: object[]; providerData?: Record; type: "shell_call_output"; } | { callId: string; id?: string; output?: string; providerData?: Record; status: "completed" | "failed"; type: "apply_patch_call_output"; } | { content: object[]; id?: string; providerData?: Record; rawContent?: object[]; type: "reasoning"; } | { created_by?: string; encrypted_content: string; id?: string; providerData?: Record; type: "compaction"; } | { id?: string; providerData?: Record; type: "unknown"; })[]; ``` ##### outputGuardrailResults [Section titled “outputGuardrailResults”](#outputguardrailresults) ```ts outputGuardrailResults: object[]; ``` ##### pendingAgentToolRuns [Section titled “pendingAgentToolRuns”](#pendingagenttoolruns) ```ts pendingAgentToolRuns: z.ZodDefault>>; ``` ##### previousResponseId? [Section titled “previousResponseId?”](#previousresponseid) ```ts optional previousResponseId?: string; ``` ##### reasoningItemIdPolicy? [Section titled “reasoningItemIdPolicy?”](#reasoningitemidpolicy) ```ts optional reasoningItemIdPolicy?: "preserve" | "omit"; ``` ##### sandbox? [Section titled “sandbox?”](#sandbox) ```ts optional sandbox?: object; ``` ###### sandbox.backendId [Section titled “sandbox.backendId”](#sandboxbackendid) ```ts backendId: string; ``` ###### sandbox.currentAgentKey [Section titled “sandbox.currentAgentKey”](#sandboxcurrentagentkey) ```ts currentAgentKey: string; ``` ###### sandbox.currentAgentName [Section titled “sandbox.currentAgentName”](#sandboxcurrentagentname) ```ts currentAgentName: string; ``` ###### sandbox.sessionsByAgent [Section titled “sandbox.sessionsByAgent”](#sandboxsessionsbyagent) ```ts sessionsByAgent: z.ZodRecord; reuseLiveSession: z.ZodOptional; sessionState: z.ZodObject<{ backendId: z.ZodString; exposedPorts: z.ZodOptional>; manifest: z.ZodRecord; providerState: z.ZodRecord; snapshot: z.ZodOptional>>; snapshotFingerprint: z.ZodOptional>; snapshotFingerprintVersion: z.ZodOptional>; version: z.ZodLiteral<1>; workspaceReady: z.ZodBoolean; }, z.core.$strip>; }, z.core.$strip>>; ``` ###### sandbox.sessionState [Section titled “sandbox.sessionState”](#sandboxsessionstate) ```ts sessionState: object; ``` ###### sandbox.sessionState.backendId [Section titled “sandbox.sessionState.backendId”](#sandboxsessionstatebackendid) ```ts backendId: string; ``` ###### sandbox.sessionState.exposedPorts? [Section titled “sandbox.sessionState.exposedPorts?”](#sandboxsessionstateexposedports) ```ts optional exposedPorts?: Record; ``` ###### sandbox.sessionState.manifest [Section titled “sandbox.sessionState.manifest”](#sandboxsessionstatemanifest) ```ts manifest: z.ZodRecord; ``` ###### sandbox.sessionState.providerState [Section titled “sandbox.sessionState.providerState”](#sandboxsessionstateproviderstate) ```ts providerState: z.ZodRecord; ``` ###### sandbox.sessionState.snapshot? [Section titled “sandbox.sessionState.snapshot?”](#sandboxsessionstatesnapshot) ```ts optional snapshot?: Record | null; ``` ###### sandbox.sessionState.snapshotFingerprint? [Section titled “sandbox.sessionState.snapshotFingerprint?”](#sandboxsessionstatesnapshotfingerprint) ```ts optional snapshotFingerprint?: string | null; ``` ###### sandbox.sessionState.snapshotFingerprintVersion? [Section titled “sandbox.sessionState.snapshotFingerprintVersion?”](#sandboxsessionstatesnapshotfingerprintversion) ```ts optional snapshotFingerprintVersion?: string | null; ``` ###### sandbox.sessionState.version [Section titled “sandbox.sessionState.version”](#sandboxsessionstateversion) ```ts version: 1; ``` ###### sandbox.sessionState.workspaceReady [Section titled “sandbox.sessionState.workspaceReady”](#sandboxsessionstateworkspaceready) ```ts workspaceReady: boolean; ``` ##### toolInputGuardrailResults [Section titled “toolInputGuardrailResults”](#toolinputguardrailresults) ```ts toolInputGuardrailResults: object[]; ``` ##### toolOutputGuardrailResults [Section titled “toolOutputGuardrailResults”](#tooloutputguardrailresults) ```ts toolOutputGuardrailResults: object[]; ``` ##### toolUseTracker [Section titled “toolUseTracker”](#toolusetracker) ```ts toolUseTracker: z.ZodRecord>; ``` ##### trace [Section titled “trace”](#trace) ```ts trace: | { group_id: string | null; id: string; metadata: z.ZodRecord; object: "trace"; tracing_api_key?: string | null; workflow_name: string; } | null; ``` *** ### toString() [Section titled “toString()”](#tostring) ```ts toString(options?): string; ``` Serializes the run state to a string. This method is used to serialize the run state to a string that can be used to resume the run later. #### Parameters [Section titled “Parameters”](#parameters-15) | Parameter | Type | | ------------------------------- | --------------------------------------- | | `options?` | { `includeTracingApiKey?`: `boolean`; } | | `options.includeTracingApiKey?` | `boolean` | #### Returns [Section titled “Returns”](#returns-20) `string` The serialized run state. *** ### fromString() [Section titled “fromString()”](#fromstring) ```ts static fromString(initialAgent, str): Promise>; ``` Deserializes a run state from a string. This method is used to deserialize a run state from a string that was serialized using the `toString` method. #### Type Parameters [Section titled “Type Parameters”](#type-parameters-1) | Type Parameter | | ------------------------------------------------------------------------------------------ | | `TContext` | | `TAgent` *extends* [`Agent`](/openai-agents-js/openai/agents/classes/agent/)<`any`, `any`> | #### Parameters [Section titled “Parameters”](#parameters-16) | Parameter | Type | | -------------- | -------- | | `initialAgent` | `TAgent` | | `str` | `string` | #### Returns [Section titled “Returns”](#returns-21) `Promise`<`RunState`<`TContext`, `TAgent`>> *** ### fromStringWithContext() [Section titled “fromStringWithContext()”](#fromstringwithcontext) ```ts static fromStringWithContext( initialAgent, str, context, options?): Promise>; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-2) | Type Parameter | | ------------------------------------------------------------------------------------------ | | `TContext` | | `TAgent` *extends* [`Agent`](/openai-agents-js/openai/agents/classes/agent/)<`any`, `any`> | #### Parameters [Section titled “Parameters”](#parameters-17) | Parameter | Type | | -------------------------- | ------------------------------------------------------------------------------- | | `initialAgent` | `TAgent` | | `str` | `string` | | `context` | [`RunContext`](/openai-agents-js/openai/agents/classes/runcontext/)<`TContext`> | | `options?` | { `contextStrategy?`: `ContextOverrideStrategy`; } | | `options.contextStrategy?` | `ContextOverrideStrategy` | #### Returns [Section titled “Returns”](#returns-22) `Promise`<`RunState`<`TContext`, `TAgent`>> # RunToolApprovalItem ## Extends [Section titled “Extends”](#extends) * `RunItemBase` ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new RunToolApprovalItem( rawItem, agent, toolName?): RunToolApprovalItem; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------- | | `rawItem` | \| { `arguments?`: `string`; `id?`: `string`; `name`: `string`; `output?`: `string`; `providerData?`: `Record`<`string`, `any`>; `status?`: `string`; `type`: `"hosted_tool_call"`; } \| { `arguments`: `string`; `callId`: `string`; `id?`: `string`; `name`: `string`; `namespace?`: `string`; `providerData?`: `Record`<`string`, `any`>; `status?`: `"completed"` \| `"in_progress"` \| `"incomplete"`; `type`: `"function_call"`; } \| { `action?`: \| { `type`: `"screenshot"`; } \| { `button`: `"left"` \| `"right"` \| `"wheel"` \| `"back"` \| `"forward"`; `type`: `"click"`; `x`: `number`; `y`: `number`; } \| { `type`: `"double_click"`; `x`: `number`; `y`: `number`; } \| { `scroll_x`: `number`; `scroll_y`: `number`; `type`: `"scroll"`; `x`: `number`; `y`: `number`; } \| { `text`: `string`; `type`: `"type"`; } \| { `type`: `"wait"`; } \| { `type`: `"move"`; `x`: `number`; `y`: `number`; } \| { `keys`: `string`\[]; `type`: `"keypress"`; } \| { `path`: `object`\[]; `type`: `"drag"`; }; `actions?`: ( \| { `type`: `"screenshot"`; } \| { `button`: `"left"` \| `"right"` \| `"wheel"` \| `"back"` \| `"forward"`; `type`: `"click"`; `x`: `number`; `y`: `number`; } \| { `type`: `"double_click"`; `x`: `number`; `y`: `number`; } \| { `scroll_x`: `number`; `scroll_y`: `number`; `type`: `"scroll"`; `x`: `number`; `y`: `number`; } \| { `text`: `string`; `type`: `"type"`; } \| { `type`: `"wait"`; } \| { `type`: `"move"`; `x`: `number`; `y`: `number`; } \| { `keys`: `string`\[]; `type`: `"keypress"`; } \| { `path`: `object`\[]; `type`: `"drag"`; })\[]; `callId`: `string`; `id?`: `string`; `providerData?`: `Record`<`string`, `any`>; `status`: `"completed"` \| `"in_progress"` \| `"incomplete"`; `type`: `"computer_call"`; } \| { `action`: { `commands`: `string`\[]; `maxOutputLength?`: `number`; `timeoutMs?`: `number`; }; `callId`: `string`; `id?`: `string`; `providerData?`: `Record`<`string`, `any`>; `status?`: `"completed"` \| `"in_progress"` \| `"incomplete"`; `type`: `"shell_call"`; } \| { `callId`: `string`; `id?`: `string`; `operation`: \| { `diff`: `string`; `path`: `string`; `type`: `"create_file"`; } \| { `diff`: `string`; `moveTo?`: `string`; `path`: `string`; `type`: `"update_file"`; } \| { `path`: `string`; `type`: `"delete_file"`; }; `providerData?`: `Record`<`string`, `any`>; `status`: `"completed"` \| `"in_progress"`; `type`: `"apply_patch_call"`; } | ‐ | | `agent` | [`Agent`](/openai-agents-js/openai/agents/classes/agent/)<`any`, `any`> | ‐ | | `toolName?` | `string` | Explicit tool name to use for approval tracking when not present on the raw item. | #### Returns [Section titled “Returns”](#returns) `RunToolApprovalItem` #### Overrides [Section titled “Overrides”](#overrides) ```ts RunItemBase.constructor ``` ## Properties [Section titled “Properties”](#properties) ### agent [Section titled “agent”](#agent) ```ts agent: Agent; ``` *** ### rawItem [Section titled “rawItem”](#rawitem) ```ts rawItem: | { arguments?: string; id?: string; name: string; output?: string; providerData?: Record; status?: string; type: "hosted_tool_call"; } | { arguments: string; callId: string; id?: string; name: string; namespace?: string; providerData?: Record; status?: "completed" | "in_progress" | "incomplete"; type: "function_call"; } | { action?: | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; }; actions?: ( | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; })[]; callId: string; id?: string; providerData?: Record; status: "completed" | "in_progress" | "incomplete"; type: "computer_call"; } | { action: { commands: string[]; maxOutputLength?: number; timeoutMs?: number; }; callId: string; id?: string; providerData?: Record; status?: "completed" | "in_progress" | "incomplete"; type: "shell_call"; } | { callId: string; id?: string; operation: | { diff: string; path: string; type: "create_file"; } | { diff: string; moveTo?: string; path: string; type: "update_file"; } | { path: string; type: "delete_file"; }; providerData?: Record; status: "completed" | "in_progress"; type: "apply_patch_call"; }; ``` #### Overrides [Section titled “Overrides”](#overrides-1) ```ts RunItemBase.rawItem ``` *** ### toolName? [Section titled “toolName?”](#toolname) ```ts optional toolName?: string; ``` Explicit tool name to use for approval tracking when not present on the raw item. *** ### type [Section titled “type”](#type) ```ts readonly type: "tool_approval_item"; ``` #### Overrides [Section titled “Overrides”](#overrides-2) ```ts RunItemBase.type ``` ## Accessors [Section titled “Accessors”](#accessors) ### arguments [Section titled “arguments”](#arguments) #### Get Signature [Section titled “Get Signature”](#get-signature) ```ts get arguments(): string | undefined; ``` Returns the arguments if the raw item has an arguments property otherwise this will be undefined. ##### Returns [Section titled “Returns”](#returns-1) `string` | `undefined` *** ### name [Section titled “name”](#name) #### Get Signature [Section titled “Get Signature”](#get-signature-1) ```ts get name(): string | undefined; ``` Returns the tool name if available on the raw item or provided explicitly. Kept for backwards compatibility with code that previously relied on `rawItem.name`. ##### Returns [Section titled “Returns”](#returns-2) `string` | `undefined` ## Methods [Section titled “Methods”](#methods) ### toJSON() [Section titled “toJSON()”](#tojson) ```ts toJSON(): object; ``` #### Returns [Section titled “Returns”](#returns-3) `object` ##### agent [Section titled “agent”](#agent-1) ```ts agent: object; ``` ###### agent.name [Section titled “agent.name”](#agentname) ```ts name: string; ``` ##### rawItem [Section titled “rawItem”](#rawitem-1) ```ts rawItem: | { content: ( | { providerData?: Record; refusal: string; type: "refusal"; } | { providerData?: Record; text: string; type: "output_text"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; } | { image: string; providerData?: Record; type: "image"; })[]; id?: string; providerData?: Record; role: "assistant"; status: "completed" | "in_progress" | "incomplete"; type?: "message"; } | { content: | string | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; })[]; id?: string; providerData?: Record; role: "user"; type?: "message"; } | { content: string; id?: string; providerData?: Record; role: "system"; type?: "message"; } | { arguments?: string; id?: string; name: string; output?: string; providerData?: Record; status?: string; type: "hosted_tool_call"; } | { arguments: string; callId: string; id?: string; name: string; namespace?: string; providerData?: Record; status?: "completed" | "in_progress" | "incomplete"; type: "function_call"; } | { arguments: unknown; call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; type: "tool_search_call"; } | { call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; tools: Record[]; type: "tool_search_output"; } | { callId: string; id?: string; name: string; namespace?: string; output: | string | { providerData?: Record; text: string; type: "text"; } | { detail?: string & object | "low" | "high" | "auto"; image?: | string | { data: string | Uint8Array; mediaType?: string; } | { url: string; } | { fileId: string; }; providerData?: Record; type: "image"; } | { file: | string | { data: string | Uint8Array; filename: string; mediaType: string; } | { filename?: string; url: string; } | { filename?: string; id: string; }; providerData?: Record; type: "file"; } | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; })[]; providerData?: Record; status: "completed" | "in_progress" | "incomplete"; type: "function_call_result"; } | { action?: | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; }; actions?: ( | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; })[]; callId: string; id?: string; providerData?: Record; status: "completed" | "in_progress" | "incomplete"; type: "computer_call"; } | { callId: string; id?: string; output: { data: string; providerData?: Record; type: "computer_screenshot"; }; providerData?: Record; type: "computer_call_result"; } | { action: { commands: string[]; maxOutputLength?: number; timeoutMs?: number; }; callId: string; id?: string; providerData?: Record; status?: "completed" | "in_progress" | "incomplete"; type: "shell_call"; } | { callId: string; id?: string; maxOutputLength?: number; output: object[]; providerData?: Record; type: "shell_call_output"; } | { callId: string; id?: string; operation: | { diff: string; path: string; type: "create_file"; } | { diff: string; moveTo?: string; path: string; type: "update_file"; } | { path: string; type: "delete_file"; }; providerData?: Record; status: "completed" | "in_progress"; type: "apply_patch_call"; } | { callId: string; id?: string; output?: string; providerData?: Record; status: "completed" | "failed"; type: "apply_patch_call_output"; } | { content: object[]; id?: string; providerData?: Record; rawContent?: object[]; type: "reasoning"; } | { created_by?: string; encrypted_content: string; id?: string; providerData?: Record; type: "compaction"; } | { id?: string; providerData?: Record; type: "unknown"; } | undefined; ``` ##### toolName [Section titled “toolName”](#toolname-1) ```ts toolName: string | undefined; ``` ##### type [Section titled “type”](#type-1) ```ts type: string; ``` #### Overrides [Section titled “Overrides”](#overrides-3) ```ts RunItemBase.toJSON ``` # RunToolCallItem ## Extends [Section titled “Extends”](#extends) * `RunItemBase` ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new RunToolCallItem(rawItem, agent): RunToolCallItem; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | `rawItem` | \| { `action?`: \| { `type`: `"screenshot"`; } \| { `button`: `"left"` \| `"right"` \| `"wheel"` \| `"back"` \| `"forward"`; `type`: `"click"`; `x`: `number`; `y`: `number`; } \| { `type`: `"double_click"`; `x`: `number`; `y`: `number`; } \| { `scroll_x`: `number`; `scroll_y`: `number`; `type`: `"scroll"`; `x`: `number`; `y`: `number`; } \| { `text`: `string`; `type`: `"type"`; } \| { `type`: `"wait"`; } \| { `type`: `"move"`; `x`: `number`; `y`: `number`; } \| { `keys`: `string`\[]; `type`: `"keypress"`; } \| { `path`: `object`\[]; `type`: `"drag"`; }; `actions?`: ( \| { `type`: `"screenshot"`; } \| { `button`: `"left"` \| `"right"` \| `"wheel"` \| `"back"` \| `"forward"`; `type`: `"click"`; `x`: `number`; `y`: `number`; } \| { `type`: `"double_click"`; `x`: `number`; `y`: `number`; } \| { `scroll_x`: `number`; `scroll_y`: `number`; `type`: `"scroll"`; `x`: `number`; `y`: `number`; } \| { `text`: `string`; `type`: `"type"`; } \| { `type`: `"wait"`; } \| { `type`: `"move"`; `x`: `number`; `y`: `number`; } \| { `keys`: `string`\[]; `type`: `"keypress"`; } \| { `path`: `object`\[]; `type`: `"drag"`; })\[]; `callId`: `string`; `id?`: `string`; `providerData?`: `Record`<`string`, `any`>; `status`: `"completed"` \| `"in_progress"` \| `"incomplete"`; `type`: `"computer_call"`; } \| { `action`: { `commands`: `string`\[]; `maxOutputLength?`: `number`; `timeoutMs?`: `number`; }; `callId`: `string`; `id?`: `string`; `providerData?`: `Record`<`string`, `any`>; `status?`: `"completed"` \| `"in_progress"` \| `"incomplete"`; `type`: `"shell_call"`; } \| { `callId`: `string`; `id?`: `string`; `operation`: \| { `diff`: `string`; `path`: `string`; `type`: `"create_file"`; } \| { `diff`: `string`; `moveTo?`: `string`; `path`: `string`; `type`: `"update_file"`; } \| { `path`: `string`; `type`: `"delete_file"`; }; `providerData?`: `Record`<`string`, `any`>; `status`: `"completed"` \| `"in_progress"`; `type`: `"apply_patch_call"`; } \| { `arguments`: `string`; `callId`: `string`; `id?`: `string`; `name`: `string`; `namespace?`: `string`; `providerData?`: `Record`<`string`, `any`>; `status?`: `"completed"` \| `"in_progress"` \| `"incomplete"`; `type`: `"function_call"`; } \| { `arguments?`: `string`; `id?`: `string`; `name`: `string`; `output?`: `string`; `providerData?`: `Record`<`string`, `any`>; `status?`: `string`; `type`: `"hosted_tool_call"`; } | | `agent` | [`Agent`](/openai-agents-js/openai/agents/classes/agent/) | #### Returns [Section titled “Returns”](#returns) `RunToolCallItem` #### Overrides [Section titled “Overrides”](#overrides) ```ts RunItemBase.constructor ``` ## Properties [Section titled “Properties”](#properties) ### agent [Section titled “agent”](#agent) ```ts agent: Agent; ``` *** ### rawItem [Section titled “rawItem”](#rawitem) ```ts rawItem: | { action?: | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; }; actions?: ( | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; })[]; callId: string; id?: string; providerData?: Record; status: "completed" | "in_progress" | "incomplete"; type: "computer_call"; } | { action: { commands: string[]; maxOutputLength?: number; timeoutMs?: number; }; callId: string; id?: string; providerData?: Record; status?: "completed" | "in_progress" | "incomplete"; type: "shell_call"; } | { callId: string; id?: string; operation: | { diff: string; path: string; type: "create_file"; } | { diff: string; moveTo?: string; path: string; type: "update_file"; } | { path: string; type: "delete_file"; }; providerData?: Record; status: "completed" | "in_progress"; type: "apply_patch_call"; } | { arguments: string; callId: string; id?: string; name: string; namespace?: string; providerData?: Record; status?: "completed" | "in_progress" | "incomplete"; type: "function_call"; } | { arguments?: string; id?: string; name: string; output?: string; providerData?: Record; status?: string; type: "hosted_tool_call"; }; ``` #### Overrides [Section titled “Overrides”](#overrides-1) ```ts RunItemBase.rawItem ``` *** ### type [Section titled “type”](#type) ```ts readonly type: "tool_call_item"; ``` #### Overrides [Section titled “Overrides”](#overrides-2) ```ts RunItemBase.type ``` ## Accessors [Section titled “Accessors”](#accessors) ### callId [Section titled “callId”](#callid) #### Get Signature [Section titled “Get Signature”](#get-signature) ```ts get callId(): string | undefined; ``` ##### Returns [Section titled “Returns”](#returns-1) `string` | `undefined` *** ### toolName [Section titled “toolName”](#toolname) #### Get Signature [Section titled “Get Signature”](#get-signature-1) ```ts get toolName(): string | undefined; ``` ##### Returns [Section titled “Returns”](#returns-2) `string` | `undefined` ## Methods [Section titled “Methods”](#methods) ### toJSON() [Section titled “toJSON()”](#tojson) ```ts toJSON(): object; ``` #### Returns [Section titled “Returns”](#returns-3) `object` ##### agent [Section titled “agent”](#agent-1) ```ts agent: object; ``` ###### agent.name [Section titled “agent.name”](#agentname) ```ts name: string; ``` ##### rawItem [Section titled “rawItem”](#rawitem-1) ```ts rawItem: | { content: ( | { providerData?: Record; refusal: string; type: "refusal"; } | { providerData?: Record; text: string; type: "output_text"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; } | { image: string; providerData?: Record; type: "image"; })[]; id?: string; providerData?: Record; role: "assistant"; status: "completed" | "in_progress" | "incomplete"; type?: "message"; } | { content: | string | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; })[]; id?: string; providerData?: Record; role: "user"; type?: "message"; } | { content: string; id?: string; providerData?: Record; role: "system"; type?: "message"; } | { arguments?: string; id?: string; name: string; output?: string; providerData?: Record; status?: string; type: "hosted_tool_call"; } | { arguments: string; callId: string; id?: string; name: string; namespace?: string; providerData?: Record; status?: "completed" | "in_progress" | "incomplete"; type: "function_call"; } | { arguments: unknown; call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; type: "tool_search_call"; } | { call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; tools: Record[]; type: "tool_search_output"; } | { callId: string; id?: string; name: string; namespace?: string; output: | string | { providerData?: Record; text: string; type: "text"; } | { detail?: string & object | "low" | "high" | "auto"; image?: | string | { data: string | Uint8Array; mediaType?: string; } | { url: string; } | { fileId: string; }; providerData?: Record; type: "image"; } | { file: | string | { data: string | Uint8Array; filename: string; mediaType: string; } | { filename?: string; url: string; } | { filename?: string; id: string; }; providerData?: Record; type: "file"; } | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; })[]; providerData?: Record; status: "completed" | "in_progress" | "incomplete"; type: "function_call_result"; } | { action?: | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; }; actions?: ( | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; })[]; callId: string; id?: string; providerData?: Record; status: "completed" | "in_progress" | "incomplete"; type: "computer_call"; } | { callId: string; id?: string; output: { data: string; providerData?: Record; type: "computer_screenshot"; }; providerData?: Record; type: "computer_call_result"; } | { action: { commands: string[]; maxOutputLength?: number; timeoutMs?: number; }; callId: string; id?: string; providerData?: Record; status?: "completed" | "in_progress" | "incomplete"; type: "shell_call"; } | { callId: string; id?: string; maxOutputLength?: number; output: object[]; providerData?: Record; type: "shell_call_output"; } | { callId: string; id?: string; operation: | { diff: string; path: string; type: "create_file"; } | { diff: string; moveTo?: string; path: string; type: "update_file"; } | { path: string; type: "delete_file"; }; providerData?: Record; status: "completed" | "in_progress"; type: "apply_patch_call"; } | { callId: string; id?: string; output?: string; providerData?: Record; status: "completed" | "failed"; type: "apply_patch_call_output"; } | { content: object[]; id?: string; providerData?: Record; rawContent?: object[]; type: "reasoning"; } | { created_by?: string; encrypted_content: string; id?: string; providerData?: Record; type: "compaction"; } | { id?: string; providerData?: Record; type: "unknown"; } | undefined; ``` ##### type [Section titled “type”](#type-1) ```ts type: string; ``` #### Overrides [Section titled “Overrides”](#overrides-3) ```ts RunItemBase.toJSON ``` # RunToolCallOutputItem ## Extends [Section titled “Extends”](#extends) * `RunItemBase` ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new RunToolCallOutputItem( rawItem, agent, output): RunToolCallOutputItem; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `rawItem` | \| { `callId`: `string`; `id?`: `string`; `name`: `string`; `namespace?`: `string`; `output`: \| `string` \| { `providerData?`: `Record`<`string`, `any`>; `text`: `string`; `type`: `"text"`; } \| { `detail?`: `string` & `object` \| `"low"` \| `"high"` \| `"auto"`; `image?`: \| `string` \| { `data`: `string` \| `Uint8Array`<`ArrayBuffer`>; `mediaType?`: `string`; } \| { `url`: `string`; } \| { `fileId`: `string`; }; `providerData?`: `Record`<`string`, `any`>; `type`: `"image"`; } \| { `file`: \| `string` \| { `data`: `string` \| `Uint8Array`<`ArrayBuffer`>; `filename`: `string`; `mediaType`: `string`; } \| { `filename?`: `string`; `url`: `string`; } \| { `filename?`: `string`; `id`: `string`; }; `providerData?`: `Record`<`string`, `any`>; `type`: `"file"`; } \| ( \| { `providerData?`: `Record`<`string`, `any`>; `text`: `string`; `type`: `"input_text"`; } \| { `detail?`: `string`; `image?`: \| `string` \| { `id`: `string`; }; `providerData?`: `Record`<`string`, `any`>; `type`: `"input_image"`; } \| { `file?`: \| `string` \| { `id`: `string`; } \| { `url`: `string`; }; `filename?`: `string`; `providerData?`: `Record`<`string`, `any`>; `type`: `"input_file"`; })\[]; `providerData?`: `Record`<`string`, `any`>; `status`: `"completed"` \| `"in_progress"` \| `"incomplete"`; `type`: `"function_call_result"`; } \| { `callId`: `string`; `id?`: `string`; `output`: { `data`: `string`; `providerData?`: `Record`<`string`, `any`>; `type`: `"computer_screenshot"`; }; `providerData?`: `Record`<`string`, `any`>; `type`: `"computer_call_result"`; } \| { `callId`: `string`; `id?`: `string`; `maxOutputLength?`: `number`; `output`: `object`\[]; `providerData?`: `Record`<`string`, `any`>; `type`: `"shell_call_output"`; } \| { `callId`: `string`; `id?`: `string`; `output?`: `string`; `providerData?`: `Record`<`string`, `any`>; `status`: `"completed"` \| `"failed"`; `type`: `"apply_patch_call_output"`; } | | `agent` | [`Agent`](/openai-agents-js/openai/agents/classes/agent/)<`any`, `any`> | | `output` | `unknown` | #### Returns [Section titled “Returns”](#returns) `RunToolCallOutputItem` #### Overrides [Section titled “Overrides”](#overrides) ```ts RunItemBase.constructor ``` ## Properties [Section titled “Properties”](#properties) ### agent [Section titled “agent”](#agent) ```ts agent: Agent; ``` *** ### output [Section titled “output”](#output) ```ts output: unknown; ``` *** ### rawItem [Section titled “rawItem”](#rawitem) ```ts rawItem: | { callId: string; id?: string; name: string; namespace?: string; output: | string | { providerData?: Record; text: string; type: "text"; } | { detail?: string & object | "low" | "high" | "auto"; image?: | string | { data: string | Uint8Array; mediaType?: string; } | { url: string; } | { fileId: string; }; providerData?: Record; type: "image"; } | { file: | string | { data: string | Uint8Array; filename: string; mediaType: string; } | { filename?: string; url: string; } | { filename?: string; id: string; }; providerData?: Record; type: "file"; } | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; })[]; providerData?: Record; status: "completed" | "in_progress" | "incomplete"; type: "function_call_result"; } | { callId: string; id?: string; output: { data: string; providerData?: Record; type: "computer_screenshot"; }; providerData?: Record; type: "computer_call_result"; } | { callId: string; id?: string; maxOutputLength?: number; output: object[]; providerData?: Record; type: "shell_call_output"; } | { callId: string; id?: string; output?: string; providerData?: Record; status: "completed" | "failed"; type: "apply_patch_call_output"; }; ``` #### Overrides [Section titled “Overrides”](#overrides-1) ```ts RunItemBase.rawItem ``` *** ### type [Section titled “type”](#type) ```ts readonly type: "tool_call_output_item"; ``` #### Overrides [Section titled “Overrides”](#overrides-2) ```ts RunItemBase.type ``` ## Accessors [Section titled “Accessors”](#accessors) ### callId [Section titled “callId”](#callid) #### Get Signature [Section titled “Get Signature”](#get-signature) ```ts get callId(): string | undefined; ``` ##### Returns [Section titled “Returns”](#returns-1) `string` | `undefined` ## Methods [Section titled “Methods”](#methods) ### toJSON() [Section titled “toJSON()”](#tojson) ```ts toJSON(): object; ``` #### Returns [Section titled “Returns”](#returns-2) `object` ##### agent [Section titled “agent”](#agent-1) ```ts agent: object; ``` ###### agent.name [Section titled “agent.name”](#agentname) ```ts name: string; ``` ##### output [Section titled “output”](#output-1) ```ts output: string; ``` ##### rawItem [Section titled “rawItem”](#rawitem-1) ```ts rawItem: | { content: ( | { providerData?: Record; refusal: string; type: "refusal"; } | { providerData?: Record; text: string; type: "output_text"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; } | { image: string; providerData?: Record; type: "image"; })[]; id?: string; providerData?: Record; role: "assistant"; status: "completed" | "in_progress" | "incomplete"; type?: "message"; } | { content: | string | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; })[]; id?: string; providerData?: Record; role: "user"; type?: "message"; } | { content: string; id?: string; providerData?: Record; role: "system"; type?: "message"; } | { arguments?: string; id?: string; name: string; output?: string; providerData?: Record; status?: string; type: "hosted_tool_call"; } | { arguments: string; callId: string; id?: string; name: string; namespace?: string; providerData?: Record; status?: "completed" | "in_progress" | "incomplete"; type: "function_call"; } | { arguments: unknown; call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; type: "tool_search_call"; } | { call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; tools: Record[]; type: "tool_search_output"; } | { callId: string; id?: string; name: string; namespace?: string; output: | string | { providerData?: Record; text: string; type: "text"; } | { detail?: string & object | "low" | "high" | "auto"; image?: | string | { data: string | Uint8Array; mediaType?: string; } | { url: string; } | { fileId: string; }; providerData?: Record; type: "image"; } | { file: | string | { data: string | Uint8Array; filename: string; mediaType: string; } | { filename?: string; url: string; } | { filename?: string; id: string; }; providerData?: Record; type: "file"; } | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; })[]; providerData?: Record; status: "completed" | "in_progress" | "incomplete"; type: "function_call_result"; } | { action?: | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; }; actions?: ( | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; })[]; callId: string; id?: string; providerData?: Record; status: "completed" | "in_progress" | "incomplete"; type: "computer_call"; } | { callId: string; id?: string; output: { data: string; providerData?: Record; type: "computer_screenshot"; }; providerData?: Record; type: "computer_call_result"; } | { action: { commands: string[]; maxOutputLength?: number; timeoutMs?: number; }; callId: string; id?: string; providerData?: Record; status?: "completed" | "in_progress" | "incomplete"; type: "shell_call"; } | { callId: string; id?: string; maxOutputLength?: number; output: object[]; providerData?: Record; type: "shell_call_output"; } | { callId: string; id?: string; operation: | { diff: string; path: string; type: "create_file"; } | { diff: string; moveTo?: string; path: string; type: "update_file"; } | { path: string; type: "delete_file"; }; providerData?: Record; status: "completed" | "in_progress"; type: "apply_patch_call"; } | { callId: string; id?: string; output?: string; providerData?: Record; status: "completed" | "failed"; type: "apply_patch_call_output"; } | { content: object[]; id?: string; providerData?: Record; rawContent?: object[]; type: "reasoning"; } | { created_by?: string; encrypted_content: string; id?: string; providerData?: Record; type: "compaction"; } | { id?: string; providerData?: Record; type: "unknown"; } | undefined; ``` ##### type [Section titled “type”](#type-1) ```ts type: string; ``` #### Overrides [Section titled “Overrides”](#overrides-3) ```ts RunItemBase.toJSON ``` # RunToolSearchCallItem ## Extends [Section titled “Extends”](#extends) * `RunItemBase` ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new RunToolSearchCallItem(rawItem, agent): RunToolSearchCallItem; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ----------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `rawItem` | { `arguments`: `unknown`; `call_id?`: `string` \| `null`; `callId?`: `string` \| `null`; `execution?`: `"client"` \| `"server"`; `id?`: `string`; `providerData?`: `Record`<`string`, `any`>; `status?`: `string`; `type`: `"tool_search_call"`; } | | `rawItem.arguments` | `unknown` | | `rawItem.call_id?` | `string` \| `null` | | `rawItem.callId?` | `string` \| `null` | | `rawItem.execution?` | `"client"` \| `"server"` | | `rawItem.id?` | `string` | | `rawItem.providerData?` | `Record`<`string`, `any`> | | `rawItem.status?` | `string` | | `rawItem.type` | `"tool_search_call"` | | `agent` | [`Agent`](/openai-agents-js/openai/agents/classes/agent/) | #### Returns [Section titled “Returns”](#returns) `RunToolSearchCallItem` #### Overrides [Section titled “Overrides”](#overrides) ```ts RunItemBase.constructor ``` ## Properties [Section titled “Properties”](#properties) ### agent [Section titled “agent”](#agent) ```ts agent: Agent; ``` *** ### rawItem [Section titled “rawItem”](#rawitem) ```ts rawItem: object; ``` | Name | Type | | --------------- | ------------------------- | | `arguments` | `unknown` | | `call_id?` | `string` \| `null` | | `callId?` | `string` \| `null` | | `execution?` | `"client"` \| `"server"` | | `id?` | `string` | | `providerData?` | `Record`<`string`, `any`> | | `status?` | `string` | | `type` | `"tool_search_call"` | #### Overrides [Section titled “Overrides”](#overrides-1) ```ts RunItemBase.rawItem ``` *** ### type [Section titled “type”](#type) ```ts readonly type: "tool_search_call_item"; ``` #### Overrides [Section titled “Overrides”](#overrides-2) ```ts RunItemBase.type ``` ## Methods [Section titled “Methods”](#methods) ### toJSON() [Section titled “toJSON()”](#tojson) ```ts toJSON(): object; ``` #### Returns [Section titled “Returns”](#returns-1) `object` ##### agent [Section titled “agent”](#agent-1) ```ts agent: object; ``` ###### agent.name [Section titled “agent.name”](#agentname) ```ts name: string; ``` ##### rawItem [Section titled “rawItem”](#rawitem-1) ```ts rawItem: | { content: ( | { providerData?: Record; refusal: string; type: "refusal"; } | { providerData?: Record; text: string; type: "output_text"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; } | { image: string; providerData?: Record; type: "image"; })[]; id?: string; providerData?: Record; role: "assistant"; status: "completed" | "in_progress" | "incomplete"; type?: "message"; } | { content: | string | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; })[]; id?: string; providerData?: Record; role: "user"; type?: "message"; } | { content: string; id?: string; providerData?: Record; role: "system"; type?: "message"; } | { arguments?: string; id?: string; name: string; output?: string; providerData?: Record; status?: string; type: "hosted_tool_call"; } | { arguments: string; callId: string; id?: string; name: string; namespace?: string; providerData?: Record; status?: "completed" | "in_progress" | "incomplete"; type: "function_call"; } | { arguments: unknown; call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; type: "tool_search_call"; } | { call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; tools: Record[]; type: "tool_search_output"; } | { callId: string; id?: string; name: string; namespace?: string; output: | string | { providerData?: Record; text: string; type: "text"; } | { detail?: string & object | "low" | "high" | "auto"; image?: | string | { data: string | Uint8Array; mediaType?: string; } | { url: string; } | { fileId: string; }; providerData?: Record; type: "image"; } | { file: | string | { data: string | Uint8Array; filename: string; mediaType: string; } | { filename?: string; url: string; } | { filename?: string; id: string; }; providerData?: Record; type: "file"; } | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; })[]; providerData?: Record; status: "completed" | "in_progress" | "incomplete"; type: "function_call_result"; } | { action?: | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; }; actions?: ( | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; })[]; callId: string; id?: string; providerData?: Record; status: "completed" | "in_progress" | "incomplete"; type: "computer_call"; } | { callId: string; id?: string; output: { data: string; providerData?: Record; type: "computer_screenshot"; }; providerData?: Record; type: "computer_call_result"; } | { action: { commands: string[]; maxOutputLength?: number; timeoutMs?: number; }; callId: string; id?: string; providerData?: Record; status?: "completed" | "in_progress" | "incomplete"; type: "shell_call"; } | { callId: string; id?: string; maxOutputLength?: number; output: object[]; providerData?: Record; type: "shell_call_output"; } | { callId: string; id?: string; operation: | { diff: string; path: string; type: "create_file"; } | { diff: string; moveTo?: string; path: string; type: "update_file"; } | { path: string; type: "delete_file"; }; providerData?: Record; status: "completed" | "in_progress"; type: "apply_patch_call"; } | { callId: string; id?: string; output?: string; providerData?: Record; status: "completed" | "failed"; type: "apply_patch_call_output"; } | { content: object[]; id?: string; providerData?: Record; rawContent?: object[]; type: "reasoning"; } | { created_by?: string; encrypted_content: string; id?: string; providerData?: Record; type: "compaction"; } | { id?: string; providerData?: Record; type: "unknown"; } | undefined; ``` ##### type [Section titled “type”](#type-1) ```ts type: string; ``` #### Overrides [Section titled “Overrides”](#overrides-3) ```ts RunItemBase.toJSON ``` # RunToolSearchOutputItem ## Extends [Section titled “Extends”](#extends) * `RunItemBase` ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new RunToolSearchOutputItem(rawItem, agent): RunToolSearchOutputItem; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `rawItem` | { `call_id?`: `string` \| `null`; `callId?`: `string` \| `null`; `execution?`: `"client"` \| `"server"`; `id?`: `string`; `providerData?`: `Record`<`string`, `any`>; `status?`: `string`; `tools`: `Record`<`string`, `any`>\[]; `type`: `"tool_search_output"`; } | | `rawItem.call_id?` | `string` \| `null` | | `rawItem.callId?` | `string` \| `null` | | `rawItem.execution?` | `"client"` \| `"server"` | | `rawItem.id?` | `string` | | `rawItem.providerData?` | `Record`<`string`, `any`> | | `rawItem.status?` | `string` | | `rawItem.tools` | `Record`<`string`, `any`>\[] | | `rawItem.type` | `"tool_search_output"` | | `agent` | [`Agent`](/openai-agents-js/openai/agents/classes/agent/) | #### Returns [Section titled “Returns”](#returns) `RunToolSearchOutputItem` #### Overrides [Section titled “Overrides”](#overrides) ```ts RunItemBase.constructor ``` ## Properties [Section titled “Properties”](#properties) ### agent [Section titled “agent”](#agent) ```ts agent: Agent; ``` *** ### rawItem [Section titled “rawItem”](#rawitem) ```ts rawItem: object; ``` | Name | Type | | --------------- | ---------------------------- | | `call_id?` | `string` \| `null` | | `callId?` | `string` \| `null` | | `execution?` | `"client"` \| `"server"` | | `id?` | `string` | | `providerData?` | `Record`<`string`, `any`> | | `status?` | `string` | | `tools` | `Record`<`string`, `any`>\[] | | `type` | `"tool_search_output"` | #### Overrides [Section titled “Overrides”](#overrides-1) ```ts RunItemBase.rawItem ``` *** ### type [Section titled “type”](#type) ```ts readonly type: "tool_search_output_item"; ``` #### Overrides [Section titled “Overrides”](#overrides-2) ```ts RunItemBase.type ``` ## Methods [Section titled “Methods”](#methods) ### toJSON() [Section titled “toJSON()”](#tojson) ```ts toJSON(): object; ``` #### Returns [Section titled “Returns”](#returns-1) `object` ##### agent [Section titled “agent”](#agent-1) ```ts agent: object; ``` ###### agent.name [Section titled “agent.name”](#agentname) ```ts name: string; ``` ##### rawItem [Section titled “rawItem”](#rawitem-1) ```ts rawItem: | { content: ( | { providerData?: Record; refusal: string; type: "refusal"; } | { providerData?: Record; text: string; type: "output_text"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; } | { image: string; providerData?: Record; type: "image"; })[]; id?: string; providerData?: Record; role: "assistant"; status: "completed" | "in_progress" | "incomplete"; type?: "message"; } | { content: | string | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; })[]; id?: string; providerData?: Record; role: "user"; type?: "message"; } | { content: string; id?: string; providerData?: Record; role: "system"; type?: "message"; } | { arguments?: string; id?: string; name: string; output?: string; providerData?: Record; status?: string; type: "hosted_tool_call"; } | { arguments: string; callId: string; id?: string; name: string; namespace?: string; providerData?: Record; status?: "completed" | "in_progress" | "incomplete"; type: "function_call"; } | { arguments: unknown; call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; type: "tool_search_call"; } | { call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; tools: Record[]; type: "tool_search_output"; } | { callId: string; id?: string; name: string; namespace?: string; output: | string | { providerData?: Record; text: string; type: "text"; } | { detail?: string & object | "low" | "high" | "auto"; image?: | string | { data: string | Uint8Array; mediaType?: string; } | { url: string; } | { fileId: string; }; providerData?: Record; type: "image"; } | { file: | string | { data: string | Uint8Array; filename: string; mediaType: string; } | { filename?: string; url: string; } | { filename?: string; id: string; }; providerData?: Record; type: "file"; } | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; })[]; providerData?: Record; status: "completed" | "in_progress" | "incomplete"; type: "function_call_result"; } | { action?: | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; }; actions?: ( | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; })[]; callId: string; id?: string; providerData?: Record; status: "completed" | "in_progress" | "incomplete"; type: "computer_call"; } | { callId: string; id?: string; output: { data: string; providerData?: Record; type: "computer_screenshot"; }; providerData?: Record; type: "computer_call_result"; } | { action: { commands: string[]; maxOutputLength?: number; timeoutMs?: number; }; callId: string; id?: string; providerData?: Record; status?: "completed" | "in_progress" | "incomplete"; type: "shell_call"; } | { callId: string; id?: string; maxOutputLength?: number; output: object[]; providerData?: Record; type: "shell_call_output"; } | { callId: string; id?: string; operation: | { diff: string; path: string; type: "create_file"; } | { diff: string; moveTo?: string; path: string; type: "update_file"; } | { path: string; type: "delete_file"; }; providerData?: Record; status: "completed" | "in_progress"; type: "apply_patch_call"; } | { callId: string; id?: string; output?: string; providerData?: Record; status: "completed" | "failed"; type: "apply_patch_call_output"; } | { content: object[]; id?: string; providerData?: Record; rawContent?: object[]; type: "reasoning"; } | { created_by?: string; encrypted_content: string; id?: string; providerData?: Record; type: "compaction"; } | { id?: string; providerData?: Record; type: "unknown"; } | undefined; ``` ##### type [Section titled “type”](#type-1) ```ts type: string; ``` #### Overrides [Section titled “Overrides”](#overrides-3) ```ts RunItemBase.toJSON ``` # Span ## Extended by [Section titled “Extended by”](#extended-by) * [`NoopSpan`](/openai-agents-js/openai/agents/classes/noopspan/) ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | -------------------------------------------------------------------------------------- | | `TData` *extends* [`SpanData`](/openai-agents-js/openai/agents/type-aliases/spandata/) | ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new Span(options, processor): Span; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ----------- | ----------------------------------------------------------------------------------- | | `options` | [`SpanOptions`](/openai-agents-js/openai/agents/type-aliases/spanoptions/)<`TData`> | | `processor` | [`TracingProcessor`](/openai-agents-js/openai/agents/interfaces/tracingprocessor/) | #### Returns [Section titled “Returns”](#returns) `Span`<`TData`> ## Properties [Section titled “Properties”](#properties) ### type [Section titled “type”](#type) ```ts type: "trace.span"; ``` ## Accessors [Section titled “Accessors”](#accessors) ### endedAt [Section titled “endedAt”](#endedat) #### Get Signature [Section titled “Get Signature”](#get-signature) ```ts get endedAt(): string | null; ``` ##### Returns [Section titled “Returns”](#returns-1) `string` | `null` *** ### error [Section titled “error”](#error) #### Get Signature [Section titled “Get Signature”](#get-signature-1) ```ts get error(): | SpanError | null; ``` ##### Returns [Section titled “Returns”](#returns-2) \| [`SpanError`](/openai-agents-js/openai/agents/type-aliases/spanerror/) | `null` *** ### parentId [Section titled “parentId”](#parentid) #### Get Signature [Section titled “Get Signature”](#get-signature-2) ```ts get parentId(): string | null; ``` ##### Returns [Section titled “Returns”](#returns-3) `string` | `null` *** ### previousSpan [Section titled “previousSpan”](#previousspan) #### Get Signature [Section titled “Get Signature”](#get-signature-3) ```ts get previousSpan(): Span | undefined; ``` ##### Returns [Section titled “Returns”](#returns-4) `Span`<`any`> | `undefined` #### Set Signature [Section titled “Set Signature”](#set-signature) ```ts set previousSpan(span): void; ``` ##### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | --------- | ---------------------------- | | `span` | `Span`<`any`> \| `undefined` | ##### Returns [Section titled “Returns”](#returns-5) `void` *** ### spanData [Section titled “spanData”](#spandata) #### Get Signature [Section titled “Get Signature”](#get-signature-4) ```ts get spanData(): TData; ``` ##### Returns [Section titled “Returns”](#returns-6) `TData` *** ### spanId [Section titled “spanId”](#spanid) #### Get Signature [Section titled “Get Signature”](#get-signature-5) ```ts get spanId(): string; ``` ##### Returns [Section titled “Returns”](#returns-7) `string` *** ### startedAt [Section titled “startedAt”](#startedat) #### Get Signature [Section titled “Get Signature”](#get-signature-6) ```ts get startedAt(): string | null; ``` ##### Returns [Section titled “Returns”](#returns-8) `string` | `null` *** ### traceId [Section titled “traceId”](#traceid) #### Get Signature [Section titled “Get Signature”](#get-signature-7) ```ts get traceId(): string; ``` ##### Returns [Section titled “Returns”](#returns-9) `string` *** ### traceMetadata [Section titled “traceMetadata”](#tracemetadata) #### Get Signature [Section titled “Get Signature”](#get-signature-8) ```ts get traceMetadata(): Record | undefined; ``` ##### Returns [Section titled “Returns”](#returns-10) `Record`<`string`, `any`> | `undefined` *** ### tracingApiKey [Section titled “tracingApiKey”](#tracingapikey) #### Get Signature [Section titled “Get Signature”](#get-signature-9) ```ts get tracingApiKey(): string | undefined; ``` ##### Returns [Section titled “Returns”](#returns-11) `string` | `undefined` ## Methods [Section titled “Methods”](#methods) ### clone() [Section titled “clone()”](#clone) ```ts clone(): Span; ``` #### Returns [Section titled “Returns”](#returns-12) `Span`<`TData`> *** ### end() [Section titled “end()”](#end) ```ts end(): void; ``` #### Returns [Section titled “Returns”](#returns-13) `void` *** ### setError() [Section titled “setError()”](#seterror) ```ts setError(error): void; ``` #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | --------- | ---------------------------------------------------------------------- | | `error` | [`SpanError`](/openai-agents-js/openai/agents/type-aliases/spanerror/) | #### Returns [Section titled “Returns”](#returns-14) `void` *** ### start() [Section titled “start()”](#start) ```ts start(): void; ``` #### Returns [Section titled “Returns”](#returns-15) `void` *** ### toJSON() [Section titled “toJSON()”](#tojson) ```ts toJSON(): object | null; ``` #### Returns [Section titled “Returns”](#returns-16) `object` | `null` # StreamedRunResult The result of an agent run in streaming mode. ## Extends [Section titled “Extends”](#extends) * `RunResultBase`<`TContext`, `TAgent`> ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `TContext` | | `TAgent` *extends* [`Agent`](/openai-agents-js/openai/agents/classes/agent/)<`TContext`, [`AgentOutputType`](/openai-agents-js/openai/agents/type-aliases/agentoutputtype/)> | ## Implements [Section titled “Implements”](#implements) * `AsyncIterable`<[`RunStreamEvent`](/openai-agents-js/openai/agents/type-aliases/runstreamevent/)> ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new StreamedRunResult(result?): StreamedRunResult; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ---------------- | ----------------------------------------------------------------------------------------------------------------------------- | | `result?` | { `signal?`: `AbortSignal`; `state`: [`RunState`](/openai-agents-js/openai/agents/classes/runstate/)<`TContext`, `TAgent`>; } | | `result.signal?` | `AbortSignal` | | `result.state?` | [`RunState`](/openai-agents-js/openai/agents/classes/runstate/)<`TContext`, `TAgent`> | #### Returns [Section titled “Returns”](#returns) `StreamedRunResult`<`TContext`, `TAgent`> #### Overrides [Section titled “Overrides”](#overrides) ```ts RunResultBase.constructor ``` ## Properties [Section titled “Properties”](#properties) ### currentTurn [Section titled “currentTurn”](#currentturn) ```ts currentTurn: number; ``` The current turn number *** ### maxTurns [Section titled “maxTurns”](#maxturns) ```ts maxTurns: number | null | undefined; ``` The maximum number of turns that can be run *** ### state [Section titled “state”](#state) ```ts readonly state: RunState; ``` The state of the run. #### Inherited from [Section titled “Inherited from”](#inherited-from) ```ts RunResultBase.state ``` ## Accessors [Section titled “Accessors”](#accessors) ### activeAgent [Section titled “activeAgent”](#activeagent) #### Get Signature [Section titled “Get Signature”](#get-signature) ```ts get activeAgent(): TAgent | undefined; ``` The agent that should handle the next turn. This is an alias for the last agent that completed a turn. ##### Returns [Section titled “Returns”](#returns-1) `TAgent` | `undefined` #### Inherited from [Section titled “Inherited from”](#inherited-from-1) ```ts RunResultBase.activeAgent ``` *** ### agentToolInvocation [Section titled “agentToolInvocation”](#agenttoolinvocation) #### Get Signature [Section titled “Get Signature”](#get-signature-1) ```ts get agentToolInvocation(): | Readonly<{ toolArguments?: string; toolCallId?: string; toolName: string; }> | undefined; ``` Metadata about the nested `Agent.asTool()` invocation that produced this result, when applicable. ##### Returns [Section titled “Returns”](#returns-2) \| `Readonly`<{ `toolArguments?`: `string`; `toolCallId?`: `string`; `toolName`: `string`; }> | `undefined` #### Inherited from [Section titled “Inherited from”](#inherited-from-2) ```ts RunResultBase.agentToolInvocation ``` *** ### cancelled [Section titled “cancelled”](#cancelled) #### Get Signature [Section titled “Get Signature”](#get-signature-2) ```ts get cancelled(): boolean; ``` Returns true if the stream has been cancelled. ##### Returns [Section titled “Returns”](#returns-3) `boolean` *** ### completed [Section titled “completed”](#completed) #### Get Signature [Section titled “Get Signature”](#get-signature-3) ```ts get completed(): Promise; ``` Await this promise to ensure that the stream has been completed if you are not consuming the stream directly. ##### Returns [Section titled “Returns”](#returns-4) `Promise`<`void`> *** ### currentAgent [Section titled “currentAgent”](#currentagent) #### Get Signature [Section titled “Get Signature”](#get-signature-4) ```ts get currentAgent(): TAgent | undefined; ``` The current agent that is running ##### Returns [Section titled “Returns”](#returns-5) `TAgent` | `undefined` *** ### error [Section titled “error”](#error) #### Get Signature [Section titled “Get Signature”](#get-signature-5) ```ts get error(): unknown; ``` Error thrown during the run, if any. ##### Returns [Section titled “Returns”](#returns-6) `unknown` *** ### finalOutput [Section titled “finalOutput”](#finaloutput) #### Get Signature [Section titled “Get Signature”](#get-signature-6) ```ts get finalOutput(): ResolvedAgentOutput | undefined; ``` The final output of the agent. If the output type was set to anything other than `text`, this will be parsed either as JSON or using the Zod schema you provided. ##### Returns [Section titled “Returns”](#returns-7) `ResolvedAgentOutput`<`TAgent`\[`"outputType"`]> | `undefined` #### Inherited from [Section titled “Inherited from”](#inherited-from-3) ```ts RunResultBase.finalOutput ``` *** ### history [Section titled “history”](#history) #### Get Signature [Section titled “Get Signature”](#get-signature-7) ```ts get history(): AgentInputItem[]; ``` The history of the agent run. This includes the input items and the new items generated during the agent run. This can be used as inputs for the next agent run. ##### Returns [Section titled “Returns”](#returns-8) [`AgentInputItem`](/openai-agents-js/openai/agents/type-aliases/agentinputitem/)\[] #### Inherited from [Section titled “Inherited from”](#inherited-from-4) ```ts RunResultBase.history ``` *** ### input [Section titled “input”](#input) #### Get Signature [Section titled “Get Signature”](#get-signature-8) ```ts get input(): | string | AgentInputItem[]; ``` A copy of the original input items. ##### Returns [Section titled “Returns”](#returns-9) \| `string` | [`AgentInputItem`](/openai-agents-js/openai/agents/type-aliases/agentinputitem/)\[] #### Inherited from [Section titled “Inherited from”](#inherited-from-5) ```ts RunResultBase.input ``` *** ### inputGuardrailResults [Section titled “inputGuardrailResults”](#inputguardrailresults) #### Get Signature [Section titled “Get Signature”](#get-signature-9) ```ts get inputGuardrailResults(): InputGuardrailResult[]; ``` Guardrail results for the input messages. ##### Returns [Section titled “Returns”](#returns-10) [`InputGuardrailResult`](/openai-agents-js/openai/agents/interfaces/inputguardrailresult/)\[] #### Inherited from [Section titled “Inherited from”](#inherited-from-6) ```ts RunResultBase.inputGuardrailResults ``` *** ### interruptions [Section titled “interruptions”](#interruptions) #### Get Signature [Section titled “Get Signature”](#get-signature-10) ```ts get interruptions(): RunToolApprovalItem[]; ``` Any interruptions that occurred during the agent run for example for tool approvals. ##### Returns [Section titled “Returns”](#returns-11) [`RunToolApprovalItem`](/openai-agents-js/openai/agents/classes/runtoolapprovalitem/)\[] #### Inherited from [Section titled “Inherited from”](#inherited-from-7) ```ts RunResultBase.interruptions ``` *** ### lastAgent [Section titled “lastAgent”](#lastagent) #### Get Signature [Section titled “Get Signature”](#get-signature-11) ```ts get lastAgent(): TAgent | undefined; ``` The last agent that was run ##### Returns [Section titled “Returns”](#returns-12) `TAgent` | `undefined` #### Inherited from [Section titled “Inherited from”](#inherited-from-8) ```ts RunResultBase.lastAgent ``` *** ### lastResponseId [Section titled “lastResponseId”](#lastresponseid) #### Get Signature [Section titled “Get Signature”](#get-signature-12) ```ts get lastResponseId(): string | undefined; ``` The last response ID generated by the model during the agent run. ##### Returns [Section titled “Returns”](#returns-13) `string` | `undefined` #### Inherited from [Section titled “Inherited from”](#inherited-from-9) ```ts RunResultBase.lastResponseId ``` *** ### newItems [Section titled “newItems”](#newitems) #### Get Signature [Section titled “Get Signature”](#get-signature-13) ```ts get newItems(): RunItem[]; ``` The run items generated during the agent run. This associates the model data with the agents. For the model data that can be used as inputs for the next agent run, use the `output` property. ##### Returns [Section titled “Returns”](#returns-14) [`RunItem`](/openai-agents-js/openai/agents/type-aliases/runitem/)\[] #### Inherited from [Section titled “Inherited from”](#inherited-from-10) ```ts RunResultBase.newItems ``` *** ### output [Section titled “output”](#output) #### Get Signature [Section titled “Get Signature”](#get-signature-14) ```ts get output(): AgentOutputItem[]; ``` The new items generated during the agent run. These include things like new messages, tool calls and their outputs, etc. It does not include information about the agents and instead represents the model data. For the output including the agents, use the `newItems` property. ##### Returns [Section titled “Returns”](#returns-15) [`AgentOutputItem`](/openai-agents-js/openai/agents/type-aliases/agentoutputitem/)\[] #### Inherited from [Section titled “Inherited from”](#inherited-from-11) ```ts RunResultBase.output ``` *** ### outputGuardrailResults [Section titled “outputGuardrailResults”](#outputguardrailresults) #### Get Signature [Section titled “Get Signature”](#get-signature-15) ```ts get outputGuardrailResults(): OutputGuardrailResult[]; ``` Guardrail results for the final output of the agent. ##### Returns [Section titled “Returns”](#returns-16) [`OutputGuardrailResult`](/openai-agents-js/openai/agents/interfaces/outputguardrailresult/)<[`OutputGuardrailMetadata`](/openai-agents-js/openai/agents/interfaces/outputguardrailmetadata/), `"text"`>\[] #### Inherited from [Section titled “Inherited from”](#inherited-from-12) ```ts RunResultBase.outputGuardrailResults ``` *** ### rawResponses [Section titled “rawResponses”](#rawresponses) #### Get Signature [Section titled “Get Signature”](#get-signature-16) ```ts get rawResponses(): ModelResponse[]; ``` The raw LLM responses generated by the model during the agent run. ##### Returns [Section titled “Returns”](#returns-17) [`ModelResponse`](/openai-agents-js/openai/agents/type-aliases/modelresponse/)\[] #### Inherited from [Section titled “Inherited from”](#inherited-from-13) ```ts RunResultBase.rawResponses ``` *** ### runContext [Section titled “runContext”](#runcontext) #### Get Signature [Section titled “Get Signature”](#get-signature-17) ```ts get runContext(): RunContext; ``` The public run context for this run. ##### Returns [Section titled “Returns”](#returns-18) [`RunContext`](/openai-agents-js/openai/agents/classes/runcontext/)<`TContext`> #### Inherited from [Section titled “Inherited from”](#inherited-from-14) ```ts RunResultBase.runContext ``` *** ### toolInputGuardrailResults [Section titled “toolInputGuardrailResults”](#toolinputguardrailresults) #### Get Signature [Section titled “Get Signature”](#get-signature-18) ```ts get toolInputGuardrailResults(): ToolInputGuardrailResult[]; ``` Guardrail results for tool inputs. ##### Returns [Section titled “Returns”](#returns-19) [`ToolInputGuardrailResult`](/openai-agents-js/openai/agents/interfaces/toolinputguardrailresult/)\[] #### Inherited from [Section titled “Inherited from”](#inherited-from-15) ```ts RunResultBase.toolInputGuardrailResults ``` *** ### toolOutputGuardrailResults [Section titled “toolOutputGuardrailResults”](#tooloutputguardrailresults) #### Get Signature [Section titled “Get Signature”](#get-signature-19) ```ts get toolOutputGuardrailResults(): ToolOutputGuardrailResult[]; ``` Guardrail results for tool outputs. ##### Returns [Section titled “Returns”](#returns-20) [`ToolOutputGuardrailResult`](/openai-agents-js/openai/agents/interfaces/tooloutputguardrailresult/)\[] #### Inherited from [Section titled “Inherited from”](#inherited-from-16) ```ts RunResultBase.toolOutputGuardrailResults ``` ## Methods [Section titled “Methods”](#methods) ### \[asyncIterator]\() [Section titled “\[asyncIterator\]()”](#asynciterator) ```ts asyncIterator: AsyncIterator; ``` #### Returns [Section titled “Returns”](#returns-21) `AsyncIterator`<[`RunStreamEvent`](/openai-agents-js/openai/agents/type-aliases/runstreamevent/)> #### Implementation of [Section titled “Implementation of”](#implementation-of) ```ts AsyncIterable.[asyncIterator] ``` *** ### toStream() [Section titled “toStream()”](#tostream) ```ts toStream(): ReadableStream; ``` Returns the underlying readable stream. #### Returns [Section titled “Returns”](#returns-22) `ReadableStream`<[`RunStreamEvent`](/openai-agents-js/openai/agents/type-aliases/runstreamevent/)> A readable stream of the agent run. *** ### toTextStream() [Section titled “toTextStream()”](#totextstream) #### Call Signature [Section titled “Call Signature”](#call-signature) ```ts toTextStream(): ReadableStream; ``` Returns a readable stream of the final text output of the agent run. ##### Returns [Section titled “Returns”](#returns-23) `ReadableStream`<`string`> A readable stream of the final output of the agent run. ##### Remarks [Section titled “Remarks”](#remarks) Pass `{ compatibleWithNodeStreams: true }` to receive a Node.js compatible stream instance. #### Call Signature [Section titled “Call Signature”](#call-signature-1) ```ts toTextStream(options?): Readable; ``` Returns a readable stream of the final text output of the agent run. ##### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | ------------------------------------ | ---------------------------------------- | | `options?` | { `compatibleWithNodeStreams`: `true`; } | | `options.compatibleWithNodeStreams?` | `true` | ##### Returns [Section titled “Returns”](#returns-24) `Readable` A readable stream of the final output of the agent run. ##### Remarks [Section titled “Remarks”](#remarks-1) Pass `{ compatibleWithNodeStreams: true }` to receive a Node.js compatible stream instance. #### Call Signature [Section titled “Call Signature”](#call-signature-2) ```ts toTextStream(options?): ReadableStream; ``` Returns a readable stream of the final text output of the agent run. ##### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | ------------------------------------ | ------------------------------------------ | | `options?` | { `compatibleWithNodeStreams?`: `false`; } | | `options.compatibleWithNodeStreams?` | `false` | ##### Returns [Section titled “Returns”](#returns-25) `ReadableStream`<`string`> A readable stream of the final output of the agent run. ##### Remarks [Section titled “Remarks”](#remarks-2) Pass `{ compatibleWithNodeStreams: true }` to receive a Node.js compatible stream instance. # SystemError System error thrown when the library encounters an error that is not caused by the user’s misconfiguration. ## Extends [Section titled “Extends”](#extends) * [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/) ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new SystemError(message, state?): SystemError; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | | `message` | `string` | | `state?` | [`RunState`](/openai-agents-js/openai/agents/classes/runstate/)<`any`, [`Agent`](/openai-agents-js/openai/agents/classes/agent/)<`any`, `any`>> | #### Returns [Section titled “Returns”](#returns) `SystemError` #### Inherited from [Section titled “Inherited from”](#inherited-from) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`constructor`](/openai-agents-js/openai/agents/classes/agentserror/#constructor) ## Properties [Section titled “Properties”](#properties) ### message [Section titled “message”](#message) ```ts message: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-1) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`message`](/openai-agents-js/openai/agents/classes/agentserror/#message) *** ### name [Section titled “name”](#name) ```ts name: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-2) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`name`](/openai-agents-js/openai/agents/classes/agentserror/#name) *** ### stack? [Section titled “stack?”](#stack) ```ts optional stack?: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-3) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`stack`](/openai-agents-js/openai/agents/classes/agentserror/#stack) *** ### state? [Section titled “state?”](#state) ```ts optional state?: RunState>; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-4) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`state`](/openai-agents-js/openai/agents/classes/agentserror/#state) *** ### stackTraceLimit [Section titled “stackTraceLimit”](#stacktracelimit) ```ts static stackTraceLimit: number; ``` The `Error.stackTraceLimit` property specifies the number of stack frames collected by a stack trace (whether generated by `new Error().stack` or `Error.captureStackTrace(obj)`). The default value is `10` but may be set to any valid JavaScript number. Changes will affect any stack trace captured *after* the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames. #### Inherited from [Section titled “Inherited from”](#inherited-from-5) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`stackTraceLimit`](/openai-agents-js/openai/agents/classes/agentserror/#stacktracelimit) ## Methods [Section titled “Methods”](#methods) ### captureStackTrace() [Section titled “captureStackTrace()”](#capturestacktrace) ```ts static captureStackTrace(targetObject, constructorOpt?): void; ``` Creates a `.stack` property on `targetObject`, which when accessed returns a string representing the location in the code at which `Error.captureStackTrace()` was called. ```js const myObject = {}; Error.captureStackTrace(myObject); myObject.stack; // Similar to `new Error().stack` ``` The first line of the trace will be prefixed with `${myObject.name}: ${myObject.message}`. The optional `constructorOpt` argument accepts a function. If given, all frames above `constructorOpt`, including `constructorOpt`, will be omitted from the generated stack trace. The `constructorOpt` argument is useful for hiding implementation details of error generation from the user. For instance: ```js function a() { b(); } function b() { c(); } function c() { // Create an error without stack trace to avoid calculating the stack trace twice. const { stackTraceLimit } = Error; Error.stackTraceLimit = 0; const error = new Error(); Error.stackTraceLimit = stackTraceLimit; // Capture the stack trace above function b Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace throw error; } a(); ``` #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | ----------------- | ---------- | | `targetObject` | `object` | | `constructorOpt?` | `Function` | #### Returns [Section titled “Returns”](#returns-1) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-6) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`captureStackTrace`](/openai-agents-js/openai/agents/classes/agentserror/#capturestacktrace) *** ### prepareStackTrace() [Section titled “prepareStackTrace()”](#preparestacktrace) ```ts static prepareStackTrace(err, stackTraces): any; ``` #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | ------------- | ------------- | | `err` | `Error` | | `stackTraces` | `CallSite`\[] | #### Returns [Section titled “Returns”](#returns-2) `any` #### See [Section titled “See”](#see) #### Inherited from [Section titled “Inherited from”](#inherited-from-7) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`prepareStackTrace`](/openai-agents-js/openai/agents/classes/agentserror/#preparestacktrace) # ToolCallError Error thrown when a tool call fails. ## Extends [Section titled “Extends”](#extends) * [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/) ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new ToolCallError( message, error, state?): ToolCallError; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | | `message` | `string` | | `error` | `Error` | | `state?` | [`RunState`](/openai-agents-js/openai/agents/classes/runstate/)<`any`, [`Agent`](/openai-agents-js/openai/agents/classes/agent/)<`any`, `any`>> | #### Returns [Section titled “Returns”](#returns) `ToolCallError` #### Overrides [Section titled “Overrides”](#overrides) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`constructor`](/openai-agents-js/openai/agents/classes/agentserror/#constructor) ## Properties [Section titled “Properties”](#properties) ### error [Section titled “error”](#error) ```ts error: Error; ``` *** ### message [Section titled “message”](#message) ```ts message: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`message`](/openai-agents-js/openai/agents/classes/agentserror/#message) *** ### name [Section titled “name”](#name) ```ts name: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-1) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`name`](/openai-agents-js/openai/agents/classes/agentserror/#name) *** ### stack? [Section titled “stack?”](#stack) ```ts optional stack?: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-2) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`stack`](/openai-agents-js/openai/agents/classes/agentserror/#stack) *** ### state? [Section titled “state?”](#state) ```ts optional state?: RunState>; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-3) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`state`](/openai-agents-js/openai/agents/classes/agentserror/#state) *** ### stackTraceLimit [Section titled “stackTraceLimit”](#stacktracelimit) ```ts static stackTraceLimit: number; ``` The `Error.stackTraceLimit` property specifies the number of stack frames collected by a stack trace (whether generated by `new Error().stack` or `Error.captureStackTrace(obj)`). The default value is `10` but may be set to any valid JavaScript number. Changes will affect any stack trace captured *after* the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames. #### Inherited from [Section titled “Inherited from”](#inherited-from-4) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`stackTraceLimit`](/openai-agents-js/openai/agents/classes/agentserror/#stacktracelimit) ## Methods [Section titled “Methods”](#methods) ### captureStackTrace() [Section titled “captureStackTrace()”](#capturestacktrace) ```ts static captureStackTrace(targetObject, constructorOpt?): void; ``` Creates a `.stack` property on `targetObject`, which when accessed returns a string representing the location in the code at which `Error.captureStackTrace()` was called. ```js const myObject = {}; Error.captureStackTrace(myObject); myObject.stack; // Similar to `new Error().stack` ``` The first line of the trace will be prefixed with `${myObject.name}: ${myObject.message}`. The optional `constructorOpt` argument accepts a function. If given, all frames above `constructorOpt`, including `constructorOpt`, will be omitted from the generated stack trace. The `constructorOpt` argument is useful for hiding implementation details of error generation from the user. For instance: ```js function a() { b(); } function b() { c(); } function c() { // Create an error without stack trace to avoid calculating the stack trace twice. const { stackTraceLimit } = Error; Error.stackTraceLimit = 0; const error = new Error(); Error.stackTraceLimit = stackTraceLimit; // Capture the stack trace above function b Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace throw error; } a(); ``` #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | ----------------- | ---------- | | `targetObject` | `object` | | `constructorOpt?` | `Function` | #### Returns [Section titled “Returns”](#returns-1) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-5) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`captureStackTrace`](/openai-agents-js/openai/agents/classes/agentserror/#capturestacktrace) *** ### prepareStackTrace() [Section titled “prepareStackTrace()”](#preparestacktrace) ```ts static prepareStackTrace(err, stackTraces): any; ``` #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | ------------- | ------------- | | `err` | `Error` | | `stackTraces` | `CallSite`\[] | #### Returns [Section titled “Returns”](#returns-2) `any` #### See [Section titled “See”](#see) #### Inherited from [Section titled “Inherited from”](#inherited-from-6) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`prepareStackTrace`](/openai-agents-js/openai/agents/classes/agentserror/#preparestacktrace) # ToolInputGuardrailTripwireTriggered Error thrown when a tool input guardrail tripwire is triggered. ## Extends [Section titled “Extends”](#extends) * [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/) ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new ToolInputGuardrailTripwireTriggered( message, result, state?): ToolInputGuardrailTripwireTriggered; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | -------------------------------------------------------------------------------------------------- | | `message` | `string` | | `result` | [`ToolInputGuardrailResult`](/openai-agents-js/openai/agents/interfaces/toolinputguardrailresult/) | | `state?` | [`RunState`](/openai-agents-js/openai/agents/classes/runstate/)<`any`, `any`> | #### Returns [Section titled “Returns”](#returns) `ToolInputGuardrailTripwireTriggered` #### Overrides [Section titled “Overrides”](#overrides) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`constructor`](/openai-agents-js/openai/agents/classes/agentserror/#constructor) ## Properties [Section titled “Properties”](#properties) ### message [Section titled “message”](#message) ```ts message: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`message`](/openai-agents-js/openai/agents/classes/agentserror/#message) *** ### name [Section titled “name”](#name) ```ts name: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-1) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`name`](/openai-agents-js/openai/agents/classes/agentserror/#name) *** ### result [Section titled “result”](#result) ```ts result: ToolInputGuardrailResult; ``` *** ### stack? [Section titled “stack?”](#stack) ```ts optional stack?: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-2) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`stack`](/openai-agents-js/openai/agents/classes/agentserror/#stack) *** ### state? [Section titled “state?”](#state) ```ts optional state?: RunState>; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-3) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`state`](/openai-agents-js/openai/agents/classes/agentserror/#state) *** ### stackTraceLimit [Section titled “stackTraceLimit”](#stacktracelimit) ```ts static stackTraceLimit: number; ``` The `Error.stackTraceLimit` property specifies the number of stack frames collected by a stack trace (whether generated by `new Error().stack` or `Error.captureStackTrace(obj)`). The default value is `10` but may be set to any valid JavaScript number. Changes will affect any stack trace captured *after* the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames. #### Inherited from [Section titled “Inherited from”](#inherited-from-4) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`stackTraceLimit`](/openai-agents-js/openai/agents/classes/agentserror/#stacktracelimit) ## Methods [Section titled “Methods”](#methods) ### captureStackTrace() [Section titled “captureStackTrace()”](#capturestacktrace) ```ts static captureStackTrace(targetObject, constructorOpt?): void; ``` Creates a `.stack` property on `targetObject`, which when accessed returns a string representing the location in the code at which `Error.captureStackTrace()` was called. ```js const myObject = {}; Error.captureStackTrace(myObject); myObject.stack; // Similar to `new Error().stack` ``` The first line of the trace will be prefixed with `${myObject.name}: ${myObject.message}`. The optional `constructorOpt` argument accepts a function. If given, all frames above `constructorOpt`, including `constructorOpt`, will be omitted from the generated stack trace. The `constructorOpt` argument is useful for hiding implementation details of error generation from the user. For instance: ```js function a() { b(); } function b() { c(); } function c() { // Create an error without stack trace to avoid calculating the stack trace twice. const { stackTraceLimit } = Error; Error.stackTraceLimit = 0; const error = new Error(); Error.stackTraceLimit = stackTraceLimit; // Capture the stack trace above function b Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace throw error; } a(); ``` #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | ----------------- | ---------- | | `targetObject` | `object` | | `constructorOpt?` | `Function` | #### Returns [Section titled “Returns”](#returns-1) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-5) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`captureStackTrace`](/openai-agents-js/openai/agents/classes/agentserror/#capturestacktrace) *** ### prepareStackTrace() [Section titled “prepareStackTrace()”](#preparestacktrace) ```ts static prepareStackTrace(err, stackTraces): any; ``` #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | ------------- | ------------- | | `err` | `Error` | | `stackTraces` | `CallSite`\[] | #### Returns [Section titled “Returns”](#returns-2) `any` #### See [Section titled “See”](#see) #### Inherited from [Section titled “Inherited from”](#inherited-from-6) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`prepareStackTrace`](/openai-agents-js/openai/agents/classes/agentserror/#preparestacktrace) # ToolOutputGuardrailTripwireTriggered Error thrown when a tool output guardrail tripwire is triggered. ## Extends [Section titled “Extends”](#extends) * [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/) ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new ToolOutputGuardrailTripwireTriggered( message, result, state?): ToolOutputGuardrailTripwireTriggered; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ---------------------------------------------------------------------------------------------------- | | `message` | `string` | | `result` | [`ToolOutputGuardrailResult`](/openai-agents-js/openai/agents/interfaces/tooloutputguardrailresult/) | | `state?` | [`RunState`](/openai-agents-js/openai/agents/classes/runstate/)<`any`, `any`> | #### Returns [Section titled “Returns”](#returns) `ToolOutputGuardrailTripwireTriggered` #### Overrides [Section titled “Overrides”](#overrides) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`constructor`](/openai-agents-js/openai/agents/classes/agentserror/#constructor) ## Properties [Section titled “Properties”](#properties) ### message [Section titled “message”](#message) ```ts message: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`message`](/openai-agents-js/openai/agents/classes/agentserror/#message) *** ### name [Section titled “name”](#name) ```ts name: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-1) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`name`](/openai-agents-js/openai/agents/classes/agentserror/#name) *** ### result [Section titled “result”](#result) ```ts result: ToolOutputGuardrailResult; ``` *** ### stack? [Section titled “stack?”](#stack) ```ts optional stack?: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-2) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`stack`](/openai-agents-js/openai/agents/classes/agentserror/#stack) *** ### state? [Section titled “state?”](#state) ```ts optional state?: RunState>; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-3) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`state`](/openai-agents-js/openai/agents/classes/agentserror/#state) *** ### stackTraceLimit [Section titled “stackTraceLimit”](#stacktracelimit) ```ts static stackTraceLimit: number; ``` The `Error.stackTraceLimit` property specifies the number of stack frames collected by a stack trace (whether generated by `new Error().stack` or `Error.captureStackTrace(obj)`). The default value is `10` but may be set to any valid JavaScript number. Changes will affect any stack trace captured *after* the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames. #### Inherited from [Section titled “Inherited from”](#inherited-from-4) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`stackTraceLimit`](/openai-agents-js/openai/agents/classes/agentserror/#stacktracelimit) ## Methods [Section titled “Methods”](#methods) ### captureStackTrace() [Section titled “captureStackTrace()”](#capturestacktrace) ```ts static captureStackTrace(targetObject, constructorOpt?): void; ``` Creates a `.stack` property on `targetObject`, which when accessed returns a string representing the location in the code at which `Error.captureStackTrace()` was called. ```js const myObject = {}; Error.captureStackTrace(myObject); myObject.stack; // Similar to `new Error().stack` ``` The first line of the trace will be prefixed with `${myObject.name}: ${myObject.message}`. The optional `constructorOpt` argument accepts a function. If given, all frames above `constructorOpt`, including `constructorOpt`, will be omitted from the generated stack trace. The `constructorOpt` argument is useful for hiding implementation details of error generation from the user. For instance: ```js function a() { b(); } function b() { c(); } function c() { // Create an error without stack trace to avoid calculating the stack trace twice. const { stackTraceLimit } = Error; Error.stackTraceLimit = 0; const error = new Error(); Error.stackTraceLimit = stackTraceLimit; // Capture the stack trace above function b Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace throw error; } a(); ``` #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | ----------------- | ---------- | | `targetObject` | `object` | | `constructorOpt?` | `Function` | #### Returns [Section titled “Returns”](#returns-1) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-5) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`captureStackTrace`](/openai-agents-js/openai/agents/classes/agentserror/#capturestacktrace) *** ### prepareStackTrace() [Section titled “prepareStackTrace()”](#preparestacktrace) ```ts static prepareStackTrace(err, stackTraces): any; ``` #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | ------------- | ------------- | | `err` | `Error` | | `stackTraces` | `CallSite`\[] | #### Returns [Section titled “Returns”](#returns-2) `any` #### See [Section titled “See”](#see) #### Inherited from [Section titled “Inherited from”](#inherited-from-6) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`prepareStackTrace`](/openai-agents-js/openai/agents/classes/agentserror/#preparestacktrace) # ToolTimeoutError Error thrown when a function tool invocation exceeds its timeout. ## Extends [Section titled “Extends”](#extends) * [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/) ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new ToolTimeoutError(__namedParameters): ToolTimeoutError; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ----------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `__namedParameters` | { `state?`: [`RunState`](/openai-agents-js/openai/agents/classes/runstate/)<`any`, [`Agent`](/openai-agents-js/openai/agents/classes/agent/)<`any`, `any`>>; `timeoutMs`: `number`; `toolName`: `string`; } | | `__namedParameters.state?` | [`RunState`](/openai-agents-js/openai/agents/classes/runstate/)<`any`, [`Agent`](/openai-agents-js/openai/agents/classes/agent/)<`any`, `any`>> | | `__namedParameters.timeoutMs` | `number` | | `__namedParameters.toolName` | `string` | #### Returns [Section titled “Returns”](#returns) `ToolTimeoutError` #### Overrides [Section titled “Overrides”](#overrides) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`constructor`](/openai-agents-js/openai/agents/classes/agentserror/#constructor) ## Properties [Section titled “Properties”](#properties) ### message [Section titled “message”](#message) ```ts message: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`message`](/openai-agents-js/openai/agents/classes/agentserror/#message) *** ### name [Section titled “name”](#name) ```ts name: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-1) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`name`](/openai-agents-js/openai/agents/classes/agentserror/#name) *** ### stack? [Section titled “stack?”](#stack) ```ts optional stack?: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-2) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`stack`](/openai-agents-js/openai/agents/classes/agentserror/#stack) *** ### state? [Section titled “state?”](#state) ```ts optional state?: RunState>; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-3) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`state`](/openai-agents-js/openai/agents/classes/agentserror/#state) *** ### timeoutMs [Section titled “timeoutMs”](#timeoutms) ```ts timeoutMs: number; ``` *** ### toolName [Section titled “toolName”](#toolname) ```ts toolName: string; ``` *** ### stackTraceLimit [Section titled “stackTraceLimit”](#stacktracelimit) ```ts static stackTraceLimit: number; ``` The `Error.stackTraceLimit` property specifies the number of stack frames collected by a stack trace (whether generated by `new Error().stack` or `Error.captureStackTrace(obj)`). The default value is `10` but may be set to any valid JavaScript number. Changes will affect any stack trace captured *after* the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames. #### Inherited from [Section titled “Inherited from”](#inherited-from-4) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`stackTraceLimit`](/openai-agents-js/openai/agents/classes/agentserror/#stacktracelimit) ## Methods [Section titled “Methods”](#methods) ### captureStackTrace() [Section titled “captureStackTrace()”](#capturestacktrace) ```ts static captureStackTrace(targetObject, constructorOpt?): void; ``` Creates a `.stack` property on `targetObject`, which when accessed returns a string representing the location in the code at which `Error.captureStackTrace()` was called. ```js const myObject = {}; Error.captureStackTrace(myObject); myObject.stack; // Similar to `new Error().stack` ``` The first line of the trace will be prefixed with `${myObject.name}: ${myObject.message}`. The optional `constructorOpt` argument accepts a function. If given, all frames above `constructorOpt`, including `constructorOpt`, will be omitted from the generated stack trace. The `constructorOpt` argument is useful for hiding implementation details of error generation from the user. For instance: ```js function a() { b(); } function b() { c(); } function c() { // Create an error without stack trace to avoid calculating the stack trace twice. const { stackTraceLimit } = Error; Error.stackTraceLimit = 0; const error = new Error(); Error.stackTraceLimit = stackTraceLimit; // Capture the stack trace above function b Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace throw error; } a(); ``` #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | ----------------- | ---------- | | `targetObject` | `object` | | `constructorOpt?` | `Function` | #### Returns [Section titled “Returns”](#returns-1) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-5) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`captureStackTrace`](/openai-agents-js/openai/agents/classes/agentserror/#capturestacktrace) *** ### prepareStackTrace() [Section titled “prepareStackTrace()”](#preparestacktrace) ```ts static prepareStackTrace(err, stackTraces): any; ``` #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | ------------- | ------------- | | `err` | `Error` | | `stackTraces` | `CallSite`\[] | #### Returns [Section titled “Returns”](#returns-2) `any` #### See [Section titled “See”](#see) #### Inherited from [Section titled “Inherited from”](#inherited-from-6) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`prepareStackTrace`](/openai-agents-js/openai/agents/classes/agentserror/#preparestacktrace) # Trace ## Extended by [Section titled “Extended by”](#extended-by) * [`NoopTrace`](/openai-agents-js/openai/agents/classes/nooptrace/) ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new Trace(options, processor?): Trace; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ------------ | ---------------------------------------------------------------------------------- | | `options` | `TraceOptions` | | `processor?` | [`TracingProcessor`](/openai-agents-js/openai/agents/interfaces/tracingprocessor/) | #### Returns [Section titled “Returns”](#returns) `Trace` ## Properties [Section titled “Properties”](#properties) ### groupId [Section titled “groupId”](#groupid) ```ts groupId: string | null; ``` *** ### metadata? [Section titled “metadata?”](#metadata) ```ts optional metadata?: Record; ``` *** ### name [Section titled “name”](#name) ```ts name: string; ``` *** ### traceId [Section titled “traceId”](#traceid) ```ts traceId: string; ``` *** ### tracingApiKey? [Section titled “tracingApiKey?”](#tracingapikey) ```ts optional tracingApiKey?: string; ``` *** ### type [Section titled “type”](#type) ```ts type: "trace"; ``` ## Methods [Section titled “Methods”](#methods) ### clone() [Section titled “clone()”](#clone) ```ts clone(): Trace; ``` #### Returns [Section titled “Returns”](#returns-1) `Trace` *** ### end() [Section titled “end()”](#end) ```ts end(): Promise; ``` #### Returns [Section titled “Returns”](#returns-2) `Promise`<`void`> *** ### start() [Section titled “start()”](#start) ```ts start(): Promise; ``` #### Returns [Section titled “Returns”](#returns-3) `Promise`<`void`> *** ### toJSON() [Section titled “toJSON()”](#tojson) ```ts toJSON(options?): object | null; ``` Serializes the trace for export or persistence. Set `includeTracingApiKey` to true only when you intentionally need to persist the exporter credentials (for example, when handing off a run to another process that cannot access the original environment). Defaults to false to avoid leaking secrets. #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | ------------------------------- | --------------------------------------- | | `options?` | { `includeTracingApiKey?`: `boolean`; } | | `options.includeTracingApiKey?` | `boolean` | #### Returns [Section titled “Returns”](#returns-4) `object` | `null` # TraceProvider ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new TraceProvider(): TraceProvider; ``` #### Returns [Section titled “Returns”](#returns) `TraceProvider` ## Methods [Section titled “Methods”](#methods) ### createSpan() [Section titled “createSpan()”](#createspan) ```ts createSpan(spanOptions, parent?): Span; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | ------------------------------------------------------------------------------------------ | | `TSpanData` *extends* [`SpanData`](/openai-agents-js/openai/agents/type-aliases/spandata/) | #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ------------- | ------------------------------------------------------------------------------------------------------------------------------ | | `spanOptions` | `CreateSpanOptions`<`TSpanData`> | | `parent?` | \| [`Span`](/openai-agents-js/openai/agents/classes/span/)<`any`> \| [`Trace`](/openai-agents-js/openai/agents/classes/trace/) | #### Returns [Section titled “Returns”](#returns-1) [`Span`](/openai-agents-js/openai/agents/classes/span/)<`TSpanData`> *** ### createTrace() [Section titled “createTrace()”](#createtrace) ```ts createTrace(traceOptions): Trace; ``` #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | -------------- | -------------- | | `traceOptions` | `TraceOptions` | #### Returns [Section titled “Returns”](#returns-2) [`Trace`](/openai-agents-js/openai/agents/classes/trace/) *** ### forceFlush() [Section titled “forceFlush()”](#forceflush) ```ts forceFlush(): Promise; ``` #### Returns [Section titled “Returns”](#returns-3) `Promise`<`void`> *** ### getCurrentSpan() [Section titled “getCurrentSpan()”](#getcurrentspan) ```ts getCurrentSpan(): Span | null; ``` #### Returns [Section titled “Returns”](#returns-4) [`Span`](/openai-agents-js/openai/agents/classes/span/)<`any`> | `null` *** ### getCurrentTrace() [Section titled “getCurrentTrace()”](#getcurrenttrace) ```ts getCurrentTrace(): Trace | null; ``` Get the current trace. #### Returns [Section titled “Returns”](#returns-5) [`Trace`](/openai-agents-js/openai/agents/classes/trace/) | `null` The current trace. *** ### registerProcessor() [Section titled “registerProcessor()”](#registerprocessor) ```ts registerProcessor(processor): void; ``` Add a processor to the list of processors. Each processor will receive all traces/spans. #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | Description | | ----------- | ---------------------------------------------------------------------------------- | --------------------- | | `processor` | [`TracingProcessor`](/openai-agents-js/openai/agents/interfaces/tracingprocessor/) | The processor to add. | #### Returns [Section titled “Returns”](#returns-6) `void` *** ### setDisabled() [Section titled “setDisabled()”](#setdisabled) ```ts setDisabled(disabled): void; ``` #### Parameters [Section titled “Parameters”](#parameters-3) | Parameter | Type | | ---------- | --------- | | `disabled` | `boolean` | #### Returns [Section titled “Returns”](#returns-7) `void` *** ### setProcessors() [Section titled “setProcessors()”](#setprocessors) ```ts setProcessors(processors): void; ``` Set the list of processors. This will replace any existing processors. #### Parameters [Section titled “Parameters”](#parameters-4) | Parameter | Type | Description | | ------------ | ------------------------------------------------------------------------------------- | ------------------------------ | | `processors` | [`TracingProcessor`](/openai-agents-js/openai/agents/interfaces/tracingprocessor/)\[] | The list of processors to set. | #### Returns [Section titled “Returns”](#returns-8) `void` *** ### shutdown() [Section titled “shutdown()”](#shutdown) ```ts shutdown(timeout?): Promise; ``` #### Parameters [Section titled “Parameters”](#parameters-5) | Parameter | Type | | ---------- | -------- | | `timeout?` | `number` | #### Returns [Section titled “Returns”](#returns-9) `Promise`<`void`> *** ### startExportLoop() [Section titled “startExportLoop()”](#startexportloop) ```ts startExportLoop(): void; ``` #### Returns [Section titled “Returns”](#returns-10) `void` # Usage Tracks token usage and request counts for an agent run. ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new Usage(input?): Usage; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ------------ | | `input?` | `UsageInput` | #### Returns [Section titled “Returns”](#returns) `Usage` ## Properties [Section titled “Properties”](#properties) ### inputTokens [Section titled “inputTokens”](#inputtokens) ```ts inputTokens: number; ``` The number of input tokens used across all requests. *** ### inputTokensDetails [Section titled “inputTokensDetails”](#inputtokensdetails) ```ts inputTokensDetails: Record[]; ``` Details about the input tokens used across all requests. *** ### outputTokens [Section titled “outputTokens”](#outputtokens) ```ts outputTokens: number; ``` The number of output tokens used across all requests. *** ### outputTokensDetails [Section titled “outputTokensDetails”](#outputtokensdetails) ```ts outputTokensDetails: Record[]; ``` Details about the output tokens used across all requests. *** ### requests [Section titled “requests”](#requests) ```ts requests: number; ``` The number of requests made to the LLM API. *** ### requestUsageEntries [Section titled “requestUsageEntries”](#requestusageentries) ```ts requestUsageEntries: | RequestUsage[] | undefined; ``` List of per-request usage entries for detailed cost calculations. *** ### totalTokens [Section titled “totalTokens”](#totaltokens) ```ts totalTokens: number; ``` The total number of tokens sent and received, across all requests. ## Methods [Section titled “Methods”](#methods) ### add() [Section titled “add()”](#add) ```ts add(newUsage): void; ``` #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | ---------- | ------- | | `newUsage` | `Usage` | #### Returns [Section titled “Returns”](#returns-1) `void` # UserError Error thrown when the error is caused by the library user’s misconfiguration. ## Extends [Section titled “Extends”](#extends) * [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/) ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new UserError(message, state?): UserError; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | | `message` | `string` | | `state?` | [`RunState`](/openai-agents-js/openai/agents/classes/runstate/)<`any`, [`Agent`](/openai-agents-js/openai/agents/classes/agent/)<`any`, `any`>> | #### Returns [Section titled “Returns”](#returns) `UserError` #### Inherited from [Section titled “Inherited from”](#inherited-from) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`constructor`](/openai-agents-js/openai/agents/classes/agentserror/#constructor) ## Properties [Section titled “Properties”](#properties) ### message [Section titled “message”](#message) ```ts message: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-1) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`message`](/openai-agents-js/openai/agents/classes/agentserror/#message) *** ### name [Section titled “name”](#name) ```ts name: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-2) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`name`](/openai-agents-js/openai/agents/classes/agentserror/#name) *** ### stack? [Section titled “stack?”](#stack) ```ts optional stack?: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-3) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`stack`](/openai-agents-js/openai/agents/classes/agentserror/#stack) *** ### state? [Section titled “state?”](#state) ```ts optional state?: RunState>; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-4) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`state`](/openai-agents-js/openai/agents/classes/agentserror/#state) *** ### stackTraceLimit [Section titled “stackTraceLimit”](#stacktracelimit) ```ts static stackTraceLimit: number; ``` The `Error.stackTraceLimit` property specifies the number of stack frames collected by a stack trace (whether generated by `new Error().stack` or `Error.captureStackTrace(obj)`). The default value is `10` but may be set to any valid JavaScript number. Changes will affect any stack trace captured *after* the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames. #### Inherited from [Section titled “Inherited from”](#inherited-from-5) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`stackTraceLimit`](/openai-agents-js/openai/agents/classes/agentserror/#stacktracelimit) ## Methods [Section titled “Methods”](#methods) ### captureStackTrace() [Section titled “captureStackTrace()”](#capturestacktrace) ```ts static captureStackTrace(targetObject, constructorOpt?): void; ``` Creates a `.stack` property on `targetObject`, which when accessed returns a string representing the location in the code at which `Error.captureStackTrace()` was called. ```js const myObject = {}; Error.captureStackTrace(myObject); myObject.stack; // Similar to `new Error().stack` ``` The first line of the trace will be prefixed with `${myObject.name}: ${myObject.message}`. The optional `constructorOpt` argument accepts a function. If given, all frames above `constructorOpt`, including `constructorOpt`, will be omitted from the generated stack trace. The `constructorOpt` argument is useful for hiding implementation details of error generation from the user. For instance: ```js function a() { b(); } function b() { c(); } function c() { // Create an error without stack trace to avoid calculating the stack trace twice. const { stackTraceLimit } = Error; Error.stackTraceLimit = 0; const error = new Error(); Error.stackTraceLimit = stackTraceLimit; // Capture the stack trace above function b Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace throw error; } a(); ``` #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | ----------------- | ---------- | | `targetObject` | `object` | | `constructorOpt?` | `Function` | #### Returns [Section titled “Returns”](#returns-1) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-6) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`captureStackTrace`](/openai-agents-js/openai/agents/classes/agentserror/#capturestacktrace) *** ### prepareStackTrace() [Section titled “prepareStackTrace()”](#preparestacktrace) ```ts static prepareStackTrace(err, stackTraces): any; ``` #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | ------------- | ------------- | | `err` | `Error` | | `stackTraces` | `CallSite`\[] | #### Returns [Section titled “Returns”](#returns-2) `any` #### See [Section titled “See”](#see) #### Inherited from [Section titled “Inherited from”](#inherited-from-7) [`AgentsError`](/openai-agents-js/openai/agents/classes/agentserror/).[`prepareStackTrace`](/openai-agents-js/openai/agents/classes/agentserror/#preparestacktrace) # addTraceProcessor ```ts function addTraceProcessor(processor): void; ``` Add a processor to the list of processors. Each processor will receive all traces/spans. ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | ----------- | ---------------------------------------------------------------------------------- | --------------------- | | `processor` | [`TracingProcessor`](/openai-agents-js/openai/agents/interfaces/tracingprocessor/) | The processor to add. | ## Returns [Section titled “Returns”](#returns) `void` # applyDiff ```ts function applyDiff( input, diff, mode?): string; ``` Applies a headerless V4A diff to the provided file content. * mode “default”: patch an existing file using V4A sections (”@@” + +/-/space lines). * mode “create”: create-file syntax that requires every line to start with ”+”. The function preserves trailing newlines from the original file and throws when the diff cannot be applied cleanly. ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ------------------------- | | `input` | `string` | | `diff` | `string` | | `mode?` | `"default"` \| `"create"` | ## Returns [Section titled “Returns”](#returns) `string` # applyPatchTool ```ts function applyPatchTool(options): ApplyPatchTool; ``` ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- | | `options` | `Partial`<`Omit`<[`ApplyPatchTool`](/openai-agents-js/openai/agents/type-aliases/applypatchtool/), `"type"` \| `"editor"` \| `"needsApproval"`>> & `object` | ## Returns [Section titled “Returns”](#returns) [`ApplyPatchTool`](/openai-agents-js/openai/agents/type-aliases/applypatchtool/) # applySessionHistoryMutations ```ts function applySessionHistoryMutations(items, mutations): AgentInputItem[]; ``` Applies persisted-history mutations and returns a new canonical item list. ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ----------- | ----------------------------------------------------------------------------------- | | `items` | [`AgentInputItem`](/openai-agents-js/openai/agents/type-aliases/agentinputitem/)\[] | | `mutations` | `SessionHistoryReplaceFunctionCallMutation`\[] | ## Returns [Section titled “Returns”](#returns) [`AgentInputItem`](/openai-agents-js/openai/agents/type-aliases/agentinputitem/)\[] # assistant ```ts function assistant(content, options?): object; ``` Creates an assistant message entry for example for multi-shot prompting ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | ---------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------- | | `content` | \| `string` \| ( \| { `providerData?`: `Record`<`string`, `any`>; `text`: `string`; `type`: `"output_text"`; } \| { `providerData?`: `Record`<`string`, `any`>; `refusal`: `string`; `type`: `"refusal"`; } \| { `audio`: \| `string` \| { `id`: `string`; }; `format?`: `string` \| `null`; `providerData?`: `Record`<`string`, `any`>; `transcript?`: `string` \| `null`; `type`: `"audio"`; } \| { `image`: `string`; `providerData?`: `Record`<`string`, `any`>; `type`: `"image"`; })\[] | The assistant response. | | `options?` | `Record`<`string`, `any`> | Any additional options that will be directly passed to the model. | ## Returns [Section titled “Returns”](#returns) `object` A message entry. ### content [Section titled “content”](#content) ```ts content: ( | { providerData?: Record; text: string; type: "output_text"; } | { providerData?: Record; refusal: string; type: "refusal"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; } | { image: string; providerData?: Record; type: "image"; })[]; ``` ### id? [Section titled “id?”](#id) ```ts optional id?: string; ``` ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` ### role [Section titled “role”](#role) ```ts role: "assistant"; ``` ### status [Section titled “status”](#status) ```ts status: "completed" | "in_progress" | "incomplete"; ``` ### type? [Section titled “type?”](#type) ```ts optional type?: "message"; ``` # attachClientToolSearchExecutor ```ts function attachClientToolSearchExecutor(tool, executor): HostedTool; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | ------------ | | `Context` | `unknown` | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ---------- | --------------------------------------------------------------------------------------------------------------- | | `tool` | [`HostedTool`](/openai-agents-js/openai/agents/type-aliases/hostedtool/) | | `executor` | [`ClientToolSearchExecutor`](/openai-agents-js/openai/agents/type-aliases/clienttoolsearchexecutor/)<`Context`> | ## Returns [Section titled “Returns”](#returns) [`HostedTool`](/openai-agents-js/openai/agents/type-aliases/hostedtool/) # codeInterpreterTool ```ts function codeInterpreterTool(options?): HostedTool; ``` Adds code interpreter abilities to your agent ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | ---------- | -------------------------------------------------- | ------------------------------------------------- | | `options?` | `Partial`<`Omit`<`CodeInterpreterTool`, `"type"`>> | Additional configuration for the code interpreter | ## Returns [Section titled “Returns”](#returns) [`HostedTool`](/openai-agents-js/openai/agents/type-aliases/hostedtool/) a code interpreter tool definition # computerTool ```ts function computerTool(options): ComputerTool; ``` Exposes a computer to the agent as a tool to be called. ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | ------------------------------ | ------------ | | `Context` | `unknown` | | `TComputer` *extends* `object` | `object` | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------- | | `options` | { `computer`: `ComputerConfig`<`Context`, `TComputer`>; `name?`: `string`; `needsApproval?`: `boolean` \| `ComputerApprovalFunction`; `onSafetyCheck?`: [`ComputerOnSafetyCheckFunction`](/openai-agents-js/openai/agents/type-aliases/computeronsafetycheckfunction/); } | Additional configuration for the computer tool like specifying the location of your agent | | `options.computer` | `ComputerConfig`<`Context`, `TComputer`> | ‐ | | `options.name?` | `string` | ‐ | | `options.needsApproval?` | `boolean` \| `ComputerApprovalFunction` | ‐ | | `options.onSafetyCheck?` | [`ComputerOnSafetyCheckFunction`](/openai-agents-js/openai/agents/type-aliases/computeronsafetycheckfunction/) | ‐ | ## Returns [Section titled “Returns”](#returns) [`ComputerTool`](/openai-agents-js/openai/agents/type-aliases/computertool/)<`Context`, `TComputer`> a computer tool definition # connectMcpServers ```ts function connectMcpServers(servers, options?): Promise; ``` Connect to multiple MCP servers and return a managed MCPServers instance. ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ---------- | -------------------------------------------------------------------------------------- | | `servers` | [`MCPServer`](/openai-agents-js/openai/agents/interfaces/mcpserver/)\[] | | `options?` | [`MCPServersOptions`](/openai-agents-js/openai/agents/type-aliases/mcpserversoptions/) | ## Returns [Section titled “Returns”](#returns) `Promise`<[`MCPServers`](/openai-agents-js/openai/agents/classes/mcpservers/)> # createAgentSpan ```ts function createAgentSpan(options?, parent?): Span; ``` Create a new agent span. The span will not be started automatically, you should either use `withAgentSpan()` or call `span.start()` and `span.end()` manually. ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | ---------- | ------------------------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------- | | `options?` | `DeepPartial`<`CreateSpanOptions`<[`AgentSpanData`](/openai-agents-js/openai/agents/type-aliases/agentspandata/)>> | Optional span creation options, including span data and identifiers. | | `parent?` | \| [`Span`](/openai-agents-js/openai/agents/classes/span/)<`any`> \| [`Trace`](/openai-agents-js/openai/agents/classes/trace/) | The parent span or trace. If not provided, the current trace/span will be used automatically. | ## Returns [Section titled “Returns”](#returns) [`Span`](/openai-agents-js/openai/agents/classes/span/)<[`AgentSpanData`](/openai-agents-js/openai/agents/type-aliases/agentspandata/)> The newly created agent span. # createCustomSpan ```ts function createCustomSpan(options, parent?): Span; ``` Create a new custom span. The span will not be started automatically, you should either use `withCustomSpan()` or call `span.start()` and `span.end()` manually. ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ------------------------------------------------------------------------------------------------------------------------------- | | `options` | `DeepPartial`<`CreateSpanOptions`<[`CustomSpanData`](/openai-agents-js/openai/agents/type-aliases/customspandata/)>> & `object` | | `parent?` | \| [`Span`](/openai-agents-js/openai/agents/classes/span/)<`any`> \| [`Trace`](/openai-agents-js/openai/agents/classes/trace/) | ## Returns [Section titled “Returns”](#returns) [`Span`](/openai-agents-js/openai/agents/classes/span/)<[`CustomSpanData`](/openai-agents-js/openai/agents/type-aliases/customspandata/)> # createFunctionSpan ```ts function createFunctionSpan(options, parent?): Span; ``` Create a new function span. The span will not be started automatically, you should either use `withFunctionSpan()` or call `span.start()` and `span.end()` manually. ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | --------- | ----------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------- | | `options` | `DeepPartial`<`CreateSpanOptions`<[`FunctionSpanData`](/openai-agents-js/openai/agents/type-aliases/functionspandata/)>> & `object` | Optional span creation options, including span data and identifiers. | | `parent?` | \| [`Span`](/openai-agents-js/openai/agents/classes/span/)<`any`> \| [`Trace`](/openai-agents-js/openai/agents/classes/trace/) | The parent span or trace. If not provided, the current trace/span will be used automatically. | ## Returns [Section titled “Returns”](#returns) [`Span`](/openai-agents-js/openai/agents/classes/span/)<[`FunctionSpanData`](/openai-agents-js/openai/agents/type-aliases/functionspandata/)> The newly created function span. # createGenerationSpan ```ts function createGenerationSpan(options?, parent?): Span; ``` Create a new generation span. The span will not be started automatically, you should either use `withGenerationSpan()` or call `span.start()` and `span.end()` manually. This span captures the details of a model generation, including input/output message sequences, model information, and usage data. If you only need to capture a model response identifier, consider using `createResponseSpan()` instead. agents-core keeps generation usage payloads as provided. Backend-specific schema constraints are enforced by each exporter. For example, the OpenAI tracing exporter in `@openai/agents-openai` keeps top-level usage to `input_tokens` and `output_tokens` for OpenAI traces ingest, and maps additional usage fields under `usage.details`. Third-party exporters can apply their own mapping. ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ---------- | ------------------------------------------------------------------------------------------------------------------------------ | | `options?` | `DeepPartial`<`CreateSpanOptions`<[`GenerationSpanData`](/openai-agents-js/openai/agents/type-aliases/generationspandata/)>> | | `parent?` | \| [`Span`](/openai-agents-js/openai/agents/classes/span/)<`any`> \| [`Trace`](/openai-agents-js/openai/agents/classes/trace/) | ## Returns [Section titled “Returns”](#returns) [`Span`](/openai-agents-js/openai/agents/classes/span/)<[`GenerationSpanData`](/openai-agents-js/openai/agents/type-aliases/generationspandata/)> # createGuardrailSpan ```ts function createGuardrailSpan(options, parent?): Span; ``` Create a new guardrail span. The span will not be started automatically, you should either use `withGuardrailSpan()` or call `span.start()` and `span.end()` manually. ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ------------------------------------------------------------------------------------------------------------------------------------- | | `options` | `DeepPartial`<`CreateSpanOptions`<[`GuardrailSpanData`](/openai-agents-js/openai/agents/type-aliases/guardrailspandata/)>> & `object` | | `parent?` | \| [`Span`](/openai-agents-js/openai/agents/classes/span/)<`any`> \| [`Trace`](/openai-agents-js/openai/agents/classes/trace/) | ## Returns [Section titled “Returns”](#returns) [`Span`](/openai-agents-js/openai/agents/classes/span/)<[`GuardrailSpanData`](/openai-agents-js/openai/agents/type-aliases/guardrailspandata/)> # createHandoffSpan ```ts function createHandoffSpan(options?, parent?): Span; ``` Create a new handoff span. The span will not be started automatically, you should either use `withHandoffSpan()` or call `span.start()` and `span.end()` manually. ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | ---------- | ------------------------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------- | | `options?` | `DeepPartial`<`CreateSpanOptions`<[`HandoffSpanData`](/openai-agents-js/openai/agents/type-aliases/handoffspandata/)>> | Optional span creation options, including span data and identifiers. | | `parent?` | \| [`Span`](/openai-agents-js/openai/agents/classes/span/)<`any`> \| [`Trace`](/openai-agents-js/openai/agents/classes/trace/) | The parent span or trace. If not provided, the current trace/span will be used automatically. | ## Returns [Section titled “Returns”](#returns) [`Span`](/openai-agents-js/openai/agents/classes/span/)<[`HandoffSpanData`](/openai-agents-js/openai/agents/type-aliases/handoffspandata/)> The newly created handoff span. # createMCPListToolsSpan ```ts function createMCPListToolsSpan(options?, parent?): Span; ``` Create a new MCP list tools span. The span will not be started automatically. ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ---------- | -------------------------------------------------------------------------------------------------------------------------------- | | `options?` | `DeepPartial`<`CreateSpanOptions`<[`MCPListToolsSpanData`](/openai-agents-js/openai/agents/type-aliases/mcplisttoolsspandata/)>> | | `parent?` | \| [`Span`](/openai-agents-js/openai/agents/classes/span/)<`any`> \| [`Trace`](/openai-agents-js/openai/agents/classes/trace/) | ## Returns [Section titled “Returns”](#returns) [`Span`](/openai-agents-js/openai/agents/classes/span/)<[`MCPListToolsSpanData`](/openai-agents-js/openai/agents/type-aliases/mcplisttoolsspandata/)> # createMCPToolStaticFilter ```ts function createMCPToolStaticFilter(options?): | MCPToolFilterStatic | undefined; ``` Convenience helper to create a static tool filter. ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ------------------ | ----------------------------------------------------- | | `options?` | { `allowed?`: `string`\[]; `blocked?`: `string`\[]; } | | `options.allowed?` | `string`\[] | | `options.blocked?` | `string`\[] | ## Returns [Section titled “Returns”](#returns) \| [`MCPToolFilterStatic`](/openai-agents-js/openai/agents/interfaces/mcptoolfilterstatic/) | `undefined` # createResponseSpan ```ts function createResponseSpan(options?, parent?): Span; ``` Create a new response span. The span will not be started automatically, you should either use `withResponseSpan()` or call `span.start()` and `span.end()` manually. This span captures the details of a model response, primarily the response identifier. If you need to capture detailed generation information such as input/output messages, model configuration, or usage data, use `createGenerationSpan()` instead. ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | ---------- | ------------------------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------- | | `options?` | `DeepPartial`<`CreateSpanOptions`<[`ResponseSpanData`](/openai-agents-js/openai/agents/type-aliases/responsespandata/)>> | Optional span creation options, including span data and identifiers. | | `parent?` | \| [`Span`](/openai-agents-js/openai/agents/classes/span/)<`any`> \| [`Trace`](/openai-agents-js/openai/agents/classes/trace/) | The parent span or trace. If not provided, the current trace/span will be used automatically. | ## Returns [Section titled “Returns”](#returns) [`Span`](/openai-agents-js/openai/agents/classes/span/)<[`ResponseSpanData`](/openai-agents-js/openai/agents/type-aliases/responsespandata/)> The newly created response span. # createSpeechGroupSpan ```ts function createSpeechGroupSpan(options?, parent?): Span; ``` Create a new speech group span. The span will not be started automatically. ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ---------- | ------------------------------------------------------------------------------------------------------------------------------ | | `options?` | `DeepPartial`<`CreateSpanOptions`<[`SpeechGroupSpanData`](/openai-agents-js/openai/agents/type-aliases/speechgroupspandata/)>> | | `parent?` | \| [`Span`](/openai-agents-js/openai/agents/classes/span/)<`any`> \| [`Trace`](/openai-agents-js/openai/agents/classes/trace/) | ## Returns [Section titled “Returns”](#returns) [`Span`](/openai-agents-js/openai/agents/classes/span/)<[`SpeechGroupSpanData`](/openai-agents-js/openai/agents/type-aliases/speechgroupspandata/)> # createSpeechSpan ```ts function createSpeechSpan(options, parent?): Span; ``` Create a new speech span. The span will not be started automatically. ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ------------------------------------------------------------------------------------------------------------------------------- | | `options` | `DeepPartial`<`CreateSpanOptions`<[`SpeechSpanData`](/openai-agents-js/openai/agents/type-aliases/speechspandata/)>> & `object` | | `parent?` | \| [`Span`](/openai-agents-js/openai/agents/classes/span/)<`any`> \| [`Trace`](/openai-agents-js/openai/agents/classes/trace/) | ## Returns [Section titled “Returns”](#returns) [`Span`](/openai-agents-js/openai/agents/classes/span/)<[`SpeechSpanData`](/openai-agents-js/openai/agents/type-aliases/speechspandata/)> # createTranscriptionSpan ```ts function createTranscriptionSpan(options, parent?): Span; ``` Create a new transcription span. The span will not be started automatically. ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | --------------------------------------------------------------------------------------------------------------------------------------------- | | `options` | `DeepPartial`<`CreateSpanOptions`<[`TranscriptionSpanData`](/openai-agents-js/openai/agents/type-aliases/transcriptionspandata/)>> & `object` | | `parent?` | \| [`Span`](/openai-agents-js/openai/agents/classes/span/)<`any`> \| [`Trace`](/openai-agents-js/openai/agents/classes/trace/) | ## Returns [Section titled “Returns”](#returns) [`Span`](/openai-agents-js/openai/agents/classes/span/)<[`TranscriptionSpanData`](/openai-agents-js/openai/agents/type-aliases/transcriptionspandata/)> # defineOutputGuardrail ```ts function defineOutputGuardrail(__namedParameters): OutputGuardrailDefinition; ``` Creates an output guardrail definition. ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | ------------------------------------------------------------------------------------------------------ | ------------ | | `TOutput` *extends* [`AgentOutputType`](/openai-agents-js/openai/agents/type-aliases/agentoutputtype/) | `"text"` | | `TContext` | `unknown` | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ------------------- | -------------------------------------------------- | | `__namedParameters` | `DefineOutputGuardrailArgs`<`TOutput`, `TContext`> | ## Returns [Section titled “Returns”](#returns) [`OutputGuardrailDefinition`](/openai-agents-js/openai/agents/interfaces/outputguardraildefinition/)<[`OutputGuardrailMetadata`](/openai-agents-js/openai/agents/interfaces/outputguardrailmetadata/), `TOutput`, `TContext`> # defineToolInputGuardrail ```ts function defineToolInputGuardrail(args): ToolInputGuardrailDefinition; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | ------------ | | `TContext` | `unknown` | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ----------- | -------------------------------------------------------------------------------------------------------------------------------------------------- | | `args` | { `name`: `string`; `run`: [`ToolInputGuardrailFunction`](/openai-agents-js/openai/agents/type-aliases/toolinputguardrailfunction/)<`TContext`>; } | | `args.name` | `string` | | `args.run` | [`ToolInputGuardrailFunction`](/openai-agents-js/openai/agents/type-aliases/toolinputguardrailfunction/)<`TContext`> | ## Returns [Section titled “Returns”](#returns) [`ToolInputGuardrailDefinition`](/openai-agents-js/openai/agents/interfaces/toolinputguardraildefinition/)<`TContext`> # defineToolOutputGuardrail ```ts function defineToolOutputGuardrail(args): ToolOutputGuardrailDefinition; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | ------------ | | `TContext` | `unknown` | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ----------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- | | `args` | { `name`: `string`; `run`: [`ToolOutputGuardrailFunction`](/openai-agents-js/openai/agents/type-aliases/tooloutputguardrailfunction/)<`TContext`>; } | | `args.name` | `string` | | `args.run` | [`ToolOutputGuardrailFunction`](/openai-agents-js/openai/agents/type-aliases/tooloutputguardrailfunction/)<`TContext`> | ## Returns [Section titled “Returns”](#returns) [`ToolOutputGuardrailDefinition`](/openai-agents-js/openai/agents/interfaces/tooloutputguardraildefinition/)<`TContext`> # extractAllTextOutput ```ts function extractAllTextOutput(items): string; ``` Extract all text output from a list of run items by concatenating the content of all message output items. ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | --------- | --------------------------------------------------------------------- | ------------------------------------------- | | `items` | [`RunItem`](/openai-agents-js/openai/agents/type-aliases/runitem/)\[] | The list of run items to extract text from. | ## Returns [Section titled “Returns”](#returns) `string` A string of all the text output from the run items. # fileSearchTool ```ts function fileSearchTool(vectorStoreIds, options?): HostedTool; ``` Adds file search abilities to your agent ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | ---------------- | ------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------- | | `vectorStoreIds` | `string` \| `string`\[] | The IDs of the vector stores to search. | | `options?` | `Partial`<`Omit`<`FileSearchTool`, `"type"` \| `"vectorStoreId"`>> | Additional configuration for the file search like specifying the maximum number of results to return. | ## Returns [Section titled “Returns”](#returns) [`HostedTool`](/openai-agents-js/openai/agents/type-aliases/hostedtool/) a file search tool definition # generateGroupId ```ts function generateGroupId(): string; ``` Generate a group ID by creating a random UUID v4 and removing the dashes. This is the equivalent of `uuid4().hex` in Python and prefixing it with `group_`. ## Returns [Section titled “Returns”](#returns) `string` A group ID. # generateSpanId ```ts function generateSpanId(): string; ``` Generate a span ID by creating a random UUID v4 and removing the dashes. This is the equivalent of `uuid4().hex` in Python and prefixing it with `span_`. ## Returns [Section titled “Returns”](#returns) `string` A span ID. # generateTraceId ```ts function generateTraceId(): string; ``` Generate a trace ID by creating a random UUID v4 and removing the dashes. This is the equivalent of `uuid4().hex` in Python and prefixing it with `trace_`. ## Returns [Section titled “Returns”](#returns) `string` A trace ID. # getAllMcpTools ```ts function getAllMcpTools( mcpServersOrOpts, runContext?, agent?, convertSchemasToStrict?): Promise[]>; ``` Returns all MCP tools from the provided servers, using the function tool conversion. If runContext and agent are provided, callable tool filters will be applied. ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | ------------ | | `TContext` | `unknown` | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `mcpServersOrOpts` | \| [`MCPServer`](/openai-agents-js/openai/agents/interfaces/mcpserver/)\[] \| [`GetAllMcpToolsOptions`](/openai-agents-js/openai/agents/type-aliases/getallmcptoolsoptions/)<`TContext`> | | `runContext?` | [`RunContext`](/openai-agents-js/openai/agents/classes/runcontext/)<`TContext`> | | `agent?` | [`Agent`](/openai-agents-js/openai/agents/classes/agent/)<`TContext`, `any`> | | `convertSchemasToStrict?` | `boolean` | ## Returns [Section titled “Returns”](#returns) `Promise`<[`Tool`](/openai-agents-js/openai/agents/type-aliases/tool/)<`TContext`>\[]> # getClientToolSearchExecutor ```ts function getClientToolSearchExecutor(tool): | ClientToolSearchExecutor | undefined; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | ------------ | | `Context` | `unknown` | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ----------------------------------------------------------------------- | | `tool` | [`Tool`](/openai-agents-js/openai/agents/type-aliases/tool/)<`Context`> | ## Returns [Section titled “Returns”](#returns) \| [`ClientToolSearchExecutor`](/openai-agents-js/openai/agents/type-aliases/clienttoolsearchexecutor/)<`Context`> | `undefined` # getCurrentSpan ```ts function getCurrentSpan(): Span | null; ``` This function will get the current span from the execution context. ## Returns [Section titled “Returns”](#returns) [`Span`](/openai-agents-js/openai/agents/classes/span/)<`any`> | `null` The current span or null if there is no span. # getCurrentTrace ```ts function getCurrentTrace(): Trace | null; ``` This function will get the current trace from the execution context. ## Returns [Section titled “Returns”](#returns) [`Trace`](/openai-agents-js/openai/agents/classes/trace/) | `null` The current trace or null if there is no trace. # getDefaultModel ```ts function getDefaultModel(): string; ``` Returns the default model name. ## Returns [Section titled “Returns”](#returns) `string` # getDefaultModelSettings ```ts function getDefaultModelSettings(model?): ModelSettings; ``` Returns the default model settings. If the default model is a GPT-5 model, returns the GPT-5 default model settings. Otherwise, returns the legacy default model settings. ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | -------- | | `model?` | `string` | ## Returns [Section titled “Returns”](#returns) [`ModelSettings`](/openai-agents-js/openai/agents/type-aliases/modelsettings/) # getGlobalTraceProvider ```ts function getGlobalTraceProvider(): TraceProvider; ``` ## Returns [Section titled “Returns”](#returns) [`TraceProvider`](/openai-agents-js/openai/agents/classes/traceprovider/) # getHandoff ```ts function getHandoff(agent): Handoff; ``` Returns a handoff for the given agent. If the agent is already wrapped into a handoff, it will be returned as is. Otherwise, a new handoff instance will be created. ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Description | | ------------------------------------------------------------------------------------------------------ | ------------------------------ | | `TContext` | The context of the handoff | | `TOutput` *extends* [`AgentOutputType`](/openai-agents-js/openai/agents/type-aliases/agentoutputtype/) | The output type of the handoff | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `agent` | \| [`Agent`](/openai-agents-js/openai/agents/classes/agent/)<`TContext`, `TOutput`> \| [`Handoff`](/openai-agents-js/openai/agents/classes/handoff/)<`TContext`, `TOutput`> | ## Returns [Section titled “Returns”](#returns) [`Handoff`](/openai-agents-js/openai/agents/classes/handoff/)<`TContext`, `TOutput`> # getLogger ```ts function getLogger(namespace?): Logger; ``` Get a logger for a given package. ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | ------------ | -------- | ------------------------------------ | | `namespace?` | `string` | the namespace to use for the logger. | ## Returns [Section titled “Returns”](#returns) `Logger` A logger object with `debug` and `error` methods. # getOrCreateTrace ```ts function getOrCreateTrace(fn, options?): Promise; ``` This function will check if there is an existing active trace in the execution context. If there is, it will run the given function with the existing trace. If there is no trace, it will create a new one and assign it to the execution context of the function. ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | -------------- | | `T` | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | ---------- | -------------------- | ----------------------------------------------------- | | `fn` | () => `Promise`<`T`> | The fzunction to run and assign the trace context to. | | `options?` | `TraceOptions` | Options for the creation of the trace | ## Returns [Section titled “Returns”](#returns) `Promise`<`T`> # getToolSearchRuntimeToolKey ```ts function getToolSearchRuntimeToolKey(tool): string | undefined; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | ------------ | | `Context` | `unknown` | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ----------------------------------------------------------------------- | | `tool` | [`Tool`](/openai-agents-js/openai/agents/type-aliases/tool/)<`Context`> | ## Returns [Section titled “Returns”](#returns) `string` | `undefined` # getTransferMessage ```ts function getTransferMessage(agent): string; ``` Generates the message that will be given as tool output to the model that requested the handoff. ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | ------------------------------------------------------------------------------------------------------ | | `TContext` | | `TOutput` *extends* [`AgentOutputType`](/openai-agents-js/openai/agents/type-aliases/agentoutputtype/) | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | --------- | -------------------------------------------------------------------------------- | ------------------------ | | `agent` | [`Agent`](/openai-agents-js/openai/agents/classes/agent/)<`TContext`, `TOutput`> | The agent to transfer to | ## Returns [Section titled “Returns”](#returns) `string` The message that will be given as tool output to the model that requested the handoff # gpt5ReasoningSettingsRequired ```ts function gpt5ReasoningSettingsRequired(modelName): boolean; ``` Returns True if the model name is a GPT-5 model and reasoning settings are required. ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ----------- | -------- | | `modelName` | `string` | ## Returns [Section titled “Returns”](#returns) `boolean` # handoff ```ts function handoff(agent, config?): Handoff; ``` Creates a handoff from an agent. Handoffs are automatically created when you pass an agent into the `handoffs` option of the `Agent` constructor. Alternatively, you can use this function to create a handoff manually, giving you more control over configuration. ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | Description | | ----------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------ | ------------------------------ | | `TContext` | `unknown` | The context of the handoff | | `TOutput` *extends* [`AgentOutputType`](/openai-agents-js/openai/agents/type-aliases/agentoutputtype/) | `"text"` | The output type of the handoff | | `TInputType` *extends* [`ToolInputParameters`](/openai-agents-js/openai/agents/type-aliases/toolinputparameters/) | [`ToolInputParameters`](/openai-agents-js/openai/agents/type-aliases/toolinputparameters/) | The input type of the handoff | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | -------------------------------------------------------------------------------- | | `agent` | [`Agent`](/openai-agents-js/openai/agents/classes/agent/)<`TContext`, `TOutput`> | | `config?` | `HandoffConfig`<`TInputType`, `TContext`> | ## Returns [Section titled “Returns”](#returns) [`Handoff`](/openai-agents-js/openai/agents/classes/handoff/)<`TContext`, `TOutput`> # hostedMcpTool ```ts function hostedMcpTool(options): HostedMCPTool; ``` Creates a hosted MCP tool definition. ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | ------------ | | `Context` | `unknown` | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | --------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------- | | `options` | `object` & ({ serverLabel: string; serverUrl?: string \| undefined; authorization?: string \| undefined; headers?: Record\ \| undefined; } \| { serverLabel: string; connectorId: string; authorization?: string \| undefined; headers?: Record<…> \| undefined; }) & ({ …; } \| … 1 more … \| { …; }) | Configuration for the hosted MCP tool, including server connection details and approval requirements. | ## Returns [Section titled “Returns”](#returns) [`HostedMCPTool`](/openai-agents-js/openai/agents/type-aliases/hostedmcptool/)<`Context`> # imageGenerationTool ```ts function imageGenerationTool(options?): HostedTool; ``` Adds image generation abilities to your agent ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | ---------- | -------------------------------------------------- | ------------------------------------------------- | | `options?` | `Partial`<`Omit`<`ImageGenerationTool`, `"type"`>> | Additional configuration for the image generation | ## Returns [Section titled “Returns”](#returns) [`HostedTool`](/openai-agents-js/openai/agents/type-aliases/hostedtool/) an image generation tool definition # invalidateServerToolsCache ```ts function invalidateServerToolsCache(serverName): Promise; ``` Remove cached tools for the given server so the next lookup fetches fresh data. ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | ------------ | -------- | ----------------------------------------------------- | | `serverName` | `string` | Name of the MCP server whose cache should be cleared. | ## Returns [Section titled “Returns”](#returns) `Promise`<`void`> # invokeFunctionTool ```ts function invokeFunctionTool(args): Promise; ``` Invoke a function tool while enforcing optional per-tool timeout settings. ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | ------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------ | | `Context` | `unknown` | | `TParameters` *extends* [`ToolInputParameters`](/openai-agents-js/openai/agents/type-aliases/toolinputparameters/) | [`ToolInputParameters`](/openai-agents-js/openai/agents/type-aliases/toolinputparameters/) | | `Result` | `unknown` | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ---------------------------------------------------------------- | | `args` | `FunctionToolInvocationArgs`<`Context`, `TParameters`, `Result`> | ## Returns [Section titled “Returns”](#returns) `Promise`<`string` | `Result`> # isGpt5Default ```ts function isGpt5Default(): boolean; ``` Returns True if the default model is a GPT-5 model. This is used to determine if the default model settings are compatible with GPT-5 models. If the default model is not a GPT-5 model, the model settings are compatible with other models. ## Returns [Section titled “Returns”](#returns) `boolean` # isOpenAIChatCompletionsRawModelStreamEvent ```ts function isOpenAIChatCompletionsRawModelStreamEvent(event): event is OpenAIChatCompletionsRawModelStreamEvent; ``` ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | -------------------------------------------------------------------------------- | | `event` | [`RunStreamEvent`](/openai-agents-js/openai/agents/type-aliases/runstreamevent/) | ## Returns [Section titled “Returns”](#returns) `event is OpenAIChatCompletionsRawModelStreamEvent` # isOpenAIResponsesCompactionAwareSession ```ts function isOpenAIResponsesCompactionAwareSession(session): session is OpenAIResponsesCompactionAwareSession; ``` ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ---------------------------------------------------------------------------------- | | `session` | \| [`Session`](/openai-agents-js/openai/agents/interfaces/session/) \| `undefined` | ## Returns [Section titled “Returns”](#returns) `session is OpenAIResponsesCompactionAwareSession` # isOpenAIResponsesRawModelStreamEvent ```ts function isOpenAIResponsesRawModelStreamEvent(event): event is OpenAIResponsesRawModelStreamEvent; ``` ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | -------------------------------------------------------------------------------- | | `event` | [`RunStreamEvent`](/openai-agents-js/openai/agents/type-aliases/runstreamevent/) | ## Returns [Section titled “Returns”](#returns) `event is OpenAIResponsesRawModelStreamEvent` # isSessionHistoryRewriteAwareSession ```ts function isSessionHistoryRewriteAwareSession(session): session is SessionHistoryRewriteAwareSession; ``` ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ---------------------------------------------------------------------------------- | | `session` | \| [`Session`](/openai-agents-js/openai/agents/interfaces/session/) \| `undefined` | ## Returns [Section titled “Returns”](#returns) `session is SessionHistoryRewriteAwareSession` # mcpToFunctionTool ```ts function mcpToFunctionTool( mcpTool, server, convertSchemasToStrict, options?): | FunctionTool, string> | FunctionTool, string>; ``` ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `mcpTool` | { `description?`: `string`; `inputSchema`: { `additionalProperties`: `boolean`; `properties`: `z.ZodRecord`<`z.ZodString`, `z.ZodAny`>; `required`: `string`\[]; `type`: `"object"`; }; `name`: `string`; } | | `mcpTool.description?` | `string` | | `mcpTool.inputSchema` | { `additionalProperties`: `boolean`; `properties`: `z.ZodRecord`<`z.ZodString`, `z.ZodAny`>; `required`: `string`\[]; `type`: `"object"`; } | | `mcpTool.inputSchema.additionalProperties` | `boolean` | | `mcpTool.inputSchema.properties?` | `z.ZodRecord`<`z.ZodString`, `z.ZodAny`> | | `mcpTool.inputSchema.required?` | `string`\[] | | `mcpTool.inputSchema.type?` | `"object"` | | `mcpTool.name?` | `string` | | `server?` | [`MCPServer`](/openai-agents-js/openai/agents/interfaces/mcpserver/) | | `convertSchemasToStrict?` | `boolean` | | `options?` | `MCPFunctionToolConversionOptions` | ## Returns [Section titled “Returns”](#returns) \| [`FunctionTool`](/openai-agents-js/openai/agents/type-aliases/functiontool/)<`any`, `JsonObjectSchemaStrict`<`any`>, `string`> | [`FunctionTool`](/openai-agents-js/openai/agents/type-aliases/functiontool/)<`any`, `JsonObjectSchemaNonStrict`<`any`>, `string`> # resetCurrentSpan ```ts function resetCurrentSpan(): void; ``` ## Returns [Section titled “Returns”](#returns) `void` # resolveToolInputGuardrails ```ts function resolveToolInputGuardrails(guardrails?): ToolInputGuardrailDefinition[]; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | ------------ | | `TContext` | `unknown` | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ------------- | --------------------------------------- | | `guardrails?` | `ToolInputGuardrailInit`<`TContext`>\[] | ## Returns [Section titled “Returns”](#returns) [`ToolInputGuardrailDefinition`](/openai-agents-js/openai/agents/interfaces/toolinputguardraildefinition/)<`TContext`>\[] # resolveToolOutputGuardrails ```ts function resolveToolOutputGuardrails(guardrails?): ToolOutputGuardrailDefinition[]; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | ------------ | | `TContext` | `unknown` | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ------------- | ---------------------------------------- | | `guardrails?` | `ToolOutputGuardrailInit`<`TContext`>\[] | ## Returns [Section titled “Returns”](#returns) [`ToolOutputGuardrailDefinition`](/openai-agents-js/openai/agents/interfaces/tooloutputguardraildefinition/)<`TContext`>\[] # run ## Call Signature [Section titled “Call Signature”](#call-signature) ```ts function run( agent, input, options?): Promise>; ``` Executes an agent workflow with the shared default `Runner` instance. ### Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | ------------------------------------------------------------------------------------------ | ------------ | | `TAgent` *extends* [`Agent`](/openai-agents-js/openai/agents/classes/agent/)<`any`, `any`> | ‐ | | `TContext` | `undefined` | ### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------- | | `agent` | `TAgent` | The entry agent to invoke. | | `input` | \| `string` \| [`AgentInputItem`](/openai-agents-js/openai/agents/type-aliases/agentinputitem/)\[] \| [`RunState`](/openai-agents-js/openai/agents/classes/runstate/)<`TContext`, `TAgent`> | A string utterance, structured input items, or a resumed `RunState`. | | `options?` | [`NonStreamRunOptions`](/openai-agents-js/openai/agents/type-aliases/nonstreamrunoptions/)<`TContext`, `TAgent`> | Controls streaming mode, context, session handling, and turn limits. | ### Returns [Section titled “Returns”](#returns) `Promise`<[`RunResult`](/openai-agents-js/openai/agents/classes/runresult/)<`TContext`, `TAgent`>> A `RunResult` when `stream` is false, otherwise a `StreamedRunResult`. ## Call Signature [Section titled “Call Signature”](#call-signature-1) ```ts function run( agent, input, options?): Promise>; ``` Executes an agent workflow with the shared default `Runner` instance. ### Type Parameters [Section titled “Type Parameters”](#type-parameters-1) | Type Parameter | Default type | | ------------------------------------------------------------------------------------------ | ------------ | | `TAgent` *extends* [`Agent`](/openai-agents-js/openai/agents/classes/agent/)<`any`, `any`> | ‐ | | `TContext` | `undefined` | ### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | Description | | ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------- | | `agent` | `TAgent` | The entry agent to invoke. | | `input` | \| `string` \| [`AgentInputItem`](/openai-agents-js/openai/agents/type-aliases/agentinputitem/)\[] \| [`RunState`](/openai-agents-js/openai/agents/classes/runstate/)<`TContext`, `TAgent`> | A string utterance, structured input items, or a resumed `RunState`. | | `options?` | [`StreamRunOptions`](/openai-agents-js/openai/agents/type-aliases/streamrunoptions/)<`TContext`, `TAgent`> | Controls streaming mode, context, session handling, and turn limits. | ### Returns [Section titled “Returns”](#returns-1) `Promise`<[`StreamedRunResult`](/openai-agents-js/openai/agents/classes/streamedrunresult/)<`TContext`, `TAgent`>> A `RunResult` when `stream` is false, otherwise a `StreamedRunResult`. # runToolInputGuardrails ```ts function runToolInputGuardrails(__namedParameters): Promise< | { type: "allow"; } | { message: string; type: "reject"; }>; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | ------------------------------------------------------------------------------------------ | | `TContext` | | `TAgent` *extends* [`Agent`](/openai-agents-js/openai/agents/classes/agent/)<`any`, `any`> | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | `__namedParameters` | { `agent`: `TAgent`; `context`: [`RunContext`](/openai-agents-js/openai/agents/classes/runcontext/)<`TContext`>; `guardrails?`: [`ToolInputGuardrailDefinition`](/openai-agents-js/openai/agents/interfaces/toolinputguardraildefinition/)<`TContext`>\[]; `onResult?`: (`result`) => `void`; `toolCall`: { `arguments`: `string`; `callId`: `string`; `id?`: `string`; `name`: `string`; `namespace?`: `string`; `providerData?`: `Record`<`string`, `any`>; `status?`: `"completed"` \| `"in_progress"` \| `"incomplete"`; `type`: `"function_call"`; }; } | | `__namedParameters.agent` | `TAgent` | | `__namedParameters.context` | [`RunContext`](/openai-agents-js/openai/agents/classes/runcontext/)<`TContext`> | | `__namedParameters.guardrails?` | [`ToolInputGuardrailDefinition`](/openai-agents-js/openai/agents/interfaces/toolinputguardraildefinition/)<`TContext`>\[] | | `__namedParameters.onResult?` | (`result`) => `void` | | `__namedParameters.toolCall` | { `arguments`: `string`; `callId`: `string`; `id?`: `string`; `name`: `string`; `namespace?`: `string`; `providerData?`: `Record`<`string`, `any`>; `status?`: `"completed"` \| `"in_progress"` \| `"incomplete"`; `type`: `"function_call"`; } | | `__namedParameters.toolCall.arguments` | `string` | | `__namedParameters.toolCall.callId` | `string` | | `__namedParameters.toolCall.id?` | `string` | | `__namedParameters.toolCall.name` | `string` | | `__namedParameters.toolCall.namespace?` | `string` | | `__namedParameters.toolCall.providerData?` | `Record`<`string`, `any`> | | `__namedParameters.toolCall.status?` | `"completed"` \| `"in_progress"` \| `"incomplete"` | | `__namedParameters.toolCall.type` | `"function_call"` | ## Returns [Section titled “Returns”](#returns) `Promise`< | { `type`: `"allow"`; } | { `message`: `string`; `type`: `"reject"`; }> # runToolOutputGuardrails ```ts function runToolOutputGuardrails(__namedParameters): Promise; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | ------------------------------------------------------------------------------------------ | | `TContext` | | `TAgent` *extends* [`Agent`](/openai-agents-js/openai/agents/classes/agent/)<`any`, `any`> | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `__namedParameters` | { `agent`: `TAgent`; `context`: [`RunContext`](/openai-agents-js/openai/agents/classes/runcontext/)<`TContext`>; `guardrails?`: [`ToolOutputGuardrailDefinition`](/openai-agents-js/openai/agents/interfaces/tooloutputguardraildefinition/)<`TContext`>\[]; `onResult?`: (`result`) => `void`; `toolCall`: { `arguments`: `string`; `callId`: `string`; `id?`: `string`; `name`: `string`; `namespace?`: `string`; `providerData?`: `Record`<`string`, `any`>; `status?`: `"completed"` \| `"in_progress"` \| `"incomplete"`; `type`: `"function_call"`; }; `toolOutput`: `unknown`; } | | `__namedParameters.agent` | `TAgent` | | `__namedParameters.context` | [`RunContext`](/openai-agents-js/openai/agents/classes/runcontext/)<`TContext`> | | `__namedParameters.guardrails?` | [`ToolOutputGuardrailDefinition`](/openai-agents-js/openai/agents/interfaces/tooloutputguardraildefinition/)<`TContext`>\[] | | `__namedParameters.onResult?` | (`result`) => `void` | | `__namedParameters.toolCall` | { `arguments`: `string`; `callId`: `string`; `id?`: `string`; `name`: `string`; `namespace?`: `string`; `providerData?`: `Record`<`string`, `any`>; `status?`: `"completed"` \| `"in_progress"` \| `"incomplete"`; `type`: `"function_call"`; } | | `__namedParameters.toolCall.arguments` | `string` | | `__namedParameters.toolCall.callId` | `string` | | `__namedParameters.toolCall.id?` | `string` | | `__namedParameters.toolCall.name` | `string` | | `__namedParameters.toolCall.namespace?` | `string` | | `__namedParameters.toolCall.providerData?` | `Record`<`string`, `any`> | | `__namedParameters.toolCall.status?` | `"completed"` \| `"in_progress"` \| `"incomplete"` | | `__namedParameters.toolCall.type` | `"function_call"` | | `__namedParameters.toolOutput` | `unknown` | ## Returns [Section titled “Returns”](#returns) `Promise`<`unknown`> # setCurrentSpan ```ts function setCurrentSpan(span): void; ``` This function will set the current span in the execution context. ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | --------- | -------------------------------------------------------------- | ------------------------------------ | | `span` | [`Span`](/openai-agents-js/openai/agents/classes/span/)<`any`> | The span to set as the current span. | ## Returns [Section titled “Returns”](#returns) `void` # setDefaultModelProvider ```ts function setDefaultModelProvider(provider): void; ``` Set the model provider used when no explicit provider is supplied. ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | ---------- | ---------------------------------------------------------------------------- | ------------------------------- | | `provider` | [`ModelProvider`](/openai-agents-js/openai/agents/interfaces/modelprovider/) | The provider to use by default. | ## Returns [Section titled “Returns”](#returns) `void` # setDefaultOpenAIClient ```ts function setDefaultOpenAIClient(client): void; ``` ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | -------- | | `client` | `OpenAI` | ## Returns [Section titled “Returns”](#returns) `void` # setDefaultOpenAIKey ```ts function setDefaultOpenAIKey(key): void; ``` ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | -------- | | `key` | `string` | ## Returns [Section titled “Returns”](#returns) `void` # setDefaultOpenAITracingExporter ```ts function setDefaultOpenAITracingExporter(): void; ``` Sets the OpenAI Tracing exporter as the default exporter with a BatchTraceProcessor handling the traces ## Returns [Section titled “Returns”](#returns) `void` # setOpenAIAPI ```ts function setOpenAIAPI(value): void; ``` ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ------------------------------------- | | `value` | `"chat_completions"` \| `"responses"` | ## Returns [Section titled “Returns”](#returns) `void` # setOpenAIResponsesTransport ```ts function setOpenAIResponsesTransport(value): void; ``` ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ------------------------- | | `value` | `"http"` \| `"websocket"` | ## Returns [Section titled “Returns”](#returns) `void` # setTraceProcessors ```ts function setTraceProcessors(processors): void; ``` Set the list of processors. This will replace any existing processors. ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | ------------ | ------------------------------------------------------------------------------------- | ------------------------------ | | `processors` | [`TracingProcessor`](/openai-agents-js/openai/agents/interfaces/tracingprocessor/)\[] | The list of processors to set. | ## Returns [Section titled “Returns”](#returns) `void` # setTracingDisabled ```ts function setTracingDisabled(disabled): void; ``` Set the disabled state of the tracing provider. ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | ---------- | --------- | --------------------------- | | `disabled` | `boolean` | Whether to disable tracing. | ## Returns [Section titled “Returns”](#returns) `void` # setTracingExportApiKey ```ts function setTracingExportApiKey(key): void; ``` ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | -------- | | `key` | `string` | ## Returns [Section titled “Returns”](#returns) `void` # shellTool ## Call Signature [Section titled “Call Signature”](#call-signature) ```ts function shellTool(options): NormalizedLocalShellTool; ``` ### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ----------------------- | | `options` | `LocalShellToolOptions` | ### Returns [Section titled “Returns”](#returns) `NormalizedLocalShellTool` ## Call Signature [Section titled “Call Signature”](#call-signature-1) ```ts function shellTool(options): HostedShellTool; ``` ### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | --------- | ------------------------ | | `options` | `HostedShellToolOptions` | ### Returns [Section titled “Returns”](#returns-1) `HostedShellTool` # startOpenAIConversationsSession ```ts function startOpenAIConversationsSession(client?): Promise; ``` ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | -------- | | `client?` | `OpenAI` | ## Returns [Section titled “Returns”](#returns) `Promise`<`string`> # startTraceExportLoop ```ts function startTraceExportLoop(): void; ``` Start the trace export loop. ## Returns [Section titled “Returns”](#returns) `void` # system ```ts function system(input, options?): object; ``` Creates a system message entry ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | ---------- | ------------------------- | ----------------------------------------------------------------- | | `input` | `string` | The system prompt. | | `options?` | `Record`<`string`, `any`> | Any additional options that will be directly passed to the model. | ## Returns [Section titled “Returns”](#returns) `object` A message entry. ### content [Section titled “content”](#content) ```ts content: string; ``` ### id? [Section titled “id?”](#id) ```ts optional id?: string; ``` ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` ### role [Section titled “role”](#role) ```ts role: "system"; ``` ### type? [Section titled “type?”](#type) ```ts optional type?: "message"; ``` # tool ```ts function tool(options): FunctionTool; ``` Exposes a function to the agent as a tool to be called ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | ------------------------------------------------------------------------------------------------------------------ | ------------ | | `TParameters` *extends* [`ToolInputParameters`](/openai-agents-js/openai/agents/type-aliases/toolinputparameters/) | `undefined` | | `Context` | `unknown` | | `Result` | `string` | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | --------- | ---------------------------------------------------------------------------------------------------- | ------------------------ | | `options` | [`ToolOptions`](/openai-agents-js/openai/agents/type-aliases/tooloptions/)<`TParameters`, `Context`> | The options for the tool | ## Returns [Section titled “Returns”](#returns) [`FunctionTool`](/openai-agents-js/openai/agents/type-aliases/functiontool/)<`Context`, `TParameters`, `Result`> A new tool # toolNamespace ```ts function toolNamespace(options): TTools; ``` Responses API only. Group function tools under a shared namespace. ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | ------------------------------------------------ | | `TTools` *extends* readonly `AnyFunctionTool`\[] | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | --------- | ------------------------------------------------------------------------------------------------------ | ------------------------------------------------ | | `options` | [`ToolNamespaceOptions`](/openai-agents-js/openai/agents/type-aliases/toolnamespaceoptions/)<`TTools`> | Namespace metadata and function tools to attach. | ## Returns [Section titled “Returns”](#returns) `TTools` shallow-cloned function tools carrying namespace metadata. # toolSearchTool ```ts function toolSearchTool(options?): HostedTool; ``` Adds tool\_search capabilities to your agent. This lets the model search deferred function tools and load them into context on demand. By default, tool search is executed by OpenAI. Set `execution: 'client'` to use a custom loop that receives `tool_search_call` / `tool_search_output` items. The standard runner only supports the default built-in client schema (leave `parameters` unset) and auto-executes `{ paths: string[] }` searches over deferred top-level function tools and deferred namespace members. ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | ------------ | | `Context` | `unknown` | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ---------- | ------------------------------------------------------------------------------------------------------------------------ | | `options?` | `Partial`<`Omit`<[`ToolSearchTool`](/openai-agents-js/openai/agents/type-aliases/toolsearchtool/)<`Context`>, `"type"`>> | ## Returns [Section titled “Returns”](#returns) [`HostedTool`](/openai-agents-js/openai/agents/type-aliases/hostedtool/) a hosted tool\_search definition. # user ```ts function user(input, options?): object; ``` Creates a user message entry ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | ---------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------- | | `input` | \| `string` \| ( \| { `providerData?`: `Record`<`string`, `any`>; `text`: `string`; `type`: `"input_text"`; } \| { `detail?`: `string`; `image?`: \| `string` \| { `id`: `string`; }; `providerData?`: `Record`<`string`, `any`>; `type`: `"input_image"`; } \| { `file?`: \| `string` \| { `id`: `string`; } \| { `url`: `string`; }; `filename?`: `string`; `providerData?`: `Record`<`string`, `any`>; `type`: `"input_file"`; } \| { `audio`: \| `string` \| { `id`: `string`; }; `format?`: `string` \| `null`; `providerData?`: `Record`<`string`, `any`>; `transcript?`: `string` \| `null`; `type`: `"audio"`; })\[] | The input message from the user. | | `options?` | `Record`<`string`, `any`> | Any additional options that will be directly passed to the model. | ## Returns [Section titled “Returns”](#returns) `object` A message entry. ### content [Section titled “content”](#content) ```ts content: | string | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; })[]; ``` ### id? [Section titled “id?”](#id) ```ts optional id?: string; ``` ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` ### role [Section titled “role”](#role) ```ts role: "user"; ``` ### type? [Section titled “type?”](#type) ```ts optional type?: "message"; ``` # webSearchTool ```ts function webSearchTool(options?): HostedTool; ``` Adds web search abilities to your agent ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | ---------- | -------------------------------------------- | -------------------------------------------------------------------------------------- | | `options?` | `Partial`<`Omit`<`WebSearchTool`, `"type"`>> | Additional configuration for the web search like specifying the location of your agent | ## Returns [Section titled “Returns”](#returns) [`HostedTool`](/openai-agents-js/openai/agents/type-aliases/hostedtool/) a web search tool definition # withResponsesWebSocketSession ```ts function withResponsesWebSocketSession(callback, options?): Promise; ``` Runs a callback within a session-scoped Responses API websocket provider/runner and closes the provider afterwards so websocket connections do not keep the process alive. ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | -------------- | | `T` | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ---------- | -------------------------------------------------------------------------------------------------------------------- | | `callback` | (`session`) => `T` \| `Promise`<`T`> | | `options?` | [`ResponsesWebSocketSessionOptions`](/openai-agents-js/openai/agents/type-aliases/responseswebsocketsessionoptions/) | ## Returns [Section titled “Returns”](#returns) `Promise`<`T`> # withTrace ```ts function withTrace( trace, fn, options?): Promise; ``` This function will create a new trace and assign it to the execution context of the function passed to it. ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | -------------- | | `T` | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | ---------- | --------------------------------------------------------------------- | ---------------------------------------------------- | | `trace` | `string` \| [`Trace`](/openai-agents-js/openai/agents/classes/trace/) | ‐ | | `fn` | (`trace`) => `Promise`<`T`> | The function to run and assign the trace context to. | | `options?` | `TraceOptions` | Options for the creation of the trace | ## Returns [Section titled “Returns”](#returns) `Promise`<`T`> # AgentConfiguration Configuration for an agent. ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | Description | | ------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------- | ------------------------------- | | `TContext` | [`UnknownContext`](/openai-agents-js/openai/agents/type-aliases/unknowncontext/) | The type of the context object. | | `TOutput` *extends* [`AgentOutputType`](/openai-agents-js/openai/agents/type-aliases/agentoutputtype/) | [`TextOutput`](/openai-agents-js/openai/agents/type-aliases/textoutput/) | The type of the output object. | ## Properties [Section titled “Properties”](#properties) ### handoffDescription [Section titled “handoffDescription”](#handoffdescription) ```ts handoffDescription: string; ``` A description of the agent. This is used when the agent is used as a handoff, so that an LLM knows what it does and when to invoke it. *** ### handoffOutputTypeWarningEnabled? [Section titled “handoffOutputTypeWarningEnabled?”](#handoffoutputtypewarningenabled) ```ts optional handoffOutputTypeWarningEnabled?: boolean; ``` The warning log would be enabled when multiple output types by handoff agents are detected. *** ### handoffs [Section titled “handoffs”](#handoffs) ```ts handoffs: ( | Agent | Handoff)[]; ``` Handoffs are sub-agents that the agent can delegate to. You can provide a list of handoffs, and the agent can choose to delegate to them if relevant. Allows for separation of concerns and modularity. *** ### inputGuardrails [Section titled “inputGuardrails”](#inputguardrails) ```ts inputGuardrails: InputGuardrail[]; ``` A list of checks that run in parallel to the agent by default; set `runInParallel` to false to block LLM/tool calls until the guardrail completes. Runs only if the agent is the first agent in the chain. *** ### instructions [Section titled “instructions”](#instructions) ```ts instructions: string | ((runContext, agent) => string | Promise); ``` The instructions for the agent. Will be used as the “system prompt” when this agent is invoked. Describes what the agent should do, and how it responds. Can either be a string, or a function that dynamically generates instructions for the agent. If you provide a function, it will be called with the context and the agent instance. It must return a string. *** ### mcpConfig [Section titled “mcpConfig”](#mcpconfig) ```ts mcpConfig: object; ``` Configuration for MCP servers used by this agent. | Name | Type | Description | | --------------------------- | --------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `convertSchemasToStrict?` | `boolean` | Try to convert MCP tool schemas to strict JSON schema. | | `errorFunction?` | \| [`MCPToolErrorFunction`](/openai-agents-js/openai/agents/type-aliases/mcptoolerrorfunction/) \| `null` | Optional function to convert MCP tool failures into model-visible messages. Set to null to rethrow errors instead of converting them. Server-level errorFunction values take precedence. | | `includeServerInToolNames?` | `boolean` | Prefix local MCP tool names with their server name before exposing them to the model. The SDK still invokes the original MCP tool name on the original server. | *** ### mcpServers [Section titled “mcpServers”](#mcpservers) ```ts mcpServers: MCPServer[]; ``` A list of [Model Context Protocol](https://modelcontextprotocol.io/) servers the agent can use. Every time the agent runs, it will include tools from these servers in the list of available tools. NOTE: You are expected to manage the lifecycle of these servers. Specifically, you must call `server.connect()` before passing it to the agent, and `server.close()` when the server is no longer needed. Consider using `connectMcpServers` or `MCPServers` to keep open/close in the same place. *** ### model [Section titled “model”](#model) ```ts model: string | Model; ``` The model implementation to use when invoking the LLM. By default, if not set, the agent will use the default model returned by getDefaultModel (currently “gpt-5.4-mini”). *** ### modelSettings [Section titled “modelSettings”](#modelsettings) ```ts modelSettings: ModelSettings; ``` Configures model-specific tuning parameters (e.g. temperature, top\_p, etc.) *** ### name [Section titled “name”](#name) ```ts name: string; ``` *** ### outputGuardrails [Section titled “outputGuardrails”](#outputguardrails) ```ts outputGuardrails: OutputGuardrail[]; ``` A list of checks that run on the final output of the agent, after generating a response. Runs only if the agent produces a final output. *** ### outputType [Section titled “outputType”](#outputtype) ```ts outputType: TOutput; ``` The type of the output object. If not provided, the output will be a string. *** ### prompt? [Section titled “prompt?”](#prompt) ```ts optional prompt?: Prompt | ((runContext, agent) => Prompt | Promise); ``` The prompt template to use for the agent (OpenAI Responses API only). Can either be a prompt template object, or a function that returns a prompt template object. If a function is provided, it will be called with the run context and the agent instance. It must return a prompt template object. *** ### resetToolChoice [Section titled “resetToolChoice”](#resettoolchoice) ```ts resetToolChoice: boolean; ``` Whether to reset the tool choice to the default value after a tool has been called. Defaults to `true`. This ensures that the agent doesn’t enter an infinite loop of tool usage. *** ### tools [Section titled “tools”](#tools) ```ts tools: Tool[]; ``` A list of tools the agent can use. *** ### toolUseBehavior [Section titled “toolUseBehavior”](#toolusebehavior) ```ts toolUseBehavior: ToolUseBehavior; ``` This lets you configure how tool use is handled. * run\_llm\_again: The default behavior. Tools are run, and then the LLM receives the results and gets to respond. * stop\_on\_first\_tool: The output of the first tool call is used as the final output. This means that the LLM does not process the result of the tool call. * A list of tool names: The agent will stop running if any of the tools in the list are called. The final output will be the output of the first matching tool call. The LLM does not process the result of the tool call. * A function: if you pass a function, it will be called with the run context and the list of tool results. It must return a `ToolsToFinalOutputResult`, which determines whether the tool call resulted in a final output. NOTE: This configuration is specific to `FunctionTools`. Hosted tools, such as file search, web search, etc. are always processed by the LLM # Editor Host interface responsible for applying diffs on disk. ## Methods [Section titled “Methods”](#methods) ### createFile() [Section titled “createFile()”](#createfile) ```ts createFile(operation, context?): Promise< | void | ApplyPatchResult>; ``` Creates a new file from a V4A diff. #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ----------------- | -------------------------------------------------------------------------------------------------- | | `operation` | { `diff`: `string`; `path`: `string`; `type`: `"create_file"`; } | | `operation.diff` | `string` | | `operation.path?` | `string` | | `operation.type?` | `"create_file"` | | `context?` | [`EditorInvocationContext`](/openai-agents-js/openai/agents/type-aliases/editorinvocationcontext/) | #### Returns [Section titled “Returns”](#returns) `Promise`< | `void` | [`ApplyPatchResult`](/openai-agents-js/openai/agents/type-aliases/applypatchresult/)> *** ### deleteFile() [Section titled “deleteFile()”](#deletefile) ```ts deleteFile(operation, context?): Promise< | void | ApplyPatchResult>; ``` Deletes an existing file. #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | ----------------- | -------------------------------------------------------------------------------------------------- | | `operation` | { `path`: `string`; `type`: `"delete_file"`; } | | `operation.path` | `string` | | `operation.type?` | `"delete_file"` | | `context?` | [`EditorInvocationContext`](/openai-agents-js/openai/agents/type-aliases/editorinvocationcontext/) | #### Returns [Section titled “Returns”](#returns-1) `Promise`< | `void` | [`ApplyPatchResult`](/openai-agents-js/openai/agents/type-aliases/applypatchresult/)> *** ### updateFile() [Section titled “updateFile()”](#updatefile) ```ts updateFile(operation, context?): Promise< | void | ApplyPatchResult>; ``` Updates an existing file based on a V4A diff. #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | ------------------- | -------------------------------------------------------------------------------------------------- | | `operation` | { `diff`: `string`; `moveTo?`: `string`; `path`: `string`; `type`: `"update_file"`; } | | `operation.diff` | `string` | | `operation.moveTo?` | `string` | | `operation.path?` | `string` | | `operation.type?` | `"update_file"` | | `context?` | [`EditorInvocationContext`](/openai-agents-js/openai/agents/type-aliases/editorinvocationcontext/) | #### Returns [Section titled “Returns”](#returns-2) `Promise`< | `void` | [`ApplyPatchResult`](/openai-agents-js/openai/agents/type-aliases/applypatchresult/)> # GuardrailFunctionOutput The output of a guardrail function. ## Properties [Section titled “Properties”](#properties) ### outputInfo [Section titled “outputInfo”](#outputinfo) ```ts outputInfo: any; ``` Optional information about the guardrail’s output. For example, the guardrail could include information about the checks it performed and granular results. *** ### tripwireTriggered [Section titled “tripwireTriggered”](#tripwiretriggered) ```ts tripwireTriggered: boolean; ``` Whether the tripwire was triggered. If triggered, the agent’s execution will be halted. # InputGuardrail A guardrail that checks the input to the agent. ## Properties [Section titled “Properties”](#properties) ### execute [Section titled “execute”](#execute) ```ts execute: InputGuardrailFunction; ``` The function that performs the guardrail check *** ### name [Section titled “name”](#name) ```ts name: string; ``` The name of the guardrail. *** ### runInParallel? [Section titled “runInParallel?”](#runinparallel) ```ts optional runInParallel?: boolean; ``` Whether the guardrail should execute alongside the agent (true, default) or block the agent until it completes (false). # InputGuardrailFunctionArgs Arguments for an input guardrail function. ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | -------------------------------------------------------------------------------- | | `TContext` | [`UnknownContext`](/openai-agents-js/openai/agents/type-aliases/unknowncontext/) | ## Properties [Section titled “Properties”](#properties) ### agent [Section titled “agent”](#agent) ```ts agent: Agent; ``` The agent that is being run. *** ### context [Section titled “context”](#context) ```ts context: RunContext; ``` The context of the agent run. *** ### input [Section titled “input”](#input) ```ts input: | string | ( | { content: | string | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; })[]; id?: string; providerData?: Record; role: "user"; type?: "message"; } | { content: ( | { providerData?: Record; text: string; type: "output_text"; } | { providerData?: Record; refusal: string; type: "refusal"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; } | { image: string; providerData?: Record; type: "image"; })[]; id?: string; providerData?: Record; role: "assistant"; status: "completed" | "in_progress" | "incomplete"; type?: "message"; } | { content: string; id?: string; providerData?: Record; role: "system"; type?: "message"; } | { arguments: unknown; call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; type: "tool_search_call"; } | { call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; tools: Record[]; type: "tool_search_output"; } | { arguments?: string; id?: string; name: string; output?: string; providerData?: Record; status?: string; type: "hosted_tool_call"; } | { arguments: string; callId: string; id?: string; name: string; namespace?: string; providerData?: Record; status?: "completed" | "in_progress" | "incomplete"; type: "function_call"; } | { action?: | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; }; actions?: ( | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; })[]; callId: string; id?: string; providerData?: Record; status: "completed" | "in_progress" | "incomplete"; type: "computer_call"; } | { action: { commands: string[]; maxOutputLength?: number; timeoutMs?: number; }; callId: string; id?: string; providerData?: Record; status?: "completed" | "in_progress" | "incomplete"; type: "shell_call"; } | { callId: string; id?: string; operation: | { diff: string; path: string; type: "create_file"; } | { diff: string; moveTo?: string; path: string; type: "update_file"; } | { path: string; type: "delete_file"; }; providerData?: Record; status: "completed" | "in_progress"; type: "apply_patch_call"; } | { callId: string; id?: string; name: string; namespace?: string; output: | string | { providerData?: Record; text: string; type: "text"; } | { detail?: string & object | "low" | "high" | "auto"; image?: | string | { data: string | Uint8Array; mediaType?: string; } | { url: string; } | { fileId: string; }; providerData?: Record; type: "image"; } | { file: | string | { data: string | Uint8Array; filename: string; mediaType: string; } | { filename?: string; url: string; } | { filename?: string; id: string; }; providerData?: Record; type: "file"; } | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; })[]; providerData?: Record; status: "completed" | "in_progress" | "incomplete"; type: "function_call_result"; } | { callId: string; id?: string; output: { data: string; providerData?: Record; type: "computer_screenshot"; }; providerData?: Record; type: "computer_call_result"; } | { callId: string; id?: string; maxOutputLength?: number; output: object[]; providerData?: Record; type: "shell_call_output"; } | { callId: string; id?: string; output?: string; providerData?: Record; status: "completed" | "failed"; type: "apply_patch_call_output"; } | { content: object[]; id?: string; providerData?: Record; rawContent?: object[]; type: "reasoning"; } | { created_by?: string; encrypted_content: string; id?: string; providerData?: Record; type: "compaction"; } | { id?: string; providerData?: Record; type: "unknown"; })[]; ``` The input to the agent. # InputGuardrailMetadata Metadata for an input guardrail. ## Properties [Section titled “Properties”](#properties) ### name [Section titled “name”](#name) ```ts name: string; ``` *** ### type [Section titled “type”](#type) ```ts type: "input"; ``` # InputGuardrailResult The result of an input guardrail execution. ## Properties [Section titled “Properties”](#properties) ### guardrail [Section titled “guardrail”](#guardrail) ```ts guardrail: InputGuardrailMetadata; ``` The metadata of the guardrail. *** ### output [Section titled “output”](#output) ```ts output: GuardrailFunctionOutput; ``` The output of the guardrail. # MCPBlobResourceContent Binary resource content returned by `readResource`. ## Indexable [Section titled “Indexable”](#indexable) ```ts [key: string]: unknown ``` ## Properties [Section titled “Properties”](#properties) ### blob [Section titled “blob”](#blob) ```ts blob: string; ``` *** ### mimeType? [Section titled “mimeType?”](#mimetype) ```ts optional mimeType?: string; ``` *** ### uri [Section titled “uri”](#uri) ```ts uri: string; ``` # MCPListResourcesParams Minimal params accepted by MCP resource-listing methods. ## Indexable [Section titled “Indexable”](#indexable) ```ts [key: string]: unknown ``` ## Properties [Section titled “Properties”](#properties) ### cursor? [Section titled “cursor?”](#cursor) ```ts optional cursor?: string; ``` # MCPListResourcesResult Result returned by `listResources`. ## Indexable [Section titled “Indexable”](#indexable) ```ts [key: string]: unknown ``` ## Properties [Section titled “Properties”](#properties) ### nextCursor? [Section titled “nextCursor?”](#nextcursor) ```ts optional nextCursor?: string; ``` *** ### resources [Section titled “resources”](#resources) ```ts resources: MCPResource[]; ``` # MCPListResourceTemplatesResult Result returned by `listResourceTemplates`. ## Indexable [Section titled “Indexable”](#indexable) ```ts [key: string]: unknown ``` ## Properties [Section titled “Properties”](#properties) ### nextCursor? [Section titled “nextCursor?”](#nextcursor) ```ts optional nextCursor?: string; ``` *** ### resourceTemplates [Section titled “resourceTemplates”](#resourcetemplates) ```ts resourceTemplates: MCPResourceTemplate[]; ``` # MCPReadResourceResult Result returned by `readResource`. ## Indexable [Section titled “Indexable”](#indexable) ```ts [key: string]: unknown ``` ## Properties [Section titled “Properties”](#properties) ### contents [Section titled “contents”](#contents) ```ts contents: MCPResourceContent[]; ``` # MCPResource Minimal MCP resource definition used by this SDK. ## Indexable [Section titled “Indexable”](#indexable) ```ts [key: string]: unknown ``` ## Properties [Section titled “Properties”](#properties) ### annotations? [Section titled “annotations?”](#annotations) ```ts optional annotations?: Record; ``` *** ### description? [Section titled “description?”](#description) ```ts optional description?: string; ``` *** ### mimeType? [Section titled “mimeType?”](#mimetype) ```ts optional mimeType?: string; ``` *** ### name? [Section titled “name?”](#name) ```ts optional name?: string; ``` *** ### size? [Section titled “size?”](#size) ```ts optional size?: number; ``` *** ### title? [Section titled “title?”](#title) ```ts optional title?: string; ``` *** ### uri [Section titled “uri”](#uri) ```ts uri: string; ``` # MCPResourceTemplate Minimal MCP resource template definition used by this SDK. ## Indexable [Section titled “Indexable”](#indexable) ```ts [key: string]: unknown ``` ## Properties [Section titled “Properties”](#properties) ### annotations? [Section titled “annotations?”](#annotations) ```ts optional annotations?: Record; ``` *** ### description? [Section titled “description?”](#description) ```ts optional description?: string; ``` *** ### mimeType? [Section titled “mimeType?”](#mimetype) ```ts optional mimeType?: string; ``` *** ### name? [Section titled “name?”](#name) ```ts optional name?: string; ``` *** ### title? [Section titled “title?”](#title) ```ts optional title?: string; ``` *** ### uriTemplate [Section titled “uriTemplate”](#uritemplate) ```ts uriTemplate: string; ``` # MCPServer Interface for MCP server implementations. Provides methods for connecting, listing tools, calling tools, and cleanup. ## Extended by [Section titled “Extended by”](#extended-by) * [`MCPServerWithResources`](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/) ## Properties [Section titled “Properties”](#properties) ### cacheToolsList [Section titled “cacheToolsList”](#cachetoolslist) ```ts cacheToolsList: boolean; ``` *** ### errorFunction? [Section titled “errorFunction?”](#errorfunction) ```ts optional errorFunction?: | MCPToolErrorFunction | null; ``` Optional function to convert MCP tool failures into model-visible messages. Set to null to rethrow errors instead of converting them. *** ### name [Section titled “name”](#name) ```ts readonly name: string; ``` *** ### toolFilter? [Section titled “toolFilter?”](#toolfilter) ```ts optional toolFilter?: | MCPToolFilterCallable | MCPToolFilterStatic; ``` *** ### toolMetaResolver? [Section titled “toolMetaResolver?”](#toolmetaresolver) ```ts optional toolMetaResolver?: MCPToolMetaResolver; ``` ## Methods [Section titled “Methods”](#methods) ### callTool() [Section titled “callTool()”](#calltool) ```ts callTool( toolName, args, meta?): Promise; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ---------- | --------------------------------------- | | `toolName` | `string` | | `args` | `Record`<`string`, `unknown`> \| `null` | | `meta?` | `Record`<`string`, `unknown`> \| `null` | #### Returns [Section titled “Returns”](#returns) `Promise`<`object`\[]> *** ### close() [Section titled “close()”](#close) ```ts close(): Promise; ``` #### Returns [Section titled “Returns”](#returns-1) `Promise`<`void`> *** ### connect() [Section titled “connect()”](#connect) ```ts connect(): Promise; ``` #### Returns [Section titled “Returns”](#returns-2) `Promise`<`void`> *** ### invalidateToolsCache() [Section titled “invalidateToolsCache()”](#invalidatetoolscache) ```ts invalidateToolsCache(): Promise; ``` #### Returns [Section titled “Returns”](#returns-3) `Promise`<`void`> *** ### listTools() [Section titled “listTools()”](#listtools) ```ts listTools(): Promise; ``` #### Returns [Section titled “Returns”](#returns-4) `Promise`<`object`\[]> # MCPServerWithResources Extended MCP server surface for servers that expose resources. ## Extends [Section titled “Extends”](#extends) * [`MCPServer`](/openai-agents-js/openai/agents/interfaces/mcpserver/) ## Properties [Section titled “Properties”](#properties) ### cacheToolsList [Section titled “cacheToolsList”](#cachetoolslist) ```ts cacheToolsList: boolean; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from) [`MCPServer`](/openai-agents-js/openai/agents/interfaces/mcpserver/).[`cacheToolsList`](/openai-agents-js/openai/agents/interfaces/mcpserver/#cachetoolslist) *** ### errorFunction? [Section titled “errorFunction?”](#errorfunction) ```ts optional errorFunction?: | MCPToolErrorFunction | null; ``` Optional function to convert MCP tool failures into model-visible messages. Set to null to rethrow errors instead of converting them. #### Inherited from [Section titled “Inherited from”](#inherited-from-1) [`MCPServer`](/openai-agents-js/openai/agents/interfaces/mcpserver/).[`errorFunction`](/openai-agents-js/openai/agents/interfaces/mcpserver/#errorfunction) *** ### name [Section titled “name”](#name) ```ts readonly name: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-2) [`MCPServer`](/openai-agents-js/openai/agents/interfaces/mcpserver/).[`name`](/openai-agents-js/openai/agents/interfaces/mcpserver/#name) *** ### toolFilter? [Section titled “toolFilter?”](#toolfilter) ```ts optional toolFilter?: | MCPToolFilterCallable | MCPToolFilterStatic; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-3) [`MCPServer`](/openai-agents-js/openai/agents/interfaces/mcpserver/).[`toolFilter`](/openai-agents-js/openai/agents/interfaces/mcpserver/#toolfilter) *** ### toolMetaResolver? [Section titled “toolMetaResolver?”](#toolmetaresolver) ```ts optional toolMetaResolver?: MCPToolMetaResolver; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-4) [`MCPServer`](/openai-agents-js/openai/agents/interfaces/mcpserver/).[`toolMetaResolver`](/openai-agents-js/openai/agents/interfaces/mcpserver/#toolmetaresolver) ## Methods [Section titled “Methods”](#methods) ### callTool() [Section titled “callTool()”](#calltool) ```ts callTool( toolName, args, meta?): Promise; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ---------- | --------------------------------------- | | `toolName` | `string` | | `args` | `Record`<`string`, `unknown`> \| `null` | | `meta?` | `Record`<`string`, `unknown`> \| `null` | #### Returns [Section titled “Returns”](#returns) `Promise`<`object`\[]> #### Inherited from [Section titled “Inherited from”](#inherited-from-5) [`MCPServer`](/openai-agents-js/openai/agents/interfaces/mcpserver/).[`callTool`](/openai-agents-js/openai/agents/interfaces/mcpserver/#calltool) *** ### close() [Section titled “close()”](#close) ```ts close(): Promise; ``` #### Returns [Section titled “Returns”](#returns-1) `Promise`<`void`> #### Inherited from [Section titled “Inherited from”](#inherited-from-6) [`MCPServer`](/openai-agents-js/openai/agents/interfaces/mcpserver/).[`close`](/openai-agents-js/openai/agents/interfaces/mcpserver/#close) *** ### connect() [Section titled “connect()”](#connect) ```ts connect(): Promise; ``` #### Returns [Section titled “Returns”](#returns-2) `Promise`<`void`> #### Inherited from [Section titled “Inherited from”](#inherited-from-7) [`MCPServer`](/openai-agents-js/openai/agents/interfaces/mcpserver/).[`connect`](/openai-agents-js/openai/agents/interfaces/mcpserver/#connect) *** ### invalidateToolsCache() [Section titled “invalidateToolsCache()”](#invalidatetoolscache) ```ts invalidateToolsCache(): Promise; ``` #### Returns [Section titled “Returns”](#returns-3) `Promise`<`void`> #### Inherited from [Section titled “Inherited from”](#inherited-from-8) [`MCPServer`](/openai-agents-js/openai/agents/interfaces/mcpserver/).[`invalidateToolsCache`](/openai-agents-js/openai/agents/interfaces/mcpserver/#invalidatetoolscache) *** ### listResources() [Section titled “listResources()”](#listresources) ```ts listResources(params?): Promise; ``` #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | --------- | ---------------------------------------------------------------------------------------------- | | `params?` | [`MCPListResourcesParams`](/openai-agents-js/openai/agents/interfaces/mcplistresourcesparams/) | #### Returns [Section titled “Returns”](#returns-4) `Promise`<[`MCPListResourcesResult`](/openai-agents-js/openai/agents/interfaces/mcplistresourcesresult/)> *** ### listResourceTemplates() [Section titled “listResourceTemplates()”](#listresourcetemplates) ```ts listResourceTemplates(params?): Promise; ``` #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | --------- | ---------------------------------------------------------------------------------------------- | | `params?` | [`MCPListResourcesParams`](/openai-agents-js/openai/agents/interfaces/mcplistresourcesparams/) | #### Returns [Section titled “Returns”](#returns-5) `Promise`<[`MCPListResourceTemplatesResult`](/openai-agents-js/openai/agents/interfaces/mcplistresourcetemplatesresult/)> *** ### listTools() [Section titled “listTools()”](#listtools) ```ts listTools(): Promise; ``` #### Returns [Section titled “Returns”](#returns-6) `Promise`<`object`\[]> #### Inherited from [Section titled “Inherited from”](#inherited-from-9) [`MCPServer`](/openai-agents-js/openai/agents/interfaces/mcpserver/).[`listTools`](/openai-agents-js/openai/agents/interfaces/mcpserver/#listtools) *** ### readResource() [Section titled “readResource()”](#readresource) ```ts readResource(uri): Promise; ``` #### Parameters [Section titled “Parameters”](#parameters-3) | Parameter | Type | | --------- | -------- | | `uri` | `string` | #### Returns [Section titled “Returns”](#returns-7) `Promise`<[`MCPReadResourceResult`](/openai-agents-js/openai/agents/interfaces/mcpreadresourceresult/)> # MCPTextResourceContent Text resource content returned by `readResource`. ## Indexable [Section titled “Indexable”](#indexable) ```ts [key: string]: unknown ``` ## Properties [Section titled “Properties”](#properties) ### mimeType? [Section titled “mimeType?”](#mimetype) ```ts optional mimeType?: string; ``` *** ### text [Section titled “text”](#text) ```ts text: string; ``` *** ### uri [Section titled “uri”](#uri) ```ts uri: string; ``` # MCPToolFilterContext Context information available to tool filter functions. ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | -------------------------------------------------------------------------------- | | `TContext` | [`UnknownContext`](/openai-agents-js/openai/agents/type-aliases/unknowncontext/) | ## Properties [Section titled “Properties”](#properties) ### agent [Section titled “agent”](#agent) ```ts agent: Agent; ``` The agent requesting the tools. *** ### runContext [Section titled “runContext”](#runcontext) ```ts runContext: RunContext; ``` The current run context. *** ### serverName [Section titled “serverName”](#servername) ```ts serverName: string; ``` Name of the MCP server providing the tools. # MCPToolFilterStatic Static tool filter configuration using allow and block lists. ## Properties [Section titled “Properties”](#properties) ### allowedToolNames? [Section titled “allowedToolNames?”](#allowedtoolnames) ```ts optional allowedToolNames?: string[]; ``` Optional list of tool names to allow. *** ### blockedToolNames? [Section titled “blockedToolNames?”](#blockedtoolnames) ```ts optional blockedToolNames?: string[]; ``` Optional list of tool names to block. # MCPToolMetaContext Context information available to MCP tool meta resolver functions. ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | -------------------------------------------------------------------------------- | | `TContext` | [`UnknownContext`](/openai-agents-js/openai/agents/type-aliases/unknowncontext/) | ## Properties [Section titled “Properties”](#properties) ### arguments [Section titled “arguments”](#arguments) ```ts arguments: Record | null; ``` Parsed tool arguments. *** ### runContext [Section titled “runContext”](#runcontext) ```ts runContext: RunContext; ``` The current run context. *** ### serverName [Section titled “serverName”](#servername) ```ts serverName: string; ``` Name of the MCP server. *** ### toolName [Section titled “toolName”](#toolname) ```ts toolName: string; ``` Name of the tool being invoked. # Model The base interface for calling an LLM. ## Methods [Section titled “Methods”](#methods) ### getResponse() [Section titled “getResponse()”](#getresponse) ```ts getResponse(request): Promise; ``` Get a response from the model. #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | --------- | ---------------------------------------------------------------------------- | ---------------------------------- | | `request` | [`ModelRequest`](/openai-agents-js/openai/agents/type-aliases/modelrequest/) | The request to get a response for. | #### Returns [Section titled “Returns”](#returns) `Promise`<[`ModelResponse`](/openai-agents-js/openai/agents/type-aliases/modelresponse/)> *** ### getRetryAdvice()? [Section titled “getRetryAdvice()?”](#getretryadvice) ```ts optional getRetryAdvice(args): | ModelRetryAdvice | Promise< | ModelRetryAdvice | undefined> | undefined; ``` Provide optional retry advice for a failed request. #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | --------- | -------------------------------------------------------------------------------------------------- | | `args` | [`ModelRetryAdviceRequest`](/openai-agents-js/openai/agents/type-aliases/modelretryadvicerequest/) | #### Returns [Section titled “Returns”](#returns-1) \| [`ModelRetryAdvice`](/openai-agents-js/openai/agents/type-aliases/modelretryadvice/) | `Promise`< | [`ModelRetryAdvice`](/openai-agents-js/openai/agents/type-aliases/modelretryadvice/) | `undefined`> | `undefined` *** ### getStreamedResponse() [Section titled “getStreamedResponse()”](#getstreamedresponse) ```ts getStreamedResponse(request): AsyncIterable; ``` Get a streamed response from the model. #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | --------- | ---------------------------------------------------------------------------- | | `request` | [`ModelRequest`](/openai-agents-js/openai/agents/type-aliases/modelrequest/) | #### Returns [Section titled “Returns”](#returns-2) `AsyncIterable`<[`StreamEvent`](/openai-agents-js/openai/agents/type-aliases/streamevent/)> # ModelProvider The base interface for a model provider. The model provider is responsible for looking up `Model` instances by name. ## Methods [Section titled “Methods”](#methods) ### getModel() [Section titled “getModel()”](#getmodel) ```ts getModel(modelName?): | Model | Promise; ``` Get a model by name #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | ------------ | -------- | ----------------------------- | | `modelName?` | `string` | The name of the model to get. | #### Returns [Section titled “Returns”](#returns) \| [`Model`](/openai-agents-js/openai/agents/interfaces/model/) | `Promise`<[`Model`](/openai-agents-js/openai/agents/interfaces/model/)> # OpenAIResponsesCompactionAwareSession Interface representing a persistent session store for conversation history. ## Extends [Section titled “Extends”](#extends) * [`Session`](/openai-agents-js/openai/agents/interfaces/session/) ## Methods [Section titled “Methods”](#methods) ### addItems() [Section titled “addItems()”](#additems) ```ts addItems(items): Promise; ``` Append new items to the conversation history. #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | --------- | ----------------------------------------------------------------------------------- | ------------------------------------ | | `items` | [`AgentInputItem`](/openai-agents-js/openai/agents/type-aliases/agentinputitem/)\[] | Items to add to the session history. | #### Returns [Section titled “Returns”](#returns) `Promise`<`void`> #### Inherited from [Section titled “Inherited from”](#inherited-from) [`Session`](/openai-agents-js/openai/agents/interfaces/session/).[`addItems`](/openai-agents-js/openai/agents/interfaces/session/#additems) *** ### clearSession() [Section titled “clearSession()”](#clearsession) ```ts clearSession(): Promise; ``` Remove all items that belong to the session and reset its state. #### Returns [Section titled “Returns”](#returns-1) `Promise`<`void`> #### Inherited from [Section titled “Inherited from”](#inherited-from-1) [`Session`](/openai-agents-js/openai/agents/interfaces/session/).[`clearSession`](/openai-agents-js/openai/agents/interfaces/session/#clearsession) *** ### getItems() [Section titled “getItems()”](#getitems) ```ts getItems(limit?): Promise; ``` Retrieve items from the conversation history. #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | Description | | --------- | -------- | --------------------------------------------------------------------------------------------------------------------------- | | `limit?` | `number` | The maximum number of items to return. When provided the most recent limit items should be returned in chronological order. | #### Returns [Section titled “Returns”](#returns-2) `Promise`<[`AgentInputItem`](/openai-agents-js/openai/agents/type-aliases/agentinputitem/)\[]> #### Inherited from [Section titled “Inherited from”](#inherited-from-2) [`Session`](/openai-agents-js/openai/agents/interfaces/session/).[`getItems`](/openai-agents-js/openai/agents/interfaces/session/#getitems) *** ### getSessionId() [Section titled “getSessionId()”](#getsessionid) ```ts getSessionId(): Promise; ``` Ensure and return the identifier for this session. #### Returns [Section titled “Returns”](#returns-3) `Promise`<`string`> #### Inherited from [Section titled “Inherited from”](#inherited-from-3) [`Session`](/openai-agents-js/openai/agents/interfaces/session/).[`getSessionId`](/openai-agents-js/openai/agents/interfaces/session/#getsessionid) *** ### popItem() [Section titled “popItem()”](#popitem) ```ts popItem(): Promise< | AgentInputItem | undefined>; ``` Remove and return the most recent item from the conversation history if it exists. #### Returns [Section titled “Returns”](#returns-4) `Promise`< | [`AgentInputItem`](/openai-agents-js/openai/agents/type-aliases/agentinputitem/) | `undefined`> #### Inherited from [Section titled “Inherited from”](#inherited-from-4) [`Session`](/openai-agents-js/openai/agents/interfaces/session/).[`popItem`](/openai-agents-js/openai/agents/interfaces/session/#popitem) *** ### prepareHistoryItemForModelInput()? [Section titled “prepareHistoryItemForModelInput()?”](#preparehistoryitemformodelinput) ```ts optional prepareHistoryItemForModelInput(item): AgentInputItem; ``` Optionally rewrite a stored history item before it is sent back to the model. Session implementations can use this to strip provider-managed replay metadata while preserving their public `getItems()` shape for UI and deletion workflows. #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | --------- | -------------------------------------------------------------------------------- | | `item` | [`AgentInputItem`](/openai-agents-js/openai/agents/type-aliases/agentinputitem/) | #### Returns [Section titled “Returns”](#returns-5) [`AgentInputItem`](/openai-agents-js/openai/agents/type-aliases/agentinputitem/) #### Inherited from [Section titled “Inherited from”](#inherited-from-5) [`Session`](/openai-agents-js/openai/agents/interfaces/session/).[`prepareHistoryItemForModelInput`](/openai-agents-js/openai/agents/interfaces/session/#preparehistoryitemformodelinput) *** ### preserveReasoningItemIdsForPersistence()? [Section titled “preserveReasoningItemIdsForPersistence()?”](#preservereasoningitemidsforpersistence) ```ts optional preserveReasoningItemIdsForPersistence(): boolean; ``` Optionally preserve reasoning item IDs when persisting generated output. Some remote session stores require provider-assigned reasoning identities to accept stored reasoning items, even when model replay should omit those IDs. #### Returns [Section titled “Returns”](#returns-6) `boolean` #### Inherited from [Section titled “Inherited from”](#inherited-from-6) [`Session`](/openai-agents-js/openai/agents/interfaces/session/).[`preserveReasoningItemIdsForPersistence`](/openai-agents-js/openai/agents/interfaces/session/#preservereasoningitemidsforpersistence) *** ### runCompaction() [Section titled “runCompaction()”](#runcompaction) ```ts runCompaction(args?): | OpenAIResponsesCompactionResult | Promise< | OpenAIResponsesCompactionResult | null> | null; ``` Invoked by the runner after it persists a completed turn into the session. Implementations may decide to call `responses.compact` (or an equivalent API) and replace the stored history. This hook is best-effort. Implementations should consider handling transient failures and deciding whether to retry or skip compaction for the current turn. #### Parameters [Section titled “Parameters”](#parameters-3) | Parameter | Type | | --------- | -------------------------------------------------------------------------------------------------------------- | | `args?` | [`OpenAIResponsesCompactionArgs`](/openai-agents-js/openai/agents/type-aliases/openairesponsescompactionargs/) | #### Returns [Section titled “Returns”](#returns-7) \| [`OpenAIResponsesCompactionResult`](/openai-agents-js/openai/agents/type-aliases/openairesponsescompactionresult/) | `Promise`< | [`OpenAIResponsesCompactionResult`](/openai-agents-js/openai/agents/type-aliases/openairesponsescompactionresult/) | `null`> | `null` # OutputGuardrail A guardrail that checks the output of the agent. ## Extended by [Section titled “Extended by”](#extended-by) * [`RealtimeOutputGuardrail`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimeoutputguardrail/) ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | ------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------- | | `TOutput` *extends* [`AgentOutputType`](/openai-agents-js/openai/agents/type-aliases/agentoutputtype/) | [`TextOutput`](/openai-agents-js/openai/agents/type-aliases/textoutput/) | | `TContext` | [`UnknownContext`](/openai-agents-js/openai/agents/type-aliases/unknowncontext/) | ## Properties [Section titled “Properties”](#properties) ### execute [Section titled “execute”](#execute) ```ts execute: OutputGuardrailFunction; ``` The function that performs the guardrail check. *** ### name [Section titled “name”](#name) ```ts name: string; ``` The name of the guardrail. # OutputGuardrailDefinition Definition of an output guardrail. ## Extends [Section titled “Extends”](#extends) * [`OutputGuardrailMetadata`](/openai-agents-js/openai/agents/interfaces/outputguardrailmetadata/) ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | ------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------ | | `TMeta` | [`OutputGuardrailMetadata`](/openai-agents-js/openai/agents/interfaces/outputguardrailmetadata/) | | `TOutput` *extends* [`AgentOutputType`](/openai-agents-js/openai/agents/type-aliases/agentoutputtype/) | [`TextOutput`](/openai-agents-js/openai/agents/type-aliases/textoutput/) | | `TContext` | [`UnknownContext`](/openai-agents-js/openai/agents/type-aliases/unknowncontext/) | ## Properties [Section titled “Properties”](#properties) ### guardrailFunction [Section titled “guardrailFunction”](#guardrailfunction) ```ts guardrailFunction: OutputGuardrailFunction; ``` *** ### name [Section titled “name”](#name) ```ts name: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from) [`OutputGuardrailMetadata`](/openai-agents-js/openai/agents/interfaces/outputguardrailmetadata/).[`name`](/openai-agents-js/openai/agents/interfaces/outputguardrailmetadata/#name) *** ### type [Section titled “type”](#type) ```ts type: "output"; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-1) [`OutputGuardrailMetadata`](/openai-agents-js/openai/agents/interfaces/outputguardrailmetadata/).[`type`](/openai-agents-js/openai/agents/interfaces/outputguardrailmetadata/#type) ## Methods [Section titled “Methods”](#methods) ### run() [Section titled “run()”](#run) ```ts run(args): Promise>; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ------------------------------------------------------------------------------------------------------------------------------- | | `args` | [`OutputGuardrailFunctionArgs`](/openai-agents-js/openai/agents/interfaces/outputguardrailfunctionargs/)<`TContext`, `TOutput`> | #### Returns [Section titled “Returns”](#returns) `Promise`<[`OutputGuardrailResult`](/openai-agents-js/openai/agents/interfaces/outputguardrailresult/)<`TMeta`, `TOutput`>> # OutputGuardrailFunctionArgs Arguments for an output guardrail function. ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | ------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------- | | `TContext` | [`UnknownContext`](/openai-agents-js/openai/agents/type-aliases/unknowncontext/) | | `TOutput` *extends* [`AgentOutputType`](/openai-agents-js/openai/agents/type-aliases/agentoutputtype/) | [`TextOutput`](/openai-agents-js/openai/agents/type-aliases/textoutput/) | ## Properties [Section titled “Properties”](#properties) ### agent [Section titled “agent”](#agent) ```ts agent: Agent; ``` *** ### agentOutput [Section titled “agentOutput”](#agentoutput) ```ts agentOutput: ResolvedAgentOutput; ``` *** ### context [Section titled “context”](#context) ```ts context: RunContext; ``` *** ### details? [Section titled “details?”](#details) ```ts optional details?: object; ``` Additional details about the agent output. | Name | Type | Description | | ---------------- | ------------------------------------------------------------------------------------- | ------------------------------------------------------------------ | | `modelResponse?` | [`ModelResponse`](/openai-agents-js/openai/agents/type-aliases/modelresponse/) | Model response associated with the output if available. | | `output?` | [`AgentOutputItem`](/openai-agents-js/openai/agents/type-aliases/agentoutputitem/)\[] | Model output items generated during the run (excluding approvals). | # OutputGuardrailMetadata Metadata for an output guardrail. ## Extended by [Section titled “Extended by”](#extended-by) * [`OutputGuardrailDefinition`](/openai-agents-js/openai/agents/interfaces/outputguardraildefinition/) ## Properties [Section titled “Properties”](#properties) ### name [Section titled “name”](#name) ```ts name: string; ``` *** ### type [Section titled “type”](#type) ```ts type: "output"; ``` # OutputGuardrailResult The result of an output guardrail execution. ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | ------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------ | | `TMeta` | [`OutputGuardrailMetadata`](/openai-agents-js/openai/agents/interfaces/outputguardrailmetadata/) | | `TOutput` *extends* [`AgentOutputType`](/openai-agents-js/openai/agents/type-aliases/agentoutputtype/) | [`TextOutput`](/openai-agents-js/openai/agents/type-aliases/textoutput/) | ## Properties [Section titled “Properties”](#properties) ### agent [Section titled “agent”](#agent) ```ts agent: Agent; ``` The agent that ran. *** ### agentOutput [Section titled “agentOutput”](#agentoutput) ```ts agentOutput: ResolvedAgentOutput; ``` The output of the agent that ran. *** ### guardrail [Section titled “guardrail”](#guardrail) ```ts guardrail: TMeta; ``` The metadata of the guardrail. *** ### output [Section titled “output”](#output) ```ts output: GuardrailFunctionOutput; ``` The output of the guardrail. # Session Interface representing a persistent session store for conversation history. ## Extended by [Section titled “Extended by”](#extended-by) * [`SessionHistoryRewriteAwareSession`](/openai-agents-js/openai/agents/interfaces/sessionhistoryrewriteawaresession/) * [`OpenAIResponsesCompactionAwareSession`](/openai-agents-js/openai/agents/interfaces/openairesponsescompactionawaresession/) ## Methods [Section titled “Methods”](#methods) ### addItems() [Section titled “addItems()”](#additems) ```ts addItems(items): Promise; ``` Append new items to the conversation history. #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | --------- | ----------------------------------------------------------------------------------- | ------------------------------------ | | `items` | [`AgentInputItem`](/openai-agents-js/openai/agents/type-aliases/agentinputitem/)\[] | Items to add to the session history. | #### Returns [Section titled “Returns”](#returns) `Promise`<`void`> *** ### clearSession() [Section titled “clearSession()”](#clearsession) ```ts clearSession(): Promise; ``` Remove all items that belong to the session and reset its state. #### Returns [Section titled “Returns”](#returns-1) `Promise`<`void`> *** ### getItems() [Section titled “getItems()”](#getitems) ```ts getItems(limit?): Promise; ``` Retrieve items from the conversation history. #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | Description | | --------- | -------- | --------------------------------------------------------------------------------------------------------------------------- | | `limit?` | `number` | The maximum number of items to return. When provided the most recent limit items should be returned in chronological order. | #### Returns [Section titled “Returns”](#returns-2) `Promise`<[`AgentInputItem`](/openai-agents-js/openai/agents/type-aliases/agentinputitem/)\[]> *** ### getSessionId() [Section titled “getSessionId()”](#getsessionid) ```ts getSessionId(): Promise; ``` Ensure and return the identifier for this session. #### Returns [Section titled “Returns”](#returns-3) `Promise`<`string`> *** ### popItem() [Section titled “popItem()”](#popitem) ```ts popItem(): Promise< | AgentInputItem | undefined>; ``` Remove and return the most recent item from the conversation history if it exists. #### Returns [Section titled “Returns”](#returns-4) `Promise`< | [`AgentInputItem`](/openai-agents-js/openai/agents/type-aliases/agentinputitem/) | `undefined`> *** ### prepareHistoryItemForModelInput()? [Section titled “prepareHistoryItemForModelInput()?”](#preparehistoryitemformodelinput) ```ts optional prepareHistoryItemForModelInput(item): AgentInputItem; ``` Optionally rewrite a stored history item before it is sent back to the model. Session implementations can use this to strip provider-managed replay metadata while preserving their public `getItems()` shape for UI and deletion workflows. #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | --------- | -------------------------------------------------------------------------------- | | `item` | [`AgentInputItem`](/openai-agents-js/openai/agents/type-aliases/agentinputitem/) | #### Returns [Section titled “Returns”](#returns-5) [`AgentInputItem`](/openai-agents-js/openai/agents/type-aliases/agentinputitem/) *** ### preserveReasoningItemIdsForPersistence()? [Section titled “preserveReasoningItemIdsForPersistence()?”](#preservereasoningitemidsforpersistence) ```ts optional preserveReasoningItemIdsForPersistence(): boolean; ``` Optionally preserve reasoning item IDs when persisting generated output. Some remote session stores require provider-assigned reasoning identities to accept stored reasoning items, even when model replay should omit those IDs. #### Returns [Section titled “Returns”](#returns-6) `boolean` # SessionHistoryRewriteAwareSession Interface representing a persistent session store for conversation history. ## Extends [Section titled “Extends”](#extends) * [`Session`](/openai-agents-js/openai/agents/interfaces/session/) ## Methods [Section titled “Methods”](#methods) ### addItems() [Section titled “addItems()”](#additems) ```ts addItems(items): Promise; ``` Append new items to the conversation history. #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | --------- | ----------------------------------------------------------------------------------- | ------------------------------------ | | `items` | [`AgentInputItem`](/openai-agents-js/openai/agents/type-aliases/agentinputitem/)\[] | Items to add to the session history. | #### Returns [Section titled “Returns”](#returns) `Promise`<`void`> #### Inherited from [Section titled “Inherited from”](#inherited-from) [`Session`](/openai-agents-js/openai/agents/interfaces/session/).[`addItems`](/openai-agents-js/openai/agents/interfaces/session/#additems) *** ### applyHistoryMutations() [Section titled “applyHistoryMutations()”](#applyhistorymutations) ```ts applyHistoryMutations(args): void | Promise; ``` #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | --------- | ------------------------------------------------------------------------------------------------------ | | `args` | [`SessionHistoryRewriteArgs`](/openai-agents-js/openai/agents/type-aliases/sessionhistoryrewriteargs/) | #### Returns [Section titled “Returns”](#returns-1) `void` | `Promise`<`void`> *** ### clearSession() [Section titled “clearSession()”](#clearsession) ```ts clearSession(): Promise; ``` Remove all items that belong to the session and reset its state. #### Returns [Section titled “Returns”](#returns-2) `Promise`<`void`> #### Inherited from [Section titled “Inherited from”](#inherited-from-1) [`Session`](/openai-agents-js/openai/agents/interfaces/session/).[`clearSession`](/openai-agents-js/openai/agents/interfaces/session/#clearsession) *** ### getItems() [Section titled “getItems()”](#getitems) ```ts getItems(limit?): Promise; ``` Retrieve items from the conversation history. #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | Description | | --------- | -------- | --------------------------------------------------------------------------------------------------------------------------- | | `limit?` | `number` | The maximum number of items to return. When provided the most recent limit items should be returned in chronological order. | #### Returns [Section titled “Returns”](#returns-3) `Promise`<[`AgentInputItem`](/openai-agents-js/openai/agents/type-aliases/agentinputitem/)\[]> #### Inherited from [Section titled “Inherited from”](#inherited-from-2) [`Session`](/openai-agents-js/openai/agents/interfaces/session/).[`getItems`](/openai-agents-js/openai/agents/interfaces/session/#getitems) *** ### getSessionId() [Section titled “getSessionId()”](#getsessionid) ```ts getSessionId(): Promise; ``` Ensure and return the identifier for this session. #### Returns [Section titled “Returns”](#returns-4) `Promise`<`string`> #### Inherited from [Section titled “Inherited from”](#inherited-from-3) [`Session`](/openai-agents-js/openai/agents/interfaces/session/).[`getSessionId`](/openai-agents-js/openai/agents/interfaces/session/#getsessionid) *** ### popItem() [Section titled “popItem()”](#popitem) ```ts popItem(): Promise< | AgentInputItem | undefined>; ``` Remove and return the most recent item from the conversation history if it exists. #### Returns [Section titled “Returns”](#returns-5) `Promise`< | [`AgentInputItem`](/openai-agents-js/openai/agents/type-aliases/agentinputitem/) | `undefined`> #### Inherited from [Section titled “Inherited from”](#inherited-from-4) [`Session`](/openai-agents-js/openai/agents/interfaces/session/).[`popItem`](/openai-agents-js/openai/agents/interfaces/session/#popitem) *** ### prepareHistoryItemForModelInput()? [Section titled “prepareHistoryItemForModelInput()?”](#preparehistoryitemformodelinput) ```ts optional prepareHistoryItemForModelInput(item): AgentInputItem; ``` Optionally rewrite a stored history item before it is sent back to the model. Session implementations can use this to strip provider-managed replay metadata while preserving their public `getItems()` shape for UI and deletion workflows. #### Parameters [Section titled “Parameters”](#parameters-3) | Parameter | Type | | --------- | -------------------------------------------------------------------------------- | | `item` | [`AgentInputItem`](/openai-agents-js/openai/agents/type-aliases/agentinputitem/) | #### Returns [Section titled “Returns”](#returns-6) [`AgentInputItem`](/openai-agents-js/openai/agents/type-aliases/agentinputitem/) #### Inherited from [Section titled “Inherited from”](#inherited-from-5) [`Session`](/openai-agents-js/openai/agents/interfaces/session/).[`prepareHistoryItemForModelInput`](/openai-agents-js/openai/agents/interfaces/session/#preparehistoryitemformodelinput) *** ### preserveReasoningItemIdsForPersistence()? [Section titled “preserveReasoningItemIdsForPersistence()?”](#preservereasoningitemidsforpersistence) ```ts optional preserveReasoningItemIdsForPersistence(): boolean; ``` Optionally preserve reasoning item IDs when persisting generated output. Some remote session stores require provider-assigned reasoning identities to accept stored reasoning items, even when model replay should omit those IDs. #### Returns [Section titled “Returns”](#returns-7) `boolean` #### Inherited from [Section titled “Inherited from”](#inherited-from-6) [`Session`](/openai-agents-js/openai/agents/interfaces/session/).[`preserveReasoningItemIdsForPersistence`](/openai-agents-js/openai/agents/interfaces/session/#preservereasoningitemidsforpersistence) # Shell Executes shell commands on behalf of the agent. ## Methods [Section titled “Methods”](#methods) ### run() [Section titled “run()”](#run) ```ts run(action): Promise; ``` Runs the given action and returns the resulting output. #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ------------------------- | ---------------------------------------------------------------------------------- | | `action` | { `commands`: `string`\[]; `maxOutputLength?`: `number`; `timeoutMs?`: `number`; } | | `action.commands` | `string`\[] | | `action.maxOutputLength?` | `number` | | `action.timeoutMs?` | `number` | #### Returns [Section titled “Returns”](#returns) `Promise`<[`ShellResult`](/openai-agents-js/openai/agents/type-aliases/shellresult/)> # ToolGuardrailFunctionOutput The output of a tool guardrail function. `behavior` drives runner control flow; `outputInfo` is optional, structured metadata for tracing or debugging. ## Properties [Section titled “Properties”](#properties) ### behavior [Section titled “behavior”](#behavior) ```ts behavior: ToolGuardrailBehavior; ``` The behavior the runner should take in response to this guardrail. *** ### outputInfo? [Section titled “outputInfo?”](#outputinfo) ```ts optional outputInfo?: any; ``` Additional data about the guardrail evaluation. # ToolGuardrailMetadata ## Properties [Section titled “Properties”](#properties) ### name [Section titled “name”](#name) ```ts name: string; ``` *** ### type [Section titled “type”](#type) ```ts type: "tool_output" | "tool_input"; ``` # ToolInputGuardrailData Input data passed to a tool input guardrail function. ## Extended by [Section titled “Extended by”](#extended-by) * [`ToolOutputGuardrailData`](/openai-agents-js/openai/agents/interfaces/tooloutputguardraildata/) ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | -------------------------------------------------------------------------------- | | `TContext` | [`UnknownContext`](/openai-agents-js/openai/agents/type-aliases/unknowncontext/) | ## Properties [Section titled “Properties”](#properties) ### agent [Section titled “agent”](#agent) ```ts agent: Agent; ``` *** ### context [Section titled “context”](#context) ```ts context: RunContext; ``` *** ### toolCall [Section titled “toolCall”](#toolcall) ```ts toolCall: object; ``` | Name | Type | | --------------- | -------------------------------------------------- | | `arguments` | `string` | | `callId` | `string` | | `id?` | `string` | | `name` | `string` | | `namespace?` | `string` | | `providerData?` | `Record`<`string`, `any`> | | `status?` | `"completed"` \| `"in_progress"` \| `"incomplete"` | | `type` | `"function_call"` | # ToolInputGuardrailDefinition ## Extends [Section titled “Extends”](#extends) * `ToolGuardrailBase` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | -------------------------------------------------------------------------------- | | `TContext` | [`UnknownContext`](/openai-agents-js/openai/agents/type-aliases/unknowncontext/) | ## Properties [Section titled “Properties”](#properties) ### name [Section titled “name”](#name) ```ts name: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from) ```ts ToolGuardrailBase.name ``` *** ### run [Section titled “run”](#run) ```ts run: ToolInputGuardrailFunction; ``` *** ### type [Section titled “type”](#type) ```ts type: "tool_input"; ``` # ToolInputGuardrailResult ## Properties [Section titled “Properties”](#properties) ### guardrail [Section titled “guardrail”](#guardrail) ```ts guardrail: ToolGuardrailMetadata & object; ``` #### Type Declaration [Section titled “Type Declaration”](#type-declaration) | Name | Type | | ------ | -------------- | | `type` | `"tool_input"` | *** ### output [Section titled “output”](#output) ```ts output: ToolGuardrailFunctionOutput; ``` # ToolOutputGuardrailData Input data passed to a tool output guardrail function. ## Extends [Section titled “Extends”](#extends) * [`ToolInputGuardrailData`](/openai-agents-js/openai/agents/interfaces/toolinputguardraildata/)<`TContext`> ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | -------------------------------------------------------------------------------- | | `TContext` | [`UnknownContext`](/openai-agents-js/openai/agents/type-aliases/unknowncontext/) | ## Properties [Section titled “Properties”](#properties) ### agent [Section titled “agent”](#agent) ```ts agent: Agent; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from) [`ToolInputGuardrailData`](/openai-agents-js/openai/agents/interfaces/toolinputguardraildata/).[`agent`](/openai-agents-js/openai/agents/interfaces/toolinputguardraildata/#agent) *** ### context [Section titled “context”](#context) ```ts context: RunContext; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-1) [`ToolInputGuardrailData`](/openai-agents-js/openai/agents/interfaces/toolinputguardraildata/).[`context`](/openai-agents-js/openai/agents/interfaces/toolinputguardraildata/#context) *** ### output [Section titled “output”](#output) ```ts output: unknown; ``` *** ### toolCall [Section titled “toolCall”](#toolcall) ```ts toolCall: object; ``` | Name | Type | | --------------- | -------------------------------------------------- | | `arguments` | `string` | | `callId` | `string` | | `id?` | `string` | | `name` | `string` | | `namespace?` | `string` | | `providerData?` | `Record`<`string`, `any`> | | `status?` | `"completed"` \| `"in_progress"` \| `"incomplete"` | | `type` | `"function_call"` | #### Inherited from [Section titled “Inherited from”](#inherited-from-2) [`ToolInputGuardrailData`](/openai-agents-js/openai/agents/interfaces/toolinputguardraildata/).[`toolCall`](/openai-agents-js/openai/agents/interfaces/toolinputguardraildata/#toolcall) # ToolOutputGuardrailDefinition ## Extends [Section titled “Extends”](#extends) * `ToolGuardrailBase` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | -------------------------------------------------------------------------------- | | `TContext` | [`UnknownContext`](/openai-agents-js/openai/agents/type-aliases/unknowncontext/) | ## Properties [Section titled “Properties”](#properties) ### name [Section titled “name”](#name) ```ts name: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from) ```ts ToolGuardrailBase.name ``` *** ### run [Section titled “run”](#run) ```ts run: ToolOutputGuardrailFunction; ``` *** ### type [Section titled “type”](#type) ```ts type: "tool_output"; ``` # ToolOutputGuardrailResult ## Properties [Section titled “Properties”](#properties) ### guardrail [Section titled “guardrail”](#guardrail) ```ts guardrail: ToolGuardrailMetadata & object; ``` #### Type Declaration [Section titled “Type Declaration”](#type-declaration) | Name | Type | | ------ | --------------- | | `type` | `"tool_output"` | *** ### output [Section titled “output”](#output) ```ts output: ToolGuardrailFunctionOutput; ``` # TracingExporter Exports traces and spans. For example, could log them or send them to a backend. ## Methods [Section titled “Methods”](#methods) ### export() [Section titled “export()”](#export) ```ts export(items, signal?): Promise; ``` Export the given traces and spans #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | --------- | ------------------------------------------------------------------------ | ------------------------------ | | `items` | ([`Trace`](/openai-agents-js/openai/agents/classes/trace/) \| `Span`)\[] | The traces and spans to export | | `signal?` | `AbortSignal` | ‐ | #### Returns [Section titled “Returns”](#returns) `Promise`<`void`> # TracingProcessor Interface for processing traces ## Methods [Section titled “Methods”](#methods) ### forceFlush() [Section titled “forceFlush()”](#forceflush) ```ts forceFlush(): Promise; ``` Called when a trace is being flushed #### Returns [Section titled “Returns”](#returns) `Promise`<`void`> *** ### onSpanEnd() [Section titled “onSpanEnd()”](#onspanend) ```ts onSpanEnd(span): Promise; ``` Called when a span is ended #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ------ | | `span` | `Span` | #### Returns [Section titled “Returns”](#returns-1) `Promise`<`void`> *** ### onSpanStart() [Section titled “onSpanStart()”](#onspanstart) ```ts onSpanStart(span): Promise; ``` Called when a span is started #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | --------- | ------ | | `span` | `Span` | #### Returns [Section titled “Returns”](#returns-2) `Promise`<`void`> *** ### onTraceEnd() [Section titled “onTraceEnd()”](#ontraceend) ```ts onTraceEnd(trace): Promise; ``` Called when a trace is ended #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | --------- | --------------------------------------------------------- | | `trace` | [`Trace`](/openai-agents-js/openai/agents/classes/trace/) | #### Returns [Section titled “Returns”](#returns-3) `Promise`<`void`> *** ### onTraceStart() [Section titled “onTraceStart()”](#ontracestart) ```ts onTraceStart(trace): Promise; ``` Called when a trace is started #### Parameters [Section titled “Parameters”](#parameters-3) | Parameter | Type | | --------- | --------------------------------------------------------- | | `trace` | [`Trace`](/openai-agents-js/openai/agents/classes/trace/) | #### Returns [Section titled “Returns”](#returns-4) `Promise`<`void`> *** ### shutdown() [Section titled “shutdown()”](#shutdown) ```ts shutdown(timeout?): Promise; ``` Called when the trace processor is shutting down #### Parameters [Section titled “Parameters”](#parameters-4) | Parameter | Type | | ---------- | -------- | | `timeout?` | `number` | #### Returns [Section titled “Returns”](#returns-5) `Promise`<`void`> *** ### start()? [Section titled “start()?”](#start) ```ts optional start(): void; ``` Called when the trace processor should start processing traces. Only available if the processor is performing tasks like exporting traces in a loop to start the loop #### Returns [Section titled “Returns”](#returns-6) `void` # ApplyPatchOperationCreateFile ```ts type ApplyPatchOperationCreateFile = object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### diff [Section titled “diff”](#diff) ```ts diff: string; ``` ### path [Section titled “path”](#path) ```ts path: string; ``` ### type [Section titled “type”](#type) ```ts type: "create_file"; ``` # ApplyPatchOperationDeleteFile ```ts type ApplyPatchOperationDeleteFile = object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### path [Section titled “path”](#path) ```ts path: string; ``` ### type [Section titled “type”](#type) ```ts type: "delete_file"; ``` # ApplyPatchOperationUpdateFile ```ts type ApplyPatchOperationUpdateFile = object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### diff [Section titled “diff”](#diff) ```ts diff: string; ``` ### moveTo? [Section titled “moveTo?”](#moveto) ```ts optional moveTo?: string; ``` ### path [Section titled “path”](#path) ```ts path: string; ``` ### type [Section titled “type”](#type) ```ts type: "update_file"; ``` # AssistantContent ```ts type AssistantContent = | { providerData?: Record; text: string; type: "output_text"; } | { providerData?: Record; refusal: string; type: "refusal"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; } | { image: string; providerData?: Record; type: "image"; }; ``` # AudioContent ```ts type AudioContent = object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### audio [Section titled “audio”](#audio) ```ts audio: | string | { id: string; }; ``` ### format? [Section titled “format?”](#format) ```ts optional format?: string | null; ``` ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` ### transcript? [Section titled “transcript?”](#transcript) ```ts optional transcript?: string | null; ``` ### type [Section titled “type”](#type) ```ts type: "audio"; ``` # CompactionItem ```ts type CompactionItem = object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### created\_by? [Section titled “created\_by?”](#created_by) ```ts optional created_by?: string; ``` ### encrypted\_content [Section titled “encrypted\_content”](#encrypted_content) ```ts encrypted_content: string; ``` ### id? [Section titled “id?”](#id) ```ts optional id?: string; ``` ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` ### type [Section titled “type”](#type) ```ts type: "compaction"; ``` # ComputerAction ```ts type ComputerAction = | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; }; ``` # ComputerToolOutput ```ts type ComputerToolOutput = object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### data [Section titled “data”](#data) ```ts data: string; ``` ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` ### type [Section titled “type”](#type) ```ts type: "computer_screenshot"; ``` # ImageContent ```ts type ImageContent = object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### image [Section titled “image”](#image) ```ts image: string; ``` ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` ### type [Section titled “type”](#type) ```ts type: "image"; ``` # InputFile ```ts type InputFile = object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### file? [Section titled “file?”](#file) ```ts optional file?: | string | { id: string; } | { url: string; }; ``` ### filename? [Section titled “filename?”](#filename) ```ts optional filename?: string; ``` ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` ### type [Section titled “type”](#type) ```ts type: "input_file"; ``` # InputImage ```ts type InputImage = object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### detail? [Section titled “detail?”](#detail) ```ts optional detail?: string; ``` ### image? [Section titled “image?”](#image) ```ts optional image?: | string | { id: string; }; ``` ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` ### type [Section titled “type”](#type) ```ts type: "input_image"; ``` # InputText ```ts type InputText = object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` ### text [Section titled “text”](#text) ```ts text: string; ``` ### type [Section titled “type”](#type) ```ts type: "input_text"; ``` # ItemBase ```ts type ItemBase = object; ``` Every item has a shared of shared item data including an optional ID. ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### id? [Section titled “id?”](#id) ```ts optional id?: string; ``` ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` # MessageItem ```ts type MessageItem = | { content: string; id?: string; providerData?: Record; role: "system"; type?: "message"; } | { content: ( | { providerData?: Record; text: string; type: "output_text"; } | { providerData?: Record; refusal: string; type: "refusal"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; } | { image: string; providerData?: Record; type: "image"; })[]; id?: string; providerData?: Record; role: "assistant"; status: "completed" | "in_progress" | "incomplete"; type?: "message"; } | { content: | string | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; })[]; id?: string; providerData?: Record; role: "user"; type?: "message"; }; ``` # ModelItem ```ts type ModelItem = | { content: | string | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; })[]; id?: string; providerData?: Record; role: "user"; type?: "message"; } | { content: ( | { providerData?: Record; text: string; type: "output_text"; } | { providerData?: Record; refusal: string; type: "refusal"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; } | { image: string; providerData?: Record; type: "image"; })[]; id?: string; providerData?: Record; role: "assistant"; status: "completed" | "in_progress" | "incomplete"; type?: "message"; } | { content: string; id?: string; providerData?: Record; role: "system"; type?: "message"; } | { arguments: unknown; call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; type: "tool_search_call"; } | { call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; tools: Record[]; type: "tool_search_output"; } | { arguments?: string; id?: string; name: string; output?: string; providerData?: Record; status?: string; type: "hosted_tool_call"; } | { arguments: string; callId: string; id?: string; name: string; namespace?: string; providerData?: Record; status?: "completed" | "in_progress" | "incomplete"; type: "function_call"; } | { action?: | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; }; actions?: ( | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; })[]; callId: string; id?: string; providerData?: Record; status: "completed" | "in_progress" | "incomplete"; type: "computer_call"; } | { action: { commands: string[]; maxOutputLength?: number; timeoutMs?: number; }; callId: string; id?: string; providerData?: Record; status?: "completed" | "in_progress" | "incomplete"; type: "shell_call"; } | { callId: string; id?: string; operation: | { diff: string; path: string; type: "create_file"; } | { diff: string; moveTo?: string; path: string; type: "update_file"; } | { path: string; type: "delete_file"; }; providerData?: Record; status: "completed" | "in_progress"; type: "apply_patch_call"; } | { callId: string; id?: string; name: string; namespace?: string; output: | string | { providerData?: Record; text: string; type: "text"; } | { detail?: string & object | "low" | "high" | "auto"; image?: | string | { data: string | Uint8Array; mediaType?: string; } | { url: string; } | { fileId: string; }; providerData?: Record; type: "image"; } | { file: | string | { data: string | Uint8Array; filename: string; mediaType: string; } | { filename?: string; url: string; } | { filename?: string; id: string; }; providerData?: Record; type: "file"; } | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; })[]; providerData?: Record; status: "completed" | "in_progress" | "incomplete"; type: "function_call_result"; } | { callId: string; id?: string; output: { data: string; providerData?: Record; type: "computer_screenshot"; }; providerData?: Record; type: "computer_call_result"; } | { callId: string; id?: string; maxOutputLength?: number; output: object[]; providerData?: Record; type: "shell_call_output"; } | { callId: string; id?: string; output?: string; providerData?: Record; status: "completed" | "failed"; type: "apply_patch_call_output"; } | { content: object[]; id?: string; providerData?: Record; rawContent?: object[]; type: "reasoning"; } | { created_by?: string; encrypted_content: string; id?: string; providerData?: Record; type: "compaction"; } | { id?: string; providerData?: Record; type: "unknown"; }; ``` # OutputModelItem ```ts type OutputModelItem = | { content: ( | { providerData?: Record; text: string; type: "output_text"; } | { providerData?: Record; refusal: string; type: "refusal"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; } | { image: string; providerData?: Record; type: "image"; })[]; id?: string; providerData?: Record; role: "assistant"; status: "completed" | "in_progress" | "incomplete"; type?: "message"; } | { arguments: unknown; call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; type: "tool_search_call"; } | { call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; tools: Record[]; type: "tool_search_output"; } | { arguments?: string; id?: string; name: string; output?: string; providerData?: Record; status?: string; type: "hosted_tool_call"; } | { arguments: string; callId: string; id?: string; name: string; namespace?: string; providerData?: Record; status?: "completed" | "in_progress" | "incomplete"; type: "function_call"; } | { action?: | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; }; actions?: ( | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; })[]; callId: string; id?: string; providerData?: Record; status: "completed" | "in_progress" | "incomplete"; type: "computer_call"; } | { action: { commands: string[]; maxOutputLength?: number; timeoutMs?: number; }; callId: string; id?: string; providerData?: Record; status?: "completed" | "in_progress" | "incomplete"; type: "shell_call"; } | { callId: string; id?: string; operation: | { diff: string; path: string; type: "create_file"; } | { diff: string; moveTo?: string; path: string; type: "update_file"; } | { path: string; type: "delete_file"; }; providerData?: Record; status: "completed" | "in_progress"; type: "apply_patch_call"; } | { callId: string; id?: string; name: string; namespace?: string; output: | string | { providerData?: Record; text: string; type: "text"; } | { detail?: string & object | "low" | "high" | "auto"; image?: | string | { data: string | Uint8Array; mediaType?: string; } | { url: string; } | { fileId: string; }; providerData?: Record; type: "image"; } | { file: | string | { data: string | Uint8Array; filename: string; mediaType: string; } | { filename?: string; url: string; } | { filename?: string; id: string; }; providerData?: Record; type: "file"; } | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; })[]; providerData?: Record; status: "completed" | "in_progress" | "incomplete"; type: "function_call_result"; } | { callId: string; id?: string; maxOutputLength?: number; output: object[]; providerData?: Record; type: "shell_call_output"; } | { callId: string; id?: string; output?: string; providerData?: Record; status: "completed" | "failed"; type: "apply_patch_call_output"; } | { content: object[]; id?: string; providerData?: Record; rawContent?: object[]; type: "reasoning"; } | { created_by?: string; encrypted_content: string; id?: string; providerData?: Record; type: "compaction"; } | { id?: string; providerData?: Record; type: "unknown"; }; ``` # OutputText ```ts type OutputText = object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` ### text [Section titled “text”](#text) ```ts text: string; ``` ### type [Section titled “type”](#type) ```ts type: "output_text"; ``` # ReasoningText ```ts type ReasoningText = object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` ### text [Section titled “text”](#text) ```ts text: string; ``` ### type [Section titled “type”](#type) ```ts type: "reasoning_text"; ``` # Refusal ```ts type Refusal = object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` ### refusal [Section titled “refusal”](#refusal) ```ts refusal: string; ``` ### type [Section titled “type”](#type) ```ts type: "refusal"; ``` # RequestUsageData ```ts type RequestUsageData = object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### endpoint? [Section titled “endpoint?”](#endpoint) ```ts optional endpoint?: string; ``` ### inputTokens [Section titled “inputTokens”](#inputtokens) ```ts inputTokens: number; ``` ### inputTokensDetails? [Section titled “inputTokensDetails?”](#inputtokensdetails) ```ts optional inputTokensDetails?: Record; ``` ### outputTokens [Section titled “outputTokens”](#outputtokens) ```ts outputTokens: number; ``` ### outputTokensDetails? [Section titled “outputTokensDetails?”](#outputtokensdetails) ```ts optional outputTokensDetails?: Record; ``` ### totalTokens [Section titled “totalTokens”](#totaltokens) ```ts totalTokens: number; ``` # SharedBase ```ts type SharedBase = object; ``` Every item in the protocol provides a `providerData` field to accommodate custom functionality or new fields ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` # ShellAction ```ts type ShellAction = object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### commands [Section titled “commands”](#commands) ```ts commands: string[]; ``` ### maxOutputLength? [Section titled “maxOutputLength?”](#maxoutputlength) ```ts optional maxOutputLength?: number; ``` ### timeoutMs? [Section titled “timeoutMs?”](#timeoutms) ```ts optional timeoutMs?: number; ``` # ShellCallOutcome ```ts type ShellCallOutcome = | { type: "timeout"; } | { exitCode: number | null; type: "exit"; }; ``` # ShellCallOutputContent ```ts type ShellCallOutputContent = object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ## Index Signature [Section titled “Index Signature”](#index-signature) ```ts [key: string]: unknown ``` ### outcome [Section titled “outcome”](#outcome) ```ts outcome: | { type: "timeout"; } | { exitCode: number | null; type: "exit"; }; ``` ### stderr [Section titled “stderr”](#stderr) ```ts stderr: string; ``` ### stdout [Section titled “stdout”](#stdout) ```ts stdout: string; ``` # ToolCallItem ```ts type ToolCallItem = | { action?: | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; }; actions?: ( | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; })[]; callId: string; id?: string; providerData?: Record; status: "completed" | "in_progress" | "incomplete"; type: "computer_call"; } | { action: { commands: string[]; maxOutputLength?: number; timeoutMs?: number; }; callId: string; id?: string; providerData?: Record; status?: "completed" | "in_progress" | "incomplete"; type: "shell_call"; } | { callId: string; id?: string; operation: | { diff: string; path: string; type: "create_file"; } | { diff: string; moveTo?: string; path: string; type: "update_file"; } | { path: string; type: "delete_file"; }; providerData?: Record; status: "completed" | "in_progress"; type: "apply_patch_call"; } | { arguments: string; callId: string; id?: string; name: string; namespace?: string; providerData?: Record; status?: "completed" | "in_progress" | "incomplete"; type: "function_call"; } | { arguments?: string; id?: string; name: string; output?: string; providerData?: Record; status?: string; type: "hosted_tool_call"; }; ``` # UsageData ```ts type UsageData = object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### inputTokens [Section titled “inputTokens”](#inputtokens) ```ts inputTokens: number; ``` ### inputTokensDetails? [Section titled “inputTokensDetails?”](#inputtokensdetails) ```ts optional inputTokensDetails?: Record | Record[]; ``` ### outputTokens [Section titled “outputTokens”](#outputtokens) ```ts outputTokens: number; ``` ### outputTokensDetails? [Section titled “outputTokensDetails?”](#outputtokensdetails) ```ts optional outputTokensDetails?: Record | Record[]; ``` ### requests? [Section titled “requests?”](#requests) ```ts optional requests?: number; ``` ### requestUsageEntries? [Section titled “requestUsageEntries?”](#requestusageentries) ```ts optional requestUsageEntries?: object[]; ``` ### totalTokens [Section titled “totalTokens”](#totaltokens) ```ts totalTokens: number; ``` # UserContent ```ts type UserContent = | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; }; ``` # ApplyPatchOperationCreateFile ```ts const ApplyPatchOperationCreateFile: z.ZodObject; ``` # ApplyPatchOperationDeleteFile ```ts const ApplyPatchOperationDeleteFile: z.ZodObject; ``` # ApplyPatchOperationUpdateFile ```ts const ApplyPatchOperationUpdateFile: z.ZodObject; ``` # AssistantContent ```ts const AssistantContent: z.ZodDiscriminatedUnion; ``` # AudioContent ```ts const AudioContent: z.ZodObject; ``` # CompactionItem ```ts const CompactionItem: z.ZodObject; ``` # computerActions ```ts const computerActions: z.ZodDiscriminatedUnion; ``` # ComputerToolOutput ```ts const ComputerToolOutput: z.ZodObject; ``` # ImageContent ```ts const ImageContent: z.ZodObject; ``` # InputFile ```ts const InputFile: z.ZodObject; ``` # InputImage ```ts const InputImage: z.ZodObject; ``` # InputText ```ts const InputText: z.ZodObject; ``` # ItemBase ```ts const ItemBase: z.ZodObject; ``` Every item has a shared of shared item data including an optional ID. # MessageItem ```ts const MessageItem: z.ZodDiscriminatedUnion; ``` # ModelItem ```ts const ModelItem: z.ZodUnion; ``` # OutputModelItem ```ts const OutputModelItem: z.ZodDiscriminatedUnion; ``` # OutputText ```ts const OutputText: z.ZodObject; ``` # ReasoningText ```ts const ReasoningText: z.ZodObject; ``` # Refusal ```ts const Refusal: z.ZodObject; ``` # RequestUsageData ```ts const RequestUsageData: z.ZodObject; ``` # SharedBase ```ts const SharedBase: z.ZodObject; ``` Every item in the protocol provides a `providerData` field to accommodate custom functionality or new fields # ShellAction ```ts const ShellAction: z.ZodObject; ``` # ShellCallOutcome ```ts const ShellCallOutcome: z.ZodDiscriminatedUnion; ``` # ShellCallOutputContent ```ts const ShellCallOutputContent: z.ZodObject; ``` # ToolCallItem ```ts const ToolCallItem: z.ZodDiscriminatedUnion; ``` # UsageData ```ts const UsageData: z.ZodObject; ``` # UserContent ```ts const UserContent: z.ZodDiscriminatedUnion; ``` # OpenAIRealtimeBase The transport layer is the layer that handles the connection to the model and the communication with the model. ## Extends [Section titled “Extends”](#extends) * `EventEmitterDelegate`<[`OpenAIRealtimeEventTypes`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/openairealtimeeventtypes/)> ## Extended by [Section titled “Extended by”](#extended-by) * [`OpenAIRealtimeWebRTC`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimewebrtc/) * [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimewebsocket/) ## Implements [Section titled “Implements”](#implements) * [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/) ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new OpenAIRealtimeBase(options?): OpenAIRealtimeBase; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ---------- | --------------------------------------------------------------------------------------------------------------------------------- | | `options?` | [`OpenAIRealtimeBaseOptions`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/openairealtimebaseoptions/) | #### Returns [Section titled “Returns”](#returns) `OpenAIRealtimeBase` #### Overrides [Section titled “Overrides”](#overrides) ```ts EventEmitterDelegate.constructor ``` ## Properties [Section titled “Properties”](#properties) ### muted [Section titled “muted”](#muted) ```ts abstract readonly muted: boolean | null; ``` Whether the input audio track is currently muted null if the muting is not handled by the transport layer #### Implementation of [Section titled “Implementation of”](#implementation-of) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/).[`muted`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/#muted) ## Accessors [Section titled “Accessors”](#accessors) ### \_tracingConfig [Section titled “\_tracingConfig”](#_tracingconfig) #### Set Signature [Section titled “Set Signature”](#set-signature) ```ts set _tracingConfig(tracingConfig): void; ``` Sets the internal tracing config. This is used to track the tracing config that has been set during the session.create event. ##### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | --------------- | --------------------------------- | | `tracingConfig` | `RealtimeTracingConfig` \| `null` | ##### Returns [Section titled “Returns”](#returns-1) `void` *** ### currentModel [Section titled “currentModel”](#currentmodel) #### Get Signature [Section titled “Get Signature”](#get-signature) ```ts get currentModel(): OpenAIRealtimeModels; ``` The current model that is being used by the transport layer. ##### Returns [Section titled “Returns”](#returns-2) [`OpenAIRealtimeModels`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/openairealtimemodels/) #### Set Signature [Section titled “Set Signature”](#set-signature-1) ```ts set currentModel(model): void; ``` The current model that is being used by the transport layer. **Note**: The model cannot be changed mid conversation. ##### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | --------- | ----------------------------------------------------------------------------------------------------------------------- | | `model` | [`OpenAIRealtimeModels`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/openairealtimemodels/) | ##### Returns [Section titled “Returns”](#returns-3) `void` *** ### status [Section titled “status”](#status) #### Get Signature [Section titled “Get Signature”](#get-signature-1) ```ts get abstract status(): "connecting" | "connected" | "disconnected" | "disconnecting"; ``` ##### Returns [Section titled “Returns”](#returns-4) `"connecting"` | `"connected"` | `"disconnected"` | `"disconnecting"` #### Implementation of [Section titled “Implementation of”](#implementation-of-1) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/).[`status`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/#status) ## Methods [Section titled “Methods”](#methods) ### addImage() [Section titled “addImage()”](#addimage) ```ts addImage(image, options?): void; ``` Sends an image to the model #### Parameters [Section titled “Parameters”](#parameters-3) | Parameter | Type | Description | | -------------------------- | ---------------------------------- | -------------------------------------------- | | `image` | `string` | The image to send | | `options?` | { `triggerResponse?`: `boolean`; } | Additional options | | `options.triggerResponse?` | `boolean` | Whether to trigger a response from the model | #### Returns [Section titled “Returns”](#returns-5) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-2) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/).[`addImage`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/#addimage) *** ### buildSessionPayload() [Section titled “buildSessionPayload()”](#buildsessionpayload) ```ts buildSessionPayload(config): RealtimeSessionPayload; ``` Build the payload object expected by the Realtime API when creating or updating a session. The helper centralises the conversion from camelCase runtime config to the snake\_case payload required by the Realtime API so transports that need a one-off payload (for example SIP call acceptance) can reuse the same logic without duplicating private state. #### Parameters [Section titled “Parameters”](#parameters-4) | Parameter | Type | Description | | --------- | ------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------ | | `config` | `Partial`<[`RealtimeSessionConfig`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimesessionconfig/)> | The session config to merge with defaults. | #### Returns [Section titled “Returns”](#returns-6) [`RealtimeSessionPayload`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimesessionpayload/) *** ### close() [Section titled “close()”](#close) ```ts abstract close(): void; ``` Closes the connection to the model #### Returns [Section titled “Returns”](#returns-7) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-3) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/).[`close`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/#close) *** ### connect() [Section titled “connect()”](#connect) ```ts abstract connect(options): Promise; ``` Establishes the connection to the model and keeps the connection alive #### Parameters [Section titled “Parameters”](#parameters-5) | Parameter | Type | Description | | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------ | | `options` | [`RealtimeTransportLayerConnectOptions`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimetransportlayerconnectoptions/) | The options for the connection | #### Returns [Section titled “Returns”](#returns-8) `Promise`<`void`> #### Implementation of [Section titled “Implementation of”](#implementation-of-4) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/).[`connect`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/#connect) *** ### emit() [Section titled “emit()”](#emit) ```ts emit(type, ...args): boolean; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | --------------------------------------------------------------------------------------------------------------------------------------------------------- | | `K` *extends* keyof [`RealtimeTransportEventTypes`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimetransporteventtypes/) | #### Parameters [Section titled “Parameters”](#parameters-6) | Parameter | Type | | --------- | ------------------------------------------------------------------------------------------------------------------------------------- | | `type` | `K` | | …`args` | [`OpenAIRealtimeEventTypes`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/openairealtimeeventtypes/)\[`K`] | #### Returns [Section titled “Returns”](#returns-9) `boolean` #### Implementation of [Section titled “Implementation of”](#implementation-of-5) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/).[`emit`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/#emit) #### Inherited from [Section titled “Inherited from”](#inherited-from) ```ts EventEmitterDelegate.emit ``` *** ### interrupt() [Section titled “interrupt()”](#interrupt) ```ts abstract interrupt(): void; ``` Interrupts the current turn. Used for example when a guardrail is triggered #### Returns [Section titled “Returns”](#returns-10) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-6) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/).[`interrupt`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/#interrupt) *** ### mute() [Section titled “mute()”](#mute) ```ts abstract mute(muted): void; ``` Mutes the input audio track #### Parameters [Section titled “Parameters”](#parameters-7) | Parameter | Type | Description | | --------- | --------- | ------------------------------------- | | `muted` | `boolean` | Whether to mute the input audio track | #### Returns [Section titled “Returns”](#returns-11) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-7) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/).[`mute`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/#mute) *** ### off() [Section titled “off()”](#off) ```ts off(type, listener): EventEmitter; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-1) | Type Parameter | | --------------------------------------------------------------------------------------------------------------------------------------------------------- | | `K` *extends* keyof [`RealtimeTransportEventTypes`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimetransporteventtypes/) | #### Parameters [Section titled “Parameters”](#parameters-8) | Parameter | Type | | ---------- | ------------------- | | `type` | `K` | | `listener` | (…`args`) => `void` | #### Returns [Section titled “Returns”](#returns-12) `EventEmitter`<`EventTypes`> #### Implementation of [Section titled “Implementation of”](#implementation-of-8) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/).[`off`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/#off) #### Inherited from [Section titled “Inherited from”](#inherited-from-1) ```ts EventEmitterDelegate.off ``` *** ### on() [Section titled “on()”](#on) ```ts on(type, listener): EventEmitter; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-2) | Type Parameter | | --------------------------------------------------------------------------------------------------------------------------------------------------------- | | `K` *extends* keyof [`RealtimeTransportEventTypes`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimetransporteventtypes/) | #### Parameters [Section titled “Parameters”](#parameters-9) | Parameter | Type | | ---------- | ------------------- | | `type` | `K` | | `listener` | (…`args`) => `void` | #### Returns [Section titled “Returns”](#returns-13) `EventEmitter`<`EventTypes`> #### Implementation of [Section titled “Implementation of”](#implementation-of-9) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/).[`on`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/#on) #### Inherited from [Section titled “Inherited from”](#inherited-from-2) ```ts EventEmitterDelegate.on ``` *** ### once() [Section titled “once()”](#once) ```ts once(type, listener): EventEmitter; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-3) | Type Parameter | | --------------------------------------------------------------------------------------------------------------------------------------------------------- | | `K` *extends* keyof [`RealtimeTransportEventTypes`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimetransporteventtypes/) | #### Parameters [Section titled “Parameters”](#parameters-10) | Parameter | Type | | ---------- | ------------------- | | `type` | `K` | | `listener` | (…`args`) => `void` | #### Returns [Section titled “Returns”](#returns-14) `EventEmitter`<`EventTypes`> #### Implementation of [Section titled “Implementation of”](#implementation-of-10) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/).[`once`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/#once) #### Inherited from [Section titled “Inherited from”](#inherited-from-3) ```ts EventEmitterDelegate.once ``` *** ### requestResponse() [Section titled “requestResponse()”](#requestresponse) ```ts requestResponse(response?): void; ``` Requests a new response for the current conversation turn. Implementations may defer the underlying `response.create` until the server has fully finished the prior response. #### Parameters [Section titled “Parameters”](#parameters-11) | Parameter | Type | Description | | ----------- | ------------------------- | ------------------------------------------- | | `response?` | `Record`<`string`, `any`> | Optional one-off response override payload. | #### Returns [Section titled “Returns”](#returns-15) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-11) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/).[`requestResponse`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/#requestresponse) *** ### resetHistory() [Section titled “resetHistory()”](#resethistory) ```ts resetHistory(oldHistory, newHistory): void; ``` Reset the history of the conversation. This will create a diff between the old and new history and send the necessary events to the Realtime API to update the history. #### Parameters [Section titled “Parameters”](#parameters-12) | Parameter | Type | Description | | ------------ | ---------------------------------------------------------------------------------------------------------- | ------------------------------------ | | `oldHistory` | [`RealtimeItem`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimeitem/)\[] | The old history of the conversation. | | `newHistory` | [`RealtimeItem`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimeitem/)\[] | The new history of the conversation. | #### Returns [Section titled “Returns”](#returns-16) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-12) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/).[`resetHistory`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/#resethistory) *** ### sendAudio() [Section titled “sendAudio()”](#sendaudio) ```ts sendAudio(audio, options?): void; ``` Send an audio buffer to the Realtime API. If `{ commit: true }` is passed, the audio buffer will be committed and the model will start processing it. This is necessary if you have disabled turn detection / voice activity detection (VAD). #### Parameters [Section titled “Parameters”](#parameters-13) | Parameter | Type | Description | | ----------------- | ------------------------- | --------------------------------- | | `audio` | `ArrayBuffer` | The audio buffer to send. | | `options?` | { `commit?`: `boolean`; } | The options for the audio buffer. | | `options.commit?` | `boolean` | ‐ | #### Returns [Section titled “Returns”](#returns-17) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-13) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/).[`sendAudio`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/#sendaudio) *** ### sendEvent() [Section titled “sendEvent()”](#sendevent) ```ts abstract sendEvent(event): void; ``` Sends a raw event to the model #### Parameters [Section titled “Parameters”](#parameters-14) | Parameter | Type | Description | | --------- | ------------------------------------------------------------------------------------------------------------------------- | ----------------- | | `event` | [`RealtimeClientMessage`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimeclientmessage/) | The event to send | #### Returns [Section titled “Returns”](#returns-18) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-14) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/).[`sendEvent`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/#sendevent) *** ### sendFunctionCallOutput() [Section titled “sendFunctionCallOutput()”](#sendfunctioncalloutput) ```ts sendFunctionCallOutput( toolCall, output, startResponse?): void; ``` Send the output of a function call to the Realtime API. #### Parameters [Section titled “Parameters”](#parameters-15) | Parameter | Type | Description | | ---------------- | --------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------- | | `toolCall` | [`TransportToolCallEvent`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/transporttoolcallevent/) | The tool call to send the output for. | | `output` | `string` | The output of the function call. | | `startResponse?` | `boolean` | Whether to start a new response after sending the output. | #### Returns [Section titled “Returns”](#returns-19) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-15) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/).[`sendFunctionCallOutput`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/#sendfunctioncalloutput) *** ### sendMcpResponse() [Section titled “sendMcpResponse()”](#sendmcpresponse) ```ts sendMcpResponse( approvalRequest, approved, reason?): void; ``` Sends a response for an MCP tool call #### Parameters [Section titled “Parameters”](#parameters-16) | Parameter | Type | Description | | ------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------- | | `approvalRequest` | { `approved?`: `boolean` \| `null`; `arguments`: `z.ZodRecord`<`z.ZodString`, `z.ZodAny`>; `itemId`: `string`; `name`: `string`; `serverLabel`: `string`; `type`: `"mcp_approval_request"`; } | The approval request to respond to | | `approvalRequest.approved?` | `boolean` \| `null` | ‐ | | `approvalRequest.arguments` | `z.ZodRecord`<`z.ZodString`, `z.ZodAny`> | ‐ | | `approvalRequest.itemId?` | `string` | ‐ | | `approvalRequest.name?` | `string` | ‐ | | `approvalRequest.serverLabel?` | `string` | ‐ | | `approvalRequest.type?` | `"mcp_approval_request"` | ‐ | | `approved?` | `boolean` | Whether the tool call was approved or rejected | | `reason?` | `string` | Optional rejection text for the provider/model. | #### Returns [Section titled “Returns”](#returns-20) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-16) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/).[`sendMcpResponse`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/#sendmcpresponse) *** ### sendMessage() [Section titled “sendMessage()”](#sendmessage) ```ts sendMessage( message, otherEventData, __namedParameters?): void; ``` Send a message to the Realtime API. This will create a new item in the conversation and trigger a response. #### Parameters [Section titled “Parameters”](#parameters-17) | Parameter | Type | Description | | ------------------------------------ | ---------------------------------- | ------------------------------ | | `message` | `RealtimeUserInput` | The message to send. | | `otherEventData` | `Record`<`string`, `any`> | Additional event data to send. | | `__namedParameters?` | { `triggerResponse?`: `boolean`; } | ‐ | | `__namedParameters.triggerResponse?` | `boolean` | ‐ | #### Returns [Section titled “Returns”](#returns-21) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-17) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/).[`sendMessage`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/#sendmessage) *** ### updateSessionConfig() [Section titled “updateSessionConfig()”](#updatesessionconfig) ```ts updateSessionConfig(config): void; ``` Updates the session config. This will merge it with the current session config with the default values and send it to the Realtime API. #### Parameters [Section titled “Parameters”](#parameters-18) | Parameter | Type | Description | | --------- | ------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------- | | `config` | `Partial`<[`RealtimeSessionConfig`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimesessionconfig/)> | The session config to update. | #### Returns [Section titled “Returns”](#returns-22) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-18) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/).[`updateSessionConfig`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/#updatesessionconfig) # OpenAIRealtimeSIP Transport layer that connects to an existing SIP-initiated Realtime call via call ID. ## Extends [Section titled “Extends”](#extends) * [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimewebsocket/) ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new OpenAIRealtimeSIP(options?): OpenAIRealtimeSIP; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ---------- | ------------------------------------------------------------------------------------------------------------------------------------------- | | `options?` | [`OpenAIRealtimeWebSocketOptions`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/openairealtimewebsocketoptions/) | #### Returns [Section titled “Returns”](#returns) `OpenAIRealtimeSIP` #### Overrides [Section titled “Overrides”](#overrides) [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimewebsocket/).[`constructor`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimewebsocket/#constructor) ## Accessors [Section titled “Accessors”](#accessors) ### \_tracingConfig [Section titled “\_tracingConfig”](#_tracingconfig) #### Set Signature [Section titled “Set Signature”](#set-signature) ```ts set _tracingConfig(tracingConfig): void; ``` Sets the internal tracing config. This is used to track the tracing config that has been set during the session.create event. ##### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | --------------- | --------------------------------- | | `tracingConfig` | `RealtimeTracingConfig` \| `null` | ##### Returns [Section titled “Returns”](#returns-1) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from) [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimewebsocket/).[`_tracingConfig`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimewebsocket/#_tracingconfig) *** ### connectionState [Section titled “connectionState”](#connectionstate) #### Get Signature [Section titled “Get Signature”](#get-signature) ```ts get connectionState(): WebSocketState; ``` The current connection state of the WebSocket connection. ##### Returns [Section titled “Returns”](#returns-2) [`WebSocketState`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/websocketstate/) #### Inherited from [Section titled “Inherited from”](#inherited-from-1) [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimewebsocket/).[`connectionState`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimewebsocket/#connectionstate) *** ### currentModel [Section titled “currentModel”](#currentmodel) #### Get Signature [Section titled “Get Signature”](#get-signature-1) ```ts get currentModel(): OpenAIRealtimeModels; ``` The current model that is being used by the transport layer. ##### Returns [Section titled “Returns”](#returns-3) [`OpenAIRealtimeModels`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/openairealtimemodels/) #### Set Signature [Section titled “Set Signature”](#set-signature-1) ```ts set currentModel(model): void; ``` The current model that is being used by the transport layer. **Note**: The model cannot be changed mid conversation. ##### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | --------- | ----------------------------------------------------------------------------------------------------------------------- | | `model` | [`OpenAIRealtimeModels`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/openairealtimemodels/) | ##### Returns [Section titled “Returns”](#returns-4) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-2) [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimewebsocket/).[`currentModel`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimewebsocket/#currentmodel) *** ### muted [Section titled “muted”](#muted) #### Get Signature [Section titled “Get Signature”](#get-signature-2) ```ts get muted(): null; ``` Always returns `null` as the WebSocket transport layer does not handle muting. Instead, this should be handled by the client by not triggering the `sendAudio` method. ##### Returns [Section titled “Returns”](#returns-5) `null` Whether the input audio track is currently muted null if the muting is not handled by the transport layer #### Inherited from [Section titled “Inherited from”](#inherited-from-3) [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimewebsocket/).[`muted`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimewebsocket/#muted) *** ### status [Section titled “status”](#status) #### Get Signature [Section titled “Get Signature”](#get-signature-3) ```ts get status(): "connecting" | "connected" | "disconnected"; ``` The current status of the WebSocket connection. ##### Returns [Section titled “Returns”](#returns-6) `"connecting"` | `"connected"` | `"disconnected"` #### Inherited from [Section titled “Inherited from”](#inherited-from-4) [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimewebsocket/).[`status`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimewebsocket/#status) ## Methods [Section titled “Methods”](#methods) ### \_cancelResponse() [Section titled “\_cancelResponse()”](#_cancelresponse) ```ts _cancelResponse(): void; ``` Send a cancel response event to the Realtime API. This is used to cancel an ongoing response that the model is currently generating. #### Returns [Section titled “Returns”](#returns-7) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-5) [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimewebsocket/).[`_cancelResponse`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimewebsocket/#_cancelresponse) *** ### \_interrupt() [Section titled “\_interrupt()”](#_interrupt) ```ts _interrupt(elapsedTime, cancelOngoingResponse?): void; ``` Do NOT call this method directly. Call `interrupt()` instead for proper interruption handling. This method is used to send the right events to the API to inform the model that the user has interrupted the response. It might be overridden/extended by an extended transport layer. See the `TwilioRealtimeTransportLayer` for an example. #### Parameters [Section titled “Parameters”](#parameters-3) | Parameter | Type | Description | | ------------------------ | --------- | -------------------------------------------- | | `elapsedTime` | `number` | The elapsed time since the response started. | | `cancelOngoingResponse?` | `boolean` | ‐ | #### Returns [Section titled “Returns”](#returns-8) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-6) [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimewebsocket/).[`_interrupt`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimewebsocket/#_interrupt) *** ### addImage() [Section titled “addImage()”](#addimage) ```ts addImage(image, options?): void; ``` Sends an image to the model #### Parameters [Section titled “Parameters”](#parameters-4) | Parameter | Type | Description | | -------------------------- | ---------------------------------- | -------------------------------------------- | | `image` | `string` | The image to send | | `options?` | { `triggerResponse?`: `boolean`; } | Additional options | | `options.triggerResponse?` | `boolean` | Whether to trigger a response from the model | #### Returns [Section titled “Returns”](#returns-9) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-7) [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimewebsocket/).[`addImage`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimewebsocket/#addimage) *** ### buildSessionPayload() [Section titled “buildSessionPayload()”](#buildsessionpayload) ```ts buildSessionPayload(config): RealtimeSessionPayload; ``` Build the payload object expected by the Realtime API when creating or updating a session. The helper centralises the conversion from camelCase runtime config to the snake\_case payload required by the Realtime API so transports that need a one-off payload (for example SIP call acceptance) can reuse the same logic without duplicating private state. #### Parameters [Section titled “Parameters”](#parameters-5) | Parameter | Type | Description | | --------- | ------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------ | | `config` | `Partial`<[`RealtimeSessionConfig`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimesessionconfig/)> | The session config to merge with defaults. | #### Returns [Section titled “Returns”](#returns-10) [`RealtimeSessionPayload`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimesessionpayload/) #### Inherited from [Section titled “Inherited from”](#inherited-from-8) [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimewebsocket/).[`buildSessionPayload`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimewebsocket/#buildsessionpayload) *** ### close() [Section titled “close()”](#close) ```ts close(): void; ``` Close the WebSocket connection. This will also reset any internal connection tracking used for interruption handling. #### Returns [Section titled “Returns”](#returns-11) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-9) [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimewebsocket/).[`close`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimewebsocket/#close) *** ### connect() [Section titled “connect()”](#connect) ```ts connect(options): Promise; ``` Establishes the connection to the model and keeps the connection alive #### Parameters [Section titled “Parameters”](#parameters-6) | Parameter | Type | Description | | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------ | | `options` | [`RealtimeTransportLayerConnectOptions`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimetransportlayerconnectoptions/) | The options for the connection | #### Returns [Section titled “Returns”](#returns-12) `Promise`<`void`> #### Overrides [Section titled “Overrides”](#overrides-1) [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimewebsocket/).[`connect`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimewebsocket/#connect) *** ### emit() [Section titled “emit()”](#emit) ```ts emit(type, ...args): boolean; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | --------------------------------------------------------------------------------------------------------------------------------------------------------- | | `K` *extends* keyof [`RealtimeTransportEventTypes`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimetransporteventtypes/) | #### Parameters [Section titled “Parameters”](#parameters-7) | Parameter | Type | | --------- | ------------------------------------------------------------------------------------------------------------------------------------- | | `type` | `K` | | …`args` | [`OpenAIRealtimeEventTypes`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/openairealtimeeventtypes/)\[`K`] | #### Returns [Section titled “Returns”](#returns-13) `boolean` #### Inherited from [Section titled “Inherited from”](#inherited-from-10) [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimewebsocket/).[`emit`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimewebsocket/#emit) *** ### interrupt() [Section titled “interrupt()”](#interrupt) ```ts interrupt(cancelOngoingResponse?): void; ``` Interrupt the ongoing response. This method is triggered automatically by the client when voice activity detection (VAD) is enabled (default) as well as when an output guardrail got triggered. You can also call this method directly if you want to interrupt the conversation for example based on an event in the client. #### Parameters [Section titled “Parameters”](#parameters-8) | Parameter | Type | | ------------------------ | --------- | | `cancelOngoingResponse?` | `boolean` | #### Returns [Section titled “Returns”](#returns-14) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-11) [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimewebsocket/).[`interrupt`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimewebsocket/#interrupt) *** ### mute() [Section titled “mute()”](#mute) ```ts mute(_muted): never; ``` Will throw an error as the WebSocket transport layer does not support muting. #### Parameters [Section titled “Parameters”](#parameters-9) | Parameter | Type | | --------- | --------- | | `_muted` | `boolean` | #### Returns [Section titled “Returns”](#returns-15) `never` #### Inherited from [Section titled “Inherited from”](#inherited-from-12) [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimewebsocket/).[`mute`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimewebsocket/#mute) *** ### off() [Section titled “off()”](#off) ```ts off(type, listener): EventEmitter; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-1) | Type Parameter | | --------------------------------------------------------------------------------------------------------------------------------------------------------- | | `K` *extends* keyof [`RealtimeTransportEventTypes`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimetransporteventtypes/) | #### Parameters [Section titled “Parameters”](#parameters-10) | Parameter | Type | | ---------- | ------------------- | | `type` | `K` | | `listener` | (…`args`) => `void` | #### Returns [Section titled “Returns”](#returns-16) `EventEmitter`<`EventTypes`> #### Inherited from [Section titled “Inherited from”](#inherited-from-13) [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimewebsocket/).[`off`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimewebsocket/#off) *** ### on() [Section titled “on()”](#on) ```ts on(type, listener): EventEmitter; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-2) | Type Parameter | | --------------------------------------------------------------------------------------------------------------------------------------------------------- | | `K` *extends* keyof [`RealtimeTransportEventTypes`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimetransporteventtypes/) | #### Parameters [Section titled “Parameters”](#parameters-11) | Parameter | Type | | ---------- | ------------------- | | `type` | `K` | | `listener` | (…`args`) => `void` | #### Returns [Section titled “Returns”](#returns-17) `EventEmitter`<`EventTypes`> #### Inherited from [Section titled “Inherited from”](#inherited-from-14) [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimewebsocket/).[`on`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimewebsocket/#on) *** ### once() [Section titled “once()”](#once) ```ts once(type, listener): EventEmitter; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-3) | Type Parameter | | --------------------------------------------------------------------------------------------------------------------------------------------------------- | | `K` *extends* keyof [`RealtimeTransportEventTypes`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimetransporteventtypes/) | #### Parameters [Section titled “Parameters”](#parameters-12) | Parameter | Type | | ---------- | ------------------- | | `type` | `K` | | `listener` | (…`args`) => `void` | #### Returns [Section titled “Returns”](#returns-18) `EventEmitter`<`EventTypes`> #### Inherited from [Section titled “Inherited from”](#inherited-from-15) [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimewebsocket/).[`once`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimewebsocket/#once) *** ### requestResponse() [Section titled “requestResponse()”](#requestresponse) ```ts requestResponse(response?): void; ``` Requests a new response for the current conversation turn. Implementations may defer the underlying `response.create` until the server has fully finished the prior response. #### Parameters [Section titled “Parameters”](#parameters-13) | Parameter | Type | Description | | ----------- | ------------------------- | ------------------------------------------- | | `response?` | `Record`<`string`, `any`> | Optional one-off response override payload. | #### Returns [Section titled “Returns”](#returns-19) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-16) [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimewebsocket/).[`requestResponse`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimewebsocket/#requestresponse) *** ### resetHistory() [Section titled “resetHistory()”](#resethistory) ```ts resetHistory(oldHistory, newHistory): void; ``` Reset the history of the conversation. This will create a diff between the old and new history and send the necessary events to the Realtime API to update the history. #### Parameters [Section titled “Parameters”](#parameters-14) | Parameter | Type | Description | | ------------ | ---------------------------------------------------------------------------------------------------------- | ------------------------------------ | | `oldHistory` | [`RealtimeItem`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimeitem/)\[] | The old history of the conversation. | | `newHistory` | [`RealtimeItem`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimeitem/)\[] | The new history of the conversation. | #### Returns [Section titled “Returns”](#returns-20) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-17) [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimewebsocket/).[`resetHistory`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimewebsocket/#resethistory) *** ### sendAudio() [Section titled “sendAudio()”](#sendaudio) ```ts sendAudio(_audio, _options?): never; ``` Send an audio buffer to the Realtime API. This is used for your client to send audio to the model to respond. #### Parameters [Section titled “Parameters”](#parameters-15) | Parameter | Type | | ------------------ | ------------------------- | | `_audio` | `ArrayBuffer` | | `_options?` | { `commit?`: `boolean`; } | | `_options.commit?` | `boolean` | #### Returns [Section titled “Returns”](#returns-21) `never` #### Overrides [Section titled “Overrides”](#overrides-2) [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimewebsocket/).[`sendAudio`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimewebsocket/#sendaudio) *** ### sendEvent() [Section titled “sendEvent()”](#sendevent) ```ts sendEvent(event): void; ``` Send an event to the Realtime API. This will stringify the event and send it directly to the API. This can be used if you want to take control over the connection and send events manually. #### Parameters [Section titled “Parameters”](#parameters-16) | Parameter | Type | Description | | --------- | ------------------------------------------------------------------------------------------------------------------------- | ------------------ | | `event` | [`RealtimeClientMessage`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimeclientmessage/) | The event to send. | #### Returns [Section titled “Returns”](#returns-22) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-18) [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimewebsocket/).[`sendEvent`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimewebsocket/#sendevent) *** ### sendFunctionCallOutput() [Section titled “sendFunctionCallOutput()”](#sendfunctioncalloutput) ```ts sendFunctionCallOutput( toolCall, output, startResponse?): void; ``` Send the output of a function call to the Realtime API. #### Parameters [Section titled “Parameters”](#parameters-17) | Parameter | Type | Description | | ---------------- | --------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------- | | `toolCall` | [`TransportToolCallEvent`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/transporttoolcallevent/) | The tool call to send the output for. | | `output` | `string` | The output of the function call. | | `startResponse?` | `boolean` | Whether to start a new response after sending the output. | #### Returns [Section titled “Returns”](#returns-23) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-19) [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimewebsocket/).[`sendFunctionCallOutput`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimewebsocket/#sendfunctioncalloutput) *** ### sendMcpResponse() [Section titled “sendMcpResponse()”](#sendmcpresponse) ```ts sendMcpResponse( approvalRequest, approved, reason?): void; ``` Sends a response for an MCP tool call #### Parameters [Section titled “Parameters”](#parameters-18) | Parameter | Type | Description | | ------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------- | | `approvalRequest` | { `approved?`: `boolean` \| `null`; `arguments`: `z.ZodRecord`<`z.ZodString`, `z.ZodAny`>; `itemId`: `string`; `name`: `string`; `serverLabel`: `string`; `type`: `"mcp_approval_request"`; } | The approval request to respond to | | `approvalRequest.approved?` | `boolean` \| `null` | ‐ | | `approvalRequest.arguments` | `z.ZodRecord`<`z.ZodString`, `z.ZodAny`> | ‐ | | `approvalRequest.itemId?` | `string` | ‐ | | `approvalRequest.name?` | `string` | ‐ | | `approvalRequest.serverLabel?` | `string` | ‐ | | `approvalRequest.type?` | `"mcp_approval_request"` | ‐ | | `approved?` | `boolean` | Whether the tool call was approved or rejected | | `reason?` | `string` | Optional rejection text for the provider/model. | #### Returns [Section titled “Returns”](#returns-24) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-20) [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimewebsocket/).[`sendMcpResponse`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimewebsocket/#sendmcpresponse) *** ### sendMessage() [Section titled “sendMessage()”](#sendmessage) ```ts sendMessage( message, otherEventData, __namedParameters?): void; ``` Send a message to the Realtime API. This will create a new item in the conversation and trigger a response. #### Parameters [Section titled “Parameters”](#parameters-19) | Parameter | Type | Description | | ------------------------------------ | ---------------------------------- | ------------------------------ | | `message` | `RealtimeUserInput` | The message to send. | | `otherEventData` | `Record`<`string`, `any`> | Additional event data to send. | | `__namedParameters?` | { `triggerResponse?`: `boolean`; } | ‐ | | `__namedParameters.triggerResponse?` | `boolean` | ‐ | #### Returns [Section titled “Returns”](#returns-25) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-21) [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimewebsocket/).[`sendMessage`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimewebsocket/#sendmessage) *** ### updateSessionConfig() [Section titled “updateSessionConfig()”](#updatesessionconfig) ```ts updateSessionConfig(config): void; ``` Updates the session config. This will merge it with the current session config with the default values and send it to the Realtime API. #### Parameters [Section titled “Parameters”](#parameters-20) | Parameter | Type | Description | | --------- | ------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------- | | `config` | `Partial`<[`RealtimeSessionConfig`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimesessionconfig/)> | The session config to update. | #### Returns [Section titled “Returns”](#returns-26) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-22) [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimewebsocket/).[`updateSessionConfig`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimewebsocket/#updatesessionconfig) *** ### buildInitialConfig() [Section titled “buildInitialConfig()”](#buildinitialconfig) ```ts static buildInitialConfig( agent, options?, overrides?): Promise; ``` Build the initial session payload for a SIP-attached session, matching the config that a RealtimeSession would send on connect. This enables SIP deployments to accept an incoming call with a payload that already reflects the active agent’s instructions, tools, prompt, and tracing metadata without duplicating the session logic outside of the SDK. The returned object structurally matches the REST `CallAcceptParams` interface, so it can be forwarded directly to `openai.realtime.calls.accept(...)`. #### Type Parameters [Section titled “Type Parameters”](#type-parameters-4) | Type Parameter | Default type | | -------------- | ------------ | | `TBaseContext` | `unknown` | #### Parameters [Section titled “Parameters”](#parameters-21) | Parameter | Type | Description | | ------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- | | `agent` | \| [`RealtimeAgent`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/realtimeagent/)<`TBaseContext`> \| [`RealtimeAgent`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/realtimeagent/)<[`RealtimeContextData`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimecontextdata/)<`TBaseContext`>> | The starting agent used to seed the session instructions, tools, and prompt. | | `options?` | `Partial`<[`RealtimeSessionOptions`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimesessionoptions/)<`TBaseContext`>> | Optional session options that mirror the ones passed to the RealtimeSession constructor. | | `overrides?` | `Partial`<[`RealtimeSessionConfig`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimesessionconfig/)> | Additional config overrides applied on top of the session options. | #### Returns [Section titled “Returns”](#returns-27) `Promise`<[`RealtimeSessionPayload`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimesessionpayload/)> # OpenAIRealtimeWebRTC Transport layer that’s handling the connection between the client and OpenAI’s Realtime API via WebRTC. While this transport layer is designed to be used within a RealtimeSession, it can also be used standalone if you want to have a direct connection to the Realtime API. Unless you specify a `mediaStream` or `audioElement` option, the transport layer will automatically configure the microphone and audio output to be used by the session. ## Extends [Section titled “Extends”](#extends) * [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/) ## Implements [Section titled “Implements”](#implements) * [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/) ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new OpenAIRealtimeWebRTC(options?): OpenAIRealtimeWebRTC; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ---------- | ------------------------------------------------------------------------------------------------------------------------------------- | | `options?` | [`OpenAIRealtimeWebRTCOptions`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/openairealtimewebrtcoptions/) | #### Returns [Section titled “Returns”](#returns) `OpenAIRealtimeWebRTC` #### Overrides [Section titled “Overrides”](#overrides) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/).[`constructor`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/#constructor) ## Accessors [Section titled “Accessors”](#accessors) ### \_tracingConfig [Section titled “\_tracingConfig”](#_tracingconfig) #### Set Signature [Section titled “Set Signature”](#set-signature) ```ts set _tracingConfig(tracingConfig): void; ``` Sets the internal tracing config. This is used to track the tracing config that has been set during the session.create event. ##### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | --------------- | --------------------------------- | | `tracingConfig` | `RealtimeTracingConfig` \| `null` | ##### Returns [Section titled “Returns”](#returns-1) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/).[`_tracingConfig`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/#_tracingconfig) *** ### callId [Section titled “callId”](#callid) #### Get Signature [Section titled “Get Signature”](#get-signature) ```ts get callId(): string | undefined; ``` The current call ID of the WebRTC connection. ##### Returns [Section titled “Returns”](#returns-2) `string` | `undefined` *** ### connectionState [Section titled “connectionState”](#connectionstate) #### Get Signature [Section titled “Get Signature”](#get-signature-1) ```ts get connectionState(): WebRTCState; ``` The current connection state of the WebRTC connection including the peer connection and data channel. ##### Returns [Section titled “Returns”](#returns-3) [`WebRTCState`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/webrtcstate/) *** ### currentModel [Section titled “currentModel”](#currentmodel) #### Get Signature [Section titled “Get Signature”](#get-signature-2) ```ts get currentModel(): OpenAIRealtimeModels; ``` The current model that is being used by the transport layer. ##### Returns [Section titled “Returns”](#returns-4) [`OpenAIRealtimeModels`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/openairealtimemodels/) #### Set Signature [Section titled “Set Signature”](#set-signature-1) ```ts set currentModel(model): void; ``` The current model that is being used by the transport layer. **Note**: The model cannot be changed mid conversation. ##### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | --------- | ----------------------------------------------------------------------------------------------------------------------- | | `model` | [`OpenAIRealtimeModels`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/openairealtimemodels/) | ##### Returns [Section titled “Returns”](#returns-5) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-1) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/).[`currentModel`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/#currentmodel) *** ### muted [Section titled “muted”](#muted) #### Get Signature [Section titled “Get Signature”](#get-signature-3) ```ts get muted(): boolean; ``` Whether the session is muted. ##### Returns [Section titled “Returns”](#returns-6) `boolean` Whether the input audio track is currently muted null if the muting is not handled by the transport layer #### Implementation of [Section titled “Implementation of”](#implementation-of) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/).[`muted`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/#muted) #### Overrides [Section titled “Overrides”](#overrides-1) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/).[`muted`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/#muted) *** ### status [Section titled “status”](#status) #### Get Signature [Section titled “Get Signature”](#get-signature-4) ```ts get status(): "connecting" | "connected" | "disconnected"; ``` The current status of the WebRTC connection. ##### Returns [Section titled “Returns”](#returns-7) `"connecting"` | `"connected"` | `"disconnected"` #### Implementation of [Section titled “Implementation of”](#implementation-of-1) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/).[`status`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/#status) #### Overrides [Section titled “Overrides”](#overrides-2) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/).[`status`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/#status) ## Methods [Section titled “Methods”](#methods) ### addImage() [Section titled “addImage()”](#addimage) ```ts addImage(image, options?): void; ``` Sends an image to the model #### Parameters [Section titled “Parameters”](#parameters-3) | Parameter | Type | Description | | -------------------------- | ---------------------------------- | -------------------------------------------- | | `image` | `string` | The image to send | | `options?` | { `triggerResponse?`: `boolean`; } | Additional options | | `options.triggerResponse?` | `boolean` | Whether to trigger a response from the model | #### Returns [Section titled “Returns”](#returns-8) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-2) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/).[`addImage`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/#addimage) #### Inherited from [Section titled “Inherited from”](#inherited-from-2) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/).[`addImage`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/#addimage) *** ### buildSessionPayload() [Section titled “buildSessionPayload()”](#buildsessionpayload) ```ts buildSessionPayload(config): RealtimeSessionPayload; ``` Build the payload object expected by the Realtime API when creating or updating a session. The helper centralises the conversion from camelCase runtime config to the snake\_case payload required by the Realtime API so transports that need a one-off payload (for example SIP call acceptance) can reuse the same logic without duplicating private state. #### Parameters [Section titled “Parameters”](#parameters-4) | Parameter | Type | Description | | --------- | ------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------ | | `config` | `Partial`<[`RealtimeSessionConfig`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimesessionconfig/)> | The session config to merge with defaults. | #### Returns [Section titled “Returns”](#returns-9) [`RealtimeSessionPayload`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimesessionpayload/) #### Inherited from [Section titled “Inherited from”](#inherited-from-3) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/).[`buildSessionPayload`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/#buildsessionpayload) *** ### close() [Section titled “close()”](#close) ```ts close(): void; ``` Close the connection to the Realtime API and disconnects the underlying WebRTC connection. #### Returns [Section titled “Returns”](#returns-10) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-3) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/).[`close`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/#close) #### Overrides [Section titled “Overrides”](#overrides-3) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/).[`close`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/#close) *** ### connect() [Section titled “connect()”](#connect) ```ts connect(options): Promise; ``` Connect to the Realtime API. This will establish the connection to the OpenAI Realtime API via WebRTC. If you are using a browser, the transport layer will also automatically configure the microphone and audio output to be used by the session. #### Parameters [Section titled “Parameters”](#parameters-5) | Parameter | Type | Description | | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------- | | `options` | [`RealtimeTransportLayerConnectOptions`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimetransportlayerconnectoptions/) | The options for the connection. | #### Returns [Section titled “Returns”](#returns-11) `Promise`<`void`> #### Implementation of [Section titled “Implementation of”](#implementation-of-4) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/).[`connect`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/#connect) #### Overrides [Section titled “Overrides”](#overrides-4) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/).[`connect`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/#connect) *** ### emit() [Section titled “emit()”](#emit) ```ts emit(type, ...args): boolean; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | --------------------------------------------------------------------------------------------------------------------------------------------------------- | | `K` *extends* keyof [`RealtimeTransportEventTypes`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimetransporteventtypes/) | #### Parameters [Section titled “Parameters”](#parameters-6) | Parameter | Type | | --------- | ------------------------------------------------------------------------------------------------------------------------------------- | | `type` | `K` | | …`args` | [`OpenAIRealtimeEventTypes`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/openairealtimeeventtypes/)\[`K`] | #### Returns [Section titled “Returns”](#returns-12) `boolean` #### Implementation of [Section titled “Implementation of”](#implementation-of-5) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/).[`emit`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/#emit) #### Inherited from [Section titled “Inherited from”](#inherited-from-4) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/).[`emit`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/#emit) *** ### interrupt() [Section titled “interrupt()”](#interrupt) ```ts interrupt(): void; ``` Interrupt the current response if one is ongoing and clear the audio buffer so that the agent stops talking. #### Returns [Section titled “Returns”](#returns-13) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-6) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/).[`interrupt`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/#interrupt) #### Overrides [Section titled “Overrides”](#overrides-5) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/).[`interrupt`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/#interrupt) *** ### mute() [Section titled “mute()”](#mute) ```ts mute(muted): void; ``` Mute or unmute the session. #### Parameters [Section titled “Parameters”](#parameters-7) | Parameter | Type | Description | | --------- | --------- | ---------------------------- | | `muted` | `boolean` | Whether to mute the session. | #### Returns [Section titled “Returns”](#returns-14) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-7) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/).[`mute`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/#mute) #### Overrides [Section titled “Overrides”](#overrides-6) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/).[`mute`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/#mute) *** ### off() [Section titled “off()”](#off) ```ts off(type, listener): EventEmitter; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-1) | Type Parameter | | --------------------------------------------------------------------------------------------------------------------------------------------------------- | | `K` *extends* keyof [`RealtimeTransportEventTypes`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimetransporteventtypes/) | #### Parameters [Section titled “Parameters”](#parameters-8) | Parameter | Type | | ---------- | ------------------- | | `type` | `K` | | `listener` | (…`args`) => `void` | #### Returns [Section titled “Returns”](#returns-15) `EventEmitter`<`EventTypes`> #### Implementation of [Section titled “Implementation of”](#implementation-of-8) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/).[`off`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/#off) #### Inherited from [Section titled “Inherited from”](#inherited-from-5) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/).[`off`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/#off) *** ### on() [Section titled “on()”](#on) ```ts on(type, listener): EventEmitter; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-2) | Type Parameter | | --------------------------------------------------------------------------------------------------------------------------------------------------------- | | `K` *extends* keyof [`RealtimeTransportEventTypes`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimetransporteventtypes/) | #### Parameters [Section titled “Parameters”](#parameters-9) | Parameter | Type | | ---------- | ------------------- | | `type` | `K` | | `listener` | (…`args`) => `void` | #### Returns [Section titled “Returns”](#returns-16) `EventEmitter`<`EventTypes`> #### Implementation of [Section titled “Implementation of”](#implementation-of-9) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/).[`on`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/#on) #### Inherited from [Section titled “Inherited from”](#inherited-from-6) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/).[`on`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/#on) *** ### once() [Section titled “once()”](#once) ```ts once(type, listener): EventEmitter; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-3) | Type Parameter | | --------------------------------------------------------------------------------------------------------------------------------------------------------- | | `K` *extends* keyof [`RealtimeTransportEventTypes`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimetransporteventtypes/) | #### Parameters [Section titled “Parameters”](#parameters-10) | Parameter | Type | | ---------- | ------------------- | | `type` | `K` | | `listener` | (…`args`) => `void` | #### Returns [Section titled “Returns”](#returns-17) `EventEmitter`<`EventTypes`> #### Implementation of [Section titled “Implementation of”](#implementation-of-10) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/).[`once`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/#once) #### Inherited from [Section titled “Inherited from”](#inherited-from-7) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/).[`once`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/#once) *** ### requestResponse() [Section titled “requestResponse()”](#requestresponse) ```ts requestResponse(response?): void; ``` Requests a new response for the current conversation turn. Implementations may defer the underlying `response.create` until the server has fully finished the prior response. #### Parameters [Section titled “Parameters”](#parameters-11) | Parameter | Type | Description | | ----------- | ------------------------- | ------------------------------------------- | | `response?` | `Record`<`string`, `any`> | Optional one-off response override payload. | #### Returns [Section titled “Returns”](#returns-18) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-11) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/).[`requestResponse`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/#requestresponse) #### Overrides [Section titled “Overrides”](#overrides-7) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/).[`requestResponse`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/#requestresponse) *** ### resetHistory() [Section titled “resetHistory()”](#resethistory) ```ts resetHistory(oldHistory, newHistory): void; ``` Reset the history of the conversation. This will create a diff between the old and new history and send the necessary events to the Realtime API to update the history. #### Parameters [Section titled “Parameters”](#parameters-12) | Parameter | Type | Description | | ------------ | ---------------------------------------------------------------------------------------------------------- | ------------------------------------ | | `oldHistory` | [`RealtimeItem`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimeitem/)\[] | The old history of the conversation. | | `newHistory` | [`RealtimeItem`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimeitem/)\[] | The new history of the conversation. | #### Returns [Section titled “Returns”](#returns-19) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-12) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/).[`resetHistory`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/#resethistory) #### Inherited from [Section titled “Inherited from”](#inherited-from-8) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/).[`resetHistory`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/#resethistory) *** ### sendAudio() [Section titled “sendAudio()”](#sendaudio) ```ts sendAudio(audio, options?): void; ``` Send an audio buffer to the Realtime API. If `{ commit: true }` is passed, the audio buffer will be committed and the model will start processing it. This is necessary if you have disabled turn detection / voice activity detection (VAD). #### Parameters [Section titled “Parameters”](#parameters-13) | Parameter | Type | Description | | ----------------- | ------------------------- | --------------------------------- | | `audio` | `ArrayBuffer` | The audio buffer to send. | | `options?` | { `commit?`: `boolean`; } | The options for the audio buffer. | | `options.commit?` | `boolean` | ‐ | #### Returns [Section titled “Returns”](#returns-20) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-13) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/).[`sendAudio`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/#sendaudio) #### Inherited from [Section titled “Inherited from”](#inherited-from-9) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/).[`sendAudio`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/#sendaudio) *** ### sendEvent() [Section titled “sendEvent()”](#sendevent) ```ts sendEvent(event): void; ``` Send an event to the Realtime API. This will stringify the event and send it directly to the API. This can be used if you want to take control over the connection and send events manually. #### Parameters [Section titled “Parameters”](#parameters-14) | Parameter | Type | Description | | --------- | ------------------------------------------------------------------------------------------------------------------------- | ------------------ | | `event` | [`RealtimeClientMessage`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimeclientmessage/) | The event to send. | #### Returns [Section titled “Returns”](#returns-21) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-14) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/).[`sendEvent`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/#sendevent) #### Overrides [Section titled “Overrides”](#overrides-8) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/).[`sendEvent`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/#sendevent) *** ### sendFunctionCallOutput() [Section titled “sendFunctionCallOutput()”](#sendfunctioncalloutput) ```ts sendFunctionCallOutput( toolCall, output, startResponse?): void; ``` Send the output of a function call to the Realtime API. #### Parameters [Section titled “Parameters”](#parameters-15) | Parameter | Type | Description | | ---------------- | --------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------- | | `toolCall` | [`TransportToolCallEvent`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/transporttoolcallevent/) | The tool call to send the output for. | | `output` | `string` | The output of the function call. | | `startResponse?` | `boolean` | Whether to start a new response after sending the output. | #### Returns [Section titled “Returns”](#returns-22) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-15) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/).[`sendFunctionCallOutput`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/#sendfunctioncalloutput) #### Inherited from [Section titled “Inherited from”](#inherited-from-10) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/).[`sendFunctionCallOutput`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/#sendfunctioncalloutput) *** ### sendMcpResponse() [Section titled “sendMcpResponse()”](#sendmcpresponse) ```ts sendMcpResponse( approvalRequest, approved, reason?): void; ``` Sends a response for an MCP tool call #### Parameters [Section titled “Parameters”](#parameters-16) | Parameter | Type | Description | | ------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------- | | `approvalRequest` | { `approved?`: `boolean` \| `null`; `arguments`: `z.ZodRecord`<`z.ZodString`, `z.ZodAny`>; `itemId`: `string`; `name`: `string`; `serverLabel`: `string`; `type`: `"mcp_approval_request"`; } | The approval request to respond to | | `approvalRequest.approved?` | `boolean` \| `null` | ‐ | | `approvalRequest.arguments` | `z.ZodRecord`<`z.ZodString`, `z.ZodAny`> | ‐ | | `approvalRequest.itemId?` | `string` | ‐ | | `approvalRequest.name?` | `string` | ‐ | | `approvalRequest.serverLabel?` | `string` | ‐ | | `approvalRequest.type?` | `"mcp_approval_request"` | ‐ | | `approved?` | `boolean` | Whether the tool call was approved or rejected | | `reason?` | `string` | Optional rejection text for the provider/model. | #### Returns [Section titled “Returns”](#returns-23) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-16) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/).[`sendMcpResponse`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/#sendmcpresponse) #### Inherited from [Section titled “Inherited from”](#inherited-from-11) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/).[`sendMcpResponse`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/#sendmcpresponse) *** ### sendMessage() [Section titled “sendMessage()”](#sendmessage) ```ts sendMessage( message, otherEventData, __namedParameters?): void; ``` Send a message to the Realtime API. This will create a new item in the conversation and trigger a response. #### Parameters [Section titled “Parameters”](#parameters-17) | Parameter | Type | Description | | ------------------------------------ | ---------------------------------- | ------------------------------ | | `message` | `RealtimeUserInput` | The message to send. | | `otherEventData` | `Record`<`string`, `any`> | Additional event data to send. | | `__namedParameters?` | { `triggerResponse?`: `boolean`; } | ‐ | | `__namedParameters.triggerResponse?` | `boolean` | ‐ | #### Returns [Section titled “Returns”](#returns-24) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-17) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/).[`sendMessage`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/#sendmessage) #### Inherited from [Section titled “Inherited from”](#inherited-from-12) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/).[`sendMessage`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/#sendmessage) *** ### updateSessionConfig() [Section titled “updateSessionConfig()”](#updatesessionconfig) ```ts updateSessionConfig(config): void; ``` Updates the session config. This will merge it with the current session config with the default values and send it to the Realtime API. #### Parameters [Section titled “Parameters”](#parameters-18) | Parameter | Type | Description | | --------- | ------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------- | | `config` | `Partial`<[`RealtimeSessionConfig`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimesessionconfig/)> | The session config to update. | #### Returns [Section titled “Returns”](#returns-25) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-18) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/).[`updateSessionConfig`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/#updatesessionconfig) #### Inherited from [Section titled “Inherited from”](#inherited-from-13) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/).[`updateSessionConfig`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/#updatesessionconfig) # OpenAIRealtimeWebSocket Transport layer that’s handling the connection between the client and OpenAI’s Realtime API via WebSockets. While this transport layer is designed to be used within a RealtimeSession, it can also be used standalone if you want to have a direct connection to the Realtime API. ## Extends [Section titled “Extends”](#extends) * [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/) ## Extended by [Section titled “Extended by”](#extended-by) * [`OpenAIRealtimeSIP`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimesip/) ## Implements [Section titled “Implements”](#implements) * [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/) ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new OpenAIRealtimeWebSocket(options?): OpenAIRealtimeWebSocket; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ---------- | ------------------------------------------------------------------------------------------------------------------------------------------- | | `options?` | [`OpenAIRealtimeWebSocketOptions`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/openairealtimewebsocketoptions/) | #### Returns [Section titled “Returns”](#returns) `OpenAIRealtimeWebSocket` #### Overrides [Section titled “Overrides”](#overrides) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/).[`constructor`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/#constructor) ## Accessors [Section titled “Accessors”](#accessors) ### \_tracingConfig [Section titled “\_tracingConfig”](#_tracingconfig) #### Set Signature [Section titled “Set Signature”](#set-signature) ```ts set _tracingConfig(tracingConfig): void; ``` Sets the internal tracing config. This is used to track the tracing config that has been set during the session.create event. ##### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | --------------- | --------------------------------- | | `tracingConfig` | `RealtimeTracingConfig` \| `null` | ##### Returns [Section titled “Returns”](#returns-1) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/).[`_tracingConfig`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/#_tracingconfig) *** ### connectionState [Section titled “connectionState”](#connectionstate) #### Get Signature [Section titled “Get Signature”](#get-signature) ```ts get connectionState(): WebSocketState; ``` The current connection state of the WebSocket connection. ##### Returns [Section titled “Returns”](#returns-2) [`WebSocketState`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/websocketstate/) *** ### currentModel [Section titled “currentModel”](#currentmodel) #### Get Signature [Section titled “Get Signature”](#get-signature-1) ```ts get currentModel(): OpenAIRealtimeModels; ``` The current model that is being used by the transport layer. ##### Returns [Section titled “Returns”](#returns-3) [`OpenAIRealtimeModels`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/openairealtimemodels/) #### Set Signature [Section titled “Set Signature”](#set-signature-1) ```ts set currentModel(model): void; ``` The current model that is being used by the transport layer. **Note**: The model cannot be changed mid conversation. ##### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | --------- | ----------------------------------------------------------------------------------------------------------------------- | | `model` | [`OpenAIRealtimeModels`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/openairealtimemodels/) | ##### Returns [Section titled “Returns”](#returns-4) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-1) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/).[`currentModel`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/#currentmodel) *** ### muted [Section titled “muted”](#muted) #### Get Signature [Section titled “Get Signature”](#get-signature-2) ```ts get muted(): null; ``` Always returns `null` as the WebSocket transport layer does not handle muting. Instead, this should be handled by the client by not triggering the `sendAudio` method. ##### Returns [Section titled “Returns”](#returns-5) `null` Whether the input audio track is currently muted null if the muting is not handled by the transport layer #### Implementation of [Section titled “Implementation of”](#implementation-of) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/).[`muted`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/#muted) #### Overrides [Section titled “Overrides”](#overrides-1) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/).[`muted`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/#muted) *** ### status [Section titled “status”](#status) #### Get Signature [Section titled “Get Signature”](#get-signature-3) ```ts get status(): "connecting" | "connected" | "disconnected"; ``` The current status of the WebSocket connection. ##### Returns [Section titled “Returns”](#returns-6) `"connecting"` | `"connected"` | `"disconnected"` #### Implementation of [Section titled “Implementation of”](#implementation-of-1) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/).[`status`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/#status) #### Overrides [Section titled “Overrides”](#overrides-2) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/).[`status`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/#status) ## Methods [Section titled “Methods”](#methods) ### \_cancelResponse() [Section titled “\_cancelResponse()”](#_cancelresponse) ```ts _cancelResponse(): void; ``` Send a cancel response event to the Realtime API. This is used to cancel an ongoing response that the model is currently generating. #### Returns [Section titled “Returns”](#returns-7) `void` *** ### \_interrupt() [Section titled “\_interrupt()”](#_interrupt) ```ts _interrupt(elapsedTime, cancelOngoingResponse?): void; ``` Do NOT call this method directly. Call `interrupt()` instead for proper interruption handling. This method is used to send the right events to the API to inform the model that the user has interrupted the response. It might be overridden/extended by an extended transport layer. See the `TwilioRealtimeTransportLayer` for an example. #### Parameters [Section titled “Parameters”](#parameters-3) | Parameter | Type | Description | | ------------------------ | --------- | -------------------------------------------- | | `elapsedTime` | `number` | The elapsed time since the response started. | | `cancelOngoingResponse?` | `boolean` | ‐ | #### Returns [Section titled “Returns”](#returns-8) `void` *** ### addImage() [Section titled “addImage()”](#addimage) ```ts addImage(image, options?): void; ``` Sends an image to the model #### Parameters [Section titled “Parameters”](#parameters-4) | Parameter | Type | Description | | -------------------------- | ---------------------------------- | -------------------------------------------- | | `image` | `string` | The image to send | | `options?` | { `triggerResponse?`: `boolean`; } | Additional options | | `options.triggerResponse?` | `boolean` | Whether to trigger a response from the model | #### Returns [Section titled “Returns”](#returns-9) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-2) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/).[`addImage`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/#addimage) #### Inherited from [Section titled “Inherited from”](#inherited-from-2) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/).[`addImage`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/#addimage) *** ### buildSessionPayload() [Section titled “buildSessionPayload()”](#buildsessionpayload) ```ts buildSessionPayload(config): RealtimeSessionPayload; ``` Build the payload object expected by the Realtime API when creating or updating a session. The helper centralises the conversion from camelCase runtime config to the snake\_case payload required by the Realtime API so transports that need a one-off payload (for example SIP call acceptance) can reuse the same logic without duplicating private state. #### Parameters [Section titled “Parameters”](#parameters-5) | Parameter | Type | Description | | --------- | ------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------ | | `config` | `Partial`<[`RealtimeSessionConfig`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimesessionconfig/)> | The session config to merge with defaults. | #### Returns [Section titled “Returns”](#returns-10) [`RealtimeSessionPayload`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimesessionpayload/) #### Inherited from [Section titled “Inherited from”](#inherited-from-3) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/).[`buildSessionPayload`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/#buildsessionpayload) *** ### close() [Section titled “close()”](#close) ```ts close(): void; ``` Close the WebSocket connection. This will also reset any internal connection tracking used for interruption handling. #### Returns [Section titled “Returns”](#returns-11) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-3) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/).[`close`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/#close) #### Overrides [Section titled “Overrides”](#overrides-3) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/).[`close`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/#close) *** ### connect() [Section titled “connect()”](#connect) ```ts connect(options): Promise; ``` Establishes the connection to the model and keeps the connection alive #### Parameters [Section titled “Parameters”](#parameters-6) | Parameter | Type | Description | | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------ | | `options` | [`RealtimeTransportLayerConnectOptions`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimetransportlayerconnectoptions/) | The options for the connection | #### Returns [Section titled “Returns”](#returns-12) `Promise`<`void`> #### Implementation of [Section titled “Implementation of”](#implementation-of-4) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/).[`connect`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/#connect) #### Overrides [Section titled “Overrides”](#overrides-4) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/).[`connect`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/#connect) *** ### emit() [Section titled “emit()”](#emit) ```ts emit(type, ...args): boolean; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | --------------------------------------------------------------------------------------------------------------------------------------------------------- | | `K` *extends* keyof [`RealtimeTransportEventTypes`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimetransporteventtypes/) | #### Parameters [Section titled “Parameters”](#parameters-7) | Parameter | Type | | --------- | ------------------------------------------------------------------------------------------------------------------------------------- | | `type` | `K` | | …`args` | [`OpenAIRealtimeEventTypes`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/openairealtimeeventtypes/)\[`K`] | #### Returns [Section titled “Returns”](#returns-13) `boolean` #### Implementation of [Section titled “Implementation of”](#implementation-of-5) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/).[`emit`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/#emit) #### Inherited from [Section titled “Inherited from”](#inherited-from-4) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/).[`emit`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/#emit) *** ### interrupt() [Section titled “interrupt()”](#interrupt) ```ts interrupt(cancelOngoingResponse?): void; ``` Interrupt the ongoing response. This method is triggered automatically by the client when voice activity detection (VAD) is enabled (default) as well as when an output guardrail got triggered. You can also call this method directly if you want to interrupt the conversation for example based on an event in the client. #### Parameters [Section titled “Parameters”](#parameters-8) | Parameter | Type | | ------------------------ | --------- | | `cancelOngoingResponse?` | `boolean` | #### Returns [Section titled “Returns”](#returns-14) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-6) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/).[`interrupt`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/#interrupt) #### Overrides [Section titled “Overrides”](#overrides-5) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/).[`interrupt`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/#interrupt) *** ### mute() [Section titled “mute()”](#mute) ```ts mute(_muted): never; ``` Will throw an error as the WebSocket transport layer does not support muting. #### Parameters [Section titled “Parameters”](#parameters-9) | Parameter | Type | | --------- | --------- | | `_muted` | `boolean` | #### Returns [Section titled “Returns”](#returns-15) `never` #### Implementation of [Section titled “Implementation of”](#implementation-of-7) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/).[`mute`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/#mute) #### Overrides [Section titled “Overrides”](#overrides-6) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/).[`mute`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/#mute) *** ### off() [Section titled “off()”](#off) ```ts off(type, listener): EventEmitter; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-1) | Type Parameter | | --------------------------------------------------------------------------------------------------------------------------------------------------------- | | `K` *extends* keyof [`RealtimeTransportEventTypes`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimetransporteventtypes/) | #### Parameters [Section titled “Parameters”](#parameters-10) | Parameter | Type | | ---------- | ------------------- | | `type` | `K` | | `listener` | (…`args`) => `void` | #### Returns [Section titled “Returns”](#returns-16) `EventEmitter`<`EventTypes`> #### Implementation of [Section titled “Implementation of”](#implementation-of-8) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/).[`off`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/#off) #### Inherited from [Section titled “Inherited from”](#inherited-from-5) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/).[`off`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/#off) *** ### on() [Section titled “on()”](#on) ```ts on(type, listener): EventEmitter; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-2) | Type Parameter | | --------------------------------------------------------------------------------------------------------------------------------------------------------- | | `K` *extends* keyof [`RealtimeTransportEventTypes`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimetransporteventtypes/) | #### Parameters [Section titled “Parameters”](#parameters-11) | Parameter | Type | | ---------- | ------------------- | | `type` | `K` | | `listener` | (…`args`) => `void` | #### Returns [Section titled “Returns”](#returns-17) `EventEmitter`<`EventTypes`> #### Implementation of [Section titled “Implementation of”](#implementation-of-9) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/).[`on`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/#on) #### Inherited from [Section titled “Inherited from”](#inherited-from-6) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/).[`on`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/#on) *** ### once() [Section titled “once()”](#once) ```ts once(type, listener): EventEmitter; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-3) | Type Parameter | | --------------------------------------------------------------------------------------------------------------------------------------------------------- | | `K` *extends* keyof [`RealtimeTransportEventTypes`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimetransporteventtypes/) | #### Parameters [Section titled “Parameters”](#parameters-12) | Parameter | Type | | ---------- | ------------------- | | `type` | `K` | | `listener` | (…`args`) => `void` | #### Returns [Section titled “Returns”](#returns-18) `EventEmitter`<`EventTypes`> #### Implementation of [Section titled “Implementation of”](#implementation-of-10) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/).[`once`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/#once) #### Inherited from [Section titled “Inherited from”](#inherited-from-7) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/).[`once`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/#once) *** ### requestResponse() [Section titled “requestResponse()”](#requestresponse) ```ts requestResponse(response?): void; ``` Requests a new response for the current conversation turn. Implementations may defer the underlying `response.create` until the server has fully finished the prior response. #### Parameters [Section titled “Parameters”](#parameters-13) | Parameter | Type | Description | | ----------- | ------------------------- | ------------------------------------------- | | `response?` | `Record`<`string`, `any`> | Optional one-off response override payload. | #### Returns [Section titled “Returns”](#returns-19) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-11) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/).[`requestResponse`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/#requestresponse) #### Overrides [Section titled “Overrides”](#overrides-7) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/).[`requestResponse`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/#requestresponse) *** ### resetHistory() [Section titled “resetHistory()”](#resethistory) ```ts resetHistory(oldHistory, newHistory): void; ``` Reset the history of the conversation. This will create a diff between the old and new history and send the necessary events to the Realtime API to update the history. #### Parameters [Section titled “Parameters”](#parameters-14) | Parameter | Type | Description | | ------------ | ---------------------------------------------------------------------------------------------------------- | ------------------------------------ | | `oldHistory` | [`RealtimeItem`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimeitem/)\[] | The old history of the conversation. | | `newHistory` | [`RealtimeItem`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimeitem/)\[] | The new history of the conversation. | #### Returns [Section titled “Returns”](#returns-20) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-12) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/).[`resetHistory`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/#resethistory) #### Inherited from [Section titled “Inherited from”](#inherited-from-8) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/).[`resetHistory`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/#resethistory) *** ### sendAudio() [Section titled “sendAudio()”](#sendaudio) ```ts sendAudio(audio, options?): void; ``` Send an audio buffer to the Realtime API. This is used for your client to send audio to the model to respond. #### Parameters [Section titled “Parameters”](#parameters-15) | Parameter | Type | Description | | ----------------- | ------------------------- | --------------------------------- | | `audio` | `ArrayBuffer` | The audio buffer to send. | | `options?` | { `commit?`: `boolean`; } | The options for the audio buffer. | | `options.commit?` | `boolean` | ‐ | #### Returns [Section titled “Returns”](#returns-21) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-13) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/).[`sendAudio`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/#sendaudio) #### Overrides [Section titled “Overrides”](#overrides-8) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/).[`sendAudio`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/#sendaudio) *** ### sendEvent() [Section titled “sendEvent()”](#sendevent) ```ts sendEvent(event): void; ``` Send an event to the Realtime API. This will stringify the event and send it directly to the API. This can be used if you want to take control over the connection and send events manually. #### Parameters [Section titled “Parameters”](#parameters-16) | Parameter | Type | Description | | --------- | ------------------------------------------------------------------------------------------------------------------------- | ------------------ | | `event` | [`RealtimeClientMessage`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimeclientmessage/) | The event to send. | #### Returns [Section titled “Returns”](#returns-22) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-14) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/).[`sendEvent`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/#sendevent) #### Overrides [Section titled “Overrides”](#overrides-9) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/).[`sendEvent`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/#sendevent) *** ### sendFunctionCallOutput() [Section titled “sendFunctionCallOutput()”](#sendfunctioncalloutput) ```ts sendFunctionCallOutput( toolCall, output, startResponse?): void; ``` Send the output of a function call to the Realtime API. #### Parameters [Section titled “Parameters”](#parameters-17) | Parameter | Type | Description | | ---------------- | --------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------- | | `toolCall` | [`TransportToolCallEvent`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/transporttoolcallevent/) | The tool call to send the output for. | | `output` | `string` | The output of the function call. | | `startResponse?` | `boolean` | Whether to start a new response after sending the output. | #### Returns [Section titled “Returns”](#returns-23) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-15) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/).[`sendFunctionCallOutput`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/#sendfunctioncalloutput) #### Inherited from [Section titled “Inherited from”](#inherited-from-9) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/).[`sendFunctionCallOutput`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/#sendfunctioncalloutput) *** ### sendMcpResponse() [Section titled “sendMcpResponse()”](#sendmcpresponse) ```ts sendMcpResponse( approvalRequest, approved, reason?): void; ``` Sends a response for an MCP tool call #### Parameters [Section titled “Parameters”](#parameters-18) | Parameter | Type | Description | | ------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------- | | `approvalRequest` | { `approved?`: `boolean` \| `null`; `arguments`: `z.ZodRecord`<`z.ZodString`, `z.ZodAny`>; `itemId`: `string`; `name`: `string`; `serverLabel`: `string`; `type`: `"mcp_approval_request"`; } | The approval request to respond to | | `approvalRequest.approved?` | `boolean` \| `null` | ‐ | | `approvalRequest.arguments` | `z.ZodRecord`<`z.ZodString`, `z.ZodAny`> | ‐ | | `approvalRequest.itemId?` | `string` | ‐ | | `approvalRequest.name?` | `string` | ‐ | | `approvalRequest.serverLabel?` | `string` | ‐ | | `approvalRequest.type?` | `"mcp_approval_request"` | ‐ | | `approved?` | `boolean` | Whether the tool call was approved or rejected | | `reason?` | `string` | Optional rejection text for the provider/model. | #### Returns [Section titled “Returns”](#returns-24) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-16) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/).[`sendMcpResponse`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/#sendmcpresponse) #### Inherited from [Section titled “Inherited from”](#inherited-from-10) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/).[`sendMcpResponse`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/#sendmcpresponse) *** ### sendMessage() [Section titled “sendMessage()”](#sendmessage) ```ts sendMessage( message, otherEventData, __namedParameters?): void; ``` Send a message to the Realtime API. This will create a new item in the conversation and trigger a response. #### Parameters [Section titled “Parameters”](#parameters-19) | Parameter | Type | Description | | ------------------------------------ | ---------------------------------- | ------------------------------ | | `message` | `RealtimeUserInput` | The message to send. | | `otherEventData` | `Record`<`string`, `any`> | Additional event data to send. | | `__namedParameters?` | { `triggerResponse?`: `boolean`; } | ‐ | | `__namedParameters.triggerResponse?` | `boolean` | ‐ | #### Returns [Section titled “Returns”](#returns-25) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-17) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/).[`sendMessage`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/#sendmessage) #### Inherited from [Section titled “Inherited from”](#inherited-from-11) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/).[`sendMessage`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/#sendmessage) *** ### updateSessionConfig() [Section titled “updateSessionConfig()”](#updatesessionconfig) ```ts updateSessionConfig(config): void; ``` Updates the session config. This will merge it with the current session config with the default values and send it to the Realtime API. #### Parameters [Section titled “Parameters”](#parameters-20) | Parameter | Type | Description | | --------- | ------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------- | | `config` | `Partial`<[`RealtimeSessionConfig`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimesessionconfig/)> | The session config to update. | #### Returns [Section titled “Returns”](#returns-26) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-18) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/).[`updateSessionConfig`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/#updatesessionconfig) #### Inherited from [Section titled “Inherited from”](#inherited-from-12) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/).[`updateSessionConfig`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/openairealtimebase/#updatesessionconfig) # RealtimeAgent A specialized agent instance that is meant to be used within a `RealtimeSession` to build voice agents. Due to the nature of this agent, some configuration options are not supported that are supported by regular `Agent` instances. For example: * `model` choice is not supported as all RealtimeAgents will be handled by the same model within a `RealtimeSession` * `modelSettings` is not supported as all RealtimeAgents will be handled by the same model within a `RealtimeSession` * `outputType` is not supported as RealtimeAgents do not support structured outputs * `toolUseBehavior` is not supported as all RealtimeAgents will be handled by the same model within a `RealtimeSession` * `voice` can be configured on an `Agent` level however it cannot be changed after the first agent within a `RealtimeSession` spoke ## Example [Section titled “Example”](#example) ```ts const agent = new RealtimeAgent({ name: 'my-agent', instructions: 'You are a helpful assistant that can answer questions and help with tasks.', }) const session = new RealtimeSession(agent); ``` ## Extends [Section titled “Extends”](#extends) * [`Agent`](/openai-agents-js/openai/agents/classes/agent/)<[`RealtimeContextData`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimecontextdata/)<`TContext`>, [`TextOutput`](/openai-agents-js/openai/agents/type-aliases/textoutput/)> ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | -------------------------------------------------------------------------------- | | `TContext` | [`UnknownContext`](/openai-agents-js/openai/agents/type-aliases/unknowncontext/) | ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new RealtimeAgent(config): RealtimeAgent; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | | `config` | [`RealtimeAgentConfiguration`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimeagentconfiguration/)<`TContext`> | #### Returns [Section titled “Returns”](#returns) `RealtimeAgent`<`TContext`> #### Overrides [Section titled “Overrides”](#overrides) [`Agent`](/openai-agents-js/openai/agents/classes/agent/).[`constructor`](/openai-agents-js/openai/agents/classes/agent/#constructor) ## Properties [Section titled “Properties”](#properties) ### handoffDescription [Section titled “handoffDescription”](#handoffdescription) ```ts handoffDescription: string; ``` A description of the agent. This is used when the agent is used as a handoff, so that an LLM knows what it does and when to invoke it. #### Inherited from [Section titled “Inherited from”](#inherited-from) [`Agent`](/openai-agents-js/openai/agents/classes/agent/).[`handoffDescription`](/openai-agents-js/openai/agents/classes/agent/#handoffdescription) *** ### handoffs [Section titled “handoffs”](#handoffs) ```ts handoffs: ( | Handoff | Agent)[]; ``` Handoffs are sub-agents that the agent can delegate to. You can provide a list of handoffs, and the agent can choose to delegate to them if relevant. Allows for separation of concerns and modularity. #### Inherited from [Section titled “Inherited from”](#inherited-from-1) [`Agent`](/openai-agents-js/openai/agents/classes/agent/).[`handoffs`](/openai-agents-js/openai/agents/classes/agent/#handoffs) *** ### inputGuardrails [Section titled “inputGuardrails”](#inputguardrails) ```ts inputGuardrails: InputGuardrail[]; ``` A list of checks that run in parallel to the agent by default; set `runInParallel` to false to block LLM/tool calls until the guardrail completes. Runs only if the agent is the first agent in the chain. #### Inherited from [Section titled “Inherited from”](#inherited-from-2) [`Agent`](/openai-agents-js/openai/agents/classes/agent/).[`inputGuardrails`](/openai-agents-js/openai/agents/classes/agent/#inputguardrails) *** ### instructions [Section titled “instructions”](#instructions) ```ts instructions: string | ((runContext, agent) => string | Promise); ``` The instructions for the agent. Will be used as the “system prompt” when this agent is invoked. Describes what the agent should do, and how it responds. Can either be a string, or a function that dynamically generates instructions for the agent. If you provide a function, it will be called with the context and the agent instance. It must return a string. #### Inherited from [Section titled “Inherited from”](#inherited-from-3) [`Agent`](/openai-agents-js/openai/agents/classes/agent/).[`instructions`](/openai-agents-js/openai/agents/classes/agent/#instructions) *** ### mcpConfig [Section titled “mcpConfig”](#mcpconfig) ```ts mcpConfig: object; ``` Configuration for MCP servers used by this agent. | Name | Type | Description | | --------------------------- | --------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `convertSchemasToStrict?` | `boolean` | Try to convert MCP tool schemas to strict JSON schema. | | `errorFunction?` | \| [`MCPToolErrorFunction`](/openai-agents-js/openai/agents/type-aliases/mcptoolerrorfunction/) \| `null` | Optional function to convert MCP tool failures into model-visible messages. Set to null to rethrow errors instead of converting them. Server-level errorFunction values take precedence. | | `includeServerInToolNames?` | `boolean` | Prefix local MCP tool names with their server name before exposing them to the model. The SDK still invokes the original MCP tool name on the original server. | #### Inherited from [Section titled “Inherited from”](#inherited-from-4) [`Agent`](/openai-agents-js/openai/agents/classes/agent/).[`mcpConfig`](/openai-agents-js/openai/agents/classes/agent/#mcpconfig) *** ### mcpServers [Section titled “mcpServers”](#mcpservers) ```ts mcpServers: MCPServer[]; ``` A list of [Model Context Protocol](https://modelcontextprotocol.io/) servers the agent can use. Every time the agent runs, it will include tools from these servers in the list of available tools. NOTE: You are expected to manage the lifecycle of these servers. Specifically, you must call `server.connect()` before passing it to the agent, and `server.close()` when the server is no longer needed. Consider using `connectMcpServers` or `MCPServers` to keep open/close in the same place. #### Inherited from [Section titled “Inherited from”](#inherited-from-5) [`Agent`](/openai-agents-js/openai/agents/classes/agent/).[`mcpServers`](/openai-agents-js/openai/agents/classes/agent/#mcpservers) *** ### model [Section titled “model”](#model) ```ts model: string | Model; ``` The model implementation to use when invoking the LLM. By default, if not set, the agent will use the default model returned by getDefaultModel (currently “gpt-5.4-mini”). #### Inherited from [Section titled “Inherited from”](#inherited-from-6) [`Agent`](/openai-agents-js/openai/agents/classes/agent/).[`model`](/openai-agents-js/openai/agents/classes/agent/#model) *** ### modelSettings [Section titled “modelSettings”](#modelsettings) ```ts modelSettings: ModelSettings; ``` Configures model-specific tuning parameters (e.g. temperature, top\_p, etc.) #### Inherited from [Section titled “Inherited from”](#inherited-from-7) [`Agent`](/openai-agents-js/openai/agents/classes/agent/).[`modelSettings`](/openai-agents-js/openai/agents/classes/agent/#modelsettings) *** ### name [Section titled “name”](#name) ```ts name: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-8) [`Agent`](/openai-agents-js/openai/agents/classes/agent/).[`name`](/openai-agents-js/openai/agents/classes/agent/#name) *** ### outputGuardrails [Section titled “outputGuardrails”](#outputguardrails) ```ts outputGuardrails: OutputGuardrail, RealtimeContextData>[]; ``` A list of checks that run on the final output of the agent, after generating a response. Runs only if the agent produces a final output. #### Inherited from [Section titled “Inherited from”](#inherited-from-9) [`Agent`](/openai-agents-js/openai/agents/classes/agent/).[`outputGuardrails`](/openai-agents-js/openai/agents/classes/agent/#outputguardrails) *** ### outputType [Section titled “outputType”](#outputtype) ```ts outputType: "text"; ``` The type of the output object. If not provided, the output will be a string. #### Inherited from [Section titled “Inherited from”](#inherited-from-10) [`Agent`](/openai-agents-js/openai/agents/classes/agent/).[`outputType`](/openai-agents-js/openai/agents/classes/agent/#outputtype) *** ### prompt? [Section titled “prompt?”](#prompt) ```ts optional prompt?: Prompt | ((runContext, agent) => Prompt | Promise); ``` The prompt template to use for the agent (OpenAI Responses API only). Can either be a prompt template object, or a function that returns a prompt template object. If a function is provided, it will be called with the run context and the agent instance. It must return a prompt template object. #### Inherited from [Section titled “Inherited from”](#inherited-from-11) [`Agent`](/openai-agents-js/openai/agents/classes/agent/).[`prompt`](/openai-agents-js/openai/agents/classes/agent/#prompt) *** ### resetToolChoice [Section titled “resetToolChoice”](#resettoolchoice) ```ts resetToolChoice: boolean; ``` Whether to reset the tool choice to the default value after a tool has been called. Defaults to `true`. This ensures that the agent doesn’t enter an infinite loop of tool usage. #### Inherited from [Section titled “Inherited from”](#inherited-from-12) [`Agent`](/openai-agents-js/openai/agents/classes/agent/).[`resetToolChoice`](/openai-agents-js/openai/agents/classes/agent/#resettoolchoice) *** ### tools [Section titled “tools”](#tools) ```ts tools: Tool>[]; ``` A list of tools the agent can use. #### Inherited from [Section titled “Inherited from”](#inherited-from-13) [`Agent`](/openai-agents-js/openai/agents/classes/agent/).[`tools`](/openai-agents-js/openai/agents/classes/agent/#tools) *** ### toolUseBehavior [Section titled “toolUseBehavior”](#toolusebehavior) ```ts toolUseBehavior: ToolUseBehavior; ``` This lets you configure how tool use is handled. * run\_llm\_again: The default behavior. Tools are run, and then the LLM receives the results and gets to respond. * stop\_on\_first\_tool: The output of the first tool call is used as the final output. This means that the LLM does not process the result of the tool call. * A list of tool names: The agent will stop running if any of the tools in the list are called. The final output will be the output of the first matching tool call. The LLM does not process the result of the tool call. * A function: if you pass a function, it will be called with the run context and the list of tool results. It must return a `ToolsToFinalOutputResult`, which determines whether the tool call resulted in a final output. NOTE: This configuration is specific to `FunctionTools`. Hosted tools, such as file search, web search, etc. are always processed by the LLM #### Inherited from [Section titled “Inherited from”](#inherited-from-14) [`Agent`](/openai-agents-js/openai/agents/classes/agent/).[`toolUseBehavior`](/openai-agents-js/openai/agents/classes/agent/#toolusebehavior) *** ### voice? [Section titled “voice?”](#voice) ```ts readonly optional voice?: string; ``` The voice intended to be used by the agent. If another agent already spoke during the RealtimeSession, changing the voice during a handoff will fail. *** ### DEFAULT\_MODEL\_PLACEHOLDER [Section titled “DEFAULT\_MODEL\_PLACEHOLDER”](#default_model_placeholder) ```ts static DEFAULT_MODEL_PLACEHOLDER: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-15) [`Agent`](/openai-agents-js/openai/agents/classes/agent/).[`DEFAULT_MODEL_PLACEHOLDER`](/openai-agents-js/openai/agents/classes/agent/#default_model_placeholder) ## Accessors [Section titled “Accessors”](#accessors) ### outputSchemaName [Section titled “outputSchemaName”](#outputschemaname) #### Get Signature [Section titled “Get Signature”](#get-signature) ```ts get outputSchemaName(): string; ``` Output schema name. ##### Returns [Section titled “Returns”](#returns-1) `string` #### Inherited from [Section titled “Inherited from”](#inherited-from-16) [`Agent`](/openai-agents-js/openai/agents/classes/agent/).[`outputSchemaName`](/openai-agents-js/openai/agents/classes/agent/#outputschemaname) ## Methods [Section titled “Methods”](#methods) ### asTool() [Section titled “asTool()”](#astool) #### Call Signature [Section titled “Call Signature”](#call-signature) ```ts asTool(this, options): AgentTool, TAgent, ZodObject<{ input: ZodString; }, $strip>>; ``` Transform this agent into a tool, callable by other agents. This is different from handoffs in two ways: 1. In handoffs, the new agent receives the conversation history. In this tool, the new agent receives generated input. 2. In handoffs, the new agent takes over the conversation. In this tool, the new agent is called as a tool, and the conversation is continued by the original agent. ##### Type Parameters [Section titled “Type Parameters”](#type-parameters-1) | Type Parameter | Default type | | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | `TAgent` *extends* [`Agent`](/openai-agents-js/openai/agents/classes/agent/)<[`RealtimeContextData`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimecontextdata/)<`TContext`>, `"text"`> | [`Agent`](/openai-agents-js/openai/agents/classes/agent/)<[`RealtimeContextData`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimecontextdata/)<`TContext`>, `"text"`> | ##### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | Description | | --------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------- | | `this` | `TAgent` | ‐ | | `options` | `AgentToolOptionsWithDefault`<[`RealtimeContextData`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimecontextdata/)<`TContext`>, `TAgent`> | Options for the tool. | ##### Returns [Section titled “Returns”](#returns-2) `AgentTool`<[`RealtimeContextData`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimecontextdata/)<`TContext`>, `TAgent`, `ZodObject`<{ `input`: `ZodString`; }, `$strip`>> A tool that runs the agent and returns the output text. ##### Inherited from [Section titled “Inherited from”](#inherited-from-17) [`Agent`](/openai-agents-js/openai/agents/classes/agent/).[`asTool`](/openai-agents-js/openai/agents/classes/agent/#astool) #### Call Signature [Section titled “Call Signature”](#call-signature-1) ```ts asTool(this, options): AgentTool, TAgent, TParameters>; ``` Transform this agent into a tool, callable by other agents. This is different from handoffs in two ways: 1. In handoffs, the new agent receives the conversation history. In this tool, the new agent receives generated input. 2. In handoffs, the new agent takes over the conversation. In this tool, the new agent is called as a tool, and the conversation is continued by the original agent. ##### Type Parameters [Section titled “Type Parameters”](#type-parameters-2) | Type Parameter | Default type | | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | `TAgent` *extends* [`Agent`](/openai-agents-js/openai/agents/classes/agent/)<[`RealtimeContextData`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimecontextdata/)<`TContext`>, `"text"`> | [`Agent`](/openai-agents-js/openai/agents/classes/agent/)<[`RealtimeContextData`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimecontextdata/)<`TContext`>, `"text"`> | | `TParameters` *extends* `AgentToolInputParameters` | `ZodObject`<{ `input`: `ZodString`; }, `$strip`> | ##### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | Description | | --------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------- | | `this` | `TAgent` | ‐ | | `options` | `AgentToolOptionsWithParameters`<[`RealtimeContextData`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimecontextdata/)<`TContext`>, `TAgent`, `TParameters`> | Options for the tool. | ##### Returns [Section titled “Returns”](#returns-3) `AgentTool`<[`RealtimeContextData`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimecontextdata/)<`TContext`>, `TAgent`, `TParameters`> A tool that runs the agent and returns the output text. ##### Inherited from [Section titled “Inherited from”](#inherited-from-18) [`Agent`](/openai-agents-js/openai/agents/classes/agent/).[`asTool`](/openai-agents-js/openai/agents/classes/agent/#astool) *** ### clone() [Section titled “clone()”](#clone) ```ts clone(config): Agent, "text">; ``` Makes a copy of the agent, with the given arguments changed. For example, you could do: ```plaintext const newAgent = agent.clone({ instructions: 'New instructions' }) ``` #### Parameters [Section titled “Parameters”](#parameters-3) | Parameter | Type | Description | | --------- | ------------------------------------------------------------------------------------------------------------------------ | ---------------------------------- | | `config` | `Partial`<[`AgentConfiguration`](/openai-agents-js/openai/agents/interfaces/agentconfiguration/)<`TContext`, `TOutput`>> | A partial configuration to change. | #### Returns [Section titled “Returns”](#returns-4) [`Agent`](/openai-agents-js/openai/agents/classes/agent/)<[`RealtimeContextData`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimecontextdata/)<`TContext`>, `"text"`> A new agent with the given changes. #### Inherited from [Section titled “Inherited from”](#inherited-from-19) [`Agent`](/openai-agents-js/openai/agents/classes/agent/).[`clone`](/openai-agents-js/openai/agents/classes/agent/#clone) *** ### emit() [Section titled “emit()”](#emit) ```ts emit(type, ...args): boolean; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-3) | Type Parameter | | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `K` *extends* keyof `AgentHookEvents`<[`RealtimeContextData`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimecontextdata/)<`TContext`>, `"text"`> | #### Parameters [Section titled “Parameters”](#parameters-4) | Parameter | Type | | --------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `type` | `K` | | …`args` | `AgentHookEvents`<[`RealtimeContextData`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimecontextdata/)<`TContext`>, `"text"`>\[`K`] | #### Returns [Section titled “Returns”](#returns-5) `boolean` #### Inherited from [Section titled “Inherited from”](#inherited-from-20) [`Agent`](/openai-agents-js/openai/agents/classes/agent/).[`emit`](/openai-agents-js/openai/agents/classes/agent/#emit) *** ### getAllTools() [Section titled “getAllTools()”](#getalltools) ```ts getAllTools(runContext): Promise>[]>; ``` ALl agent tools, including the MCPl and function tools. #### Parameters [Section titled “Parameters”](#parameters-5) | Parameter | Type | | ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | `runContext` | [`RunContext`](/openai-agents-js/openai/agents/classes/runcontext/)<[`RealtimeContextData`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimecontextdata/)<`TContext`>> | #### Returns [Section titled “Returns”](#returns-6) `Promise`<[`Tool`](/openai-agents-js/openai/agents/type-aliases/tool/)<[`RealtimeContextData`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimecontextdata/)<`TContext`>>\[]> all configured tools #### Inherited from [Section titled “Inherited from”](#inherited-from-21) [`Agent`](/openai-agents-js/openai/agents/classes/agent/).[`getAllTools`](/openai-agents-js/openai/agents/classes/agent/#getalltools) *** ### getEnabledHandoffs() [Section titled “getEnabledHandoffs()”](#getenabledhandoffs) ```ts getEnabledHandoffs(runContext): Promise[]>; ``` Returns the handoffs that should be exposed to the model for the current run. Handoffs that provide an `isEnabled` function returning `false` are omitted. #### Parameters [Section titled “Parameters”](#parameters-6) | Parameter | Type | | ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | `runContext` | [`RunContext`](/openai-agents-js/openai/agents/classes/runcontext/)<[`RealtimeContextData`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimecontextdata/)<`TContext`>> | #### Returns [Section titled “Returns”](#returns-7) `Promise`<[`Handoff`](/openai-agents-js/openai/agents/classes/handoff/)<`any`, `any`>\[]> #### Inherited from [Section titled “Inherited from”](#inherited-from-22) [`Agent`](/openai-agents-js/openai/agents/classes/agent/).[`getEnabledHandoffs`](/openai-agents-js/openai/agents/classes/agent/#getenabledhandoffs) *** ### getMcpTools() [Section titled “getMcpTools()”](#getmcptools) ```ts getMcpTools(runContext): Promise>[]>; ``` Fetches the available tools from the MCP servers. #### Parameters [Section titled “Parameters”](#parameters-7) | Parameter | Type | | ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | `runContext` | [`RunContext`](/openai-agents-js/openai/agents/classes/runcontext/)<[`RealtimeContextData`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimecontextdata/)<`TContext`>> | #### Returns [Section titled “Returns”](#returns-8) `Promise`<[`Tool`](/openai-agents-js/openai/agents/type-aliases/tool/)<[`RealtimeContextData`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimecontextdata/)<`TContext`>>\[]> the MCP powered tools #### Inherited from [Section titled “Inherited from”](#inherited-from-23) [`Agent`](/openai-agents-js/openai/agents/classes/agent/).[`getMcpTools`](/openai-agents-js/openai/agents/classes/agent/#getmcptools) *** ### getPrompt() [Section titled “getPrompt()”](#getprompt) ```ts getPrompt(runContext): Promise; ``` Returns the prompt template for the agent, if defined. If the agent has a function as its prompt, this function will be called with the runContext and the agent instance. #### Parameters [Section titled “Parameters”](#parameters-8) | Parameter | Type | | ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | `runContext` | [`RunContext`](/openai-agents-js/openai/agents/classes/runcontext/)<[`RealtimeContextData`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimecontextdata/)<`TContext`>> | #### Returns [Section titled “Returns”](#returns-9) `Promise`<`Prompt` | `undefined`> #### Inherited from [Section titled “Inherited from”](#inherited-from-24) [`Agent`](/openai-agents-js/openai/agents/classes/agent/).[`getPrompt`](/openai-agents-js/openai/agents/classes/agent/#getprompt) *** ### getSystemPrompt() [Section titled “getSystemPrompt()”](#getsystemprompt) ```ts getSystemPrompt(runContext): Promise; ``` Returns the system prompt for the agent. If the agent has a function as its instructions, this function will be called with the runContext and the agent instance. #### Parameters [Section titled “Parameters”](#parameters-9) | Parameter | Type | | ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | `runContext` | [`RunContext`](/openai-agents-js/openai/agents/classes/runcontext/)<[`RealtimeContextData`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimecontextdata/)<`TContext`>> | #### Returns [Section titled “Returns”](#returns-10) `Promise`<`string` | `undefined`> #### Inherited from [Section titled “Inherited from”](#inherited-from-25) [`Agent`](/openai-agents-js/openai/agents/classes/agent/).[`getSystemPrompt`](/openai-agents-js/openai/agents/classes/agent/#getsystemprompt) *** ### hasExplicitToolConfig() [Section titled “hasExplicitToolConfig()”](#hasexplicittoolconfig) ```ts hasExplicitToolConfig(): boolean; ``` #### Returns [Section titled “Returns”](#returns-11) `boolean` #### Inherited from [Section titled “Inherited from”](#inherited-from-26) [`Agent`](/openai-agents-js/openai/agents/classes/agent/).[`hasExplicitToolConfig`](/openai-agents-js/openai/agents/classes/agent/#hasexplicittoolconfig) *** ### off() [Section titled “off()”](#off) ```ts off(type, listener): EventEmitter; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-4) | Type Parameter | | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `K` *extends* keyof `AgentHookEvents`<[`RealtimeContextData`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimecontextdata/)<`TContext`>, `"text"`> | #### Parameters [Section titled “Parameters”](#parameters-10) | Parameter | Type | | ---------- | ------------------- | | `type` | `K` | | `listener` | (…`args`) => `void` | #### Returns [Section titled “Returns”](#returns-12) `EventEmitter`<`EventTypes`> #### Inherited from [Section titled “Inherited from”](#inherited-from-27) [`Agent`](/openai-agents-js/openai/agents/classes/agent/).[`off`](/openai-agents-js/openai/agents/classes/agent/#off) *** ### on() [Section titled “on()”](#on) ```ts on(type, listener): EventEmitter; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-5) | Type Parameter | | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `K` *extends* keyof `AgentHookEvents`<[`RealtimeContextData`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimecontextdata/)<`TContext`>, `"text"`> | #### Parameters [Section titled “Parameters”](#parameters-11) | Parameter | Type | | ---------- | ------------------- | | `type` | `K` | | `listener` | (…`args`) => `void` | #### Returns [Section titled “Returns”](#returns-13) `EventEmitter`<`EventTypes`> #### Inherited from [Section titled “Inherited from”](#inherited-from-28) [`Agent`](/openai-agents-js/openai/agents/classes/agent/).[`on`](/openai-agents-js/openai/agents/classes/agent/#on) *** ### once() [Section titled “once()”](#once) ```ts once(type, listener): EventEmitter; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-6) | Type Parameter | | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `K` *extends* keyof `AgentHookEvents`<[`RealtimeContextData`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimecontextdata/)<`TContext`>, `"text"`> | #### Parameters [Section titled “Parameters”](#parameters-12) | Parameter | Type | | ---------- | ------------------- | | `type` | `K` | | `listener` | (…`args`) => `void` | #### Returns [Section titled “Returns”](#returns-14) `EventEmitter`<`EventTypes`> #### Inherited from [Section titled “Inherited from”](#inherited-from-29) [`Agent`](/openai-agents-js/openai/agents/classes/agent/).[`once`](/openai-agents-js/openai/agents/classes/agent/#once) *** ### processFinalOutput() [Section titled “processFinalOutput()”](#processfinaloutput) ```ts processFinalOutput(output): string; ``` Processes the final output of the agent. #### Parameters [Section titled “Parameters”](#parameters-13) | Parameter | Type | Description | | --------- | -------- | ------------------------ | | `output` | `string` | The output of the agent. | #### Returns [Section titled “Returns”](#returns-15) `string` The parsed out. #### Inherited from [Section titled “Inherited from”](#inherited-from-30) [`Agent`](/openai-agents-js/openai/agents/classes/agent/).[`processFinalOutput`](/openai-agents-js/openai/agents/classes/agent/#processfinaloutput) *** ### toJSON() [Section titled “toJSON()”](#tojson) ```ts toJSON(): object; ``` Returns a JSON representation of the agent, which is serializable. #### Returns [Section titled “Returns”](#returns-16) `object` A JSON object containing the agent’s name. ##### name [Section titled “name”](#name-1) ```ts name: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-31) [`Agent`](/openai-agents-js/openai/agents/classes/agent/).[`toJSON`](/openai-agents-js/openai/agents/classes/agent/#tojson) *** ### create() [Section titled “create()”](#create) ```ts static create(config): Agent>; ``` Create an Agent with handoffs and automatically infer the union type for TOutput from the handoff agents’ output types. #### Type Parameters [Section titled “Type Parameters”](#type-parameters-7) | Type Parameter | Default type | | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------ | | `TOutput` *extends* [`AgentOutputType`](/openai-agents-js/openai/agents/type-aliases/agentoutputtype/)<`unknown`> | `"text"` | | `Handoffs` *extends* readonly ( \| [`Agent`](/openai-agents-js/openai/agents/classes/agent/)<`any`, `any`> \| [`Handoff`](/openai-agents-js/openai/agents/classes/handoff/)<`any`, `any`>)\[] | \[] | #### Parameters [Section titled “Parameters”](#parameters-14) | Parameter | Type | | --------- | ------------------------------------------------------------------------------------------------------------------------- | | `config` | [`AgentConfigWithHandoffs`](/openai-agents-js/openai/agents/type-aliases/agentconfigwithhandoffs/)<`TOutput`, `Handoffs`> | #### Returns [Section titled “Returns”](#returns-17) [`Agent`](/openai-agents-js/openai/agents/classes/agent/)<`unknown`, `TOutput` | `HandoffsOutputUnion`<`Handoffs`>> #### Inherited from [Section titled “Inherited from”](#inherited-from-32) [`Agent`](/openai-agents-js/openai/agents/classes/agent/).[`create`](/openai-agents-js/openai/agents/classes/agent/#create) # RealtimeSession A `RealtimeSession` is the cornerstone of building Voice Agents. It’s the equivalent of a Runner in text-based agents except that it automatically handles multiple turns by maintaining a connection with the underlying transport layer. The session handles managing the local history copy, executes tools, runs output guardrails, and facilitates handoffs. The actual audio handling and generation of model responses is handled by the underlying transport layer. By default if you are using a browser with WebRTC support, the session will automatically use the WebRTC version of the OpenAI Realtime API. On the server or if you pass `websocket` as the transport layer, the session will establish a connection using WebSockets. In the case of WebRTC, in the browser, the transport layer will also automatically configure the microphone and audio output to be used by the session. You can also create a transport layer instance yourself and pass it in to have more control over the configuration or even extend the existing ones. Check out the `TwilioRealtimeTransportLayer` for an example of how to create a custom transport layer. ## Example [Section titled “Example”](#example) ```ts const agent = new RealtimeAgent({ name: 'my-agent', instructions: 'You are a helpful assistant that can answer questions and help with tasks.', }) const session = new RealtimeSession(agent); session.connect({ apiKey: 'your-api-key', }); ``` ## Extends [Section titled “Extends”](#extends) * `EventEmitter`<[`RealtimeSessionEventTypes`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimesessioneventtypes/)<`TBaseContext`>> ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | ------------ | | `TBaseContext` | `unknown` | ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new RealtimeSession(initialAgent, options?): RealtimeSession; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | -------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `initialAgent` | \| [`RealtimeAgent`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/realtimeagent/)<`TBaseContext`> \| [`RealtimeAgent`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/realtimeagent/)<[`RealtimeContextData`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimecontextdata/)<`TBaseContext`>> | | `options?` | `Partial`<[`RealtimeSessionOptions`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimesessionoptions/)<`TBaseContext`>> | #### Returns [Section titled “Returns”](#returns) `RealtimeSession`<`TBaseContext`> #### Overrides [Section titled “Overrides”](#overrides) ```ts RuntimeEventEmitter>.constructor ``` ## Properties [Section titled “Properties”](#properties) ### initialAgent [Section titled “initialAgent”](#initialagent) ```ts readonly initialAgent: | RealtimeAgent | RealtimeAgent>; ``` *** ### options [Section titled “options”](#options) ```ts readonly options: Partial>; ``` *** ### captureRejections [Section titled “captureRejections”](#capturerejections) ```ts static captureRejections: boolean; ``` Value: [boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type) Change the default `captureRejections` option on all new `EventEmitter` objects. #### Since [Section titled “Since”](#since) v13.4.0, v12.16.0 #### Inherited from [Section titled “Inherited from”](#inherited-from) ```ts RuntimeEventEmitter.captureRejections ``` *** ### captureRejectionSymbol [Section titled “captureRejectionSymbol”](#capturerejectionsymbol) ```ts readonly static captureRejectionSymbol: typeof captureRejectionSymbol; ``` Value: `Symbol.for('nodejs.rejection')` See how to write a custom `rejection handler`. #### Since [Section titled “Since”](#since-1) v13.4.0, v12.16.0 #### Inherited from [Section titled “Inherited from”](#inherited-from-1) ```ts RuntimeEventEmitter.captureRejectionSymbol ``` *** ### defaultMaxListeners [Section titled “defaultMaxListeners”](#defaultmaxlisteners) ```ts static defaultMaxListeners: number; ``` By default, a maximum of `10` listeners can be registered for any single event. This limit can be changed for individual `EventEmitter` instances using the `emitter.setMaxListeners(n)` method. To change the default for *all*`EventEmitter` instances, the `events.defaultMaxListeners` property can be used. If this value is not a positive number, a `RangeError` is thrown. Take caution when setting the `events.defaultMaxListeners` because the change affects *all* `EventEmitter` instances, including those created before the change is made. However, calling `emitter.setMaxListeners(n)` still has precedence over `events.defaultMaxListeners`. This is not a hard limit. The `EventEmitter` instance will allow more listeners to be added but will output a trace warning to stderr indicating that a “possible EventEmitter memory leak” has been detected. For any single `EventEmitter`, the `emitter.getMaxListeners()` and `emitter.setMaxListeners()` methods can be used to temporarily avoid this warning: ```js import { EventEmitter } from 'node:events'; const emitter = new EventEmitter(); emitter.setMaxListeners(emitter.getMaxListeners() + 1); emitter.once('event', () => { // do stuff emitter.setMaxListeners(Math.max(emitter.getMaxListeners() - 1, 0)); }); ``` The `--trace-warnings` command-line flag can be used to display the stack trace for such warnings. The emitted warning can be inspected with `process.on('warning')` and will have the additional `emitter`, `type`, and `count` properties, referring to the event emitter instance, the event’s name and the number of attached listeners, respectively. Its `name` property is set to `'MaxListenersExceededWarning'`. #### Since [Section titled “Since”](#since-2) v0.11.2 #### Inherited from [Section titled “Inherited from”](#inherited-from-2) ```ts RuntimeEventEmitter.defaultMaxListeners ``` *** ### errorMonitor [Section titled “errorMonitor”](#errormonitor) ```ts readonly static errorMonitor: typeof errorMonitor; ``` This symbol shall be used to install a listener for only monitoring `'error'` events. Listeners installed using this symbol are called before the regular `'error'` listeners are called. Installing a listener using this symbol does not change the behavior once an `'error'` event is emitted. Therefore, the process will still crash if no regular `'error'` listener is installed. #### Since [Section titled “Since”](#since-3) v13.6.0, v12.17.0 #### Inherited from [Section titled “Inherited from”](#inherited-from-3) ```ts RuntimeEventEmitter.errorMonitor ``` ## Accessors [Section titled “Accessors”](#accessors) ### availableMcpTools [Section titled “availableMcpTools”](#availablemcptools) #### Get Signature [Section titled “Get Signature”](#get-signature) ```ts get availableMcpTools(): RealtimeMcpToolInfo[]; ``` ##### Returns [Section titled “Returns”](#returns-1) `RealtimeMcpToolInfo`\[] *** ### context [Section titled “context”](#context) #### Get Signature [Section titled “Get Signature”](#get-signature-1) ```ts get context(): RunContext>; ``` The current context of the session. ##### Returns [Section titled “Returns”](#returns-2) [`RunContext`](/openai-agents-js/openai/agents/classes/runcontext/)<[`RealtimeContextData`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimecontextdata/)<`TBaseContext`>> *** ### currentAgent [Section titled “currentAgent”](#currentagent) #### Get Signature [Section titled “Get Signature”](#get-signature-2) ```ts get currentAgent(): | RealtimeAgent | RealtimeAgent>; ``` The current agent in the session. ##### Returns [Section titled “Returns”](#returns-3) \| [`RealtimeAgent`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/realtimeagent/)<`TBaseContext`> | [`RealtimeAgent`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/realtimeagent/)<[`RealtimeContextData`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimecontextdata/)<`TBaseContext`>> *** ### history [Section titled “history”](#history) #### Get Signature [Section titled “Get Signature”](#get-signature-3) ```ts get history(): RealtimeItem[]; ``` The history of the session. ##### Returns [Section titled “Returns”](#returns-4) [`RealtimeItem`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimeitem/)\[] *** ### muted [Section titled “muted”](#muted) #### Get Signature [Section titled “Get Signature”](#get-signature-4) ```ts get muted(): boolean | null; ``` Whether the session is muted. Might be `null` if the underlying transport layer does not support muting. ##### Returns [Section titled “Returns”](#returns-5) `boolean` | `null` *** ### transport [Section titled “transport”](#transport) #### Get Signature [Section titled “Get Signature”](#get-signature-5) ```ts get transport(): RealtimeTransportLayer; ``` The transport layer used by the session. ##### Returns [Section titled “Returns”](#returns-6) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/openai/namespaces/realtime/interfaces/realtimetransportlayer/) *** ### usage [Section titled “usage”](#usage) #### Get Signature [Section titled “Get Signature”](#get-signature-6) ```ts get usage(): Usage; ``` The current usage of the session. ##### Returns [Section titled “Returns”](#returns-7) [`Usage`](/openai-agents-js/openai/agents/classes/usage/) ## Methods [Section titled “Methods”](#methods) ### \[captureRejectionSymbol]\()? [Section titled “\[captureRejectionSymbol\]()?”](#capturerejectionsymbol-1) ```ts optional [captureRejectionSymbol]( error, event, ... args): void; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-1) | Type Parameter | | -------------- | | `K` | #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `error` | `Error` | | `event` | `K` \| keyof RealtimeSessionEventTypes\ | | …`args` | `K` *extends* keyof [`RealtimeSessionEventTypes`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimesessioneventtypes/)<`TBaseContext`> ? [`RealtimeSessionEventTypes`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimesessioneventtypes/)<`TBaseContext`>\[`K`] : `never` | #### Returns [Section titled “Returns”](#returns-8) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-4) ```ts RuntimeEventEmitter.[captureRejectionSymbol] ``` *** ### addImage() [Section titled “addImage()”](#addimage) ```ts addImage(image, __namedParameters?): void; ``` Add image to the session #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | Description | | ------------------------------------ | ---------------------------------- | ----------------- | | `image` | `string` | The image to add. | | `__namedParameters?` | { `triggerResponse?`: `boolean`; } | ‐ | | `__namedParameters.triggerResponse?` | `boolean` | ‐ | #### Returns [Section titled “Returns”](#returns-9) `void` *** ### addListener() [Section titled “addListener()”](#addlistener) ```ts addListener(eventName, listener): this; ``` Alias for `emitter.on(eventName, listener)`. #### Type Parameters [Section titled “Type Parameters”](#type-parameters-2) | Type Parameter | | -------------- | | `K` | #### Parameters [Section titled “Parameters”](#parameters-3) | Parameter | Type | | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | `eventName` | keyof RealtimeSessionEventTypes\ \| `K` | | `listener` | `K` *extends* keyof [`RealtimeSessionEventTypes`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimesessioneventtypes/)<`TBaseContext`> ? [`RealtimeSessionEventTypes`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimesessioneventtypes/)<`TBaseContext`>\[`K`] *extends* `unknown`\[] ? (…`args`) => `void` : `never` : `never` | #### Returns [Section titled “Returns”](#returns-10) `this` #### Since [Section titled “Since”](#since-4) v0.1.26 #### Inherited from [Section titled “Inherited from”](#inherited-from-5) ```ts RuntimeEventEmitter.addListener ``` *** ### approve() [Section titled “approve()”](#approve) ```ts approve(approvalItem, options?): Promise; ``` Approve a tool call. This will also trigger the tool call to the agent. #### Parameters [Section titled “Parameters”](#parameters-4) | Parameter | Type | Description | | ------------------------ | ------------------------------------------------------------------------------------- | ---------------------------------------- | | `approvalItem` | [`RunToolApprovalItem`](/openai-agents-js/openai/agents/classes/runtoolapprovalitem/) | The approval item to approve. | | `options?` | { `alwaysApprove?`: `boolean`; } | Additional options. | | `options.alwaysApprove?` | `boolean` | Whether to always approve the tool call. | #### Returns [Section titled “Returns”](#returns-11) `Promise`<`void`> *** ### close() [Section titled “close()”](#close) ```ts close(): void; ``` Disconnect from the session. #### Returns [Section titled “Returns”](#returns-12) `void` *** ### connect() [Section titled “connect()”](#connect) ```ts connect(options): Promise; ``` Connect to the session. This will establish the connection to the underlying transport layer and start the session. After connecting, the session will also emit a `history_updated` event with an empty history. #### Parameters [Section titled “Parameters”](#parameters-5) | Parameter | Type | Description | | --------- | ----------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------- | | `options` | [`RealtimeSessionConnectOptions`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimesessionconnectoptions/) | The options for the connection. | #### Returns [Section titled “Returns”](#returns-13) `Promise`<`void`> *** ### emit() [Section titled “emit()”](#emit) ```ts emit(eventName, ...args): boolean; ``` Synchronously calls each of the listeners registered for the event named `eventName`, in the order they were registered, passing the supplied arguments to each. Returns `true` if the event had listeners, `false` otherwise. ```js import { EventEmitter } from 'node:events'; const myEmitter = new EventEmitter(); // First listener myEmitter.on('event', function firstListener() { console.log('Helloooo! first listener'); }); // Second listener myEmitter.on('event', function secondListener(arg1, arg2) { console.log(`event with parameters ${arg1}, ${arg2} in second listener`); }); // Third listener myEmitter.on('event', function thirdListener(...args) { const parameters = args.join(', '); console.log(`event with parameters ${parameters} in third listener`); }); console.log(myEmitter.listeners('event')); myEmitter.emit('event', 1, 2, 3, 4, 5); // Prints: // [ // [Function: firstListener], // [Function: secondListener], // [Function: thirdListener] // ] // Helloooo! first listener // event with parameters 1, 2 in second listener // event with parameters 1, 2, 3, 4, 5 in third listener ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-3) | Type Parameter | | -------------- | | `K` | #### Parameters [Section titled “Parameters”](#parameters-6) | Parameter | Type | | ----------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `eventName` | keyof RealtimeSessionEventTypes\ \| `K` | | …`args` | `K` *extends* keyof [`RealtimeSessionEventTypes`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimesessioneventtypes/)<`TBaseContext`> ? [`RealtimeSessionEventTypes`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimesessioneventtypes/)<`TBaseContext`>\[`K`] : `never` | #### Returns [Section titled “Returns”](#returns-14) `boolean` #### Since [Section titled “Since”](#since-5) v0.1.26 #### Inherited from [Section titled “Inherited from”](#inherited-from-6) ```ts RuntimeEventEmitter.emit ``` *** ### eventNames() [Section titled “eventNames()”](#eventnames) ```ts eventNames(): ( | "error" | "agent_start" | "agent_end" | "agent_handoff" | "agent_tool_start" | "agent_tool_end" | "tool_approval_requested" | "audio" | "transport_event" | "audio_start" | "audio_stopped" | "audio_interrupted" | "guardrail_tripped" | "history_updated" | "history_added" | "mcp_tool_call_completed" | "mcp_tools_changed")[]; ``` Returns an array listing the events for which the emitter has registered listeners. The values in the array are strings or `Symbol`s. ```js import { EventEmitter } from 'node:events'; const myEE = new EventEmitter(); myEE.on('foo', () => {}); myEE.on('bar', () => {}); const sym = Symbol('symbol'); myEE.on(sym, () => {}); console.log(myEE.eventNames()); // Prints: [ 'foo', 'bar', Symbol(symbol) ] ``` #### Returns [Section titled “Returns”](#returns-15) ( | `"error"` | `"agent_start"` | `"agent_end"` | `"agent_handoff"` | `"agent_tool_start"` | `"agent_tool_end"` | `"tool_approval_requested"` | `"audio"` | `"transport_event"` | `"audio_start"` | `"audio_stopped"` | `"audio_interrupted"` | `"guardrail_tripped"` | `"history_updated"` | `"history_added"` | `"mcp_tool_call_completed"` | `"mcp_tools_changed"`)\[] #### Since [Section titled “Since”](#since-6) v6.0.0 #### Inherited from [Section titled “Inherited from”](#inherited-from-7) ```ts RuntimeEventEmitter.eventNames ``` *** ### getInitialSessionConfig() [Section titled “getInitialSessionConfig()”](#getinitialsessionconfig) ```ts getInitialSessionConfig(overrides?): Promise>; ``` Compute the initial session config that the current session will use when connecting. This mirrors the configuration payload we send during `connect`, including dynamic values such as the upstream agent instructions, tool definitions, and prompt content generated at runtime. Keeping this helper exposed allows transports or orchestration layers to precompute a CallAccept-compatible payload without opening a socket. #### Parameters [Section titled “Parameters”](#parameters-7) | Parameter | Type | Description | | ------------ | ------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------ | | `overrides?` | `Partial`<[`RealtimeSessionConfig`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimesessionconfig/)> | Additional config overrides applied on top of the session options. | #### Returns [Section titled “Returns”](#returns-16) `Promise`<`Partial`<[`RealtimeSessionConfig`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimesessionconfig/)>> *** ### getMaxListeners() [Section titled “getMaxListeners()”](#getmaxlisteners) ```ts getMaxListeners(): number; ``` Returns the current max listener value for the `EventEmitter` which is either set by `emitter.setMaxListeners(n)` or defaults to [EventEmitter.defaultMaxListeners](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/realtimesession/#defaultmaxlisteners). #### Returns [Section titled “Returns”](#returns-17) `number` #### Since [Section titled “Since”](#since-7) v1.0.0 #### Inherited from [Section titled “Inherited from”](#inherited-from-8) ```ts RuntimeEventEmitter.getMaxListeners ``` *** ### interrupt() [Section titled “interrupt()”](#interrupt) ```ts interrupt(): void; ``` Interrupt the session artificially for example if you want to build a “stop talking” button. #### Returns [Section titled “Returns”](#returns-18) `void` *** ### listenerCount() [Section titled “listenerCount()”](#listenercount) ```ts listenerCount(eventName, listener?): number; ``` Returns the number of listeners listening for the event named `eventName`. If `listener` is provided, it will return how many times the listener is found in the list of the listeners of the event. #### Type Parameters [Section titled “Type Parameters”](#type-parameters-4) | Type Parameter | | -------------- | | `K` | #### Parameters [Section titled “Parameters”](#parameters-8) | Parameter | Type | Description | | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------- | | `eventName` | keyof RealtimeSessionEventTypes\ \| `K` | The name of the event being listened for | | `listener?` | `K` *extends* keyof [`RealtimeSessionEventTypes`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimesessioneventtypes/)<`TBaseContext`> ? [`RealtimeSessionEventTypes`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimesessioneventtypes/)<`TBaseContext`>\[`K`] *extends* `unknown`\[] ? (…`args`) => `void` : `never` : `never` | The event handler function | #### Returns [Section titled “Returns”](#returns-19) `number` #### Since [Section titled “Since”](#since-8) v3.2.0 #### Inherited from [Section titled “Inherited from”](#inherited-from-9) ```ts RuntimeEventEmitter.listenerCount ``` *** ### listeners() [Section titled “listeners()”](#listeners) ```ts listeners(eventName): K extends keyof RealtimeSessionEventTypes ? RealtimeSessionEventTypes[K] extends unknown[] ? (...args) => void : never : never[]; ``` Returns a copy of the array of listeners for the event named `eventName`. ```js server.on('connection', (stream) => { console.log('someone connected!'); }); console.log(util.inspect(server.listeners('connection'))); // Prints: [ [Function] ] ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-5) | Type Parameter | | -------------- | | `K` | #### Parameters [Section titled “Parameters”](#parameters-9) | Parameter | Type | | ----------- | ----------------------------------------------------- | | `eventName` | keyof RealtimeSessionEventTypes\ \| `K` | #### Returns [Section titled “Returns”](#returns-20) `K` *extends* keyof [`RealtimeSessionEventTypes`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimesessioneventtypes/)<`TBaseContext`> ? [`RealtimeSessionEventTypes`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimesessioneventtypes/)<`TBaseContext`>\[`K`] *extends* `unknown`\[] ? (…`args`) => `void` : `never` : `never`\[] #### Since [Section titled “Since”](#since-9) v0.1.26 #### Inherited from [Section titled “Inherited from”](#inherited-from-10) ```ts RuntimeEventEmitter.listeners ``` *** ### mute() [Section titled “mute()”](#mute) ```ts mute(muted): void; ``` Mute the session. #### Parameters [Section titled “Parameters”](#parameters-10) | Parameter | Type | Description | | --------- | --------- | ---------------------------- | | `muted` | `boolean` | Whether to mute the session. | #### Returns [Section titled “Returns”](#returns-21) `void` *** ### off() [Section titled “off()”](#off) ```ts off(eventName, listener): this; ``` Alias for `emitter.removeListener()`. #### Type Parameters [Section titled “Type Parameters”](#type-parameters-6) | Type Parameter | | -------------- | | `K` | #### Parameters [Section titled “Parameters”](#parameters-11) | Parameter | Type | | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | `eventName` | keyof RealtimeSessionEventTypes\ \| `K` | | `listener` | `K` *extends* keyof [`RealtimeSessionEventTypes`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimesessioneventtypes/)<`TBaseContext`> ? [`RealtimeSessionEventTypes`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimesessioneventtypes/)<`TBaseContext`>\[`K`] *extends* `unknown`\[] ? (…`args`) => `void` : `never` : `never` | #### Returns [Section titled “Returns”](#returns-22) `this` #### Since [Section titled “Since”](#since-10) v10.0.0 #### Inherited from [Section titled “Inherited from”](#inherited-from-11) ```ts RuntimeEventEmitter.off ``` *** ### on() [Section titled “on()”](#on) ```ts on(eventName, listener): this; ``` Adds the `listener` function to the end of the listeners array for the event named `eventName`. No checks are made to see if the `listener` has already been added. Multiple calls passing the same combination of `eventName` and `listener` will result in the `listener` being added, and called, multiple times. ```js server.on('connection', (stream) => { console.log('someone connected!'); }); ``` Returns a reference to the `EventEmitter`, so that calls can be chained. By default, event listeners are invoked in the order they are added. The `emitter.prependListener()` method can be used as an alternative to add the event listener to the beginning of the listeners array. ```js import { EventEmitter } from 'node:events'; const myEE = new EventEmitter(); myEE.on('foo', () => console.log('a')); myEE.prependListener('foo', () => console.log('b')); myEE.emit('foo'); // Prints: // b // a ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-7) | Type Parameter | | -------------- | | `K` | #### Parameters [Section titled “Parameters”](#parameters-12) | Parameter | Type | Description | | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------- | | `eventName` | keyof RealtimeSessionEventTypes\ \| `K` | The name of the event. | | `listener` | `K` *extends* keyof [`RealtimeSessionEventTypes`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimesessioneventtypes/)<`TBaseContext`> ? [`RealtimeSessionEventTypes`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimesessioneventtypes/)<`TBaseContext`>\[`K`] *extends* `unknown`\[] ? (…`args`) => `void` : `never` : `never` | The callback function | #### Returns [Section titled “Returns”](#returns-23) `this` #### Since [Section titled “Since”](#since-11) v0.1.101 #### Inherited from [Section titled “Inherited from”](#inherited-from-12) ```ts RuntimeEventEmitter.on ``` *** ### once() [Section titled “once()”](#once) ```ts once(eventName, listener): this; ``` Adds a **one-time** `listener` function for the event named `eventName`. The next time `eventName` is triggered, this listener is removed and then invoked. ```js server.once('connection', (stream) => { console.log('Ah, we have our first user!'); }); ``` Returns a reference to the `EventEmitter`, so that calls can be chained. By default, event listeners are invoked in the order they are added. The `emitter.prependOnceListener()` method can be used as an alternative to add the event listener to the beginning of the listeners array. ```js import { EventEmitter } from 'node:events'; const myEE = new EventEmitter(); myEE.once('foo', () => console.log('a')); myEE.prependOnceListener('foo', () => console.log('b')); myEE.emit('foo'); // Prints: // b // a ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-8) | Type Parameter | | -------------- | | `K` | #### Parameters [Section titled “Parameters”](#parameters-13) | Parameter | Type | Description | | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------- | | `eventName` | keyof RealtimeSessionEventTypes\ \| `K` | The name of the event. | | `listener` | `K` *extends* keyof [`RealtimeSessionEventTypes`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimesessioneventtypes/)<`TBaseContext`> ? [`RealtimeSessionEventTypes`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimesessioneventtypes/)<`TBaseContext`>\[`K`] *extends* `unknown`\[] ? (…`args`) => `void` : `never` : `never` | The callback function | #### Returns [Section titled “Returns”](#returns-24) `this` #### Since [Section titled “Since”](#since-12) v0.3.0 #### Inherited from [Section titled “Inherited from”](#inherited-from-13) ```ts RuntimeEventEmitter.once ``` *** ### prependListener() [Section titled “prependListener()”](#prependlistener) ```ts prependListener(eventName, listener): this; ``` Adds the `listener` function to the *beginning* of the listeners array for the event named `eventName`. No checks are made to see if the `listener` has already been added. Multiple calls passing the same combination of `eventName` and `listener` will result in the `listener` being added, and called, multiple times. ```js server.prependListener('connection', (stream) => { console.log('someone connected!'); }); ``` Returns a reference to the `EventEmitter`, so that calls can be chained. #### Type Parameters [Section titled “Type Parameters”](#type-parameters-9) | Type Parameter | | -------------- | | `K` | #### Parameters [Section titled “Parameters”](#parameters-14) | Parameter | Type | Description | | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------- | | `eventName` | keyof RealtimeSessionEventTypes\ \| `K` | The name of the event. | | `listener` | `K` *extends* keyof [`RealtimeSessionEventTypes`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimesessioneventtypes/)<`TBaseContext`> ? [`RealtimeSessionEventTypes`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimesessioneventtypes/)<`TBaseContext`>\[`K`] *extends* `unknown`\[] ? (…`args`) => `void` : `never` : `never` | The callback function | #### Returns [Section titled “Returns”](#returns-25) `this` #### Since [Section titled “Since”](#since-13) v6.0.0 #### Inherited from [Section titled “Inherited from”](#inherited-from-14) ```ts RuntimeEventEmitter.prependListener ``` *** ### prependOnceListener() [Section titled “prependOnceListener()”](#prependoncelistener) ```ts prependOnceListener(eventName, listener): this; ``` Adds a **one-time**`listener` function for the event named `eventName` to the *beginning* of the listeners array. The next time `eventName` is triggered, this listener is removed, and then invoked. ```js server.prependOnceListener('connection', (stream) => { console.log('Ah, we have our first user!'); }); ``` Returns a reference to the `EventEmitter`, so that calls can be chained. #### Type Parameters [Section titled “Type Parameters”](#type-parameters-10) | Type Parameter | | -------------- | | `K` | #### Parameters [Section titled “Parameters”](#parameters-15) | Parameter | Type | Description | | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------- | | `eventName` | keyof RealtimeSessionEventTypes\ \| `K` | The name of the event. | | `listener` | `K` *extends* keyof [`RealtimeSessionEventTypes`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimesessioneventtypes/)<`TBaseContext`> ? [`RealtimeSessionEventTypes`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimesessioneventtypes/)<`TBaseContext`>\[`K`] *extends* `unknown`\[] ? (…`args`) => `void` : `never` : `never` | The callback function | #### Returns [Section titled “Returns”](#returns-26) `this` #### Since [Section titled “Since”](#since-14) v6.0.0 #### Inherited from [Section titled “Inherited from”](#inherited-from-15) ```ts RuntimeEventEmitter.prependOnceListener ``` *** ### rawListeners() [Section titled “rawListeners()”](#rawlisteners) ```ts rawListeners(eventName): K extends keyof RealtimeSessionEventTypes ? RealtimeSessionEventTypes[K] extends unknown[] ? (...args) => void : never : never[]; ``` Returns a copy of the array of listeners for the event named `eventName`, including any wrappers (such as those created by `.once()`). ```js import { EventEmitter } from 'node:events'; const emitter = new EventEmitter(); emitter.once('log', () => console.log('log once')); // Returns a new Array with a function `onceWrapper` which has a property // `listener` which contains the original listener bound above const listeners = emitter.rawListeners('log'); const logFnWrapper = listeners[0]; // Logs "log once" to the console and does not unbind the `once` event logFnWrapper.listener(); // Logs "log once" to the console and removes the listener logFnWrapper(); emitter.on('log', () => console.log('log persistently')); // Will return a new Array with a single function bound by `.on()` above const newListeners = emitter.rawListeners('log'); // Logs "log persistently" twice newListeners[0](); emitter.emit('log'); ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-11) | Type Parameter | | -------------- | | `K` | #### Parameters [Section titled “Parameters”](#parameters-16) | Parameter | Type | | ----------- | ----------------------------------------------------- | | `eventName` | keyof RealtimeSessionEventTypes\ \| `K` | #### Returns [Section titled “Returns”](#returns-27) `K` *extends* keyof [`RealtimeSessionEventTypes`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimesessioneventtypes/)<`TBaseContext`> ? [`RealtimeSessionEventTypes`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimesessioneventtypes/)<`TBaseContext`>\[`K`] *extends* `unknown`\[] ? (…`args`) => `void` : `never` : `never`\[] #### Since [Section titled “Since”](#since-15) v9.4.0 #### Inherited from [Section titled “Inherited from”](#inherited-from-16) ```ts RuntimeEventEmitter.rawListeners ``` *** ### reject() [Section titled “reject()”](#reject) ```ts reject(approvalItem, options?): Promise; ``` Reject a tool call. This will also trigger the tool call to the agent. #### Parameters [Section titled “Parameters”](#parameters-17) | Parameter | Type | Description | | ----------------------- | ------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------- | | `approvalItem` | [`RunToolApprovalItem`](/openai-agents-js/openai/agents/classes/runtoolapprovalitem/) | The approval item to reject. | | `options?` | { `alwaysReject?`: `boolean`; `message?`: `string`; } | Additional options. | | `options.alwaysReject?` | `boolean` | Whether to always reject the tool call. | | `options.message?` | `string` | The rejection text sent to the model. If not provided, `toolErrorFormatter` (if configured) or the SDK default is used. | #### Returns [Section titled “Returns”](#returns-28) `Promise`<`void`> *** ### removeAllListeners() [Section titled “removeAllListeners()”](#removealllisteners) ```ts removeAllListeners(eventName?): this; ``` Removes all listeners, or those of the specified `eventName`. It is bad practice to remove listeners added elsewhere in the code, particularly when the `EventEmitter` instance was created by some other component or module (e.g. sockets or file streams). Returns a reference to the `EventEmitter`, so that calls can be chained. #### Parameters [Section titled “Parameters”](#parameters-18) | Parameter | Type | | ------------ | --------- | | `eventName?` | `unknown` | #### Returns [Section titled “Returns”](#returns-29) `this` #### Since [Section titled “Since”](#since-16) v0.1.26 #### Inherited from [Section titled “Inherited from”](#inherited-from-17) ```ts RuntimeEventEmitter.removeAllListeners ``` *** ### removeListener() [Section titled “removeListener()”](#removelistener) ```ts removeListener(eventName, listener): this; ``` Removes the specified `listener` from the listener array for the event named `eventName`. ```js const callback = (stream) => { console.log('someone connected!'); }; server.on('connection', callback); // ... server.removeListener('connection', callback); ``` `removeListener()` will remove, at most, one instance of a listener from the listener array. If any single listener has been added multiple times to the listener array for the specified `eventName`, then `removeListener()` must be called multiple times to remove each instance. Once an event is emitted, all listeners attached to it at the time of emitting are called in order. This implies that any `removeListener()` or `removeAllListeners()` calls *after* emitting and *before* the last listener finishes execution will not remove them from`emit()` in progress. Subsequent events behave as expected. ```js import { EventEmitter } from 'node:events'; class MyEmitter extends EventEmitter {} const myEmitter = new MyEmitter(); const callbackA = () => { console.log('A'); myEmitter.removeListener('event', callbackB); }; const callbackB = () => { console.log('B'); }; myEmitter.on('event', callbackA); myEmitter.on('event', callbackB); // callbackA removes listener callbackB but it will still be called. // Internal listener array at time of emit [callbackA, callbackB] myEmitter.emit('event'); // Prints: // A // B // callbackB is now removed. // Internal listener array [callbackA] myEmitter.emit('event'); // Prints: // A ``` Because listeners are managed using an internal array, calling this will change the position indices of any listener registered *after* the listener being removed. This will not impact the order in which listeners are called, but it means that any copies of the listener array as returned by the `emitter.listeners()` method will need to be recreated. When a single function has been added as a handler multiple times for a single event (as in the example below), `removeListener()` will remove the most recently added instance. In the example the `once('ping')` listener is removed: ```js import { EventEmitter } from 'node:events'; const ee = new EventEmitter(); function pong() { console.log('pong'); } ee.on('ping', pong); ee.once('ping', pong); ee.removeListener('ping', pong); ee.emit('ping'); ee.emit('ping'); ``` Returns a reference to the `EventEmitter`, so that calls can be chained. #### Type Parameters [Section titled “Type Parameters”](#type-parameters-12) | Type Parameter | | -------------- | | `K` | #### Parameters [Section titled “Parameters”](#parameters-19) | Parameter | Type | | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | `eventName` | keyof RealtimeSessionEventTypes\ \| `K` | | `listener` | `K` *extends* keyof [`RealtimeSessionEventTypes`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimesessioneventtypes/)<`TBaseContext`> ? [`RealtimeSessionEventTypes`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimesessioneventtypes/)<`TBaseContext`>\[`K`] *extends* `unknown`\[] ? (…`args`) => `void` : `never` : `never` | #### Returns [Section titled “Returns”](#returns-30) `this` #### Since [Section titled “Since”](#since-17) v0.1.26 #### Inherited from [Section titled “Inherited from”](#inherited-from-18) ```ts RuntimeEventEmitter.removeListener ``` *** ### sendAudio() [Section titled “sendAudio()”](#sendaudio) ```ts sendAudio(audio, options?): void; ``` Send audio to the session. #### Parameters [Section titled “Parameters”](#parameters-20) | Parameter | Type | Description | | ----------------- | ------------------------- | ------------------------------------------- | | `audio` | `ArrayBuffer` | The audio to send. | | `options?` | { `commit?`: `boolean`; } | Additional options. | | `options.commit?` | `boolean` | Whether to finish the turn with this audio. | #### Returns [Section titled “Returns”](#returns-31) `void` *** ### sendMessage() [Section titled “sendMessage()”](#sendmessage) ```ts sendMessage(message, otherEventData?): void; ``` Send a message to the session. #### Parameters [Section titled “Parameters”](#parameters-21) | Parameter | Type | Description | | ----------------- | ------------------------- | ------------------------------ | | `message` | `RealtimeUserInput` | The message to send. | | `otherEventData?` | `Record`<`string`, `any`> | Additional event data to send. | #### Returns [Section titled “Returns”](#returns-32) `void` *** ### setMaxListeners() [Section titled “setMaxListeners()”](#setmaxlisteners) ```ts setMaxListeners(n): this; ``` By default `EventEmitter`s will print a warning if more than `10` listeners are added for a particular event. This is a useful default that helps finding memory leaks. The `emitter.setMaxListeners()` method allows the limit to be modified for this specific `EventEmitter` instance. The value can be set to `Infinity` (or `0`) to indicate an unlimited number of listeners. Returns a reference to the `EventEmitter`, so that calls can be chained. #### Parameters [Section titled “Parameters”](#parameters-22) | Parameter | Type | | --------- | -------- | | `n` | `number` | #### Returns [Section titled “Returns”](#returns-33) `this` #### Since [Section titled “Since”](#since-18) v0.3.5 #### Inherited from [Section titled “Inherited from”](#inherited-from-19) ```ts RuntimeEventEmitter.setMaxListeners ``` *** ### updateAgent() [Section titled “updateAgent()”](#updateagent) ```ts updateAgent(newAgent): Promise>; ``` #### Parameters [Section titled “Parameters”](#parameters-23) | Parameter | Type | | ---------- | -------------------------------------------------------------------------------------------------------------------- | | `newAgent` | [`RealtimeAgent`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/realtimeagent/)<`TBaseContext`> | #### Returns [Section titled “Returns”](#returns-34) `Promise`<[`RealtimeAgent`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/realtimeagent/)<`TBaseContext`>> *** ### updateHistory() [Section titled “updateHistory()”](#updatehistory) ```ts updateHistory(newHistory): void; ``` Update the history of the session. #### Parameters [Section titled “Parameters”](#parameters-24) | Parameter | Type | Description | | ------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------- | | `newHistory` | \| [`RealtimeItem`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimeitem/)\[] \| ((`history`) => [`RealtimeItem`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimeitem/)\[]) | The new history to set. | #### Returns [Section titled “Returns”](#returns-35) `void` *** ### addAbortListener() [Section titled “addAbortListener()”](#addabortlistener) ```ts static addAbortListener(signal, resource): Disposable; ``` Listens once to the `abort` event on the provided `signal`. Listening to the `abort` event on abort signals is unsafe and may lead to resource leaks since another third party with the signal can call `e.stopImmediatePropagation()`. Unfortunately Node.js cannot change this since it would violate the web standard. Additionally, the original API makes it easy to forget to remove listeners. This API allows safely using `AbortSignal`s in Node.js APIs by solving these two issues by listening to the event such that `stopImmediatePropagation` does not prevent the listener from running. Returns a disposable so that it may be unsubscribed from more easily. ```js import { addAbortListener } from 'node:events'; function example(signal) { let disposable; try { signal.addEventListener('abort', (e) => e.stopImmediatePropagation()); disposable = addAbortListener(signal, (e) => { // Do something when signal is aborted. }); } finally { disposable?.[Symbol.dispose](); } } ``` #### Parameters [Section titled “Parameters”](#parameters-25) | Parameter | Type | | ---------- | ------------------- | | `signal` | `AbortSignal` | | `resource` | (`event`) => `void` | #### Returns [Section titled “Returns”](#returns-36) `Disposable` Disposable that removes the `abort` listener. #### Since [Section titled “Since”](#since-19) v20.5.0 #### Inherited from [Section titled “Inherited from”](#inherited-from-20) ```ts RuntimeEventEmitter.addAbortListener ``` *** ### computeInitialSessionConfig() [Section titled “computeInitialSessionConfig()”](#computeinitialsessionconfig) ```ts static computeInitialSessionConfig( agent, options?, overrides?): Promise>; ``` Convenience helper to compute the initial session config without manually instantiating and connecting a session. This is primarily useful for integrations that must provide the session configuration to a third party (for example the SIP `calls.accept` endpoint) before the actual realtime session is attached. The helper instantiates a throwaway session so all agent-driven dynamic fields resolve in exactly the same way as the live session path. #### Type Parameters [Section titled “Type Parameters”](#type-parameters-13) | Type Parameter | Default type | | -------------- | ------------ | | `TBaseContext` | `unknown` | #### Parameters [Section titled “Parameters”](#parameters-26) | Parameter | Type | Description | | ------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------- | | `agent` | \| [`RealtimeAgent`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/realtimeagent/)<`TBaseContext`> \| [`RealtimeAgent`](/openai-agents-js/openai/agents/openai/namespaces/realtime/classes/realtimeagent/)<[`RealtimeContextData`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimecontextdata/)<`TBaseContext`>> | The starting agent for the session. | | `options?` | `Partial`<[`RealtimeSessionOptions`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimesessionoptions/)<`TBaseContext`>> | Session options used to seed the config calculation. | | `overrides?` | `Partial`<[`RealtimeSessionConfig`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimesessionconfig/)> | Additional config overrides applied on top of the provided options. | #### Returns [Section titled “Returns”](#returns-37) `Promise`<`Partial`<[`RealtimeSessionConfig`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimesessionconfig/)>> *** ### getEventListeners() [Section titled “getEventListeners()”](#geteventlisteners) ```ts static getEventListeners(emitter, name): Function[]; ``` Returns a copy of the array of listeners for the event named `eventName`. For `EventEmitter`s this behaves exactly the same as calling `.listeners` on the emitter. For `EventTarget`s this is the only way to get the event listeners for the event target. This is useful for debugging and diagnostic purposes. ```js import { getEventListeners, EventEmitter } from 'node:events'; { const ee = new EventEmitter(); const listener = () => console.log('Events are fun'); ee.on('foo', listener); console.log(getEventListeners(ee, 'foo')); // [ [Function: listener] ] } { const et = new EventTarget(); const listener = () => console.log('Events are fun'); et.addEventListener('foo', listener); console.log(getEventListeners(et, 'foo')); // [ [Function: listener] ] } ``` #### Parameters [Section titled “Parameters”](#parameters-27) | Parameter | Type | | --------- | -------------------------------------------------- | | `emitter` | `EventTarget` \| `EventEmitter`<`DefaultEventMap`> | | `name` | `string` \| `symbol` | #### Returns [Section titled “Returns”](#returns-38) `Function`\[] #### Since [Section titled “Since”](#since-20) v15.2.0, v14.17.0 #### Inherited from [Section titled “Inherited from”](#inherited-from-21) ```ts RuntimeEventEmitter.getEventListeners ``` *** ### getMaxListeners() [Section titled “getMaxListeners()”](#getmaxlisteners-1) ```ts static getMaxListeners(emitter): number; ``` Returns the currently set max amount of listeners. For `EventEmitter`s this behaves exactly the same as calling `.getMaxListeners` on the emitter. For `EventTarget`s this is the only way to get the max event listeners for the event target. If the number of event handlers on a single EventTarget exceeds the max set, the EventTarget will print a warning. ```js import { getMaxListeners, setMaxListeners, EventEmitter } from 'node:events'; { const ee = new EventEmitter(); console.log(getMaxListeners(ee)); // 10 setMaxListeners(11, ee); console.log(getMaxListeners(ee)); // 11 } { const et = new EventTarget(); console.log(getMaxListeners(et)); // 10 setMaxListeners(11, et); console.log(getMaxListeners(et)); // 11 } ``` #### Parameters [Section titled “Parameters”](#parameters-28) | Parameter | Type | | --------- | -------------------------------------------------- | | `emitter` | `EventTarget` \| `EventEmitter`<`DefaultEventMap`> | #### Returns [Section titled “Returns”](#returns-39) `number` #### Since [Section titled “Since”](#since-21) v19.9.0 #### Inherited from [Section titled “Inherited from”](#inherited-from-22) ```ts RuntimeEventEmitter.getMaxListeners ``` *** ### ~~listenerCount()~~ [Section titled “listenerCount()”](#listenercount-1) ```ts static listenerCount(emitter, eventName): number; ``` A class method that returns the number of listeners for the given `eventName` registered on the given `emitter`. ```js import { EventEmitter, listenerCount } from 'node:events'; const myEmitter = new EventEmitter(); myEmitter.on('event', () => {}); myEmitter.on('event', () => {}); console.log(listenerCount(myEmitter, 'event')); // Prints: 2 ``` Deprecated Since v3.2.0 - Use `listenerCount` instead. #### Parameters [Section titled “Parameters”](#parameters-29) | Parameter | Type | Description | | ----------- | -------------------- | -------------------- | | `emitter` | `EventEmitter` | The emitter to query | | `eventName` | `string` \| `symbol` | The event name | #### Returns [Section titled “Returns”](#returns-40) `number` #### Since [Section titled “Since”](#since-22) v0.9.12 #### Inherited from [Section titled “Inherited from”](#inherited-from-23) ```ts RuntimeEventEmitter.listenerCount ``` *** ### on() [Section titled “on()”](#on-1) #### Call Signature [Section titled “Call Signature”](#call-signature) ```ts static on( emitter, eventName, options?): AsyncIterator; ``` ```js import { on, EventEmitter } from 'node:events'; import process from 'node:process'; const ee = new EventEmitter(); // Emit later on process.nextTick(() => { ee.emit('foo', 'bar'); ee.emit('foo', 42); }); for await (const event of on(ee, 'foo')) { // The execution of this inner block is synchronous and it // processes one event at a time (even with await). Do not use // if concurrent execution is required. console.log(event); // prints ['bar'] [42] } // Unreachable here ``` Returns an `AsyncIterator` that iterates `eventName` events. It will throw if the `EventEmitter` emits `'error'`. It removes all listeners when exiting the loop. The `value` returned by each iteration is an array composed of the emitted event arguments. An `AbortSignal` can be used to cancel waiting on events: ```js import { on, EventEmitter } from 'node:events'; import process from 'node:process'; const ac = new AbortController(); (async () => { const ee = new EventEmitter(); // Emit later on process.nextTick(() => { ee.emit('foo', 'bar'); ee.emit('foo', 42); }); for await (const event of on(ee, 'foo', { signal: ac.signal })) { // The execution of this inner block is synchronous and it // processes one event at a time (even with await). Do not use // if concurrent execution is required. console.log(event); // prints ['bar'] [42] } // Unreachable here })(); process.nextTick(() => ac.abort()); ``` Use the `close` option to specify an array of event names that will end the iteration: ```js import { on, EventEmitter } from 'node:events'; import process from 'node:process'; const ee = new EventEmitter(); // Emit later on process.nextTick(() => { ee.emit('foo', 'bar'); ee.emit('foo', 42); ee.emit('close'); }); for await (const event of on(ee, 'foo', { close: ['close'] })) { console.log(event); // prints ['bar'] [42] } // the loop will exit after 'close' is emitted console.log('done'); // prints 'done' ``` ##### Parameters [Section titled “Parameters”](#parameters-30) | Parameter | Type | | ----------- | ----------------------------------- | | `emitter` | `EventEmitter` | | `eventName` | `string` \| `symbol` | | `options?` | `StaticEventEmitterIteratorOptions` | ##### Returns [Section titled “Returns”](#returns-41) `AsyncIterator`<`any`\[]> An `AsyncIterator` that iterates `eventName` events emitted by the `emitter` ##### Since [Section titled “Since”](#since-23) v13.6.0, v12.16.0 ##### Inherited from [Section titled “Inherited from”](#inherited-from-24) ```ts RuntimeEventEmitter.on ``` #### Call Signature [Section titled “Call Signature”](#call-signature-1) ```ts static on( emitter, eventName, options?): AsyncIterator; ``` ```js import { on, EventEmitter } from 'node:events'; import process from 'node:process'; const ee = new EventEmitter(); // Emit later on process.nextTick(() => { ee.emit('foo', 'bar'); ee.emit('foo', 42); }); for await (const event of on(ee, 'foo')) { // The execution of this inner block is synchronous and it // processes one event at a time (even with await). Do not use // if concurrent execution is required. console.log(event); // prints ['bar'] [42] } // Unreachable here ``` Returns an `AsyncIterator` that iterates `eventName` events. It will throw if the `EventEmitter` emits `'error'`. It removes all listeners when exiting the loop. The `value` returned by each iteration is an array composed of the emitted event arguments. An `AbortSignal` can be used to cancel waiting on events: ```js import { on, EventEmitter } from 'node:events'; import process from 'node:process'; const ac = new AbortController(); (async () => { const ee = new EventEmitter(); // Emit later on process.nextTick(() => { ee.emit('foo', 'bar'); ee.emit('foo', 42); }); for await (const event of on(ee, 'foo', { signal: ac.signal })) { // The execution of this inner block is synchronous and it // processes one event at a time (even with await). Do not use // if concurrent execution is required. console.log(event); // prints ['bar'] [42] } // Unreachable here })(); process.nextTick(() => ac.abort()); ``` Use the `close` option to specify an array of event names that will end the iteration: ```js import { on, EventEmitter } from 'node:events'; import process from 'node:process'; const ee = new EventEmitter(); // Emit later on process.nextTick(() => { ee.emit('foo', 'bar'); ee.emit('foo', 42); ee.emit('close'); }); for await (const event of on(ee, 'foo', { close: ['close'] })) { console.log(event); // prints ['bar'] [42] } // the loop will exit after 'close' is emitted console.log('done'); // prints 'done' ``` ##### Parameters [Section titled “Parameters”](#parameters-31) | Parameter | Type | | ----------- | ----------------------------------- | | `emitter` | `EventTarget` | | `eventName` | `string` | | `options?` | `StaticEventEmitterIteratorOptions` | ##### Returns [Section titled “Returns”](#returns-42) `AsyncIterator`<`any`\[]> An `AsyncIterator` that iterates `eventName` events emitted by the `emitter` ##### Since [Section titled “Since”](#since-24) v13.6.0, v12.16.0 ##### Inherited from [Section titled “Inherited from”](#inherited-from-25) ```ts RuntimeEventEmitter.on ``` *** ### once() [Section titled “once()”](#once-1) #### Call Signature [Section titled “Call Signature”](#call-signature-2) ```ts static once( emitter, eventName, options?): Promise; ``` Creates a `Promise` that is fulfilled when the `EventEmitter` emits the given event or that is rejected if the `EventEmitter` emits `'error'` while waiting. The `Promise` will resolve with an array of all the arguments emitted to the given event. This method is intentionally generic and works with the web platform [EventTarget](https://dom.spec.whatwg.org/#interface-eventtarget) interface, which has no special`'error'` event semantics and does not listen to the `'error'` event. ```js import { once, EventEmitter } from 'node:events'; import process from 'node:process'; const ee = new EventEmitter(); process.nextTick(() => { ee.emit('myevent', 42); }); const [value] = await once(ee, 'myevent'); console.log(value); const err = new Error('kaboom'); process.nextTick(() => { ee.emit('error', err); }); try { await once(ee, 'myevent'); } catch (err) { console.error('error happened', err); } ``` The special handling of the `'error'` event is only used when `events.once()` is used to wait for another event. If `events.once()` is used to wait for the ‘`error'` event itself, then it is treated as any other kind of event without special handling: ```js import { EventEmitter, once } from 'node:events'; const ee = new EventEmitter(); once(ee, 'error') .then(([err]) => console.log('ok', err.message)) .catch((err) => console.error('error', err.message)); ee.emit('error', new Error('boom')); // Prints: ok boom ``` An `AbortSignal` can be used to cancel waiting for the event: ```js import { EventEmitter, once } from 'node:events'; const ee = new EventEmitter(); const ac = new AbortController(); async function foo(emitter, event, signal) { try { await once(emitter, event, { signal }); console.log('event emitted!'); } catch (error) { if (error.name === 'AbortError') { console.error('Waiting for the event was canceled!'); } else { console.error('There was an error', error.message); } } } foo(ee, 'foo', ac.signal); ac.abort(); // Abort waiting for the event ee.emit('foo'); // Prints: Waiting for the event was canceled! ``` ##### Parameters [Section titled “Parameters”](#parameters-32) | Parameter | Type | | ----------- | --------------------------- | | `emitter` | `EventEmitter` | | `eventName` | `string` \| `symbol` | | `options?` | `StaticEventEmitterOptions` | ##### Returns [Section titled “Returns”](#returns-43) `Promise`<`any`\[]> ##### Since [Section titled “Since”](#since-25) v11.13.0, v10.16.0 ##### Inherited from [Section titled “Inherited from”](#inherited-from-26) ```ts RuntimeEventEmitter.once ``` #### Call Signature [Section titled “Call Signature”](#call-signature-3) ```ts static once( emitter, eventName, options?): Promise; ``` Creates a `Promise` that is fulfilled when the `EventEmitter` emits the given event or that is rejected if the `EventEmitter` emits `'error'` while waiting. The `Promise` will resolve with an array of all the arguments emitted to the given event. This method is intentionally generic and works with the web platform [EventTarget](https://dom.spec.whatwg.org/#interface-eventtarget) interface, which has no special`'error'` event semantics and does not listen to the `'error'` event. ```js import { once, EventEmitter } from 'node:events'; import process from 'node:process'; const ee = new EventEmitter(); process.nextTick(() => { ee.emit('myevent', 42); }); const [value] = await once(ee, 'myevent'); console.log(value); const err = new Error('kaboom'); process.nextTick(() => { ee.emit('error', err); }); try { await once(ee, 'myevent'); } catch (err) { console.error('error happened', err); } ``` The special handling of the `'error'` event is only used when `events.once()` is used to wait for another event. If `events.once()` is used to wait for the ‘`error'` event itself, then it is treated as any other kind of event without special handling: ```js import { EventEmitter, once } from 'node:events'; const ee = new EventEmitter(); once(ee, 'error') .then(([err]) => console.log('ok', err.message)) .catch((err) => console.error('error', err.message)); ee.emit('error', new Error('boom')); // Prints: ok boom ``` An `AbortSignal` can be used to cancel waiting for the event: ```js import { EventEmitter, once } from 'node:events'; const ee = new EventEmitter(); const ac = new AbortController(); async function foo(emitter, event, signal) { try { await once(emitter, event, { signal }); console.log('event emitted!'); } catch (error) { if (error.name === 'AbortError') { console.error('Waiting for the event was canceled!'); } else { console.error('There was an error', error.message); } } } foo(ee, 'foo', ac.signal); ac.abort(); // Abort waiting for the event ee.emit('foo'); // Prints: Waiting for the event was canceled! ``` ##### Parameters [Section titled “Parameters”](#parameters-33) | Parameter | Type | | ----------- | --------------------------- | | `emitter` | `EventTarget` | | `eventName` | `string` | | `options?` | `StaticEventEmitterOptions` | ##### Returns [Section titled “Returns”](#returns-44) `Promise`<`any`\[]> ##### Since [Section titled “Since”](#since-26) v11.13.0, v10.16.0 ##### Inherited from [Section titled “Inherited from”](#inherited-from-27) ```ts RuntimeEventEmitter.once ``` *** ### setMaxListeners() [Section titled “setMaxListeners()”](#setmaxlisteners-1) ```ts static setMaxListeners(n?, ...eventTargets): void; ``` ```js import { setMaxListeners, EventEmitter } from 'node:events'; const target = new EventTarget(); const emitter = new EventEmitter(); setMaxListeners(5, target, emitter); ``` #### Parameters [Section titled “Parameters”](#parameters-34) | Parameter | Type | Description | | ---------------- | ------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `n?` | `number` | A non-negative number. The maximum number of listeners per `EventTarget` event. | | …`eventTargets?` | (`EventTarget` \| `EventEmitter`<`DefaultEventMap`>)\[] | Zero or more {EventTarget} or {EventEmitter} instances. If none are specified, `n` is set as the default max for all newly created {EventTarget} and {EventEmitter} objects. | #### Returns [Section titled “Returns”](#returns-45) `void` #### Since [Section titled “Since”](#since-27) v15.4.0 #### Inherited from [Section titled “Inherited from”](#inherited-from-28) ```ts RuntimeEventEmitter.setMaxListeners ``` # backgroundResult ```ts function backgroundResult(content): BackgroundResult; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | -------------- | | `T` | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ---- | | `content` | `T` | ## Returns [Section titled “Returns”](#returns) `BackgroundResult`<`T`> # isBackgroundResult ```ts function isBackgroundResult(result): result is BackgroundResult; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | -------------- | | `T` | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | --------- | | `result` | `unknown` | ## Returns [Section titled “Returns”](#returns) `result is BackgroundResult` # RealtimeOutputGuardrail A guardrail that checks the output of the agent. ## Extends [Section titled “Extends”](#extends) * [`OutputGuardrail`](/openai-agents-js/openai/agents/interfaces/outputguardrail/) ## Properties [Section titled “Properties”](#properties) ### execute [Section titled “execute”](#execute) ```ts execute: OutputGuardrailFunction<"text", unknown>; ``` The function that performs the guardrail check. #### Inherited from [Section titled “Inherited from”](#inherited-from) [`OutputGuardrail`](/openai-agents-js/openai/agents/interfaces/outputguardrail/).[`execute`](/openai-agents-js/openai/agents/interfaces/outputguardrail/#execute) *** ### name [Section titled “name”](#name) ```ts name: string; ``` The name of the guardrail. #### Inherited from [Section titled “Inherited from”](#inherited-from-1) [`OutputGuardrail`](/openai-agents-js/openai/agents/interfaces/outputguardrail/).[`name`](/openai-agents-js/openai/agents/interfaces/outputguardrail/#name) *** ### policyHint? [Section titled “policyHint?”](#policyhint) ```ts optional policyHint?: string; ``` This will be passed to the model to inform it about why the guardrail was triggered and to correct the behavior. If it’s not specified the name of your guardrail will be passed instead. # RealtimeTransportLayer The transport layer is the layer that handles the connection to the model and the communication with the model. ## Extends [Section titled “Extends”](#extends) * `EventEmitter`<[`RealtimeTransportEventTypes`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimetransporteventtypes/)> ## Properties [Section titled “Properties”](#properties) ### muted [Section titled “muted”](#muted) ```ts readonly muted: boolean | null; ``` Whether the input audio track is currently muted null if the muting is not handled by the transport layer *** ### status [Section titled “status”](#status) ```ts status: "connecting" | "connected" | "disconnected" | "disconnecting"; ``` ## Methods [Section titled “Methods”](#methods) ### addImage() [Section titled “addImage()”](#addimage) ```ts addImage(image, options?): void; ``` Sends an image to the model #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | -------------------------- | ---------------------------------- | -------------------------------------------- | | `image` | `string` | The image to send | | `options?` | { `triggerResponse?`: `boolean`; } | Additional options | | `options.triggerResponse?` | `boolean` | Whether to trigger a response from the model | #### Returns [Section titled “Returns”](#returns) `void` *** ### close() [Section titled “close()”](#close) ```ts close(): void; ``` Closes the connection to the model #### Returns [Section titled “Returns”](#returns-1) `void` *** ### connect() [Section titled “connect()”](#connect) ```ts connect(options): Promise; ``` Establishes the connection to the model and keeps the connection alive #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | Description | | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------ | | `options` | [`RealtimeTransportLayerConnectOptions`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimetransportlayerconnectoptions/) | The options for the connection | #### Returns [Section titled “Returns”](#returns-2) `Promise`<`void`> *** ### emit() [Section titled “emit()”](#emit) ```ts emit(type, ...args): boolean; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | --------------------------------------------------------------------------------------------------------------------------------------------------------- | | `K` *extends* keyof [`RealtimeTransportEventTypes`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimetransporteventtypes/) | #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | --------- | ------------------------------------------------------------------------------------------------------------------------------------------- | | `type` | `K` | | …`args` | [`RealtimeTransportEventTypes`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimetransporteventtypes/)\[`K`] | #### Returns [Section titled “Returns”](#returns-3) `boolean` #### Inherited from [Section titled “Inherited from”](#inherited-from) ```ts EventEmitter.emit ``` *** ### interrupt() [Section titled “interrupt()”](#interrupt) ```ts interrupt(): void; ``` Interrupts the current turn. Used for example when a guardrail is triggered #### Returns [Section titled “Returns”](#returns-4) `void` *** ### mute() [Section titled “mute()”](#mute) ```ts mute(muted): void; ``` Mutes the input audio track #### Parameters [Section titled “Parameters”](#parameters-3) | Parameter | Type | Description | | --------- | --------- | ------------------------------------- | | `muted` | `boolean` | Whether to mute the input audio track | #### Returns [Section titled “Returns”](#returns-5) `void` *** ### off() [Section titled “off()”](#off) ```ts off(type, listener): EventEmitter; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-1) | Type Parameter | | --------------------------------------------------------------------------------------------------------------------------------------------------------- | | `K` *extends* keyof [`RealtimeTransportEventTypes`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimetransporteventtypes/) | #### Parameters [Section titled “Parameters”](#parameters-4) | Parameter | Type | | ---------- | ------------------- | | `type` | `K` | | `listener` | (…`args`) => `void` | #### Returns [Section titled “Returns”](#returns-6) `EventEmitter`<[`RealtimeTransportEventTypes`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimetransporteventtypes/)> #### Inherited from [Section titled “Inherited from”](#inherited-from-1) ```ts EventEmitter.off ``` *** ### on() [Section titled “on()”](#on) ```ts on(type, listener): EventEmitter; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-2) | Type Parameter | | --------------------------------------------------------------------------------------------------------------------------------------------------------- | | `K` *extends* keyof [`RealtimeTransportEventTypes`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimetransporteventtypes/) | #### Parameters [Section titled “Parameters”](#parameters-5) | Parameter | Type | | ---------- | ------------------- | | `type` | `K` | | `listener` | (…`args`) => `void` | #### Returns [Section titled “Returns”](#returns-7) `EventEmitter`<[`RealtimeTransportEventTypes`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimetransporteventtypes/)> #### Inherited from [Section titled “Inherited from”](#inherited-from-2) ```ts EventEmitter.on ``` *** ### once() [Section titled “once()”](#once) ```ts once(type, listener): EventEmitter; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-3) | Type Parameter | | --------------------------------------------------------------------------------------------------------------------------------------------------------- | | `K` *extends* keyof [`RealtimeTransportEventTypes`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimetransporteventtypes/) | #### Parameters [Section titled “Parameters”](#parameters-6) | Parameter | Type | | ---------- | ------------------- | | `type` | `K` | | `listener` | (…`args`) => `void` | #### Returns [Section titled “Returns”](#returns-8) `EventEmitter`<[`RealtimeTransportEventTypes`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimetransporteventtypes/)> #### Inherited from [Section titled “Inherited from”](#inherited-from-3) ```ts EventEmitter.once ``` *** ### requestResponse()? [Section titled “requestResponse()?”](#requestresponse) ```ts optional requestResponse(response?): void; ``` Requests a new response for the current conversation turn. Implementations may defer the underlying `response.create` until the server has fully finished the prior response. #### Parameters [Section titled “Parameters”](#parameters-7) | Parameter | Type | Description | | ----------- | ------------------------- | ------------------------------------------- | | `response?` | `Record`<`string`, `any`> | Optional one-off response override payload. | #### Returns [Section titled “Returns”](#returns-9) `void` *** ### resetHistory() [Section titled “resetHistory()”](#resethistory) ```ts resetHistory(oldHistory, newHistory): void; ``` Resets the conversation history / context to a specific state #### Parameters [Section titled “Parameters”](#parameters-8) | Parameter | Type | Description | | ------------ | ---------------------------------------------------------------------------------------------------------- | ------------------------------------------------------ | | `oldHistory` | [`RealtimeItem`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimeitem/)\[] | The history that is currently stored on the session. | | `newHistory` | [`RealtimeItem`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimeitem/)\[] | The history you want the session to use going forward. | #### Returns [Section titled “Returns”](#returns-10) `void` *** ### sendAudio() [Section titled “sendAudio()”](#sendaudio) ```ts sendAudio(audio, options): void; ``` Sends a raw audio buffer to the model #### Parameters [Section titled “Parameters”](#parameters-9) | Parameter | Type | Description | | ----------------- | ------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- | | `audio` | `ArrayBuffer` | The audio buffer to send | | `options` | { `commit?`: `boolean`; } | Additional options | | `options.commit?` | `boolean` | Whether to commit the audio buffer to the model. If the model does not do turn detection, this can be used to indicate the turn is completed. | #### Returns [Section titled “Returns”](#returns-11) `void` *** ### sendEvent() [Section titled “sendEvent()”](#sendevent) ```ts sendEvent(event): void; ``` Sends a raw event to the model #### Parameters [Section titled “Parameters”](#parameters-10) | Parameter | Type | Description | | --------- | ------------------------------------------------------------------------------------------------------------------------- | ----------------- | | `event` | [`RealtimeClientMessage`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimeclientmessage/) | The event to send | #### Returns [Section titled “Returns”](#returns-12) `void` *** ### sendFunctionCallOutput() [Section titled “sendFunctionCallOutput()”](#sendfunctioncalloutput) ```ts sendFunctionCallOutput( toolCall, output, startResponse): void; ``` Sends a function call output to the model #### Parameters [Section titled “Parameters”](#parameters-11) | Parameter | Type | Description | | --------------- | --------------------------------------------------------------------------------------------------------------------------- | --------------------------- | | `toolCall` | [`TransportToolCallEvent`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/transporttoolcallevent/) | The tool call to send | | `output` | `string` | The output of the tool call | | `startResponse` | `boolean` | ‐ | #### Returns [Section titled “Returns”](#returns-13) `void` *** ### sendMcpResponse() [Section titled “sendMcpResponse()”](#sendmcpresponse) ```ts sendMcpResponse( approvalRequest, approved, reason?): void; ``` Sends a response for an MCP tool call #### Parameters [Section titled “Parameters”](#parameters-12) | Parameter | Type | Description | | ------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------- | | `approvalRequest` | { `approved?`: `boolean` \| `null`; `arguments`: `z.ZodRecord`<`z.ZodString`, `z.ZodAny`>; `itemId`: `string`; `name`: `string`; `serverLabel`: `string`; `type`: `"mcp_approval_request"`; } | The approval request to respond to | | `approvalRequest.approved?` | `boolean` \| `null` | ‐ | | `approvalRequest.arguments` | `z.ZodRecord`<`z.ZodString`, `z.ZodAny`> | ‐ | | `approvalRequest.itemId?` | `string` | ‐ | | `approvalRequest.name?` | `string` | ‐ | | `approvalRequest.serverLabel?` | `string` | ‐ | | `approvalRequest.type?` | `"mcp_approval_request"` | ‐ | | `approved?` | `boolean` | Whether the tool call was approved or rejected | | `reason?` | `string` | Optional rejection text for the provider/model. | #### Returns [Section titled “Returns”](#returns-14) `void` *** ### sendMessage() [Section titled “sendMessage()”](#sendmessage) ```ts sendMessage( message, otherEventData, options?): void; ``` Sends a text message to the model #### Parameters [Section titled “Parameters”](#parameters-13) | Parameter | Type | Description | | -------------------------- | ---------------------------------- | ---------------------------------------------------- | | `message` | `RealtimeUserInput` | The message to send | | `otherEventData` | `Record`<`string`, `any`> | Additional event data, will be merged into the event | | `options?` | { `triggerResponse?`: `boolean`; } | Additional options | | `options.triggerResponse?` | `boolean` | Whether to trigger a response from the model | #### Returns [Section titled “Returns”](#returns-15) `void` *** ### updateSessionConfig() [Section titled “updateSessionConfig()”](#updatesessionconfig) ```ts updateSessionConfig(config): void; ``` Sends an updated session configuration to the model. Used to update for example the model instructions during a handoff #### Parameters [Section titled “Parameters”](#parameters-14) | Parameter | Type | Description | | --------- | ------------------------------------------------------------------------------------------------------------------------------------ | ---------------------- | | `config` | `Partial`<[`RealtimeSessionConfig`](/openai-agents-js/openai/agents/openai/namespaces/realtime/type-aliases/realtimesessionconfig/)> | The new session config | #### Returns [Section titled “Returns”](#returns-16) `void` # ApiKey ```ts type ApiKey = string | (() => string | Promise); ``` The type of the API key. Can be a string or a function that returns a string or a promise that resolves to a string. # OpenAIRealtimeBaseOptions ```ts type OpenAIRealtimeBaseOptions = object; ``` The options for the OpenAI Realtime transport layer. ## Properties [Section titled “Properties”](#properties) ### apiKey? [Section titled “apiKey?”](#apikey) ```ts optional apiKey?: ApiKey; ``` The API key to use for the connection. *** ### model? [Section titled “model?”](#model) ```ts optional model?: OpenAIRealtimeModels; ``` The model to used during the connection. # OpenAIRealtimeEventTypes ```ts type OpenAIRealtimeEventTypes = object & RealtimeTransportEventTypes; ``` The events that are emitted by the OpenAI Realtime transport layer. ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### connected [Section titled “connected”](#connected) ```ts connected: []; ``` Triggered when the connection is established. ### disconnected [Section titled “disconnected”](#disconnected) ```ts disconnected: []; ``` Triggered when the connection is closed. # OpenAIRealtimeModels ```ts type OpenAIRealtimeModels = | "gpt-realtime" | "gpt-realtime-1.5" | "gpt-realtime-2" | "gpt-realtime-2025-08-28" | "gpt-4o-realtime-preview" | "gpt-4o-realtime-preview-2024-10-01" | "gpt-4o-realtime-preview-2024-12-17" | "gpt-4o-realtime-preview-2025-06-03" | "gpt-4o-mini-realtime-preview" | "gpt-4o-mini-realtime-preview-2024-12-17" | "gpt-realtime-mini" | "gpt-realtime-mini-2025-10-06" | "gpt-realtime-mini-2025-12-15" | string & object; ``` The models that are supported by the OpenAI Realtime API. # OpenAIRealtimeWebRTCOptions ```ts type OpenAIRealtimeWebRTCOptions = object & OpenAIRealtimeBaseOptions; ``` The options for the OpenAI Realtime WebRTC transport layer. ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### audioElement? [Section titled “audioElement?”](#audioelement) ```ts optional audioElement?: HTMLAudioElement; ``` The audio element to use for audio playback. If not provided, a new audio element will be created. ### baseUrl? [Section titled “baseUrl?”](#baseurl) ```ts optional baseUrl?: string; ``` Override of the base URL for the Realtime API ### changePeerConnection? [Section titled “changePeerConnection?”](#changepeerconnection) ```ts optional changePeerConnection?: (peerConnection) => RTCPeerConnection | Promise; ``` Optional hook invoked with the freshly created peer connection. Returning a different connection will override the one created by the transport layer. This is called right before the offer is created and can be asynchronous. #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ---------------- | ------------------- | | `peerConnection` | `RTCPeerConnection` | #### Returns [Section titled “Returns”](#returns) `RTCPeerConnection` | `Promise`<`RTCPeerConnection`> ### mediaStream? [Section titled “mediaStream?”](#mediastream) ```ts optional mediaStream?: MediaStream; ``` The media stream to use for audio input. If not provided, the default microphone will be used. ### useInsecureApiKey? [Section titled “useInsecureApiKey?”](#useinsecureapikey) ```ts optional useInsecureApiKey?: boolean; ``` **Important**: Do not use this option unless you know what you are doing. Whether to use an insecure API key. This has to be set if you are trying to use a regular OpenAI API key instead of a client ephemeral key. #### See [Section titled “See”](#see) # OpenAIRealtimeWebSocketOptions ```ts type OpenAIRealtimeWebSocketOptions = object & OpenAIRealtimeBaseOptions; ``` The options for the OpenAI Realtime WebSocket transport layer. ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### createWebSocket? [Section titled “createWebSocket?”](#createwebsocket) ```ts optional createWebSocket?: (options) => Promise; ``` Builds a new WebSocket connection. #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | --------- | ------------------------ | ----------------------------------------- | | `options` | `CreateWebSocketOptions` | The options for the WebSocket connection. | #### Returns [Section titled “Returns”](#returns) `Promise`<[`RuntimeEventEmitter`](/openai-agents-js/openai/agents/variables/runtimeeventemitter/)> The WebSocket connection. ### skipOpenEventListeners? [Section titled “skipOpenEventListeners?”](#skipopeneventlisteners) ```ts optional skipOpenEventListeners?: boolean; ``` When you pass your own createWebSocket function, which completes the connection state transition, you can set this to true to skip registering the `open` event listener for the same purpose. If this flag is set to true, the constructor will immediately call the internal operation to mark the internal connection state to `connected`. Otherwise, the constructor will register the `open` event listener and wait for it to be triggered. By default (meaning if this property is absent), this is set to false. ### url? [Section titled “url?”](#url) ```ts optional url?: string; ``` The URL to use for the WebSocket connection. ### useInsecureApiKey? [Section titled “useInsecureApiKey?”](#useinsecureapikey) ```ts optional useInsecureApiKey?: boolean; ``` **Important**: Do not use this option unless you know what you are doing. Whether to use an insecure API key. This has to be set if you are trying to use a regular OpenAI API key instead of a client ephemeral key. #### See [Section titled “See”](#see) # RealtimeAgentConfiguration ```ts type RealtimeAgentConfiguration = Partial, TextOutput>, | "model" | "handoffs" | "modelSettings" | "outputType" | "toolUseBehavior" | "resetToolChoice" | "outputGuardrails" | "inputGuardrails" | "model">> & object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### handoffs? [Section titled “handoffs?”](#handoffs) ```ts optional handoffs?: ( | RealtimeAgent | Handoff, TextOutput>)[]; ``` Any other `RealtimeAgent` instances the agent is able to hand off to. ### name [Section titled “name”](#name) ```ts name: string; ``` The name of your realtime agent. ### voice? [Section titled “voice?”](#voice) ```ts optional voice?: string; ``` The voice intended to be used by the agent. If another agent already spoke during the RealtimeSession, changing the voice during a handoff will fail. ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | -------------------------------------------------------------------------------- | | `TContext` | [`UnknownContext`](/openai-agents-js/openai/agents/type-aliases/unknowncontext/) | # RealtimeAudioFormat ```ts type RealtimeAudioFormat = RealtimeAudioFormatLegacy | RealtimeAudioFormatDefinition; ``` # RealtimeBaseItem ```ts type RealtimeBaseItem = object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### itemId [Section titled “itemId”](#itemid) ```ts itemId: string; ``` # RealtimeClientMessage ```ts type RealtimeClientMessage = object; ``` ## Indexable [Section titled “Indexable”](#indexable) ```ts [key: string]: any ``` ## Properties [Section titled “Properties”](#properties) ### type [Section titled “type”](#type) ```ts type: string; ``` # RealtimeContextData ```ts type RealtimeContextData = TContext & object; ``` The context data for a realtime session. This is the context data that is passed to the agent. The RealtimeSession will automatically add the current snapshot of the history to the context. ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### history [Section titled “history”](#history) ```ts history: RealtimeItem[]; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | ------------ | | `TContext` | `unknown` | # RealtimeItem ```ts type RealtimeItem = | RealtimeMessageItem | RealtimeToolCallItem | RealtimeMcpCallItem | RealtimeMcpCallApprovalRequestItem; ``` # RealtimeMcpCallItem ```ts type RealtimeMcpCallItem = object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### arguments [Section titled “arguments”](#arguments) ```ts arguments: string; ``` ### itemId [Section titled “itemId”](#itemid) ```ts itemId: string; ``` ### name [Section titled “name”](#name) ```ts name: string; ``` ### output [Section titled “output”](#output) ```ts output: string | null; ``` ### previousItemId? [Section titled “previousItemId?”](#previousitemid) ```ts optional previousItemId?: string | null; ``` ### status [Section titled “status”](#status) ```ts status: "completed" | "in_progress" | "incomplete"; ``` ### type [Section titled “type”](#type) ```ts type: "mcp_call" | "mcp_tool_call"; ``` # RealtimeMessageItem ```ts type RealtimeMessageItem = | { content: object[]; itemId: string; previousItemId?: string | null; role: "system"; type: "message"; } | { content: ( | { text: string; type: "input_text"; } | { audio?: string | null; transcript: string | null; type: "input_audio"; })[]; itemId: string; previousItemId?: string | null; role: "user"; status: "completed" | "in_progress"; type: "message"; } | { content: ( | { text: string; type: "output_text"; } | { audio?: string | null; transcript?: string | null; type: "output_audio"; })[]; itemId: string; previousItemId?: string | null; role: "assistant"; status: "completed" | "in_progress" | "incomplete"; type: "message"; }; ``` # RealtimeReasoningConfig ```ts type RealtimeReasoningConfig = object; ``` ## Properties [Section titled “Properties”](#properties) ### effort? [Section titled “effort?”](#effort) ```ts optional effort?: RealtimeReasoningEffort; ``` # RealtimeReasoningEffort ```ts type RealtimeReasoningEffort = "minimal" | "low" | "medium" | "high" | "xhigh"; ``` # RealtimeSessionConfig ```ts type RealtimeSessionConfig = RealtimeSessionConfigDefinition | RealtimeSessionConfigDeprecated; ``` # RealtimeSessionConnectOptions ```ts type RealtimeSessionConnectOptions = object; ``` ## Properties [Section titled “Properties”](#properties) ### apiKey [Section titled “apiKey”](#apikey) ```ts apiKey: string | (() => string | Promise); ``` The API key to use for the connection. Pass a function to lazily load the API key. Overrides default client options. *** ### callId? [Section titled “callId?”](#callid) ```ts optional callId?: string; ``` The call ID to attach to when connecting to a SIP-initiated session. *** ### model? [Section titled “model?”](#model) ```ts optional model?: | OpenAIRealtimeModels | string & object; ``` The model to use for the connection. *** ### url? [Section titled “url?”](#url) ```ts optional url?: string; ``` The URL to use for the connection. # RealtimeSessionEventTypes ```ts type RealtimeSessionEventTypes = object; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | ------------ | | `TContext` | `unknown` | ## Properties [Section titled “Properties”](#properties) ### agent\_end [Section titled “agent\_end”](#agent_end) ```ts agent_end: [RunContext>, AgentWithOrWithoutHistory, string]; ``` Triggered when an agent ends its work on a response. *** ### agent\_handoff [Section titled “agent\_handoff”](#agent_handoff) ```ts agent_handoff: [RunContext>, AgentWithOrWithoutHistory, AgentWithOrWithoutHistory]; ``` Triggered when an agent hands off to another agent. *** ### agent\_start [Section titled “agent\_start”](#agent_start) ```ts agent_start: [RunContext>, AgentWithOrWithoutHistory, AgentInputItem[]]; ``` Triggered when an agent starts its work on a response. *** ### agent\_tool\_end [Section titled “agent\_tool\_end”](#agent_tool_end) ```ts agent_tool_end: [RunContext>, AgentWithOrWithoutHistory, FunctionTool>, string, object]; ``` Triggered when an agent ends a tool call. *** ### agent\_tool\_start [Section titled “agent\_tool\_start”](#agent_tool_start) ```ts agent_tool_start: [RunContext>, AgentWithOrWithoutHistory, FunctionTool>, object]; ``` Triggered when an agent starts a tool call. *** ### audio [Section titled “audio”](#audio) ```ts audio: [TransportLayerAudio]; ``` Triggered when there is new audio data available for playing to the user. *** ### audio\_interrupted [Section titled “audio\_interrupted”](#audio_interrupted) ```ts audio_interrupted: [RunContext>, AgentWithOrWithoutHistory]; ``` Triggered when the agent is interrupted. Can be listened to by the user to stop audio playback or give visual indicators to the user. *** ### audio\_start [Section titled “audio\_start”](#audio_start) ```ts audio_start: [RunContext>, AgentWithOrWithoutHistory]; ``` Triggered when the agent starts generating audio. *** ### audio\_stopped [Section titled “audio\_stopped”](#audio_stopped) ```ts audio_stopped: [RunContext>, AgentWithOrWithoutHistory]; ``` Triggered when the agent stops generating audio. *** ### error [Section titled “error”](#error) ```ts error: [RealtimeSessionError]; ``` Triggered when an error occurs. *** ### guardrail\_tripped [Section titled “guardrail\_tripped”](#guardrail_tripped) ```ts guardrail_tripped: [RunContext>, AgentWithOrWithoutHistory, OutputGuardrailTripwireTriggered, object]; ``` Triggered when an output guardrail is tripped. *** ### history\_added [Section titled “history\_added”](#history_added) ```ts history_added: [RealtimeItem]; ``` Triggered when a new item is added to the history. At this point the transcript/response might still be in progress. *** ### history\_updated [Section titled “history\_updated”](#history_updated) ```ts history_updated: [RealtimeItem[]]; ``` Triggered when the history got updated. Contains the full history of the conversation. *** ### mcp\_tool\_call\_completed [Section titled “mcp\_tool\_call\_completed”](#mcp_tool_call_completed) ```ts mcp_tool_call_completed: [RunContext>, AgentWithOrWithoutHistory, RealtimeMcpCallItem]; ``` Triggered when an MCP tool call is completed. *** ### mcp\_tools\_changed [Section titled “mcp\_tools\_changed”](#mcp_tools_changed) ```ts mcp_tools_changed: [RealtimeMcpToolInfo[]]; ``` Triggered when the set of currently available MCP tools changes (e.g. after a list-tools result arrives, or when the active agent changes). Carries the list of available tools filtered by the active agent’s server\_labels. *** ### tool\_approval\_requested [Section titled “tool\_approval\_requested”](#tool_approval_requested) ```ts tool_approval_requested: [RunContext>, AgentWithOrWithoutHistory, RealtimeToolApprovalRequest | RealtimeMcpApprovalRequest]; ``` Triggered when a tool approval is requested. *** ### transport\_event [Section titled “transport\_event”](#transport_event) ```ts transport_event: [TransportEvent]; ``` Emits all the raw events from the transport layer. # RealtimeSessionOptions ```ts type RealtimeSessionOptions = object; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | ------------ | | `TContext` | `unknown` | ## Properties [Section titled “Properties”](#properties) ### apiKey [Section titled “apiKey”](#apikey) ```ts apiKey: ApiKey; ``` The API key to use for the connection. Pass a function to lazily load the API key *** ### automaticallyTriggerResponseForMcpToolCalls? [Section titled “automaticallyTriggerResponseForMcpToolCalls?”](#automaticallytriggerresponseformcptoolcalls) ```ts optional automaticallyTriggerResponseForMcpToolCalls?: boolean; ``` Whether to automatically trigger a response for MCP tool calls. *** ### config? [Section titled “config?”](#config) ```ts optional config?: Partial; ``` Additional session config options. Overrides default client options. *** ### context? [Section titled “context?”](#context) ```ts optional context?: TContext; ``` Additional context to pass to the agent *** ### groupId? [Section titled “groupId?”](#groupid) ```ts optional groupId?: string; ``` A group identifier to use for tracing, to link multiple traces together. For example, if you want to connect your RealtimeSession traces with those of a backend text-based agent run. *** ### historyStoreAudio? [Section titled “historyStoreAudio?”](#historystoreaudio) ```ts optional historyStoreAudio?: boolean; ``` Whether the history copy should include a local copy of the audio data. By default it is not included in the history to save runtime memory on the client. If you wish to keep this data you can enable this option. *** ### model? [Section titled “model?”](#model) ```ts optional model?: | OpenAIRealtimeModels | string & object; ``` The model to use. *** ### outputGuardrails? [Section titled “outputGuardrails?”](#outputguardrails) ```ts optional outputGuardrails?: RealtimeOutputGuardrail[]; ``` Any output guardrails to apply to agent output in parallel *** ### outputGuardrailSettings? [Section titled “outputGuardrailSettings?”](#outputguardrailsettings) ```ts optional outputGuardrailSettings?: RealtimeOutputGuardrailSettings; ``` Configure the behavior of your guardrails *** ### toolErrorFormatter? [Section titled “toolErrorFormatter?”](#toolerrorformatter) ```ts optional toolErrorFormatter?: ToolErrorFormatter>; ``` Formats tool error messages that are returned to the model. Returning `undefined` falls back to the SDK default message. *** ### traceMetadata? [Section titled “traceMetadata?”](#tracemetadata) ```ts optional traceMetadata?: Record; ``` An optional dictionary of additional metadata to include with the trace. *** ### tracingDisabled? [Section titled “tracingDisabled?”](#tracingdisabled) ```ts optional tracingDisabled?: boolean; ``` Whether tracing is disabled for this session. If disabled, we will not trace the agent run. *** ### transport [Section titled “transport”](#transport) ```ts transport: | "webrtc" | "websocket" | RealtimeTransportLayer; ``` The transport layer to use. *** ### workflowName? [Section titled “workflowName?”](#workflowname) ```ts optional workflowName?: string; ``` The workflow name to use for tracing. # RealtimeSessionPayload ```ts type RealtimeSessionPayload = object & Record; ``` Shape of the payload that the Realtime API expects for session.create/update operations. This closely mirrors the REST `CallAcceptParams` type so that callers can feed the payload directly into the `openai.realtime.calls.accept` helper without casts. ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### type [Section titled “type”](#type) ```ts type: "realtime"; ``` # RealtimeToolCallItem ```ts type RealtimeToolCallItem = object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### arguments [Section titled “arguments”](#arguments) ```ts arguments: string; ``` ### itemId [Section titled “itemId”](#itemid) ```ts itemId: string; ``` ### name [Section titled “name”](#name) ```ts name: string; ``` ### output [Section titled “output”](#output) ```ts output: string | null; ``` ### previousItemId? [Section titled “previousItemId?”](#previousitemid) ```ts optional previousItemId?: string | null; ``` ### status [Section titled “status”](#status) ```ts status: "completed" | "in_progress" | "incomplete"; ``` ### type [Section titled “type”](#type) ```ts type: "function_call"; ``` # RealtimeTransportEventTypes ```ts type RealtimeTransportEventTypes = object; ``` ## Indexable [Section titled “Indexable”](#indexable) ```ts [key: string]: any[] ``` ## Properties [Section titled “Properties”](#properties) ### \* ```ts *: [TransportEvent]; ``` A raw event from the transport layer. Allows a user to tap directly into the events of the transport layer. *** ### audio [Section titled “audio”](#audio) ```ts audio: [TransportLayerAudio]; ``` Triggered when there is new audio data available. Might not be triggered if the transport layer handles the audio internally (WebRTC). *** ### audio\_done [Section titled “audio\_done”](#audio_done) ```ts audio_done: []; ``` Triggered when the audio generation is done. *** ### audio\_interrupted [Section titled “audio\_interrupted”](#audio_interrupted) ```ts audio_interrupted: []; ``` Triggered when the model detected that it was interrupted. This can be used by the client to stop audio playback. *** ### audio\_transcript\_delta [Section titled “audio\_transcript\_delta”](#audio_transcript_delta) ```ts audio_transcript_delta: [TransportLayerTranscriptDelta]; ``` Triggered when there is a new text delta of the transcript available. *** ### connection\_change [Section titled “connection\_change”](#connection_change) ```ts connection_change: [ConnectionStatus]; ``` Triggered whenever the connection status of the transport changes. Emits the new status after the change. *** ### error [Section titled “error”](#error) ```ts error: [TransportError]; ``` Triggered if the model / transport layer encountered an error *** ### function\_call [Section titled “function\_call”](#function_call) ```ts function_call: [TransportToolCallEvent]; ``` Triggered when the model is trying to call a function. *** ### item\_deleted [Section titled “item\_deleted”](#item_deleted) ```ts item_deleted: [RealtimeBaseItem]; ``` Triggered when an item is deleted. *** ### item\_update [Section titled “item\_update”](#item_update) ```ts item_update: [RealtimeItem]; ``` Triggered when the history is added or updated. *** ### mcp\_approval\_request [Section titled “mcp\_approval\_request”](#mcp_approval_request) ```ts mcp_approval_request: [RealtimeMcpCallApprovalRequestItem]; ``` Triggered when a remote MCP tool requires approval. *** ### mcp\_tool\_call\_completed [Section titled “mcp\_tool\_call\_completed”](#mcp_tool_call_completed) ```ts mcp_tool_call_completed: [RealtimeMcpCallItem]; ``` Triggered when an MCP tool call is completed. *** ### mcp\_tools\_listed [Section titled “mcp\_tools\_listed”](#mcp_tools_listed) ```ts mcp_tools_listed: [object]; ``` Triggered when a remote MCP server lists its tools (via mcp\_list\_tools). *** ### turn\_done [Section titled “turn\_done”](#turn_done) ```ts turn_done: [TransportLayerResponseCompleted]; ``` Triggered when the model is done generating a response for a turn. *** ### turn\_started [Section titled “turn\_started”](#turn_started) ```ts turn_started: [TransportLayerResponseStarted]; ``` Triggered when the model starts generating a response for a turn. *** ### usage\_update [Section titled “usage\_update”](#usage_update) ```ts usage_update: [Usage]; ``` Triggered when the usage update is available. # RealtimeTransportLayerConnectOptions ```ts type RealtimeTransportLayerConnectOptions = object; ``` The options for the connection to the model. ## Properties [Section titled “Properties”](#properties) ### apiKey [Section titled “apiKey”](#apikey) ```ts apiKey: ApiKey; ``` The API key to use for the connection. *** ### callId? [Section titled “callId?”](#callid) ```ts optional callId?: string; ``` The call ID to attach to instead of starting a new session. *** ### initialSessionConfig? [Section titled “initialSessionConfig?”](#initialsessionconfig) ```ts optional initialSessionConfig?: Partial; ``` The initial session config to use for the session. *** ### model? [Section titled “model?”](#model) ```ts optional model?: string; ``` The model to use for the connection. *** ### url? [Section titled “url?”](#url) ```ts optional url?: string; ``` The URL to use for the connection. # TransportError ```ts type TransportError = object; ``` Represents an error that occurred on the transport layer. ## Properties [Section titled “Properties”](#properties) ### error [Section titled “error”](#error) ```ts error: unknown; ``` *** ### type [Section titled “type”](#type) ```ts type: "error"; ``` # TransportEvent ```ts type TransportEvent = | TransportError | TransportToolCallEvent | InputAudioTranscriptionCompletedEvent | { [key: string]: any; type: string; }; ``` # TransportLayerAudio ```ts type TransportLayerAudio = object; ``` Event representing audio data from the model on the transport layer. ## Properties [Section titled “Properties”](#properties) ### data [Section titled “data”](#data) ```ts data: ArrayBuffer; ``` *** ### responseId [Section titled “responseId”](#responseid) ```ts responseId: string; ``` *** ### type [Section titled “type”](#type) ```ts type: "audio"; ``` # TransportLayerResponseCompleted ```ts type TransportLayerResponseCompleted = StreamEventResponseCompleted; ``` # TransportLayerResponseStarted ```ts type TransportLayerResponseStarted = StreamEventResponseStarted; ``` # TransportLayerTranscriptDelta ```ts type TransportLayerTranscriptDelta = object; ``` ## Properties [Section titled “Properties”](#properties) ### delta [Section titled “delta”](#delta) ```ts delta: string; ``` *** ### itemId [Section titled “itemId”](#itemid) ```ts itemId: string; ``` *** ### responseId [Section titled “responseId”](#responseid) ```ts responseId: string; ``` *** ### type [Section titled “type”](#type) ```ts type: "transcript_delta"; ``` # TransportToolCallEvent ```ts type TransportToolCallEvent = object; ``` Event representing an attempted tool call by the model on the transport layer. ## Properties [Section titled “Properties”](#properties) ### arguments [Section titled “arguments”](#arguments) ```ts arguments: string; ``` *** ### callId [Section titled “callId”](#callid) ```ts callId: string; ``` *** ### id? [Section titled “id?”](#id) ```ts optional id?: string; ``` *** ### name [Section titled “name”](#name) ```ts name: string; ``` *** ### previousItemId? [Section titled “previousItemId?”](#previousitemid) ```ts optional previousItemId?: string; ``` *** ### type [Section titled “type”](#type) ```ts type: "function_call"; ``` # WebRTCState ```ts type WebRTCState = | { callId: string | undefined; dataChannel: undefined; peerConnection: undefined; status: "disconnected"; } | { callId: string | undefined; dataChannel: RTCDataChannel; peerConnection: RTCPeerConnection; status: "connecting"; } | { callId: string | undefined; dataChannel: RTCDataChannel; peerConnection: RTCPeerConnection; status: "connected"; }; ``` The connection state of the WebRTC connection. # WebSocketState ```ts type WebSocketState = | { status: "disconnected"; websocket: undefined; } | { status: "connecting"; websocket: RuntimeEventEmitter; } | { status: "connected"; websocket: RuntimeEventEmitter; }; ``` The connection state of the WebSocket connection. # DEFAULT_OPENAI_REALTIME_MODEL ```ts const DEFAULT_OPENAI_REALTIME_MODEL: OpenAIRealtimeModels; ``` The default model that is used during the connection if no model is provided. # DEFAULT_OPENAI_REALTIME_SESSION_CONFIG ```ts const DEFAULT_OPENAI_REALTIME_SESSION_CONFIG: Partial; ``` The default session config that gets send over during session connection unless overridden by the user. # utils ```ts const utils: object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### arrayBufferToBase64 [Section titled “arrayBufferToBase64”](#arraybuffertobase64) ```ts arrayBufferToBase64: typeof utilImport.arrayBufferToBase64; ``` ### base64ToArrayBuffer [Section titled “base64ToArrayBuffer”](#base64toarraybuffer) ```ts base64ToArrayBuffer: typeof utilImport.base64ToArrayBuffer; ``` ### getLastTextFromAudioOutputMessage [Section titled “getLastTextFromAudioOutputMessage”](#getlasttextfromaudiooutputmessage) ```ts getLastTextFromAudioOutputMessage: typeof utilImport.getLastTextFromAudioOutputMessage; ``` # @openai/agents ## Namespaces [Section titled “Namespaces”](#namespaces) * [protocol](/openai-agents-js/openai/agents/openai/namespaces/protocol/readme/) * [realtime](/openai-agents-js/openai/agents/openai/namespaces/realtime/readme/) ## Classes [Section titled “Classes”](#classes) * [Agent](/openai-agents-js/openai/agents/classes/agent/) * [AgentHooks](/openai-agents-js/openai/agents/classes/agenthooks/) * [AgentsError](/openai-agents-js/openai/agents/classes/agentserror/) * [BatchTraceProcessor](/openai-agents-js/openai/agents/classes/batchtraceprocessor/) * [ConsoleSpanExporter](/openai-agents-js/openai/agents/classes/consolespanexporter/) * [GuardrailExecutionError](/openai-agents-js/openai/agents/classes/guardrailexecutionerror/) * [Handoff](/openai-agents-js/openai/agents/classes/handoff/) * [InputGuardrailTripwireTriggered](/openai-agents-js/openai/agents/classes/inputguardrailtripwiretriggered/) * [MaxTurnsExceededError](/openai-agents-js/openai/agents/classes/maxturnsexceedederror/) * [MCPServers](/openai-agents-js/openai/agents/classes/mcpservers/) * [MCPServerSSE](/openai-agents-js/openai/agents/classes/mcpserversse/) * [MCPServerStdio](/openai-agents-js/openai/agents/classes/mcpserverstdio/) * [MCPServerStreamableHttp](/openai-agents-js/openai/agents/classes/mcpserverstreamablehttp/) * [MemorySession](/openai-agents-js/openai/agents/classes/memorysession/) * [ModelBehaviorError](/openai-agents-js/openai/agents/classes/modelbehaviorerror/) * [ModelRefusalError](/openai-agents-js/openai/agents/classes/modelrefusalerror/) * [NoopSpan](/openai-agents-js/openai/agents/classes/noopspan/) * [NoopTrace](/openai-agents-js/openai/agents/classes/nooptrace/) * [OpenAIChatCompletionsModel](/openai-agents-js/openai/agents/classes/openaichatcompletionsmodel/) * [OpenAIConversationsSession](/openai-agents-js/openai/agents/classes/openaiconversationssession/) * [OpenAIProvider](/openai-agents-js/openai/agents/classes/openaiprovider/) * [OpenAIResponsesCompactionSession](/openai-agents-js/openai/agents/classes/openairesponsescompactionsession/) * [OpenAIResponsesModel](/openai-agents-js/openai/agents/classes/openairesponsesmodel/) * [OpenAIResponsesWSModel](/openai-agents-js/openai/agents/classes/openairesponseswsmodel/) * [OpenAITracingExporter](/openai-agents-js/openai/agents/classes/openaitracingexporter/) * [OutputGuardrailTripwireTriggered](/openai-agents-js/openai/agents/classes/outputguardrailtripwiretriggered/) * [RequestUsage](/openai-agents-js/openai/agents/classes/requestusage/) * [RunAgentUpdatedStreamEvent](/openai-agents-js/openai/agents/classes/runagentupdatedstreamevent/) * [RunContext](/openai-agents-js/openai/agents/classes/runcontext/) * [RunHandoffCallItem](/openai-agents-js/openai/agents/classes/runhandoffcallitem/) * [RunHandoffOutputItem](/openai-agents-js/openai/agents/classes/runhandoffoutputitem/) * [RunItemStreamEvent](/openai-agents-js/openai/agents/classes/runitemstreamevent/) * [RunMessageOutputItem](/openai-agents-js/openai/agents/classes/runmessageoutputitem/) * [Runner](/openai-agents-js/openai/agents/classes/runner/) * [RunRawModelStreamEvent](/openai-agents-js/openai/agents/classes/runrawmodelstreamevent/) * [RunReasoningItem](/openai-agents-js/openai/agents/classes/runreasoningitem/) * [RunResult](/openai-agents-js/openai/agents/classes/runresult/) * [RunState](/openai-agents-js/openai/agents/classes/runstate/) * [RunToolApprovalItem](/openai-agents-js/openai/agents/classes/runtoolapprovalitem/) * [RunToolCallItem](/openai-agents-js/openai/agents/classes/runtoolcallitem/) * [RunToolCallOutputItem](/openai-agents-js/openai/agents/classes/runtoolcalloutputitem/) * [RunToolSearchCallItem](/openai-agents-js/openai/agents/classes/runtoolsearchcallitem/) * [RunToolSearchOutputItem](/openai-agents-js/openai/agents/classes/runtoolsearchoutputitem/) * [Span](/openai-agents-js/openai/agents/classes/span/) * [StreamedRunResult](/openai-agents-js/openai/agents/classes/streamedrunresult/) * [SystemError](/openai-agents-js/openai/agents/classes/systemerror/) * [ToolCallError](/openai-agents-js/openai/agents/classes/toolcallerror/) * [ToolInputGuardrailTripwireTriggered](/openai-agents-js/openai/agents/classes/toolinputguardrailtripwiretriggered/) * [ToolOutputGuardrailTripwireTriggered](/openai-agents-js/openai/agents/classes/tooloutputguardrailtripwiretriggered/) * [ToolTimeoutError](/openai-agents-js/openai/agents/classes/tooltimeouterror/) * [Trace](/openai-agents-js/openai/agents/classes/trace/) * [TraceProvider](/openai-agents-js/openai/agents/classes/traceprovider/) * [Usage](/openai-agents-js/openai/agents/classes/usage/) * [UserError](/openai-agents-js/openai/agents/classes/usererror/) ## Interfaces [Section titled “Interfaces”](#interfaces) * [AgentConfiguration](/openai-agents-js/openai/agents/interfaces/agentconfiguration/) * [Editor](/openai-agents-js/openai/agents/interfaces/editor/) * [GuardrailFunctionOutput](/openai-agents-js/openai/agents/interfaces/guardrailfunctionoutput/) * [InputGuardrail](/openai-agents-js/openai/agents/interfaces/inputguardrail/) * [InputGuardrailFunctionArgs](/openai-agents-js/openai/agents/interfaces/inputguardrailfunctionargs/) * [InputGuardrailMetadata](/openai-agents-js/openai/agents/interfaces/inputguardrailmetadata/) * [InputGuardrailResult](/openai-agents-js/openai/agents/interfaces/inputguardrailresult/) * [MCPBlobResourceContent](/openai-agents-js/openai/agents/interfaces/mcpblobresourcecontent/) * [MCPListResourcesParams](/openai-agents-js/openai/agents/interfaces/mcplistresourcesparams/) * [MCPListResourcesResult](/openai-agents-js/openai/agents/interfaces/mcplistresourcesresult/) * [MCPListResourceTemplatesResult](/openai-agents-js/openai/agents/interfaces/mcplistresourcetemplatesresult/) * [MCPReadResourceResult](/openai-agents-js/openai/agents/interfaces/mcpreadresourceresult/) * [MCPResource](/openai-agents-js/openai/agents/interfaces/mcpresource/) * [MCPResourceTemplate](/openai-agents-js/openai/agents/interfaces/mcpresourcetemplate/) * [MCPServer](/openai-agents-js/openai/agents/interfaces/mcpserver/) * [MCPServerWithResources](/openai-agents-js/openai/agents/interfaces/mcpserverwithresources/) * [MCPTextResourceContent](/openai-agents-js/openai/agents/interfaces/mcptextresourcecontent/) * [MCPToolFilterContext](/openai-agents-js/openai/agents/interfaces/mcptoolfiltercontext/) * [MCPToolFilterStatic](/openai-agents-js/openai/agents/interfaces/mcptoolfilterstatic/) * [MCPToolMetaContext](/openai-agents-js/openai/agents/interfaces/mcptoolmetacontext/) * [Model](/openai-agents-js/openai/agents/interfaces/model/) * [ModelProvider](/openai-agents-js/openai/agents/interfaces/modelprovider/) * [OpenAIResponsesCompactionAwareSession](/openai-agents-js/openai/agents/interfaces/openairesponsescompactionawaresession/) * [OutputGuardrail](/openai-agents-js/openai/agents/interfaces/outputguardrail/) * [OutputGuardrailDefinition](/openai-agents-js/openai/agents/interfaces/outputguardraildefinition/) * [OutputGuardrailFunctionArgs](/openai-agents-js/openai/agents/interfaces/outputguardrailfunctionargs/) * [OutputGuardrailMetadata](/openai-agents-js/openai/agents/interfaces/outputguardrailmetadata/) * [OutputGuardrailResult](/openai-agents-js/openai/agents/interfaces/outputguardrailresult/) * [Session](/openai-agents-js/openai/agents/interfaces/session/) * [SessionHistoryRewriteAwareSession](/openai-agents-js/openai/agents/interfaces/sessionhistoryrewriteawaresession/) * [Shell](/openai-agents-js/openai/agents/interfaces/shell/) * [ToolGuardrailFunctionOutput](/openai-agents-js/openai/agents/interfaces/toolguardrailfunctionoutput/) * [ToolGuardrailMetadata](/openai-agents-js/openai/agents/interfaces/toolguardrailmetadata/) * [ToolInputGuardrailData](/openai-agents-js/openai/agents/interfaces/toolinputguardraildata/) * [ToolInputGuardrailDefinition](/openai-agents-js/openai/agents/interfaces/toolinputguardraildefinition/) * [ToolInputGuardrailResult](/openai-agents-js/openai/agents/interfaces/toolinputguardrailresult/) * [ToolOutputGuardrailData](/openai-agents-js/openai/agents/interfaces/tooloutputguardraildata/) * [ToolOutputGuardrailDefinition](/openai-agents-js/openai/agents/interfaces/tooloutputguardraildefinition/) * [ToolOutputGuardrailResult](/openai-agents-js/openai/agents/interfaces/tooloutputguardrailresult/) * [TracingExporter](/openai-agents-js/openai/agents/interfaces/tracingexporter/) * [TracingProcessor](/openai-agents-js/openai/agents/interfaces/tracingprocessor/) ## Type Aliases [Section titled “Type Aliases”](#type-aliases) * [AgentConfigWithHandoffs](/openai-agents-js/openai/agents/type-aliases/agentconfigwithhandoffs/) * [AgentInputItem](/openai-agents-js/openai/agents/type-aliases/agentinputitem/) * [AgentOptions](/openai-agents-js/openai/agents/type-aliases/agentoptions/) * [AgentOutputItem](/openai-agents-js/openai/agents/type-aliases/agentoutputitem/) * [AgentOutputType](/openai-agents-js/openai/agents/type-aliases/agentoutputtype/) * [AgentSpanData](/openai-agents-js/openai/agents/type-aliases/agentspandata/) * [AgentToolInvocation](/openai-agents-js/openai/agents/type-aliases/agenttoolinvocation/) * [ApplyPatchCallItem](/openai-agents-js/openai/agents/type-aliases/applypatchcallitem/) * [ApplyPatchCallItem](/openai-agents-js/openai/agents/type-aliases/applypatchcallitem-1/) * [ApplyPatchCallResultItem](/openai-agents-js/openai/agents/type-aliases/applypatchcallresultitem/) * [ApplyPatchCallResultItem](/openai-agents-js/openai/agents/type-aliases/applypatchcallresultitem-1/) * [ApplyPatchOperation](/openai-agents-js/openai/agents/type-aliases/applypatchoperation/) * [ApplyPatchOperation](/openai-agents-js/openai/agents/type-aliases/applypatchoperation-1/) * [ApplyPatchResult](/openai-agents-js/openai/agents/type-aliases/applypatchresult/) * [ApplyPatchTool](/openai-agents-js/openai/agents/type-aliases/applypatchtool/) * [AssistantMessageItem](/openai-agents-js/openai/agents/type-aliases/assistantmessageitem/) * [AssistantMessageItem](/openai-agents-js/openai/agents/type-aliases/assistantmessageitem-1/) * [CallModelInputFilter](/openai-agents-js/openai/agents/type-aliases/callmodelinputfilter/) * [CallModelInputFilterArgs](/openai-agents-js/openai/agents/type-aliases/callmodelinputfilterargs/) * [ClientToolSearchExecutor](/openai-agents-js/openai/agents/type-aliases/clienttoolsearchexecutor/) * [ClientToolSearchExecutorArgs](/openai-agents-js/openai/agents/type-aliases/clienttoolsearchexecutorargs/) * [ClientToolSearchExecutorResult](/openai-agents-js/openai/agents/type-aliases/clienttoolsearchexecutorresult/) * [CompletedAgentToolInvocationRunResult](/openai-agents-js/openai/agents/type-aliases/completedagenttoolinvocationrunresult/) * [Computer](/openai-agents-js/openai/agents/type-aliases/computer/) * [ComputerCallResultItem](/openai-agents-js/openai/agents/type-aliases/computercallresultitem/) * [ComputerCallResultItem](/openai-agents-js/openai/agents/type-aliases/computercallresultitem-1/) * [ComputerOnSafetyCheckFunction](/openai-agents-js/openai/agents/type-aliases/computeronsafetycheckfunction/) * [ComputerSafetyCheck](/openai-agents-js/openai/agents/type-aliases/computersafetycheck/) * [ComputerSafetyCheckResult](/openai-agents-js/openai/agents/type-aliases/computersafetycheckresult/) * [ComputerTool](/openai-agents-js/openai/agents/type-aliases/computertool/) * [ComputerUseCallItem](/openai-agents-js/openai/agents/type-aliases/computerusecallitem/) * [ComputerUseCallItem](/openai-agents-js/openai/agents/type-aliases/computerusecallitem-1/) * [CustomSpanData](/openai-agents-js/openai/agents/type-aliases/customspandata/) * [EditorInvocationContext](/openai-agents-js/openai/agents/type-aliases/editorinvocationcontext/) * [FunctionCallItem](/openai-agents-js/openai/agents/type-aliases/functioncallitem/) * [FunctionCallItem](/openai-agents-js/openai/agents/type-aliases/functioncallitem-1/) * [FunctionCallResultItem](/openai-agents-js/openai/agents/type-aliases/functioncallresultitem/) * [FunctionCallResultItem](/openai-agents-js/openai/agents/type-aliases/functioncallresultitem-1/) * [FunctionSpanData](/openai-agents-js/openai/agents/type-aliases/functionspandata/) * [FunctionTool](/openai-agents-js/openai/agents/type-aliases/functiontool/) * [FunctionToolResult](/openai-agents-js/openai/agents/type-aliases/functiontoolresult/) * [FunctionToolTimeoutBehavior](/openai-agents-js/openai/agents/type-aliases/functiontooltimeoutbehavior/) * [GenerationSpanData](/openai-agents-js/openai/agents/type-aliases/generationspandata/) * [GenerationUsageData](/openai-agents-js/openai/agents/type-aliases/generationusagedata/) * [GetAllMcpToolsOptions](/openai-agents-js/openai/agents/type-aliases/getallmcptoolsoptions/) * [GuardrailSpanData](/openai-agents-js/openai/agents/type-aliases/guardrailspandata/) * [HandoffEnabledFunction](/openai-agents-js/openai/agents/type-aliases/handoffenabledfunction/) * [HandoffInputData](/openai-agents-js/openai/agents/type-aliases/handoffinputdata/) * [HandoffSpanData](/openai-agents-js/openai/agents/type-aliases/handoffspandata/) * [HostedMCPTool](/openai-agents-js/openai/agents/type-aliases/hostedmcptool/) * [HostedTool](/openai-agents-js/openai/agents/type-aliases/hostedtool/) * [HostedToolCallItem](/openai-agents-js/openai/agents/type-aliases/hostedtoolcallitem/) * [HostedToolCallItem](/openai-agents-js/openai/agents/type-aliases/hostedtoolcallitem-1/) * [IndividualRunOptions](/openai-agents-js/openai/agents/type-aliases/individualrunoptions/) * [InputGuardrailFunction](/openai-agents-js/openai/agents/type-aliases/inputguardrailfunction/) * [JsonSchemaDefinition](/openai-agents-js/openai/agents/type-aliases/jsonschemadefinition/) * [MCPListToolsSpanData](/openai-agents-js/openai/agents/type-aliases/mcplisttoolsspandata/) * [MCPResourceContent](/openai-agents-js/openai/agents/type-aliases/mcpresourcecontent/) * [MCPServersOptions](/openai-agents-js/openai/agents/type-aliases/mcpserversoptions/) * [MCPServersReconnectOptions](/openai-agents-js/openai/agents/type-aliases/mcpserversreconnectoptions/) * [MCPToolCacheKeyGenerator](/openai-agents-js/openai/agents/type-aliases/mcptoolcachekeygenerator/) * [MCPToolErrorFunction](/openai-agents-js/openai/agents/type-aliases/mcptoolerrorfunction/) * [MCPToolFilterCallable](/openai-agents-js/openai/agents/type-aliases/mcptoolfiltercallable/) * [MCPToolMetaResolver](/openai-agents-js/openai/agents/type-aliases/mcptoolmetaresolver/) * [ModelInputData](/openai-agents-js/openai/agents/type-aliases/modelinputdata/) * [ModelRequest](/openai-agents-js/openai/agents/type-aliases/modelrequest/) * [ModelResponse](/openai-agents-js/openai/agents/type-aliases/modelresponse/) * [ModelRetryAdvice](/openai-agents-js/openai/agents/type-aliases/modelretryadvice/) * [ModelRetryAdviceRequest](/openai-agents-js/openai/agents/type-aliases/modelretryadvicerequest/) * [ModelRetryBackoffSettings](/openai-agents-js/openai/agents/type-aliases/modelretrybackoffsettings/) * [ModelRetryNormalizedError](/openai-agents-js/openai/agents/type-aliases/modelretrynormalizederror/) * [ModelRetrySettings](/openai-agents-js/openai/agents/type-aliases/modelretrysettings/) * [ModelSettings](/openai-agents-js/openai/agents/type-aliases/modelsettings/) * [ModelSettingsContextManagement](/openai-agents-js/openai/agents/type-aliases/modelsettingscontextmanagement/) * [ModelSettingsToolChoice](/openai-agents-js/openai/agents/type-aliases/modelsettingstoolchoice/) * [NonStreamRunOptions](/openai-agents-js/openai/agents/type-aliases/nonstreamrunoptions/) * [OpenAIChatCompletionsModelOptions](/openai-agents-js/openai/agents/type-aliases/openaichatcompletionsmodeloptions/) * [OpenAIChatCompletionsRawModelStreamEvent](/openai-agents-js/openai/agents/type-aliases/openaichatcompletionsrawmodelstreamevent/) * [OpenAIConversationsSessionOptions](/openai-agents-js/openai/agents/type-aliases/openaiconversationssessionoptions/) * [OpenAIProviderOptions](/openai-agents-js/openai/agents/type-aliases/openaiprovideroptions/) * [OpenAIRawModelEventSource](/openai-agents-js/openai/agents/type-aliases/openairawmodeleventsource/) * [OpenAIResponsesCompactionArgs](/openai-agents-js/openai/agents/type-aliases/openairesponsescompactionargs/) * [OpenAIResponsesCompactionDecisionContext](/openai-agents-js/openai/agents/type-aliases/openairesponsescompactiondecisioncontext/) * [OpenAIResponsesCompactionMode](/openai-agents-js/openai/agents/type-aliases/openairesponsescompactionmode/) * [OpenAIResponsesCompactionResult](/openai-agents-js/openai/agents/type-aliases/openairesponsescompactionresult/) * [OpenAIResponsesCompactionSessionOptions](/openai-agents-js/openai/agents/type-aliases/openairesponsescompactionsessionoptions/) * [OpenAIResponsesRawModelStreamEvent](/openai-agents-js/openai/agents/type-aliases/openairesponsesrawmodelstreamevent/) * [OpenAIResponsesWebSocketOptions](/openai-agents-js/openai/agents/type-aliases/openairesponseswebsocketoptions/) * [OpenAITracingExporterOptions](/openai-agents-js/openai/agents/type-aliases/openaitracingexporteroptions/) * [OutputGuardrailFunction](/openai-agents-js/openai/agents/type-aliases/outputguardrailfunction/) * [ReasoningItem](/openai-agents-js/openai/agents/type-aliases/reasoningitem/) * [ReasoningItem](/openai-agents-js/openai/agents/type-aliases/reasoningitem-1/) * [ReasoningItemIdPolicy](/openai-agents-js/openai/agents/type-aliases/reasoningitemidpolicy/) * [ResponseSpanData](/openai-agents-js/openai/agents/type-aliases/responsespandata/) * [ResponseStreamEvent](/openai-agents-js/openai/agents/type-aliases/responsestreamevent/) * [ResponsesWebSocketSession](/openai-agents-js/openai/agents/type-aliases/responseswebsocketsession/) * [ResponsesWebSocketSessionOptions](/openai-agents-js/openai/agents/type-aliases/responseswebsocketsessionoptions/) * [RetryDecision](/openai-agents-js/openai/agents/type-aliases/retrydecision/) * [RetryPolicy](/openai-agents-js/openai/agents/type-aliases/retrypolicy/) * [RetryPolicyContext](/openai-agents-js/openai/agents/type-aliases/retrypolicycontext/) * [RunConfig](/openai-agents-js/openai/agents/type-aliases/runconfig/) * [RunErrorData](/openai-agents-js/openai/agents/type-aliases/runerrordata/) * [RunErrorHandler](/openai-agents-js/openai/agents/type-aliases/runerrorhandler/) * [RunErrorHandlerInput](/openai-agents-js/openai/agents/type-aliases/runerrorhandlerinput/) * [RunErrorHandlerResult](/openai-agents-js/openai/agents/type-aliases/runerrorhandlerresult/) * [RunErrorHandlers](/openai-agents-js/openai/agents/type-aliases/runerrorhandlers/) * [RunErrorKind](/openai-agents-js/openai/agents/type-aliases/runerrorkind/) * [RunItem](/openai-agents-js/openai/agents/type-aliases/runitem/) * [RunStreamEvent](/openai-agents-js/openai/agents/type-aliases/runstreamevent/) * [SerializedHandoff](/openai-agents-js/openai/agents/type-aliases/serializedhandoff/) * [SerializedOutputType](/openai-agents-js/openai/agents/type-aliases/serializedoutputtype/) * [SerializedTool](/openai-agents-js/openai/agents/type-aliases/serializedtool/) * [SessionHistoryMutation](/openai-agents-js/openai/agents/type-aliases/sessionhistorymutation/) * [SessionHistoryRewriteArgs](/openai-agents-js/openai/agents/type-aliases/sessionhistoryrewriteargs/) * [SessionInputCallback](/openai-agents-js/openai/agents/type-aliases/sessioninputcallback/) * [ShellAction](/openai-agents-js/openai/agents/type-aliases/shellaction/) * [ShellCallItem](/openai-agents-js/openai/agents/type-aliases/shellcallitem/) * [ShellCallItem](/openai-agents-js/openai/agents/type-aliases/shellcallitem-1/) * [ShellCallResultItem](/openai-agents-js/openai/agents/type-aliases/shellcallresultitem/) * [ShellCallResultItem](/openai-agents-js/openai/agents/type-aliases/shellcallresultitem-1/) * [ShellOutputResult](/openai-agents-js/openai/agents/type-aliases/shelloutputresult/) * [ShellResult](/openai-agents-js/openai/agents/type-aliases/shellresult/) * [ShellTool](/openai-agents-js/openai/agents/type-aliases/shelltool/) * [ShellToolContainerAutoEnvironment](/openai-agents-js/openai/agents/type-aliases/shelltoolcontainerautoenvironment/) * [ShellToolContainerNetworkPolicy](/openai-agents-js/openai/agents/type-aliases/shelltoolcontainernetworkpolicy/) * [ShellToolContainerNetworkPolicyAllowlist](/openai-agents-js/openai/agents/type-aliases/shelltoolcontainernetworkpolicyallowlist/) * [ShellToolContainerNetworkPolicyDisabled](/openai-agents-js/openai/agents/type-aliases/shelltoolcontainernetworkpolicydisabled/) * [ShellToolContainerNetworkPolicyDomainSecret](/openai-agents-js/openai/agents/type-aliases/shelltoolcontainernetworkpolicydomainsecret/) * [ShellToolContainerReferenceEnvironment](/openai-agents-js/openai/agents/type-aliases/shelltoolcontainerreferenceenvironment/) * [ShellToolContainerSkill](/openai-agents-js/openai/agents/type-aliases/shelltoolcontainerskill/) * [ShellToolEnvironment](/openai-agents-js/openai/agents/type-aliases/shelltoolenvironment/) * [ShellToolHostedEnvironment](/openai-agents-js/openai/agents/type-aliases/shelltoolhostedenvironment/) * [ShellToolInlineSkill](/openai-agents-js/openai/agents/type-aliases/shelltoolinlineskill/) * [ShellToolInlineSkillSource](/openai-agents-js/openai/agents/type-aliases/shelltoolinlineskillsource/) * [ShellToolLocalEnvironment](/openai-agents-js/openai/agents/type-aliases/shelltoollocalenvironment/) * [ShellToolLocalSkill](/openai-agents-js/openai/agents/type-aliases/shelltoollocalskill/) * [ShellToolSkillReference](/openai-agents-js/openai/agents/type-aliases/shelltoolskillreference/) * [SpanData](/openai-agents-js/openai/agents/type-aliases/spandata/) * [SpanError](/openai-agents-js/openai/agents/type-aliases/spanerror/) * [SpanOptions](/openai-agents-js/openai/agents/type-aliases/spanoptions/) * [SpeechGroupSpanData](/openai-agents-js/openai/agents/type-aliases/speechgroupspandata/) * [SpeechSpanData](/openai-agents-js/openai/agents/type-aliases/speechspandata/) * [StreamEvent](/openai-agents-js/openai/agents/type-aliases/streamevent/) * [StreamEvent](/openai-agents-js/openai/agents/type-aliases/streamevent-1/) * [StreamEventGenericItem](/openai-agents-js/openai/agents/type-aliases/streameventgenericitem/) * [StreamEventGenericItem](/openai-agents-js/openai/agents/type-aliases/streameventgenericitem-1/) * [StreamEventResponseCompleted](/openai-agents-js/openai/agents/type-aliases/streameventresponsecompleted/) * [StreamEventResponseCompleted](/openai-agents-js/openai/agents/type-aliases/streameventresponsecompleted-1/) * [StreamEventResponseStarted](/openai-agents-js/openai/agents/type-aliases/streameventresponsestarted/) * [StreamEventResponseStarted](/openai-agents-js/openai/agents/type-aliases/streameventresponsestarted-1/) * [StreamEventTextStream](/openai-agents-js/openai/agents/type-aliases/streameventtextstream/) * [StreamEventTextStream](/openai-agents-js/openai/agents/type-aliases/streameventtextstream-1/) * [StreamRunOptions](/openai-agents-js/openai/agents/type-aliases/streamrunoptions/) * [SystemMessageItem](/openai-agents-js/openai/agents/type-aliases/systemmessageitem/) * [TextOutput](/openai-agents-js/openai/agents/type-aliases/textoutput/) * [Tool](/openai-agents-js/openai/agents/type-aliases/tool/) * [ToolCallOutputContent](/openai-agents-js/openai/agents/type-aliases/toolcalloutputcontent/) * [ToolCallOutputContent](/openai-agents-js/openai/agents/type-aliases/toolcalloutputcontent-1/) * [ToolCallStructuredOutput](/openai-agents-js/openai/agents/type-aliases/toolcallstructuredoutput/) * [ToolCallStructuredOutput](/openai-agents-js/openai/agents/type-aliases/toolcallstructuredoutput-1/) * [ToolEnabledFunction](/openai-agents-js/openai/agents/type-aliases/toolenabledfunction/) * [ToolErrorFormatter](/openai-agents-js/openai/agents/type-aliases/toolerrorformatter/) * [ToolErrorFormatterArgs](/openai-agents-js/openai/agents/type-aliases/toolerrorformatterargs/) * [ToolExecuteArgument](/openai-agents-js/openai/agents/type-aliases/toolexecuteargument/) * [ToolExecutionConfig](/openai-agents-js/openai/agents/type-aliases/toolexecutionconfig/) * [ToolGuardrailBehavior](/openai-agents-js/openai/agents/type-aliases/toolguardrailbehavior/) * [ToolInputGuardrailFunction](/openai-agents-js/openai/agents/type-aliases/toolinputguardrailfunction/) * [ToolInputParameters](/openai-agents-js/openai/agents/type-aliases/toolinputparameters/) * [ToolNamespaceOptions](/openai-agents-js/openai/agents/type-aliases/toolnamespaceoptions/) * [ToolOptions](/openai-agents-js/openai/agents/type-aliases/tooloptions/) * [ToolOptionsWithGuardrails](/openai-agents-js/openai/agents/type-aliases/tooloptionswithguardrails/) * [ToolOutputFileContent](/openai-agents-js/openai/agents/type-aliases/tooloutputfilecontent/) * [ToolOutputFileContent](/openai-agents-js/openai/agents/type-aliases/tooloutputfilecontent-1/) * [ToolOutputGuardrailFunction](/openai-agents-js/openai/agents/type-aliases/tooloutputguardrailfunction/) * [ToolOutputImage](/openai-agents-js/openai/agents/type-aliases/tooloutputimage/) * [ToolOutputImage](/openai-agents-js/openai/agents/type-aliases/tooloutputimage-1/) * [ToolOutputText](/openai-agents-js/openai/agents/type-aliases/tooloutputtext/) * [ToolOutputText](/openai-agents-js/openai/agents/type-aliases/tooloutputtext-1/) * [ToolReference](/openai-agents-js/openai/agents/type-aliases/toolreference/) * [ToolReference](/openai-agents-js/openai/agents/type-aliases/toolreference-1/) * [ToolSearchCallArguments](/openai-agents-js/openai/agents/type-aliases/toolsearchcallarguments/) * [ToolSearchCallArguments](/openai-agents-js/openai/agents/type-aliases/toolsearchcallarguments-1/) * [ToolSearchCallItem](/openai-agents-js/openai/agents/type-aliases/toolsearchcallitem/) * [ToolSearchCallItem](/openai-agents-js/openai/agents/type-aliases/toolsearchcallitem-1/) * [ToolSearchOutputItem](/openai-agents-js/openai/agents/type-aliases/toolsearchoutputitem/) * [ToolSearchOutputItem](/openai-agents-js/openai/agents/type-aliases/toolsearchoutputitem-1/) * [ToolSearchOutputTool](/openai-agents-js/openai/agents/type-aliases/toolsearchoutputtool/) * [ToolSearchOutputTool](/openai-agents-js/openai/agents/type-aliases/toolsearchoutputtool-1/) * [ToolSearchTool](/openai-agents-js/openai/agents/type-aliases/toolsearchtool/) * [ToolsToFinalOutputResult](/openai-agents-js/openai/agents/type-aliases/toolstofinaloutputresult/) * [ToolTimeoutErrorFunction](/openai-agents-js/openai/agents/type-aliases/tooltimeouterrorfunction/) * [ToolToFinalOutputFunction](/openai-agents-js/openai/agents/type-aliases/tooltofinaloutputfunction/) * [ToolUseBehavior](/openai-agents-js/openai/agents/type-aliases/toolusebehavior/) * [ToolUseBehaviorFlags](/openai-agents-js/openai/agents/type-aliases/toolusebehaviorflags/) * [TracingConfig](/openai-agents-js/openai/agents/type-aliases/tracingconfig/) * [TranscriptionSpanData](/openai-agents-js/openai/agents/type-aliases/transcriptionspandata/) * [UnknownContext](/openai-agents-js/openai/agents/type-aliases/unknowncontext/) * [UnknownItem](/openai-agents-js/openai/agents/type-aliases/unknownitem/) * [UnknownItem](/openai-agents-js/openai/agents/type-aliases/unknownitem-1/) * [UserMessageItem](/openai-agents-js/openai/agents/type-aliases/usermessageitem/) * [UserMessageItem](/openai-agents-js/openai/agents/type-aliases/usermessageitem-1/) ## Variables [Section titled “Variables”](#variables) * [OPENAI\_CHAT\_COMPLETIONS\_RAW\_MODEL\_EVENT\_SOURCE](/openai-agents-js/openai/agents/variables/openai_chat_completions_raw_model_event_source/) * [OPENAI\_DEFAULT\_MODEL\_ENV\_VARIABLE\_NAME](/openai-agents-js/openai/agents/variables/openai_default_model_env_variable_name/) * [OPENAI\_RESPONSES\_RAW\_MODEL\_EVENT\_SOURCE](/openai-agents-js/openai/agents/variables/openai_responses_raw_model_event_source/) * [retryPolicies](/openai-agents-js/openai/agents/variables/retrypolicies/) * [RuntimeEventEmitter](/openai-agents-js/openai/agents/variables/runtimeeventemitter/) * [ToolGuardrailFunctionOutputFactory](/openai-agents-js/openai/agents/variables/toolguardrailfunctionoutputfactory/) * [withAgentSpan](/openai-agents-js/openai/agents/variables/withagentspan/) * [withCustomSpan](/openai-agents-js/openai/agents/variables/withcustomspan/) * [withFunctionSpan](/openai-agents-js/openai/agents/variables/withfunctionspan/) * [withGenerationSpan](/openai-agents-js/openai/agents/variables/withgenerationspan/) * [withGuardrailSpan](/openai-agents-js/openai/agents/variables/withguardrailspan/) * [withHandoffSpan](/openai-agents-js/openai/agents/variables/withhandoffspan/) * [withMCPListToolsSpan](/openai-agents-js/openai/agents/variables/withmcplisttoolsspan/) * [withResponseSpan](/openai-agents-js/openai/agents/variables/withresponsespan/) * [withSpeechGroupSpan](/openai-agents-js/openai/agents/variables/withspeechgroupspan/) * [withSpeechSpan](/openai-agents-js/openai/agents/variables/withspeechspan/) * [withTranscriptionSpan](/openai-agents-js/openai/agents/variables/withtranscriptionspan/) ## Functions [Section titled “Functions”](#functions) * [addTraceProcessor](/openai-agents-js/openai/agents/functions/addtraceprocessor/) * [applyDiff](/openai-agents-js/openai/agents/functions/applydiff/) * [applyPatchTool](/openai-agents-js/openai/agents/functions/applypatchtool/) * [applySessionHistoryMutations](/openai-agents-js/openai/agents/functions/applysessionhistorymutations/) * [assistant](/openai-agents-js/openai/agents/functions/assistant/) * [attachClientToolSearchExecutor](/openai-agents-js/openai/agents/functions/attachclienttoolsearchexecutor/) * [codeInterpreterTool](/openai-agents-js/openai/agents/functions/codeinterpretertool/) * [computerTool](/openai-agents-js/openai/agents/functions/computertool/) * [connectMcpServers](/openai-agents-js/openai/agents/functions/connectmcpservers/) * [createAgentSpan](/openai-agents-js/openai/agents/functions/createagentspan/) * [createCustomSpan](/openai-agents-js/openai/agents/functions/createcustomspan/) * [createFunctionSpan](/openai-agents-js/openai/agents/functions/createfunctionspan/) * [createGenerationSpan](/openai-agents-js/openai/agents/functions/creategenerationspan/) * [createGuardrailSpan](/openai-agents-js/openai/agents/functions/createguardrailspan/) * [createHandoffSpan](/openai-agents-js/openai/agents/functions/createhandoffspan/) * [createMCPListToolsSpan](/openai-agents-js/openai/agents/functions/createmcplisttoolsspan/) * [createMCPToolStaticFilter](/openai-agents-js/openai/agents/functions/createmcptoolstaticfilter/) * [createResponseSpan](/openai-agents-js/openai/agents/functions/createresponsespan/) * [createSpeechGroupSpan](/openai-agents-js/openai/agents/functions/createspeechgroupspan/) * [createSpeechSpan](/openai-agents-js/openai/agents/functions/createspeechspan/) * [createTranscriptionSpan](/openai-agents-js/openai/agents/functions/createtranscriptionspan/) * [defineOutputGuardrail](/openai-agents-js/openai/agents/functions/defineoutputguardrail/) * [defineToolInputGuardrail](/openai-agents-js/openai/agents/functions/definetoolinputguardrail/) * [defineToolOutputGuardrail](/openai-agents-js/openai/agents/functions/definetooloutputguardrail/) * [extractAllTextOutput](/openai-agents-js/openai/agents/functions/extractalltextoutput/) * [fileSearchTool](/openai-agents-js/openai/agents/functions/filesearchtool/) * [generateGroupId](/openai-agents-js/openai/agents/functions/generategroupid/) * [generateSpanId](/openai-agents-js/openai/agents/functions/generatespanid/) * [generateTraceId](/openai-agents-js/openai/agents/functions/generatetraceid/) * [getAllMcpTools](/openai-agents-js/openai/agents/functions/getallmcptools/) * [getClientToolSearchExecutor](/openai-agents-js/openai/agents/functions/getclienttoolsearchexecutor/) * [getCurrentSpan](/openai-agents-js/openai/agents/functions/getcurrentspan/) * [getCurrentTrace](/openai-agents-js/openai/agents/functions/getcurrenttrace/) * [getDefaultModel](/openai-agents-js/openai/agents/functions/getdefaultmodel/) * [getDefaultModelSettings](/openai-agents-js/openai/agents/functions/getdefaultmodelsettings/) * [getGlobalTraceProvider](/openai-agents-js/openai/agents/functions/getglobaltraceprovider/) * [getHandoff](/openai-agents-js/openai/agents/functions/gethandoff/) * [getLogger](/openai-agents-js/openai/agents/functions/getlogger/) * [getOrCreateTrace](/openai-agents-js/openai/agents/functions/getorcreatetrace/) * [getToolSearchRuntimeToolKey](/openai-agents-js/openai/agents/functions/gettoolsearchruntimetoolkey/) * [getTransferMessage](/openai-agents-js/openai/agents/functions/gettransfermessage/) * [gpt5ReasoningSettingsRequired](/openai-agents-js/openai/agents/functions/gpt5reasoningsettingsrequired/) * [handoff](/openai-agents-js/openai/agents/functions/handoff/) * [hostedMcpTool](/openai-agents-js/openai/agents/functions/hostedmcptool/) * [imageGenerationTool](/openai-agents-js/openai/agents/functions/imagegenerationtool/) * [invalidateServerToolsCache](/openai-agents-js/openai/agents/functions/invalidateservertoolscache/) * [invokeFunctionTool](/openai-agents-js/openai/agents/functions/invokefunctiontool/) * [isGpt5Default](/openai-agents-js/openai/agents/functions/isgpt5default/) * [isOpenAIChatCompletionsRawModelStreamEvent](/openai-agents-js/openai/agents/functions/isopenaichatcompletionsrawmodelstreamevent/) * [isOpenAIResponsesCompactionAwareSession](/openai-agents-js/openai/agents/functions/isopenairesponsescompactionawaresession/) * [isOpenAIResponsesRawModelStreamEvent](/openai-agents-js/openai/agents/functions/isopenairesponsesrawmodelstreamevent/) * [isSessionHistoryRewriteAwareSession](/openai-agents-js/openai/agents/functions/issessionhistoryrewriteawaresession/) * [mcpToFunctionTool](/openai-agents-js/openai/agents/functions/mcptofunctiontool/) * [resetCurrentSpan](/openai-agents-js/openai/agents/functions/resetcurrentspan/) * [resolveToolInputGuardrails](/openai-agents-js/openai/agents/functions/resolvetoolinputguardrails/) * [resolveToolOutputGuardrails](/openai-agents-js/openai/agents/functions/resolvetooloutputguardrails/) * [run](/openai-agents-js/openai/agents/functions/run/) * [runToolInputGuardrails](/openai-agents-js/openai/agents/functions/runtoolinputguardrails/) * [runToolOutputGuardrails](/openai-agents-js/openai/agents/functions/runtooloutputguardrails/) * [setCurrentSpan](/openai-agents-js/openai/agents/functions/setcurrentspan/) * [setDefaultModelProvider](/openai-agents-js/openai/agents/functions/setdefaultmodelprovider/) * [setDefaultOpenAIClient](/openai-agents-js/openai/agents/functions/setdefaultopenaiclient/) * [setDefaultOpenAIKey](/openai-agents-js/openai/agents/functions/setdefaultopenaikey/) * [setDefaultOpenAITracingExporter](/openai-agents-js/openai/agents/functions/setdefaultopenaitracingexporter/) * [setOpenAIAPI](/openai-agents-js/openai/agents/functions/setopenaiapi/) * [setOpenAIResponsesTransport](/openai-agents-js/openai/agents/functions/setopenairesponsestransport/) * [setTraceProcessors](/openai-agents-js/openai/agents/functions/settraceprocessors/) * [setTracingDisabled](/openai-agents-js/openai/agents/functions/settracingdisabled/) * [setTracingExportApiKey](/openai-agents-js/openai/agents/functions/settracingexportapikey/) * [shellTool](/openai-agents-js/openai/agents/functions/shelltool/) * [startOpenAIConversationsSession](/openai-agents-js/openai/agents/functions/startopenaiconversationssession/) * [startTraceExportLoop](/openai-agents-js/openai/agents/functions/starttraceexportloop/) * [system](/openai-agents-js/openai/agents/functions/system/) * [tool](/openai-agents-js/openai/agents/functions/tool/) * [toolNamespace](/openai-agents-js/openai/agents/functions/toolnamespace/) * [toolSearchTool](/openai-agents-js/openai/agents/functions/toolsearchtool/) * [user](/openai-agents-js/openai/agents/functions/user/) * [webSearchTool](/openai-agents-js/openai/agents/functions/websearchtool/) * [withResponsesWebSocketSession](/openai-agents-js/openai/agents/functions/withresponseswebsocketsession/) * [withTrace](/openai-agents-js/openai/agents/functions/withtrace/) # ModelBehaviorError Error thrown when a model behavior is unexpected. ## Extends [Section titled “Extends”](#extends) * `AgentsError` ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new ModelBehaviorError(message, state?): ModelBehaviorError; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ---------------------------------------- | | `message` | `string` | | `state?` | `RunState`<`any`, `Agent`<`any`, `any`>> | #### Returns [Section titled “Returns”](#returns) `ModelBehaviorError` #### Inherited from [Section titled “Inherited from”](#inherited-from) ```ts AgentsError.constructor ``` ## Properties [Section titled “Properties”](#properties) ### message [Section titled “message”](#message) ```ts message: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-1) ```ts AgentsError.message ``` *** ### name [Section titled “name”](#name) ```ts name: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-2) ```ts AgentsError.name ``` *** ### stack? [Section titled “stack?”](#stack) ```ts optional stack?: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-3) ```ts AgentsError.stack ``` *** ### state? [Section titled “state?”](#state) ```ts optional state?: RunState>; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-4) ```ts AgentsError.state ``` *** ### stackTraceLimit [Section titled “stackTraceLimit”](#stacktracelimit) ```ts static stackTraceLimit: number; ``` The `Error.stackTraceLimit` property specifies the number of stack frames collected by a stack trace (whether generated by `new Error().stack` or `Error.captureStackTrace(obj)`). The default value is `10` but may be set to any valid JavaScript number. Changes will affect any stack trace captured *after* the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames. #### Inherited from [Section titled “Inherited from”](#inherited-from-5) ```ts AgentsError.stackTraceLimit ``` ## Methods [Section titled “Methods”](#methods) ### captureStackTrace() [Section titled “captureStackTrace()”](#capturestacktrace) ```ts static captureStackTrace(targetObject, constructorOpt?): void; ``` Creates a `.stack` property on `targetObject`, which when accessed returns a string representing the location in the code at which `Error.captureStackTrace()` was called. ```js const myObject = {}; Error.captureStackTrace(myObject); myObject.stack; // Similar to `new Error().stack` ``` The first line of the trace will be prefixed with `${myObject.name}: ${myObject.message}`. The optional `constructorOpt` argument accepts a function. If given, all frames above `constructorOpt`, including `constructorOpt`, will be omitted from the generated stack trace. The `constructorOpt` argument is useful for hiding implementation details of error generation from the user. For instance: ```js function a() { b(); } function b() { c(); } function c() { // Create an error without stack trace to avoid calculating the stack trace twice. const { stackTraceLimit } = Error; Error.stackTraceLimit = 0; const error = new Error(); Error.stackTraceLimit = stackTraceLimit; // Capture the stack trace above function b Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace throw error; } a(); ``` #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | ----------------- | ---------- | | `targetObject` | `object` | | `constructorOpt?` | `Function` | #### Returns [Section titled “Returns”](#returns-1) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-6) ```ts AgentsError.captureStackTrace ``` *** ### prepareStackTrace() [Section titled “prepareStackTrace()”](#preparestacktrace) ```ts static prepareStackTrace(err, stackTraces): any; ``` #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | ------------- | ------------- | | `err` | `Error` | | `stackTraces` | `CallSite`\[] | #### Returns [Section titled “Returns”](#returns-2) `any` #### See [Section titled “See”](#see) #### Inherited from [Section titled “Inherited from”](#inherited-from-7) ```ts AgentsError.prepareStackTrace ``` # OpenAIRealtimeBase The transport layer is the layer that handles the connection to the model and the communication with the model. ## Extends [Section titled “Extends”](#extends) * `EventEmitterDelegate`<[`OpenAIRealtimeEventTypes`](/openai-agents-js/openai/agents/realtime/type-aliases/openairealtimeeventtypes/)> ## Extended by [Section titled “Extended by”](#extended-by) * [`OpenAIRealtimeWebRTC`](/openai-agents-js/openai/agents/realtime/classes/openairealtimewebrtc/) * [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents/realtime/classes/openairealtimewebsocket/) ## Implements [Section titled “Implements”](#implements) * [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/) ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new OpenAIRealtimeBase(options?): OpenAIRealtimeBase; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ---------- | --------------------------------------------------------------------------------------------------------------- | | `options?` | [`OpenAIRealtimeBaseOptions`](/openai-agents-js/openai/agents/realtime/type-aliases/openairealtimebaseoptions/) | #### Returns [Section titled “Returns”](#returns) `OpenAIRealtimeBase` #### Overrides [Section titled “Overrides”](#overrides) ```ts EventEmitterDelegate.constructor ``` ## Properties [Section titled “Properties”](#properties) ### muted [Section titled “muted”](#muted) ```ts abstract readonly muted: boolean | null; ``` Whether the input audio track is currently muted null if the muting is not handled by the transport layer #### Implementation of [Section titled “Implementation of”](#implementation-of) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/).[`muted`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/#muted) ## Accessors [Section titled “Accessors”](#accessors) ### \_tracingConfig [Section titled “\_tracingConfig”](#_tracingconfig) #### Set Signature [Section titled “Set Signature”](#set-signature) ```ts set _tracingConfig(tracingConfig): void; ``` Sets the internal tracing config. This is used to track the tracing config that has been set during the session.create event. ##### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | --------------- | --------------------------------- | | `tracingConfig` | `RealtimeTracingConfig` \| `null` | ##### Returns [Section titled “Returns”](#returns-1) `void` *** ### currentModel [Section titled “currentModel”](#currentmodel) #### Get Signature [Section titled “Get Signature”](#get-signature) ```ts get currentModel(): OpenAIRealtimeModels; ``` The current model that is being used by the transport layer. ##### Returns [Section titled “Returns”](#returns-2) [`OpenAIRealtimeModels`](/openai-agents-js/openai/agents/realtime/type-aliases/openairealtimemodels/) #### Set Signature [Section titled “Set Signature”](#set-signature-1) ```ts set currentModel(model): void; ``` The current model that is being used by the transport layer. **Note**: The model cannot be changed mid conversation. ##### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | --------- | ----------------------------------------------------------------------------------------------------- | | `model` | [`OpenAIRealtimeModels`](/openai-agents-js/openai/agents/realtime/type-aliases/openairealtimemodels/) | ##### Returns [Section titled “Returns”](#returns-3) `void` *** ### status [Section titled “status”](#status) #### Get Signature [Section titled “Get Signature”](#get-signature-1) ```ts get abstract status(): "connecting" | "connected" | "disconnected" | "disconnecting"; ``` ##### Returns [Section titled “Returns”](#returns-4) `"connecting"` | `"connected"` | `"disconnected"` | `"disconnecting"` #### Implementation of [Section titled “Implementation of”](#implementation-of-1) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/).[`status`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/#status) ## Methods [Section titled “Methods”](#methods) ### addImage() [Section titled “addImage()”](#addimage) ```ts addImage(image, options?): void; ``` Sends an image to the model #### Parameters [Section titled “Parameters”](#parameters-3) | Parameter | Type | Description | | -------------------------- | ---------------------------------- | -------------------------------------------- | | `image` | `string` | The image to send | | `options?` | { `triggerResponse?`: `boolean`; } | Additional options | | `options.triggerResponse?` | `boolean` | Whether to trigger a response from the model | #### Returns [Section titled “Returns”](#returns-5) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-2) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/).[`addImage`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/#addimage) *** ### buildSessionPayload() [Section titled “buildSessionPayload()”](#buildsessionpayload) ```ts buildSessionPayload(config): RealtimeSessionPayload; ``` Build the payload object expected by the Realtime API when creating or updating a session. The helper centralises the conversion from camelCase runtime config to the snake\_case payload required by the Realtime API so transports that need a one-off payload (for example SIP call acceptance) can reuse the same logic without duplicating private state. #### Parameters [Section titled “Parameters”](#parameters-4) | Parameter | Type | Description | | --------- | ------------------------------------------------------------------------------------------------------------------ | ------------------------------------------ | | `config` | `Partial`<[`RealtimeSessionConfig`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimesessionconfig/)> | The session config to merge with defaults. | #### Returns [Section titled “Returns”](#returns-6) [`RealtimeSessionPayload`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimesessionpayload/) *** ### close() [Section titled “close()”](#close) ```ts abstract close(): void; ``` Closes the connection to the model #### Returns [Section titled “Returns”](#returns-7) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-3) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/).[`close`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/#close) *** ### connect() [Section titled “connect()”](#connect) ```ts abstract connect(options): Promise; ``` Establishes the connection to the model and keeps the connection alive #### Parameters [Section titled “Parameters”](#parameters-5) | Parameter | Type | Description | | --------- | ------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------ | | `options` | [`RealtimeTransportLayerConnectOptions`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimetransportlayerconnectoptions/) | The options for the connection | #### Returns [Section titled “Returns”](#returns-8) `Promise`<`void`> #### Implementation of [Section titled “Implementation of”](#implementation-of-4) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/).[`connect`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/#connect) *** ### emit() [Section titled “emit()”](#emit) ```ts emit(type, ...args): boolean; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | --------------------------------------------------------------------------------------------------------------------------------------- | | `K` *extends* keyof [`RealtimeTransportEventTypes`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimetransporteventtypes/) | #### Parameters [Section titled “Parameters”](#parameters-6) | Parameter | Type | | --------- | ------------------------------------------------------------------------------------------------------------------- | | `type` | `K` | | …`args` | [`OpenAIRealtimeEventTypes`](/openai-agents-js/openai/agents/realtime/type-aliases/openairealtimeeventtypes/)\[`K`] | #### Returns [Section titled “Returns”](#returns-9) `boolean` #### Implementation of [Section titled “Implementation of”](#implementation-of-5) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/).[`emit`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/#emit) #### Inherited from [Section titled “Inherited from”](#inherited-from) ```ts EventEmitterDelegate.emit ``` *** ### interrupt() [Section titled “interrupt()”](#interrupt) ```ts abstract interrupt(): void; ``` Interrupts the current turn. Used for example when a guardrail is triggered #### Returns [Section titled “Returns”](#returns-10) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-6) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/).[`interrupt`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/#interrupt) *** ### mute() [Section titled “mute()”](#mute) ```ts abstract mute(muted): void; ``` Mutes the input audio track #### Parameters [Section titled “Parameters”](#parameters-7) | Parameter | Type | Description | | --------- | --------- | ------------------------------------- | | `muted` | `boolean` | Whether to mute the input audio track | #### Returns [Section titled “Returns”](#returns-11) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-7) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/).[`mute`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/#mute) *** ### off() [Section titled “off()”](#off) ```ts off(type, listener): EventEmitter; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-1) | Type Parameter | | --------------------------------------------------------------------------------------------------------------------------------------- | | `K` *extends* keyof [`RealtimeTransportEventTypes`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimetransporteventtypes/) | #### Parameters [Section titled “Parameters”](#parameters-8) | Parameter | Type | | ---------- | ------------------- | | `type` | `K` | | `listener` | (…`args`) => `void` | #### Returns [Section titled “Returns”](#returns-12) `EventEmitter`<`EventTypes`> #### Implementation of [Section titled “Implementation of”](#implementation-of-8) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/).[`off`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/#off) #### Inherited from [Section titled “Inherited from”](#inherited-from-1) ```ts EventEmitterDelegate.off ``` *** ### on() [Section titled “on()”](#on) ```ts on(type, listener): EventEmitter; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-2) | Type Parameter | | --------------------------------------------------------------------------------------------------------------------------------------- | | `K` *extends* keyof [`RealtimeTransportEventTypes`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimetransporteventtypes/) | #### Parameters [Section titled “Parameters”](#parameters-9) | Parameter | Type | | ---------- | ------------------- | | `type` | `K` | | `listener` | (…`args`) => `void` | #### Returns [Section titled “Returns”](#returns-13) `EventEmitter`<`EventTypes`> #### Implementation of [Section titled “Implementation of”](#implementation-of-9) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/).[`on`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/#on) #### Inherited from [Section titled “Inherited from”](#inherited-from-2) ```ts EventEmitterDelegate.on ``` *** ### once() [Section titled “once()”](#once) ```ts once(type, listener): EventEmitter; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-3) | Type Parameter | | --------------------------------------------------------------------------------------------------------------------------------------- | | `K` *extends* keyof [`RealtimeTransportEventTypes`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimetransporteventtypes/) | #### Parameters [Section titled “Parameters”](#parameters-10) | Parameter | Type | | ---------- | ------------------- | | `type` | `K` | | `listener` | (…`args`) => `void` | #### Returns [Section titled “Returns”](#returns-14) `EventEmitter`<`EventTypes`> #### Implementation of [Section titled “Implementation of”](#implementation-of-10) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/).[`once`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/#once) #### Inherited from [Section titled “Inherited from”](#inherited-from-3) ```ts EventEmitterDelegate.once ``` *** ### requestResponse() [Section titled “requestResponse()”](#requestresponse) ```ts requestResponse(response?): void; ``` Requests a new response for the current conversation turn. Implementations may defer the underlying `response.create` until the server has fully finished the prior response. #### Parameters [Section titled “Parameters”](#parameters-11) | Parameter | Type | Description | | ----------- | ------------------------- | ------------------------------------------- | | `response?` | `Record`<`string`, `any`> | Optional one-off response override payload. | #### Returns [Section titled “Returns”](#returns-15) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-11) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/).[`requestResponse`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/#requestresponse) *** ### resetHistory() [Section titled “resetHistory()”](#resethistory) ```ts resetHistory(oldHistory, newHistory): void; ``` Reset the history of the conversation. This will create a diff between the old and new history and send the necessary events to the Realtime API to update the history. #### Parameters [Section titled “Parameters”](#parameters-12) | Parameter | Type | Description | | ------------ | ---------------------------------------------------------------------------------------- | ------------------------------------ | | `oldHistory` | [`RealtimeItem`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimeitem/)\[] | The old history of the conversation. | | `newHistory` | [`RealtimeItem`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimeitem/)\[] | The new history of the conversation. | #### Returns [Section titled “Returns”](#returns-16) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-12) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/).[`resetHistory`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/#resethistory) *** ### sendAudio() [Section titled “sendAudio()”](#sendaudio) ```ts sendAudio(audio, options?): void; ``` Send an audio buffer to the Realtime API. If `{ commit: true }` is passed, the audio buffer will be committed and the model will start processing it. This is necessary if you have disabled turn detection / voice activity detection (VAD). #### Parameters [Section titled “Parameters”](#parameters-13) | Parameter | Type | Description | | ----------------- | ------------------------- | --------------------------------- | | `audio` | `ArrayBuffer` | The audio buffer to send. | | `options?` | { `commit?`: `boolean`; } | The options for the audio buffer. | | `options.commit?` | `boolean` | ‐ | #### Returns [Section titled “Returns”](#returns-17) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-13) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/).[`sendAudio`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/#sendaudio) *** ### sendEvent() [Section titled “sendEvent()”](#sendevent) ```ts abstract sendEvent(event): void; ``` Sends a raw event to the model #### Parameters [Section titled “Parameters”](#parameters-14) | Parameter | Type | Description | | --------- | ------------------------------------------------------------------------------------------------------- | ----------------- | | `event` | [`RealtimeClientMessage`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimeclientmessage/) | The event to send | #### Returns [Section titled “Returns”](#returns-18) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-14) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/).[`sendEvent`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/#sendevent) *** ### sendFunctionCallOutput() [Section titled “sendFunctionCallOutput()”](#sendfunctioncalloutput) ```ts sendFunctionCallOutput( toolCall, output, startResponse?): void; ``` Send the output of a function call to the Realtime API. #### Parameters [Section titled “Parameters”](#parameters-15) | Parameter | Type | Description | | ---------------- | --------------------------------------------------------------------------------------------------------- | --------------------------------------------------------- | | `toolCall` | [`TransportToolCallEvent`](/openai-agents-js/openai/agents/realtime/type-aliases/transporttoolcallevent/) | The tool call to send the output for. | | `output` | `string` | The output of the function call. | | `startResponse?` | `boolean` | Whether to start a new response after sending the output. | #### Returns [Section titled “Returns”](#returns-19) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-15) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/).[`sendFunctionCallOutput`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/#sendfunctioncalloutput) *** ### sendMcpResponse() [Section titled “sendMcpResponse()”](#sendmcpresponse) ```ts sendMcpResponse( approvalRequest, approved, reason?): void; ``` Sends a response for an MCP tool call #### Parameters [Section titled “Parameters”](#parameters-16) | Parameter | Type | Description | | ------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------- | | `approvalRequest` | { `approved?`: `boolean` \| `null`; `arguments`: `z.ZodRecord`<`z.ZodString`, `z.ZodAny`>; `itemId`: `string`; `name`: `string`; `serverLabel`: `string`; `type`: `"mcp_approval_request"`; } | The approval request to respond to | | `approvalRequest.approved?` | `boolean` \| `null` | ‐ | | `approvalRequest.arguments` | `z.ZodRecord`<`z.ZodString`, `z.ZodAny`> | ‐ | | `approvalRequest.itemId?` | `string` | ‐ | | `approvalRequest.name?` | `string` | ‐ | | `approvalRequest.serverLabel?` | `string` | ‐ | | `approvalRequest.type?` | `"mcp_approval_request"` | ‐ | | `approved?` | `boolean` | Whether the tool call was approved or rejected | | `reason?` | `string` | Optional rejection text for the provider/model. | #### Returns [Section titled “Returns”](#returns-20) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-16) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/).[`sendMcpResponse`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/#sendmcpresponse) *** ### sendMessage() [Section titled “sendMessage()”](#sendmessage) ```ts sendMessage( message, otherEventData, __namedParameters?): void; ``` Send a message to the Realtime API. This will create a new item in the conversation and trigger a response. #### Parameters [Section titled “Parameters”](#parameters-17) | Parameter | Type | Description | | ------------------------------------ | ---------------------------------- | ------------------------------ | | `message` | `RealtimeUserInput` | The message to send. | | `otherEventData` | `Record`<`string`, `any`> | Additional event data to send. | | `__namedParameters?` | { `triggerResponse?`: `boolean`; } | ‐ | | `__namedParameters.triggerResponse?` | `boolean` | ‐ | #### Returns [Section titled “Returns”](#returns-21) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-17) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/).[`sendMessage`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/#sendmessage) *** ### updateSessionConfig() [Section titled “updateSessionConfig()”](#updatesessionconfig) ```ts updateSessionConfig(config): void; ``` Updates the session config. This will merge it with the current session config with the default values and send it to the Realtime API. #### Parameters [Section titled “Parameters”](#parameters-18) | Parameter | Type | Description | | --------- | ------------------------------------------------------------------------------------------------------------------ | ----------------------------- | | `config` | `Partial`<[`RealtimeSessionConfig`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimesessionconfig/)> | The session config to update. | #### Returns [Section titled “Returns”](#returns-22) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-18) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/).[`updateSessionConfig`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/#updatesessionconfig) # OpenAIRealtimeSIP Transport layer that connects to an existing SIP-initiated Realtime call via call ID. ## Extends [Section titled “Extends”](#extends) * [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents/realtime/classes/openairealtimewebsocket/) ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new OpenAIRealtimeSIP(options?): OpenAIRealtimeSIP; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ---------- | ------------------------------------------------------------------------------------------------------------------------- | | `options?` | [`OpenAIRealtimeWebSocketOptions`](/openai-agents-js/openai/agents/realtime/type-aliases/openairealtimewebsocketoptions/) | #### Returns [Section titled “Returns”](#returns) `OpenAIRealtimeSIP` #### Overrides [Section titled “Overrides”](#overrides) [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents/realtime/classes/openairealtimewebsocket/).[`constructor`](/openai-agents-js/openai/agents/realtime/classes/openairealtimewebsocket/#constructor) ## Accessors [Section titled “Accessors”](#accessors) ### \_tracingConfig [Section titled “\_tracingConfig”](#_tracingconfig) #### Set Signature [Section titled “Set Signature”](#set-signature) ```ts set _tracingConfig(tracingConfig): void; ``` Sets the internal tracing config. This is used to track the tracing config that has been set during the session.create event. ##### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | --------------- | --------------------------------- | | `tracingConfig` | `RealtimeTracingConfig` \| `null` | ##### Returns [Section titled “Returns”](#returns-1) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from) [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents/realtime/classes/openairealtimewebsocket/).[`_tracingConfig`](/openai-agents-js/openai/agents/realtime/classes/openairealtimewebsocket/#_tracingconfig) *** ### connectionState [Section titled “connectionState”](#connectionstate) #### Get Signature [Section titled “Get Signature”](#get-signature) ```ts get connectionState(): WebSocketState; ``` The current connection state of the WebSocket connection. ##### Returns [Section titled “Returns”](#returns-2) [`WebSocketState`](/openai-agents-js/openai/agents/realtime/type-aliases/websocketstate/) #### Inherited from [Section titled “Inherited from”](#inherited-from-1) [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents/realtime/classes/openairealtimewebsocket/).[`connectionState`](/openai-agents-js/openai/agents/realtime/classes/openairealtimewebsocket/#connectionstate) *** ### currentModel [Section titled “currentModel”](#currentmodel) #### Get Signature [Section titled “Get Signature”](#get-signature-1) ```ts get currentModel(): OpenAIRealtimeModels; ``` The current model that is being used by the transport layer. ##### Returns [Section titled “Returns”](#returns-3) [`OpenAIRealtimeModels`](/openai-agents-js/openai/agents/realtime/type-aliases/openairealtimemodels/) #### Set Signature [Section titled “Set Signature”](#set-signature-1) ```ts set currentModel(model): void; ``` The current model that is being used by the transport layer. **Note**: The model cannot be changed mid conversation. ##### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | --------- | ----------------------------------------------------------------------------------------------------- | | `model` | [`OpenAIRealtimeModels`](/openai-agents-js/openai/agents/realtime/type-aliases/openairealtimemodels/) | ##### Returns [Section titled “Returns”](#returns-4) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-2) [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents/realtime/classes/openairealtimewebsocket/).[`currentModel`](/openai-agents-js/openai/agents/realtime/classes/openairealtimewebsocket/#currentmodel) *** ### muted [Section titled “muted”](#muted) #### Get Signature [Section titled “Get Signature”](#get-signature-2) ```ts get muted(): null; ``` Always returns `null` as the WebSocket transport layer does not handle muting. Instead, this should be handled by the client by not triggering the `sendAudio` method. ##### Returns [Section titled “Returns”](#returns-5) `null` Whether the input audio track is currently muted null if the muting is not handled by the transport layer #### Inherited from [Section titled “Inherited from”](#inherited-from-3) [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents/realtime/classes/openairealtimewebsocket/).[`muted`](/openai-agents-js/openai/agents/realtime/classes/openairealtimewebsocket/#muted) *** ### status [Section titled “status”](#status) #### Get Signature [Section titled “Get Signature”](#get-signature-3) ```ts get status(): "connecting" | "connected" | "disconnected"; ``` The current status of the WebSocket connection. ##### Returns [Section titled “Returns”](#returns-6) `"connecting"` | `"connected"` | `"disconnected"` #### Inherited from [Section titled “Inherited from”](#inherited-from-4) [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents/realtime/classes/openairealtimewebsocket/).[`status`](/openai-agents-js/openai/agents/realtime/classes/openairealtimewebsocket/#status) ## Methods [Section titled “Methods”](#methods) ### \_cancelResponse() [Section titled “\_cancelResponse()”](#_cancelresponse) ```ts _cancelResponse(): void; ``` Send a cancel response event to the Realtime API. This is used to cancel an ongoing response that the model is currently generating. #### Returns [Section titled “Returns”](#returns-7) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-5) [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents/realtime/classes/openairealtimewebsocket/).[`_cancelResponse`](/openai-agents-js/openai/agents/realtime/classes/openairealtimewebsocket/#_cancelresponse) *** ### \_interrupt() [Section titled “\_interrupt()”](#_interrupt) ```ts _interrupt(elapsedTime, cancelOngoingResponse?): void; ``` Do NOT call this method directly. Call `interrupt()` instead for proper interruption handling. This method is used to send the right events to the API to inform the model that the user has interrupted the response. It might be overridden/extended by an extended transport layer. See the `TwilioRealtimeTransportLayer` for an example. #### Parameters [Section titled “Parameters”](#parameters-3) | Parameter | Type | Description | | ------------------------ | --------- | -------------------------------------------- | | `elapsedTime` | `number` | The elapsed time since the response started. | | `cancelOngoingResponse?` | `boolean` | ‐ | #### Returns [Section titled “Returns”](#returns-8) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-6) [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents/realtime/classes/openairealtimewebsocket/).[`_interrupt`](/openai-agents-js/openai/agents/realtime/classes/openairealtimewebsocket/#_interrupt) *** ### addImage() [Section titled “addImage()”](#addimage) ```ts addImage(image, options?): void; ``` Sends an image to the model #### Parameters [Section titled “Parameters”](#parameters-4) | Parameter | Type | Description | | -------------------------- | ---------------------------------- | -------------------------------------------- | | `image` | `string` | The image to send | | `options?` | { `triggerResponse?`: `boolean`; } | Additional options | | `options.triggerResponse?` | `boolean` | Whether to trigger a response from the model | #### Returns [Section titled “Returns”](#returns-9) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-7) [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents/realtime/classes/openairealtimewebsocket/).[`addImage`](/openai-agents-js/openai/agents/realtime/classes/openairealtimewebsocket/#addimage) *** ### buildSessionPayload() [Section titled “buildSessionPayload()”](#buildsessionpayload) ```ts buildSessionPayload(config): RealtimeSessionPayload; ``` Build the payload object expected by the Realtime API when creating or updating a session. The helper centralises the conversion from camelCase runtime config to the snake\_case payload required by the Realtime API so transports that need a one-off payload (for example SIP call acceptance) can reuse the same logic without duplicating private state. #### Parameters [Section titled “Parameters”](#parameters-5) | Parameter | Type | Description | | --------- | ------------------------------------------------------------------------------------------------------------------ | ------------------------------------------ | | `config` | `Partial`<[`RealtimeSessionConfig`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimesessionconfig/)> | The session config to merge with defaults. | #### Returns [Section titled “Returns”](#returns-10) [`RealtimeSessionPayload`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimesessionpayload/) #### Inherited from [Section titled “Inherited from”](#inherited-from-8) [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents/realtime/classes/openairealtimewebsocket/).[`buildSessionPayload`](/openai-agents-js/openai/agents/realtime/classes/openairealtimewebsocket/#buildsessionpayload) *** ### close() [Section titled “close()”](#close) ```ts close(): void; ``` Close the WebSocket connection. This will also reset any internal connection tracking used for interruption handling. #### Returns [Section titled “Returns”](#returns-11) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-9) [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents/realtime/classes/openairealtimewebsocket/).[`close`](/openai-agents-js/openai/agents/realtime/classes/openairealtimewebsocket/#close) *** ### connect() [Section titled “connect()”](#connect) ```ts connect(options): Promise; ``` Establishes the connection to the model and keeps the connection alive #### Parameters [Section titled “Parameters”](#parameters-6) | Parameter | Type | Description | | --------- | ------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------ | | `options` | [`RealtimeTransportLayerConnectOptions`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimetransportlayerconnectoptions/) | The options for the connection | #### Returns [Section titled “Returns”](#returns-12) `Promise`<`void`> #### Overrides [Section titled “Overrides”](#overrides-1) [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents/realtime/classes/openairealtimewebsocket/).[`connect`](/openai-agents-js/openai/agents/realtime/classes/openairealtimewebsocket/#connect) *** ### emit() [Section titled “emit()”](#emit) ```ts emit(type, ...args): boolean; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | --------------------------------------------------------------------------------------------------------------------------------------- | | `K` *extends* keyof [`RealtimeTransportEventTypes`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimetransporteventtypes/) | #### Parameters [Section titled “Parameters”](#parameters-7) | Parameter | Type | | --------- | ------------------------------------------------------------------------------------------------------------------- | | `type` | `K` | | …`args` | [`OpenAIRealtimeEventTypes`](/openai-agents-js/openai/agents/realtime/type-aliases/openairealtimeeventtypes/)\[`K`] | #### Returns [Section titled “Returns”](#returns-13) `boolean` #### Inherited from [Section titled “Inherited from”](#inherited-from-10) [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents/realtime/classes/openairealtimewebsocket/).[`emit`](/openai-agents-js/openai/agents/realtime/classes/openairealtimewebsocket/#emit) *** ### interrupt() [Section titled “interrupt()”](#interrupt) ```ts interrupt(cancelOngoingResponse?): void; ``` Interrupt the ongoing response. This method is triggered automatically by the client when voice activity detection (VAD) is enabled (default) as well as when an output guardrail got triggered. You can also call this method directly if you want to interrupt the conversation for example based on an event in the client. #### Parameters [Section titled “Parameters”](#parameters-8) | Parameter | Type | | ------------------------ | --------- | | `cancelOngoingResponse?` | `boolean` | #### Returns [Section titled “Returns”](#returns-14) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-11) [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents/realtime/classes/openairealtimewebsocket/).[`interrupt`](/openai-agents-js/openai/agents/realtime/classes/openairealtimewebsocket/#interrupt) *** ### mute() [Section titled “mute()”](#mute) ```ts mute(_muted): never; ``` Will throw an error as the WebSocket transport layer does not support muting. #### Parameters [Section titled “Parameters”](#parameters-9) | Parameter | Type | | --------- | --------- | | `_muted` | `boolean` | #### Returns [Section titled “Returns”](#returns-15) `never` #### Inherited from [Section titled “Inherited from”](#inherited-from-12) [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents/realtime/classes/openairealtimewebsocket/).[`mute`](/openai-agents-js/openai/agents/realtime/classes/openairealtimewebsocket/#mute) *** ### off() [Section titled “off()”](#off) ```ts off(type, listener): EventEmitter; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-1) | Type Parameter | | --------------------------------------------------------------------------------------------------------------------------------------- | | `K` *extends* keyof [`RealtimeTransportEventTypes`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimetransporteventtypes/) | #### Parameters [Section titled “Parameters”](#parameters-10) | Parameter | Type | | ---------- | ------------------- | | `type` | `K` | | `listener` | (…`args`) => `void` | #### Returns [Section titled “Returns”](#returns-16) `EventEmitter`<`EventTypes`> #### Inherited from [Section titled “Inherited from”](#inherited-from-13) [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents/realtime/classes/openairealtimewebsocket/).[`off`](/openai-agents-js/openai/agents/realtime/classes/openairealtimewebsocket/#off) *** ### on() [Section titled “on()”](#on) ```ts on(type, listener): EventEmitter; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-2) | Type Parameter | | --------------------------------------------------------------------------------------------------------------------------------------- | | `K` *extends* keyof [`RealtimeTransportEventTypes`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimetransporteventtypes/) | #### Parameters [Section titled “Parameters”](#parameters-11) | Parameter | Type | | ---------- | ------------------- | | `type` | `K` | | `listener` | (…`args`) => `void` | #### Returns [Section titled “Returns”](#returns-17) `EventEmitter`<`EventTypes`> #### Inherited from [Section titled “Inherited from”](#inherited-from-14) [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents/realtime/classes/openairealtimewebsocket/).[`on`](/openai-agents-js/openai/agents/realtime/classes/openairealtimewebsocket/#on) *** ### once() [Section titled “once()”](#once) ```ts once(type, listener): EventEmitter; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-3) | Type Parameter | | --------------------------------------------------------------------------------------------------------------------------------------- | | `K` *extends* keyof [`RealtimeTransportEventTypes`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimetransporteventtypes/) | #### Parameters [Section titled “Parameters”](#parameters-12) | Parameter | Type | | ---------- | ------------------- | | `type` | `K` | | `listener` | (…`args`) => `void` | #### Returns [Section titled “Returns”](#returns-18) `EventEmitter`<`EventTypes`> #### Inherited from [Section titled “Inherited from”](#inherited-from-15) [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents/realtime/classes/openairealtimewebsocket/).[`once`](/openai-agents-js/openai/agents/realtime/classes/openairealtimewebsocket/#once) *** ### requestResponse() [Section titled “requestResponse()”](#requestresponse) ```ts requestResponse(response?): void; ``` Requests a new response for the current conversation turn. Implementations may defer the underlying `response.create` until the server has fully finished the prior response. #### Parameters [Section titled “Parameters”](#parameters-13) | Parameter | Type | Description | | ----------- | ------------------------- | ------------------------------------------- | | `response?` | `Record`<`string`, `any`> | Optional one-off response override payload. | #### Returns [Section titled “Returns”](#returns-19) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-16) [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents/realtime/classes/openairealtimewebsocket/).[`requestResponse`](/openai-agents-js/openai/agents/realtime/classes/openairealtimewebsocket/#requestresponse) *** ### resetHistory() [Section titled “resetHistory()”](#resethistory) ```ts resetHistory(oldHistory, newHistory): void; ``` Reset the history of the conversation. This will create a diff between the old and new history and send the necessary events to the Realtime API to update the history. #### Parameters [Section titled “Parameters”](#parameters-14) | Parameter | Type | Description | | ------------ | ---------------------------------------------------------------------------------------- | ------------------------------------ | | `oldHistory` | [`RealtimeItem`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimeitem/)\[] | The old history of the conversation. | | `newHistory` | [`RealtimeItem`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimeitem/)\[] | The new history of the conversation. | #### Returns [Section titled “Returns”](#returns-20) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-17) [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents/realtime/classes/openairealtimewebsocket/).[`resetHistory`](/openai-agents-js/openai/agents/realtime/classes/openairealtimewebsocket/#resethistory) *** ### sendAudio() [Section titled “sendAudio()”](#sendaudio) ```ts sendAudio(_audio, _options?): never; ``` Send an audio buffer to the Realtime API. This is used for your client to send audio to the model to respond. #### Parameters [Section titled “Parameters”](#parameters-15) | Parameter | Type | | ------------------ | ------------------------- | | `_audio` | `ArrayBuffer` | | `_options?` | { `commit?`: `boolean`; } | | `_options.commit?` | `boolean` | #### Returns [Section titled “Returns”](#returns-21) `never` #### Overrides [Section titled “Overrides”](#overrides-2) [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents/realtime/classes/openairealtimewebsocket/).[`sendAudio`](/openai-agents-js/openai/agents/realtime/classes/openairealtimewebsocket/#sendaudio) *** ### sendEvent() [Section titled “sendEvent()”](#sendevent) ```ts sendEvent(event): void; ``` Send an event to the Realtime API. This will stringify the event and send it directly to the API. This can be used if you want to take control over the connection and send events manually. #### Parameters [Section titled “Parameters”](#parameters-16) | Parameter | Type | Description | | --------- | ------------------------------------------------------------------------------------------------------- | ------------------ | | `event` | [`RealtimeClientMessage`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimeclientmessage/) | The event to send. | #### Returns [Section titled “Returns”](#returns-22) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-18) [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents/realtime/classes/openairealtimewebsocket/).[`sendEvent`](/openai-agents-js/openai/agents/realtime/classes/openairealtimewebsocket/#sendevent) *** ### sendFunctionCallOutput() [Section titled “sendFunctionCallOutput()”](#sendfunctioncalloutput) ```ts sendFunctionCallOutput( toolCall, output, startResponse?): void; ``` Send the output of a function call to the Realtime API. #### Parameters [Section titled “Parameters”](#parameters-17) | Parameter | Type | Description | | ---------------- | --------------------------------------------------------------------------------------------------------- | --------------------------------------------------------- | | `toolCall` | [`TransportToolCallEvent`](/openai-agents-js/openai/agents/realtime/type-aliases/transporttoolcallevent/) | The tool call to send the output for. | | `output` | `string` | The output of the function call. | | `startResponse?` | `boolean` | Whether to start a new response after sending the output. | #### Returns [Section titled “Returns”](#returns-23) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-19) [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents/realtime/classes/openairealtimewebsocket/).[`sendFunctionCallOutput`](/openai-agents-js/openai/agents/realtime/classes/openairealtimewebsocket/#sendfunctioncalloutput) *** ### sendMcpResponse() [Section titled “sendMcpResponse()”](#sendmcpresponse) ```ts sendMcpResponse( approvalRequest, approved, reason?): void; ``` Sends a response for an MCP tool call #### Parameters [Section titled “Parameters”](#parameters-18) | Parameter | Type | Description | | ------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------- | | `approvalRequest` | { `approved?`: `boolean` \| `null`; `arguments`: `z.ZodRecord`<`z.ZodString`, `z.ZodAny`>; `itemId`: `string`; `name`: `string`; `serverLabel`: `string`; `type`: `"mcp_approval_request"`; } | The approval request to respond to | | `approvalRequest.approved?` | `boolean` \| `null` | ‐ | | `approvalRequest.arguments` | `z.ZodRecord`<`z.ZodString`, `z.ZodAny`> | ‐ | | `approvalRequest.itemId?` | `string` | ‐ | | `approvalRequest.name?` | `string` | ‐ | | `approvalRequest.serverLabel?` | `string` | ‐ | | `approvalRequest.type?` | `"mcp_approval_request"` | ‐ | | `approved?` | `boolean` | Whether the tool call was approved or rejected | | `reason?` | `string` | Optional rejection text for the provider/model. | #### Returns [Section titled “Returns”](#returns-24) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-20) [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents/realtime/classes/openairealtimewebsocket/).[`sendMcpResponse`](/openai-agents-js/openai/agents/realtime/classes/openairealtimewebsocket/#sendmcpresponse) *** ### sendMessage() [Section titled “sendMessage()”](#sendmessage) ```ts sendMessage( message, otherEventData, __namedParameters?): void; ``` Send a message to the Realtime API. This will create a new item in the conversation and trigger a response. #### Parameters [Section titled “Parameters”](#parameters-19) | Parameter | Type | Description | | ------------------------------------ | ---------------------------------- | ------------------------------ | | `message` | `RealtimeUserInput` | The message to send. | | `otherEventData` | `Record`<`string`, `any`> | Additional event data to send. | | `__namedParameters?` | { `triggerResponse?`: `boolean`; } | ‐ | | `__namedParameters.triggerResponse?` | `boolean` | ‐ | #### Returns [Section titled “Returns”](#returns-25) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-21) [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents/realtime/classes/openairealtimewebsocket/).[`sendMessage`](/openai-agents-js/openai/agents/realtime/classes/openairealtimewebsocket/#sendmessage) *** ### updateSessionConfig() [Section titled “updateSessionConfig()”](#updatesessionconfig) ```ts updateSessionConfig(config): void; ``` Updates the session config. This will merge it with the current session config with the default values and send it to the Realtime API. #### Parameters [Section titled “Parameters”](#parameters-20) | Parameter | Type | Description | | --------- | ------------------------------------------------------------------------------------------------------------------ | ----------------------------- | | `config` | `Partial`<[`RealtimeSessionConfig`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimesessionconfig/)> | The session config to update. | #### Returns [Section titled “Returns”](#returns-26) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-22) [`OpenAIRealtimeWebSocket`](/openai-agents-js/openai/agents/realtime/classes/openairealtimewebsocket/).[`updateSessionConfig`](/openai-agents-js/openai/agents/realtime/classes/openairealtimewebsocket/#updatesessionconfig) *** ### buildInitialConfig() [Section titled “buildInitialConfig()”](#buildinitialconfig) ```ts static buildInitialConfig( agent, options?, overrides?): Promise; ``` Build the initial session payload for a SIP-attached session, matching the config that a RealtimeSession would send on connect. This enables SIP deployments to accept an incoming call with a payload that already reflects the active agent’s instructions, tools, prompt, and tracing metadata without duplicating the session logic outside of the SDK. The returned object structurally matches the REST `CallAcceptParams` interface, so it can be forwarded directly to `openai.realtime.calls.accept(...)`. #### Type Parameters [Section titled “Type Parameters”](#type-parameters-4) | Type Parameter | Default type | | -------------- | ------------ | | `TBaseContext` | `unknown` | #### Parameters [Section titled “Parameters”](#parameters-21) | Parameter | Type | Description | | ------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- | | `agent` | \| [`RealtimeAgent`](/openai-agents-js/openai/agents/realtime/classes/realtimeagent/)<`TBaseContext`> \| [`RealtimeAgent`](/openai-agents-js/openai/agents/realtime/classes/realtimeagent/)<[`RealtimeContextData`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimecontextdata/)<`TBaseContext`>> | The starting agent used to seed the session instructions, tools, and prompt. | | `options?` | `Partial`<[`RealtimeSessionOptions`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimesessionoptions/)<`TBaseContext`>> | Optional session options that mirror the ones passed to the RealtimeSession constructor. | | `overrides?` | `Partial`<[`RealtimeSessionConfig`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimesessionconfig/)> | Additional config overrides applied on top of the session options. | #### Returns [Section titled “Returns”](#returns-27) `Promise`<[`RealtimeSessionPayload`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimesessionpayload/)> # OpenAIRealtimeWebRTC Transport layer that’s handling the connection between the client and OpenAI’s Realtime API via WebRTC. While this transport layer is designed to be used within a RealtimeSession, it can also be used standalone if you want to have a direct connection to the Realtime API. Unless you specify a `mediaStream` or `audioElement` option, the transport layer will automatically configure the microphone and audio output to be used by the session. ## Extends [Section titled “Extends”](#extends) * [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/) ## Implements [Section titled “Implements”](#implements) * [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/) ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new OpenAIRealtimeWebRTC(options?): OpenAIRealtimeWebRTC; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ---------- | ------------------------------------------------------------------------------------------------------------------- | | `options?` | [`OpenAIRealtimeWebRTCOptions`](/openai-agents-js/openai/agents/realtime/type-aliases/openairealtimewebrtcoptions/) | #### Returns [Section titled “Returns”](#returns) `OpenAIRealtimeWebRTC` #### Overrides [Section titled “Overrides”](#overrides) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/).[`constructor`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/#constructor) ## Accessors [Section titled “Accessors”](#accessors) ### \_tracingConfig [Section titled “\_tracingConfig”](#_tracingconfig) #### Set Signature [Section titled “Set Signature”](#set-signature) ```ts set _tracingConfig(tracingConfig): void; ``` Sets the internal tracing config. This is used to track the tracing config that has been set during the session.create event. ##### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | --------------- | --------------------------------- | | `tracingConfig` | `RealtimeTracingConfig` \| `null` | ##### Returns [Section titled “Returns”](#returns-1) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/).[`_tracingConfig`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/#_tracingconfig) *** ### callId [Section titled “callId”](#callid) #### Get Signature [Section titled “Get Signature”](#get-signature) ```ts get callId(): string | undefined; ``` The current call ID of the WebRTC connection. ##### Returns [Section titled “Returns”](#returns-2) `string` | `undefined` *** ### connectionState [Section titled “connectionState”](#connectionstate) #### Get Signature [Section titled “Get Signature”](#get-signature-1) ```ts get connectionState(): WebRTCState; ``` The current connection state of the WebRTC connection including the peer connection and data channel. ##### Returns [Section titled “Returns”](#returns-3) [`WebRTCState`](/openai-agents-js/openai/agents/realtime/type-aliases/webrtcstate/) *** ### currentModel [Section titled “currentModel”](#currentmodel) #### Get Signature [Section titled “Get Signature”](#get-signature-2) ```ts get currentModel(): OpenAIRealtimeModels; ``` The current model that is being used by the transport layer. ##### Returns [Section titled “Returns”](#returns-4) [`OpenAIRealtimeModels`](/openai-agents-js/openai/agents/realtime/type-aliases/openairealtimemodels/) #### Set Signature [Section titled “Set Signature”](#set-signature-1) ```ts set currentModel(model): void; ``` The current model that is being used by the transport layer. **Note**: The model cannot be changed mid conversation. ##### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | --------- | ----------------------------------------------------------------------------------------------------- | | `model` | [`OpenAIRealtimeModels`](/openai-agents-js/openai/agents/realtime/type-aliases/openairealtimemodels/) | ##### Returns [Section titled “Returns”](#returns-5) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-1) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/).[`currentModel`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/#currentmodel) *** ### muted [Section titled “muted”](#muted) #### Get Signature [Section titled “Get Signature”](#get-signature-3) ```ts get muted(): boolean; ``` Whether the session is muted. ##### Returns [Section titled “Returns”](#returns-6) `boolean` Whether the input audio track is currently muted null if the muting is not handled by the transport layer #### Implementation of [Section titled “Implementation of”](#implementation-of) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/).[`muted`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/#muted) #### Overrides [Section titled “Overrides”](#overrides-1) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/).[`muted`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/#muted) *** ### status [Section titled “status”](#status) #### Get Signature [Section titled “Get Signature”](#get-signature-4) ```ts get status(): "connecting" | "connected" | "disconnected"; ``` The current status of the WebRTC connection. ##### Returns [Section titled “Returns”](#returns-7) `"connecting"` | `"connected"` | `"disconnected"` #### Implementation of [Section titled “Implementation of”](#implementation-of-1) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/).[`status`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/#status) #### Overrides [Section titled “Overrides”](#overrides-2) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/).[`status`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/#status) ## Methods [Section titled “Methods”](#methods) ### addImage() [Section titled “addImage()”](#addimage) ```ts addImage(image, options?): void; ``` Sends an image to the model #### Parameters [Section titled “Parameters”](#parameters-3) | Parameter | Type | Description | | -------------------------- | ---------------------------------- | -------------------------------------------- | | `image` | `string` | The image to send | | `options?` | { `triggerResponse?`: `boolean`; } | Additional options | | `options.triggerResponse?` | `boolean` | Whether to trigger a response from the model | #### Returns [Section titled “Returns”](#returns-8) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-2) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/).[`addImage`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/#addimage) #### Inherited from [Section titled “Inherited from”](#inherited-from-2) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/).[`addImage`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/#addimage) *** ### buildSessionPayload() [Section titled “buildSessionPayload()”](#buildsessionpayload) ```ts buildSessionPayload(config): RealtimeSessionPayload; ``` Build the payload object expected by the Realtime API when creating or updating a session. The helper centralises the conversion from camelCase runtime config to the snake\_case payload required by the Realtime API so transports that need a one-off payload (for example SIP call acceptance) can reuse the same logic without duplicating private state. #### Parameters [Section titled “Parameters”](#parameters-4) | Parameter | Type | Description | | --------- | ------------------------------------------------------------------------------------------------------------------ | ------------------------------------------ | | `config` | `Partial`<[`RealtimeSessionConfig`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimesessionconfig/)> | The session config to merge with defaults. | #### Returns [Section titled “Returns”](#returns-9) [`RealtimeSessionPayload`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimesessionpayload/) #### Inherited from [Section titled “Inherited from”](#inherited-from-3) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/).[`buildSessionPayload`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/#buildsessionpayload) *** ### close() [Section titled “close()”](#close) ```ts close(): void; ``` Close the connection to the Realtime API and disconnects the underlying WebRTC connection. #### Returns [Section titled “Returns”](#returns-10) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-3) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/).[`close`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/#close) #### Overrides [Section titled “Overrides”](#overrides-3) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/).[`close`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/#close) *** ### connect() [Section titled “connect()”](#connect) ```ts connect(options): Promise; ``` Connect to the Realtime API. This will establish the connection to the OpenAI Realtime API via WebRTC. If you are using a browser, the transport layer will also automatically configure the microphone and audio output to be used by the session. #### Parameters [Section titled “Parameters”](#parameters-5) | Parameter | Type | Description | | --------- | ------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------- | | `options` | [`RealtimeTransportLayerConnectOptions`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimetransportlayerconnectoptions/) | The options for the connection. | #### Returns [Section titled “Returns”](#returns-11) `Promise`<`void`> #### Implementation of [Section titled “Implementation of”](#implementation-of-4) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/).[`connect`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/#connect) #### Overrides [Section titled “Overrides”](#overrides-4) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/).[`connect`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/#connect) *** ### emit() [Section titled “emit()”](#emit) ```ts emit(type, ...args): boolean; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | --------------------------------------------------------------------------------------------------------------------------------------- | | `K` *extends* keyof [`RealtimeTransportEventTypes`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimetransporteventtypes/) | #### Parameters [Section titled “Parameters”](#parameters-6) | Parameter | Type | | --------- | ------------------------------------------------------------------------------------------------------------------- | | `type` | `K` | | …`args` | [`OpenAIRealtimeEventTypes`](/openai-agents-js/openai/agents/realtime/type-aliases/openairealtimeeventtypes/)\[`K`] | #### Returns [Section titled “Returns”](#returns-12) `boolean` #### Implementation of [Section titled “Implementation of”](#implementation-of-5) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/).[`emit`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/#emit) #### Inherited from [Section titled “Inherited from”](#inherited-from-4) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/).[`emit`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/#emit) *** ### interrupt() [Section titled “interrupt()”](#interrupt) ```ts interrupt(): void; ``` Interrupt the current response if one is ongoing and clear the audio buffer so that the agent stops talking. #### Returns [Section titled “Returns”](#returns-13) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-6) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/).[`interrupt`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/#interrupt) #### Overrides [Section titled “Overrides”](#overrides-5) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/).[`interrupt`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/#interrupt) *** ### mute() [Section titled “mute()”](#mute) ```ts mute(muted): void; ``` Mute or unmute the session. #### Parameters [Section titled “Parameters”](#parameters-7) | Parameter | Type | Description | | --------- | --------- | ---------------------------- | | `muted` | `boolean` | Whether to mute the session. | #### Returns [Section titled “Returns”](#returns-14) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-7) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/).[`mute`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/#mute) #### Overrides [Section titled “Overrides”](#overrides-6) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/).[`mute`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/#mute) *** ### off() [Section titled “off()”](#off) ```ts off(type, listener): EventEmitter; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-1) | Type Parameter | | --------------------------------------------------------------------------------------------------------------------------------------- | | `K` *extends* keyof [`RealtimeTransportEventTypes`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimetransporteventtypes/) | #### Parameters [Section titled “Parameters”](#parameters-8) | Parameter | Type | | ---------- | ------------------- | | `type` | `K` | | `listener` | (…`args`) => `void` | #### Returns [Section titled “Returns”](#returns-15) `EventEmitter`<`EventTypes`> #### Implementation of [Section titled “Implementation of”](#implementation-of-8) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/).[`off`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/#off) #### Inherited from [Section titled “Inherited from”](#inherited-from-5) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/).[`off`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/#off) *** ### on() [Section titled “on()”](#on) ```ts on(type, listener): EventEmitter; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-2) | Type Parameter | | --------------------------------------------------------------------------------------------------------------------------------------- | | `K` *extends* keyof [`RealtimeTransportEventTypes`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimetransporteventtypes/) | #### Parameters [Section titled “Parameters”](#parameters-9) | Parameter | Type | | ---------- | ------------------- | | `type` | `K` | | `listener` | (…`args`) => `void` | #### Returns [Section titled “Returns”](#returns-16) `EventEmitter`<`EventTypes`> #### Implementation of [Section titled “Implementation of”](#implementation-of-9) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/).[`on`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/#on) #### Inherited from [Section titled “Inherited from”](#inherited-from-6) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/).[`on`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/#on) *** ### once() [Section titled “once()”](#once) ```ts once(type, listener): EventEmitter; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-3) | Type Parameter | | --------------------------------------------------------------------------------------------------------------------------------------- | | `K` *extends* keyof [`RealtimeTransportEventTypes`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimetransporteventtypes/) | #### Parameters [Section titled “Parameters”](#parameters-10) | Parameter | Type | | ---------- | ------------------- | | `type` | `K` | | `listener` | (…`args`) => `void` | #### Returns [Section titled “Returns”](#returns-17) `EventEmitter`<`EventTypes`> #### Implementation of [Section titled “Implementation of”](#implementation-of-10) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/).[`once`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/#once) #### Inherited from [Section titled “Inherited from”](#inherited-from-7) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/).[`once`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/#once) *** ### requestResponse() [Section titled “requestResponse()”](#requestresponse) ```ts requestResponse(response?): void; ``` Requests a new response for the current conversation turn. Implementations may defer the underlying `response.create` until the server has fully finished the prior response. #### Parameters [Section titled “Parameters”](#parameters-11) | Parameter | Type | Description | | ----------- | ------------------------- | ------------------------------------------- | | `response?` | `Record`<`string`, `any`> | Optional one-off response override payload. | #### Returns [Section titled “Returns”](#returns-18) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-11) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/).[`requestResponse`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/#requestresponse) #### Overrides [Section titled “Overrides”](#overrides-7) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/).[`requestResponse`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/#requestresponse) *** ### resetHistory() [Section titled “resetHistory()”](#resethistory) ```ts resetHistory(oldHistory, newHistory): void; ``` Reset the history of the conversation. This will create a diff between the old and new history and send the necessary events to the Realtime API to update the history. #### Parameters [Section titled “Parameters”](#parameters-12) | Parameter | Type | Description | | ------------ | ---------------------------------------------------------------------------------------- | ------------------------------------ | | `oldHistory` | [`RealtimeItem`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimeitem/)\[] | The old history of the conversation. | | `newHistory` | [`RealtimeItem`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimeitem/)\[] | The new history of the conversation. | #### Returns [Section titled “Returns”](#returns-19) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-12) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/).[`resetHistory`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/#resethistory) #### Inherited from [Section titled “Inherited from”](#inherited-from-8) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/).[`resetHistory`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/#resethistory) *** ### sendAudio() [Section titled “sendAudio()”](#sendaudio) ```ts sendAudio(audio, options?): void; ``` Send an audio buffer to the Realtime API. If `{ commit: true }` is passed, the audio buffer will be committed and the model will start processing it. This is necessary if you have disabled turn detection / voice activity detection (VAD). #### Parameters [Section titled “Parameters”](#parameters-13) | Parameter | Type | Description | | ----------------- | ------------------------- | --------------------------------- | | `audio` | `ArrayBuffer` | The audio buffer to send. | | `options?` | { `commit?`: `boolean`; } | The options for the audio buffer. | | `options.commit?` | `boolean` | ‐ | #### Returns [Section titled “Returns”](#returns-20) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-13) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/).[`sendAudio`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/#sendaudio) #### Inherited from [Section titled “Inherited from”](#inherited-from-9) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/).[`sendAudio`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/#sendaudio) *** ### sendEvent() [Section titled “sendEvent()”](#sendevent) ```ts sendEvent(event): void; ``` Send an event to the Realtime API. This will stringify the event and send it directly to the API. This can be used if you want to take control over the connection and send events manually. #### Parameters [Section titled “Parameters”](#parameters-14) | Parameter | Type | Description | | --------- | ------------------------------------------------------------------------------------------------------- | ------------------ | | `event` | [`RealtimeClientMessage`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimeclientmessage/) | The event to send. | #### Returns [Section titled “Returns”](#returns-21) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-14) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/).[`sendEvent`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/#sendevent) #### Overrides [Section titled “Overrides”](#overrides-8) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/).[`sendEvent`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/#sendevent) *** ### sendFunctionCallOutput() [Section titled “sendFunctionCallOutput()”](#sendfunctioncalloutput) ```ts sendFunctionCallOutput( toolCall, output, startResponse?): void; ``` Send the output of a function call to the Realtime API. #### Parameters [Section titled “Parameters”](#parameters-15) | Parameter | Type | Description | | ---------------- | --------------------------------------------------------------------------------------------------------- | --------------------------------------------------------- | | `toolCall` | [`TransportToolCallEvent`](/openai-agents-js/openai/agents/realtime/type-aliases/transporttoolcallevent/) | The tool call to send the output for. | | `output` | `string` | The output of the function call. | | `startResponse?` | `boolean` | Whether to start a new response after sending the output. | #### Returns [Section titled “Returns”](#returns-22) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-15) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/).[`sendFunctionCallOutput`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/#sendfunctioncalloutput) #### Inherited from [Section titled “Inherited from”](#inherited-from-10) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/).[`sendFunctionCallOutput`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/#sendfunctioncalloutput) *** ### sendMcpResponse() [Section titled “sendMcpResponse()”](#sendmcpresponse) ```ts sendMcpResponse( approvalRequest, approved, reason?): void; ``` Sends a response for an MCP tool call #### Parameters [Section titled “Parameters”](#parameters-16) | Parameter | Type | Description | | ------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------- | | `approvalRequest` | { `approved?`: `boolean` \| `null`; `arguments`: `z.ZodRecord`<`z.ZodString`, `z.ZodAny`>; `itemId`: `string`; `name`: `string`; `serverLabel`: `string`; `type`: `"mcp_approval_request"`; } | The approval request to respond to | | `approvalRequest.approved?` | `boolean` \| `null` | ‐ | | `approvalRequest.arguments` | `z.ZodRecord`<`z.ZodString`, `z.ZodAny`> | ‐ | | `approvalRequest.itemId?` | `string` | ‐ | | `approvalRequest.name?` | `string` | ‐ | | `approvalRequest.serverLabel?` | `string` | ‐ | | `approvalRequest.type?` | `"mcp_approval_request"` | ‐ | | `approved?` | `boolean` | Whether the tool call was approved or rejected | | `reason?` | `string` | Optional rejection text for the provider/model. | #### Returns [Section titled “Returns”](#returns-23) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-16) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/).[`sendMcpResponse`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/#sendmcpresponse) #### Inherited from [Section titled “Inherited from”](#inherited-from-11) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/).[`sendMcpResponse`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/#sendmcpresponse) *** ### sendMessage() [Section titled “sendMessage()”](#sendmessage) ```ts sendMessage( message, otherEventData, __namedParameters?): void; ``` Send a message to the Realtime API. This will create a new item in the conversation and trigger a response. #### Parameters [Section titled “Parameters”](#parameters-17) | Parameter | Type | Description | | ------------------------------------ | ---------------------------------- | ------------------------------ | | `message` | `RealtimeUserInput` | The message to send. | | `otherEventData` | `Record`<`string`, `any`> | Additional event data to send. | | `__namedParameters?` | { `triggerResponse?`: `boolean`; } | ‐ | | `__namedParameters.triggerResponse?` | `boolean` | ‐ | #### Returns [Section titled “Returns”](#returns-24) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-17) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/).[`sendMessage`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/#sendmessage) #### Inherited from [Section titled “Inherited from”](#inherited-from-12) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/).[`sendMessage`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/#sendmessage) *** ### updateSessionConfig() [Section titled “updateSessionConfig()”](#updatesessionconfig) ```ts updateSessionConfig(config): void; ``` Updates the session config. This will merge it with the current session config with the default values and send it to the Realtime API. #### Parameters [Section titled “Parameters”](#parameters-18) | Parameter | Type | Description | | --------- | ------------------------------------------------------------------------------------------------------------------ | ----------------------------- | | `config` | `Partial`<[`RealtimeSessionConfig`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimesessionconfig/)> | The session config to update. | #### Returns [Section titled “Returns”](#returns-25) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-18) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/).[`updateSessionConfig`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/#updatesessionconfig) #### Inherited from [Section titled “Inherited from”](#inherited-from-13) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/).[`updateSessionConfig`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/#updatesessionconfig) # OpenAIRealtimeWebSocket Transport layer that’s handling the connection between the client and OpenAI’s Realtime API via WebSockets. While this transport layer is designed to be used within a RealtimeSession, it can also be used standalone if you want to have a direct connection to the Realtime API. ## Extends [Section titled “Extends”](#extends) * [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/) ## Extended by [Section titled “Extended by”](#extended-by) * [`OpenAIRealtimeSIP`](/openai-agents-js/openai/agents/realtime/classes/openairealtimesip/) ## Implements [Section titled “Implements”](#implements) * [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/) ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new OpenAIRealtimeWebSocket(options?): OpenAIRealtimeWebSocket; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ---------- | ------------------------------------------------------------------------------------------------------------------------- | | `options?` | [`OpenAIRealtimeWebSocketOptions`](/openai-agents-js/openai/agents/realtime/type-aliases/openairealtimewebsocketoptions/) | #### Returns [Section titled “Returns”](#returns) `OpenAIRealtimeWebSocket` #### Overrides [Section titled “Overrides”](#overrides) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/).[`constructor`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/#constructor) ## Accessors [Section titled “Accessors”](#accessors) ### \_tracingConfig [Section titled “\_tracingConfig”](#_tracingconfig) #### Set Signature [Section titled “Set Signature”](#set-signature) ```ts set _tracingConfig(tracingConfig): void; ``` Sets the internal tracing config. This is used to track the tracing config that has been set during the session.create event. ##### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | --------------- | --------------------------------- | | `tracingConfig` | `RealtimeTracingConfig` \| `null` | ##### Returns [Section titled “Returns”](#returns-1) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/).[`_tracingConfig`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/#_tracingconfig) *** ### connectionState [Section titled “connectionState”](#connectionstate) #### Get Signature [Section titled “Get Signature”](#get-signature) ```ts get connectionState(): WebSocketState; ``` The current connection state of the WebSocket connection. ##### Returns [Section titled “Returns”](#returns-2) [`WebSocketState`](/openai-agents-js/openai/agents/realtime/type-aliases/websocketstate/) *** ### currentModel [Section titled “currentModel”](#currentmodel) #### Get Signature [Section titled “Get Signature”](#get-signature-1) ```ts get currentModel(): OpenAIRealtimeModels; ``` The current model that is being used by the transport layer. ##### Returns [Section titled “Returns”](#returns-3) [`OpenAIRealtimeModels`](/openai-agents-js/openai/agents/realtime/type-aliases/openairealtimemodels/) #### Set Signature [Section titled “Set Signature”](#set-signature-1) ```ts set currentModel(model): void; ``` The current model that is being used by the transport layer. **Note**: The model cannot be changed mid conversation. ##### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | --------- | ----------------------------------------------------------------------------------------------------- | | `model` | [`OpenAIRealtimeModels`](/openai-agents-js/openai/agents/realtime/type-aliases/openairealtimemodels/) | ##### Returns [Section titled “Returns”](#returns-4) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-1) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/).[`currentModel`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/#currentmodel) *** ### muted [Section titled “muted”](#muted) #### Get Signature [Section titled “Get Signature”](#get-signature-2) ```ts get muted(): null; ``` Always returns `null` as the WebSocket transport layer does not handle muting. Instead, this should be handled by the client by not triggering the `sendAudio` method. ##### Returns [Section titled “Returns”](#returns-5) `null` Whether the input audio track is currently muted null if the muting is not handled by the transport layer #### Implementation of [Section titled “Implementation of”](#implementation-of) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/).[`muted`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/#muted) #### Overrides [Section titled “Overrides”](#overrides-1) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/).[`muted`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/#muted) *** ### status [Section titled “status”](#status) #### Get Signature [Section titled “Get Signature”](#get-signature-3) ```ts get status(): "connecting" | "connected" | "disconnected"; ``` The current status of the WebSocket connection. ##### Returns [Section titled “Returns”](#returns-6) `"connecting"` | `"connected"` | `"disconnected"` #### Implementation of [Section titled “Implementation of”](#implementation-of-1) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/).[`status`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/#status) #### Overrides [Section titled “Overrides”](#overrides-2) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/).[`status`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/#status) ## Methods [Section titled “Methods”](#methods) ### \_cancelResponse() [Section titled “\_cancelResponse()”](#_cancelresponse) ```ts _cancelResponse(): void; ``` Send a cancel response event to the Realtime API. This is used to cancel an ongoing response that the model is currently generating. #### Returns [Section titled “Returns”](#returns-7) `void` *** ### \_interrupt() [Section titled “\_interrupt()”](#_interrupt) ```ts _interrupt(elapsedTime, cancelOngoingResponse?): void; ``` Do NOT call this method directly. Call `interrupt()` instead for proper interruption handling. This method is used to send the right events to the API to inform the model that the user has interrupted the response. It might be overridden/extended by an extended transport layer. See the `TwilioRealtimeTransportLayer` for an example. #### Parameters [Section titled “Parameters”](#parameters-3) | Parameter | Type | Description | | ------------------------ | --------- | -------------------------------------------- | | `elapsedTime` | `number` | The elapsed time since the response started. | | `cancelOngoingResponse?` | `boolean` | ‐ | #### Returns [Section titled “Returns”](#returns-8) `void` *** ### addImage() [Section titled “addImage()”](#addimage) ```ts addImage(image, options?): void; ``` Sends an image to the model #### Parameters [Section titled “Parameters”](#parameters-4) | Parameter | Type | Description | | -------------------------- | ---------------------------------- | -------------------------------------------- | | `image` | `string` | The image to send | | `options?` | { `triggerResponse?`: `boolean`; } | Additional options | | `options.triggerResponse?` | `boolean` | Whether to trigger a response from the model | #### Returns [Section titled “Returns”](#returns-9) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-2) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/).[`addImage`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/#addimage) #### Inherited from [Section titled “Inherited from”](#inherited-from-2) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/).[`addImage`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/#addimage) *** ### buildSessionPayload() [Section titled “buildSessionPayload()”](#buildsessionpayload) ```ts buildSessionPayload(config): RealtimeSessionPayload; ``` Build the payload object expected by the Realtime API when creating or updating a session. The helper centralises the conversion from camelCase runtime config to the snake\_case payload required by the Realtime API so transports that need a one-off payload (for example SIP call acceptance) can reuse the same logic without duplicating private state. #### Parameters [Section titled “Parameters”](#parameters-5) | Parameter | Type | Description | | --------- | ------------------------------------------------------------------------------------------------------------------ | ------------------------------------------ | | `config` | `Partial`<[`RealtimeSessionConfig`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimesessionconfig/)> | The session config to merge with defaults. | #### Returns [Section titled “Returns”](#returns-10) [`RealtimeSessionPayload`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimesessionpayload/) #### Inherited from [Section titled “Inherited from”](#inherited-from-3) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/).[`buildSessionPayload`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/#buildsessionpayload) *** ### close() [Section titled “close()”](#close) ```ts close(): void; ``` Close the WebSocket connection. This will also reset any internal connection tracking used for interruption handling. #### Returns [Section titled “Returns”](#returns-11) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-3) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/).[`close`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/#close) #### Overrides [Section titled “Overrides”](#overrides-3) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/).[`close`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/#close) *** ### connect() [Section titled “connect()”](#connect) ```ts connect(options): Promise; ``` Establishes the connection to the model and keeps the connection alive #### Parameters [Section titled “Parameters”](#parameters-6) | Parameter | Type | Description | | --------- | ------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------ | | `options` | [`RealtimeTransportLayerConnectOptions`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimetransportlayerconnectoptions/) | The options for the connection | #### Returns [Section titled “Returns”](#returns-12) `Promise`<`void`> #### Implementation of [Section titled “Implementation of”](#implementation-of-4) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/).[`connect`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/#connect) #### Overrides [Section titled “Overrides”](#overrides-4) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/).[`connect`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/#connect) *** ### emit() [Section titled “emit()”](#emit) ```ts emit(type, ...args): boolean; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | --------------------------------------------------------------------------------------------------------------------------------------- | | `K` *extends* keyof [`RealtimeTransportEventTypes`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimetransporteventtypes/) | #### Parameters [Section titled “Parameters”](#parameters-7) | Parameter | Type | | --------- | ------------------------------------------------------------------------------------------------------------------- | | `type` | `K` | | …`args` | [`OpenAIRealtimeEventTypes`](/openai-agents-js/openai/agents/realtime/type-aliases/openairealtimeeventtypes/)\[`K`] | #### Returns [Section titled “Returns”](#returns-13) `boolean` #### Implementation of [Section titled “Implementation of”](#implementation-of-5) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/).[`emit`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/#emit) #### Inherited from [Section titled “Inherited from”](#inherited-from-4) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/).[`emit`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/#emit) *** ### interrupt() [Section titled “interrupt()”](#interrupt) ```ts interrupt(cancelOngoingResponse?): void; ``` Interrupt the ongoing response. This method is triggered automatically by the client when voice activity detection (VAD) is enabled (default) as well as when an output guardrail got triggered. You can also call this method directly if you want to interrupt the conversation for example based on an event in the client. #### Parameters [Section titled “Parameters”](#parameters-8) | Parameter | Type | | ------------------------ | --------- | | `cancelOngoingResponse?` | `boolean` | #### Returns [Section titled “Returns”](#returns-14) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-6) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/).[`interrupt`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/#interrupt) #### Overrides [Section titled “Overrides”](#overrides-5) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/).[`interrupt`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/#interrupt) *** ### mute() [Section titled “mute()”](#mute) ```ts mute(_muted): never; ``` Will throw an error as the WebSocket transport layer does not support muting. #### Parameters [Section titled “Parameters”](#parameters-9) | Parameter | Type | | --------- | --------- | | `_muted` | `boolean` | #### Returns [Section titled “Returns”](#returns-15) `never` #### Implementation of [Section titled “Implementation of”](#implementation-of-7) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/).[`mute`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/#mute) #### Overrides [Section titled “Overrides”](#overrides-6) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/).[`mute`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/#mute) *** ### off() [Section titled “off()”](#off) ```ts off(type, listener): EventEmitter; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-1) | Type Parameter | | --------------------------------------------------------------------------------------------------------------------------------------- | | `K` *extends* keyof [`RealtimeTransportEventTypes`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimetransporteventtypes/) | #### Parameters [Section titled “Parameters”](#parameters-10) | Parameter | Type | | ---------- | ------------------- | | `type` | `K` | | `listener` | (…`args`) => `void` | #### Returns [Section titled “Returns”](#returns-16) `EventEmitter`<`EventTypes`> #### Implementation of [Section titled “Implementation of”](#implementation-of-8) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/).[`off`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/#off) #### Inherited from [Section titled “Inherited from”](#inherited-from-5) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/).[`off`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/#off) *** ### on() [Section titled “on()”](#on) ```ts on(type, listener): EventEmitter; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-2) | Type Parameter | | --------------------------------------------------------------------------------------------------------------------------------------- | | `K` *extends* keyof [`RealtimeTransportEventTypes`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimetransporteventtypes/) | #### Parameters [Section titled “Parameters”](#parameters-11) | Parameter | Type | | ---------- | ------------------- | | `type` | `K` | | `listener` | (…`args`) => `void` | #### Returns [Section titled “Returns”](#returns-17) `EventEmitter`<`EventTypes`> #### Implementation of [Section titled “Implementation of”](#implementation-of-9) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/).[`on`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/#on) #### Inherited from [Section titled “Inherited from”](#inherited-from-6) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/).[`on`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/#on) *** ### once() [Section titled “once()”](#once) ```ts once(type, listener): EventEmitter; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-3) | Type Parameter | | --------------------------------------------------------------------------------------------------------------------------------------- | | `K` *extends* keyof [`RealtimeTransportEventTypes`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimetransporteventtypes/) | #### Parameters [Section titled “Parameters”](#parameters-12) | Parameter | Type | | ---------- | ------------------- | | `type` | `K` | | `listener` | (…`args`) => `void` | #### Returns [Section titled “Returns”](#returns-18) `EventEmitter`<`EventTypes`> #### Implementation of [Section titled “Implementation of”](#implementation-of-10) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/).[`once`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/#once) #### Inherited from [Section titled “Inherited from”](#inherited-from-7) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/).[`once`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/#once) *** ### requestResponse() [Section titled “requestResponse()”](#requestresponse) ```ts requestResponse(response?): void; ``` Requests a new response for the current conversation turn. Implementations may defer the underlying `response.create` until the server has fully finished the prior response. #### Parameters [Section titled “Parameters”](#parameters-13) | Parameter | Type | Description | | ----------- | ------------------------- | ------------------------------------------- | | `response?` | `Record`<`string`, `any`> | Optional one-off response override payload. | #### Returns [Section titled “Returns”](#returns-19) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-11) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/).[`requestResponse`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/#requestresponse) #### Overrides [Section titled “Overrides”](#overrides-7) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/).[`requestResponse`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/#requestresponse) *** ### resetHistory() [Section titled “resetHistory()”](#resethistory) ```ts resetHistory(oldHistory, newHistory): void; ``` Reset the history of the conversation. This will create a diff between the old and new history and send the necessary events to the Realtime API to update the history. #### Parameters [Section titled “Parameters”](#parameters-14) | Parameter | Type | Description | | ------------ | ---------------------------------------------------------------------------------------- | ------------------------------------ | | `oldHistory` | [`RealtimeItem`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimeitem/)\[] | The old history of the conversation. | | `newHistory` | [`RealtimeItem`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimeitem/)\[] | The new history of the conversation. | #### Returns [Section titled “Returns”](#returns-20) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-12) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/).[`resetHistory`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/#resethistory) #### Inherited from [Section titled “Inherited from”](#inherited-from-8) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/).[`resetHistory`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/#resethistory) *** ### sendAudio() [Section titled “sendAudio()”](#sendaudio) ```ts sendAudio(audio, options?): void; ``` Send an audio buffer to the Realtime API. This is used for your client to send audio to the model to respond. #### Parameters [Section titled “Parameters”](#parameters-15) | Parameter | Type | Description | | ----------------- | ------------------------- | --------------------------------- | | `audio` | `ArrayBuffer` | The audio buffer to send. | | `options?` | { `commit?`: `boolean`; } | The options for the audio buffer. | | `options.commit?` | `boolean` | ‐ | #### Returns [Section titled “Returns”](#returns-21) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-13) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/).[`sendAudio`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/#sendaudio) #### Overrides [Section titled “Overrides”](#overrides-8) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/).[`sendAudio`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/#sendaudio) *** ### sendEvent() [Section titled “sendEvent()”](#sendevent) ```ts sendEvent(event): void; ``` Send an event to the Realtime API. This will stringify the event and send it directly to the API. This can be used if you want to take control over the connection and send events manually. #### Parameters [Section titled “Parameters”](#parameters-16) | Parameter | Type | Description | | --------- | ------------------------------------------------------------------------------------------------------- | ------------------ | | `event` | [`RealtimeClientMessage`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimeclientmessage/) | The event to send. | #### Returns [Section titled “Returns”](#returns-22) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-14) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/).[`sendEvent`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/#sendevent) #### Overrides [Section titled “Overrides”](#overrides-9) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/).[`sendEvent`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/#sendevent) *** ### sendFunctionCallOutput() [Section titled “sendFunctionCallOutput()”](#sendfunctioncalloutput) ```ts sendFunctionCallOutput( toolCall, output, startResponse?): void; ``` Send the output of a function call to the Realtime API. #### Parameters [Section titled “Parameters”](#parameters-17) | Parameter | Type | Description | | ---------------- | --------------------------------------------------------------------------------------------------------- | --------------------------------------------------------- | | `toolCall` | [`TransportToolCallEvent`](/openai-agents-js/openai/agents/realtime/type-aliases/transporttoolcallevent/) | The tool call to send the output for. | | `output` | `string` | The output of the function call. | | `startResponse?` | `boolean` | Whether to start a new response after sending the output. | #### Returns [Section titled “Returns”](#returns-23) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-15) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/).[`sendFunctionCallOutput`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/#sendfunctioncalloutput) #### Inherited from [Section titled “Inherited from”](#inherited-from-9) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/).[`sendFunctionCallOutput`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/#sendfunctioncalloutput) *** ### sendMcpResponse() [Section titled “sendMcpResponse()”](#sendmcpresponse) ```ts sendMcpResponse( approvalRequest, approved, reason?): void; ``` Sends a response for an MCP tool call #### Parameters [Section titled “Parameters”](#parameters-18) | Parameter | Type | Description | | ------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------- | | `approvalRequest` | { `approved?`: `boolean` \| `null`; `arguments`: `z.ZodRecord`<`z.ZodString`, `z.ZodAny`>; `itemId`: `string`; `name`: `string`; `serverLabel`: `string`; `type`: `"mcp_approval_request"`; } | The approval request to respond to | | `approvalRequest.approved?` | `boolean` \| `null` | ‐ | | `approvalRequest.arguments` | `z.ZodRecord`<`z.ZodString`, `z.ZodAny`> | ‐ | | `approvalRequest.itemId?` | `string` | ‐ | | `approvalRequest.name?` | `string` | ‐ | | `approvalRequest.serverLabel?` | `string` | ‐ | | `approvalRequest.type?` | `"mcp_approval_request"` | ‐ | | `approved?` | `boolean` | Whether the tool call was approved or rejected | | `reason?` | `string` | Optional rejection text for the provider/model. | #### Returns [Section titled “Returns”](#returns-24) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-16) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/).[`sendMcpResponse`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/#sendmcpresponse) #### Inherited from [Section titled “Inherited from”](#inherited-from-10) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/).[`sendMcpResponse`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/#sendmcpresponse) *** ### sendMessage() [Section titled “sendMessage()”](#sendmessage) ```ts sendMessage( message, otherEventData, __namedParameters?): void; ``` Send a message to the Realtime API. This will create a new item in the conversation and trigger a response. #### Parameters [Section titled “Parameters”](#parameters-19) | Parameter | Type | Description | | ------------------------------------ | ---------------------------------- | ------------------------------ | | `message` | `RealtimeUserInput` | The message to send. | | `otherEventData` | `Record`<`string`, `any`> | Additional event data to send. | | `__namedParameters?` | { `triggerResponse?`: `boolean`; } | ‐ | | `__namedParameters.triggerResponse?` | `boolean` | ‐ | #### Returns [Section titled “Returns”](#returns-25) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-17) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/).[`sendMessage`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/#sendmessage) #### Inherited from [Section titled “Inherited from”](#inherited-from-11) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/).[`sendMessage`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/#sendmessage) *** ### updateSessionConfig() [Section titled “updateSessionConfig()”](#updatesessionconfig) ```ts updateSessionConfig(config): void; ``` Updates the session config. This will merge it with the current session config with the default values and send it to the Realtime API. #### Parameters [Section titled “Parameters”](#parameters-20) | Parameter | Type | Description | | --------- | ------------------------------------------------------------------------------------------------------------------ | ----------------------------- | | `config` | `Partial`<[`RealtimeSessionConfig`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimesessionconfig/)> | The session config to update. | #### Returns [Section titled “Returns”](#returns-26) `void` #### Implementation of [Section titled “Implementation of”](#implementation-of-18) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/).[`updateSessionConfig`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/#updatesessionconfig) #### Inherited from [Section titled “Inherited from”](#inherited-from-12) [`OpenAIRealtimeBase`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/).[`updateSessionConfig`](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/#updatesessionconfig) # OutputGuardrailTripwireTriggered Error thrown when an output guardrail tripwire is triggered. ## Extends [Section titled “Extends”](#extends) * `AgentsError` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | ------------------------------------------- | ------------ | | `TMeta` *extends* `OutputGuardrailMetadata` | ‐ | | `TOutputType` *extends* `AgentOutputType` | `TextOutput` | ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new OutputGuardrailTripwireTriggered( message, result, state?): OutputGuardrailTripwireTriggered; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ----------------------------------------------- | | `message` | `string` | | `result` | `OutputGuardrailResult`<`TMeta`, `TOutputType`> | | `state?` | `RunState`<`any`, `any`> | #### Returns [Section titled “Returns”](#returns) `OutputGuardrailTripwireTriggered`<`TMeta`, `TOutputType`> #### Overrides [Section titled “Overrides”](#overrides) ```ts AgentsError.constructor ``` ## Properties [Section titled “Properties”](#properties) ### message [Section titled “message”](#message) ```ts message: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from) ```ts AgentsError.message ``` *** ### name [Section titled “name”](#name) ```ts name: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-1) ```ts AgentsError.name ``` *** ### result [Section titled “result”](#result) ```ts result: OutputGuardrailResult; ``` *** ### stack? [Section titled “stack?”](#stack) ```ts optional stack?: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-2) ```ts AgentsError.stack ``` *** ### state? [Section titled “state?”](#state) ```ts optional state?: RunState>; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-3) ```ts AgentsError.state ``` *** ### stackTraceLimit [Section titled “stackTraceLimit”](#stacktracelimit) ```ts static stackTraceLimit: number; ``` The `Error.stackTraceLimit` property specifies the number of stack frames collected by a stack trace (whether generated by `new Error().stack` or `Error.captureStackTrace(obj)`). The default value is `10` but may be set to any valid JavaScript number. Changes will affect any stack trace captured *after* the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames. #### Inherited from [Section titled “Inherited from”](#inherited-from-4) ```ts AgentsError.stackTraceLimit ``` ## Methods [Section titled “Methods”](#methods) ### captureStackTrace() [Section titled “captureStackTrace()”](#capturestacktrace) ```ts static captureStackTrace(targetObject, constructorOpt?): void; ``` Creates a `.stack` property on `targetObject`, which when accessed returns a string representing the location in the code at which `Error.captureStackTrace()` was called. ```js const myObject = {}; Error.captureStackTrace(myObject); myObject.stack; // Similar to `new Error().stack` ``` The first line of the trace will be prefixed with `${myObject.name}: ${myObject.message}`. The optional `constructorOpt` argument accepts a function. If given, all frames above `constructorOpt`, including `constructorOpt`, will be omitted from the generated stack trace. The `constructorOpt` argument is useful for hiding implementation details of error generation from the user. For instance: ```js function a() { b(); } function b() { c(); } function c() { // Create an error without stack trace to avoid calculating the stack trace twice. const { stackTraceLimit } = Error; Error.stackTraceLimit = 0; const error = new Error(); Error.stackTraceLimit = stackTraceLimit; // Capture the stack trace above function b Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace throw error; } a(); ``` #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | ----------------- | ---------- | | `targetObject` | `object` | | `constructorOpt?` | `Function` | #### Returns [Section titled “Returns”](#returns-1) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-5) ```ts AgentsError.captureStackTrace ``` *** ### prepareStackTrace() [Section titled “prepareStackTrace()”](#preparestacktrace) ```ts static prepareStackTrace(err, stackTraces): any; ``` #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | ------------- | ------------- | | `err` | `Error` | | `stackTraces` | `CallSite`\[] | #### Returns [Section titled “Returns”](#returns-2) `any` #### See [Section titled “See”](#see) #### Inherited from [Section titled “Inherited from”](#inherited-from-6) ```ts AgentsError.prepareStackTrace ``` # RealtimeAgent A specialized agent instance that is meant to be used within a `RealtimeSession` to build voice agents. Due to the nature of this agent, some configuration options are not supported that are supported by regular `Agent` instances. For example: * `model` choice is not supported as all RealtimeAgents will be handled by the same model within a `RealtimeSession` * `modelSettings` is not supported as all RealtimeAgents will be handled by the same model within a `RealtimeSession` * `outputType` is not supported as RealtimeAgents do not support structured outputs * `toolUseBehavior` is not supported as all RealtimeAgents will be handled by the same model within a `RealtimeSession` * `voice` can be configured on an `Agent` level however it cannot be changed after the first agent within a `RealtimeSession` spoke ## Example [Section titled “Example”](#example) ```ts const agent = new RealtimeAgent({ name: 'my-agent', instructions: 'You are a helpful assistant that can answer questions and help with tasks.', }) const session = new RealtimeSession(agent); ``` ## Extends [Section titled “Extends”](#extends) * `Agent`<[`RealtimeContextData`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimecontextdata/)<`TContext`>, `TextOutput`> ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | ---------------- | | `TContext` | `UnknownContext` | ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new RealtimeAgent(config): RealtimeAgent; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ----------------------------------------------------------------------------------------------------------------------------- | | `config` | [`RealtimeAgentConfiguration`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimeagentconfiguration/)<`TContext`> | #### Returns [Section titled “Returns”](#returns) `RealtimeAgent`<`TContext`> #### Overrides [Section titled “Overrides”](#overrides) ```ts Agent, TextOutput>.constructor ``` ## Properties [Section titled “Properties”](#properties) ### handoffDescription [Section titled “handoffDescription”](#handoffdescription) ```ts handoffDescription: string; ``` A description of the agent. This is used when the agent is used as a handoff, so that an LLM knows what it does and when to invoke it. #### Inherited from [Section titled “Inherited from”](#inherited-from) ```ts Agent.handoffDescription ``` *** ### handoffs [Section titled “handoffs”](#handoffs) ```ts handoffs: (Agent | Handoff)[]; ``` Handoffs are sub-agents that the agent can delegate to. You can provide a list of handoffs, and the agent can choose to delegate to them if relevant. Allows for separation of concerns and modularity. #### Inherited from [Section titled “Inherited from”](#inherited-from-1) ```ts Agent.handoffs ``` *** ### inputGuardrails [Section titled “inputGuardrails”](#inputguardrails) ```ts inputGuardrails: InputGuardrail[]; ``` A list of checks that run in parallel to the agent by default; set `runInParallel` to false to block LLM/tool calls until the guardrail completes. Runs only if the agent is the first agent in the chain. #### Inherited from [Section titled “Inherited from”](#inherited-from-2) ```ts Agent.inputGuardrails ``` *** ### instructions [Section titled “instructions”](#instructions) ```ts instructions: string | ((runContext, agent) => string | Promise); ``` The instructions for the agent. Will be used as the “system prompt” when this agent is invoked. Describes what the agent should do, and how it responds. Can either be a string, or a function that dynamically generates instructions for the agent. If you provide a function, it will be called with the context and the agent instance. It must return a string. #### Inherited from [Section titled “Inherited from”](#inherited-from-3) ```ts Agent.instructions ``` *** ### mcpConfig [Section titled “mcpConfig”](#mcpconfig) ```ts mcpConfig: object; ``` Configuration for MCP servers used by this agent. | Name | Type | Description | | --------------------------- | -------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `convertSchemasToStrict?` | `boolean` | Try to convert MCP tool schemas to strict JSON schema. | | `errorFunction?` | `MCPToolErrorFunction` \| `null` | Optional function to convert MCP tool failures into model-visible messages. Set to null to rethrow errors instead of converting them. Server-level errorFunction values take precedence. | | `includeServerInToolNames?` | `boolean` | Prefix local MCP tool names with their server name before exposing them to the model. The SDK still invokes the original MCP tool name on the original server. | #### Inherited from [Section titled “Inherited from”](#inherited-from-4) ```ts Agent.mcpConfig ``` *** ### mcpServers [Section titled “mcpServers”](#mcpservers) ```ts mcpServers: MCPServer[]; ``` A list of [Model Context Protocol](https://modelcontextprotocol.io/) servers the agent can use. Every time the agent runs, it will include tools from these servers in the list of available tools. NOTE: You are expected to manage the lifecycle of these servers. Specifically, you must call `server.connect()` before passing it to the agent, and `server.close()` when the server is no longer needed. Consider using `connectMcpServers` or `MCPServers` to keep open/close in the same place. #### Inherited from [Section titled “Inherited from”](#inherited-from-5) ```ts Agent.mcpServers ``` *** ### model [Section titled “model”](#model) ```ts model: string | Model; ``` The model implementation to use when invoking the LLM. By default, if not set, the agent will use the default model returned by getDefaultModel (currently “gpt-5.4-mini”). #### Inherited from [Section titled “Inherited from”](#inherited-from-6) ```ts Agent.model ``` *** ### modelSettings [Section titled “modelSettings”](#modelsettings) ```ts modelSettings: ModelSettings; ``` Configures model-specific tuning parameters (e.g. temperature, top\_p, etc.) #### Inherited from [Section titled “Inherited from”](#inherited-from-7) ```ts Agent.modelSettings ``` *** ### name [Section titled “name”](#name) ```ts name: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-8) ```ts Agent.name ``` *** ### outputGuardrails [Section titled “outputGuardrails”](#outputguardrails) ```ts outputGuardrails: OutputGuardrail, RealtimeContextData>[]; ``` A list of checks that run on the final output of the agent, after generating a response. Runs only if the agent produces a final output. #### Inherited from [Section titled “Inherited from”](#inherited-from-9) ```ts Agent.outputGuardrails ``` *** ### outputType [Section titled “outputType”](#outputtype) ```ts outputType: "text"; ``` The type of the output object. If not provided, the output will be a string. #### Inherited from [Section titled “Inherited from”](#inherited-from-10) ```ts Agent.outputType ``` *** ### prompt? [Section titled “prompt?”](#prompt) ```ts optional prompt?: Prompt | ((runContext, agent) => Prompt | Promise); ``` The prompt template to use for the agent (OpenAI Responses API only). Can either be a prompt template object, or a function that returns a prompt template object. If a function is provided, it will be called with the run context and the agent instance. It must return a prompt template object. #### Inherited from [Section titled “Inherited from”](#inherited-from-11) ```ts Agent.prompt ``` *** ### resetToolChoice [Section titled “resetToolChoice”](#resettoolchoice) ```ts resetToolChoice: boolean; ``` Whether to reset the tool choice to the default value after a tool has been called. Defaults to `true`. This ensures that the agent doesn’t enter an infinite loop of tool usage. #### Inherited from [Section titled “Inherited from”](#inherited-from-12) ```ts Agent.resetToolChoice ``` *** ### tools [Section titled “tools”](#tools) ```ts tools: Tool>[]; ``` A list of tools the agent can use. #### Inherited from [Section titled “Inherited from”](#inherited-from-13) ```ts Agent.tools ``` *** ### toolUseBehavior [Section titled “toolUseBehavior”](#toolusebehavior) ```ts toolUseBehavior: ToolUseBehavior; ``` This lets you configure how tool use is handled. * run\_llm\_again: The default behavior. Tools are run, and then the LLM receives the results and gets to respond. * stop\_on\_first\_tool: The output of the first tool call is used as the final output. This means that the LLM does not process the result of the tool call. * A list of tool names: The agent will stop running if any of the tools in the list are called. The final output will be the output of the first matching tool call. The LLM does not process the result of the tool call. * A function: if you pass a function, it will be called with the run context and the list of tool results. It must return a `ToolsToFinalOutputResult`, which determines whether the tool call resulted in a final output. NOTE: This configuration is specific to `FunctionTools`. Hosted tools, such as file search, web search, etc. are always processed by the LLM #### Inherited from [Section titled “Inherited from”](#inherited-from-14) ```ts Agent.toolUseBehavior ``` *** ### voice? [Section titled “voice?”](#voice) ```ts readonly optional voice?: string; ``` The voice intended to be used by the agent. If another agent already spoke during the RealtimeSession, changing the voice during a handoff will fail. *** ### DEFAULT\_MODEL\_PLACEHOLDER [Section titled “DEFAULT\_MODEL\_PLACEHOLDER”](#default_model_placeholder) ```ts static DEFAULT_MODEL_PLACEHOLDER: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-15) ```ts Agent.DEFAULT_MODEL_PLACEHOLDER ``` ## Accessors [Section titled “Accessors”](#accessors) ### outputSchemaName [Section titled “outputSchemaName”](#outputschemaname) #### Get Signature [Section titled “Get Signature”](#get-signature) ```ts get outputSchemaName(): string; ``` Output schema name. ##### Returns [Section titled “Returns”](#returns-1) `string` #### Inherited from [Section titled “Inherited from”](#inherited-from-16) ```ts Agent.outputSchemaName ``` ## Methods [Section titled “Methods”](#methods) ### asTool() [Section titled “asTool()”](#astool) #### Call Signature [Section titled “Call Signature”](#call-signature) ```ts asTool(this, options): AgentTool, TAgent, ZodObject<{ input: ZodString; }, $strip>>; ``` Transform this agent into a tool, callable by other agents. This is different from handoffs in two ways: 1. In handoffs, the new agent receives the conversation history. In this tool, the new agent receives generated input. 2. In handoffs, the new agent takes over the conversation. In this tool, the new agent is called as a tool, and the conversation is continued by the original agent. ##### Type Parameters [Section titled “Type Parameters”](#type-parameters-1) | Type Parameter | Default type | | ----------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- | | `TAgent` *extends* `Agent`<[`RealtimeContextData`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimecontextdata/)<`TContext`>, `"text"`> | `Agent`<[`RealtimeContextData`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimecontextdata/)<`TContext`>, `"text"`> | ##### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | Description | | --------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------- | | `this` | `TAgent` | ‐ | | `options` | `AgentToolOptionsWithDefault`<[`RealtimeContextData`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimecontextdata/)<`TContext`>, `TAgent`> | Options for the tool. | ##### Returns [Section titled “Returns”](#returns-2) `AgentTool`<[`RealtimeContextData`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimecontextdata/)<`TContext`>, `TAgent`, `ZodObject`<{ `input`: `ZodString`; }, `$strip`>> A tool that runs the agent and returns the output text. ##### Inherited from [Section titled “Inherited from”](#inherited-from-17) ```ts Agent.asTool ``` #### Call Signature [Section titled “Call Signature”](#call-signature-1) ```ts asTool(this, options): AgentTool, TAgent, TParameters>; ``` Transform this agent into a tool, callable by other agents. This is different from handoffs in two ways: 1. In handoffs, the new agent receives the conversation history. In this tool, the new agent receives generated input. 2. In handoffs, the new agent takes over the conversation. In this tool, the new agent is called as a tool, and the conversation is continued by the original agent. ##### Type Parameters [Section titled “Type Parameters”](#type-parameters-2) | Type Parameter | Default type | | ----------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- | | `TAgent` *extends* `Agent`<[`RealtimeContextData`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimecontextdata/)<`TContext`>, `"text"`> | `Agent`<[`RealtimeContextData`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimecontextdata/)<`TContext`>, `"text"`> | | `TParameters` *extends* `AgentToolInputParameters` | `ZodObject`<{ `input`: `ZodString`; }, `$strip`> | ##### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | Description | | --------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------- | | `this` | `TAgent` | ‐ | | `options` | `AgentToolOptionsWithParameters`<[`RealtimeContextData`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimecontextdata/)<`TContext`>, `TAgent`, `TParameters`> | Options for the tool. | ##### Returns [Section titled “Returns”](#returns-3) `AgentTool`<[`RealtimeContextData`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimecontextdata/)<`TContext`>, `TAgent`, `TParameters`> A tool that runs the agent and returns the output text. ##### Inherited from [Section titled “Inherited from”](#inherited-from-18) ```ts Agent.asTool ``` *** ### clone() [Section titled “clone()”](#clone) ```ts clone(config): Agent, "text">; ``` Makes a copy of the agent, with the given arguments changed. For example, you could do: ```plaintext const newAgent = agent.clone({ instructions: 'New instructions' }) ``` #### Parameters [Section titled “Parameters”](#parameters-3) | Parameter | Type | Description | | --------- | ------------------------------------------------------ | ---------------------------------- | | `config` | `Partial`<`AgentConfiguration`<`TContext`, `TOutput`>> | A partial configuration to change. | #### Returns [Section titled “Returns”](#returns-4) `Agent`<[`RealtimeContextData`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimecontextdata/)<`TContext`>, `"text"`> A new agent with the given changes. #### Inherited from [Section titled “Inherited from”](#inherited-from-19) ```ts Agent.clone ``` *** ### emit() [Section titled “emit()”](#emit) ```ts emit(type, ...args): boolean; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-3) | Type Parameter | | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `K` *extends* keyof `AgentHookEvents`<[`RealtimeContextData`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimecontextdata/)<`TContext`>, `"text"`> | #### Parameters [Section titled “Parameters”](#parameters-4) | Parameter | Type | | --------- | -------------------------------------------------------------------------------------------------------------------------------------------------- | | `type` | `K` | | …`args` | `AgentHookEvents`<[`RealtimeContextData`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimecontextdata/)<`TContext`>, `"text"`>\[`K`] | #### Returns [Section titled “Returns”](#returns-5) `boolean` #### Inherited from [Section titled “Inherited from”](#inherited-from-20) ```ts Agent.emit ``` *** ### getAllTools() [Section titled “getAllTools()”](#getalltools) ```ts getAllTools(runContext): Promise>[]>; ``` ALl agent tools, including the MCPl and function tools. #### Parameters [Section titled “Parameters”](#parameters-5) | Parameter | Type | | ------------ | ----------------------------------------------------------------------------------------------------------------------------- | | `runContext` | `RunContext`<[`RealtimeContextData`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimecontextdata/)<`TContext`>> | #### Returns [Section titled “Returns”](#returns-6) `Promise`<`Tool`<[`RealtimeContextData`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimecontextdata/)<`TContext`>>\[]> all configured tools #### Inherited from [Section titled “Inherited from”](#inherited-from-21) ```ts Agent.getAllTools ``` *** ### getEnabledHandoffs() [Section titled “getEnabledHandoffs()”](#getenabledhandoffs) ```ts getEnabledHandoffs(runContext): Promise[]>; ``` Returns the handoffs that should be exposed to the model for the current run. Handoffs that provide an `isEnabled` function returning `false` are omitted. #### Parameters [Section titled “Parameters”](#parameters-6) | Parameter | Type | | ------------ | ----------------------------------------------------------------------------------------------------------------------------- | | `runContext` | `RunContext`<[`RealtimeContextData`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimecontextdata/)<`TContext`>> | #### Returns [Section titled “Returns”](#returns-7) `Promise`<`Handoff`<`any`, `any`>\[]> #### Inherited from [Section titled “Inherited from”](#inherited-from-22) ```ts Agent.getEnabledHandoffs ``` *** ### getMcpTools() [Section titled “getMcpTools()”](#getmcptools) ```ts getMcpTools(runContext): Promise>[]>; ``` Fetches the available tools from the MCP servers. #### Parameters [Section titled “Parameters”](#parameters-7) | Parameter | Type | | ------------ | ----------------------------------------------------------------------------------------------------------------------------- | | `runContext` | `RunContext`<[`RealtimeContextData`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimecontextdata/)<`TContext`>> | #### Returns [Section titled “Returns”](#returns-8) `Promise`<`Tool`<[`RealtimeContextData`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimecontextdata/)<`TContext`>>\[]> the MCP powered tools #### Inherited from [Section titled “Inherited from”](#inherited-from-23) ```ts Agent.getMcpTools ``` *** ### getPrompt() [Section titled “getPrompt()”](#getprompt) ```ts getPrompt(runContext): Promise; ``` Returns the prompt template for the agent, if defined. If the agent has a function as its prompt, this function will be called with the runContext and the agent instance. #### Parameters [Section titled “Parameters”](#parameters-8) | Parameter | Type | | ------------ | ----------------------------------------------------------------------------------------------------------------------------- | | `runContext` | `RunContext`<[`RealtimeContextData`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimecontextdata/)<`TContext`>> | #### Returns [Section titled “Returns”](#returns-9) `Promise`<`Prompt` | `undefined`> #### Inherited from [Section titled “Inherited from”](#inherited-from-24) ```ts Agent.getPrompt ``` *** ### getSystemPrompt() [Section titled “getSystemPrompt()”](#getsystemprompt) ```ts getSystemPrompt(runContext): Promise; ``` Returns the system prompt for the agent. If the agent has a function as its instructions, this function will be called with the runContext and the agent instance. #### Parameters [Section titled “Parameters”](#parameters-9) | Parameter | Type | | ------------ | ----------------------------------------------------------------------------------------------------------------------------- | | `runContext` | `RunContext`<[`RealtimeContextData`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimecontextdata/)<`TContext`>> | #### Returns [Section titled “Returns”](#returns-10) `Promise`<`string` | `undefined`> #### Inherited from [Section titled “Inherited from”](#inherited-from-25) ```ts Agent.getSystemPrompt ``` *** ### hasExplicitToolConfig() [Section titled “hasExplicitToolConfig()”](#hasexplicittoolconfig) ```ts hasExplicitToolConfig(): boolean; ``` #### Returns [Section titled “Returns”](#returns-11) `boolean` #### Inherited from [Section titled “Inherited from”](#inherited-from-26) ```ts Agent.hasExplicitToolConfig ``` *** ### off() [Section titled “off()”](#off) ```ts off(type, listener): EventEmitter; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-4) | Type Parameter | | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `K` *extends* keyof `AgentHookEvents`<[`RealtimeContextData`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimecontextdata/)<`TContext`>, `"text"`> | #### Parameters [Section titled “Parameters”](#parameters-10) | Parameter | Type | | ---------- | ------------------- | | `type` | `K` | | `listener` | (…`args`) => `void` | #### Returns [Section titled “Returns”](#returns-12) `EventEmitter`<`EventTypes`> #### Inherited from [Section titled “Inherited from”](#inherited-from-27) ```ts Agent.off ``` *** ### on() [Section titled “on()”](#on) ```ts on(type, listener): EventEmitter; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-5) | Type Parameter | | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `K` *extends* keyof `AgentHookEvents`<[`RealtimeContextData`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimecontextdata/)<`TContext`>, `"text"`> | #### Parameters [Section titled “Parameters”](#parameters-11) | Parameter | Type | | ---------- | ------------------- | | `type` | `K` | | `listener` | (…`args`) => `void` | #### Returns [Section titled “Returns”](#returns-13) `EventEmitter`<`EventTypes`> #### Inherited from [Section titled “Inherited from”](#inherited-from-28) ```ts Agent.on ``` *** ### once() [Section titled “once()”](#once) ```ts once(type, listener): EventEmitter; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-6) | Type Parameter | | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `K` *extends* keyof `AgentHookEvents`<[`RealtimeContextData`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimecontextdata/)<`TContext`>, `"text"`> | #### Parameters [Section titled “Parameters”](#parameters-12) | Parameter | Type | | ---------- | ------------------- | | `type` | `K` | | `listener` | (…`args`) => `void` | #### Returns [Section titled “Returns”](#returns-14) `EventEmitter`<`EventTypes`> #### Inherited from [Section titled “Inherited from”](#inherited-from-29) ```ts Agent.once ``` *** ### processFinalOutput() [Section titled “processFinalOutput()”](#processfinaloutput) ```ts processFinalOutput(output): string; ``` Processes the final output of the agent. #### Parameters [Section titled “Parameters”](#parameters-13) | Parameter | Type | Description | | --------- | -------- | ------------------------ | | `output` | `string` | The output of the agent. | #### Returns [Section titled “Returns”](#returns-15) `string` The parsed out. #### Inherited from [Section titled “Inherited from”](#inherited-from-30) ```ts Agent.processFinalOutput ``` *** ### toJSON() [Section titled “toJSON()”](#tojson) ```ts toJSON(): object; ``` Returns a JSON representation of the agent, which is serializable. #### Returns [Section titled “Returns”](#returns-16) `object` A JSON object containing the agent’s name. ##### name [Section titled “name”](#name-1) ```ts name: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-31) ```ts Agent.toJSON ``` *** ### create() [Section titled “create()”](#create) ```ts static create(config): Agent>; ``` Create an Agent with handoffs and automatically infer the union type for TOutput from the handoff agents’ output types. #### Type Parameters [Section titled “Type Parameters”](#type-parameters-7) | Type Parameter | Default type | | ----------------------------------------------------------------------------------- | ------------ | | `TOutput` *extends* `AgentOutputType`<`unknown`> | `"text"` | | `Handoffs` *extends* readonly (`Agent`<`any`, `any`> \| `Handoff`<`any`, `any`>)\[] | \[] | #### Parameters [Section titled “Parameters”](#parameters-14) | Parameter | Type | | --------- | ------------------------------------------------ | | `config` | `AgentConfigWithHandoffs`<`TOutput`, `Handoffs`> | #### Returns [Section titled “Returns”](#returns-17) `Agent`<`unknown`, `TOutput` | `HandoffsOutputUnion`<`Handoffs`>> #### Inherited from [Section titled “Inherited from”](#inherited-from-32) ```ts Agent.create ``` # RealtimeSession A `RealtimeSession` is the cornerstone of building Voice Agents. It’s the equivalent of a Runner in text-based agents except that it automatically handles multiple turns by maintaining a connection with the underlying transport layer. The session handles managing the local history copy, executes tools, runs output guardrails, and facilitates handoffs. The actual audio handling and generation of model responses is handled by the underlying transport layer. By default if you are using a browser with WebRTC support, the session will automatically use the WebRTC version of the OpenAI Realtime API. On the server or if you pass `websocket` as the transport layer, the session will establish a connection using WebSockets. In the case of WebRTC, in the browser, the transport layer will also automatically configure the microphone and audio output to be used by the session. You can also create a transport layer instance yourself and pass it in to have more control over the configuration or even extend the existing ones. Check out the `TwilioRealtimeTransportLayer` for an example of how to create a custom transport layer. ## Example [Section titled “Example”](#example) ```ts const agent = new RealtimeAgent({ name: 'my-agent', instructions: 'You are a helpful assistant that can answer questions and help with tasks.', }) const session = new RealtimeSession(agent); session.connect({ apiKey: 'your-api-key', }); ``` ## Extends [Section titled “Extends”](#extends) * `EventEmitter`<[`RealtimeSessionEventTypes`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimesessioneventtypes/)<`TBaseContext`>> ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | ------------ | | `TBaseContext` | `unknown` | ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new RealtimeSession(initialAgent, options?): RealtimeSession; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | -------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `initialAgent` | \| [`RealtimeAgent`](/openai-agents-js/openai/agents/realtime/classes/realtimeagent/)<`TBaseContext`> \| [`RealtimeAgent`](/openai-agents-js/openai/agents/realtime/classes/realtimeagent/)<[`RealtimeContextData`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimecontextdata/)<`TBaseContext`>> | | `options?` | `Partial`<[`RealtimeSessionOptions`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimesessionoptions/)<`TBaseContext`>> | #### Returns [Section titled “Returns”](#returns) `RealtimeSession`<`TBaseContext`> #### Overrides [Section titled “Overrides”](#overrides) ```ts RuntimeEventEmitter>.constructor ``` ## Properties [Section titled “Properties”](#properties) ### initialAgent [Section titled “initialAgent”](#initialagent) ```ts readonly initialAgent: | RealtimeAgent | RealtimeAgent>; ``` *** ### options [Section titled “options”](#options) ```ts readonly options: Partial>; ``` *** ### captureRejections [Section titled “captureRejections”](#capturerejections) ```ts static captureRejections: boolean; ``` Value: [boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type) Change the default `captureRejections` option on all new `EventEmitter` objects. #### Since [Section titled “Since”](#since) v13.4.0, v12.16.0 #### Inherited from [Section titled “Inherited from”](#inherited-from) ```ts RuntimeEventEmitter.captureRejections ``` *** ### captureRejectionSymbol [Section titled “captureRejectionSymbol”](#capturerejectionsymbol) ```ts readonly static captureRejectionSymbol: typeof captureRejectionSymbol; ``` Value: `Symbol.for('nodejs.rejection')` See how to write a custom `rejection handler`. #### Since [Section titled “Since”](#since-1) v13.4.0, v12.16.0 #### Inherited from [Section titled “Inherited from”](#inherited-from-1) ```ts RuntimeEventEmitter.captureRejectionSymbol ``` *** ### defaultMaxListeners [Section titled “defaultMaxListeners”](#defaultmaxlisteners) ```ts static defaultMaxListeners: number; ``` By default, a maximum of `10` listeners can be registered for any single event. This limit can be changed for individual `EventEmitter` instances using the `emitter.setMaxListeners(n)` method. To change the default for *all*`EventEmitter` instances, the `events.defaultMaxListeners` property can be used. If this value is not a positive number, a `RangeError` is thrown. Take caution when setting the `events.defaultMaxListeners` because the change affects *all* `EventEmitter` instances, including those created before the change is made. However, calling `emitter.setMaxListeners(n)` still has precedence over `events.defaultMaxListeners`. This is not a hard limit. The `EventEmitter` instance will allow more listeners to be added but will output a trace warning to stderr indicating that a “possible EventEmitter memory leak” has been detected. For any single `EventEmitter`, the `emitter.getMaxListeners()` and `emitter.setMaxListeners()` methods can be used to temporarily avoid this warning: ```js import { EventEmitter } from 'node:events'; const emitter = new EventEmitter(); emitter.setMaxListeners(emitter.getMaxListeners() + 1); emitter.once('event', () => { // do stuff emitter.setMaxListeners(Math.max(emitter.getMaxListeners() - 1, 0)); }); ``` The `--trace-warnings` command-line flag can be used to display the stack trace for such warnings. The emitted warning can be inspected with `process.on('warning')` and will have the additional `emitter`, `type`, and `count` properties, referring to the event emitter instance, the event’s name and the number of attached listeners, respectively. Its `name` property is set to `'MaxListenersExceededWarning'`. #### Since [Section titled “Since”](#since-2) v0.11.2 #### Inherited from [Section titled “Inherited from”](#inherited-from-2) ```ts RuntimeEventEmitter.defaultMaxListeners ``` *** ### errorMonitor [Section titled “errorMonitor”](#errormonitor) ```ts readonly static errorMonitor: typeof errorMonitor; ``` This symbol shall be used to install a listener for only monitoring `'error'` events. Listeners installed using this symbol are called before the regular `'error'` listeners are called. Installing a listener using this symbol does not change the behavior once an `'error'` event is emitted. Therefore, the process will still crash if no regular `'error'` listener is installed. #### Since [Section titled “Since”](#since-3) v13.6.0, v12.17.0 #### Inherited from [Section titled “Inherited from”](#inherited-from-3) ```ts RuntimeEventEmitter.errorMonitor ``` ## Accessors [Section titled “Accessors”](#accessors) ### availableMcpTools [Section titled “availableMcpTools”](#availablemcptools) #### Get Signature [Section titled “Get Signature”](#get-signature) ```ts get availableMcpTools(): RealtimeMcpToolInfo[]; ``` ##### Returns [Section titled “Returns”](#returns-1) `RealtimeMcpToolInfo`\[] *** ### context [Section titled “context”](#context) #### Get Signature [Section titled “Get Signature”](#get-signature-1) ```ts get context(): RunContext>; ``` The current context of the session. ##### Returns [Section titled “Returns”](#returns-2) `RunContext`<[`RealtimeContextData`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimecontextdata/)<`TBaseContext`>> *** ### currentAgent [Section titled “currentAgent”](#currentagent) #### Get Signature [Section titled “Get Signature”](#get-signature-2) ```ts get currentAgent(): | RealtimeAgent | RealtimeAgent>; ``` The current agent in the session. ##### Returns [Section titled “Returns”](#returns-3) \| [`RealtimeAgent`](/openai-agents-js/openai/agents/realtime/classes/realtimeagent/)<`TBaseContext`> | [`RealtimeAgent`](/openai-agents-js/openai/agents/realtime/classes/realtimeagent/)<[`RealtimeContextData`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimecontextdata/)<`TBaseContext`>> *** ### history [Section titled “history”](#history) #### Get Signature [Section titled “Get Signature”](#get-signature-3) ```ts get history(): RealtimeItem[]; ``` The history of the session. ##### Returns [Section titled “Returns”](#returns-4) [`RealtimeItem`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimeitem/)\[] *** ### muted [Section titled “muted”](#muted) #### Get Signature [Section titled “Get Signature”](#get-signature-4) ```ts get muted(): boolean | null; ``` Whether the session is muted. Might be `null` if the underlying transport layer does not support muting. ##### Returns [Section titled “Returns”](#returns-5) `boolean` | `null` *** ### transport [Section titled “transport”](#transport) #### Get Signature [Section titled “Get Signature”](#get-signature-5) ```ts get transport(): RealtimeTransportLayer; ``` The transport layer used by the session. ##### Returns [Section titled “Returns”](#returns-6) [`RealtimeTransportLayer`](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/) *** ### usage [Section titled “usage”](#usage) #### Get Signature [Section titled “Get Signature”](#get-signature-6) ```ts get usage(): Usage; ``` The current usage of the session. ##### Returns [Section titled “Returns”](#returns-7) `Usage` ## Methods [Section titled “Methods”](#methods) ### \[captureRejectionSymbol]\()? [Section titled “\[captureRejectionSymbol\]()?”](#capturerejectionsymbol-1) ```ts optional [captureRejectionSymbol]( error, event, ... args): void; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-1) | Type Parameter | | -------------- | | `K` | #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `error` | `Error` | | `event` | `K` \| keyof RealtimeSessionEventTypes\ | | …`args` | `K` *extends* keyof [`RealtimeSessionEventTypes`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimesessioneventtypes/)<`TBaseContext`> ? [`RealtimeSessionEventTypes`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimesessioneventtypes/)<`TBaseContext`>\[`K`] : `never` | #### Returns [Section titled “Returns”](#returns-8) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-4) ```ts RuntimeEventEmitter.[captureRejectionSymbol] ``` *** ### addImage() [Section titled “addImage()”](#addimage) ```ts addImage(image, __namedParameters?): void; ``` Add image to the session #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | Description | | ------------------------------------ | ---------------------------------- | ----------------- | | `image` | `string` | The image to add. | | `__namedParameters?` | { `triggerResponse?`: `boolean`; } | ‐ | | `__namedParameters.triggerResponse?` | `boolean` | ‐ | #### Returns [Section titled “Returns”](#returns-9) `void` *** ### addListener() [Section titled “addListener()”](#addlistener) ```ts addListener(eventName, listener): this; ``` Alias for `emitter.on(eventName, listener)`. #### Type Parameters [Section titled “Type Parameters”](#type-parameters-2) | Type Parameter | | -------------- | | `K` | #### Parameters [Section titled “Parameters”](#parameters-3) | Parameter | Type | | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | `eventName` | keyof RealtimeSessionEventTypes\ \| `K` | | `listener` | `K` *extends* keyof [`RealtimeSessionEventTypes`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimesessioneventtypes/)<`TBaseContext`> ? [`RealtimeSessionEventTypes`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimesessioneventtypes/)<`TBaseContext`>\[`K`] *extends* `unknown`\[] ? (…`args`) => `void` : `never` : `never` | #### Returns [Section titled “Returns”](#returns-10) `this` #### Since [Section titled “Since”](#since-4) v0.1.26 #### Inherited from [Section titled “Inherited from”](#inherited-from-5) ```ts RuntimeEventEmitter.addListener ``` *** ### approve() [Section titled “approve()”](#approve) ```ts approve(approvalItem, options?): Promise; ``` Approve a tool call. This will also trigger the tool call to the agent. #### Parameters [Section titled “Parameters”](#parameters-4) | Parameter | Type | Description | | ------------------------ | -------------------------------- | ---------------------------------------- | | `approvalItem` | `RunToolApprovalItem` | The approval item to approve. | | `options?` | { `alwaysApprove?`: `boolean`; } | Additional options. | | `options.alwaysApprove?` | `boolean` | Whether to always approve the tool call. | #### Returns [Section titled “Returns”](#returns-11) `Promise`<`void`> *** ### close() [Section titled “close()”](#close) ```ts close(): void; ``` Disconnect from the session. #### Returns [Section titled “Returns”](#returns-12) `void` *** ### connect() [Section titled “connect()”](#connect) ```ts connect(options): Promise; ``` Connect to the session. This will establish the connection to the underlying transport layer and start the session. After connecting, the session will also emit a `history_updated` event with an empty history. #### Parameters [Section titled “Parameters”](#parameters-5) | Parameter | Type | Description | | --------- | ----------------------------------------------------------------------------------------------------------------------- | ------------------------------- | | `options` | [`RealtimeSessionConnectOptions`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimesessionconnectoptions/) | The options for the connection. | #### Returns [Section titled “Returns”](#returns-13) `Promise`<`void`> *** ### emit() [Section titled “emit()”](#emit) ```ts emit(eventName, ...args): boolean; ``` Synchronously calls each of the listeners registered for the event named `eventName`, in the order they were registered, passing the supplied arguments to each. Returns `true` if the event had listeners, `false` otherwise. ```js import { EventEmitter } from 'node:events'; const myEmitter = new EventEmitter(); // First listener myEmitter.on('event', function firstListener() { console.log('Helloooo! first listener'); }); // Second listener myEmitter.on('event', function secondListener(arg1, arg2) { console.log(`event with parameters ${arg1}, ${arg2} in second listener`); }); // Third listener myEmitter.on('event', function thirdListener(...args) { const parameters = args.join(', '); console.log(`event with parameters ${parameters} in third listener`); }); console.log(myEmitter.listeners('event')); myEmitter.emit('event', 1, 2, 3, 4, 5); // Prints: // [ // [Function: firstListener], // [Function: secondListener], // [Function: thirdListener] // ] // Helloooo! first listener // event with parameters 1, 2 in second listener // event with parameters 1, 2, 3, 4, 5 in third listener ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-3) | Type Parameter | | -------------- | | `K` | #### Parameters [Section titled “Parameters”](#parameters-6) | Parameter | Type | | ----------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `eventName` | keyof RealtimeSessionEventTypes\ \| `K` | | …`args` | `K` *extends* keyof [`RealtimeSessionEventTypes`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimesessioneventtypes/)<`TBaseContext`> ? [`RealtimeSessionEventTypes`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimesessioneventtypes/)<`TBaseContext`>\[`K`] : `never` | #### Returns [Section titled “Returns”](#returns-14) `boolean` #### Since [Section titled “Since”](#since-5) v0.1.26 #### Inherited from [Section titled “Inherited from”](#inherited-from-6) ```ts RuntimeEventEmitter.emit ``` *** ### eventNames() [Section titled “eventNames()”](#eventnames) ```ts eventNames(): ( | "agent_start" | "agent_end" | "agent_handoff" | "agent_tool_start" | "agent_tool_end" | "transport_event" | "audio_start" | "audio_stopped" | "audio" | "audio_interrupted" | "guardrail_tripped" | "history_updated" | "history_added" | "error" | "tool_approval_requested" | "mcp_tool_call_completed" | "mcp_tools_changed")[]; ``` Returns an array listing the events for which the emitter has registered listeners. The values in the array are strings or `Symbol`s. ```js import { EventEmitter } from 'node:events'; const myEE = new EventEmitter(); myEE.on('foo', () => {}); myEE.on('bar', () => {}); const sym = Symbol('symbol'); myEE.on(sym, () => {}); console.log(myEE.eventNames()); // Prints: [ 'foo', 'bar', Symbol(symbol) ] ``` #### Returns [Section titled “Returns”](#returns-15) ( | `"agent_start"` | `"agent_end"` | `"agent_handoff"` | `"agent_tool_start"` | `"agent_tool_end"` | `"transport_event"` | `"audio_start"` | `"audio_stopped"` | `"audio"` | `"audio_interrupted"` | `"guardrail_tripped"` | `"history_updated"` | `"history_added"` | `"error"` | `"tool_approval_requested"` | `"mcp_tool_call_completed"` | `"mcp_tools_changed"`)\[] #### Since [Section titled “Since”](#since-6) v6.0.0 #### Inherited from [Section titled “Inherited from”](#inherited-from-7) ```ts RuntimeEventEmitter.eventNames ``` *** ### getInitialSessionConfig() [Section titled “getInitialSessionConfig()”](#getinitialsessionconfig) ```ts getInitialSessionConfig(overrides?): Promise>; ``` Compute the initial session config that the current session will use when connecting. This mirrors the configuration payload we send during `connect`, including dynamic values such as the upstream agent instructions, tool definitions, and prompt content generated at runtime. Keeping this helper exposed allows transports or orchestration layers to precompute a CallAccept-compatible payload without opening a socket. #### Parameters [Section titled “Parameters”](#parameters-7) | Parameter | Type | Description | | ------------ | ------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------ | | `overrides?` | `Partial`<[`RealtimeSessionConfig`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimesessionconfig/)> | Additional config overrides applied on top of the session options. | #### Returns [Section titled “Returns”](#returns-16) `Promise`<`Partial`<[`RealtimeSessionConfig`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimesessionconfig/)>> *** ### getMaxListeners() [Section titled “getMaxListeners()”](#getmaxlisteners) ```ts getMaxListeners(): number; ``` Returns the current max listener value for the `EventEmitter` which is either set by `emitter.setMaxListeners(n)` or defaults to [EventEmitter.defaultMaxListeners](/openai-agents-js/openai/agents/realtime/classes/realtimesession/#defaultmaxlisteners). #### Returns [Section titled “Returns”](#returns-17) `number` #### Since [Section titled “Since”](#since-7) v1.0.0 #### Inherited from [Section titled “Inherited from”](#inherited-from-8) ```ts RuntimeEventEmitter.getMaxListeners ``` *** ### interrupt() [Section titled “interrupt()”](#interrupt) ```ts interrupt(): void; ``` Interrupt the session artificially for example if you want to build a “stop talking” button. #### Returns [Section titled “Returns”](#returns-18) `void` *** ### listenerCount() [Section titled “listenerCount()”](#listenercount) ```ts listenerCount(eventName, listener?): number; ``` Returns the number of listeners listening for the event named `eventName`. If `listener` is provided, it will return how many times the listener is found in the list of the listeners of the event. #### Type Parameters [Section titled “Type Parameters”](#type-parameters-4) | Type Parameter | | -------------- | | `K` | #### Parameters [Section titled “Parameters”](#parameters-8) | Parameter | Type | Description | | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------- | | `eventName` | keyof RealtimeSessionEventTypes\ \| `K` | The name of the event being listened for | | `listener?` | `K` *extends* keyof [`RealtimeSessionEventTypes`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimesessioneventtypes/)<`TBaseContext`> ? [`RealtimeSessionEventTypes`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimesessioneventtypes/)<`TBaseContext`>\[`K`] *extends* `unknown`\[] ? (…`args`) => `void` : `never` : `never` | The event handler function | #### Returns [Section titled “Returns”](#returns-19) `number` #### Since [Section titled “Since”](#since-8) v3.2.0 #### Inherited from [Section titled “Inherited from”](#inherited-from-9) ```ts RuntimeEventEmitter.listenerCount ``` *** ### listeners() [Section titled “listeners()”](#listeners) ```ts listeners(eventName): K extends keyof RealtimeSessionEventTypes ? RealtimeSessionEventTypes[K] extends unknown[] ? (...args) => void : never : never[]; ``` Returns a copy of the array of listeners for the event named `eventName`. ```js server.on('connection', (stream) => { console.log('someone connected!'); }); console.log(util.inspect(server.listeners('connection'))); // Prints: [ [Function] ] ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-5) | Type Parameter | | -------------- | | `K` | #### Parameters [Section titled “Parameters”](#parameters-9) | Parameter | Type | | ----------- | ----------------------------------------------------- | | `eventName` | keyof RealtimeSessionEventTypes\ \| `K` | #### Returns [Section titled “Returns”](#returns-20) `K` *extends* keyof [`RealtimeSessionEventTypes`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimesessioneventtypes/)<`TBaseContext`> ? [`RealtimeSessionEventTypes`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimesessioneventtypes/)<`TBaseContext`>\[`K`] *extends* `unknown`\[] ? (…`args`) => `void` : `never` : `never`\[] #### Since [Section titled “Since”](#since-9) v0.1.26 #### Inherited from [Section titled “Inherited from”](#inherited-from-10) ```ts RuntimeEventEmitter.listeners ``` *** ### mute() [Section titled “mute()”](#mute) ```ts mute(muted): void; ``` Mute the session. #### Parameters [Section titled “Parameters”](#parameters-10) | Parameter | Type | Description | | --------- | --------- | ---------------------------- | | `muted` | `boolean` | Whether to mute the session. | #### Returns [Section titled “Returns”](#returns-21) `void` *** ### off() [Section titled “off()”](#off) ```ts off(eventName, listener): this; ``` Alias for `emitter.removeListener()`. #### Type Parameters [Section titled “Type Parameters”](#type-parameters-6) | Type Parameter | | -------------- | | `K` | #### Parameters [Section titled “Parameters”](#parameters-11) | Parameter | Type | | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | `eventName` | keyof RealtimeSessionEventTypes\ \| `K` | | `listener` | `K` *extends* keyof [`RealtimeSessionEventTypes`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimesessioneventtypes/)<`TBaseContext`> ? [`RealtimeSessionEventTypes`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimesessioneventtypes/)<`TBaseContext`>\[`K`] *extends* `unknown`\[] ? (…`args`) => `void` : `never` : `never` | #### Returns [Section titled “Returns”](#returns-22) `this` #### Since [Section titled “Since”](#since-10) v10.0.0 #### Inherited from [Section titled “Inherited from”](#inherited-from-11) ```ts RuntimeEventEmitter.off ``` *** ### on() [Section titled “on()”](#on) ```ts on(eventName, listener): this; ``` Adds the `listener` function to the end of the listeners array for the event named `eventName`. No checks are made to see if the `listener` has already been added. Multiple calls passing the same combination of `eventName` and `listener` will result in the `listener` being added, and called, multiple times. ```js server.on('connection', (stream) => { console.log('someone connected!'); }); ``` Returns a reference to the `EventEmitter`, so that calls can be chained. By default, event listeners are invoked in the order they are added. The `emitter.prependListener()` method can be used as an alternative to add the event listener to the beginning of the listeners array. ```js import { EventEmitter } from 'node:events'; const myEE = new EventEmitter(); myEE.on('foo', () => console.log('a')); myEE.prependListener('foo', () => console.log('b')); myEE.emit('foo'); // Prints: // b // a ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-7) | Type Parameter | | -------------- | | `K` | #### Parameters [Section titled “Parameters”](#parameters-12) | Parameter | Type | Description | | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------- | | `eventName` | keyof RealtimeSessionEventTypes\ \| `K` | The name of the event. | | `listener` | `K` *extends* keyof [`RealtimeSessionEventTypes`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimesessioneventtypes/)<`TBaseContext`> ? [`RealtimeSessionEventTypes`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimesessioneventtypes/)<`TBaseContext`>\[`K`] *extends* `unknown`\[] ? (…`args`) => `void` : `never` : `never` | The callback function | #### Returns [Section titled “Returns”](#returns-23) `this` #### Since [Section titled “Since”](#since-11) v0.1.101 #### Inherited from [Section titled “Inherited from”](#inherited-from-12) ```ts RuntimeEventEmitter.on ``` *** ### once() [Section titled “once()”](#once) ```ts once(eventName, listener): this; ``` Adds a **one-time** `listener` function for the event named `eventName`. The next time `eventName` is triggered, this listener is removed and then invoked. ```js server.once('connection', (stream) => { console.log('Ah, we have our first user!'); }); ``` Returns a reference to the `EventEmitter`, so that calls can be chained. By default, event listeners are invoked in the order they are added. The `emitter.prependOnceListener()` method can be used as an alternative to add the event listener to the beginning of the listeners array. ```js import { EventEmitter } from 'node:events'; const myEE = new EventEmitter(); myEE.once('foo', () => console.log('a')); myEE.prependOnceListener('foo', () => console.log('b')); myEE.emit('foo'); // Prints: // b // a ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-8) | Type Parameter | | -------------- | | `K` | #### Parameters [Section titled “Parameters”](#parameters-13) | Parameter | Type | Description | | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------- | | `eventName` | keyof RealtimeSessionEventTypes\ \| `K` | The name of the event. | | `listener` | `K` *extends* keyof [`RealtimeSessionEventTypes`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimesessioneventtypes/)<`TBaseContext`> ? [`RealtimeSessionEventTypes`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimesessioneventtypes/)<`TBaseContext`>\[`K`] *extends* `unknown`\[] ? (…`args`) => `void` : `never` : `never` | The callback function | #### Returns [Section titled “Returns”](#returns-24) `this` #### Since [Section titled “Since”](#since-12) v0.3.0 #### Inherited from [Section titled “Inherited from”](#inherited-from-13) ```ts RuntimeEventEmitter.once ``` *** ### prependListener() [Section titled “prependListener()”](#prependlistener) ```ts prependListener(eventName, listener): this; ``` Adds the `listener` function to the *beginning* of the listeners array for the event named `eventName`. No checks are made to see if the `listener` has already been added. Multiple calls passing the same combination of `eventName` and `listener` will result in the `listener` being added, and called, multiple times. ```js server.prependListener('connection', (stream) => { console.log('someone connected!'); }); ``` Returns a reference to the `EventEmitter`, so that calls can be chained. #### Type Parameters [Section titled “Type Parameters”](#type-parameters-9) | Type Parameter | | -------------- | | `K` | #### Parameters [Section titled “Parameters”](#parameters-14) | Parameter | Type | Description | | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------- | | `eventName` | keyof RealtimeSessionEventTypes\ \| `K` | The name of the event. | | `listener` | `K` *extends* keyof [`RealtimeSessionEventTypes`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimesessioneventtypes/)<`TBaseContext`> ? [`RealtimeSessionEventTypes`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimesessioneventtypes/)<`TBaseContext`>\[`K`] *extends* `unknown`\[] ? (…`args`) => `void` : `never` : `never` | The callback function | #### Returns [Section titled “Returns”](#returns-25) `this` #### Since [Section titled “Since”](#since-13) v6.0.0 #### Inherited from [Section titled “Inherited from”](#inherited-from-14) ```ts RuntimeEventEmitter.prependListener ``` *** ### prependOnceListener() [Section titled “prependOnceListener()”](#prependoncelistener) ```ts prependOnceListener(eventName, listener): this; ``` Adds a **one-time**`listener` function for the event named `eventName` to the *beginning* of the listeners array. The next time `eventName` is triggered, this listener is removed, and then invoked. ```js server.prependOnceListener('connection', (stream) => { console.log('Ah, we have our first user!'); }); ``` Returns a reference to the `EventEmitter`, so that calls can be chained. #### Type Parameters [Section titled “Type Parameters”](#type-parameters-10) | Type Parameter | | -------------- | | `K` | #### Parameters [Section titled “Parameters”](#parameters-15) | Parameter | Type | Description | | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------- | | `eventName` | keyof RealtimeSessionEventTypes\ \| `K` | The name of the event. | | `listener` | `K` *extends* keyof [`RealtimeSessionEventTypes`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimesessioneventtypes/)<`TBaseContext`> ? [`RealtimeSessionEventTypes`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimesessioneventtypes/)<`TBaseContext`>\[`K`] *extends* `unknown`\[] ? (…`args`) => `void` : `never` : `never` | The callback function | #### Returns [Section titled “Returns”](#returns-26) `this` #### Since [Section titled “Since”](#since-14) v6.0.0 #### Inherited from [Section titled “Inherited from”](#inherited-from-15) ```ts RuntimeEventEmitter.prependOnceListener ``` *** ### rawListeners() [Section titled “rawListeners()”](#rawlisteners) ```ts rawListeners(eventName): K extends keyof RealtimeSessionEventTypes ? RealtimeSessionEventTypes[K] extends unknown[] ? (...args) => void : never : never[]; ``` Returns a copy of the array of listeners for the event named `eventName`, including any wrappers (such as those created by `.once()`). ```js import { EventEmitter } from 'node:events'; const emitter = new EventEmitter(); emitter.once('log', () => console.log('log once')); // Returns a new Array with a function `onceWrapper` which has a property // `listener` which contains the original listener bound above const listeners = emitter.rawListeners('log'); const logFnWrapper = listeners[0]; // Logs "log once" to the console and does not unbind the `once` event logFnWrapper.listener(); // Logs "log once" to the console and removes the listener logFnWrapper(); emitter.on('log', () => console.log('log persistently')); // Will return a new Array with a single function bound by `.on()` above const newListeners = emitter.rawListeners('log'); // Logs "log persistently" twice newListeners[0](); emitter.emit('log'); ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-11) | Type Parameter | | -------------- | | `K` | #### Parameters [Section titled “Parameters”](#parameters-16) | Parameter | Type | | ----------- | ----------------------------------------------------- | | `eventName` | keyof RealtimeSessionEventTypes\ \| `K` | #### Returns [Section titled “Returns”](#returns-27) `K` *extends* keyof [`RealtimeSessionEventTypes`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimesessioneventtypes/)<`TBaseContext`> ? [`RealtimeSessionEventTypes`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimesessioneventtypes/)<`TBaseContext`>\[`K`] *extends* `unknown`\[] ? (…`args`) => `void` : `never` : `never`\[] #### Since [Section titled “Since”](#since-15) v9.4.0 #### Inherited from [Section titled “Inherited from”](#inherited-from-16) ```ts RuntimeEventEmitter.rawListeners ``` *** ### reject() [Section titled “reject()”](#reject) ```ts reject(approvalItem, options?): Promise; ``` Reject a tool call. This will also trigger the tool call to the agent. #### Parameters [Section titled “Parameters”](#parameters-17) | Parameter | Type | Description | | ----------------------- | ----------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------- | | `approvalItem` | `RunToolApprovalItem` | The approval item to reject. | | `options?` | { `alwaysReject?`: `boolean`; `message?`: `string`; } | Additional options. | | `options.alwaysReject?` | `boolean` | Whether to always reject the tool call. | | `options.message?` | `string` | The rejection text sent to the model. If not provided, `toolErrorFormatter` (if configured) or the SDK default is used. | #### Returns [Section titled “Returns”](#returns-28) `Promise`<`void`> *** ### removeAllListeners() [Section titled “removeAllListeners()”](#removealllisteners) ```ts removeAllListeners(eventName?): this; ``` Removes all listeners, or those of the specified `eventName`. It is bad practice to remove listeners added elsewhere in the code, particularly when the `EventEmitter` instance was created by some other component or module (e.g. sockets or file streams). Returns a reference to the `EventEmitter`, so that calls can be chained. #### Parameters [Section titled “Parameters”](#parameters-18) | Parameter | Type | | ------------ | --------- | | `eventName?` | `unknown` | #### Returns [Section titled “Returns”](#returns-29) `this` #### Since [Section titled “Since”](#since-16) v0.1.26 #### Inherited from [Section titled “Inherited from”](#inherited-from-17) ```ts RuntimeEventEmitter.removeAllListeners ``` *** ### removeListener() [Section titled “removeListener()”](#removelistener) ```ts removeListener(eventName, listener): this; ``` Removes the specified `listener` from the listener array for the event named `eventName`. ```js const callback = (stream) => { console.log('someone connected!'); }; server.on('connection', callback); // ... server.removeListener('connection', callback); ``` `removeListener()` will remove, at most, one instance of a listener from the listener array. If any single listener has been added multiple times to the listener array for the specified `eventName`, then `removeListener()` must be called multiple times to remove each instance. Once an event is emitted, all listeners attached to it at the time of emitting are called in order. This implies that any `removeListener()` or `removeAllListeners()` calls *after* emitting and *before* the last listener finishes execution will not remove them from`emit()` in progress. Subsequent events behave as expected. ```js import { EventEmitter } from 'node:events'; class MyEmitter extends EventEmitter {} const myEmitter = new MyEmitter(); const callbackA = () => { console.log('A'); myEmitter.removeListener('event', callbackB); }; const callbackB = () => { console.log('B'); }; myEmitter.on('event', callbackA); myEmitter.on('event', callbackB); // callbackA removes listener callbackB but it will still be called. // Internal listener array at time of emit [callbackA, callbackB] myEmitter.emit('event'); // Prints: // A // B // callbackB is now removed. // Internal listener array [callbackA] myEmitter.emit('event'); // Prints: // A ``` Because listeners are managed using an internal array, calling this will change the position indices of any listener registered *after* the listener being removed. This will not impact the order in which listeners are called, but it means that any copies of the listener array as returned by the `emitter.listeners()` method will need to be recreated. When a single function has been added as a handler multiple times for a single event (as in the example below), `removeListener()` will remove the most recently added instance. In the example the `once('ping')` listener is removed: ```js import { EventEmitter } from 'node:events'; const ee = new EventEmitter(); function pong() { console.log('pong'); } ee.on('ping', pong); ee.once('ping', pong); ee.removeListener('ping', pong); ee.emit('ping'); ee.emit('ping'); ``` Returns a reference to the `EventEmitter`, so that calls can be chained. #### Type Parameters [Section titled “Type Parameters”](#type-parameters-12) | Type Parameter | | -------------- | | `K` | #### Parameters [Section titled “Parameters”](#parameters-19) | Parameter | Type | | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | `eventName` | keyof RealtimeSessionEventTypes\ \| `K` | | `listener` | `K` *extends* keyof [`RealtimeSessionEventTypes`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimesessioneventtypes/)<`TBaseContext`> ? [`RealtimeSessionEventTypes`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimesessioneventtypes/)<`TBaseContext`>\[`K`] *extends* `unknown`\[] ? (…`args`) => `void` : `never` : `never` | #### Returns [Section titled “Returns”](#returns-30) `this` #### Since [Section titled “Since”](#since-17) v0.1.26 #### Inherited from [Section titled “Inherited from”](#inherited-from-18) ```ts RuntimeEventEmitter.removeListener ``` *** ### sendAudio() [Section titled “sendAudio()”](#sendaudio) ```ts sendAudio(audio, options?): void; ``` Send audio to the session. #### Parameters [Section titled “Parameters”](#parameters-20) | Parameter | Type | Description | | ----------------- | ------------------------- | ------------------------------------------- | | `audio` | `ArrayBuffer` | The audio to send. | | `options?` | { `commit?`: `boolean`; } | Additional options. | | `options.commit?` | `boolean` | Whether to finish the turn with this audio. | #### Returns [Section titled “Returns”](#returns-31) `void` *** ### sendMessage() [Section titled “sendMessage()”](#sendmessage) ```ts sendMessage(message, otherEventData?): void; ``` Send a message to the session. #### Parameters [Section titled “Parameters”](#parameters-21) | Parameter | Type | Description | | ----------------- | ------------------------- | ------------------------------ | | `message` | `RealtimeUserInput` | The message to send. | | `otherEventData?` | `Record`<`string`, `any`> | Additional event data to send. | #### Returns [Section titled “Returns”](#returns-32) `void` *** ### setMaxListeners() [Section titled “setMaxListeners()”](#setmaxlisteners) ```ts setMaxListeners(n): this; ``` By default `EventEmitter`s will print a warning if more than `10` listeners are added for a particular event. This is a useful default that helps finding memory leaks. The `emitter.setMaxListeners()` method allows the limit to be modified for this specific `EventEmitter` instance. The value can be set to `Infinity` (or `0`) to indicate an unlimited number of listeners. Returns a reference to the `EventEmitter`, so that calls can be chained. #### Parameters [Section titled “Parameters”](#parameters-22) | Parameter | Type | | --------- | -------- | | `n` | `number` | #### Returns [Section titled “Returns”](#returns-33) `this` #### Since [Section titled “Since”](#since-18) v0.3.5 #### Inherited from [Section titled “Inherited from”](#inherited-from-19) ```ts RuntimeEventEmitter.setMaxListeners ``` *** ### updateAgent() [Section titled “updateAgent()”](#updateagent) ```ts updateAgent(newAgent): Promise>; ``` #### Parameters [Section titled “Parameters”](#parameters-23) | Parameter | Type | | ---------- | -------------------------------------------------------------------------------------------------- | | `newAgent` | [`RealtimeAgent`](/openai-agents-js/openai/agents/realtime/classes/realtimeagent/)<`TBaseContext`> | #### Returns [Section titled “Returns”](#returns-34) `Promise`<[`RealtimeAgent`](/openai-agents-js/openai/agents/realtime/classes/realtimeagent/)<`TBaseContext`>> *** ### updateHistory() [Section titled “updateHistory()”](#updatehistory) ```ts updateHistory(newHistory): void; ``` Update the history of the session. #### Parameters [Section titled “Parameters”](#parameters-24) | Parameter | Type | Description | | ------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------- | | `newHistory` | \| [`RealtimeItem`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimeitem/)\[] \| ((`history`) => [`RealtimeItem`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimeitem/)\[]) | The new history to set. | #### Returns [Section titled “Returns”](#returns-35) `void` *** ### addAbortListener() [Section titled “addAbortListener()”](#addabortlistener) ```ts static addAbortListener(signal, resource): Disposable; ``` Listens once to the `abort` event on the provided `signal`. Listening to the `abort` event on abort signals is unsafe and may lead to resource leaks since another third party with the signal can call `e.stopImmediatePropagation()`. Unfortunately Node.js cannot change this since it would violate the web standard. Additionally, the original API makes it easy to forget to remove listeners. This API allows safely using `AbortSignal`s in Node.js APIs by solving these two issues by listening to the event such that `stopImmediatePropagation` does not prevent the listener from running. Returns a disposable so that it may be unsubscribed from more easily. ```js import { addAbortListener } from 'node:events'; function example(signal) { let disposable; try { signal.addEventListener('abort', (e) => e.stopImmediatePropagation()); disposable = addAbortListener(signal, (e) => { // Do something when signal is aborted. }); } finally { disposable?.[Symbol.dispose](); } } ``` #### Parameters [Section titled “Parameters”](#parameters-25) | Parameter | Type | | ---------- | ------------------- | | `signal` | `AbortSignal` | | `resource` | (`event`) => `void` | #### Returns [Section titled “Returns”](#returns-36) `Disposable` Disposable that removes the `abort` listener. #### Since [Section titled “Since”](#since-19) v20.5.0 #### Inherited from [Section titled “Inherited from”](#inherited-from-20) ```ts RuntimeEventEmitter.addAbortListener ``` *** ### computeInitialSessionConfig() [Section titled “computeInitialSessionConfig()”](#computeinitialsessionconfig) ```ts static computeInitialSessionConfig( agent, options?, overrides?): Promise>; ``` Convenience helper to compute the initial session config without manually instantiating and connecting a session. This is primarily useful for integrations that must provide the session configuration to a third party (for example the SIP `calls.accept` endpoint) before the actual realtime session is attached. The helper instantiates a throwaway session so all agent-driven dynamic fields resolve in exactly the same way as the live session path. #### Type Parameters [Section titled “Type Parameters”](#type-parameters-13) | Type Parameter | Default type | | -------------- | ------------ | | `TBaseContext` | `unknown` | #### Parameters [Section titled “Parameters”](#parameters-26) | Parameter | Type | Description | | ------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------- | | `agent` | \| [`RealtimeAgent`](/openai-agents-js/openai/agents/realtime/classes/realtimeagent/)<`TBaseContext`> \| [`RealtimeAgent`](/openai-agents-js/openai/agents/realtime/classes/realtimeagent/)<[`RealtimeContextData`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimecontextdata/)<`TBaseContext`>> | The starting agent for the session. | | `options?` | `Partial`<[`RealtimeSessionOptions`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimesessionoptions/)<`TBaseContext`>> | Session options used to seed the config calculation. | | `overrides?` | `Partial`<[`RealtimeSessionConfig`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimesessionconfig/)> | Additional config overrides applied on top of the provided options. | #### Returns [Section titled “Returns”](#returns-37) `Promise`<`Partial`<[`RealtimeSessionConfig`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimesessionconfig/)>> *** ### getEventListeners() [Section titled “getEventListeners()”](#geteventlisteners) ```ts static getEventListeners(emitter, name): Function[]; ``` Returns a copy of the array of listeners for the event named `eventName`. For `EventEmitter`s this behaves exactly the same as calling `.listeners` on the emitter. For `EventTarget`s this is the only way to get the event listeners for the event target. This is useful for debugging and diagnostic purposes. ```js import { getEventListeners, EventEmitter } from 'node:events'; { const ee = new EventEmitter(); const listener = () => console.log('Events are fun'); ee.on('foo', listener); console.log(getEventListeners(ee, 'foo')); // [ [Function: listener] ] } { const et = new EventTarget(); const listener = () => console.log('Events are fun'); et.addEventListener('foo', listener); console.log(getEventListeners(et, 'foo')); // [ [Function: listener] ] } ``` #### Parameters [Section titled “Parameters”](#parameters-27) | Parameter | Type | | --------- | -------------------------------------------------- | | `emitter` | `EventEmitter`<`DefaultEventMap`> \| `EventTarget` | | `name` | `string` \| `symbol` | #### Returns [Section titled “Returns”](#returns-38) `Function`\[] #### Since [Section titled “Since”](#since-20) v15.2.0, v14.17.0 #### Inherited from [Section titled “Inherited from”](#inherited-from-21) ```ts RuntimeEventEmitter.getEventListeners ``` *** ### getMaxListeners() [Section titled “getMaxListeners()”](#getmaxlisteners-1) ```ts static getMaxListeners(emitter): number; ``` Returns the currently set max amount of listeners. For `EventEmitter`s this behaves exactly the same as calling `.getMaxListeners` on the emitter. For `EventTarget`s this is the only way to get the max event listeners for the event target. If the number of event handlers on a single EventTarget exceeds the max set, the EventTarget will print a warning. ```js import { getMaxListeners, setMaxListeners, EventEmitter } from 'node:events'; { const ee = new EventEmitter(); console.log(getMaxListeners(ee)); // 10 setMaxListeners(11, ee); console.log(getMaxListeners(ee)); // 11 } { const et = new EventTarget(); console.log(getMaxListeners(et)); // 10 setMaxListeners(11, et); console.log(getMaxListeners(et)); // 11 } ``` #### Parameters [Section titled “Parameters”](#parameters-28) | Parameter | Type | | --------- | -------------------------------------------------- | | `emitter` | `EventEmitter`<`DefaultEventMap`> \| `EventTarget` | #### Returns [Section titled “Returns”](#returns-39) `number` #### Since [Section titled “Since”](#since-21) v19.9.0 #### Inherited from [Section titled “Inherited from”](#inherited-from-22) ```ts RuntimeEventEmitter.getMaxListeners ``` *** ### ~~listenerCount()~~ [Section titled “listenerCount()”](#listenercount-1) ```ts static listenerCount(emitter, eventName): number; ``` A class method that returns the number of listeners for the given `eventName` registered on the given `emitter`. ```js import { EventEmitter, listenerCount } from 'node:events'; const myEmitter = new EventEmitter(); myEmitter.on('event', () => {}); myEmitter.on('event', () => {}); console.log(listenerCount(myEmitter, 'event')); // Prints: 2 ``` Deprecated Since v3.2.0 - Use `listenerCount` instead. #### Parameters [Section titled “Parameters”](#parameters-29) | Parameter | Type | Description | | ----------- | -------------------- | -------------------- | | `emitter` | `EventEmitter` | The emitter to query | | `eventName` | `string` \| `symbol` | The event name | #### Returns [Section titled “Returns”](#returns-40) `number` #### Since [Section titled “Since”](#since-22) v0.9.12 #### Inherited from [Section titled “Inherited from”](#inherited-from-23) ```ts RuntimeEventEmitter.listenerCount ``` *** ### on() [Section titled “on()”](#on-1) #### Call Signature [Section titled “Call Signature”](#call-signature) ```ts static on( emitter, eventName, options?): AsyncIterator; ``` ```js import { on, EventEmitter } from 'node:events'; import process from 'node:process'; const ee = new EventEmitter(); // Emit later on process.nextTick(() => { ee.emit('foo', 'bar'); ee.emit('foo', 42); }); for await (const event of on(ee, 'foo')) { // The execution of this inner block is synchronous and it // processes one event at a time (even with await). Do not use // if concurrent execution is required. console.log(event); // prints ['bar'] [42] } // Unreachable here ``` Returns an `AsyncIterator` that iterates `eventName` events. It will throw if the `EventEmitter` emits `'error'`. It removes all listeners when exiting the loop. The `value` returned by each iteration is an array composed of the emitted event arguments. An `AbortSignal` can be used to cancel waiting on events: ```js import { on, EventEmitter } from 'node:events'; import process from 'node:process'; const ac = new AbortController(); (async () => { const ee = new EventEmitter(); // Emit later on process.nextTick(() => { ee.emit('foo', 'bar'); ee.emit('foo', 42); }); for await (const event of on(ee, 'foo', { signal: ac.signal })) { // The execution of this inner block is synchronous and it // processes one event at a time (even with await). Do not use // if concurrent execution is required. console.log(event); // prints ['bar'] [42] } // Unreachable here })(); process.nextTick(() => ac.abort()); ``` Use the `close` option to specify an array of event names that will end the iteration: ```js import { on, EventEmitter } from 'node:events'; import process from 'node:process'; const ee = new EventEmitter(); // Emit later on process.nextTick(() => { ee.emit('foo', 'bar'); ee.emit('foo', 42); ee.emit('close'); }); for await (const event of on(ee, 'foo', { close: ['close'] })) { console.log(event); // prints ['bar'] [42] } // the loop will exit after 'close' is emitted console.log('done'); // prints 'done' ``` ##### Parameters [Section titled “Parameters”](#parameters-30) | Parameter | Type | | ----------- | ----------------------------------- | | `emitter` | `EventEmitter` | | `eventName` | `string` \| `symbol` | | `options?` | `StaticEventEmitterIteratorOptions` | ##### Returns [Section titled “Returns”](#returns-41) `AsyncIterator`<`any`\[]> An `AsyncIterator` that iterates `eventName` events emitted by the `emitter` ##### Since [Section titled “Since”](#since-23) v13.6.0, v12.16.0 ##### Inherited from [Section titled “Inherited from”](#inherited-from-24) ```ts RuntimeEventEmitter.on ``` #### Call Signature [Section titled “Call Signature”](#call-signature-1) ```ts static on( emitter, eventName, options?): AsyncIterator; ``` ```js import { on, EventEmitter } from 'node:events'; import process from 'node:process'; const ee = new EventEmitter(); // Emit later on process.nextTick(() => { ee.emit('foo', 'bar'); ee.emit('foo', 42); }); for await (const event of on(ee, 'foo')) { // The execution of this inner block is synchronous and it // processes one event at a time (even with await). Do not use // if concurrent execution is required. console.log(event); // prints ['bar'] [42] } // Unreachable here ``` Returns an `AsyncIterator` that iterates `eventName` events. It will throw if the `EventEmitter` emits `'error'`. It removes all listeners when exiting the loop. The `value` returned by each iteration is an array composed of the emitted event arguments. An `AbortSignal` can be used to cancel waiting on events: ```js import { on, EventEmitter } from 'node:events'; import process from 'node:process'; const ac = new AbortController(); (async () => { const ee = new EventEmitter(); // Emit later on process.nextTick(() => { ee.emit('foo', 'bar'); ee.emit('foo', 42); }); for await (const event of on(ee, 'foo', { signal: ac.signal })) { // The execution of this inner block is synchronous and it // processes one event at a time (even with await). Do not use // if concurrent execution is required. console.log(event); // prints ['bar'] [42] } // Unreachable here })(); process.nextTick(() => ac.abort()); ``` Use the `close` option to specify an array of event names that will end the iteration: ```js import { on, EventEmitter } from 'node:events'; import process from 'node:process'; const ee = new EventEmitter(); // Emit later on process.nextTick(() => { ee.emit('foo', 'bar'); ee.emit('foo', 42); ee.emit('close'); }); for await (const event of on(ee, 'foo', { close: ['close'] })) { console.log(event); // prints ['bar'] [42] } // the loop will exit after 'close' is emitted console.log('done'); // prints 'done' ``` ##### Parameters [Section titled “Parameters”](#parameters-31) | Parameter | Type | | ----------- | ----------------------------------- | | `emitter` | `EventTarget` | | `eventName` | `string` | | `options?` | `StaticEventEmitterIteratorOptions` | ##### Returns [Section titled “Returns”](#returns-42) `AsyncIterator`<`any`\[]> An `AsyncIterator` that iterates `eventName` events emitted by the `emitter` ##### Since [Section titled “Since”](#since-24) v13.6.0, v12.16.0 ##### Inherited from [Section titled “Inherited from”](#inherited-from-25) ```ts RuntimeEventEmitter.on ``` *** ### once() [Section titled “once()”](#once-1) #### Call Signature [Section titled “Call Signature”](#call-signature-2) ```ts static once( emitter, eventName, options?): Promise; ``` Creates a `Promise` that is fulfilled when the `EventEmitter` emits the given event or that is rejected if the `EventEmitter` emits `'error'` while waiting. The `Promise` will resolve with an array of all the arguments emitted to the given event. This method is intentionally generic and works with the web platform [EventTarget](https://dom.spec.whatwg.org/#interface-eventtarget) interface, which has no special`'error'` event semantics and does not listen to the `'error'` event. ```js import { once, EventEmitter } from 'node:events'; import process from 'node:process'; const ee = new EventEmitter(); process.nextTick(() => { ee.emit('myevent', 42); }); const [value] = await once(ee, 'myevent'); console.log(value); const err = new Error('kaboom'); process.nextTick(() => { ee.emit('error', err); }); try { await once(ee, 'myevent'); } catch (err) { console.error('error happened', err); } ``` The special handling of the `'error'` event is only used when `events.once()` is used to wait for another event. If `events.once()` is used to wait for the ‘`error'` event itself, then it is treated as any other kind of event without special handling: ```js import { EventEmitter, once } from 'node:events'; const ee = new EventEmitter(); once(ee, 'error') .then(([err]) => console.log('ok', err.message)) .catch((err) => console.error('error', err.message)); ee.emit('error', new Error('boom')); // Prints: ok boom ``` An `AbortSignal` can be used to cancel waiting for the event: ```js import { EventEmitter, once } from 'node:events'; const ee = new EventEmitter(); const ac = new AbortController(); async function foo(emitter, event, signal) { try { await once(emitter, event, { signal }); console.log('event emitted!'); } catch (error) { if (error.name === 'AbortError') { console.error('Waiting for the event was canceled!'); } else { console.error('There was an error', error.message); } } } foo(ee, 'foo', ac.signal); ac.abort(); // Abort waiting for the event ee.emit('foo'); // Prints: Waiting for the event was canceled! ``` ##### Parameters [Section titled “Parameters”](#parameters-32) | Parameter | Type | | ----------- | --------------------------- | | `emitter` | `EventEmitter` | | `eventName` | `string` \| `symbol` | | `options?` | `StaticEventEmitterOptions` | ##### Returns [Section titled “Returns”](#returns-43) `Promise`<`any`\[]> ##### Since [Section titled “Since”](#since-25) v11.13.0, v10.16.0 ##### Inherited from [Section titled “Inherited from”](#inherited-from-26) ```ts RuntimeEventEmitter.once ``` #### Call Signature [Section titled “Call Signature”](#call-signature-3) ```ts static once( emitter, eventName, options?): Promise; ``` Creates a `Promise` that is fulfilled when the `EventEmitter` emits the given event or that is rejected if the `EventEmitter` emits `'error'` while waiting. The `Promise` will resolve with an array of all the arguments emitted to the given event. This method is intentionally generic and works with the web platform [EventTarget](https://dom.spec.whatwg.org/#interface-eventtarget) interface, which has no special`'error'` event semantics and does not listen to the `'error'` event. ```js import { once, EventEmitter } from 'node:events'; import process from 'node:process'; const ee = new EventEmitter(); process.nextTick(() => { ee.emit('myevent', 42); }); const [value] = await once(ee, 'myevent'); console.log(value); const err = new Error('kaboom'); process.nextTick(() => { ee.emit('error', err); }); try { await once(ee, 'myevent'); } catch (err) { console.error('error happened', err); } ``` The special handling of the `'error'` event is only used when `events.once()` is used to wait for another event. If `events.once()` is used to wait for the ‘`error'` event itself, then it is treated as any other kind of event without special handling: ```js import { EventEmitter, once } from 'node:events'; const ee = new EventEmitter(); once(ee, 'error') .then(([err]) => console.log('ok', err.message)) .catch((err) => console.error('error', err.message)); ee.emit('error', new Error('boom')); // Prints: ok boom ``` An `AbortSignal` can be used to cancel waiting for the event: ```js import { EventEmitter, once } from 'node:events'; const ee = new EventEmitter(); const ac = new AbortController(); async function foo(emitter, event, signal) { try { await once(emitter, event, { signal }); console.log('event emitted!'); } catch (error) { if (error.name === 'AbortError') { console.error('Waiting for the event was canceled!'); } else { console.error('There was an error', error.message); } } } foo(ee, 'foo', ac.signal); ac.abort(); // Abort waiting for the event ee.emit('foo'); // Prints: Waiting for the event was canceled! ``` ##### Parameters [Section titled “Parameters”](#parameters-33) | Parameter | Type | | ----------- | --------------------------- | | `emitter` | `EventTarget` | | `eventName` | `string` | | `options?` | `StaticEventEmitterOptions` | ##### Returns [Section titled “Returns”](#returns-44) `Promise`<`any`\[]> ##### Since [Section titled “Since”](#since-26) v11.13.0, v10.16.0 ##### Inherited from [Section titled “Inherited from”](#inherited-from-27) ```ts RuntimeEventEmitter.once ``` *** ### setMaxListeners() [Section titled “setMaxListeners()”](#setmaxlisteners-1) ```ts static setMaxListeners(n?, ...eventTargets): void; ``` ```js import { setMaxListeners, EventEmitter } from 'node:events'; const target = new EventTarget(); const emitter = new EventEmitter(); setMaxListeners(5, target, emitter); ``` #### Parameters [Section titled “Parameters”](#parameters-34) | Parameter | Type | Description | | ---------------- | ------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `n?` | `number` | A non-negative number. The maximum number of listeners per `EventTarget` event. | | …`eventTargets?` | (`EventEmitter`<`DefaultEventMap`> \| `EventTarget`)\[] | Zero or more {EventTarget} or {EventEmitter} instances. If none are specified, `n` is set as the default max for all newly created {EventTarget} and {EventEmitter} objects. | #### Returns [Section titled “Returns”](#returns-45) `void` #### Since [Section titled “Since”](#since-27) v15.4.0 #### Inherited from [Section titled “Inherited from”](#inherited-from-28) ```ts RuntimeEventEmitter.setMaxListeners ``` # UserError Error thrown when the error is caused by the library user’s misconfiguration. ## Extends [Section titled “Extends”](#extends) * `AgentsError` ## Constructors [Section titled “Constructors”](#constructors) ### Constructor [Section titled “Constructor”](#constructor) ```ts new UserError(message, state?): UserError; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ---------------------------------------- | | `message` | `string` | | `state?` | `RunState`<`any`, `Agent`<`any`, `any`>> | #### Returns [Section titled “Returns”](#returns) `UserError` #### Inherited from [Section titled “Inherited from”](#inherited-from) ```ts AgentsError.constructor ``` ## Properties [Section titled “Properties”](#properties) ### message [Section titled “message”](#message) ```ts message: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-1) ```ts AgentsError.message ``` *** ### name [Section titled “name”](#name) ```ts name: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-2) ```ts AgentsError.name ``` *** ### stack? [Section titled “stack?”](#stack) ```ts optional stack?: string; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-3) ```ts AgentsError.stack ``` *** ### state? [Section titled “state?”](#state) ```ts optional state?: RunState>; ``` #### Inherited from [Section titled “Inherited from”](#inherited-from-4) ```ts AgentsError.state ``` *** ### stackTraceLimit [Section titled “stackTraceLimit”](#stacktracelimit) ```ts static stackTraceLimit: number; ``` The `Error.stackTraceLimit` property specifies the number of stack frames collected by a stack trace (whether generated by `new Error().stack` or `Error.captureStackTrace(obj)`). The default value is `10` but may be set to any valid JavaScript number. Changes will affect any stack trace captured *after* the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames. #### Inherited from [Section titled “Inherited from”](#inherited-from-5) ```ts AgentsError.stackTraceLimit ``` ## Methods [Section titled “Methods”](#methods) ### captureStackTrace() [Section titled “captureStackTrace()”](#capturestacktrace) ```ts static captureStackTrace(targetObject, constructorOpt?): void; ``` Creates a `.stack` property on `targetObject`, which when accessed returns a string representing the location in the code at which `Error.captureStackTrace()` was called. ```js const myObject = {}; Error.captureStackTrace(myObject); myObject.stack; // Similar to `new Error().stack` ``` The first line of the trace will be prefixed with `${myObject.name}: ${myObject.message}`. The optional `constructorOpt` argument accepts a function. If given, all frames above `constructorOpt`, including `constructorOpt`, will be omitted from the generated stack trace. The `constructorOpt` argument is useful for hiding implementation details of error generation from the user. For instance: ```js function a() { b(); } function b() { c(); } function c() { // Create an error without stack trace to avoid calculating the stack trace twice. const { stackTraceLimit } = Error; Error.stackTraceLimit = 0; const error = new Error(); Error.stackTraceLimit = stackTraceLimit; // Capture the stack trace above function b Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace throw error; } a(); ``` #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | ----------------- | ---------- | | `targetObject` | `object` | | `constructorOpt?` | `Function` | #### Returns [Section titled “Returns”](#returns-1) `void` #### Inherited from [Section titled “Inherited from”](#inherited-from-6) ```ts AgentsError.captureStackTrace ``` *** ### prepareStackTrace() [Section titled “prepareStackTrace()”](#preparestacktrace) ```ts static prepareStackTrace(err, stackTraces): any; ``` #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | ------------- | ------------- | | `err` | `Error` | | `stackTraces` | `CallSite`\[] | #### Returns [Section titled “Returns”](#returns-2) `any` #### See [Section titled “See”](#see) #### Inherited from [Section titled “Inherited from”](#inherited-from-7) ```ts AgentsError.prepareStackTrace ``` # backgroundResult ```ts function backgroundResult(content): BackgroundResult; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | -------------- | | `T` | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ---- | | `content` | `T` | ## Returns [Section titled “Returns”](#returns) `BackgroundResult`<`T`> # isBackgroundResult ```ts function isBackgroundResult(result): result is BackgroundResult; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | -------------- | | `T` | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | --------- | | `result` | `unknown` | ## Returns [Section titled “Returns”](#returns) `result is BackgroundResult` # tool ```ts function tool(options): FunctionTool; ``` Exposes a function to the agent as a tool to be called ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | --------------------------------------------- | ------------ | | `TParameters` *extends* `ToolInputParameters` | `undefined` | | `Context` | `unknown` | | `Result` | `string` | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | --------- | --------------------------------------- | ------------------------ | | `options` | `ToolOptions`<`TParameters`, `Context`> | The options for the tool | ## Returns [Section titled “Returns”](#returns) [`FunctionTool`](/openai-agents-js/openai/agents/realtime/type-aliases/functiontool/)<`Context`, `TParameters`, `Result`> A new tool # RealtimeOutputGuardrail ## Extends [Section titled “Extends”](#extends) * `OutputGuardrail` ## Properties [Section titled “Properties”](#properties) ### execute [Section titled “execute”](#execute) ```ts execute: OutputGuardrailFunction<"text", unknown>; ``` The function that performs the guardrail check. #### Inherited from [Section titled “Inherited from”](#inherited-from) ```ts OutputGuardrail.execute ``` *** ### name [Section titled “name”](#name) ```ts name: string; ``` The name of the guardrail. #### Inherited from [Section titled “Inherited from”](#inherited-from-1) ```ts OutputGuardrail.name ``` *** ### policyHint? [Section titled “policyHint?”](#policyhint) ```ts optional policyHint?: string; ``` This will be passed to the model to inform it about why the guardrail was triggered and to correct the behavior. If it’s not specified the name of your guardrail will be passed instead. # RealtimeTransportLayer The transport layer is the layer that handles the connection to the model and the communication with the model. ## Extends [Section titled “Extends”](#extends) * `EventEmitter`<[`RealtimeTransportEventTypes`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimetransporteventtypes/)> ## Properties [Section titled “Properties”](#properties) ### muted [Section titled “muted”](#muted) ```ts readonly muted: boolean | null; ``` Whether the input audio track is currently muted null if the muting is not handled by the transport layer *** ### status [Section titled “status”](#status) ```ts status: "connecting" | "connected" | "disconnected" | "disconnecting"; ``` ## Methods [Section titled “Methods”](#methods) ### addImage() [Section titled “addImage()”](#addimage) ```ts addImage(image, options?): void; ``` Sends an image to the model #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | -------------------------- | ---------------------------------- | -------------------------------------------- | | `image` | `string` | The image to send | | `options?` | { `triggerResponse?`: `boolean`; } | Additional options | | `options.triggerResponse?` | `boolean` | Whether to trigger a response from the model | #### Returns [Section titled “Returns”](#returns) `void` *** ### close() [Section titled “close()”](#close) ```ts close(): void; ``` Closes the connection to the model #### Returns [Section titled “Returns”](#returns-1) `void` *** ### connect() [Section titled “connect()”](#connect) ```ts connect(options): Promise; ``` Establishes the connection to the model and keeps the connection alive #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | Description | | --------- | ------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------ | | `options` | [`RealtimeTransportLayerConnectOptions`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimetransportlayerconnectoptions/) | The options for the connection | #### Returns [Section titled “Returns”](#returns-2) `Promise`<`void`> *** ### emit() [Section titled “emit()”](#emit) ```ts emit(type, ...args): boolean; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | --------------------------------------------------------------------------------------------------------------------------------------- | | `K` *extends* keyof [`RealtimeTransportEventTypes`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimetransporteventtypes/) | #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | --------- | ------------------------------------------------------------------------------------------------------------------------- | | `type` | `K` | | …`args` | [`RealtimeTransportEventTypes`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimetransporteventtypes/)\[`K`] | #### Returns [Section titled “Returns”](#returns-3) `boolean` #### Inherited from [Section titled “Inherited from”](#inherited-from) ```ts EventEmitter.emit ``` *** ### interrupt() [Section titled “interrupt()”](#interrupt) ```ts interrupt(): void; ``` Interrupts the current turn. Used for example when a guardrail is triggered #### Returns [Section titled “Returns”](#returns-4) `void` *** ### mute() [Section titled “mute()”](#mute) ```ts mute(muted): void; ``` Mutes the input audio track #### Parameters [Section titled “Parameters”](#parameters-3) | Parameter | Type | Description | | --------- | --------- | ------------------------------------- | | `muted` | `boolean` | Whether to mute the input audio track | #### Returns [Section titled “Returns”](#returns-5) `void` *** ### off() [Section titled “off()”](#off) ```ts off(type, listener): EventEmitter; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-1) | Type Parameter | | --------------------------------------------------------------------------------------------------------------------------------------- | | `K` *extends* keyof [`RealtimeTransportEventTypes`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimetransporteventtypes/) | #### Parameters [Section titled “Parameters”](#parameters-4) | Parameter | Type | | ---------- | ------------------- | | `type` | `K` | | `listener` | (…`args`) => `void` | #### Returns [Section titled “Returns”](#returns-6) `EventEmitter`<[`RealtimeTransportEventTypes`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimetransporteventtypes/)> #### Inherited from [Section titled “Inherited from”](#inherited-from-1) ```ts EventEmitter.off ``` *** ### on() [Section titled “on()”](#on) ```ts on(type, listener): EventEmitter; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-2) | Type Parameter | | --------------------------------------------------------------------------------------------------------------------------------------- | | `K` *extends* keyof [`RealtimeTransportEventTypes`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimetransporteventtypes/) | #### Parameters [Section titled “Parameters”](#parameters-5) | Parameter | Type | | ---------- | ------------------- | | `type` | `K` | | `listener` | (…`args`) => `void` | #### Returns [Section titled “Returns”](#returns-7) `EventEmitter`<[`RealtimeTransportEventTypes`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimetransporteventtypes/)> #### Inherited from [Section titled “Inherited from”](#inherited-from-2) ```ts EventEmitter.on ``` *** ### once() [Section titled “once()”](#once) ```ts once(type, listener): EventEmitter; ``` #### Type Parameters [Section titled “Type Parameters”](#type-parameters-3) | Type Parameter | | --------------------------------------------------------------------------------------------------------------------------------------- | | `K` *extends* keyof [`RealtimeTransportEventTypes`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimetransporteventtypes/) | #### Parameters [Section titled “Parameters”](#parameters-6) | Parameter | Type | | ---------- | ------------------- | | `type` | `K` | | `listener` | (…`args`) => `void` | #### Returns [Section titled “Returns”](#returns-8) `EventEmitter`<[`RealtimeTransportEventTypes`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimetransporteventtypes/)> #### Inherited from [Section titled “Inherited from”](#inherited-from-3) ```ts EventEmitter.once ``` *** ### requestResponse()? [Section titled “requestResponse()?”](#requestresponse) ```ts optional requestResponse(response?): void; ``` Requests a new response for the current conversation turn. Implementations may defer the underlying `response.create` until the server has fully finished the prior response. #### Parameters [Section titled “Parameters”](#parameters-7) | Parameter | Type | Description | | ----------- | ------------------------- | ------------------------------------------- | | `response?` | `Record`<`string`, `any`> | Optional one-off response override payload. | #### Returns [Section titled “Returns”](#returns-9) `void` *** ### resetHistory() [Section titled “resetHistory()”](#resethistory) ```ts resetHistory(oldHistory, newHistory): void; ``` Resets the conversation history / context to a specific state #### Parameters [Section titled “Parameters”](#parameters-8) | Parameter | Type | Description | | ------------ | ---------------------------------------------------------------------------------------- | ------------------------------------------------------ | | `oldHistory` | [`RealtimeItem`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimeitem/)\[] | The history that is currently stored on the session. | | `newHistory` | [`RealtimeItem`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimeitem/)\[] | The history you want the session to use going forward. | #### Returns [Section titled “Returns”](#returns-10) `void` *** ### sendAudio() [Section titled “sendAudio()”](#sendaudio) ```ts sendAudio(audio, options): void; ``` Sends a raw audio buffer to the model #### Parameters [Section titled “Parameters”](#parameters-9) | Parameter | Type | Description | | ----------------- | ------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- | | `audio` | `ArrayBuffer` | The audio buffer to send | | `options` | { `commit?`: `boolean`; } | Additional options | | `options.commit?` | `boolean` | Whether to commit the audio buffer to the model. If the model does not do turn detection, this can be used to indicate the turn is completed. | #### Returns [Section titled “Returns”](#returns-11) `void` *** ### sendEvent() [Section titled “sendEvent()”](#sendevent) ```ts sendEvent(event): void; ``` Sends a raw event to the model #### Parameters [Section titled “Parameters”](#parameters-10) | Parameter | Type | Description | | --------- | ------------------------------------------------------------------------------------------------------- | ----------------- | | `event` | [`RealtimeClientMessage`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimeclientmessage/) | The event to send | #### Returns [Section titled “Returns”](#returns-12) `void` *** ### sendFunctionCallOutput() [Section titled “sendFunctionCallOutput()”](#sendfunctioncalloutput) ```ts sendFunctionCallOutput( toolCall, output, startResponse): void; ``` Sends a function call output to the model #### Parameters [Section titled “Parameters”](#parameters-11) | Parameter | Type | Description | | --------------- | --------------------------------------------------------------------------------------------------------- | --------------------------- | | `toolCall` | [`TransportToolCallEvent`](/openai-agents-js/openai/agents/realtime/type-aliases/transporttoolcallevent/) | The tool call to send | | `output` | `string` | The output of the tool call | | `startResponse` | `boolean` | ‐ | #### Returns [Section titled “Returns”](#returns-13) `void` *** ### sendMcpResponse() [Section titled “sendMcpResponse()”](#sendmcpresponse) ```ts sendMcpResponse( approvalRequest, approved, reason?): void; ``` Sends a response for an MCP tool call #### Parameters [Section titled “Parameters”](#parameters-12) | Parameter | Type | Description | | ------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------- | | `approvalRequest` | { `approved?`: `boolean` \| `null`; `arguments`: `z.ZodRecord`<`z.ZodString`, `z.ZodAny`>; `itemId`: `string`; `name`: `string`; `serverLabel`: `string`; `type`: `"mcp_approval_request"`; } | The approval request to respond to | | `approvalRequest.approved?` | `boolean` \| `null` | ‐ | | `approvalRequest.arguments` | `z.ZodRecord`<`z.ZodString`, `z.ZodAny`> | ‐ | | `approvalRequest.itemId?` | `string` | ‐ | | `approvalRequest.name?` | `string` | ‐ | | `approvalRequest.serverLabel?` | `string` | ‐ | | `approvalRequest.type?` | `"mcp_approval_request"` | ‐ | | `approved?` | `boolean` | Whether the tool call was approved or rejected | | `reason?` | `string` | Optional rejection text for the provider/model. | #### Returns [Section titled “Returns”](#returns-14) `void` *** ### sendMessage() [Section titled “sendMessage()”](#sendmessage) ```ts sendMessage( message, otherEventData, options?): void; ``` Sends a text message to the model #### Parameters [Section titled “Parameters”](#parameters-13) | Parameter | Type | Description | | -------------------------- | ---------------------------------- | ---------------------------------------------------- | | `message` | `RealtimeUserInput` | The message to send | | `otherEventData` | `Record`<`string`, `any`> | Additional event data, will be merged into the event | | `options?` | { `triggerResponse?`: `boolean`; } | Additional options | | `options.triggerResponse?` | `boolean` | Whether to trigger a response from the model | #### Returns [Section titled “Returns”](#returns-15) `void` *** ### updateSessionConfig() [Section titled “updateSessionConfig()”](#updatesessionconfig) ```ts updateSessionConfig(config): void; ``` Sends an updated session configuration to the model. Used to update for example the model instructions during a handoff #### Parameters [Section titled “Parameters”](#parameters-14) | Parameter | Type | Description | | --------- | ------------------------------------------------------------------------------------------------------------------ | ---------------------- | | `config` | `Partial`<[`RealtimeSessionConfig`](/openai-agents-js/openai/agents/realtime/type-aliases/realtimesessionconfig/)> | The new session config | #### Returns [Section titled “Returns”](#returns-16) `void` # @openai/agents ## Classes [Section titled “Classes”](#classes) * [ModelBehaviorError](/openai-agents-js/openai/agents/realtime/classes/modelbehaviorerror/) * [OpenAIRealtimeBase](/openai-agents-js/openai/agents/realtime/classes/openairealtimebase/) * [OpenAIRealtimeSIP](/openai-agents-js/openai/agents/realtime/classes/openairealtimesip/) * [OpenAIRealtimeWebRTC](/openai-agents-js/openai/agents/realtime/classes/openairealtimewebrtc/) * [OpenAIRealtimeWebSocket](/openai-agents-js/openai/agents/realtime/classes/openairealtimewebsocket/) * [OutputGuardrailTripwireTriggered](/openai-agents-js/openai/agents/realtime/classes/outputguardrailtripwiretriggered/) * [RealtimeAgent](/openai-agents-js/openai/agents/realtime/classes/realtimeagent/) * [RealtimeSession](/openai-agents-js/openai/agents/realtime/classes/realtimesession/) * [UserError](/openai-agents-js/openai/agents/realtime/classes/usererror/) ## Interfaces [Section titled “Interfaces”](#interfaces) * [RealtimeOutputGuardrail](/openai-agents-js/openai/agents/realtime/interfaces/realtimeoutputguardrail/) * [RealtimeTransportLayer](/openai-agents-js/openai/agents/realtime/interfaces/realtimetransportlayer/) ## Type Aliases [Section titled “Type Aliases”](#type-aliases) * [ApiKey](/openai-agents-js/openai/agents/realtime/type-aliases/apikey/) * [FunctionTool](/openai-agents-js/openai/agents/realtime/type-aliases/functiontool/) * [OpenAIRealtimeBaseOptions](/openai-agents-js/openai/agents/realtime/type-aliases/openairealtimebaseoptions/) * [OpenAIRealtimeEventTypes](/openai-agents-js/openai/agents/realtime/type-aliases/openairealtimeeventtypes/) * [OpenAIRealtimeModels](/openai-agents-js/openai/agents/realtime/type-aliases/openairealtimemodels/) * [OpenAIRealtimeWebRTCOptions](/openai-agents-js/openai/agents/realtime/type-aliases/openairealtimewebrtcoptions/) * [OpenAIRealtimeWebSocketOptions](/openai-agents-js/openai/agents/realtime/type-aliases/openairealtimewebsocketoptions/) * [RealtimeAgentConfiguration](/openai-agents-js/openai/agents/realtime/type-aliases/realtimeagentconfiguration/) * [RealtimeAudioFormat](/openai-agents-js/openai/agents/realtime/type-aliases/realtimeaudioformat/) * [RealtimeBaseItem](/openai-agents-js/openai/agents/realtime/type-aliases/realtimebaseitem/) * [RealtimeClientMessage](/openai-agents-js/openai/agents/realtime/type-aliases/realtimeclientmessage/) * [RealtimeContextData](/openai-agents-js/openai/agents/realtime/type-aliases/realtimecontextdata/) * [RealtimeItem](/openai-agents-js/openai/agents/realtime/type-aliases/realtimeitem/) * [RealtimeMcpCallItem](/openai-agents-js/openai/agents/realtime/type-aliases/realtimemcpcallitem/) * [RealtimeMessageItem](/openai-agents-js/openai/agents/realtime/type-aliases/realtimemessageitem/) * [RealtimeReasoningConfig](/openai-agents-js/openai/agents/realtime/type-aliases/realtimereasoningconfig/) * [RealtimeReasoningEffort](/openai-agents-js/openai/agents/realtime/type-aliases/realtimereasoningeffort/) * [RealtimeSessionConfig](/openai-agents-js/openai/agents/realtime/type-aliases/realtimesessionconfig/) * [RealtimeSessionConnectOptions](/openai-agents-js/openai/agents/realtime/type-aliases/realtimesessionconnectoptions/) * [RealtimeSessionEventTypes](/openai-agents-js/openai/agents/realtime/type-aliases/realtimesessioneventtypes/) * [RealtimeSessionOptions](/openai-agents-js/openai/agents/realtime/type-aliases/realtimesessionoptions/) * [RealtimeSessionPayload](/openai-agents-js/openai/agents/realtime/type-aliases/realtimesessionpayload/) * [RealtimeToolCallItem](/openai-agents-js/openai/agents/realtime/type-aliases/realtimetoolcallitem/) * [RealtimeTransportEventTypes](/openai-agents-js/openai/agents/realtime/type-aliases/realtimetransporteventtypes/) * [RealtimeTransportLayerConnectOptions](/openai-agents-js/openai/agents/realtime/type-aliases/realtimetransportlayerconnectoptions/) * [TransportError](/openai-agents-js/openai/agents/realtime/type-aliases/transporterror/) * [TransportEvent](/openai-agents-js/openai/agents/realtime/type-aliases/transportevent/) * [TransportLayerAudio](/openai-agents-js/openai/agents/realtime/type-aliases/transportlayeraudio/) * [TransportLayerResponseCompleted](/openai-agents-js/openai/agents/realtime/type-aliases/transportlayerresponsecompleted/) * [TransportLayerResponseStarted](/openai-agents-js/openai/agents/realtime/type-aliases/transportlayerresponsestarted/) * [TransportLayerTranscriptDelta](/openai-agents-js/openai/agents/realtime/type-aliases/transportlayertranscriptdelta/) * [TransportToolCallEvent](/openai-agents-js/openai/agents/realtime/type-aliases/transporttoolcallevent/) * [WebRTCState](/openai-agents-js/openai/agents/realtime/type-aliases/webrtcstate/) * [WebSocketState](/openai-agents-js/openai/agents/realtime/type-aliases/websocketstate/) ## Variables [Section titled “Variables”](#variables) * [DEFAULT\_OPENAI\_REALTIME\_MODEL](/openai-agents-js/openai/agents/realtime/variables/default_openai_realtime_model/) * [DEFAULT\_OPENAI\_REALTIME\_SESSION\_CONFIG](/openai-agents-js/openai/agents/realtime/variables/default_openai_realtime_session_config/) * [utils](/openai-agents-js/openai/agents/realtime/variables/utils/) ## Functions [Section titled “Functions”](#functions) * [backgroundResult](/openai-agents-js/openai/agents/realtime/functions/backgroundresult/) * [isBackgroundResult](/openai-agents-js/openai/agents/realtime/functions/isbackgroundresult/) * [tool](/openai-agents-js/openai/agents/realtime/functions/tool/) # ApiKey ```ts type ApiKey = string | (() => string | Promise); ``` The type of the API key. Can be a string or a function that returns a string or a promise that resolves to a string. # FunctionTool ```ts type FunctionTool = object; ``` Exposes a function to the agent as a tool to be called ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | Description | | --------------------------------------------- | ---------------- | ----------------------- | | `Context` | `UnknownContext` | The context of the tool | | `TParameters` *extends* `ToolInputParameters` | `undefined` | ‐ | | `Result` | `unknown` | The result of the tool | ## Properties [Section titled “Properties”](#properties) ### deferLoading? [Section titled “deferLoading?”](#deferloading) ```ts optional deferLoading?: boolean; ``` Responses API only. Hides a top-level function tool definition until tool search loads it. *** ### description [Section titled “description”](#description) ```ts description: string; ``` The description of the tool that helps the model to understand when to use the tool *** ### inputGuardrails? [Section titled “inputGuardrails?”](#inputguardrails) ```ts optional inputGuardrails?: ToolInputGuardrailDefinition[]; ``` Guardrails that run before the tool executes. *** ### invoke [Section titled “invoke”](#invoke) ```ts invoke: (runContext, input, details?) => Promise; ``` The function to invoke when the tool is called. #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ------------ | ----------------------- | | `runContext` | `RunContext`<`Context`> | | `input` | `string` | | `details?` | `ToolCallDetails` | #### Returns [Section titled “Returns”](#returns) `Promise`<`string` | `Result`> *** ### isEnabled [Section titled “isEnabled”](#isenabled) ```ts isEnabled: ToolEnabledFunction; ``` Determines whether the tool should be made available to the model for the current run. *** ### name [Section titled “name”](#name) ```ts name: string; ``` The name of the tool. *** ### needsApproval [Section titled “needsApproval”](#needsapproval) ```ts needsApproval: ToolApprovalFunction; ``` Whether the tool needs human approval before it can be called. If this is true, the run will result in an `interruption` that the program has to resolve by approving or rejecting the tool call. *** ### outputGuardrails? [Section titled “outputGuardrails?”](#outputguardrails) ```ts optional outputGuardrails?: ToolOutputGuardrailDefinition[]; ``` Guardrails that run after the tool executes. *** ### parameters [Section titled “parameters”](#parameters-1) ```ts parameters: JsonObjectSchema; ``` A JSON schema describing the parameters of the tool. *** ### strict [Section titled “strict”](#strict) ```ts strict: boolean; ``` Whether the tool is strict. If true, the model must try to strictly follow the schema (might result in slower response times). *** ### timeoutBehavior? [Section titled “timeoutBehavior?”](#timeoutbehavior) ```ts optional timeoutBehavior?: FunctionToolTimeoutBehavior; ``` Defines how timeout errors are handled. * `error_as_result`: return a model-visible timeout message. * `raise_exception`: raise `ToolTimeoutError` and fail the run. *** ### timeoutErrorFunction? [Section titled “timeoutErrorFunction?”](#timeouterrorfunction) ```ts optional timeoutErrorFunction?: ToolTimeoutErrorFunction; ``` Optional formatter for timeout errors when timeoutBehavior is `error_as_result`. *** ### timeoutMs? [Section titled “timeoutMs?”](#timeoutms) ```ts optional timeoutMs?: number; ``` Optional timeout in milliseconds for each tool invocation. *** ### type [Section titled “type”](#type) ```ts type: "function"; ``` # OpenAIRealtimeBaseOptions ```ts type OpenAIRealtimeBaseOptions = object; ``` The options for the OpenAI Realtime transport layer. ## Properties [Section titled “Properties”](#properties) ### apiKey? [Section titled “apiKey?”](#apikey) ```ts optional apiKey?: ApiKey; ``` The API key to use for the connection. *** ### model? [Section titled “model?”](#model) ```ts optional model?: OpenAIRealtimeModels; ``` The model to used during the connection. # OpenAIRealtimeEventTypes ```ts type OpenAIRealtimeEventTypes = object & RealtimeTransportEventTypes; ``` The events that are emitted by the OpenAI Realtime transport layer. ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### connected [Section titled “connected”](#connected) ```ts connected: []; ``` Triggered when the connection is established. ### disconnected [Section titled “disconnected”](#disconnected) ```ts disconnected: []; ``` Triggered when the connection is closed. # OpenAIRealtimeModels ```ts type OpenAIRealtimeModels = | "gpt-realtime" | "gpt-realtime-1.5" | "gpt-realtime-2" | "gpt-realtime-2025-08-28" | "gpt-4o-realtime-preview" | "gpt-4o-realtime-preview-2024-10-01" | "gpt-4o-realtime-preview-2024-12-17" | "gpt-4o-realtime-preview-2025-06-03" | "gpt-4o-mini-realtime-preview" | "gpt-4o-mini-realtime-preview-2024-12-17" | "gpt-realtime-mini" | "gpt-realtime-mini-2025-10-06" | "gpt-realtime-mini-2025-12-15" | string & object; ``` The models that are supported by the OpenAI Realtime API. # OpenAIRealtimeWebRTCOptions ```ts type OpenAIRealtimeWebRTCOptions = object & OpenAIRealtimeBaseOptions; ``` The options for the OpenAI Realtime WebRTC transport layer. ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### audioElement? [Section titled “audioElement?”](#audioelement) ```ts optional audioElement?: HTMLAudioElement; ``` The audio element to use for audio playback. If not provided, a new audio element will be created. ### baseUrl? [Section titled “baseUrl?”](#baseurl) ```ts optional baseUrl?: string; ``` Override of the base URL for the Realtime API ### changePeerConnection? [Section titled “changePeerConnection?”](#changepeerconnection) ```ts optional changePeerConnection?: (peerConnection) => RTCPeerConnection | Promise; ``` Optional hook invoked with the freshly created peer connection. Returning a different connection will override the one created by the transport layer. This is called right before the offer is created and can be asynchronous. #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ---------------- | ------------------- | | `peerConnection` | `RTCPeerConnection` | #### Returns [Section titled “Returns”](#returns) `RTCPeerConnection` | `Promise`<`RTCPeerConnection`> ### mediaStream? [Section titled “mediaStream?”](#mediastream) ```ts optional mediaStream?: MediaStream; ``` The media stream to use for audio input. If not provided, the default microphone will be used. ### useInsecureApiKey? [Section titled “useInsecureApiKey?”](#useinsecureapikey) ```ts optional useInsecureApiKey?: boolean; ``` **Important**: Do not use this option unless you know what you are doing. Whether to use an insecure API key. This has to be set if you are trying to use a regular OpenAI API key instead of a client ephemeral key. #### See [Section titled “See”](#see) # OpenAIRealtimeWebSocketOptions ```ts type OpenAIRealtimeWebSocketOptions = object & OpenAIRealtimeBaseOptions; ``` The options for the OpenAI Realtime WebSocket transport layer. ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### createWebSocket? [Section titled “createWebSocket?”](#createwebsocket) ```ts optional createWebSocket?: (options) => Promise; ``` Builds a new WebSocket connection. #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | Description | | --------- | ------------------------ | ----------------------------------------- | | `options` | `CreateWebSocketOptions` | The options for the WebSocket connection. | #### Returns [Section titled “Returns”](#returns) `Promise`<`WebSocket`> The WebSocket connection. ### skipOpenEventListeners? [Section titled “skipOpenEventListeners?”](#skipopeneventlisteners) ```ts optional skipOpenEventListeners?: boolean; ``` When you pass your own createWebSocket function, which completes the connection state transition, you can set this to true to skip registering the `open` event listener for the same purpose. If this flag is set to true, the constructor will immediately call the internal operation to mark the internal connection state to `connected`. Otherwise, the constructor will register the `open` event listener and wait for it to be triggered. By default (meaning if this property is absent), this is set to false. ### url? [Section titled “url?”](#url) ```ts optional url?: string; ``` The URL to use for the WebSocket connection. ### useInsecureApiKey? [Section titled “useInsecureApiKey?”](#useinsecureapikey) ```ts optional useInsecureApiKey?: boolean; ``` **Important**: Do not use this option unless you know what you are doing. Whether to use an insecure API key. This has to be set if you are trying to use a regular OpenAI API key instead of a client ephemeral key. #### See [Section titled “See”](#see) # RealtimeAgentConfiguration ```ts type RealtimeAgentConfiguration = Partial, TextOutput>, | "model" | "handoffs" | "modelSettings" | "outputType" | "toolUseBehavior" | "resetToolChoice" | "outputGuardrails" | "inputGuardrails" | "model">> & object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### handoffs? [Section titled “handoffs?”](#handoffs) ```ts optional handoffs?: ( | RealtimeAgent | Handoff, TextOutput>)[]; ``` Any other `RealtimeAgent` instances the agent is able to hand off to. ### name [Section titled “name”](#name) ```ts name: string; ``` The name of your realtime agent. ### voice? [Section titled “voice?”](#voice) ```ts optional voice?: string; ``` The voice intended to be used by the agent. If another agent already spoke during the RealtimeSession, changing the voice during a handoff will fail. ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | ---------------- | | `TContext` | `UnknownContext` | # RealtimeAudioFormat ```ts type RealtimeAudioFormat = RealtimeAudioFormatLegacy | RealtimeAudioFormatDefinition; ``` # RealtimeBaseItem ```ts type RealtimeBaseItem = object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### itemId [Section titled “itemId”](#itemid) ```ts itemId: string; ``` # RealtimeClientMessage ```ts type RealtimeClientMessage = object; ``` ## Indexable [Section titled “Indexable”](#indexable) ```ts [key: string]: any ``` ## Properties [Section titled “Properties”](#properties) ### type [Section titled “type”](#type) ```ts type: string; ``` # RealtimeContextData ```ts type RealtimeContextData = TContext & object; ``` The context data for a realtime session. This is the context data that is passed to the agent. The RealtimeSession will automatically add the current snapshot of the history to the context. ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### history [Section titled “history”](#history) ```ts history: RealtimeItem[]; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | ------------ | | `TContext` | `unknown` | # RealtimeItem ```ts type RealtimeItem = | RealtimeMessageItem | RealtimeToolCallItem | RealtimeMcpCallItem | RealtimeMcpCallApprovalRequestItem; ``` # RealtimeMcpCallItem ```ts type RealtimeMcpCallItem = object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### arguments [Section titled “arguments”](#arguments) ```ts arguments: string; ``` ### itemId [Section titled “itemId”](#itemid) ```ts itemId: string; ``` ### name [Section titled “name”](#name) ```ts name: string; ``` ### output [Section titled “output”](#output) ```ts output: string | null; ``` ### previousItemId? [Section titled “previousItemId?”](#previousitemid) ```ts optional previousItemId?: string | null; ``` ### status [Section titled “status”](#status) ```ts status: "in_progress" | "completed" | "incomplete"; ``` ### type [Section titled “type”](#type) ```ts type: "mcp_call" | "mcp_tool_call"; ``` # RealtimeMessageItem ```ts type RealtimeMessageItem = | { content: object[]; itemId: string; previousItemId?: string | null; role: "system"; type: "message"; } | { content: ( | { text: string; type: "input_text"; } | { audio?: string | null; transcript: string | null; type: "input_audio"; })[]; itemId: string; previousItemId?: string | null; role: "user"; status: "in_progress" | "completed"; type: "message"; } | { content: ( | { text: string; type: "output_text"; } | { audio?: string | null; transcript?: string | null; type: "output_audio"; })[]; itemId: string; previousItemId?: string | null; role: "assistant"; status: "in_progress" | "completed" | "incomplete"; type: "message"; }; ``` # RealtimeReasoningConfig ```ts type RealtimeReasoningConfig = object; ``` ## Properties [Section titled “Properties”](#properties) ### effort? [Section titled “effort?”](#effort) ```ts optional effort?: RealtimeReasoningEffort; ``` # RealtimeReasoningEffort ```ts type RealtimeReasoningEffort = "minimal" | "low" | "medium" | "high" | "xhigh"; ``` # RealtimeSessionConfig ```ts type RealtimeSessionConfig = RealtimeSessionConfigDefinition | RealtimeSessionConfigDeprecated; ``` # RealtimeSessionConnectOptions ```ts type RealtimeSessionConnectOptions = object; ``` ## Properties [Section titled “Properties”](#properties) ### apiKey [Section titled “apiKey”](#apikey) ```ts apiKey: string | (() => string | Promise); ``` The API key to use for the connection. Pass a function to lazily load the API key. Overrides default client options. *** ### callId? [Section titled “callId?”](#callid) ```ts optional callId?: string; ``` The call ID to attach to when connecting to a SIP-initiated session. *** ### model? [Section titled “model?”](#model) ```ts optional model?: | OpenAIRealtimeModels | string & object; ``` The model to use for the connection. *** ### url? [Section titled “url?”](#url) ```ts optional url?: string; ``` The URL to use for the connection. # RealtimeSessionEventTypes ```ts type RealtimeSessionEventTypes = object; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | ------------ | | `TContext` | `unknown` | ## Properties [Section titled “Properties”](#properties) ### agent\_end [Section titled “agent\_end”](#agent_end) ```ts agent_end: [RunContext>, AgentWithOrWithoutHistory, string]; ``` Triggered when an agent ends its work on a response. *** ### agent\_handoff [Section titled “agent\_handoff”](#agent_handoff) ```ts agent_handoff: [RunContext>, AgentWithOrWithoutHistory, AgentWithOrWithoutHistory]; ``` Triggered when an agent hands off to another agent. *** ### agent\_start [Section titled “agent\_start”](#agent_start) ```ts agent_start: [RunContext>, AgentWithOrWithoutHistory, AgentInputItem[]]; ``` Triggered when an agent starts its work on a response. *** ### agent\_tool\_end [Section titled “agent\_tool\_end”](#agent_tool_end) ```ts agent_tool_end: [RunContext>, AgentWithOrWithoutHistory, FunctionTool>, string, object]; ``` Triggered when an agent ends a tool call. *** ### agent\_tool\_start [Section titled “agent\_tool\_start”](#agent_tool_start) ```ts agent_tool_start: [RunContext>, AgentWithOrWithoutHistory, FunctionTool>, object]; ``` Triggered when an agent starts a tool call. *** ### audio [Section titled “audio”](#audio) ```ts audio: [TransportLayerAudio]; ``` Triggered when there is new audio data available for playing to the user. *** ### audio\_interrupted [Section titled “audio\_interrupted”](#audio_interrupted) ```ts audio_interrupted: [RunContext>, AgentWithOrWithoutHistory]; ``` Triggered when the agent is interrupted. Can be listened to by the user to stop audio playback or give visual indicators to the user. *** ### audio\_start [Section titled “audio\_start”](#audio_start) ```ts audio_start: [RunContext>, AgentWithOrWithoutHistory]; ``` Triggered when the agent starts generating audio. *** ### audio\_stopped [Section titled “audio\_stopped”](#audio_stopped) ```ts audio_stopped: [RunContext>, AgentWithOrWithoutHistory]; ``` Triggered when the agent stops generating audio. *** ### error [Section titled “error”](#error) ```ts error: [RealtimeSessionError]; ``` Triggered when an error occurs. *** ### guardrail\_tripped [Section titled “guardrail\_tripped”](#guardrail_tripped) ```ts guardrail_tripped: [RunContext>, AgentWithOrWithoutHistory, OutputGuardrailTripwireTriggered, object]; ``` Triggered when an output guardrail is tripped. *** ### history\_added [Section titled “history\_added”](#history_added) ```ts history_added: [RealtimeItem]; ``` Triggered when a new item is added to the history. At this point the transcript/response might still be in progress. *** ### history\_updated [Section titled “history\_updated”](#history_updated) ```ts history_updated: [RealtimeItem[]]; ``` Triggered when the history got updated. Contains the full history of the conversation. *** ### mcp\_tool\_call\_completed [Section titled “mcp\_tool\_call\_completed”](#mcp_tool_call_completed) ```ts mcp_tool_call_completed: [RunContext>, AgentWithOrWithoutHistory, RealtimeMcpCallItem]; ``` Triggered when an MCP tool call is completed. *** ### mcp\_tools\_changed [Section titled “mcp\_tools\_changed”](#mcp_tools_changed) ```ts mcp_tools_changed: [RealtimeMcpToolInfo[]]; ``` Triggered when the set of currently available MCP tools changes (e.g. after a list-tools result arrives, or when the active agent changes). Carries the list of available tools filtered by the active agent’s server\_labels. *** ### tool\_approval\_requested [Section titled “tool\_approval\_requested”](#tool_approval_requested) ```ts tool_approval_requested: [RunContext>, AgentWithOrWithoutHistory, RealtimeToolApprovalRequest | RealtimeMcpApprovalRequest]; ``` Triggered when a tool approval is requested. *** ### transport\_event [Section titled “transport\_event”](#transport_event) ```ts transport_event: [TransportEvent]; ``` Emits all the raw events from the transport layer. # RealtimeSessionOptions ```ts type RealtimeSessionOptions = object; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | ------------ | | `TContext` | `unknown` | ## Properties [Section titled “Properties”](#properties) ### apiKey [Section titled “apiKey”](#apikey) ```ts apiKey: ApiKey; ``` The API key to use for the connection. Pass a function to lazily load the API key *** ### automaticallyTriggerResponseForMcpToolCalls? [Section titled “automaticallyTriggerResponseForMcpToolCalls?”](#automaticallytriggerresponseformcptoolcalls) ```ts optional automaticallyTriggerResponseForMcpToolCalls?: boolean; ``` Whether to automatically trigger a response for MCP tool calls. *** ### config? [Section titled “config?”](#config) ```ts optional config?: Partial; ``` Additional session config options. Overrides default client options. *** ### context? [Section titled “context?”](#context) ```ts optional context?: TContext; ``` Additional context to pass to the agent *** ### groupId? [Section titled “groupId?”](#groupid) ```ts optional groupId?: string; ``` A group identifier to use for tracing, to link multiple traces together. For example, if you want to connect your RealtimeSession traces with those of a backend text-based agent run. *** ### historyStoreAudio? [Section titled “historyStoreAudio?”](#historystoreaudio) ```ts optional historyStoreAudio?: boolean; ``` Whether the history copy should include a local copy of the audio data. By default it is not included in the history to save runtime memory on the client. If you wish to keep this data you can enable this option. *** ### model? [Section titled “model?”](#model) ```ts optional model?: | OpenAIRealtimeModels | string & object; ``` The model to use. *** ### outputGuardrails? [Section titled “outputGuardrails?”](#outputguardrails) ```ts optional outputGuardrails?: RealtimeOutputGuardrail[]; ``` Any output guardrails to apply to agent output in parallel *** ### outputGuardrailSettings? [Section titled “outputGuardrailSettings?”](#outputguardrailsettings) ```ts optional outputGuardrailSettings?: RealtimeOutputGuardrailSettings; ``` Configure the behavior of your guardrails *** ### toolErrorFormatter? [Section titled “toolErrorFormatter?”](#toolerrorformatter) ```ts optional toolErrorFormatter?: ToolErrorFormatter>; ``` Formats tool error messages that are returned to the model. Returning `undefined` falls back to the SDK default message. *** ### traceMetadata? [Section titled “traceMetadata?”](#tracemetadata) ```ts optional traceMetadata?: Record; ``` An optional dictionary of additional metadata to include with the trace. *** ### tracingDisabled? [Section titled “tracingDisabled?”](#tracingdisabled) ```ts optional tracingDisabled?: boolean; ``` Whether tracing is disabled for this session. If disabled, we will not trace the agent run. *** ### transport [Section titled “transport”](#transport) ```ts transport: | "webrtc" | "websocket" | RealtimeTransportLayer; ``` The transport layer to use. *** ### workflowName? [Section titled “workflowName?”](#workflowname) ```ts optional workflowName?: string; ``` The workflow name to use for tracing. # RealtimeSessionPayload ```ts type RealtimeSessionPayload = object & Record; ``` Shape of the payload that the Realtime API expects for session.create/update operations. This closely mirrors the REST `CallAcceptParams` type so that callers can feed the payload directly into the `openai.realtime.calls.accept` helper without casts. ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### type [Section titled “type”](#type) ```ts type: "realtime"; ``` # RealtimeToolCallItem ```ts type RealtimeToolCallItem = object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### arguments [Section titled “arguments”](#arguments) ```ts arguments: string; ``` ### itemId [Section titled “itemId”](#itemid) ```ts itemId: string; ``` ### name [Section titled “name”](#name) ```ts name: string; ``` ### output [Section titled “output”](#output) ```ts output: string | null; ``` ### previousItemId? [Section titled “previousItemId?”](#previousitemid) ```ts optional previousItemId?: string | null; ``` ### status [Section titled “status”](#status) ```ts status: "in_progress" | "completed" | "incomplete"; ``` ### type [Section titled “type”](#type) ```ts type: "function_call"; ``` # RealtimeTransportEventTypes ```ts type RealtimeTransportEventTypes = object; ``` ## Indexable [Section titled “Indexable”](#indexable) ```ts [key: string]: any[] ``` ## Properties [Section titled “Properties”](#properties) ### \* ```ts *: [TransportEvent]; ``` A raw event from the transport layer. Allows a user to tap directly into the events of the transport layer. *** ### audio [Section titled “audio”](#audio) ```ts audio: [TransportLayerAudio]; ``` Triggered when there is new audio data available. Might not be triggered if the transport layer handles the audio internally (WebRTC). *** ### audio\_done [Section titled “audio\_done”](#audio_done) ```ts audio_done: []; ``` Triggered when the audio generation is done. *** ### audio\_interrupted [Section titled “audio\_interrupted”](#audio_interrupted) ```ts audio_interrupted: []; ``` Triggered when the model detected that it was interrupted. This can be used by the client to stop audio playback. *** ### audio\_transcript\_delta [Section titled “audio\_transcript\_delta”](#audio_transcript_delta) ```ts audio_transcript_delta: [TransportLayerTranscriptDelta]; ``` Triggered when there is a new text delta of the transcript available. *** ### connection\_change [Section titled “connection\_change”](#connection_change) ```ts connection_change: [ConnectionStatus]; ``` Triggered whenever the connection status of the transport changes. Emits the new status after the change. *** ### error [Section titled “error”](#error) ```ts error: [TransportError]; ``` Triggered if the model / transport layer encountered an error *** ### function\_call [Section titled “function\_call”](#function_call) ```ts function_call: [TransportToolCallEvent]; ``` Triggered when the model is trying to call a function. *** ### item\_deleted [Section titled “item\_deleted”](#item_deleted) ```ts item_deleted: [RealtimeBaseItem]; ``` Triggered when an item is deleted. *** ### item\_update [Section titled “item\_update”](#item_update) ```ts item_update: [RealtimeItem]; ``` Triggered when the history is added or updated. *** ### mcp\_approval\_request [Section titled “mcp\_approval\_request”](#mcp_approval_request) ```ts mcp_approval_request: [RealtimeMcpCallApprovalRequestItem]; ``` Triggered when a remote MCP tool requires approval. *** ### mcp\_tool\_call\_completed [Section titled “mcp\_tool\_call\_completed”](#mcp_tool_call_completed) ```ts mcp_tool_call_completed: [RealtimeMcpCallItem]; ``` Triggered when an MCP tool call is completed. *** ### mcp\_tools\_listed [Section titled “mcp\_tools\_listed”](#mcp_tools_listed) ```ts mcp_tools_listed: [object]; ``` Triggered when a remote MCP server lists its tools (via mcp\_list\_tools). *** ### turn\_done [Section titled “turn\_done”](#turn_done) ```ts turn_done: [TransportLayerResponseCompleted]; ``` Triggered when the model is done generating a response for a turn. *** ### turn\_started [Section titled “turn\_started”](#turn_started) ```ts turn_started: [TransportLayerResponseStarted]; ``` Triggered when the model starts generating a response for a turn. *** ### usage\_update [Section titled “usage\_update”](#usage_update) ```ts usage_update: [Usage]; ``` Triggered when the usage update is available. # RealtimeTransportLayerConnectOptions ```ts type RealtimeTransportLayerConnectOptions = object; ``` The options for the connection to the model. ## Properties [Section titled “Properties”](#properties) ### apiKey [Section titled “apiKey”](#apikey) ```ts apiKey: ApiKey; ``` The API key to use for the connection. *** ### callId? [Section titled “callId?”](#callid) ```ts optional callId?: string; ``` The call ID to attach to instead of starting a new session. *** ### initialSessionConfig? [Section titled “initialSessionConfig?”](#initialsessionconfig) ```ts optional initialSessionConfig?: Partial; ``` The initial session config to use for the session. *** ### model? [Section titled “model?”](#model) ```ts optional model?: string; ``` The model to use for the connection. *** ### url? [Section titled “url?”](#url) ```ts optional url?: string; ``` The URL to use for the connection. # TransportError ```ts type TransportError = object; ``` Represents an error that occurred on the transport layer. ## Properties [Section titled “Properties”](#properties) ### error [Section titled “error”](#error) ```ts error: unknown; ``` *** ### type [Section titled “type”](#type) ```ts type: "error"; ``` # TransportEvent ```ts type TransportEvent = | TransportError | TransportToolCallEvent | InputAudioTranscriptionCompletedEvent | { [key: string]: any; type: string; }; ``` # TransportLayerAudio ```ts type TransportLayerAudio = object; ``` Event representing audio data from the model on the transport layer. ## Properties [Section titled “Properties”](#properties) ### data [Section titled “data”](#data) ```ts data: ArrayBuffer; ``` *** ### responseId [Section titled “responseId”](#responseid) ```ts responseId: string; ``` *** ### type [Section titled “type”](#type) ```ts type: "audio"; ``` # TransportLayerResponseCompleted ```ts type TransportLayerResponseCompleted = protocol.StreamEventResponseCompleted; ``` # TransportLayerResponseStarted ```ts type TransportLayerResponseStarted = protocol.StreamEventResponseStarted; ``` # TransportLayerTranscriptDelta ```ts type TransportLayerTranscriptDelta = object; ``` ## Properties [Section titled “Properties”](#properties) ### delta [Section titled “delta”](#delta) ```ts delta: string; ``` *** ### itemId [Section titled “itemId”](#itemid) ```ts itemId: string; ``` *** ### responseId [Section titled “responseId”](#responseid) ```ts responseId: string; ``` *** ### type [Section titled “type”](#type) ```ts type: "transcript_delta"; ``` # TransportToolCallEvent ```ts type TransportToolCallEvent = object; ``` Event representing an attempted tool call by the model on the transport layer. ## Properties [Section titled “Properties”](#properties) ### arguments [Section titled “arguments”](#arguments) ```ts arguments: string; ``` *** ### callId [Section titled “callId”](#callid) ```ts callId: string; ``` *** ### id? [Section titled “id?”](#id) ```ts optional id?: string; ``` *** ### name [Section titled “name”](#name) ```ts name: string; ``` *** ### previousItemId? [Section titled “previousItemId?”](#previousitemid) ```ts optional previousItemId?: string; ``` *** ### type [Section titled “type”](#type) ```ts type: "function_call"; ``` # WebRTCState ```ts type WebRTCState = | { callId: string | undefined; dataChannel: undefined; peerConnection: undefined; status: "disconnected"; } | { callId: string | undefined; dataChannel: RTCDataChannel; peerConnection: RTCPeerConnection; status: "connecting"; } | { callId: string | undefined; dataChannel: RTCDataChannel; peerConnection: RTCPeerConnection; status: "connected"; }; ``` The connection state of the WebRTC connection. # WebSocketState ```ts type WebSocketState = | { status: "disconnected"; websocket: undefined; } | { status: "connecting"; websocket: WebSocket; } | { status: "connected"; websocket: WebSocket; }; ``` The connection state of the WebSocket connection. # DEFAULT_OPENAI_REALTIME_MODEL ```ts const DEFAULT_OPENAI_REALTIME_MODEL: OpenAIRealtimeModels; ``` The default model that is used during the connection if no model is provided. # DEFAULT_OPENAI_REALTIME_SESSION_CONFIG ```ts const DEFAULT_OPENAI_REALTIME_SESSION_CONFIG: Partial; ``` The default session config that gets send over during session connection unless overridden by the user. # utils ```ts const utils: object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### arrayBufferToBase64 [Section titled “arrayBufferToBase64”](#arraybuffertobase64) ```ts arrayBufferToBase64: typeof utilImport.arrayBufferToBase64; ``` ### base64ToArrayBuffer [Section titled “base64ToArrayBuffer”](#base64toarraybuffer) ```ts base64ToArrayBuffer: typeof utilImport.base64ToArrayBuffer; ``` ### getLastTextFromAudioOutputMessage [Section titled “getLastTextFromAudioOutputMessage”](#getlasttextfromaudiooutputmessage) ```ts getLastTextFromAudioOutputMessage: typeof utilImport.getLastTextFromAudioOutputMessage; ``` # AgentConfigWithHandoffs ```ts type AgentConfigWithHandoffs = object & Partial>, "name" | "handoffs" | "outputType">>; ``` Helper type for config with handoffs ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### handoffs? [Section titled “handoffs?”](#handoffs) ```ts optional handoffs?: Handoffs; ``` ### name [Section titled “name”](#name) ```ts name: string; ``` ### outputType? [Section titled “outputType?”](#outputtype) ```ts optional outputType?: TOutput; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Description | | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------ | | `TOutput` *extends* [`AgentOutputType`](/openai-agents-js/openai/agents/type-aliases/agentoutputtype/) | The type of the output object. | | `Handoffs` *extends* readonly ( \| [`Agent`](/openai-agents-js/openai/agents/classes/agent/)<`any`, `any`> \| [`Handoff`](/openai-agents-js/openai/agents/classes/handoff/)<`any`, `any`>)\[] | The type of the handoffs. | # AgentInputItem ```ts type AgentInputItem = | UserMessageItem | AssistantMessageItem | SystemMessageItem | ToolSearchCallItem | ToolSearchOutputItem | HostedToolCallItem | FunctionCallItem | ComputerUseCallItem | ShellCallItem | ApplyPatchCallItem | FunctionCallResultItem | ComputerCallResultItem | ShellCallResultItem | ApplyPatchCallResultItem | ReasoningItem | CompactionItem | UnknownItem; ``` Agent input # AgentOptions ```ts type AgentOptions = Expand, "name"> & Partial>>; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | ------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------- | | `TContext` | [`UnknownContext`](/openai-agents-js/openai/agents/type-aliases/unknowncontext/) | | `TOutput` *extends* [`AgentOutputType`](/openai-agents-js/openai/agents/type-aliases/agentoutputtype/) | [`TextOutput`](/openai-agents-js/openai/agents/type-aliases/textoutput/) | # AgentOutputItem ```ts type AgentOutputItem = | UserMessageItem | AssistantMessageItem | SystemMessageItem | ToolSearchCallItem | ToolSearchOutputItem | HostedToolCallItem | FunctionCallItem | ComputerUseCallItem | ShellCallItem | ApplyPatchCallItem | FunctionCallResultItem | ComputerCallResultItem | ShellCallResultItem | ApplyPatchCallResultItem | ReasoningItem | CompactionItem | UnknownItem; ``` Agent output items # AgentOutputType ```ts type AgentOutputType = | TextOutput | ZodObjectLike | JsonSchemaDefinition | HandoffsOutput; ``` The type of the output object. If not provided, the output will be a string. ‘text’ is a special type that indicates the output will be a string. ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | Description | | ------------------- | -------------------------------------------------------------------------------- | -------------------------------------- | | `HandoffOutputType` | [`UnknownContext`](/openai-agents-js/openai/agents/type-aliases/unknowncontext/) | The type of the output of the handoff. | # AgentSpanData ```ts type AgentSpanData = SpanDataBase & object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### handoffs? [Section titled “handoffs?”](#handoffs) ```ts optional handoffs?: string[]; ``` ### name [Section titled “name”](#name) ```ts name: string; ``` ### output\_type? [Section titled “output\_type?”](#output_type) ```ts optional output_type?: string; ``` ### tools? [Section titled “tools?”](#tools) ```ts optional tools?: string[]; ``` ### type [Section titled “type”](#type) ```ts type: "agent"; ``` # AgentToolInvocation ```ts type AgentToolInvocation = Readonly<{ toolArguments?: string; toolCallId?: string; toolName: string; }>; ``` # ApplyPatchCallItem ```ts type ApplyPatchCallItem = ZodObject; ``` # ApplyPatchCallItem ```ts type ApplyPatchCallItem = object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### callId [Section titled “callId”](#callid) ```ts callId: string; ``` ### id? [Section titled “id?”](#id) ```ts optional id?: string; ``` ### operation [Section titled “operation”](#operation) ```ts operation: | { diff: string; path: string; type: "create_file"; } | { diff: string; moveTo?: string; path: string; type: "update_file"; } | { path: string; type: "delete_file"; }; ``` ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` ### status [Section titled “status”](#status) ```ts status: "completed" | "in_progress"; ``` ### type [Section titled “type”](#type) ```ts type: "apply_patch_call"; ``` # ApplyPatchCallResultItem ```ts type ApplyPatchCallResultItem = ZodObject; ``` # ApplyPatchCallResultItem ```ts type ApplyPatchCallResultItem = object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### callId [Section titled “callId”](#callid) ```ts callId: string; ``` ### id? [Section titled “id?”](#id) ```ts optional id?: string; ``` ### output? [Section titled “output?”](#output) ```ts optional output?: string; ``` ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` ### status [Section titled “status”](#status) ```ts status: "completed" | "failed"; ``` ### type [Section titled “type”](#type) ```ts type: "apply_patch_call_output"; ``` # ApplyPatchOperation ```ts type ApplyPatchOperation = ZodDiscriminatedUnion; ``` # ApplyPatchOperation ```ts type ApplyPatchOperation = | { diff: string; path: string; type: "create_file"; } | { diff: string; moveTo?: string; path: string; type: "update_file"; } | { path: string; type: "delete_file"; }; ``` # ApplyPatchResult ```ts type ApplyPatchResult = object; ``` Result returned by an Editor operation. ## Properties [Section titled “Properties”](#properties) ### output? [Section titled “output?”](#output) ```ts optional output?: string; ``` Optional textual output to forward to the model. *** ### status? [Section titled “status?”](#status) ```ts optional status?: "completed" | "failed"; ``` Whether the operation completed successfully. Defaults to `completed`. # ApplyPatchTool ```ts type ApplyPatchTool = object; ``` ## Properties [Section titled “Properties”](#properties) ### editor [Section titled “editor”](#editor) ```ts editor: Editor; ``` Diff applier invoked when the tool is called. *** ### name [Section titled “name”](#name) ```ts name: string; ``` Public name exposed to the model. Defaults to `apply_patch`. *** ### needsApproval [Section titled “needsApproval”](#needsapproval) ```ts needsApproval: ApplyPatchApprovalFunction; ``` Predicate determining whether this apply\_patch operation requires approval. *** ### onApproval? [Section titled “onApproval?”](#onapproval) ```ts optional onApproval?: ApplyPatchOnApprovalFunction; ``` Optional handler to auto-approve or reject when approval is required. *** ### type [Section titled “type”](#type) ```ts type: "apply_patch"; ``` # AssistantMessageItem ```ts type AssistantMessageItem = ZodObject; ``` # AssistantMessageItem ```ts type AssistantMessageItem = object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### content [Section titled “content”](#content) ```ts content: ( | { providerData?: Record; text: string; type: "output_text"; } | { providerData?: Record; refusal: string; type: "refusal"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; } | { image: string; providerData?: Record; type: "image"; })[]; ``` ### id? [Section titled “id?”](#id) ```ts optional id?: string; ``` ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` ### role [Section titled “role”](#role) ```ts role: "assistant"; ``` ### status [Section titled “status”](#status) ```ts status: "completed" | "in_progress" | "incomplete"; ``` ### type? [Section titled “type?”](#type) ```ts optional type?: "message"; ``` # CallModelInputFilter ```ts type CallModelInputFilter = (args) => | ModelInputData | Promise; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | ------------ | | `TContext` | `unknown` | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ---------------------------------------------------------------------------------------------------------------- | | `args` | [`CallModelInputFilterArgs`](/openai-agents-js/openai/agents/type-aliases/callmodelinputfilterargs/)<`TContext`> | ## Returns [Section titled “Returns”](#returns) \| [`ModelInputData`](/openai-agents-js/openai/agents/type-aliases/modelinputdata/) | `Promise`<[`ModelInputData`](/openai-agents-js/openai/agents/type-aliases/modelinputdata/)> # CallModelInputFilterArgs ```ts type CallModelInputFilterArgs = object; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | ------------ | | `TContext` | `unknown` | ## Properties [Section titled “Properties”](#properties) ### agent [Section titled “agent”](#agent) ```ts agent: Agent; ``` *** ### context [Section titled “context”](#context) ```ts context: TContext | undefined; ``` *** ### modelData [Section titled “modelData”](#modeldata) ```ts modelData: ModelInputData; ``` # ClientToolSearchExecutor ```ts type ClientToolSearchExecutor = (args) => | ClientToolSearchExecutorResult | Promise>; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | -------------------------------------------------------------------------------- | | `Context` | [`UnknownContext`](/openai-agents-js/openai/agents/type-aliases/unknowncontext/) | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ----------------------------------------------------------------------------------------------------------------------- | | `args` | [`ClientToolSearchExecutorArgs`](/openai-agents-js/openai/agents/type-aliases/clienttoolsearchexecutorargs/)<`Context`> | ## Returns [Section titled “Returns”](#returns) \| [`ClientToolSearchExecutorResult`](/openai-agents-js/openai/agents/type-aliases/clienttoolsearchexecutorresult/)<`Context`> | `Promise`<[`ClientToolSearchExecutorResult`](/openai-agents-js/openai/agents/type-aliases/clienttoolsearchexecutorresult/)<`Context`>> # ClientToolSearchExecutorArgs ```ts type ClientToolSearchExecutorArgs = object; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | -------------------------------------------------------------------------------- | | `Context` | [`UnknownContext`](/openai-agents-js/openai/agents/type-aliases/unknowncontext/) | ## Properties [Section titled “Properties”](#properties) ### agent [Section titled “agent”](#agent) ```ts agent: Agent; ``` *** ### availableTools [Section titled “availableTools”](#availabletools) ```ts availableTools: Tool[]; ``` *** ### loadDefault [Section titled “loadDefault”](#loaddefault) ```ts loadDefault: ClientToolSearchLoadDefaultFunction; ``` *** ### runContext [Section titled “runContext”](#runcontext) ```ts runContext: RunContext; ``` *** ### toolCall [Section titled “toolCall”](#toolcall) ```ts toolCall: ToolSearchCallItem; ``` # ClientToolSearchExecutorResult ```ts type ClientToolSearchExecutorResult = | Tool | Tool[] | null | undefined; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | -------------------------------------------------------------------------------- | | `Context` | [`UnknownContext`](/openai-agents-js/openai/agents/type-aliases/unknowncontext/) | # CompletedAgentToolInvocationRunResult ```ts type CompletedAgentToolInvocationRunResult = CompletedRunResult & object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### agentToolInvocation [Section titled “agentToolInvocation”](#agenttoolinvocation) ```ts agentToolInvocation: AgentToolInvocation; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | ----------------------------------------------------------------------------------------------- | | `TContext` | | `TAgent` *extends* [`Agent`](/openai-agents-js/openai/agents/classes/agent/)<`TContext`, `any`> | # Computer ```ts type Computer = Expand, never>>; ``` Interface representing a fully implemented computer environment. Combines the base operations with a constraint that no extra action names beyond those in `ComputerAction` are present. # ComputerCallResultItem ```ts type ComputerCallResultItem = ZodObject; ``` # ComputerCallResultItem ```ts type ComputerCallResultItem = object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### callId [Section titled “callId”](#callid) ```ts callId: string; ``` ### id? [Section titled “id?”](#id) ```ts optional id?: string; ``` ### output [Section titled “output”](#output) ```ts output: object; ``` #### output.data [Section titled “output.data”](#outputdata) ```ts data: string; ``` #### output.providerData? [Section titled “output.providerData?”](#outputproviderdata) ```ts optional providerData?: Record; ``` #### output.type [Section titled “output.type”](#outputtype) ```ts type: "computer_screenshot"; ``` ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` ### type [Section titled “type”](#type) ```ts type: "computer_call_result"; ``` # ComputerOnSafetyCheckFunction ```ts type ComputerOnSafetyCheckFunction = (args) => Promise; ``` ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | -------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `args` | { `pendingSafetyChecks`: [`ComputerSafetyCheck`](/openai-agents-js/openai/agents/type-aliases/computersafetycheck/)\[]; `runContext`: [`RunContext`](/openai-agents-js/openai/agents/classes/runcontext/); `toolCall`: [`ComputerUseCallItem`](/openai-agents-js/openai/agents/type-aliases/computerusecallitem/); } | | `args.pendingSafetyChecks` | [`ComputerSafetyCheck`](/openai-agents-js/openai/agents/type-aliases/computersafetycheck/)\[] | | `args.runContext` | [`RunContext`](/openai-agents-js/openai/agents/classes/runcontext/) | | `args.toolCall` | [`ComputerUseCallItem`](/openai-agents-js/openai/agents/type-aliases/computerusecallitem/) | ## Returns [Section titled “Returns”](#returns) `Promise`<[`ComputerSafetyCheckResult`](/openai-agents-js/openai/agents/type-aliases/computersafetycheckresult/)> # ComputerSafetyCheck ```ts type ComputerSafetyCheck = object; ``` ## Indexable [Section titled “Indexable”](#indexable) ```ts [key: string]: unknown ``` ## Properties [Section titled “Properties”](#properties) ### code [Section titled “code”](#code) ```ts code: string; ``` *** ### id [Section titled “id”](#id) ```ts id: string; ``` *** ### message? [Section titled “message?”](#message) ```ts optional message?: string; ``` # ComputerSafetyCheckResult ```ts type ComputerSafetyCheckResult = | void | boolean | { acknowledgedSafetyChecks: ComputerSafetyCheck[]; } | { acknowledged_safety_checks: ComputerSafetyCheck[]; }; ``` # ComputerTool ```ts type ComputerTool = object; ``` Exposes a computer to the model as a tool to be called ## Param [Section titled “Param”](#param) The result of the tool ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | Description | | ------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------- | ----------------------- | | `Context` | [`UnknownContext`](/openai-agents-js/openai/agents/type-aliases/unknowncontext/) | The context of the tool | | `TComputer` *extends* [`Computer`](/openai-agents-js/openai/agents/type-aliases/computer/) | [`Computer`](/openai-agents-js/openai/agents/type-aliases/computer/) | ‐ | ## Properties [Section titled “Properties”](#properties) ### computer [Section titled “computer”](#computer) ```ts computer: ComputerConfig; ``` The computer to use. *** ### name [Section titled “name”](#name) ```ts name: "computer_use_preview" | string & object; ``` The name of the tool. *** ### needsApproval [Section titled “needsApproval”](#needsapproval) ```ts needsApproval: ComputerApprovalFunction; ``` Predicate determining whether this computer action requires approval. *** ### onSafetyCheck? [Section titled “onSafetyCheck?”](#onsafetycheck) ```ts optional onSafetyCheck?: ComputerOnSafetyCheckFunction; ``` Optional handler to acknowledge pending safety checks. *** ### type [Section titled “type”](#type) ```ts type: "computer"; ``` # ComputerUseCallItem ```ts type ComputerUseCallItem = ZodObject; ``` # ComputerUseCallItem ```ts type ComputerUseCallItem = object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### action? [Section titled “action?”](#action) ```ts optional action?: | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; }; ``` ### actions? [Section titled “actions?”](#actions) ```ts optional actions?: ( | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; })[]; ``` ### callId [Section titled “callId”](#callid) ```ts callId: string; ``` ### id? [Section titled “id?”](#id) ```ts optional id?: string; ``` ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` ### status [Section titled “status”](#status) ```ts status: "completed" | "in_progress" | "incomplete"; ``` ### type [Section titled “type”](#type) ```ts type: "computer_call"; ``` # CustomSpanData ```ts type CustomSpanData = SpanDataBase & object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### data [Section titled “data”](#data) ```ts data: Record; ``` ### name [Section titled “name”](#name) ```ts name: string; ``` ### type [Section titled “type”](#type) ```ts type: "custom"; ``` # EditorInvocationContext ```ts type EditorInvocationContext = object; ``` Runtime context passed to editor operations. ## Properties [Section titled “Properties”](#properties) ### runContext [Section titled “runContext”](#runcontext) ```ts runContext: RunContext; ``` Current run context. # FunctionCallItem ```ts type FunctionCallItem = ZodObject; ``` # FunctionCallItem ```ts type FunctionCallItem = object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### arguments [Section titled “arguments”](#arguments) ```ts arguments: string; ``` ### callId [Section titled “callId”](#callid) ```ts callId: string; ``` ### id? [Section titled “id?”](#id) ```ts optional id?: string; ``` ### name [Section titled “name”](#name) ```ts name: string; ``` ### namespace? [Section titled “namespace?”](#namespace) ```ts optional namespace?: string; ``` ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` ### status? [Section titled “status?”](#status) ```ts optional status?: "completed" | "in_progress" | "incomplete"; ``` ### type [Section titled “type”](#type) ```ts type: "function_call"; ``` # FunctionCallResultItem ```ts type FunctionCallResultItem = ZodObject; ``` # FunctionCallResultItem ```ts type FunctionCallResultItem = object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### callId [Section titled “callId”](#callid) ```ts callId: string; ``` ### id? [Section titled “id?”](#id) ```ts optional id?: string; ``` ### name [Section titled “name”](#name) ```ts name: string; ``` ### namespace? [Section titled “namespace?”](#namespace) ```ts optional namespace?: string; ``` ### output [Section titled “output”](#output) ```ts output: | string | { providerData?: Record; text: string; type: "text"; } | { detail?: string & object | "low" | "high" | "auto"; image?: | string | { data: string | Uint8Array; mediaType?: string; } | { url: string; } | { fileId: string; }; providerData?: Record; type: "image"; } | { file: | string | { data: string | Uint8Array; filename: string; mediaType: string; } | { filename?: string; url: string; } | { filename?: string; id: string; }; providerData?: Record; type: "file"; } | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; })[]; ``` ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` ### status [Section titled “status”](#status) ```ts status: "completed" | "in_progress" | "incomplete"; ``` ### type [Section titled “type”](#type) ```ts type: "function_call_result"; ``` # FunctionSpanData ```ts type FunctionSpanData = SpanDataBase & object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### input [Section titled “input”](#input) ```ts input: string; ``` ### mcp\_data? [Section titled “mcp\_data?”](#mcp_data) ```ts optional mcp_data?: string; ``` ### name [Section titled “name”](#name) ```ts name: string; ``` ### output [Section titled “output”](#output) ```ts output: string; ``` ### type [Section titled “type”](#type) ```ts type: "function"; ``` # FunctionTool ```ts type FunctionTool = object; ``` Exposes a function to the agent as a tool to be called ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | Description | | ------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------- | ----------------------- | | `Context` | [`UnknownContext`](/openai-agents-js/openai/agents/type-aliases/unknowncontext/) | The context of the tool | | `TParameters` *extends* [`ToolInputParameters`](/openai-agents-js/openai/agents/type-aliases/toolinputparameters/) | `undefined` | ‐ | | `Result` | `unknown` | The result of the tool | ## Properties [Section titled “Properties”](#properties) ### deferLoading? [Section titled “deferLoading?”](#deferloading) ```ts optional deferLoading?: boolean; ``` Responses API only. Hides a top-level function tool definition until tool search loads it. *** ### description [Section titled “description”](#description) ```ts description: string; ``` The description of the tool that helps the model to understand when to use the tool *** ### inputGuardrails? [Section titled “inputGuardrails?”](#inputguardrails) ```ts optional inputGuardrails?: ToolInputGuardrailDefinition[]; ``` Guardrails that run before the tool executes. *** ### invoke [Section titled “invoke”](#invoke) ```ts invoke: (runContext, input, details?) => Promise; ``` The function to invoke when the tool is called. #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ------------ | ------------------------------------------------------------------------------ | | `runContext` | [`RunContext`](/openai-agents-js/openai/agents/classes/runcontext/)<`Context`> | | `input` | `string` | | `details?` | `ToolCallDetails` | #### Returns [Section titled “Returns”](#returns) `Promise`<`string` | `Result`> *** ### isEnabled [Section titled “isEnabled”](#isenabled) ```ts isEnabled: ToolEnabledFunction; ``` Determines whether the tool should be made available to the model for the current run. *** ### name [Section titled “name”](#name) ```ts name: string; ``` The name of the tool. *** ### needsApproval [Section titled “needsApproval”](#needsapproval) ```ts needsApproval: ToolApprovalFunction; ``` Whether the tool needs human approval before it can be called. If this is true, the run will result in an `interruption` that the program has to resolve by approving or rejecting the tool call. *** ### outputGuardrails? [Section titled “outputGuardrails?”](#outputguardrails) ```ts optional outputGuardrails?: ToolOutputGuardrailDefinition[]; ``` Guardrails that run after the tool executes. *** ### parameters [Section titled “parameters”](#parameters-1) ```ts parameters: JsonObjectSchema; ``` A JSON schema describing the parameters of the tool. *** ### strict [Section titled “strict”](#strict) ```ts strict: boolean; ``` Whether the tool is strict. If true, the model must try to strictly follow the schema (might result in slower response times). *** ### timeoutBehavior? [Section titled “timeoutBehavior?”](#timeoutbehavior) ```ts optional timeoutBehavior?: FunctionToolTimeoutBehavior; ``` Defines how timeout errors are handled. * `error_as_result`: return a model-visible timeout message. * `raise_exception`: raise `ToolTimeoutError` and fail the run. *** ### timeoutErrorFunction? [Section titled “timeoutErrorFunction?”](#timeouterrorfunction) ```ts optional timeoutErrorFunction?: ToolTimeoutErrorFunction; ``` Optional formatter for timeout errors when timeoutBehavior is `error_as_result`. *** ### timeoutMs? [Section titled “timeoutMs?”](#timeoutms) ```ts optional timeoutMs?: number; ``` Optional timeout in milliseconds for each tool invocation. *** ### type [Section titled “type”](#type) ```ts type: "function"; ``` # FunctionToolResult ```ts type FunctionToolResult = | { agentRunResult?: RunResult>; interruptions?: RunToolApprovalItem[]; output: string | unknown; runItem: RunToolCallOutputItem; tool: FunctionTool; type: "function_output"; } | { runItem: RunToolApprovalItem; tool: FunctionTool; type: "function_approval"; } | { runItem: RunToolApprovalItem; tool: HostedMCPTool; type: "hosted_mcp_tool_approval"; }; ``` The result of invoking a function tool. Either the actual output of the execution or a tool approval request. These get passed for example to the `toolUseBehavior` option of the `Agent` constructor. ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | ------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------- | | `Context` | [`UnknownContext`](/openai-agents-js/openai/agents/type-aliases/unknowncontext/) | | `TParameters` *extends* [`ToolInputParameters`](/openai-agents-js/openai/agents/type-aliases/toolinputparameters/) | `any` | | `Result` | `any` | ## Union Members [Section titled “Union Members”](#union-members) ### Type Literal [Section titled “Type Literal”](#type-literal) ```ts { agentRunResult?: RunResult>; interruptions?: RunToolApprovalItem[]; output: string | unknown; runItem: RunToolCallOutputItem; tool: FunctionTool; type: "function_output"; } ``` #### agentRunResult? [Section titled “agentRunResult?”](#agentrunresult) ```ts optional agentRunResult?: RunResult>; ``` The result returned when the tool execution runs another agent. Populated when the invocation originated from [Agent.asTool](/openai-agents-js/openai/agents/classes/agent/#astool) and the nested agent completed a run. #### interruptions? [Section titled “interruptions?”](#interruptions) ```ts optional interruptions?: RunToolApprovalItem[]; ``` Any interruptions collected while the nested agent executed. These are surfaced to allow callers to pause and resume workflows that require approvals. #### output [Section titled “output”](#output) ```ts output: string | unknown; ``` The output of the tool call. This can be a string or a stringifable item. #### runItem [Section titled “runItem”](#runitem) ```ts runItem: RunToolCallOutputItem; ``` The run item representing the tool call output. #### tool [Section titled “tool”](#tool) ```ts tool: FunctionTool; ``` The tool that was called. #### type [Section titled “type”](#type) ```ts type: "function_output"; ``` *** ### Type Literal [Section titled “Type Literal”](#type-literal-1) ```ts { runItem: RunToolApprovalItem; tool: FunctionTool; type: "function_approval"; } ``` #### runItem [Section titled “runItem”](#runitem-1) ```ts runItem: RunToolApprovalItem; ``` The item representing the tool call that is requiring approval. #### tool [Section titled “tool”](#tool-1) ```ts tool: FunctionTool; ``` The tool that is requiring to be approved. #### type [Section titled “type”](#type-1) ```ts type: "function_approval"; ``` Indicates that the tool requires approval before it can be called. *** ### Type Literal [Section titled “Type Literal”](#type-literal-2) ```ts { runItem: RunToolApprovalItem; tool: HostedMCPTool; type: "hosted_mcp_tool_approval"; } ``` #### runItem [Section titled “runItem”](#runitem-2) ```ts runItem: RunToolApprovalItem; ``` The item representing the tool call that is requiring approval. #### tool [Section titled “tool”](#tool-2) ```ts tool: HostedMCPTool; ``` The tool that is requiring to be approved. #### type [Section titled “type”](#type-2) ```ts type: "hosted_mcp_tool_approval"; ``` Indicates that the tool requires approval before it can be called. # FunctionToolTimeoutBehavior ```ts type FunctionToolTimeoutBehavior = "error_as_result" | "raise_exception"; ``` # GenerationSpanData ```ts type GenerationSpanData = SpanDataBase & object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### input? [Section titled “input?”](#input) ```ts optional input?: Record[]; ``` ### model? [Section titled “model?”](#model) ```ts optional model?: string; ``` ### model\_config? [Section titled “model\_config?”](#model_config) ```ts optional model_config?: Record; ``` ### output? [Section titled “output?”](#output) ```ts optional output?: Record[]; ``` ### type [Section titled “type”](#type) ```ts type: "generation"; ``` ### usage? [Section titled “usage?”](#usage) ```ts optional usage?: GenerationUsageData; ``` Usage fields are intentionally flexible in agents-core tracing. Exporters are responsible for backend-specific mapping and validation. For example, the OpenAI tracing exporter in `@openai/agents-openai` keeps top-level generation usage to `input_tokens` and `output_tokens` for OpenAI traces ingest, and maps additional usage fields under `usage.details`. Third-party exporters can choose their own usage schema and transformation strategy. # GenerationUsageData ```ts type GenerationUsageData = object; ``` ## Indexable [Section titled “Indexable”](#indexable) ```ts [key: string]: unknown ``` ## Properties [Section titled “Properties”](#properties) ### details? [Section titled “details?”](#details) ```ts optional details?: Record | null; ``` *** ### input\_tokens? [Section titled “input\_tokens?”](#input_tokens) ```ts optional input_tokens?: number; ``` *** ### output\_tokens? [Section titled “output\_tokens?”](#output_tokens) ```ts optional output_tokens?: number; ``` # GetAllMcpToolsOptions ```ts type GetAllMcpToolsOptions = object; ``` Options for fetching MCP tools. ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | -------------- | | `TContext` | ## Properties [Section titled “Properties”](#properties) ### agent? [Section titled “agent?”](#agent) ```ts optional agent?: Agent; ``` *** ### convertSchemasToStrict? [Section titled “convertSchemasToStrict?”](#convertschemastostrict) ```ts optional convertSchemasToStrict?: boolean; ``` *** ### errorFunction? [Section titled “errorFunction?”](#errorfunction) ```ts optional errorFunction?: | MCPToolErrorFunction | null; ``` *** ### generateMCPToolCacheKey? [Section titled “generateMCPToolCacheKey?”](#generatemcptoolcachekey) ```ts optional generateMCPToolCacheKey?: MCPToolCacheKeyGenerator; ``` *** ### includeServerInToolNames? [Section titled “includeServerInToolNames?”](#includeserverintoolnames) ```ts optional includeServerInToolNames?: boolean; ``` *** ### mcpServers [Section titled “mcpServers”](#mcpservers) ```ts mcpServers: MCPServer[]; ``` *** ### reservedToolNames? [Section titled “reservedToolNames?”](#reservedtoolnames) ```ts optional reservedToolNames?: Set; ``` *** ### runContext? [Section titled “runContext?”](#runcontext) ```ts optional runContext?: RunContext; ``` # GuardrailSpanData ```ts type GuardrailSpanData = SpanDataBase & object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### name [Section titled “name”](#name) ```ts name: string; ``` ### triggered [Section titled “triggered”](#triggered) ```ts triggered: boolean; ``` ### type [Section titled “type”](#type) ```ts type: "guardrail"; ``` # HandoffEnabledFunction ```ts type HandoffEnabledFunction = (args) => Promise; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | -------------------------------------------------------------------------------- | | `TContext` | [`UnknownContext`](/openai-agents-js/openai/agents/type-aliases/unknowncontext/) | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | `args` | { `agent`: [`Agent`](/openai-agents-js/openai/agents/classes/agent/)<`any`, `any`>; `runContext`: [`RunContext`](/openai-agents-js/openai/agents/classes/runcontext/)<`TContext`>; } | | `args.agent` | [`Agent`](/openai-agents-js/openai/agents/classes/agent/)<`any`, `any`> | | `args.runContext` | [`RunContext`](/openai-agents-js/openai/agents/classes/runcontext/)<`TContext`> | ## Returns [Section titled “Returns”](#returns) `Promise`<`boolean`> # HandoffInputData ```ts type HandoffInputData = object; ``` Data passed to the handoff function. ## Properties [Section titled “Properties”](#properties) ### inputHistory [Section titled “inputHistory”](#inputhistory) ```ts inputHistory: | string | AgentInputItem[]; ``` The input history before `Runner.run()` was called. *** ### newItems [Section titled “newItems”](#newitems) ```ts newItems: RunItem[]; ``` The new items generated during the current agent turn, including the item that triggered the handoff and the tool output message representing the response from the handoff output. *** ### preHandoffItems [Section titled “preHandoffItems”](#prehandoffitems) ```ts preHandoffItems: RunItem[]; ``` The items generated before the agent turn where the handoff was invoked. *** ### runContext? [Section titled “runContext?”](#runcontext) ```ts optional runContext?: RunContext; ``` The context of the handoff. Note that, since this property was added later on, it’s optional to pass from users. # HandoffSpanData ```ts type HandoffSpanData = SpanDataBase & object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### from\_agent? [Section titled “from\_agent?”](#from_agent) ```ts optional from_agent?: string; ``` ### to\_agent? [Section titled “to\_agent?”](#to_agent) ```ts optional to_agent?: string; ``` ### type [Section titled “type”](#type) ```ts type: "handoff"; ``` # HostedMCPTool ```ts type HostedMCPTool = HostedTool & object; ``` A hosted MCP tool that lets the model call a remote MCP server directly without a round trip back to your code. ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### name [Section titled “name”](#name) ```ts name: "hosted_mcp"; ``` ### providerData [Section titled “providerData”](#providerdata) ```ts providerData: ProviderData.HostedMCPTool; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | -------------------------------------------------------------------------------- | | `Context` | [`UnknownContext`](/openai-agents-js/openai/agents/type-aliases/unknowncontext/) | # HostedTool ```ts type HostedTool = object; ``` A built-in hosted tool that will be executed directly by the model during the request and won’t result in local code executions. Examples of these are `web_search_call` or `file_search_call`. ## Param [Section titled “Param”](#param) The context of the tool ## Param [Section titled “Param”](#param-1) The result of the tool ## Properties [Section titled “Properties”](#properties) ### name [Section titled “name”](#name) ```ts name: string; ``` A unique name for the tool. *** ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` Additional configuration data that gets passed to the tool *** ### type [Section titled “type”](#type) ```ts type: "hosted_tool"; ``` # HostedToolCallItem ```ts type HostedToolCallItem = ZodObject; ``` # HostedToolCallItem ```ts type HostedToolCallItem = object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### arguments? [Section titled “arguments?”](#arguments) ```ts optional arguments?: string; ``` ### id? [Section titled “id?”](#id) ```ts optional id?: string; ``` ### name [Section titled “name”](#name) ```ts name: string; ``` ### output? [Section titled “output?”](#output) ```ts optional output?: string; ``` ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` ### status? [Section titled “status?”](#status) ```ts optional status?: string; ``` ### type [Section titled “type”](#type) ```ts type: "hosted_tool_call"; ``` # IndividualRunOptions ```ts type IndividualRunOptions = | StreamRunOptions | NonStreamRunOptions; ``` Options polymorphic over streaming or non-streaming execution modes. ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | ------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------- | | `TContext` | `undefined` | | `TAgent` *extends* [`Agent`](/openai-agents-js/openai/agents/classes/agent/)<`any`, `any`> | [`Agent`](/openai-agents-js/openai/agents/classes/agent/)<`any`, `any`> | # InputGuardrailFunction ```ts type InputGuardrailFunction = (args) => Promise; ``` The function that performs the actual input guardrail check and returns the decision on whether a guardrail was triggered. ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ------------------------------------------------------------------------------------------------------ | | `args` | [`InputGuardrailFunctionArgs`](/openai-agents-js/openai/agents/interfaces/inputguardrailfunctionargs/) | ## Returns [Section titled “Returns”](#returns) `Promise`<[`GuardrailFunctionOutput`](/openai-agents-js/openai/agents/interfaces/guardrailfunctionoutput/)> # JsonSchemaDefinition ```ts type JsonSchemaDefinition = object; ``` Wrapper around a JSON schema used for describing tool parameters. ## Properties [Section titled “Properties”](#properties) ### name [Section titled “name”](#name) ```ts name: string; ``` *** ### schema [Section titled “schema”](#schema) ```ts schema: JsonObjectSchema>; ``` *** ### strict [Section titled “strict”](#strict) ```ts strict: boolean; ``` *** ### type [Section titled “type”](#type) ```ts type: "json_schema"; ``` # MCPListToolsSpanData ```ts type MCPListToolsSpanData = SpanDataBase & object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### result? [Section titled “result?”](#result) ```ts optional result?: string[]; ``` ### server? [Section titled “server?”](#server) ```ts optional server?: string; ``` ### type [Section titled “type”](#type) ```ts type: "mcp_tools"; ``` # MCPResourceContent ```ts type MCPResourceContent = | MCPTextResourceContent | MCPBlobResourceContent; ``` # MCPServersOptions ```ts type MCPServersOptions = object; ``` ## Properties [Section titled “Properties”](#properties) ### closeTimeoutMs? [Section titled “closeTimeoutMs?”](#closetimeoutms) ```ts optional closeTimeoutMs?: number | null; ``` *** ### connectInParallel? [Section titled “connectInParallel?”](#connectinparallel) ```ts optional connectInParallel?: boolean; ``` *** ### connectTimeoutMs? [Section titled “connectTimeoutMs?”](#connecttimeoutms) ```ts optional connectTimeoutMs?: number | null; ``` *** ### dropFailed? [Section titled “dropFailed?”](#dropfailed) ```ts optional dropFailed?: boolean; ``` *** ### strict? [Section titled “strict?”](#strict) ```ts optional strict?: boolean; ``` *** ### suppressAbortError? [Section titled “suppressAbortError?”](#suppressaborterror) ```ts optional suppressAbortError?: boolean; ``` # MCPServersReconnectOptions ```ts type MCPServersReconnectOptions = object; ``` ## Properties [Section titled “Properties”](#properties) ### failedOnly? [Section titled “failedOnly?”](#failedonly) ```ts optional failedOnly?: boolean; ``` # MCPToolCacheKeyGenerator ```ts type MCPToolCacheKeyGenerator = (params) => string; ``` Function signature for generating the MCP tool cache key. Customizable so the cache key can depend on any context—server, agent, runContext, etc. ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `params` | { `agent?`: [`Agent`](/openai-agents-js/openai/agents/classes/agent/)<`any`, `any`>; `runContext?`: [`RunContext`](/openai-agents-js/openai/agents/classes/runcontext/)<`any`>; `server`: [`MCPServer`](/openai-agents-js/openai/agents/interfaces/mcpserver/); } | | `params.agent?` | [`Agent`](/openai-agents-js/openai/agents/classes/agent/)<`any`, `any`> | | `params.runContext?` | [`RunContext`](/openai-agents-js/openai/agents/classes/runcontext/)<`any`> | | `params.server` | [`MCPServer`](/openai-agents-js/openai/agents/interfaces/mcpserver/) | ## Returns [Section titled “Returns”](#returns) `string` # MCPToolErrorFunction ```ts type MCPToolErrorFunction = (args) => Promise | string; ``` ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | -------------- | ------------------------------------------------------------------------------------------------------------------ | | `args` | { `context`: [`RunContext`](/openai-agents-js/openai/agents/classes/runcontext/); `error`: `Error` \| `unknown`; } | | `args.context` | [`RunContext`](/openai-agents-js/openai/agents/classes/runcontext/) | | `args.error` | `Error` \| `unknown` | ## Returns [Section titled “Returns”](#returns) `Promise`<`string`> | `string` # MCPToolFilterCallable ```ts type MCPToolFilterCallable = (context, tool) => Promise; ``` A function that determines whether a tool should be available. ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | -------------------------------------------------------------------------------- | | `TContext` | [`UnknownContext`](/openai-agents-js/openai/agents/type-aliases/unknowncontext/) | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ------------------------------------------------------------------------------------------------------ | | `context` | [`MCPToolFilterContext`](/openai-agents-js/openai/agents/interfaces/mcptoolfiltercontext/)<`TContext`> | | `tool` | `MCPTool` | ## Returns [Section titled “Returns”](#returns) `Promise`<`boolean`> # MCPToolMetaResolver ```ts type MCPToolMetaResolver = (context) => | Promise | null | undefined> | Record | null | undefined; ``` A function that produces MCP request metadata (`_meta`) for tool calls. ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | -------------------------------------------------------------------------------- | | `TContext` | [`UnknownContext`](/openai-agents-js/openai/agents/type-aliases/unknowncontext/) | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | -------------------------------------------------------------------------------------------------- | | `context` | [`MCPToolMetaContext`](/openai-agents-js/openai/agents/interfaces/mcptoolmetacontext/)<`TContext`> | ## Returns [Section titled “Returns”](#returns) \| `Promise`<`Record`<`string`, `unknown`> | `null` | `undefined`> | `Record`<`string`, `unknown`> | `null` | `undefined` # ModelInputData ```ts type ModelInputData = object; ``` ## Properties [Section titled “Properties”](#properties) ### input [Section titled “input”](#input) ```ts input: AgentInputItem[]; ``` *** ### instructions? [Section titled “instructions?”](#instructions) ```ts optional instructions?: string; ``` # ModelRequest ```ts type ModelRequest = object; ``` A request to a large language model. ## Properties [Section titled “Properties”](#properties) ### conversationId? [Section titled “conversationId?”](#conversationid) ```ts optional conversationId?: string; ``` The ID of stored conversation to use for the model. see see *** ### handoffs [Section titled “handoffs”](#handoffs) ```ts handoffs: SerializedHandoff[]; ``` The handoffs to use for the model. *** ### input [Section titled “input”](#input) ```ts input: | string | AgentInputItem[]; ``` The input to the model. *** ### modelSettings [Section titled “modelSettings”](#modelsettings) ```ts modelSettings: ModelSettings; ``` The model settings to use for the model. *** ### outputType [Section titled “outputType”](#outputtype) ```ts outputType: SerializedOutputType; ``` The type of the output to use for the model. *** ### overridePromptModel? [Section titled “overridePromptModel?”](#overridepromptmodel) ```ts optional overridePromptModel?: boolean; ``` When true, the resolved model should override the model configured in the prompt template. Providers that support prompt templates should include the explicit model name in the request even when a prompt is supplied. *** ### previousResponseId? [Section titled “previousResponseId?”](#previousresponseid) ```ts optional previousResponseId?: string; ``` The ID of the previous response to use for the model. *** ### prompt? [Section titled “prompt?”](#prompt) ```ts optional prompt?: Prompt; ``` The prompt template to use for the model, if any. *** ### signal? [Section titled “signal?”](#signal) ```ts optional signal?: AbortSignal; ``` An optional signal to abort the model request. *** ### systemInstructions? [Section titled “systemInstructions?”](#systeminstructions) ```ts optional systemInstructions?: string; ``` The system instructions to use for the model. *** ### tools [Section titled “tools”](#tools) ```ts tools: SerializedTool[]; ``` The tools to use for the model. *** ### toolsExplicitlyProvided? [Section titled “toolsExplicitlyProvided?”](#toolsexplicitlyprovided) ```ts optional toolsExplicitlyProvided?: boolean; ``` When true, the caller explicitly configured the tools list (even if empty). Providers can use this to avoid overwriting prompt-defined tools when an agent does not specify its own tools. *** ### tracing [Section titled “tracing”](#tracing) ```ts tracing: ModelTracing; ``` Whether to enable tracing for the model. # ModelResponse ```ts type ModelResponse = object; ``` ## Properties [Section titled “Properties”](#properties) ### output [Section titled “output”](#output) ```ts output: AgentOutputItem[]; ``` A list of outputs (messages, tool calls, etc.) generated by the model. *** ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` Raw response data from the underlying model provider. *** ### requestId? [Section titled “requestId?”](#requestid) ```ts optional requestId?: string; ``` The transport request ID for this model call, if provided by the model SDK or transport. *** ### responseId? [Section titled “responseId?”](#responseid) ```ts optional responseId?: string; ``` An ID for the response which can be used to refer to the response in subsequent calls to the model. Not supported by all model providers. *** ### usage [Section titled “usage”](#usage) ```ts usage: Usage; ``` The usage information for response. # ModelRetryAdvice ```ts type ModelRetryAdvice = object; ``` ## Properties [Section titled “Properties”](#properties) ### normalized? [Section titled “normalized?”](#normalized) ```ts optional normalized?: Partial; ``` Provider-supplied normalized facts that should override generic extraction when present. *** ### reason? [Section titled “reason?”](#reason) ```ts optional reason?: string; ``` Optional explanation for why the provider suggested or vetoed a retry. *** ### replaySafety? [Section titled “replaySafety?”](#replaysafety) ```ts optional replaySafety?: "unsafe" | "safe"; ``` Provider confidence about whether replaying the request is safe. Omit this field when replay safety is unknown. *** ### retryAfterMs? [Section titled “retryAfterMs?”](#retryafterms) ```ts optional retryAfterMs?: number; ``` Optional delay hint in milliseconds from the provider or transport layer. *** ### suggested? [Section titled “suggested?”](#suggested) ```ts optional suggested?: boolean; ``` Optional provider recommendation for whether this error is retryable. The runner still applies safety vetoes first and user policy remains the final authority. # ModelRetryAdviceRequest ```ts type ModelRetryAdviceRequest = object; ``` ## Properties [Section titled “Properties”](#properties) ### attempt [Section titled “attempt”](#attempt) ```ts attempt: number; ``` The 1-based number of the failed attempt. *** ### error [Section titled “error”](#error) ```ts error: unknown; ``` The error thrown by the failed attempt. *** ### request [Section titled “request”](#request) ```ts request: ModelRequest; ``` The failed request that is being evaluated for replay. *** ### stream [Section titled “stream”](#stream) ```ts stream: boolean; ``` Whether the failed request used streaming. # ModelRetryBackoffSettings ```ts type ModelRetryBackoffSettings = object; ``` ## Properties [Section titled “Properties”](#properties) ### initialDelayMs? [Section titled “initialDelayMs?”](#initialdelayms) ```ts optional initialDelayMs?: number; ``` Delay for the first retry in milliseconds. *** ### jitter? [Section titled “jitter?”](#jitter) ```ts optional jitter?: boolean; ``` Whether to apply jitter to the computed backoff delay. *** ### maxDelayMs? [Section titled “maxDelayMs?”](#maxdelayms) ```ts optional maxDelayMs?: number; ``` Maximum delay between retries in milliseconds. *** ### multiplier? [Section titled “multiplier?”](#multiplier) ```ts optional multiplier?: number; ``` Multiplier applied after each retry attempt. # ModelRetryNormalizedError ```ts type ModelRetryNormalizedError = object; ``` ## Properties [Section titled “Properties”](#properties) ### errorCode? [Section titled “errorCode?”](#errorcode) ```ts optional errorCode?: string; ``` Provider or transport-specific error code when exposed. *** ### isAbort [Section titled “isAbort”](#isabort) ```ts isAbort: boolean; ``` Whether the error was caused by an abort signal or abort exception. *** ### isNetworkError [Section titled “isNetworkError”](#isnetworkerror) ```ts isNetworkError: boolean; ``` Whether the error appears to come from a transient transport or connectivity problem. *** ### retryAfterMs? [Section titled “retryAfterMs?”](#retryafterms) ```ts optional retryAfterMs?: number; ``` Suggested delay in milliseconds derived from retry-after style headers. *** ### statusCode? [Section titled “statusCode?”](#statuscode) ```ts optional statusCode?: number; ``` HTTP status code when the provider exposes one. # ModelRetrySettings ```ts type ModelRetrySettings = object; ``` ## Properties [Section titled “Properties”](#properties) ### backoff? [Section titled “backoff?”](#backoff) ```ts optional backoff?: ModelRetryBackoffSettings; ``` Backoff configuration used when the retry policy requests a retry without returning an explicit delay. *** ### maxRetries? [Section titled “maxRetries?”](#maxretries) ```ts optional maxRetries?: number; ``` Number of retries allowed after the initial model request. Retries remain opt-in; no retries occur unless `policy` returns `true`. *** ### policy? [Section titled “policy?”](#policy) ```ts optional policy?: RetryPolicy; ``` Runtime-only retry policy. This callback is not serialized into persisted run state. # ModelSettings ```ts type ModelSettings = object; ``` Settings to use when calling an LLM. This class holds optional model configuration parameters (e.g. temperature, topP, penalties, truncation, etc.). Not all models/providers support all of these parameters, so please check the API documentation for the specific model and provider you are using. ## Properties [Section titled “Properties”](#properties) ### contextManagement? [Section titled “contextManagement?”](#contextmanagement) ```ts optional contextManagement?: ModelSettingsContextManagement; ``` Context-management strategies to apply when calling the model. This setting is available on OpenAI Responses requests, including server-side compaction. See . *** ### frequencyPenalty? [Section titled “frequencyPenalty?”](#frequencypenalty) ```ts optional frequencyPenalty?: number; ``` The frequency penalty to use when calling the model. *** ### maxTokens? [Section titled “maxTokens?”](#maxtokens) ```ts optional maxTokens?: number; ``` The maximum number of output tokens to generate. *** ### parallelToolCalls? [Section titled “parallelToolCalls?”](#paralleltoolcalls) ```ts optional parallelToolCalls?: boolean; ``` Whether to use parallel tool calls when calling the model. Defaults to false if not provided. *** ### presencePenalty? [Section titled “presencePenalty?”](#presencepenalty) ```ts optional presencePenalty?: number; ``` The presence penalty to use when calling the model. *** ### promptCacheRetention? [Section titled “promptCacheRetention?”](#promptcacheretention) ```ts optional promptCacheRetention?: "in-memory" | "24h" | null; ``` Enables prompt caching and controls how long cached content should be retained by the model provider. See for the available options. *** ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` Additional provider specific settings to be passed directly to the model request. *** ### reasoning? [Section titled “reasoning?”](#reasoning) ```ts optional reasoning?: ModelSettingsReasoning; ``` The reasoning settings to use when calling the model. *** ### retry? [Section titled “retry?”](#retry) ```ts optional retry?: ModelRetrySettings; ``` Runtime-only retry configuration for the model request. *** ### store? [Section titled “store?”](#store) ```ts optional store?: boolean; ``` Whether to store the generated model response for later retrieval. Defaults to true if not provided. *** ### temperature? [Section titled “temperature?”](#temperature) ```ts optional temperature?: number; ``` The temperature to use when calling the model. *** ### text? [Section titled “text?”](#text) ```ts optional text?: ModelSettingsText; ``` The text settings to use when calling the model. *** ### toolChoice? [Section titled “toolChoice?”](#toolchoice) ```ts optional toolChoice?: ModelSettingsToolChoice; ``` The tool choice to use when calling the model. *** ### topP? [Section titled “topP?”](#topp) ```ts optional topP?: number; ``` The topP to use when calling the model. *** ### truncation? [Section titled “truncation?”](#truncation) ```ts optional truncation?: "auto" | "disabled"; ``` The truncation strategy to use when calling the model. # ModelSettingsContextManagement ```ts type ModelSettingsContextManagement = object[]; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ## Index Signature [Section titled “Index Signature”](#index-signature) ```ts [key: string]: unknown ``` ### compact\_threshold? [Section titled “compact\_threshold?”](#compact_threshold) ```ts optional compact_threshold?: number; ``` Rendered-token threshold that triggers server-side compaction. ### compactThreshold? [Section titled “compactThreshold?”](#compactthreshold) ```ts optional compactThreshold?: number; ``` Rendered-token threshold that triggers server-side compaction. ### type [Section titled “type”](#type) ```ts type: "compaction" | string & object; ``` The context-management strategy to apply. # ModelSettingsToolChoice ```ts type ModelSettingsToolChoice = "auto" | "required" | "none" | string & object; ``` # NonStreamRunOptions ```ts type NonStreamRunOptions = SharedRunOptions & object; ``` Options for runs that collect the full model response before returning. ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### stream? [Section titled “stream?”](#stream) ```ts optional stream?: false; ``` Run to completion without streaming incremental events; leave undefined or set to `false`. ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | ------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------- | | `TContext` | `undefined` | | `TAgent` *extends* [`Agent`](/openai-agents-js/openai/agents/classes/agent/)<`any`, `any`> | [`Agent`](/openai-agents-js/openai/agents/classes/agent/)<`any`, `any`> | # OpenAIChatCompletionsModelOptions ```ts type OpenAIChatCompletionsModelOptions = object; ``` A model that uses (or is compatible with) OpenAI’s Chat Completions API. ## Properties [Section titled “Properties”](#properties) ### strictFeatureValidation? [Section titled “strictFeatureValidation?”](#strictfeaturevalidation) ```ts optional strictFeatureValidation?: boolean; ``` When true, reject Responses-only features that Chat Completions cannot honor. Defaults to false, which preserves the previous ignore-and-warn behavior. # OpenAIChatCompletionsRawModelStreamEvent ```ts type OpenAIChatCompletionsRawModelStreamEvent = Omit & object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### data [Section titled “data”](#data) ```ts data: OpenAIRawModelEventData; ``` ### source [Section titled “source”](#source) ```ts source: typeof OPENAI_CHAT_COMPLETIONS_RAW_MODEL_EVENT_SOURCE; ``` # OpenAIConversationsSessionOptions ```ts type OpenAIConversationsSessionOptions = object; ``` ## Properties [Section titled “Properties”](#properties) ### apiKey? [Section titled “apiKey?”](#apikey) ```ts optional apiKey?: string; ``` *** ### baseURL? [Section titled “baseURL?”](#baseurl) ```ts optional baseURL?: string; ``` *** ### client? [Section titled “client?”](#client) ```ts optional client?: OpenAI; ``` *** ### conversationId? [Section titled “conversationId?”](#conversationid) ```ts optional conversationId?: string; ``` *** ### organization? [Section titled “organization?”](#organization) ```ts optional organization?: string; ``` *** ### project? [Section titled “project?”](#project) ```ts optional project?: string; ``` # OpenAIProviderOptions ```ts type OpenAIProviderOptions = object; ``` Options for OpenAIProvider. ## Properties [Section titled “Properties”](#properties) ### apiKey? [Section titled “apiKey?”](#apikey) ```ts optional apiKey?: string; ``` *** ### baseURL? [Section titled “baseURL?”](#baseurl) ```ts optional baseURL?: string; ``` *** ### cacheResponsesWebSocketModels? [Section titled “cacheResponsesWebSocketModels?”](#cacheresponseswebsocketmodels) ```ts optional cacheResponsesWebSocketModels?: boolean; ``` *** ### openAIClient? [Section titled “openAIClient?”](#openaiclient) ```ts optional openAIClient?: OpenAI; ``` *** ### organization? [Section titled “organization?”](#organization) ```ts optional organization?: string; ``` *** ### project? [Section titled “project?”](#project) ```ts optional project?: string; ``` *** ### responsesWebSocketOptions? [Section titled “responsesWebSocketOptions?”](#responseswebsocketoptions) ```ts optional responsesWebSocketOptions?: OpenAIResponsesWebSocketOptions; ``` *** ### strictFeatureValidation? [Section titled “strictFeatureValidation?”](#strictfeaturevalidation) ```ts optional strictFeatureValidation?: boolean; ``` When false, Chat Completions models warn and ignore Responses-only features such as previousResponseId, conversationId, and prompt. When true, they raise UserError instead. *** ### useResponses? [Section titled “useResponses?”](#useresponses) ```ts optional useResponses?: boolean; ``` *** ### useResponsesWebSocket? [Section titled “useResponsesWebSocket?”](#useresponseswebsocket) ```ts optional useResponsesWebSocket?: boolean; ``` *** ### websocketBaseURL? [Section titled “websocketBaseURL?”](#websocketbaseurl) ```ts optional websocketBaseURL?: string; ``` # OpenAIRawModelEventSource ```ts type OpenAIRawModelEventSource = | typeof OPENAI_RESPONSES_RAW_MODEL_EVENT_SOURCE | typeof OPENAI_CHAT_COMPLETIONS_RAW_MODEL_EVENT_SOURCE; ``` # OpenAIResponsesCompactionArgs ```ts type OpenAIResponsesCompactionArgs = object; ``` Session subtype that can run compaction logic after a completed turn is persisted. ## Properties [Section titled “Properties”](#properties) ### compactionMode? [Section titled “compactionMode?”](#compactionmode) ```ts optional compactionMode?: "previous_response_id" | "input" | "auto"; ``` How the compaction request should provide conversation history. When omitted, implementations use their configured default. *** ### force? [Section titled “force?”](#force) ```ts optional force?: boolean; ``` When true, compaction should run regardless of any internal thresholds or hooks. *** ### responseId? [Section titled “responseId?”](#responseid) ```ts optional responseId?: string; ``` The `response.id` from a completed OpenAI Responses API turn, if available. When omitted, implementations may fall back to a cached value or throw. *** ### store? [Section titled “store?”](#store) ```ts optional store?: boolean; ``` Whether the last model response was stored on the server. When set to false, compaction should avoid `previous_response_id` unless explicitly overridden. # OpenAIResponsesCompactionDecisionContext ```ts type OpenAIResponsesCompactionDecisionContext = object; ``` ## Properties [Section titled “Properties”](#properties) ### compactionCandidateItems [Section titled “compactionCandidateItems”](#compactioncandidateitems) ```ts compactionCandidateItems: AgentInputItem[]; ``` Items considered compaction candidates (excludes user and compaction items). The array must not be mutated. *** ### compactionMode [Section titled “compactionMode”](#compactionmode) ```ts compactionMode: OpenAIResponsesCompactionMode; ``` Resolved compaction mode used for this request. *** ### responseId [Section titled “responseId”](#responseid) ```ts responseId: string | undefined; ``` The `response.id` from a completed OpenAI Responses API turn, if available. When `compactionMode` is `input`, this may be undefined. *** ### sessionItems [Section titled “sessionItems”](#sessionitems) ```ts sessionItems: AgentInputItem[]; ``` All stored items retrieved from the underlying session, if available. The array must not be mutated. # OpenAIResponsesCompactionMode ```ts type OpenAIResponsesCompactionMode = "previous_response_id" | "input" | "auto"; ``` # OpenAIResponsesCompactionResult ```ts type OpenAIResponsesCompactionResult = object; ``` ## Properties [Section titled “Properties”](#properties) ### usage [Section titled “usage”](#usage) ```ts usage: RequestUsage; ``` # OpenAIResponsesCompactionSessionOptions ```ts type OpenAIResponsesCompactionSessionOptions = object; ``` ## Properties [Section titled “Properties”](#properties) ### client? [Section titled “client?”](#client) ```ts optional client?: OpenAI; ``` OpenAI client used to call `responses.compact`. When omitted, the session will use `getDefaultOpenAIClient()` if configured. Otherwise it creates a new `OpenAI()` instance via `new OpenAI()`. *** ### compactionMode? [Section titled “compactionMode?”](#compactionmode) ```ts optional compactionMode?: OpenAIResponsesCompactionMode; ``` Controls how the compaction request is built. * `auto` (default): Uses `input` when the last response was not stored or no response id is available. * `previous_response_id`: Uses the server-managed response chain. * `input`: Sends the locally stored session items as input and does not require a response id. *** ### model? [Section titled “model?”](#model) ```ts optional model?: OpenAI.ResponsesModel; ``` The OpenAI model to use for `responses.compact`. Defaults to `DEFAULT_OPENAI_MODEL`. The value must resemble an OpenAI model name (for example `gpt-*`, `o*`, or a fine-tuned `ft:gpt-*` identifier), otherwise the constructor throws. *** ### shouldTriggerCompaction? [Section titled “shouldTriggerCompaction?”](#shouldtriggercompaction) ```ts optional shouldTriggerCompaction?: (context) => boolean | Promise; ``` Custom decision hook that determines whether to call `responses.compact`. The default implementation compares the length of [OpenAIResponsesCompactionDecisionContext.compactionCandidateItems](/openai-agents-js/openai/agents/type-aliases/openairesponsescompactiondecisioncontext/#compactioncandidateitems) to an internal threshold (10). Override this to support token-based triggers or other heuristics using [OpenAIResponsesCompactionDecisionContext.compactionCandidateItems](/openai-agents-js/openai/agents/type-aliases/openairesponsescompactiondecisioncontext/#compactioncandidateitems) or [OpenAIResponsesCompactionDecisionContext.sessionItems](/openai-agents-js/openai/agents/type-aliases/openairesponsescompactiondecisioncontext/#sessionitems). #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ------------------------------------------------------------------------------------------------------------------------------------ | | `context` | [`OpenAIResponsesCompactionDecisionContext`](/openai-agents-js/openai/agents/type-aliases/openairesponsescompactiondecisioncontext/) | #### Returns [Section titled “Returns”](#returns) `boolean` | `Promise`<`boolean`> *** ### underlyingSession? [Section titled “underlyingSession?”](#underlyingsession) ```ts optional underlyingSession?: Session & object; ``` Session store that receives items and holds the compacted history. The underlying session is the source of truth for persisted items. Compaction clears the underlying session and writes the output items returned by `responses.compact`. This must not be an `OpenAIConversationsSession`, because compaction relies on locally stored items and replaces the underlying session history after `responses.compact`. Defaults to an in-memory session for demos. #### Type Declaration [Section titled “Type Declaration”](#type-declaration) | Name | Type | | ----------------------- | ------------- | | `[OPENAI_SESSION_API]?` | `"responses"` | # OpenAIResponsesRawModelStreamEvent ```ts type OpenAIResponsesRawModelStreamEvent = Omit & object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### data [Section titled “data”](#data) ```ts data: OpenAIRawModelEventData; ``` ### source [Section titled “source”](#source) ```ts source: typeof OPENAI_RESPONSES_RAW_MODEL_EVENT_SOURCE; ``` # OpenAIResponsesWebSocketOptions ```ts type OpenAIResponsesWebSocketOptions = ResponsesWebSocketKeepAliveOptions; ``` # OpenAITracingExporterOptions ```ts type OpenAITracingExporterOptions = object; ``` Options for OpenAITracingExporter. ## Properties [Section titled “Properties”](#properties) ### apiKey? [Section titled “apiKey?”](#apikey) ```ts optional apiKey?: string; ``` *** ### baseDelay [Section titled “baseDelay”](#basedelay) ```ts baseDelay: number; ``` *** ### endpoint [Section titled “endpoint”](#endpoint) ```ts endpoint: string; ``` *** ### maxDelay [Section titled “maxDelay”](#maxdelay) ```ts maxDelay: number; ``` *** ### maxRetries [Section titled “maxRetries”](#maxretries) ```ts maxRetries: number; ``` *** ### organization [Section titled “organization”](#organization) ```ts organization: string; ``` *** ### project [Section titled “project”](#project) ```ts project: string; ``` # OutputGuardrailFunction ```ts type OutputGuardrailFunction = (args) => Promise; ``` A function that takes an output guardrail function arguments and returns a `GuardrailFunctionOutput`. ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | ------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------- | | `TOutput` *extends* [`AgentOutputType`](/openai-agents-js/openai/agents/type-aliases/agentoutputtype/) | [`TextOutput`](/openai-agents-js/openai/agents/type-aliases/textoutput/) | | `TContext` | [`UnknownContext`](/openai-agents-js/openai/agents/type-aliases/unknowncontext/) | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ------------------------------------------------------------------------------------------------------------------------------- | | `args` | [`OutputGuardrailFunctionArgs`](/openai-agents-js/openai/agents/interfaces/outputguardrailfunctionargs/)<`TContext`, `TOutput`> | ## Returns [Section titled “Returns”](#returns) `Promise`<[`GuardrailFunctionOutput`](/openai-agents-js/openai/agents/interfaces/guardrailfunctionoutput/)> # ReasoningItem ```ts type ReasoningItem = ZodObject; ``` # ReasoningItem ```ts type ReasoningItem = object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### content [Section titled “content”](#content) ```ts content: object[]; ``` ### id? [Section titled “id?”](#id) ```ts optional id?: string; ``` ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` ### rawContent? [Section titled “rawContent?”](#rawcontent) ```ts optional rawContent?: object[]; ``` ### type [Section titled “type”](#type) ```ts type: "reasoning"; ``` # ReasoningItemIdPolicy ```ts type ReasoningItemIdPolicy = "preserve" | "omit"; ``` # ResponseSpanData ```ts type ResponseSpanData = SpanDataBase & object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### \_input? [Section titled “\_input?”](#_input) ```ts optional _input?: string | Record[]; ``` Not used by the OpenAI tracing provider but helpful for other tracing providers. ### \_response? [Section titled “\_response?”](#_response) ```ts optional _response?: Record; ``` ### response\_id? [Section titled “response\_id?”](#response_id) ```ts optional response_id?: string; ``` ### type [Section titled “type”](#type) ```ts type: "response"; ``` # ResponseStreamEvent ```ts type ResponseStreamEvent = StreamEvent; ``` Event emitted when streaming model responses. # ResponsesWebSocketSession ```ts type ResponsesWebSocketSession = object; ``` ## Properties [Section titled “Properties”](#properties) ### provider [Section titled “provider”](#provider) ```ts provider: OpenAIProvider; ``` *** ### run [Section titled “run”](#run) ```ts run: Runner["run"]; ``` *** ### runner [Section titled “runner”](#runner) ```ts runner: Runner; ``` # ResponsesWebSocketSessionOptions ```ts type ResponsesWebSocketSessionOptions = object; ``` ## Properties [Section titled “Properties”](#properties) ### providerOptions? [Section titled “providerOptions?”](#provideroptions) ```ts optional providerOptions?: OpenAIProviderOptions; ``` Options used to construct the session-scoped OpenAI provider. *** ### responsesWebSocketOptions? [Section titled “responsesWebSocketOptions?”](#responseswebsocketoptions) ```ts optional responsesWebSocketOptions?: OpenAIResponsesWebSocketOptions; ``` Low-level keepalive options for the session-scoped Responses WebSocket transport. *** ### runnerConfig? [Section titled “runnerConfig?”](#runnerconfig) ```ts optional runnerConfig?: Omit, "modelProvider">; ``` Runner configuration for the session. modelProvider is controlled by this helper. # RetryDecision ```ts type RetryDecision = | boolean | { delayMs?: number; reason?: string; retry: boolean; }; ``` ## Union Members [Section titled “Union Members”](#union-members) `boolean` *** ### Type Literal [Section titled “Type Literal”](#type-literal) ```ts { delayMs?: number; reason?: string; retry: boolean; } ``` #### delayMs? [Section titled “delayMs?”](#delayms) ```ts optional delayMs?: number; ``` Optional delay override in milliseconds before the next retry attempt. #### reason? [Section titled “reason?”](#reason) ```ts optional reason?: string; ``` Optional explanation for logging or debugging. #### retry [Section titled “retry”](#retry) ```ts retry: boolean; ``` Whether the failed request should be retried. # RetryPolicy ```ts type RetryPolicy = (context) => | RetryDecision | Promise; ``` ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ---------------------------------------------------------------------------------------- | | `context` | [`RetryPolicyContext`](/openai-agents-js/openai/agents/type-aliases/retrypolicycontext/) | ## Returns [Section titled “Returns”](#returns) \| [`RetryDecision`](/openai-agents-js/openai/agents/type-aliases/retrydecision/) | `Promise`<[`RetryDecision`](/openai-agents-js/openai/agents/type-aliases/retrydecision/)> # RetryPolicyContext ```ts type RetryPolicyContext = object; ``` ## Properties [Section titled “Properties”](#properties) ### attempt [Section titled “attempt”](#attempt) ```ts attempt: number; ``` The 1-based number of the failed attempt. *** ### error [Section titled “error”](#error) ```ts error: unknown; ``` The error thrown by the failed model attempt. *** ### maxRetries [Section titled “maxRetries”](#maxretries) ```ts maxRetries: number; ``` The configured number of retries allowed after the initial attempt. *** ### normalized [Section titled “normalized”](#normalized) ```ts normalized: ModelRetryNormalizedError; ``` Generic normalized facts extracted from the error and provider advice. *** ### providerAdvice? [Section titled “providerAdvice?”](#provideradvice) ```ts optional providerAdvice?: ModelRetryAdvice; ``` Optional provider guidance for the failure. *** ### stream [Section titled “stream”](#stream) ```ts stream: boolean; ``` Whether the failed request was streaming. # RunConfig ```ts type RunConfig = object; ``` Configures settings for the entire agent run. ## Properties [Section titled “Properties”](#properties) ### callModelInputFilter? [Section titled “callModelInputFilter?”](#callmodelinputfilter) ```ts optional callModelInputFilter?: CallModelInputFilter; ``` Invoked immediately before calling the model, allowing callers to edit the system instructions or input items that will be sent to the model. *** ### groupId? [Section titled “groupId?”](#groupid) ```ts optional groupId?: string; ``` A grouping identifier to use for tracing, to link multiple traces from the same conversation or process. For example, you might use a chat thread ID. *** ### handoffInputFilter? [Section titled “handoffInputFilter?”](#handoffinputfilter) ```ts optional handoffInputFilter?: HandoffInputFilter; ``` A global input filter to apply to all handoffs. If `Handoff.inputFilter` is set, then that will take precedence. The input filter allows you to edit the inputs that are sent to the new agent. See the documentation in `Handoff.inputFilter` for more details. *** ### inputGuardrails? [Section titled “inputGuardrails?”](#inputguardrails) ```ts optional inputGuardrails?: InputGuardrail[]; ``` A list of input guardrails to run on the initial run input. *** ### model? [Section titled “model?”](#model) ```ts optional model?: string | Model; ``` The model to use for the entire agent run. If set, will override the model set on every agent. The modelProvider passed in below must be able to resolve this model name. *** ### modelProvider [Section titled “modelProvider”](#modelprovider) ```ts modelProvider: ModelProvider; ``` The model provider to use when looking up string model names. Defaults to OpenAI. *** ### modelSettings? [Section titled “modelSettings?”](#modelsettings) ```ts optional modelSettings?: ModelSettings; ``` Configure global model settings. Any non-null values will override the agent-specific model settings. *** ### outputGuardrails? [Section titled “outputGuardrails?”](#outputguardrails) ```ts optional outputGuardrails?: OutputGuardrail>[]; ``` A list of output guardrails to run on the final output of the run. *** ### reasoningItemIdPolicy? [Section titled “reasoningItemIdPolicy?”](#reasoningitemidpolicy) ```ts optional reasoningItemIdPolicy?: ReasoningItemIdPolicy; ``` Controls how run items are converted into model input for subsequent turns. *** ### sandbox? [Section titled “sandbox?”](#sandbox) ```ts optional sandbox?: SandboxRunConfig; ``` Sandbox runtime configuration used when execution reaches a sandbox agent. *** ### sessionInputCallback? [Section titled “sessionInputCallback?”](#sessioninputcallback) ```ts optional sessionInputCallback?: SessionInputCallback; ``` Customizes how session history is combined with the current turn’s input. When omitted, history items are appended before the new input. *** ### toolErrorFormatter? [Section titled “toolErrorFormatter?”](#toolerrorformatter) ```ts optional toolErrorFormatter?: ToolErrorFormatter; ``` Formats tool error messages that are returned to the model. Returning `undefined` falls back to the SDK default message. *** ### toolExecution? [Section titled “toolExecution?”](#toolexecution) ```ts optional toolExecution?: ToolExecutionConfig; ``` SDK-side execution settings for local tool calls. *** ### traceId? [Section titled “traceId?”](#traceid) ```ts optional traceId?: string; ``` A custom trace ID to use for tracing. If not provided, we will generate a new trace ID. *** ### traceIncludeSensitiveData [Section titled “traceIncludeSensitiveData”](#traceincludesensitivedata) ```ts traceIncludeSensitiveData: boolean; ``` Whether we include potentially sensitive data (for example: inputs/outputs of tool calls or LLM generations) in traces. If false, we’ll still create spans for these events, but the sensitive data will not be included. *** ### traceMetadata? [Section titled “traceMetadata?”](#tracemetadata) ```ts optional traceMetadata?: Record; ``` An optional dictionary of additional metadata to include with the trace. *** ### tracing? [Section titled “tracing?”](#tracing) ```ts optional tracing?: TracingConfig; ``` Tracing configuration for this run. Use this to override the API key used when exporting traces. *** ### tracingDisabled [Section titled “tracingDisabled”](#tracingdisabled) ```ts tracingDisabled: boolean; ``` Whether tracing is disabled for the agent run. If disabled, we will not trace the agent run. *** ### workflowName? [Section titled “workflowName?”](#workflowname) ```ts optional workflowName?: string; ``` The name of the run, used for tracing. Should be a logical name for the run, like “Code generation workflow” or “Customer support agent”. # RunErrorData ```ts type RunErrorData = object; ``` Snapshot of run data passed to error handlers. ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | ------------------------------------------------------------------------------------------ | | `TContext` | | `TAgent` *extends* [`Agent`](/openai-agents-js/openai/agents/classes/agent/)<`any`, `any`> | ## Properties [Section titled “Properties”](#properties) ### history [Section titled “history”](#history) ```ts history: AgentInputItem[]; ``` *** ### input [Section titled “input”](#input) ```ts input: | string | AgentInputItem[]; ``` *** ### lastAgent? [Section titled “lastAgent?”](#lastagent) ```ts optional lastAgent?: TAgent; ``` *** ### newItems [Section titled “newItems”](#newitems) ```ts newItems: RunItem[]; ``` *** ### output [Section titled “output”](#output) ```ts output: AgentOutputItem[]; ``` *** ### rawResponses [Section titled “rawResponses”](#rawresponses) ```ts rawResponses: ModelResponse[]; ``` *** ### state? [Section titled “state?”](#state) ```ts optional state?: RunState; ``` # RunErrorHandler ```ts type RunErrorHandler = (input) => | RunErrorHandlerResult | void | Promise< | RunErrorHandlerResult | void>; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | ------------------------------------------------------------------------------------------ | | `TContext` | | `TAgent` *extends* [`Agent`](/openai-agents-js/openai/agents/classes/agent/)<`any`, `any`> | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ------------------------------------------------------------------------------------------------------------------ | | `input` | [`RunErrorHandlerInput`](/openai-agents-js/openai/agents/type-aliases/runerrorhandlerinput/)<`TContext`, `TAgent`> | ## Returns [Section titled “Returns”](#returns) \| [`RunErrorHandlerResult`](/openai-agents-js/openai/agents/type-aliases/runerrorhandlerresult/)<`TAgent`> | `void` | `Promise`< | [`RunErrorHandlerResult`](/openai-agents-js/openai/agents/type-aliases/runerrorhandlerresult/)<`TAgent`> | `void`> # RunErrorHandlerInput ```ts type RunErrorHandlerInput = object; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | ------------------------------------------------------------------------------------------ | | `TContext` | | `TAgent` *extends* [`Agent`](/openai-agents-js/openai/agents/classes/agent/)<`any`, `any`> | ## Properties [Section titled “Properties”](#properties) ### context [Section titled “context”](#context) ```ts context: RunContext; ``` *** ### error [Section titled “error”](#error) ```ts error: | MaxTurnsExceededError | ModelRefusalError; ``` *** ### runData [Section titled “runData”](#rundata) ```ts runData: RunErrorData; ``` # RunErrorHandlerResult ```ts type RunErrorHandlerResult = object; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | ------------------------------------------------------------------------------------------ | | `TAgent` *extends* [`Agent`](/openai-agents-js/openai/agents/classes/agent/)<`any`, `any`> | ## Properties [Section titled “Properties”](#properties) ### finalOutput [Section titled “finalOutput”](#finaloutput) ```ts finalOutput: ResolvedAgentOutput; ``` The final output to return for the run. *** ### includeInHistory? [Section titled “includeInHistory?”](#includeinhistory) ```ts optional includeInHistory?: boolean; ``` Whether to append the synthesized output to history for subsequent runs. # RunErrorHandlers ```ts type RunErrorHandlers = Partial>> & object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### default? [Section titled “default?”](#default) ```ts optional default?: RunErrorHandler; ``` Fallback handler for supported error kinds. ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | ------------------------------------------------------------------------------------------ | | `TContext` | | `TAgent` *extends* [`Agent`](/openai-agents-js/openai/agents/classes/agent/)<`any`, `any`> | # RunErrorKind ```ts type RunErrorKind = "maxTurns" | "modelRefusal"; ``` Error kinds supported by run error handlers. # RunItem ```ts type RunItem = | RunMessageOutputItem | RunToolCallItem | RunToolSearchCallItem | RunToolSearchOutputItem | RunReasoningItem | RunHandoffCallItem | RunToolCallOutputItem | RunHandoffOutputItem | RunToolApprovalItem; ``` # RunStreamEvent ```ts type RunStreamEvent = | RunRawModelStreamEvent | RunItemStreamEvent | RunAgentUpdatedStreamEvent; ``` A streaming event from an agent run. # SerializedHandoff ```ts type SerializedHandoff = object; ``` ## Properties [Section titled “Properties”](#properties) ### inputJsonSchema [Section titled “inputJsonSchema”](#inputjsonschema) ```ts inputJsonSchema: Handoff["inputJsonSchema"]; ``` The JSON schema for the handoff input. Can be empty if the handoff does not take an input *** ### strictJsonSchema [Section titled “strictJsonSchema”](#strictjsonschema) ```ts strictJsonSchema: Handoff["strictJsonSchema"]; ``` Whether the input JSON schema is in strict mode. We strongly recommend setting this to true, as it increases the likelihood of correct JSON input. *** ### toolDescription [Section titled “toolDescription”](#tooldescription) ```ts toolDescription: Handoff["toolDescription"]; ``` The tool description for the handoff *** ### toolName [Section titled “toolName”](#toolname) ```ts toolName: Handoff["toolName"]; ``` The name of the tool that represents the handoff. # SerializedOutputType ```ts type SerializedOutputType = | JsonSchemaDefinition | TextOutput; ``` The output type passed to the model. Has any Zod types serialized to JSON Schema # SerializedTool ```ts type SerializedTool = | SerializedFunctionTool | SerializedComputerTool | SerializedShellTool | SerializedApplyPatchTool | SerializedHostedTool; ``` # SessionHistoryMutation ```ts type SessionHistoryMutation = SessionHistoryReplaceFunctionCallMutation; ``` # SessionHistoryRewriteArgs ```ts type SessionHistoryRewriteArgs = object; ``` ## Properties [Section titled “Properties”](#properties) ### mutations [Section titled “mutations”](#mutations) ```ts mutations: SessionHistoryMutation[]; ``` # SessionInputCallback ```ts type SessionInputCallback = (historyItems, newItems) => | AgentInputItem[] | Promise; ``` A function that combines session history with new input items before the model call. ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | -------------- | ----------------------------------------------------------------------------------- | | `historyItems` | [`AgentInputItem`](/openai-agents-js/openai/agents/type-aliases/agentinputitem/)\[] | | `newItems` | [`AgentInputItem`](/openai-agents-js/openai/agents/type-aliases/agentinputitem/)\[] | ## Returns [Section titled “Returns”](#returns) \| [`AgentInputItem`](/openai-agents-js/openai/agents/type-aliases/agentinputitem/)\[] | `Promise`<[`AgentInputItem`](/openai-agents-js/openai/agents/type-aliases/agentinputitem/)\[]> # ShellAction ```ts type ShellAction = ShellAction; ``` Describes the work to perform when executing a shell tool call. Re-export protocol type to keep a single source of truth. # ShellCallItem ```ts type ShellCallItem = ZodObject; ``` # ShellCallItem ```ts type ShellCallItem = object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### action [Section titled “action”](#action) ```ts action: object; ``` #### action.commands [Section titled “action.commands”](#actioncommands) ```ts commands: string[]; ``` #### action.maxOutputLength? [Section titled “action.maxOutputLength?”](#actionmaxoutputlength) ```ts optional maxOutputLength?: number; ``` #### action.timeoutMs? [Section titled “action.timeoutMs?”](#actiontimeoutms) ```ts optional timeoutMs?: number; ``` ### callId [Section titled “callId”](#callid) ```ts callId: string; ``` ### id? [Section titled “id?”](#id) ```ts optional id?: string; ``` ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` ### status? [Section titled “status?”](#status) ```ts optional status?: "completed" | "in_progress" | "incomplete"; ``` ### type [Section titled “type”](#type) ```ts type: "shell_call"; ``` # ShellCallResultItem ```ts type ShellCallResultItem = ZodObject; ``` # ShellCallResultItem ```ts type ShellCallResultItem = object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### callId [Section titled “callId”](#callid) ```ts callId: string; ``` ### id? [Section titled “id?”](#id) ```ts optional id?: string; ``` ### maxOutputLength? [Section titled “maxOutputLength?”](#maxoutputlength) ```ts optional maxOutputLength?: number; ``` ### output [Section titled “output”](#output) ```ts output: object[]; ``` #### Index Signature [Section titled “Index Signature”](#index-signature) ```ts [key: string]: unknown ``` ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` ### type [Section titled “type”](#type) ```ts type: "shell_call_output"; ``` # ShellOutputResult ```ts type ShellOutputResult = ShellCallOutputContent; ``` Output for a single executed command. # ShellResult ```ts type ShellResult = object; ``` ## Properties [Section titled “Properties”](#properties) ### maxOutputLength? [Section titled “maxOutputLength?”](#maxoutputlength) ```ts optional maxOutputLength?: number; ``` If you applied truncation yourself, set the limit you enforced for telemetry. *** ### output [Section titled “output”](#output) ```ts output: ShellOutputResult[]; ``` One entry per executed command (or logical chunk) in order. *** ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` Optional provider-specific metadata merged into the tool call output. # ShellTool ```ts type ShellTool = LocalShellTool | HostedShellTool; ``` # ShellToolContainerAutoEnvironment ```ts type ShellToolContainerAutoEnvironment = object; ``` ## Properties [Section titled “Properties”](#properties) ### fileIds? [Section titled “fileIds?”](#fileids) ```ts optional fileIds?: string[]; ``` *** ### memoryLimit? [Section titled “memoryLimit?”](#memorylimit) ```ts optional memoryLimit?: "1g" | "4g" | "16g" | "64g" | null; ``` *** ### networkPolicy? [Section titled “networkPolicy?”](#networkpolicy) ```ts optional networkPolicy?: ShellToolContainerNetworkPolicy; ``` *** ### skills? [Section titled “skills?”](#skills) ```ts optional skills?: ShellToolContainerSkill[]; ``` *** ### type [Section titled “type”](#type) ```ts type: "container_auto"; ``` # ShellToolContainerNetworkPolicy ```ts type ShellToolContainerNetworkPolicy = | ShellToolContainerNetworkPolicyAllowlist | ShellToolContainerNetworkPolicyDisabled; ``` # ShellToolContainerNetworkPolicyAllowlist ```ts type ShellToolContainerNetworkPolicyAllowlist = object; ``` ## Properties [Section titled “Properties”](#properties) ### allowedDomains [Section titled “allowedDomains”](#alloweddomains) ```ts allowedDomains: string[]; ``` *** ### domainSecrets? [Section titled “domainSecrets?”](#domainsecrets) ```ts optional domainSecrets?: ShellToolContainerNetworkPolicyDomainSecret[]; ``` *** ### type [Section titled “type”](#type) ```ts type: "allowlist"; ``` # ShellToolContainerNetworkPolicyDisabled ```ts type ShellToolContainerNetworkPolicyDisabled = object; ``` ## Properties [Section titled “Properties”](#properties) ### type [Section titled “type”](#type) ```ts type: "disabled"; ``` # ShellToolContainerNetworkPolicyDomainSecret ```ts type ShellToolContainerNetworkPolicyDomainSecret = object; ``` ## Properties [Section titled “Properties”](#properties) ### domain [Section titled “domain”](#domain) ```ts domain: string; ``` *** ### name [Section titled “name”](#name) ```ts name: string; ``` *** ### value [Section titled “value”](#value) ```ts value: string; ``` # ShellToolContainerReferenceEnvironment ```ts type ShellToolContainerReferenceEnvironment = object; ``` ## Properties [Section titled “Properties”](#properties) ### containerId [Section titled “containerId”](#containerid) ```ts containerId: string; ``` *** ### type [Section titled “type”](#type) ```ts type: "container_reference"; ``` # ShellToolContainerSkill ```ts type ShellToolContainerSkill = | ShellToolSkillReference | ShellToolInlineSkill; ``` # ShellToolEnvironment ```ts type ShellToolEnvironment = | ShellToolLocalEnvironment | ShellToolHostedEnvironment; ``` # ShellToolHostedEnvironment ```ts type ShellToolHostedEnvironment = | ShellToolContainerAutoEnvironment | ShellToolContainerReferenceEnvironment; ``` # ShellToolInlineSkill ```ts type ShellToolInlineSkill = object; ``` ## Properties [Section titled “Properties”](#properties) ### description [Section titled “description”](#description) ```ts description: string; ``` *** ### name [Section titled “name”](#name) ```ts name: string; ``` *** ### source [Section titled “source”](#source) ```ts source: ShellToolInlineSkillSource; ``` *** ### type [Section titled “type”](#type) ```ts type: "inline"; ``` # ShellToolInlineSkillSource ```ts type ShellToolInlineSkillSource = object; ``` ## Properties [Section titled “Properties”](#properties) ### data [Section titled “data”](#data) ```ts data: string; ``` *** ### mediaType [Section titled “mediaType”](#mediatype) ```ts mediaType: "application/zip"; ``` *** ### type [Section titled “type”](#type) ```ts type: "base64"; ``` # ShellToolLocalEnvironment ```ts type ShellToolLocalEnvironment = object; ``` ## Properties [Section titled “Properties”](#properties) ### skills? [Section titled “skills?”](#skills) ```ts optional skills?: ShellToolLocalSkill[]; ``` *** ### type [Section titled “type”](#type) ```ts type: "local"; ``` # ShellToolLocalSkill ```ts type ShellToolLocalSkill = object; ``` ## Properties [Section titled “Properties”](#properties) ### description [Section titled “description”](#description) ```ts description: string; ``` *** ### name [Section titled “name”](#name) ```ts name: string; ``` *** ### path [Section titled “path”](#path) ```ts path: string; ``` # ShellToolSkillReference ```ts type ShellToolSkillReference = object; ``` ## Properties [Section titled “Properties”](#properties) ### skillId [Section titled “skillId”](#skillid) ```ts skillId: string; ``` *** ### type [Section titled “type”](#type) ```ts type: "skill_reference"; ``` *** ### version? [Section titled “version?”](#version) ```ts optional version?: string; ``` # SpanData ```ts type SpanData = | AgentSpanData | FunctionSpanData | GenerationSpanData | ResponseSpanData | HandoffSpanData | CustomSpanData | GuardrailSpanData | TranscriptionSpanData | SpeechSpanData | SpeechGroupSpanData | MCPListToolsSpanData; ``` # SpanError ```ts type SpanError = object; ``` ## Properties [Section titled “Properties”](#properties) ### data? [Section titled “data?”](#data) ```ts optional data?: Record; ``` *** ### message [Section titled “message”](#message) ```ts message: string; ``` # SpanOptions ```ts type SpanOptions = object; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | -------------------------------------------------------------------------------------- | | `TData` *extends* [`SpanData`](/openai-agents-js/openai/agents/type-aliases/spandata/) | ## Properties [Section titled “Properties”](#properties) ### data [Section titled “data”](#data) ```ts data: TData; ``` *** ### endedAt? [Section titled “endedAt?”](#endedat) ```ts optional endedAt?: string; ``` *** ### error? [Section titled “error?”](#error) ```ts optional error?: SpanError; ``` *** ### parentId? [Section titled “parentId?”](#parentid) ```ts optional parentId?: string; ``` *** ### spanId? [Section titled “spanId?”](#spanid) ```ts optional spanId?: string; ``` *** ### startedAt? [Section titled “startedAt?”](#startedat) ```ts optional startedAt?: string; ``` *** ### traceId [Section titled “traceId”](#traceid) ```ts traceId: string; ``` *** ### traceMetadata? [Section titled “traceMetadata?”](#tracemetadata) ```ts optional traceMetadata?: Record; ``` *** ### tracingApiKey? [Section titled “tracingApiKey?”](#tracingapikey) ```ts optional tracingApiKey?: string; ``` # SpeechGroupSpanData ```ts type SpeechGroupSpanData = SpanDataBase & object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### input? [Section titled “input?”](#input) ```ts optional input?: string; ``` ### type [Section titled “type”](#type) ```ts type: "speech_group"; ``` # SpeechSpanData ```ts type SpeechSpanData = SpanDataBase & object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### input? [Section titled “input?”](#input) ```ts optional input?: string; ``` ### model? [Section titled “model?”](#model) ```ts optional model?: string; ``` ### model\_config? [Section titled “model\_config?”](#model_config) ```ts optional model_config?: Record; ``` ### output [Section titled “output”](#output) ```ts output: object; ``` #### output.data [Section titled “output.data”](#outputdata) ```ts data: string; ``` #### output.format [Section titled “output.format”](#outputformat) ```ts format: "pcm" | string & object; ``` ### type [Section titled “type”](#type) ```ts type: "speech"; ``` # StreamEvent ```ts type StreamEvent = ZodDiscriminatedUnion<[ZodObject<{ delta: ZodString; providerData: ZodOptional>; type: ZodLiteral<"output_text_delta">; }, $strip>, ZodObject<{ providerData: ZodOptional>; response: ZodObject<{ id: ZodString; output: ZodArray, ZodObject<{ arguments: ...; call_id: ...; callId: ...; execution: ...; id: ...; providerData: ...; status: ...; type: ...; }, $strip>, ZodObject<{ call_id: ...; callId: ...; execution: ...; id: ...; providerData: ...; status: ...; tools: ...; type: ...; }, $strip>], "type">>; providerData: ZodOptional>; requestId: ZodOptional; usage: ZodObject<{ inputTokens: ZodNumber; inputTokensDetails: ZodOptional>; outputTokens: ZodNumber; outputTokensDetails: ZodOptional>; requests: ZodOptional; requestUsageEntries: ZodOptional>>; totalTokens: ZodNumber; }, $strip>; }, $strip>; type: ZodLiteral<"response_done">; }, $strip>, ZodObject<{ providerData: ZodOptional>; type: ZodLiteral<"response_started">; }, $strip>, ZodObject<{ event: ZodAny; providerData: ZodOptional>; type: ZodLiteral<"model">; }, $strip>], "type">; ``` # StreamEvent ```ts type StreamEvent = | StreamEventTextStream | StreamEventResponseCompleted | StreamEventResponseStarted | StreamEventGenericItem; ``` # StreamEventGenericItem ```ts type StreamEventGenericItem = ZodObject; ``` Event returned for every item that gets streamed to the model. Used to expose the raw events from the model. # StreamEventGenericItem ```ts type StreamEventGenericItem = object; ``` Event returned for every item that gets streamed to the model. Used to expose the raw events from the model. ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### event [Section titled “event”](#event) ```ts event: any; ``` ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` ### type [Section titled “type”](#type) ```ts type: "model"; ``` # StreamEventResponseCompleted ```ts type StreamEventResponseCompleted = ZodObject; ``` Event returned by the model when a response is completed. # StreamEventResponseCompleted ```ts type StreamEventResponseCompleted = object; ``` Event returned by the model when a response is completed. ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` ### response [Section titled “response”](#response) ```ts response: object; ``` #### response.id [Section titled “response.id”](#responseid) ```ts id: string; ``` #### response.output [Section titled “response.output”](#responseoutput) ```ts output: ( | { content: ( | { providerData?: Record; text: string; type: "output_text"; } | { providerData?: Record; refusal: string; type: "refusal"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; } | { image: string; providerData?: Record; type: "image"; })[]; id?: string; providerData?: Record; role: "assistant"; status: "completed" | "in_progress" | "incomplete"; type?: "message"; } | { arguments: unknown; call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; type: "tool_search_call"; } | { call_id?: string | null; callId?: string | null; execution?: "client" | "server"; id?: string; providerData?: Record; status?: string; tools: Record[]; type: "tool_search_output"; } | { arguments?: string; id?: string; name: string; output?: string; providerData?: Record; status?: string; type: "hosted_tool_call"; } | { arguments: string; callId: string; id?: string; name: string; namespace?: string; providerData?: Record; status?: "completed" | "in_progress" | "incomplete"; type: "function_call"; } | { action?: | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; }; actions?: ( | { type: "screenshot"; } | { button: "left" | "right" | "wheel" | "back" | "forward"; type: "click"; x: number; y: number; } | { type: "double_click"; x: number; y: number; } | { scroll_x: number; scroll_y: number; type: "scroll"; x: number; y: number; } | { text: string; type: "type"; } | { type: "wait"; } | { type: "move"; x: number; y: number; } | { keys: string[]; type: "keypress"; } | { path: object[]; type: "drag"; })[]; callId: string; id?: string; providerData?: Record; status: "completed" | "in_progress" | "incomplete"; type: "computer_call"; } | { action: { commands: string[]; maxOutputLength?: number; timeoutMs?: number; }; callId: string; id?: string; providerData?: Record; status?: "completed" | "in_progress" | "incomplete"; type: "shell_call"; } | { callId: string; id?: string; operation: | { diff: string; path: string; type: "create_file"; } | { diff: string; moveTo?: string; path: string; type: "update_file"; } | { path: string; type: "delete_file"; }; providerData?: Record; status: "completed" | "in_progress"; type: "apply_patch_call"; } | { callId: string; id?: string; name: string; namespace?: string; output: | string | { providerData?: Record; text: string; type: "text"; } | { detail?: string & object | "low" | "high" | "auto"; image?: | string | { data: string | Uint8Array<...>; mediaType?: string; } | { url: string; } | { fileId: string; }; providerData?: Record; type: "image"; } | { file: | string | { data: string | Uint8Array<...>; filename: string; mediaType: string; } | { filename?: string; url: string; } | { filename?: string; id: string; }; providerData?: Record; type: "file"; } | ( | { providerData?: Record<..., ...>; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: ...; }; providerData?: Record<..., ...>; type: "input_image"; } | { file?: | string | { id: ...; } | { url: ...; }; filename?: string; providerData?: Record<..., ...>; type: "input_file"; })[]; providerData?: Record; status: "completed" | "in_progress" | "incomplete"; type: "function_call_result"; } | { callId: string; id?: string; maxOutputLength?: number; output: object[]; providerData?: Record; type: "shell_call_output"; } | { callId: string; id?: string; output?: string; providerData?: Record; status: "completed" | "failed"; type: "apply_patch_call_output"; } | { content: object[]; id?: string; providerData?: Record; rawContent?: object[]; type: "reasoning"; } | { created_by?: string; encrypted_content: string; id?: string; providerData?: Record; type: "compaction"; } | { id?: string; providerData?: Record; type: "unknown"; })[]; ``` #### response.providerData? [Section titled “response.providerData?”](#responseproviderdata) ```ts optional providerData?: Record; ``` #### response.requestId? [Section titled “response.requestId?”](#responserequestid) ```ts optional requestId?: string; ``` #### response.usage [Section titled “response.usage”](#responseusage) ```ts usage: object; ``` #### response.usage.inputTokens [Section titled “response.usage.inputTokens”](#responseusageinputtokens) ```ts inputTokens: number; ``` #### response.usage.inputTokensDetails? [Section titled “response.usage.inputTokensDetails?”](#responseusageinputtokensdetails) ```ts optional inputTokensDetails?: Record | Record[]; ``` #### response.usage.outputTokens [Section titled “response.usage.outputTokens”](#responseusageoutputtokens) ```ts outputTokens: number; ``` #### response.usage.outputTokensDetails? [Section titled “response.usage.outputTokensDetails?”](#responseusageoutputtokensdetails) ```ts optional outputTokensDetails?: Record | Record[]; ``` #### response.usage.requests? [Section titled “response.usage.requests?”](#responseusagerequests) ```ts optional requests?: number; ``` #### response.usage.requestUsageEntries? [Section titled “response.usage.requestUsageEntries?”](#responseusagerequestusageentries) ```ts optional requestUsageEntries?: object[]; ``` #### response.usage.totalTokens [Section titled “response.usage.totalTokens”](#responseusagetotaltokens) ```ts totalTokens: number; ``` ### type [Section titled “type”](#type) ```ts type: "response_done"; ``` # StreamEventResponseStarted ```ts type StreamEventResponseStarted = ZodObject; ``` Event returned by the model when a new response is started. # StreamEventResponseStarted ```ts type StreamEventResponseStarted = object; ``` Event returned by the model when a new response is started. ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` ### type [Section titled “type”](#type) ```ts type: "response_started"; ``` # StreamEventTextStream ```ts type StreamEventTextStream = ZodObject; ``` Event returned by the model when new output text is available to stream to the user. # StreamEventTextStream ```ts type StreamEventTextStream = object; ``` Event returned by the model when new output text is available to stream to the user. ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### delta [Section titled “delta”](#delta) ```ts delta: string; ``` ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` ### type [Section titled “type”](#type) ```ts type: "output_text_delta"; ``` # StreamRunOptions ```ts type StreamRunOptions = SharedRunOptions & object; ``` Options for runs that stream incremental events as the model responds. ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### stream [Section titled “stream”](#stream) ```ts stream: true; ``` Whether to stream the run. If true, the run will emit events as the model responds. ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | ------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------- | | `TContext` | `undefined` | | `TAgent` *extends* [`Agent`](/openai-agents-js/openai/agents/classes/agent/)<`any`, `any`> | [`Agent`](/openai-agents-js/openai/agents/classes/agent/)<`any`, `any`> | # SystemMessageItem ```ts type SystemMessageItem = object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### content [Section titled “content”](#content) ```ts content: string; ``` ### id? [Section titled “id?”](#id) ```ts optional id?: string; ``` ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` ### role [Section titled “role”](#role) ```ts role: "system"; ``` ### type? [Section titled “type?”](#type) ```ts optional type?: "message"; ``` # TextOutput ```ts type TextOutput = "text"; ``` Agent is expected to output text # Tool ```ts type Tool = | FunctionTool | ComputerTool | ShellTool | ApplyPatchTool | HostedTool; ``` A tool that can be called by the model. ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | Description | | -------------- | ------------ | ------------------------------ | | `Context` | `unknown` | The context passed to the tool | # ToolCallOutputContent ```ts type ToolCallOutputContent = ZodDiscriminatedUnion; ``` # ToolCallOutputContent ```ts type ToolCallOutputContent = | { providerData?: Record; text: string; type: "text"; } | { detail?: string & object | "low" | "high" | "auto"; image?: | string | { data: string | Uint8Array; mediaType?: string; } | { url: string; } | { fileId: string; }; providerData?: Record; type: "image"; } | { file: | string | { data: string | Uint8Array; filename: string; mediaType: string; } | { filename?: string; url: string; } | { filename?: string; id: string; }; providerData?: Record; type: "file"; }; ``` # ToolCallStructuredOutput ```ts type ToolCallStructuredOutput = ZodDiscriminatedUnion; ``` # ToolCallStructuredOutput ```ts type ToolCallStructuredOutput = | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; }; ``` # ToolEnabledFunction ```ts type ToolEnabledFunction = (runContext, agent) => Promise; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | -------------------------------------------------------------------------------- | | `Context` | [`UnknownContext`](/openai-agents-js/openai/agents/type-aliases/unknowncontext/) | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ------------ | ------------------------------------------------------------------------------ | | `runContext` | [`RunContext`](/openai-agents-js/openai/agents/classes/runcontext/)<`Context`> | | `agent` | [`Agent`](/openai-agents-js/openai/agents/classes/agent/)<`any`, `any`> | ## Returns [Section titled “Returns”](#returns) `Promise`<`boolean`> # ToolErrorFormatter ```ts type ToolErrorFormatter = (args) => Promise | string | undefined; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | ------------ | | `TContext` | `unknown` | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ------------------------------------------------------------------------------------------------------------ | | `args` | [`ToolErrorFormatterArgs`](/openai-agents-js/openai/agents/type-aliases/toolerrorformatterargs/)<`TContext`> | ## Returns [Section titled “Returns”](#returns) `Promise`<`string` | `undefined`> | `string` | `undefined` # ToolErrorFormatterArgs ```ts type ToolErrorFormatterArgs = object; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | --------------------------------------- | --------------------- | | `TContext` | `unknown` | | `TKind` *extends* `"approval_rejected"` | `"approval_rejected"` | ## Properties [Section titled “Properties”](#properties) ### callId [Section titled “callId”](#callid) ```ts callId: string; ``` The unique tool call identifier. *** ### defaultMessage [Section titled “defaultMessage”](#defaultmessage) ```ts defaultMessage: string; ``` The SDK’s default message for this error kind. *** ### kind [Section titled “kind”](#kind) ```ts kind: TKind; ``` The category of tool error being formatted. *** ### runContext [Section titled “runContext”](#runcontext) ```ts runContext: RunContext; ``` The active run context for the current execution. *** ### toolName [Section titled “toolName”](#toolname) ```ts toolName: string; ``` The name of the tool that produced the error. *** ### toolType [Section titled “toolType”](#tooltype) ```ts toolType: "function" | "computer" | "shell" | "apply_patch"; ``` The tool runtime that produced the error. # ToolExecuteArgument ```ts type ToolExecuteArgument = TParameters extends ZodObjectLike ? ZodInfer : TParameters extends JsonObjectSchema ? unknown : string; ``` The arguments to a tool. The type of the arguments are derived from the parameters passed to the tool definition. If the parameters are passed as a JSON schema the type is `unknown`. For Zod schemas it will match the inferred Zod type. Otherwise the type is `string` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | ------------------------------------------------------------------------------------------------------------------ | | `TParameters` *extends* [`ToolInputParameters`](/openai-agents-js/openai/agents/type-aliases/toolinputparameters/) | # ToolExecutionConfig ```ts type ToolExecutionConfig = object; ``` SDK-side execution settings for local tool calls. ## Properties [Section titled “Properties”](#properties) ### maxFunctionToolConcurrency? [Section titled “maxFunctionToolConcurrency?”](#maxfunctiontoolconcurrency) ```ts optional maxFunctionToolConcurrency?: number | null; ``` Maximum number of local function tool calls to execute concurrently. Set to `null` or leave unset to start all function tool calls emitted in a turn. This does not change provider-side `parallelToolCalls` behavior. # ToolGuardrailBehavior ```ts type ToolGuardrailBehavior = | { type: "allow"; } | { message: string; type: "rejectContent"; } | { type: "throwException"; }; ``` The action a tool guardrail should take after evaluation. * `allow`: proceed to the next guardrail or tool execution/output handling. * `rejectContent`: treat the guardrail as rejecting the call/output and short‑circuit with a message. * `throwException`: escalate immediately as a tripwire to fail fast and surface diagnostics. # ToolInputGuardrailFunction ```ts type ToolInputGuardrailFunction = (data) => Promise; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | -------------------------------------------------------------------------------- | | `TContext` | [`UnknownContext`](/openai-agents-js/openai/agents/type-aliases/unknowncontext/) | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ---------------------------------------------------------------------------------------------------------- | | `data` | [`ToolInputGuardrailData`](/openai-agents-js/openai/agents/interfaces/toolinputguardraildata/)<`TContext`> | ## Returns [Section titled “Returns”](#returns) `Promise`<[`ToolGuardrailFunctionOutput`](/openai-agents-js/openai/agents/interfaces/toolguardrailfunctionoutput/)> # ToolInputParameters ```ts type ToolInputParameters = undefined | ZodObjectLike | JsonObjectSchema; ``` The parameters of a tool. This can be a Zod schema, a JSON schema or undefined. If a Zod schema is provided, the arguments to the tool will automatically be parsed and validated against the schema. If a JSON schema is provided, the arguments to the tool will be passed as is. If undefined is provided, the arguments to the tool will be passed as a string. # ToolNamespaceOptions ```ts type ToolNamespaceOptions = object; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | ------------------------------------------------ | ----------------------------- | | `TTools` *extends* readonly `AnyFunctionTool`\[] | readonly `AnyFunctionTool`\[] | ## Properties [Section titled “Properties”](#properties) ### description [Section titled “description”](#description) ```ts description: string; ``` Description shared by all tools in the namespace. *** ### name [Section titled “name”](#name) ```ts name: string; ``` The namespace name to expose to the model. *** ### tools [Section titled “tools”](#tools) ```ts tools: TTools; ``` Function tools to attach to the namespace. # ToolOptions ```ts type ToolOptions = | StrictToolOptions, Context> | NonStrictToolOptions, Context>; ``` The options for a tool. ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | Description | | ------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------- | -------------------------- | | `TParameters` *extends* [`ToolInputParameters`](/openai-agents-js/openai/agents/type-aliases/toolinputparameters/) | ‐ | The parameters of the tool | | `Context` | [`UnknownContext`](/openai-agents-js/openai/agents/type-aliases/unknowncontext/) | The context of the tool | # ToolOptionsWithGuardrails ```ts type ToolOptionsWithGuardrails = ToolOptions; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | ------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------- | | `TParameters` *extends* [`ToolInputParameters`](/openai-agents-js/openai/agents/type-aliases/toolinputparameters/) | ‐ | | `Context` | [`UnknownContext`](/openai-agents-js/openai/agents/type-aliases/unknowncontext/) | # ToolOutputFileContent ```ts type ToolOutputFileContent = ZodObject; ``` # ToolOutputFileContent ```ts type ToolOutputFileContent = object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### file [Section titled “file”](#file) ```ts file: | string | { data: string | Uint8Array; filename: string; mediaType: string; } | { filename?: string; url: string; } | { filename?: string; id: string; }; ``` ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` ### type [Section titled “type”](#type) ```ts type: "file"; ``` # ToolOutputGuardrailFunction ```ts type ToolOutputGuardrailFunction = (data) => Promise; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | -------------------------------------------------------------------------------- | | `TContext` | [`UnknownContext`](/openai-agents-js/openai/agents/type-aliases/unknowncontext/) | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ------------------------------------------------------------------------------------------------------------ | | `data` | [`ToolOutputGuardrailData`](/openai-agents-js/openai/agents/interfaces/tooloutputguardraildata/)<`TContext`> | ## Returns [Section titled “Returns”](#returns) `Promise`<[`ToolGuardrailFunctionOutput`](/openai-agents-js/openai/agents/interfaces/toolguardrailfunctionoutput/)> # ToolOutputImage ```ts type ToolOutputImage = ZodObject; ``` # ToolOutputImage ```ts type ToolOutputImage = object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### detail? [Section titled “detail?”](#detail) ```ts optional detail?: string & object | "low" | "high" | "auto"; ``` ### image? [Section titled “image?”](#image) ```ts optional image?: | string | { data: string | Uint8Array; mediaType?: string; } | { url: string; } | { fileId: string; }; ``` ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` ### type [Section titled “type”](#type) ```ts type: "image"; ``` # ToolOutputText ```ts type ToolOutputText = ZodObject; ``` # ToolOutputText ```ts type ToolOutputText = object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` ### text [Section titled “text”](#text) ```ts text: string; ``` ### type [Section titled “type”](#type) ```ts type: "text"; ``` # ToolReference ```ts type ToolReference = ZodObject; ``` # ToolReference ```ts type ToolReference = object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### functionName [Section titled “functionName”](#functionname) ```ts functionName: string; ``` ### namespace? [Section titled “namespace?”](#namespace) ```ts optional namespace?: string; ``` ### type [Section titled “type”](#type) ```ts type: "tool_reference"; ``` # ToolSearchCallArguments ```ts type ToolSearchCallArguments = ZodUnknown; ``` Tool search call arguments are provider-defined. Hosted tool search uses `{ paths, query }`, while client-executed tool search can use a custom schema. # ToolSearchCallArguments ```ts type ToolSearchCallArguments = unknown; ``` Tool search call arguments are provider-defined. Hosted tool search uses `{ paths, query }`, while client-executed tool search can use a custom schema. # ToolSearchCallItem ```ts type ToolSearchCallItem = ZodObject; ``` # ToolSearchCallItem ```ts type ToolSearchCallItem = object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### arguments [Section titled “arguments”](#arguments) ```ts arguments: unknown; ``` ### call\_id? [Section titled “call\_id?”](#call_id) ```ts optional call_id?: string | null; ``` ### callId? [Section titled “callId?”](#callid) ```ts optional callId?: string | null; ``` ### execution? [Section titled “execution?”](#execution) ```ts optional execution?: "client" | "server"; ``` ### id? [Section titled “id?”](#id) ```ts optional id?: string; ``` ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` ### status? [Section titled “status?”](#status) ```ts optional status?: string; ``` ### type [Section titled “type”](#type) ```ts type: "tool_search_call"; ``` # ToolSearchOutputItem ```ts type ToolSearchOutputItem = ZodObject; ``` # ToolSearchOutputItem ```ts type ToolSearchOutputItem = object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### call\_id? [Section titled “call\_id?”](#call_id) ```ts optional call_id?: string | null; ``` ### callId? [Section titled “callId?”](#callid) ```ts optional callId?: string | null; ``` ### execution? [Section titled “execution?”](#execution) ```ts optional execution?: "client" | "server"; ``` ### id? [Section titled “id?”](#id) ```ts optional id?: string; ``` ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` ### status? [Section titled “status?”](#status) ```ts optional status?: string; ``` ### tools [Section titled “tools”](#tools) ```ts tools: Record[]; ``` ### type [Section titled “type”](#type) ```ts type: "tool_search_output"; ``` # ToolSearchOutputTool ```ts type ToolSearchOutputTool = ZodRecord; ``` Tool search outputs may contain tool references or concrete tool definitions. Preserve the payload as returned so stateless continuation can replay it losslessly. # ToolSearchOutputTool ```ts type ToolSearchOutputTool = Record; ``` Tool search outputs may contain tool references or concrete tool definitions. Preserve the payload as returned so stateless continuation can replay it losslessly. # ToolSearchTool ```ts type ToolSearchTool = object; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | ------------ | | `Context` | `unknown` | ## Properties [Section titled “Properties”](#properties) ### description? [Section titled “description?”](#description) ```ts optional description?: string | null; ``` *** ### execute? [Section titled “execute?”](#execute) ```ts optional execute?: ClientToolSearchExecutor; ``` *** ### execution? [Section titled “execution?”](#execution) ```ts optional execution?: OpenAI.Responses.ToolSearchTool["execution"]; ``` *** ### name? [Section titled “name?”](#name) ```ts optional name?: "tool_search"; ``` *** ### parameters? [Section titled “parameters?”](#parameters) ```ts optional parameters?: unknown | null; ``` *** ### type [Section titled “type”](#type) ```ts type: "tool_search"; ``` # ToolsToFinalOutputResult ```ts type ToolsToFinalOutputResult = | { isFinalOutput: false; isInterrupted: undefined; } | { interruptions: RunToolApprovalItem[]; isFinalOutput: false; isInterrupted: true; } | { finalOutput: string; isFinalOutput: true; isInterrupted: undefined; }; ``` ## Union Members [Section titled “Union Members”](#union-members) ### Type Literal [Section titled “Type Literal”](#type-literal) ```ts { isFinalOutput: false; isInterrupted: undefined; } ``` #### isFinalOutput [Section titled “isFinalOutput”](#isfinaloutput) ```ts isFinalOutput: false; ``` Whether this is the final output. If `false`, the LLM will run again and receive the tool call output #### isInterrupted [Section titled “isInterrupted”](#isinterrupted) ```ts isInterrupted: undefined; ``` Whether the agent was interrupted by a tool approval. If `true`, the LLM will run again and receive the tool call output *** ### Type Literal [Section titled “Type Literal”](#type-literal-1) ```ts { interruptions: RunToolApprovalItem[]; isFinalOutput: false; isInterrupted: true; } ``` #### interruptions [Section titled “interruptions”](#interruptions) ```ts interruptions: RunToolApprovalItem[]; ``` #### isFinalOutput [Section titled “isFinalOutput”](#isfinaloutput-1) ```ts isFinalOutput: false; ``` #### isInterrupted [Section titled “isInterrupted”](#isinterrupted-1) ```ts isInterrupted: true; ``` Whether the agent was interrupted by a tool approval. If `true`, the LLM will run again and receive the tool call output *** ### Type Literal [Section titled “Type Literal”](#type-literal-2) ```ts { finalOutput: string; isFinalOutput: true; isInterrupted: undefined; } ``` #### finalOutput [Section titled “finalOutput”](#finaloutput) ```ts finalOutput: string; ``` The final output. Can be undefined if `isFinalOutput` is `false`, otherwise it must be a string that will be processed based on the `outputType` of the agent. #### isFinalOutput [Section titled “isFinalOutput”](#isfinaloutput-2) ```ts isFinalOutput: true; ``` Whether this is the final output. If `false`, the LLM will run again and receive the tool call output #### isInterrupted [Section titled “isInterrupted”](#isinterrupted-2) ```ts isInterrupted: undefined; ``` Whether the agent was interrupted by a tool approval. If `true`, the LLM will run again and receive the tool call output # ToolTimeoutErrorFunction ```ts type ToolTimeoutErrorFunction = (context, error) => Promise | string; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | Default type | | -------------- | -------------------------------------------------------------------------------- | | `Context` | [`UnknownContext`](/openai-agents-js/openai/agents/type-aliases/unknowncontext/) | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ------------------------------------------------------------------------------- | | `context` | [`RunContext`](/openai-agents-js/openai/agents/classes/runcontext/)<`Context`> | | `error` | [`ToolTimeoutError`](/openai-agents-js/openai/agents/classes/tooltimeouterror/) | ## Returns [Section titled “Returns”](#returns) `Promise`<`string`> | `string` # ToolToFinalOutputFunction ```ts type ToolToFinalOutputFunction = (context, toolResults) => | ToolsToFinalOutputResult | Promise; ``` A function that takes a run context and a list of tool results and returns a `ToolsToFinalOutputResult`. ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ------------- | ------------------------------------------------------------------------------------------- | | `context` | [`RunContext`](/openai-agents-js/openai/agents/classes/runcontext/) | | `toolResults` | [`FunctionToolResult`](/openai-agents-js/openai/agents/type-aliases/functiontoolresult/)\[] | ## Returns [Section titled “Returns”](#returns) \| [`ToolsToFinalOutputResult`](/openai-agents-js/openai/agents/type-aliases/toolstofinaloutputresult/) | `Promise`<[`ToolsToFinalOutputResult`](/openai-agents-js/openai/agents/type-aliases/toolstofinaloutputresult/)> # ToolUseBehavior ```ts type ToolUseBehavior = | ToolUseBehaviorFlags | { stopAtToolNames: string[]; } | ToolToFinalOutputFunction; ``` The behavior of the agent when a tool is called. ## Union Members [Section titled “Union Members”](#union-members) [`ToolUseBehaviorFlags`](/openai-agents-js/openai/agents/type-aliases/toolusebehaviorflags/) *** ### Type Literal [Section titled “Type Literal”](#type-literal) ```ts { stopAtToolNames: string[]; } ``` #### stopAtToolNames [Section titled “stopAtToolNames”](#stopattoolnames) ```ts stopAtToolNames: string[]; ``` List of tool names that will stop the agent from running further. The final output will be the output of the first tool in the list that was called. *** [`ToolToFinalOutputFunction`](/openai-agents-js/openai/agents/type-aliases/tooltofinaloutputfunction/) # ToolUseBehaviorFlags ```ts type ToolUseBehaviorFlags = "run_llm_again" | "stop_on_first_tool"; ``` # TracingConfig ```ts type TracingConfig = object; ``` ## Properties [Section titled “Properties”](#properties) ### apiKey? [Section titled “apiKey?”](#apikey) ```ts optional apiKey?: string; ``` # TranscriptionSpanData ```ts type TranscriptionSpanData = SpanDataBase & object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### input [Section titled “input”](#input) ```ts input: object; ``` #### input.data [Section titled “input.data”](#inputdata) ```ts data: string; ``` #### input.format [Section titled “input.format”](#inputformat) ```ts format: "pcm" | string & object; ``` ### model? [Section titled “model?”](#model) ```ts optional model?: string; ``` ### model\_config? [Section titled “model\_config?”](#model_config) ```ts optional model_config?: Record; ``` ### output? [Section titled “output?”](#output) ```ts optional output?: string; ``` ### type [Section titled “type”](#type) ```ts type: "transcription"; ``` # UnknownContext ```ts type UnknownContext = unknown; ``` Context that is being passed around as part of the session is unknown # UnknownItem ```ts type UnknownItem = ZodObject; ``` This is a catch all for items that are not part of the protocol. For example, a model might return an item that is not part of the protocol using this type. In that case everything returned from the model should be passed in the `providerData` field. This enables new features to be added to be added by a model provider without breaking the protocol. # UnknownItem ```ts type UnknownItem = object; ``` This is a catch all for items that are not part of the protocol. For example, a model might return an item that is not part of the protocol using this type. In that case everything returned from the model should be passed in the `providerData` field. This enables new features to be added to be added by a model provider without breaking the protocol. ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### id? [Section titled “id?”](#id) ```ts optional id?: string; ``` ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` ### type [Section titled “type”](#type) ```ts type: "unknown"; ``` # UserMessageItem ```ts type UserMessageItem = ZodObject; ``` # UserMessageItem ```ts type UserMessageItem = object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### content [Section titled “content”](#content) ```ts content: | string | ( | { providerData?: Record; text: string; type: "input_text"; } | { detail?: string; image?: | string | { id: string; }; providerData?: Record; type: "input_image"; } | { file?: | string | { id: string; } | { url: string; }; filename?: string; providerData?: Record; type: "input_file"; } | { audio: | string | { id: string; }; format?: string | null; providerData?: Record; transcript?: string | null; type: "audio"; })[]; ``` ### id? [Section titled “id?”](#id) ```ts optional id?: string; ``` ### providerData? [Section titled “providerData?”](#providerdata) ```ts optional providerData?: Record; ``` ### role [Section titled “role”](#role) ```ts role: "user"; ``` ### type? [Section titled “type?”](#type) ```ts optional type?: "message"; ``` # OPENAI_CHAT_COMPLETIONS_RAW_MODEL_EVENT_SOURCE ```ts const OPENAI_CHAT_COMPLETIONS_RAW_MODEL_EVENT_SOURCE: "openai-chat-completions" = "openai-chat-completions"; ``` # OPENAI_DEFAULT_MODEL_ENV_VARIABLE_NAME ```ts const OPENAI_DEFAULT_MODEL_ENV_VARIABLE_NAME: "OPENAI_DEFAULT_MODEL" = "OPENAI_DEFAULT_MODEL"; ``` # OPENAI_RESPONSES_RAW_MODEL_EVENT_SOURCE ```ts const OPENAI_RESPONSES_RAW_MODEL_EVENT_SOURCE: "openai-responses" = "openai-responses"; ``` # retryPolicies ```ts const retryPolicies: object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### all [Section titled “all”](#all) ```ts readonly all: (...policies) => RetryPolicy; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ----------- | ----------------------------------------------------------------------------- | | …`policies` | [`RetryPolicy`](/openai-agents-js/openai/agents/type-aliases/retrypolicy/)\[] | #### Returns [Section titled “Returns”](#returns) [`RetryPolicy`](/openai-agents-js/openai/agents/type-aliases/retrypolicy/) ### any [Section titled “any”](#any) ```ts readonly any: (...policies) => RetryPolicy; ``` #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | ----------- | ----------------------------------------------------------------------------- | | …`policies` | [`RetryPolicy`](/openai-agents-js/openai/agents/type-aliases/retrypolicy/)\[] | #### Returns [Section titled “Returns”](#returns-1) [`RetryPolicy`](/openai-agents-js/openai/agents/type-aliases/retrypolicy/) ### httpStatus [Section titled “httpStatus”](#httpstatus) ```ts readonly httpStatus: (statuses) => RetryPolicy; ``` #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | ---------- | ----------- | | `statuses` | `number`\[] | #### Returns [Section titled “Returns”](#returns-2) [`RetryPolicy`](/openai-agents-js/openai/agents/type-aliases/retrypolicy/) ### networkError [Section titled “networkError”](#networkerror) ```ts readonly networkError: () => RetryPolicy; ``` #### Returns [Section titled “Returns”](#returns-3) [`RetryPolicy`](/openai-agents-js/openai/agents/type-aliases/retrypolicy/) ### never [Section titled “never”](#never) ```ts readonly never: () => RetryPolicy; ``` #### Returns [Section titled “Returns”](#returns-4) [`RetryPolicy`](/openai-agents-js/openai/agents/type-aliases/retrypolicy/) ### providerSuggested [Section titled “providerSuggested”](#providersuggested) ```ts readonly providerSuggested: () => RetryPolicy; ``` #### Returns [Section titled “Returns”](#returns-5) [`RetryPolicy`](/openai-agents-js/openai/agents/type-aliases/retrypolicy/) ### retryAfter [Section titled “retryAfter”](#retryafter) ```ts readonly retryAfter: () => RetryPolicy; ``` #### Returns [Section titled “Returns”](#returns-6) [`RetryPolicy`](/openai-agents-js/openai/agents/type-aliases/retrypolicy/) # RuntimeEventEmitter ```ts RuntimeEventEmitter: any; ``` # ToolGuardrailFunctionOutputFactory ```ts const ToolGuardrailFunctionOutputFactory: object; ``` ## Type Declaration [Section titled “Type Declaration”](#type-declaration) ### allow() [Section titled “allow()”](#allow) ```ts allow(outputInfo?): ToolGuardrailFunctionOutput; ``` #### Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ------------- | ----- | | `outputInfo?` | `any` | #### Returns [Section titled “Returns”](#returns) [`ToolGuardrailFunctionOutput`](/openai-agents-js/openai/agents/interfaces/toolguardrailfunctionoutput/) ### rejectContent() [Section titled “rejectContent()”](#rejectcontent) ```ts rejectContent(message, outputInfo?): ToolGuardrailFunctionOutput; ``` #### Parameters [Section titled “Parameters”](#parameters-1) | Parameter | Type | | ------------- | -------- | | `message` | `string` | | `outputInfo?` | `any` | #### Returns [Section titled “Returns”](#returns-1) [`ToolGuardrailFunctionOutput`](/openai-agents-js/openai/agents/interfaces/toolguardrailfunctionoutput/) ### throwException() [Section titled “throwException()”](#throwexception) ```ts throwException(outputInfo?): ToolGuardrailFunctionOutput; ``` #### Parameters [Section titled “Parameters”](#parameters-2) | Parameter | Type | | ------------- | ----- | | `outputInfo?` | `any` | #### Returns [Section titled “Returns”](#returns-2) [`ToolGuardrailFunctionOutput`](/openai-agents-js/openai/agents/interfaces/toolguardrailfunctionoutput/) # withAgentSpan ```ts const withAgentSpan: (fn, options?, parent?) => Promise; ``` Create a new agent span and automatically start and end it. ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | -------------- | | `TOutput` | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ---------- | ------------------------------------------------------------------------------------------------------------------------------ | | `fn` | (`span`) => `Promise`<`TOutput`> | | `options?` | `DeepPartial`<`CreateSpanOptions`<[`AgentSpanData`](/openai-agents-js/openai/agents/type-aliases/agentspandata/)>> | | `parent?` | \| [`Span`](/openai-agents-js/openai/agents/classes/span/)<`any`> \| [`Trace`](/openai-agents-js/openai/agents/classes/trace/) | ## Returns [Section titled “Returns”](#returns) `Promise`<`TOutput`> # withCustomSpan ```ts const withCustomSpan: (fn, options, parent?) => Promise; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | -------------- | | `TOutput` | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ------------------------------------------------------------------------------------------------------------------------------- | | `fn` | (`span`) => `Promise`<`TOutput`> | | `options` | `DeepPartial`<`CreateSpanOptions`<[`CustomSpanData`](/openai-agents-js/openai/agents/type-aliases/customspandata/)>> & `object` | | `parent?` | \| [`Span`](/openai-agents-js/openai/agents/classes/span/)<`any`> \| [`Trace`](/openai-agents-js/openai/agents/classes/trace/) | ## Returns [Section titled “Returns”](#returns) `Promise`<`TOutput`> # withFunctionSpan ```ts const withFunctionSpan: (fn, options, parent?) => Promise; ``` Create a new function span and automatically start and end it. ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | -------------- | | `TOutput` | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ----------------------------------------------------------------------------------------------------------------------------------- | | `fn` | (`span`) => `Promise`<`TOutput`> | | `options` | `DeepPartial`<`CreateSpanOptions`<[`FunctionSpanData`](/openai-agents-js/openai/agents/type-aliases/functionspandata/)>> & `object` | | `parent?` | \| [`Span`](/openai-agents-js/openai/agents/classes/span/)<`any`> \| [`Trace`](/openai-agents-js/openai/agents/classes/trace/) | ## Returns [Section titled “Returns”](#returns) `Promise`<`TOutput`> # withGenerationSpan ```ts const withGenerationSpan: (fn, options?, parent?) => Promise; ``` Automatically create a generation span, run fn and close the span ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | -------------- | | `TOutput` | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ---------- | ------------------------------------------------------------------------------------------------------------------------------ | | `fn` | (`span`) => `Promise`<`TOutput`> | | `options?` | `DeepPartial`<`CreateSpanOptions`<[`GenerationSpanData`](/openai-agents-js/openai/agents/type-aliases/generationspandata/)>> | | `parent?` | \| [`Span`](/openai-agents-js/openai/agents/classes/span/)<`any`> \| [`Trace`](/openai-agents-js/openai/agents/classes/trace/) | ## Returns [Section titled “Returns”](#returns) `Promise`<`TOutput`> # withGuardrailSpan ```ts const withGuardrailSpan: (fn, options, parent?) => Promise; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | -------------- | | `TOutput` | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ------------------------------------------------------------------------------------------------------------------------------------- | | `fn` | (`span`) => `Promise`<`TOutput`> | | `options` | `DeepPartial`<`CreateSpanOptions`<[`GuardrailSpanData`](/openai-agents-js/openai/agents/type-aliases/guardrailspandata/)>> & `object` | | `parent?` | \| [`Span`](/openai-agents-js/openai/agents/classes/span/)<`any`> \| [`Trace`](/openai-agents-js/openai/agents/classes/trace/) | ## Returns [Section titled “Returns”](#returns) `Promise`<`TOutput`> # withHandoffSpan ```ts const withHandoffSpan: (fn, options?, parent?) => Promise; ``` Create a new handoff span and automatically start and end it. ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | -------------- | | `TOutput` | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ---------- | ------------------------------------------------------------------------------------------------------------------------------ | | `fn` | (`span`) => `Promise`<`TOutput`> | | `options?` | `DeepPartial`<`CreateSpanOptions`<[`HandoffSpanData`](/openai-agents-js/openai/agents/type-aliases/handoffspandata/)>> | | `parent?` | \| [`Span`](/openai-agents-js/openai/agents/classes/span/)<`any`> \| [`Trace`](/openai-agents-js/openai/agents/classes/trace/) | ## Returns [Section titled “Returns”](#returns) `Promise`<`TOutput`> # withMCPListToolsSpan ```ts const withMCPListToolsSpan: (fn, options?, parent?) => Promise; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | -------------- | | `TOutput` | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ---------- | -------------------------------------------------------------------------------------------------------------------------------- | | `fn` | (`span`) => `Promise`<`TOutput`> | | `options?` | `DeepPartial`<`CreateSpanOptions`<[`MCPListToolsSpanData`](/openai-agents-js/openai/agents/type-aliases/mcplisttoolsspandata/)>> | | `parent?` | \| [`Span`](/openai-agents-js/openai/agents/classes/span/)<`any`> \| [`Trace`](/openai-agents-js/openai/agents/classes/trace/) | ## Returns [Section titled “Returns”](#returns) `Promise`<`TOutput`> # withResponseSpan ```ts const withResponseSpan: (fn, options?, parent?) => Promise; ``` Create a new response span and automatically start and end it. This span captures the details of a model response, primarily the response identifier. If you need to capture detailed generation information such as input/output messages, model configuration, or usage data, use `generationSpan()` instead. ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | -------------- | | `TOutput` | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ---------- | ------------------------------------------------------------------------------------------------------------------------------ | | `fn` | (`span`) => `Promise`<`TOutput`> | | `options?` | `DeepPartial`<`CreateSpanOptions`<[`ResponseSpanData`](/openai-agents-js/openai/agents/type-aliases/responsespandata/)>> | | `parent?` | \| [`Span`](/openai-agents-js/openai/agents/classes/span/)<`any`> \| [`Trace`](/openai-agents-js/openai/agents/classes/trace/) | ## Returns [Section titled “Returns”](#returns) `Promise`<`TOutput`> # withSpeechGroupSpan ```ts const withSpeechGroupSpan: (fn, options?, parent?) => Promise; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | -------------- | | `TOutput` | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | ---------- | ------------------------------------------------------------------------------------------------------------------------------ | | `fn` | (`span`) => `Promise`<`TOutput`> | | `options?` | `DeepPartial`<`CreateSpanOptions`<[`SpeechGroupSpanData`](/openai-agents-js/openai/agents/type-aliases/speechgroupspandata/)>> | | `parent?` | \| [`Span`](/openai-agents-js/openai/agents/classes/span/)<`any`> \| [`Trace`](/openai-agents-js/openai/agents/classes/trace/) | ## Returns [Section titled “Returns”](#returns) `Promise`<`TOutput`> # withSpeechSpan ```ts const withSpeechSpan: (fn, options, parent?) => Promise; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | -------------- | | `TOutput` | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | ------------------------------------------------------------------------------------------------------------------------------- | | `fn` | (`span`) => `Promise`<`TOutput`> | | `options` | `DeepPartial`<`CreateSpanOptions`<[`SpeechSpanData`](/openai-agents-js/openai/agents/type-aliases/speechspandata/)>> & `object` | | `parent?` | \| [`Span`](/openai-agents-js/openai/agents/classes/span/)<`any`> \| [`Trace`](/openai-agents-js/openai/agents/classes/trace/) | ## Returns [Section titled “Returns”](#returns) `Promise`<`TOutput`> # withTranscriptionSpan ```ts const withTranscriptionSpan: (fn, options, parent?) => Promise; ``` ## Type Parameters [Section titled “Type Parameters”](#type-parameters) | Type Parameter | | -------------- | | `TOutput` | ## Parameters [Section titled “Parameters”](#parameters) | Parameter | Type | | --------- | --------------------------------------------------------------------------------------------------------------------------------------------- | | `fn` | (`span`) => `Promise`<`TOutput`> | | `options` | `DeepPartial`<`CreateSpanOptions`<[`TranscriptionSpanData`](/openai-agents-js/openai/agents/type-aliases/transcriptionspandata/)>> & `object` | | `parent?` | \| [`Span`](/openai-agents-js/openai/agents/classes/span/)<`any`> \| [`Trace`](/openai-agents-js/openai/agents/classes/trace/) | ## Returns [Section titled “Returns”](#returns) `Promise`<`TOutput`>