openai-agents-python/examples/codex/recipes
Mark Stuart 5839a96668
Clarify Python SDK APIs for alpha.8 (#6029)
* Clarify Python SDK APIs for alpha.8

* Move preview guides to a docs-only pull request

* Keep the web starter's application approval type

* Verify the native Realtime facade against its owner

---------

Co-authored-by: markstuart-oai <323302876+markstuart-oai@users.noreply.github.com>
2026-11-15 16:18:53 -08:00
..
fixtures chore: restore classic examples and organize example collections (#5566) 2026-11-06 11:43:21 -08:00
accepted-output.md docs: Clarify Python SDK setup, tool names, and output limits (#6014) 2026-11-14 21:47:20 -08:00
accepted_output.py Token budgets have been retaining usage across manual restore (#5851) 2026-11-11 21:20:33 -08:00
accepted_text.py feat: Logical send totals, text approval, and Decisions handoffs (#5891) 2026-11-12 11:16:43 -08:00
application_memory.py chore: restore classic examples and organize example collections (#5566) 2026-11-06 11:43:21 -08:00
concurrent_tools.py chore: restore classic examples and organize example collections (#5566) 2026-11-06 11:43:21 -08:00
decision_handoff.py feat: Logical send totals, text approval, and Decisions handoffs (#5891) 2026-11-12 11:16:43 -08:00
decisions_handoffs.py Clarify Python SDK APIs for alpha.8 (#6029) 2026-11-15 16:18:53 -08:00
decisions_routing.py Add native examples for accepted output, specialist routing, and tracing (#5816) 2026-11-11 10:28:01 -08:00
image_input.py fix(codex): preserve v1 handoff ownership and saved state (#5666) 2026-11-09 15:24:09 -08:00
inspect_requests.py chore: restore classic examples and organize example collections (#5566) 2026-11-06 11:43:21 -08:00
local_mcp.py chore: restore classic examples and organize example collections (#5566) 2026-11-06 11:43:21 -08:00
mcp_prompts.py feat: add native MCP prompt discovery and reads (#5604) 2026-11-07 20:19:44 -08:00
mcp_resources.py feat: expose native MCP resource pages and reads (#5597) 2026-11-07 15:48:08 -08:00
observed_transport_attempts.py docs: organize SDK guides around developer tasks (#5920) 2026-11-12 21:00:58 -08:00
oversized_mcp_output.py docs: organize SDK guides around developer tasks (#5920) 2026-11-12 21:00:58 -08:00
oversized_tool_output.py docs: organize SDK guides around developer tasks (#5920) 2026-11-12 21:00:58 -08:00
prepared_request.py chore: restore classic examples and organize example collections (#5566) 2026-11-06 11:43:21 -08:00
programmatic_tools.py chore: restore classic examples and organize example collections (#5566) 2026-11-06 11:43:21 -08:00
README.md docs: organize SDK guides around developer tasks (#5920) 2026-11-12 21:00:58 -08:00
retrieval.py chore: restore classic examples and organize example collections (#5566) 2026-11-06 11:43:21 -08:00
safe_effects.py chore: restore classic examples and organize example collections (#5566) 2026-11-06 11:43:21 -08:00
specialist_agents.py feat: Report native turn outcomes and preserve request budgets on restore (#5844) 2026-11-11 18:07:34 -08:00
typed_tools.py chore: restore classic examples and organize example collections (#5566) 2026-11-06 11:43:21 -08:00

Choose a task recipe

Use these recipes to test one application behavior at a time. Install the SDK preview wheel and use example files from the same release. Activate that Python environment and run commands from the source archive or checkout root. Entries marked development-only require a matching source build and example files from that checkout.

For example, run the typed-tools recipe without model credentials:

python -m examples.codex.recipes.typed_tools

Expect a JSON receipt for SKU synthetic with accepted equal to 2. The native engine executes the Python callback and validates its output. A local scripted peer chooses the tool calls and answer, so this run checks application wiring rather than model quality.

For scripted recipes, allow direct access to 127.0.0.1 or add it to your proxy bypass list. Live recipes require OPENAI_API_KEY and can incur model charges. Use synthetic inputs when inspecting requests or writing result artifacts.

Validate tools and control effects

For each file below, run python -m examples.codex.recipes.MODULE, replacing MODULE with the filename without .py.

Module Execution Expected result
typed_tools Scripted Coerces the input quantity to 2, records one order line, and prints its validated receipt.
inspect_requests Scripted Prints tool declarations, original and effective arguments, and the result after the application changes the limit from 3 to 2.
concurrent_tools Scripted Two overlapping Sessions share one quota unit. Assertions check one reservation and one full result.
safe_effects Scripted Repeats a synthetic write with the same key and checks that the injected in-memory writer records one effect.
oversized_tool_output Development-only, scripted Reduces large function results, retains full evidence in application data, and refuses an excessive row count. Prints measured request and evidence counts.
oversized_mcp_output Development-only, scripted, with a local MCP peer Keeps bounded summaries in history and full evidence in application memory. Checks rejection of an oversized summary. Requires aiohttp.
prepared_request Scripted Edits the next sampling request after a tool result while preserving the original tool validation and policies. Prints The record is allowed.
accepted_output Development-only, scripted Withholds rejected drafts and publishes only application-checked values in memory. See the accepted-output guide.

The fake writer in safe_effects deduplicates only inside one process. It does not supply durable idempotency. Likewise, scripted model replies still execute real Python callbacks; replace external writers before using scripted tests.

Add memory, retrieval, and specialists

Module Execution Expected result
application_memory Scripted Saves, recalls, and deletes one user-scoped fact across fresh Sessions. Removes its temporary SQLite database on exit.
specialist_agents Scripted Calls a separately configured Agent through a Python tool and returns its typed catalog summary.
decisions_routing Development-only, scripted Checks default and Decisions-based routing, permission changes, invalid choices, and timeouts across separate specialist Sessions. See the Decisions guide.
decisions_handoffs Development-only, scripted Offers one authorized native handoff before model submission and checks selection, denial, cancellation, and a model call to an unoffered target.
retrieval Live Searches a tenant-scoped synthetic corpus and validates that the answer cites only source IDs retrieved in this run.
image_input Live Creates an inline red PNG and prints a validated color and confidence. The expected dominant color is red.
programmatic_tools Live Uses model-generated JavaScript to aggregate Python tool results. The expected paper-sales total is 50. Prints tool-call metadata and recorded call items.

A separate specialist Session does not inherit native child tracking or isolation. The application supplies its tools, context, and permissions. Retrieval source checks establish source membership, not whether a source supports every claim in the answer.

Connect MCP servers and inspect transport retries

local_mcp.py launches the included stdio catalog server, asks a live model for the price of PAPER, and prints the answer. The synthetic catalog price is 5 dollars. The server uses only the standard library; the model request still requires credentials:

python -m examples.codex.recipes.local_mcp

mcp_resources.py and mcp_prompts.py use an existing trusted streamable HTTP MCP endpoint. They print server data without opening a model turn. Replace the endpoint, resource URI, and prompt name with values from your server:

python -m examples.codex.recipes.mcp_resources http://127.0.0.1:8000/mcp 'documents://catalog'
python -m examples.codex.recipes.mcp_prompts http://127.0.0.1:8000/mcp summarize --argument language=Python

These commands do not start an MCP server. The examples omit endpoint authentication; add your server's required headers in application code before connecting to a protected endpoint. Resource lists return individual pages. Prompt listing collects the supported bounded inventory. Neither operation adds its returned content to model context.

observed_transport_attempts.py wraps a borrowed OpenAI client's HTTP transport. This development-only recipe requires a matching source build. It also needs openai, httpx, and aiohttp from the matching contributor environment. Its local peer returns HTTP 503, then HTTP 200, without live credentials:

python -m examples.codex.recipes.observed_transport_attempts

Expect two transport entries, two peer receipts, one completed model response, and one adapter invocation. These counters describe different boundaries. A transport entry alone does not prove a socket write, service receipt, or billing event.