Skip to content

Commit 0b88565

Browse files
authored
docs: add codex tool document section (#2325)
1 parent 5c91b4e commit 0b88565

1 file changed

Lines changed: 40 additions & 1 deletion

File tree

docs/tools.md

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
# Tools
22

3-
Tools let agents take actions: things like fetching data, running code, calling external APIs, and even using a computer. The SDK supports four categories:
3+
Tools let agents take actions: things like fetching data, running code, calling external APIs, and even using a computer. The SDK supports five categories:
44

55
- Hosted OpenAI tools: run alongside the model on OpenAI servers.
66
- Local runtime tools: run in your environment (computer use, shell, apply patch).
77
- Function calling: wrap any Python function as a tool.
88
- Agents as tools: expose an agent as a callable tool without a full handoff.
9+
- Experimental: Codex tool: run workspace-scoped Codex tasks from a tool call.
910

1011
## Hosted tools
1112

@@ -464,6 +465,44 @@ Disabled tools are completely hidden from the LLM at runtime, making this useful
464465
- A/B testing different tool configurations
465466
- Dynamic tool filtering based on runtime state
466467

468+
## Experimental: Codex tool
469+
470+
The `codex_tool` wraps the Codex CLI so an agent can run workspace-scoped tasks (shell, file edits, MCP tools)
471+
during a tool call. This surface is experimental and may change.
472+
473+
```python
474+
from agents import Agent
475+
from agents.extensions.experimental.codex import ThreadOptions, codex_tool
476+
477+
agent = Agent(
478+
name="Codex Agent",
479+
instructions="Use the codex tool to inspect the workspace and answer the question.",
480+
tools=[
481+
codex_tool(
482+
sandbox_mode="workspace-write",
483+
working_directory="/path/to/repo",
484+
default_thread_options=ThreadOptions(
485+
model="gpt-5.2-codex",
486+
network_access_enabled=True,
487+
web_search_enabled=False,
488+
),
489+
persist_session=True,
490+
)
491+
],
492+
)
493+
```
494+
495+
What to know:
496+
497+
- Auth: set `CODEX_API_KEY` (preferred) or `OPENAI_API_KEY`, or pass `codex_options={"api_key": "..."}`.
498+
- Inputs: tool calls must include at least one item in `inputs` with `{ "type": "text", "text": ... }` or `{ "type": "local_image", "path": ... }`.
499+
- Safety: pair `sandbox_mode` with `working_directory`; set `skip_git_repo_check=True` outside Git repos.
500+
- Behavior: `persist_session=True` reuses a single Codex thread and returns its `thread_id`.
501+
- Streaming: `on_stream` receives Codex events (reasoning, command execution, MCP tool calls, file changes, web search).
502+
- Outputs: results include `response`, `usage`, and `thread_id`; usage is added to `RunContextWrapper.usage`.
503+
- Structure: `output_schema` enforces structured Codex responses when you need typed outputs.
504+
- See `examples/tools/codex.py` for a complete runnable sample.
505+
467506
## Handling errors in function tools
468507

469508
When you create a function tool via `@function_tool`, you can pass a `failure_error_function`. This is a function that provides an error response to the LLM in case the tool call crashes.

0 commit comments

Comments
 (0)