()
| 102 | |
| 103 | |
| 104 | async def main() -> None: |
| 105 | agent = Agent( |
| 106 | name="Codex Agent", |
| 107 | instructions=( |
| 108 | "Use the codex tool to inspect the workspace in read-only mode and answer the question. " |
| 109 | "When skill names, which usually starts with `$`, are mentioned, " |
| 110 | "you must rely on the codex tool to use the skill and answer the question.\n\n" |
| 111 | "When you send the final answer, you must include the following info at the end:\n\n" |
| 112 | "Run `codex resume <thread_id>` to continue the codex session." |
| 113 | ), |
| 114 | tools=[ |
| 115 | # Run local Codex CLI as a sub process |
| 116 | codex_tool( |
| 117 | sandbox_mode="read-only", |
| 118 | default_thread_options=ThreadOptions( |
| 119 | # You can pass a Codex instance to customize CLI details |
| 120 | # codex=Codex(executable_path="/path/to/codex", base_url="..."), |
| 121 | model="gpt-5.5", |
| 122 | model_reasoning_effort="low", |
| 123 | network_access_enabled=True, |
| 124 | web_search_enabled=False, |
| 125 | approval_policy="never", # We'll update this example once the HITL is implemented |
| 126 | ), |
| 127 | default_turn_options=TurnOptions( |
| 128 | # Abort Codex CLI if no events arrive within this many seconds. |
| 129 | idle_timeout_seconds=60, |
| 130 | ), |
| 131 | on_stream=on_codex_stream, |
| 132 | ) |
| 133 | ], |
| 134 | ) |
| 135 | trace_id = gen_trace_id() |
| 136 | log(f"View trace: https://platform.openai.com/traces/trace?trace_id={trace_id}") |
| 137 | |
| 138 | with trace("Codex tool example", trace_id=trace_id): |
| 139 | log("Using the Codex tool to inspect pyproject.toml and summarize Python requirements...") |
| 140 | result = await Runner.run( |
| 141 | agent, |
| 142 | ( |
| 143 | "Inspect pyproject.toml in this repository and summarize the supported Python " |
| 144 | "version plus the main local test command. Do not modify any files." |
| 145 | ), |
| 146 | ) |
| 147 | log(result.final_output) |
| 148 | |
| 149 | # Use local inspection in read-only mode. |
| 150 | log( |
| 151 | "Using the Codex tool to inspect AGENTS.md and summarize the local verification workflow..." |
| 152 | ) |
| 153 | result = await Runner.run( |
| 154 | agent, |
| 155 | ( |
| 156 | "Inspect AGENTS.md and summarize the mandatory local verification commands for this " |
| 157 | "repository. Do not modify any files or suggest code changes." |
| 158 | ), |
| 159 | ) |
| 160 | log(result.final_output) |
| 161 | # (A read-only summary of the local verification workflow will be displayed.) |
no test coverage detected