惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 聂微东
博客园 - 叶小钗
爱范儿
爱范儿
罗磊的独立博客
Hugging Face - Blog
Hugging Face - Blog
阮一峰的网络日志
阮一峰的网络日志
S
SegmentFault 最新的问题
Apple Machine Learning Research
Apple Machine Learning Research
美团技术团队
T
Tailwind CSS Blog
博客园 - 司徒正美
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
宝玉的分享
宝玉的分享
量子位
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
The Cloudflare Blog
人人都是产品经理
人人都是产品经理
小众软件
小众软件
博客园 - 【当耐特】
博客园 - 三生石上(FineUI控件)
V
Visual Studio Blog
雷峰网
雷峰网
酷 壳 – CoolShell
酷 壳 – CoolShell

博客园 - 张润昊

项目文档治理方案形成全过程(证据审计版) 在AI时代, 关于编程的思考 Coding Agent 工程化实践《一》 : 前端页面自验实践 大模型为什么会产生幻觉?从原理到工程防御 Codex 的 Skill 到底是怎么被调用的? Superpowers:如何约束 Coding Agent 使用 Codex 的一次危险提醒 我的Nginx 的配置分析 NextJS 安全漏洞分析 AI工具学习02 - 使用 ChatGPT 进行 PRD 产品设计 NextJS 02 - 服务端渲染 NextJS01 - page router - 问题列表 Flutter02-布局 Flutter01-本地数据库 isar React 学习 03-两种 Api 的使用 React 学习 02-commit 渲染 React 学习 01-时间切片 安卓低机型卡顿分析以优化方案 命令行 查找某个结尾的文件. 总结下vim快捷键 React技术揭密学习(二) React技术揭密学习(一) Build your own React 前端监控系统博客总结 记账项目 - webpack优化 React源码解携(二): 走一趟render流程 macos更新后, MySQL不能启动问题
Codex Subagent :如何隔离 Coding Agent 的上下文
张润昊 · 2026-07-26 · via 博客园 - 张润昊

Subagent: 管理上下文的一种方法

阅读笔记

  • 直接对话的Agent, 是Main Agent(全部上下文). Main Agent 在适合的时间创建 Sub Agent
  • 技术本质: 打开一个新的 messages 数组(上下文)
  • Main Agent 没有 Sub Agent 执行过程的上下文, 只有结论
  • 探索搜索 / 独立性子任务 / 独立审查意见
  • Codex 内置的 Subagent : default / worker(生成代码) / explorer(定位代码). 默认同时最多有6个
  • Subagent 只能有一层, 不能无羡套.
  • 可以类似自定义 Skill 进行自定义 Subagent (也是只有自定义工作流的时候, 才需要自定义 Subagent, 比如每次写完代码的独立审查)
name = "reviewer"
description = "PR reviewer focused on correctness and security."
developer_instructions = """
Review code like an owner.
Prioritize correctness, security, and missing test coverage.
"""
  • Subagent fields
    • required: name; description(when to use); developer_instructions(subagent behavior)
    • optional: nickname_candidates(many same subagents name); model; model_reasoning_effort;
  • project: .codex/agent; global: ~/.codex/agents/
  • configuration: agents_max_threads(6);agents_max_depth(1);agents_job_max_runtime_seconds(1800)
  • how to use: ask directly; AGENT.md; skill instructions;
  • why help: noisy intermediate output make context large, model limit; context pollution; context rot;
  • prompt: spawn two agents; delegate this work in parallel; use one agent per point;
  • good subagent prompt: explain how to work; whether should wait; what return;
  • Subagent的继承: explicit value ⇒ [agent] default(只要不设置) ⇒ parent’s value

Subagent 的概念

Subagent是一个执行具体任务, 返回具体结果, 干净上下文的agent.

主要用来解决Context pollution; Context rot;

Sub Agent 的使用

什么情况下使用 / 如何使用 / 实践

使用背景:

  1. 当Agent需要多个任务并行开发时;
  2. 当Agent执行某个具体的任务, 只需要知道结果, 又不希望上下文影响这个任务时.

AI提供的使用场景:

  • 主 Agent 搜索过程太长,开始忘记原始要求;
  • 大量测试、日志把上下文塞满;
  • 一个 PR 需要从多个独立角度审查;
  • 多个模块可以并行调查;
  • 想让一个独立 Agent 对主方案提出反对意见。

如何使用: 直接派发 / 项目中的agent.md 派发 / skill 进行派发

实践:

I would like to review the following points on the current PR (this branch vs main). Spawn one agent per point, wait for all of them, and summarize the result for each point.
1. Security issue
2. Code quality
3. Bugs
4. Race
5. Test flakiness
6. Maintainability of the code

!image.png

!image.png

参考资料

https://learn.chatgpt.com/docs/agent-configuration/subagents?surface=app

https://labuladong.online/zh/ai-coding/basics/sub-agent/

https://www.youtube.com/watch?v=1XB22Jx2YXI

https://github.com/VoltAgent/awesome-codex-subagents

疑问延伸: