Phase 5 · 编码 Agent 实战

使用 Codex CLI 和 Agents SDK 构建一致的工作流

OpenAI·2026/7/21·8 阅读

使用 Codex CLI 和 Agents SDK 构建一致的工作流

来源: https://developers.openai.com/cookbook/examples/codex/codex_mcp_agents_sdk/building_consistent_workflows_codex_cli_agents_sdk 抓取时间: 2026-07-21 16:21:36


确保可重复、可追踪且可扩展的智能体开发

介绍

开发者在他们所做的一切中都追求一致性。借助 Codex CLI 和 Agents SDK,这种一致性现在可以以前所未有的方式扩展。无论您是在重构大型代码库、推出新功能还是引入新的测试框架,Codex 都能无缝集成到 CLI、IDE 和云工作流中,以自动化并强制执行可重复的开发模式。 在本教程中,我们将使用 Agents SDK 构建单智能体和多智能体系统,并将 Codex CLI 作为 MCP Server 暴露。这将实现:

  • 一致性和可重复性 —— 通过为每个智能体提供作用域上下文。
  • 可扩展的编排 —— 协调单智能体和多智能体系统。
  • 可观察性和可审计性 —— 通过查看完整的智能体堆栈跟踪。

我们将涵盖的内容

  • 将 Codex CLI 初始化为 MCP Server:如何将 Codex 作为长期运行的 MCP 进程。
  • 构建单智能体系统:使用 Codex MCP 执行作用域任务。
  • 编排多智能体工作流:协调多个专业智能体。
  • 追踪智能体行为:利用智能体追踪获取可见性和评估。

前提条件和设置

在开始本教程之前,请确保您具备以下条件:

  • 基本编码熟悉度:您应该熟悉 Python 和 JavaScript。
  • 开发环境:您需要一个 IDE,如 VS Code 或 Cursor。
  • OpenAI API 密钥:在 OpenAI 仪表板中创建或找到您的 API 密钥。

环境设置

  1. 在您的目录中创建一个 .env 文件夹,并添加您的 OPENAI_API_KEY 密钥
  2. 安装依赖项
%pip install openai-agents openai ## install dependencies

将 Codex CLI 初始化为 MCP Server

在这里,我们在 Agents SDK 内将 Codex CLI 作为 MCP Server 运行。我们提供 codex mcp 的初始化参数。此命令将 Codex CLI 作为 MCP 服务器启动,并在 MCP 服务器上暴露两个 Codex 工具 —— codex()codex-reply()。这些是 Agents SDK 在需要调用 Codex 时将调用的底层工具。

  • codex() 用于创建对话。
  • codex-reply() 用于继续对话。
import asyncio
from agents import Agent, Runner
from agents.mcp import MCPServerStdio

async def main() -> None:
    async with MCPServerStdio(
        name="Codex CLI",
        params={
            "command": "npx",
            "args": ["-y", "codex", "mcp-server"],
        },
        client_session_timeout_seconds=360000,
    ) as codex_mcp_server:
        print("Codex MCP server started.")
        # We will add more code here in the next section
        return

另外请注意,我们正在扩展 MCP Server 超时时间是为了让 Codex CLI 有足够的时间执行和完成给定的任务。


构建单智能体系统

让我们从一个简单的示例开始,使用我们的 Codex MCP Server。我们定义两个智能体:

  1. 设计师智能体 —— 头脑风暴并为游戏创建一个简短的说明。
  2. 开发者智能体 —— 根据设计师的规范实现一个简单的游戏。
developer_agent = Agent(
    name="Game Developer",
    instructions=(
        "You are an expert in building simple games using basic html + css + javascript with no dependencies. "
        "Save your work in a file called index.html in the current directory."
        "Always call codex with \"approval-policy\": \"never\" and \"sandbox\": \"workspace-write\""
    ),
    mcp_servers=[codex_mcp_server],
)

