Agent Build智能体搭建 Tutor教程
Platforms各平台 / Coding agent编程智能体

Codex

Codex is a finished harness for work in a repository. You do not write its loop. You configure its model, instructions, tools, and limits, and you can run it without a terminal session as a step in a pipeline.Codex 是面向代码仓库工作的现成 Harness。它的循环不用你写。你配置的是模型、指令、工具和限制,还可以让它脱离终端会话,作为流水线中的一个步骤运行。

These guides were written from vendor documentation read in October 2026. None was executed: there was no account on these platforms. Product names change often. Confirm each command against the linked source before you rely on it.这些指南依据 2026 年 10 月查阅的厂商文档编写。全部未经实际执行:编写时没有这些平台的账号。产品名称经常变化。使用前请对照链接的来源逐条核实命令。

What you own归你负责的

AGENTS.md, skills, MCP servers, the eval scripts it runs, the approval and sandbox settings.AGENTS.md、技能、MCP 服务、它要运行的评估脚本、审批和沙箱设置。

What the platform runs由平台运行的

The loop, context management, the sandbox, session history.循环、上下文管理、沙箱、会话历史。

Build steps搭建步骤

01Find the config file and choose the model provider找到配置文件并选择模型供应商

Do this操作

  1. User settings live in `~/.codex/config.toml`. A trusted project may add `.codex/config.toml`.用户级设置在 `~/.codex/config.toml`。受信任的项目可以另加 `.codex/config.toml`。
  2. A provider is a table with a base URL and the name of the environment variable holding its key.供应商是一张表,包含 base URL 和存放其密钥的环境变量名。
  3. Provider settings in a project-level file are ignored. Set them in the user file.项目级文件里的供应商设置会被忽略。要在用户级文件里设置。
~/.codex/config.toml
model_provider = "local"

[model_providers.local]
base_url = "http://127.0.0.1:8000/v1"     # your gateway from module 2
env_key = "LOCAL_GATEWAY_KEY"
You are done when完成标志A prompt is answered and your gateway log shows the request.一条提示得到了回答,并且你的网关日志里出现了这次请求。
02Write AGENTS.md编写 AGENTS.md

Do this操作

  1. Put standing instructions in `AGENTS.md` at the repository root.把长期有效的指令放在仓库根目录的 `AGENTS.md` 里。
  2. Keep it short. Add a rule only after it has been broken once.保持简短。某条规则被违反过一次之后,才把它加进去。
You are done when完成标志A new session follows a rule that appears only in the file.新的会话遵守了一条只出现在该文件里的规则。
03Register the MCP server from lab 6注册 lab 6 的 MCP 服务

Do this操作

  1. Add a table per server with the launcher command and arguments.为每个服务添加一张表,写明启动命令和参数。
  2. Raise the per-tool timeout if a tool can run longer than the default 60 seconds.如果某个工具的运行时间可能超过默认的 60 秒,就调高单个工具的超时时间。
~/.codex/config.toml
[mcp_servers.policy-desk]
command = "/abs/path/to/venv/bin/python3"
args = ["-m", "labs.m06_tools.mcp_server"]
tool_timeout_sec = 120

[mcp_servers.policy-desk.env]
PYTHONPATH = "/abs/path/to/aitutor"
You are done when完成标志The agent can call `search_policy`.智能体可以调用 `search_policy`。
04Add skills添加技能

Do this操作

  1. Skills are supported. Reuse the skill bodies from lab 8.Codex 支持技能。复用 lab 8 里的技能正文。
  2. The folder location and frontmatter were not on the page read. Follow the vendor's skills page.所查阅的页面上没有给出目录位置和 frontmatter 格式。请参照厂商的技能文档。
You are done when完成标志The agent loads the skill for a matching request.遇到匹配的请求时,智能体加载了该技能。
05Set approvals, permissions, and hooks设置审批、权限和钩子

Do this操作

  1. `approval_policy` takes `on-request` or `never`, or a granular table.`approval_policy` 取值为 `on-request`、`never`,或一张细粒度配置表。
  2. Built-in permission profiles are read-only, workspace, and full access. Start with the narrowest that lets the task finish.内置的权限档位有只读、工作区和完全访问。从能完成任务的最窄档位开始。
  3. Lifecycle hooks can be enabled and are loaded from a hooks file. Use one to run your checks before a change is accepted.可以启用生命周期钩子,它们从一个 hooks 文件加载。用钩子在接受改动之前运行你的检查。
You are done when完成标志A write outside the workspace is refused.对工作区之外的写入被拒绝。
06Run it without a terminal as an eval gate脱离终端运行,把评估作为关卡

Do this操作

  1. Run Codex non-interactively in a pipeline with a fixed prompt.在流水线里用固定的提示以非交互方式运行 Codex。
  2. Have the pipeline run your retrieval and agent evals afterward and fail on a drop.之后让流水线运行你的检索评估和智能体评估,得分下降就判定失败。
  3. Keep gold files outside the paths the agent may write.把标准集文件放在智能体可写路径之外。
  4. The `exec` subcommand is from general knowledge and was not on the page read. Confirm it with `codex --help`.`exec` 子命令来自一般性了解,所查阅的页面上没有出现。请用 `codex --help` 确认。
bash
codex exec "Run python3 -m labs.run_all --check and summarize any failure."
python3 -m labs.run_all --check
You are done when完成标志The pipeline fails when an eval score drops.评估得分下降时,流水线失败。
07For your own service, use the Agents SDK要做自己的服务,就用 Agents SDK

Do this操作

  1. Codex is for work in a repository. For an agent you host, the loop is the OpenAI Agents SDK.Codex 面向的是仓库内的工作。要托管自己的智能体,循环用的是 OpenAI Agents SDK。
  2. Lab 14 has that port, running against your gateway.lab 14 里有这个移植版本,对接的是你的网关。
You are done when完成标志`python3 -m labs.m14_sdk.demo` prints the Agents SDK line.`python3 -m labs.m14_sdk.demo` 输出了 Agents SDK 那一行。

Sources来源