Skip to main content

OpenAI Agents SDK PyPI

The OpenAI Agents SDK is a lightweight yet powerful framework for building multi-agent workflows. It is provider-agnostic, supporting the OpenAI Responses and Chat Completions APIs, as well as 100+ other LLMs.

Image of the Agents Tracing UI

[!NOTE] Looking for the JavaScript/TypeScript version? Check out Agents SDK JS/TS.

Core concepts:

  1. Agents: LLMs configured with instructions, tools, guardrails, and handoffs
  2. Sandbox agents: Agents preconfigured to work with a container to perform work over long time horizons.
  3. Realtime agents: Build powerful voice agents with gpt-realtime-2.1 and full agent features
  4. Voice agents: Build voice pipelines that combine speech-to-text, an agent workflow, and text-to-speech
  5. Agents as tools / Handoffs: Delegating to other agents for specific tasks
  6. Tools: Various Tools let agents take actions (functions, MCP, hosted tools)
  7. Guardrails: Configurable safety checks for input and output validation
  8. Human in the loop: Built-in mechanisms for involving humans across agent runs
  9. Sessions: Automatic conversation history management across agent runs
  10. Tracing: Built-in tracking of agent runs, allowing you to view, debug and optimize your workflows

Explore the examples directory to see the SDK in action, and read our documentation for more details.

Get started

To get started, set up your Python environment (Python 3.10 or newer required), and then install OpenAI Agents SDK package.

venv

python -m venv .venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate
pip install openai-agents

For voice support, install with the optional voice group: pip install 'openai-agents[voice]'. For Redis session support, install with the optional redis group: pip install 'openai-agents[redis]'.

uv

If you're familiar with uv, installing the package would be even easier:

uv init
uv add openai-agents

For voice support, install with the optional voice group: uv add 'openai-agents[voice]'. For Redis session support, install with the optional redis group: uv add 'openai-agents[redis]'.

Run your first agents

The SDK supports four primary ways to run agents. Set the OPENAI_API_KEY environment variable before running any of these examples.

Run a text agent

Use a text Agent for workflows that do not need a persistent realtime connection or a sandbox workspace.

from agents import Agent, Runner

agent = Agent(name="Assistant", instructions="You are a helpful assistant")

result = Runner.run_sync(agent, "Write a haiku about recursion in programming.")
print(result.final_output)

# Code within the code,
# Functions calling themselves,
# Infinite loop's dance.

(For Jupyter notebook users, see hello_world_jupyter.ipynb)

Run a sandbox agent

Use a SandboxAgent when the agent needs to inspect files, run commands, apply patches, or preserve workspace state across longer tasks.

This example uses UnixLocalSandboxClient, which is supported on macOS and Linux. On Windows, use DockerSandboxClient with the openai-agents[docker] extra or a hosted sandbox client instead; see Sandbox clients for setup details.

from agents import Runner
from agents.run import RunConfig
from agents.sandbox import Manifest, SandboxAgent, SandboxRunConfig
from agents.sandbox.entries import GitRepo
from agents.sandbox.sandboxes import UnixLocalSandboxClient

agent = SandboxAgent(
    name="Workspace Assistant",
    instructions="Inspect the sandbox workspace before answering.",
    default_manifest=Manifest(entries={"repo": GitRepo(repo="openai/openai-agents-python", ref="main")}),
)

result = Runner.run_sync(
    agent,
    "Inspect the repo README and summarize what this project does.",
    run_config=RunConfig(sandbox=SandboxRunConfig(client=UnixLocalSandboxClient())),
)
print(result.final_output)

Run a realtime agent

Use a RealtimeAgent for low-latency, server-side voice and multimodal experiences over WebSocket.

import asyncio
from agents.realtime import RealtimeAgent, RealtimeRunner

async def main() -> None:
    agent = RealtimeAgent(name="Assistant", instructions="You are a helpful voice assistant. Keep responses short.")
    runner = RealtimeRunner(starting_agent=agent)
    session = await runner.run()

    async with session:
        await session.send_message("Say hello in one short sentence.")
        async for event in session:
            if event.type == "audio":
                # Forward or play event.audio.data.
                pass
            elif event.type == "history_added":
                print(event.item)
            elif event.type == "agent_end":
                break

if __name__ == "__main__":
    asyncio.run(main())

Run a voice agent

Use a VoicePipeline to turn audio into text, run an agent workflow, and stream generated speech.

import asyncio

import numpy as np

from agents import Agent
from agents.voice import AudioInput, SingleAgentVoiceWorkflow, VoicePipeline


async def main() -> None:
    agent = Agent(name="Assistant", instructions="You are a helpful voice assistant.")
    pipeline = VoicePipeline(workflow=SingleAgentVoiceWorkflow(agent))
    audio_input = AudioInput(buffer=np.zeros(24000 * 3, dtype=np.int16))

    result = await pipeline.run(audio_input)
    async for event in result.stream():
        if event.type == "voice_stream_event_audio":
            # Forward or play event.data.
            pass


if __name__ == "__main__":
    asyncio.run(main())

Explore the examples directory to see the SDK in action, and read our documentation for more details.

Acknowledgements

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

This library has these optional dependencies:

We also rely on the following tools to manage the project:

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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

openai_agents-0.19.4.tar.gz (5.8 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

openai_agents-0.19.4-py3-none-any.whl (968.5 kB view details)

Uploaded Python 3

File details

Details for the file openai_agents-0.19.4.tar.gz.

File metadata

  • Download URL: openai_agents-0.19.4.tar.gz
  • Upload date:
  • Size: 5.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for openai_agents-0.19.4.tar.gz
Algorithm Hash digest
SHA256 fe21778ee1e8216c9cdb775fa86d11b08be68c0184e14023993088d3f812c0be
MD5 7ff6c77e3982de896e61d46d96d32683
BLAKE2b-256 ffeaa8cae2dadf798f369be5f9cb544a169f5f6aecc096a80f1a209dddc4c00f

See more details on using hashes here.

Provenance

The following attestation bundles were made for openai_agents-0.19.4.tar.gz:

Publisher: publish.yml on openai/openai-agents-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file openai_agents-0.19.4-py3-none-any.whl.

File metadata

  • Download URL: openai_agents-0.19.4-py3-none-any.whl
  • Upload date:
  • Size: 968.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for openai_agents-0.19.4-py3-none-any.whl
Algorithm Hash digest
SHA256 12e0372fae9698fe6f78e05aaeb4ccdb229602f7ef99b8195a7d68dc82869f51
MD5 b1650f04fe93d47bc489356fbf702170
BLAKE2b-256 90d898925e1e4888e58d7694ba71af2ba93b94540f481c45ee8b7f7be7e30fcd

See more details on using hashes here.

Provenance

The following attestation bundles were made for openai_agents-0.19.4-py3-none-any.whl:

Publisher: publish.yml on openai/openai-agents-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page