designer_agent = Agent(
    name="Game Designer",
    instructions=(
        "You are an indie game connoisseur. Come up with an idea for a single page html + css + javascript game that a developer could build in about 50 lines of code. "
        "Format your request as a 3 sentence design brief for a game developer and call the Game Developer coder with your idea."
    ),
    model="gpt-5",
    handoffs=[developer_agent],
)

result = await Runner.run(designer_agent, "Implement a fun new game!")

请注意,我们为开发者智能体提供了向项目目录写入文件的能力,而无需向用户请求权限。 现在运行代码,您将看到生成了一个 index.html 文件。打开文件并开始玩游戏! 这是我的智能体系统创建的游戏的一些截图。您的会有所不同!

示例游戏界面游戏结束分数
Example gameplayGame Over Score

以下是完整的可执行代码。请注意,运行可能需要几分钟。如果您看到生成的输出文件生成,它就已成功运行。您还可能看到一些关于格式的 MCP 事件警告。您可以忽略这些事件。

import os
from dotenv import load_dotenv
import asyncio
from agents import Agent, Runner, set_default_openai_api
from agents.mcp import MCPServerStdio

load_dotenv(override=True) # load the API key from the .env file. We set override to True here to ensure the notebook is loading any changes
set_default_openai_api(os.getenv("OPENAI_API_KEY"))

async def main() -> None:
    async with MCPServerStdio(
        name="Codex CLI",
        params={
            "command": "npx",
            "args": ["-y", "codex", "mcp-server"],
        },
        client_session_timeout_seconds=360000,
    ) as codex_mcp_server:
        developer_agent = Agent(
            name="Game Developer",
            instructions=(
                "You are an expert in building simple games using basic html + css + javascript with no dependencies. "
                "Save your work in a file called index.html in the current directory."
                "Always call codex with \"approval-policy\": \"never\" and \"sandbox\": \"workspace-write\""
            ),
            mcp_servers=[codex_mcp_server],
        )

        designer_agent = Agent(
            name="Game Designer",
            instructions=(
                "You are an indie game connoisseur. Come up with an idea for a single page html + css + javascript game that a developer could build in about 50 lines of code. "
                "Format your request as a 3 sentence design brief for a game developer and call the Game Developer coder with your idea."
            ),
            model="gpt-5",
            handoffs=[developer_agent],
        )

        result = await Runner.run(designer_agent, "Implement a fun new game!")
        # print(result.final_output)


if __name__ == "__main__":
    # Jupyter/IPython already runs an event loop, so calling asyncio.run() here
    # raises "asyncio.run() cannot be called from a running event loop".
    # Workaround: if a loop is running (notebook), use top-level `await`; otherwise use asyncio.run().
    try:
        asyncio.get_running_loop()
        await main()
    except RuntimeError:
        asyncio.run(main())

编排多智能体工作流

对于更大的工作流,我们引入一组智能体:

  • 项目经理:分解任务列表,创建需求,并协调工作。
  • 设计师:制定 UI/UX 规范。
  • 前端开发者:实现 UI/UX。
  • 后端开发者:实现 API 和逻辑。
  • 测试人员:根据验收标准验证输出。

在本示例中,我们有意让项目经理智能体在每个专业下游智能体之间强制执行门控逻辑。这确保在进行交接之前工件已存在。这反映了现实世界的企业工作流,如 JIRA 任务编排、长链部署和 QA 签署。 Multi-Agent Codex Workflow with Codex MCP 使用 Codex MCP 和门控交接生成工件的多智能体编排。

在这种结构中,我们的每个智能体都服务于专门的目的。项目经理全面负责协调所有其他智能体并确保整体任务完成。

定义 Codex CLI MCP Server

我们设置 MCP Server 来初始化 Codex CLI,就像我们在单智能体示例中所做的那样。

async def main() -> None:
    async with MCPServerStdio(
        name="Codex CLI",
        params={
            "command": "npx",
            "args": ["-y", "codex", "mcp-server"],
        },
        client_session_timeout_seconds=360000,
    ) as codex_mcp_server:
        print("Codex MCP server started.")
        # We will add more code here in the next section
        return

定义每个专业智能体

下面我们定义每个专业智能体,并提供对我们的 Codex MCP 服务器的访问。请注意,我们还将 RECOMMENDED_PROMPT_PREFIX 传递给每个智能体,以帮助系统优化智能体之间的交接。

# Downstream agents are defined first for clarity, then PM references them in handoffs.
designer_agent = Agent(
    name="Designer",
    instructions=(
        f"""{RECOMMENDED_PROMPT_PREFIX}"""
        "You are the Designer.\n"
        "Your only source of truth is AGENT_TASKS.md and REQUIREMENTS.md from the Project Manager.\n"
        "Do not assume anything that is not written there.\n\n"
        "You may use the internet for additional guidance or research."
        "Deliverables (write to /design):\n"
        "- design_spec.md – a single page describing the UI/UX layout, main screens, and key visual notes as requested in AGENT_TASKS.md.\n"
        "- wireframe.md – a simple text or ASCII wireframe if specified.\n\n"
        "Keep the output short and implementation-friendly.\n"
        "When complete, handoff to the Project Manager with transfer_to_project_manager."
        "When creating files, call Codex MCP with {\"approval-policy\":\"never\",\"sandbox\":\"workspace-write\"}."
    ),
    model="gpt-5",
    tools=[WebSearchTool()],
    mcp_servers=[codex_mcp_server],
    handoffs=[],
)

frontend_developer_agent = Agent(
    name="Frontend Developer",
    instructions=(
        f"""{RECOMMENDED_PROMPT_PREFIX}"""
        "You are the Frontend Developer.\n"
        "Read AGENT_TASKS.md and design_spec.md. Implement exactly what is described there.\n\n"
        "Deliverables (write to /frontend):\n"
        "- index.html – main page structure\n"
        "- styles.css or inline styles if specified\n"
        "- main.js or game.js if specified\n\n"
        "Follow the Designer's DOM structure and any integration points given by the Project Manager.\n"
        "Do not add features or branding beyond the provided documents.\n\n"
        "When complete, handoff to the Project Manager with transfer_to_project_manager_agent."
        "When creating files, call Codex MCP with {\"approval-policy\":\"never\",\"sandbox\":\"workspace-write\"}."
    ),
    model="gpt-5",
    mcp_servers=[codex_mcp_server],
    handoffs=[],
)

backend_developer_agent = Agent(
    name="Backend Developer",
    instructions=(
        f"""{RECOMMENDED_PROMPT_PREFIX}"""
        "You are the Backend Developer.\n"
        "Read AGENT_TASKS.md and REQUIREMENTS.md. Implement the backend endpoints described there.\n\n"
        "Deliverables (write to /backend):\n"
        "- package.json – include a start script if requested\n"
        "- server.js – implement the API endpoints and logic exactly as specified\n\n"
        "Keep the code as simple and readable as possible. No external database.\n\n"
        "When complete, handoff to the Project Manager with transfer_to_project_manager_agent."
        "When creating files, call Codex MCP with {\"approval-policy\":\"never\",\"sandbox\":\"workspace-write\"}."
    ),
    model="gpt-5",
    mcp_servers=[codex_mcp_server],
    handoffs=[],
)

tester_agent = Agent(
    name="Tester",
    instructions=(
        f"""{RECOMMENDED_PROMPT_PREFIX}"""
        "You are the Tester.\n"
        "Read AGENT_TASKS.md and TEST.md. Verify that the outputs of the other roles meet the acceptance criteria.\n\n"
        "Deliverables (write to /tests):\n"
        "- TEST_PLAN.md – bullet list of manual checks or automated steps as requested\n"
        "- test.sh or a simple automated script if specified\n\n"
        "Keep it minimal and easy to run.\n\n"
        "When complete, handoff to the Project Manager with transfer_to_project_manager."
        "When creating files, call Codex MCP with {\"approval-policy\":\"never\",\"sandbox\":\"workspace-write\"}."
    ),
    model="gpt-5",
    mcp_servers=[codex_mcp_server],
    handoffs=[],
)

在每个角色完成其任务后,它将调用 transfer_to_project_manager_agent,并让项目经理确认所需文件存在(或请求修复),然后再解锁下一个团队。

定义项目经理智能体

项目经理是唯一接收初始提示、在项目目录中创建立划文档并在每次传输前强制执行看门逻辑的智能体。

project_manager_agent = Agent(
name="Project Manager",
instructions=(
    f"""{RECOMMENDED_PROMPT_PREFIX}"""
    """
    You are the Project Manager.

    Objective:
    Convert the input task list into three project-root files the team will execute against.

    Deliverables (write in project root):
    - REQUIREMENTS.md: concise summary of product goals, target users, key features, and constraints.
    - TEST.md: tasks with [Owner] tags (Designer, Frontend, Backend, Tester) and clear acceptance criteria.
    - AGENT_TASKS.md: one section per role containing:
        - Project name
        - Required deliverables (exact file names and purpose)
        - Key technical notes and constraints

    Process:
    - Resolve ambiguities with minimal, reasonable assumptions. Be specific so each role can act without guessing.
    - Create files using Codex MCP with {"approval-policy":"never","sandbox":"workspace-write"}.
    - Do not create folders. Only create REQUIREMENTS.md, TEST.md, AGENT_TASKS.md.

    Handoffs (gated by required files):
    1) After the three files above are created, hand off to the Designer with transfer_to_designer_agent and include REQUIREMENTS.md, and AGENT_TASKS.md.
    2) Wait for the Designer to produce /design/design_spec.md. Verify that file exists before proceeding.
    3) When design_spec.md exists, hand off in parallel to both:
        - Frontend Developer with transfer_to_frontend_developer_agent (provide design_spec.md, REQUIREMENTS.md, AGENT_TASKS.md).
        - Backend Developer with transfer_to_backend_developer_agent (provide REQUIREMENTS.md, AGENT_TASKS.md).
    4) Wait for Frontend to produce /frontend/index.html and Backend to produce /backend/server.js. Verify both files exist.
    5) When both exist, hand off to the Tester with transfer_to_tester_agent and provide all prior artifacts and outputs.
    6) Do not advance to the next handoff until the required files for that step are present. If something is missing, request the owning agent to supply it and re-check.

    PM Responsibilities:
    - Coordinate all roles, track file completion, and enforce the above gating checks.
    - Do NOT respond with status updates. Just handoff to the next agent until the project is complete.
    """
),
model="gpt-5",
model_settings=ModelSettings(
    reasoning=Reasoning(effort="medium")
),
handoffs=[designer_agent, frontend_developer_agent, backend_developer_agent, tester_agent],
mcp_servers=[codex_mcp_server],
)

构建项目经理后,脚本将每个专家的交接设置回项目经理。这确保在继续之前返回交付物进行验证。

designer_agent.handoffs = [project_manager_agent]
frontend_developer_agent.handoffs = [project_manager_agent]
backend_developer_agent.handoffs = [project_manager_agent]
tester_agent.handoffs = [project_manager_agent]

添加您的任务列表

这是项目经理将细化为整个系统的特定需求和任务的任务。

task_list = """
Goal: Build a tiny browser game to showcase a multi-agent workflow.

High-level requirements:
- Single-screen game called "Bug Busters".
- Player clicks a moving bug to earn points.
- Game ends after 20 seconds and shows final score.
- Optional: submit score to a simple backend and display a top-10 leaderboard.

Roles:
- Designer: create a one-page UI/UX spec and basic wireframe.
- Frontend Developer: implement the page and game logic.
- Backend Developer: implement a minimal API (GET /health, GET/POST /scores).
- Tester: write a quick test plan and a simple script to verify core routes.

Constraints:
- No external database—memory storage is fine.
- Keep everything readable for beginners; no frameworks required.
- All outputs should be small files saved in clearly named folders.
"""

接下来,运行您的系统,坐下来,您会看到智能体开始工作并在几分钟内创建一个游戏!我们在下面包含了完整的可执行代码。完成后,您会注意到创建了以下文件目录。请注意,这种多智能体编排通常需要大约 11 分钟才能完全完成。

root_directory/
├── AGENT_TASKS.md
├── REQUIREMENTS.md
├── backend
│   ├── package.json
│   └── server.js
├── design
│   ├── design_spec.md
│   └── wireframe.md
├── frontend
│   ├── game.js
│   ├── index.html
│   └── styles.css
└── TEST.md

使用 node server.js 启动您的后端服务器,打开 index.html 文件玩您的游戏。

import os
from dotenv import load_dotenv
import asyncio
from agents import Agent, Runner, WebSearchTool, ModelSettings, set_default_openai_api
from agents.mcp import MCPServerStdio
from agents.extensions.handoff_prompt import RECOMMENDED_PROMPT_PREFIX
from openai.types.shared import Reasoning

load_dotenv(override=True) # load the API key from the .env file. We set override to True here to ensure the notebook is loading any changes
set_default_openai_api(os.getenv("OPENAI_API_KEY"))

async def main() -> None:
    async with MCPServerStdio(
        name="Codex CLI",
        params={"command": "npx", "args": ["-y", "codex", "mcp-server"]},
        client_session_timeout_seconds=360000,
    ) as codex_mcp_server:

        # Downstream agents are defined first for clarity, then PM references them in handoffs.
        designer_agent = Agent(
            name="Designer",
            instructions=(
                f"""{RECOMMENDED_PROMPT_PREFIX}"""
                "You are the Designer.\n"
                "Your only source of truth is AGENT_TASKS.md and REQUIREMENTS.md from the Project Manager.\n"
                "Do not assume anything that is not written there.\n\n"
                "You may use the internet for additional guidance or research."
                "Deliverables (write to /design):\n"
                "- design_spec.md – a single page describing the UI/UX layout, main screens, and key visual notes as requested in AGENT_TASKS.md.\n"
                "- wireframe.md – a simple text or ASCII wireframe if specified.\n\n"
                "Keep the output short and implementation-friendly.\n"
                "When complete, handoff to the Project Manager with transfer_to_project_manager."
                "When creating files, call Codex MCP with {\"approval-policy\":\"never\",\"sandbox\":\"workspace-write\"}."
            ),
            model="gpt-5",
            tools=[WebSearchTool()],
            mcp_servers=[codex_mcp_server],
            handoffs=[],
        )

        frontend_developer_agent = Agent(
            name="Frontend Developer",
            instructions=(
                f"""{RECOMMENDED_PROMPT_PREFIX}"""
                "You are the Frontend Developer.\n"
                "Read AGENT_TASKS.md and design_spec.md. Implement exactly what is described there.\n\n"
                "Deliverables (write to /frontend):\n"
                "- index.html – main page structure\n"
                "- styles.css or inline styles if specified\n"
                "- main.js or game.js if specified\n\n"
                "Follow the Designer's DOM structure and any integration points given by the Project Manager.\n"
                "Do not add features or branding beyond the provided documents.\n\n"
                "When complete, handoff to the Project Manager with transfer_to_project_manager_agent."
                "When creating files, call Codex MCP with {\"approval-policy\":\"never\",\"sandbox\":\"workspace-write\"}."
            ),
            model="gpt-5",
            mcp_servers=[codex_mcp_server],
            handoffs=[],
        )

        backend_developer_agent = Agent(
            name="Backend Developer",
            instructions=(
                f"""{RECOMMENDED_PROMPT_PREFIX}"""
                "You are the Backend Developer.\n"
                "Read AGENT_TASKS.md and REQUIREMENTS.md. Implement the backend endpoints described there.\n\n"
                "Deliverables (write to /backend):\n"
                "- package.json – include a start script if requested\n"
                "- server.js – implement the API endpoints and logic exactly as specified\n\n"
                "Keep the code as simple and readable as possible. No external database.\n\n"
                "When complete, handoff to the Project Manager with transfer_to_project_manager_agent."
                "When creating files, call Codex MCP with {\"approval-policy\":\"never\",\"sandbox\":\"workspace-write\"}."
            ),
            model="gpt-5",
            mcp_servers=[codex_mcp_server],
            handoffs=[],
        )

        tester_agent = Agent(
            name="Tester",
            instructions=(
                f"""{RECOMMENDED_PROMPT_PREFIX}"""
                "You are the Tester.\n"
                "Read AGENT_TASKS.md and TEST.md. Verify that the outputs of the other roles meet the acceptance criteria.\n\n"
                "Deliverables (write to /tests):\n"
                "- TEST_PLAN.md – bullet list of manual checks or automated steps as requested\n"
                "- test.sh or a simple automated script if specified\n\n"
                "Keep it minimal and easy to run.\n\n"
                "When complete, handoff to the Project Manager with transfer_to_project_manager."
                "When creating files, call Codex MCP with {\"approval-policy\":\"never\",\"sandbox\":\"workspace-write\"}."
            ),
            model="gpt-5",
            mcp_servers=[codex_mcp_server],
            handoffs=[],
        )

        project_manager_agent = Agent(
            name="Project Manager",
            instructions=(
                f"""{RECOMMENDED_PROMPT_PREFIX}"""
                """
                You are the Project Manager.

                Objective:
                Convert the input task list into three project-root files the team will execute against.

                Deliverables (write in project root):
                - REQUIREMENTS.md: concise summary of product goals, target users, key features, and constraints.
                - TEST.md: tasks with [Owner] tags (Designer, Frontend, Backend, Tester) and clear acceptance criteria.
                - AGENT_TASKS.md: one section per role containing:
                  - Project name
                  - Required deliverables (exact file names and purpose)
                  - Key technical notes and constraints

                Process:
                - Resolve ambiguities with minimal, reasonable assumptions. Be specific so each role can act without guessing.
                - Create files using Codex MCP with {"approval-policy":"never","sandbox":"workspace-write"}.
                - Do not create folders. Only create REQUIREMENTS.md, TEST.md, AGENT_TASKS.md.

                Handoffs (gated by required files):
                1) After the three files above are created, hand off to the Designer with transfer_to_designer_agent and include REQUIREMENTS.md, and AGENT_TASKS.md.
                2) Wait for the Designer to produce /design/design_spec.md. Verify that file exists before proceeding.
                3) When design_spec.md exists, hand off in parallel to both:
                   - Frontend Developer with transfer_to_frontend_developer_agent (provide design_spec.md, REQUIREMENTS.md, AGENT_TASKS.md).
                   - Backend Developer with transfer_to_backend_developer_agent (provide REQUIREMENTS.md, AGENT_TASKS.md).
                4) Wait for Frontend to produce /frontend/index.html and Backend to produce /backend/server.js. Verify both files exist.
                5) When both exist, hand off to the Tester with transfer_to_tester_agent and provide all prior artifacts and outputs.
                6) Do not advance to the next handoff until the required files for that step are present. If something is missing, request the owning agent to supply it and re-check.

                PM Responsibilities:
                - Coordinate all roles, track file completion, and enforce the above gating checks.
                - Do NOT respond with status updates. Just handoff to the next agent until the project is complete.
                """
            ),
            model="gpt-5",
            model_settings=ModelSettings(
                reasoning=Reasoning(effort="medium")
            ),
            handoffs=[designer_agent, frontend_developer_agent, backend_developer_agent, tester_agent],
            mcp_servers=[codex_mcp_server],
        )

        designer_agent.handoffs = [project_manager_agent]
        frontend_developer_agent.handoffs = [project_manager_agent]
        backend_developer_agent.handoffs = [project_manager_agent]
        tester_agent.handoffs = [project_manager_agent]


        # Example task list input for the Project Manager
        task_list = """
Goal: Build a tiny browser game to showcase a multi-agent workflow.

High-level requirements:
- Single-screen game called "Bug Busters".
- Player clicks a moving bug to earn points.
- Game ends after 20 seconds and shows final score.
- Optional: submit score to a simple backend and display a top-10 leaderboard.

Roles:
- Designer: create a one-page UI/UX spec and basic wireframe.
- Frontend Developer: implement the page and game logic.
- Backend Developer: implement a minimal API (GET /health, GET/POST /scores).
- Tester: write a quick test plan and a simple script to verify core routes.

Constraints:
- No external database—memory storage is fine.
- Keep everything readable for beginners; no frameworks required.
- All outputs should be small files saved in clearly named folders.
"""

        # Only the Project Manager receives the task list directly
        result = await Runner.run(project_manager_agent, task_list, max_turns=30)
        print(result.final_output)

if __name__ == "__main__":
    # Jupyter/IPython already runs an event loop, so calling asyncio.run() here
    # raises "asyncio.run() cannot be called from a running event loop".
    # Workaround: if a loop is running (notebook), use top-level `await`; otherwise use asyncio.run().
    try:
        asyncio.get_running_loop()
        await main()
    except RuntimeError:
        asyncio.run(main())

使用追踪来追踪智能体行为

随着您的智能体系统的复杂性增加,了解这些智能体如何交互非常重要。我们可以使用追踪仪表板来记录:

  • 智能体之间的提示、工具调用和交接。
  • MCP Server 调用、Codex CLI 调用、执行时间和文件写入。
  • 错误和警告。

让我们查看上述智能体团队的智能体追踪。 Multi-Agent Codex Workflow with Codex MCP 在此追踪中,我们可以确认每个智能体交接都由我们的项目经理智能体协调,该智能体在交接给下一个智能体之前确认特定工件存在。此外,我们可以看到 Codex MCP Server 的特定创新,并通过调用 Responses API 生成每个输出。时间线栏突出显示执行持续时间,使您可以轻松发现长时间运行的步骤并了解控制如何在智能体之间传递。 您甚至可以点击每个追踪来查看提示、工具调用和其他元数据的具体细节。随着时间的推移,您可以查看这些信息来进一步调整、优化和跟踪您的智能体系统性能。 Multi-Agent Trace Details


