Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/RELEASING.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,4 @@ Publish v1 alpha versions as GitHub Releases marked as prereleases. The `Codex r
1. Choose an unused `v1.X.Y-alpha.N` tag. Set the root `pyproject.toml` version to `1.X.YaN` and `native/codex/Cargo.toml` to `1.X.Y-alpha.N`. Update both lockfiles. Review the changes to confirm that only the two project versions changed.
2. Open `release/v1.X.Y-alpha.N` from this repository into `v1-alpha`. Wait for the regression suite, the v1 session checks, the four release builds and maintainer approval of the same PR head. Each build installs the optimized SDK wheel on CPython 3.10 and 3.14 and exercises an offline conversation.
3. Download the four `codex-<platform>-<commit>-<attempt>` artifacts from the successful run. Verify each SDK wheel against its `SHA256SUMS`. Keep all four wheels, a combined `SHA256SUMS` with one entry per wheel, the run URL and the four hash-pinned install commands from its summary.
4. After merge, verify that the release commit on `v1-alpha` has the same Git tree as the reviewed PR head. If it differs, prepare a fresh candidate. With publication approval, tag the verified commit and create a GitHub **prerelease**. Attach the four wheels and combined checksum file. Include the run URL, the four platform-specific install commands, and a short example using `from openai_agents import Agent, Runner` in the release notes. Confirm that the downloaded assets match the reviewed hashes.
4. After merge, verify that the release commit on `v1-alpha` has the same Git tree as the reviewed PR head. If it differs, prepare a fresh candidate. With publication approval, tag the verified commit and create a GitHub **prerelease**. Attach the four wheels and combined checksum file. Include the run URL, the four platform-specific install commands, and a short example from the [v1 quickstart](../docs/v1/quickstart.md#4-run-the-tutor) using `from openai_agents import Agent` and `await agent.run(prompt)` in the release notes. Confirm that the downloaded assets match the reviewed hashes.
14 changes: 7 additions & 7 deletions MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Keep your existing v0 dependency lock and [install v1](native/codex/README.md#in

To retain the earlier Python loop, move imports to `openai_agents.classic`. Realtime has its own namespace and uses Classic tools. Voice pipelines remain under Classic.

| Earlier import | v1 import |
| v0 import | v1 import |
| --- | --- |
| `from agents import Agent, Runner` | `from openai_agents.classic import Agent, Runner` |
| `from agents import function_tool` | `from openai_agents.classic import function_tool` |
Expand All @@ -25,7 +25,7 @@ To retain the earlier Python loop, move imports to `openai_agents.classic`. Real

Install the [optional dependencies](native/codex/README.md#install-optional-dependencies) for the features you use, such as `voice`, `any-llm`, or `litellm`. Importing the SDK alone does not install those dependencies.

The repository's historical v0 documentation, examples, and tests still use earlier imports in places. Apply this mapping to copied examples. If you used `agents.classic` from an earlier v1 build, replace that prefix with `openai_agents.classic`.
Apply this mapping to imports in examples you copy from the v0 documentation.

Check each import before replacing a prefix. An application can also have its own module named `agents`. Update dynamic imports and test patch targets, and check third-party libraries for dependencies on the old package path.

Expand All @@ -45,7 +45,7 @@ async def answer(model: str, prompt: str) -> str:

## Port a text turn to Codex

Import `Agent` and `Runner` from `openai_agents` to use Codex. These are the same classes exported by `openai_agents.codex`. If you used an earlier Codex build with `agents` imports, move its helpers to `openai_agents.codex` and check the current [session API](native/codex/README.md#run-and-resume-a-conversation).
Import `Agent` from `openai_agents`, omit `name`, and replace `await Runner.run(agent, prompt)` with `await agent.run(prompt)`. Both `Runner` and `Agent.name` are deprecated in the v1 Codex runtime.

If you use a Classic model adapter, review routing and credentials before you switch. Codex sends its own model requests.

Expand All @@ -55,19 +55,19 @@ Set `OPENAI_API_KEY` and `OPENAI_MODEL` in the v1 environment. Save this as `gui
import asyncio
import os

from openai_agents import Agent, Runner
from openai_agents import Agent


async def answer(model: str, prompt: str) -> str | None:
agent = Agent(name="Guide", model=model, instructions="Help plan a trip.")
result = await Runner.run(agent, prompt)
agent = Agent(model=model, instructions="Help plan a trip.")
result = await agent.run(prompt)
return result.output_text


