openai-agents-python/docs/sdk/index.md
Mark Stuart ba3fbbf400
docs: organize SDK guides around developer tasks (#5920)
* docs: organize SDK guides and clarify examples

* fix: correct native SDK type declarations

* test: update native SDK contract fixtures

* fix: normalize persisted agent profile transport settings

* test: reconcile inherited model settings API snapshot

* test: preserve executor coverage on Windows

---------

Co-authored-by: markstuart-oai <323302876+markstuart-oai@users.noreply.github.com>
2026-11-12 21:00:58 -08:00

3.7 KiB

Quickstart

Build an agent that calls a Python function and returns a greeting. You define its instructions and tools. The Agents SDK uses Codex to coordinate model requests and tool calls inside your application.

Before you begin

  1. Follow the installation guide to install a preview wheel and activate your Python environment.
  2. Create an OpenAI API key for the live example below.

These guides use the alpha.7 wheel as the installation baseline and mark features that require a newer development build. See releases and documentation when choosing examples or upgrading.

The example below needs an OpenAI API key and makes live model requests that can incur charges. To test with scripted responses and no API key, use the testing guide.

Run your first agent

1. Create the agent

Save this script as agent.py in your project directory. The @function_tool decorator makes greeting available to the model and describes its arguments from the Python type annotations.

import asyncio

from agents import Agent, function_tool


@function_tool
async def greeting(name: str) -> str:
    return f"Hello, {name}!"


async def main() -> None:
    agent = Agent(
        name="Assistant",
        instructions="Use greeting to greet the user.",
        tools=[greeting],
    )
    result = await agent.run("Greet Ada.")
    print(result.final_output)


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

2. Set your API key and run the script

Replace your-key with your OpenAI API key. In the same shell, with your Python environment activated, run:

export OPENAI_API_KEY="your-key"
python agent.py

On Windows PowerShell:

$env:OPENAI_API_KEY = "your-key"
python agent.py

3. Check the result

The script prints a greeting for Ada, such as Hello, Ada!. When the model requests the greeting tool, the SDK calls your Python function and returns its result to the model. The model chooses the final wording, so it can vary.

Importing agents or declaring the agent and tools does not start work. The agent.run() call opens a Session, waits for the result, and closes the Session. With the default in-memory storage, calling agent.run() again without a saved checkpoint starts an independent conversation.

Use agent.session() to keep history between messages or stream progress. In synchronous code, use agent.run_sync() outside an existing event loop. See core concepts for the relationship between Agent, Session, and Turn.

Choose your next task

Task Guide
Call Python code with application data Function tools and context
Connect a tool server MCP servers
Continue a conversation Conversations
Display progress as it arrives Streaming and events
Save a conversation and resume later Save and restore state
Return a validated Python value Structured output
Choose a model or supply credentials Models and authentication
Test without a model service Testing
Diagnose failures or set a timeout Troubleshooting

Find worked examples for images, retrieval, application memory, and specialist agents. Use the API reference to look up calls and defaults.

For an existing v0 application, start with the runtime comparison and migration guide.