本指南内容回顾

在本指南中,我们逐步介绍了使用 Codex CLI 和 Agents SDK 构建一致、可扩展工作流的过程。具体来说,我们涵盖了:

  • Codex MCP Server 设置 —— 如何将 Codex CLI 初始化为 MCP 服务器,并使其作为智能体交互的工具可用。
  • 单智能体示例 —— 带有设计师智能体和开发者智能体的简单工作流,其中 Codex 确定性地执行作用域任务以生成可玩的游戏。
  • 多智能体编排 —— 扩展到更大的工作流,包括项目经理、设计师、前端开发者、后端开发者和测试人员,反映复杂的任务编排和签署流程。
  • 追踪与可观察性 —— 使用内置追踪来捕获提示、工具调用、交接、执行时间和工件,提供智能体行为的完全可见性,用于调试、评估和未来优化。

下一步:应用这些经验

既然您已经看到了 Codex MCP 和 Agents SDK 的实际应用,以下是您如何在实际项目中应用这些概念并提取价值:

1. 扩展到实际部署

  • 将相同的多智能体编排应用于大型代码重构(例如,500多个文件,框架迁移)。
  • 使用 Codex MCP 的确定性执行进行长期、可审计的部署,并具有可追踪的进度。

2. 加速交付而不失控制

  • 组织专业智能体团队来并行开发,同时保持工件验证的门控逻辑。
  • 减少新功能、测试或代码库现代化的周转时间。

3. 扩展并连接到您的开发工作流

  • 通过 Webhook 将 MCP 驱动的智能体与 Jira、GitHub 或 CI/CD 管道连接,实现自动化、可重复的开发周期。
  • 在多智能体服务编排中利用 Codex MCP:不仅是代码生成,还包括文档、QA 和部署。

评论 (0)

暂无评论,快来抢沙发吧!

91学AI

© 2026 91学AI · 按岗位学 AI 与大数据. All rights reserved.