print(asyncio.run(answer(os.environ["OPENAI_MODEL"], "Suggest a walk in Lisbon.")))
```

`await agent.run(prompt)` uses the same Codex API as `await Runner.run(agent, prompt)`. Read `output_text` for Codex and `final_output` for Classic. If Codex returns no final text, `output_text` is `None`.
Read `output_text` for Codex and `final_output` for Classic. If Codex returns no final text, `output_text` is `None`.

## Check what the workflow relies on

Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Build a Python agent powered by the **Codex harness**. Give your agent an [order
## Installation

1. Use your project's Python environment, or [create one](native/codex/README.md#create-an-environment).
2. Choose a v1 release from [GitHub Releases](https://github.com/openai/openai-agents-python/releases) whose example imports `openai_agents`.
2. Find the latest v1 release on [GitHub Releases](https://github.com/openai/openai-agents-python/releases).
3. Run the pip command for your platform from the release notes. The wheel includes the compiled Codex engine.
4. Set `OPENAI_API_KEY` and `OPENAI_MODEL` as shown below.

Expand Down Expand Up @@ -54,7 +54,7 @@ Save this order lookup as `orders.py`.
import asyncio
import os

from openai_agents import Agent, Runner
from openai_agents import Agent
from openai_agents.codex import function_tool


Expand All @@ -69,7 +69,7 @@ agent = Agent(
instructions="Use delivery_date to check the order before you answer.",
tools=[delivery_date],
)
result = asyncio.run(Runner.run(agent, "When will order A12 arrive?"))
result = asyncio.run(agent.run("When will order A12 arrive?"))
print(result.output_text)
```

Expand All @@ -86,6 +86,7 @@ The answer should report Friday as the delivery day.

## Next steps

- Use `agent.stream(prompt)` for live output or `agent.session()` for follow-up questions. Try the [quickstart examples](docs/v1/quickstart.md#stream-the-answer).
- Give an agent [access to files or commands](native/codex/README.md#choose-where-to-run-commands).
- Continue or resume a conversation with [sessions and checkpoints](native/codex/README.md#run-and-resume-a-conversation).

Expand Down
5 changes: 3 additions & 2 deletions docs/v1/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Save this order lookup as `orders.py`.
import asyncio
import os

from openai_agents import Agent, Runner
from openai_agents import Agent
from openai_agents.codex import function_tool


Expand All @@ -56,7 +56,7 @@ agent = Agent(
instructions="Use delivery_date to check the order before you answer.",
tools=[delivery_date],
)
result = asyncio.run(Runner.run(agent, "When will order A12 arrive?"))
result = asyncio.run(agent.run("When will order A12 arrive?"))
print(result.output_text)
```

Expand All @@ -73,6 +73,7 @@ Check that the answer reports Friday as the delivery day. To see each step, [fol

## Next steps

- [Stream the answer](quickstart.md#stream-the-answer) with `agent.stream(prompt)` or [ask a follow-up](quickstart.md#ask-a-follow-up) with `agent.session()`.
- Give an agent access to files or commands by choosing [where code runs](runtime.md#where-code-runs).
- Continue a conversation or resume it later with [sessions and checkpoints](runtime.md#what-survives-the-turn).
- For a v0 workflow, start with [Compare v0 and v1](migration.md). If it uses a Python model adapter such as LiteLLM, keep it on the supported **Classic** subpackage, `openai_agents.classic`, while you migrate.
Expand Down
23 changes: 10 additions & 13 deletions docs/v1/migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ Both versions use the `openai-agents` distribution name. The **import selects th

## The same tutor, side by side

Both examples use `Runner.run`. The import changes which code runs when you call it. Set `OPENAI_API_KEY` and `OPENAI_MODEL` in each environment as described in the [quickstart](quickstart.md#4-run-the-tutor).
In v1, import `Agent` from `openai_agents` and call `await tutor.run(q)`. Set `OPENAI_API_KEY` and `OPENAI_MODEL` in each environment as described in the [quickstart](quickstart.md#4-run-the-tutor).

<div class="grid" markdown>

```python title="v0 · Python" hl_lines="4 15"
```python title="v0 · Python" hl_lines="4 10 14 15"
import asyncio
import os

Expand All @@ -29,21 +29,18 @@ async def main():
asyncio.run(main())
```

```python title="v1 · Codex" hl_lines="4 15"
```python title="v1 · Codex" hl_lines="4 9 11 12"
import asyncio
import os

from openai_agents import Agent, Runner
from openai_agents import Agent


async def main():
model = os.environ["OPENAI_MODEL"]
tutor = Agent(
name="Tutor",
model=model,
)
tutor = Agent(model=model)
q = "Why was Rome built on hills?"
result = await Runner.run(tutor, q)
result = await tutor.run(q)
print(result.output_text)


Expand All @@ -58,10 +55,10 @@ Save either example as `tutor.py` and run `python tutor.py` in its environment.

| Task | Python loop (v0) | Codex runtime (v1 default) |
| --- | --- | --- |
| Define an agent | `Agent(name=...)` requires a name and can use a default model. | [`Agent(model=...)`](ref/codex/agent.md) requires a model ID. The name is optional. Instructions extend the Codex base instructions. |
| Run a turn | `await Runner.run(agent, prompt)` | The same call, or `await agent.run(prompt)`. |
| Read the answer | `result.final_output` can be text or a typed value. | `result.output_text` is text or `None`. `result.final_output` returns the same value. |
| Register a function | Use a Python-loop tool, such as `agents.function_tool`. | Use [`openai_agents.codex.function_tool`](ref/codex/tool.md). Register the function with the Codex agent. |
| Define an agent | `Agent(name=...)` requires a name and can use a default model. | Pass a model ID to [`Agent(model=...)`](ref/codex/agent.md) and omit the deprecated `name` argument. Codex appends `instructions` to its base instructions. |
| Run a turn | `await Runner.run(agent, prompt)` | Call `await agent.run(prompt)` and drop the `Runner` import. The Codex `Runner` is deprecated. |
| Read the answer | `result.final_output` can be text or a typed value. | `result.output_text` is text or `None`. |
| Register a function | Decorate the function with `agents.decorators.tool` or `agents.function_tool`. | Decorate it with [`openai_agents.codex.function_tool`](ref/codex/tool.md) and pass it in `Agent(tools=[...])`. |
| Stream a turn | `Runner.run_streamed(agent, prompt)`, then iterate over `result.stream_events()`. | `async with agent.stream(prompt) as events`, then iterate over `events`. Use `await events.get_final_result()` for the result. The event types differ. |
| Continue a conversation | Pass a session to `Runner.run` or reuse `result.to_input_list()`. | Open a [Codex session](ref/codex/session.md) for multiple turns, pass `state=result.state` to the next run, or resume by ID with Codex storage. |

Expand Down
32 changes: 28 additions & 4 deletions docs/v1/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ py -3 -m venv .venv

If you need v0 and v1 installed side by side, use separate environments. Both versions use the `openai-agents` distribution name, so installing v1 replaces v0 in that environment.

Open [GitHub Releases](https://github.com/openai/openai-agents-python/releases) and choose a v1 release whose examples import `openai_agents`. Earlier v1 releases use the old `agents` imports and cannot run this guide. If no compatible release exists, Linux x86-64 users can [build from source](#build-from-source), while other platforms need a matching release wheel.
Open the latest v1 release on [GitHub Releases](https://github.com/openai/openai-agents-python/releases). Linux x86-64 users can also [build from source](#build-from-source).

Use the wheel for the system running Python.

Expand Down Expand Up @@ -69,15 +69,15 @@ Save this as `tutor.py`.
import asyncio
import os

from openai_agents import Agent, Runner
from openai_agents import Agent


async def main():
tutor = Agent(
model=os.environ["OPENAI_MODEL"],
instructions="You answer history questions clearly and concisely.",
)
result = await Runner.run(tutor, "When did the Roman Empire fall?")
result = await tutor.run("When did the Roman Empire fall?")
print(result.output_text)


Expand All @@ -87,4 +87,28 @@ if __name__ == "__main__":

Run `python tutor.py`. The tutor makes a billable model request and prints its answer. Codex runs the loop locally and calls the model over the network. This example grants no shell or file tools.

Next, [give the agent a Python tool](runtime.md) or [compare the same call in v0 and v1](migration.md).
## Stream the answer

To print text as it arrives, add `from openai_agents.codex import TextDelta` to the imports in `tutor.py`. Replace the `tutor.run(...)` assignment and the `print(...)` line in `main()` with this block.

```python
async with tutor.stream("When did the Roman Empire fall?") as events:
async for event in events:
if isinstance(event, TextDelta):
print(event.delta, end="", flush=True)
print()
```

## Ask a follow-up

To give the tutor access to the first question and its answer during the second turn, keep a session open. Replace the two lines after the tutor definition in the original `main()` with this block.

```python
async with tutor.session() as session:
first = await session.run("When did the Western Roman Empire fall?")
print(first.output_text)
second = await session.run("Who was emperor at the time?")
print(second.output_text)
```

Next, [give the agent a Python tool](runtime.md), [save a conversation](runtime.md#what-survives-the-turn), or [compare the same call in v0 and v1](migration.md).
8 changes: 4 additions & 4 deletions docs/v1/runtime.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# How the Codex runtime works

The **Codex harness** runs the agent loop inside your Python process. In v1, `openai_agents.Runner` calls the Rust Codex core to send a request to the model. If the model requests a tool, the harness runs the tool and sends the result back to the model. This repeats until the turn ends.
The **Codex harness** runs the agent loop inside your Python process. When you call `await agent.run(prompt)`, the Rust Codex core sends a request to the model. If the model requests a tool, the harness runs the tool and sends the result back to the model. This repeats until the turn ends.

## Follow an order lookup through one turn

Expand All @@ -10,7 +10,7 @@ Suppose a customer asks when their order will arrive. Only your application know
import asyncio
import os

from openai_agents import Agent, Runner
from openai_agents import Agent
from openai_agents.codex import function_tool


Expand All @@ -26,7 +26,7 @@ async def main():
instructions="Use delivery_date to check the order before you answer.",
tools=[delivery_date],
)
result = await Runner.run(agent, "When will order A12 arrive?")
result = await agent.run("When will order A12 arrive?")
print(result.output_text)


Expand All @@ -36,7 +36,7 @@ if __name__ == "__main__":

When the model requests the lookup, the turn goes through four steps.

1. **Python starts the turn.** `Runner.run(agent, prompt)` passes the prompt, instructions, and tool definition through a Python binding (PyO3) to the Rust Codex engine in the same process. `agent.run(prompt)` takes the same path.
1. **Python starts the turn.** `agent.run(prompt)` passes the prompt, instructions, and tool definition through a Python binding (PyO3) to the Rust Codex engine in the same process.
2. **Codex calls the model.** The model sees the description and argument schema for `delivery_date`. It can request a call with `order_id="A12"`. The function body stays in your application.
3. **Python runs the tool.** The SDK dispatches the call to `delivery_date` on your worker. Codex adds the returned value, `Friday`, to the conversation and sends the next request. A turn can include several tool calls.
4. **Python receives the result.** When the model finishes, the [result](ref/codex/result.md) includes the reply, the items produced during the turn, usage, and a checkpoint. For a live UI, use `agent.stream(prompt)` to receive [events](ref/codex/events.md) as the turn progresses.
Expand Down
24 changes: 3 additions & 21 deletions examples/codex/tool_access.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,29 +78,11 @@ Discovery is eager and reads the server's tool metadata before applying the allo

## Load explicit project guidance

Choose trusted absolute paths for the project root, working directory, and optional user guidance. Review project files before treating their contents as instructions. The loader returns a `ProjectInstructions` snapshot containing `instructions`, `sources`, and hashes.
For an agent that already runs in a trusted workspace, place reviewed project guidance in `AGENTS.md`. Codex discovers the file when it opens the workspace. Passing its contents through `Agent.instructions` as well would duplicate the guidance.

```python
from pathlib import Path

from openai_agents import Agent
from openai_agents.codex.extensions.project_instructions import load_project_instructions


def project_agent(model: str, root: Path, cwd: Path, user_file: Path) -> Agent:
snapshot = load_project_instructions(
root=root,
cwd=cwd,
user_file=user_file,
filenames=("APP_GUIDE.md",),
max_bytes=32768,
)
return Agent(model=model, instructions=snapshot.instructions)
```

Place reviewed application guidance in `APP_GUIDE.md` under the selected root. The loader reads matching files from root to cwd, after the explicit user file. Imports remain disabled unless the application enables them and grants each imported file explicitly. Paths must not contain symlink components, and cwd must be under root.
For a run with `environment=None`, pass reviewed text directly to `Agent(model=model, instructions=trusted_text)`. Enabling a workspace also grants access to shell and file tools.

A workspace can independently discover `AGENTS.md` through the native engine. Passing the same file through `Agent.instructions` would duplicate it. The custom filename above avoids that duplication. The snapshot records what the loader read and does not attest to the engine's separate discovery settings.
If your application reads instructions from custom files, enforce its file access and size limits before passing the text to the agent.

## Handle structured gateway status

Expand Down
Loading
Loading