Skip to content

Agent 系统提示词 — 上下文块契约与 Debug 形状

对应 packages/agent/src/zhin-agent/prompt.ts§1–§10 分段架构(与文件头注释一致)。

块顺序(稳定段 → 动态段)

ID(debug)章节稳定性说明
§1_identity_environmentIdentity & Environment每轮重建persona、CWD、Node、时区、内存文件提示
§2_systemSystem固定模板输出格式、注入警惕、压缩提示
§3_doing_tasksDoing tasks固定模板工具优先、安全编码
§4_action_safetyAction safety固定模板只读/破坏性分界、ask_user
§5_toolsTools固定模板专用工具优先、并行调用
§6_styleStyle固定模板简洁、语言跟随
§7_skillsAvailable Skills动态有技能 XML 或 registry 时出现
§8_active_skillsActive Skills动态已激活技能上下文
§9_memoryMemory动态文件记忆 MEMORY.md / 当日笔记
§10_bootstrapBootstrap动态额外注入

块之间使用 SECTION_SEPpackages/agent/src/zhin-agent/config.ts 导出)拼接。

用户消息与历史

  • 多轮历史由 buildUserMessageWithHistory 包装,内含 HISTORY_CONTEXT_MARKERCURRENT_MESSAGE_MARKERconfig.ts),与上述系统段分离;不计入上表 § 编号,但在 token 预算中占用显著比例。

Debug 导出(运行时)

调用 describePromptSectionsForDebug(ctx)prompt.ts 导出,@zhin.js/agent re-export)得到非空段的 { id, approxChars }[],用于:

  • 观测「渐进披露」下各段体积;
  • 对照业界经验(上下文过长时质量下降),做日志或排障,改变默认 prompt 语义。

Tier 映射(Harness 上下文架构)

Tier本仓库载体
1 常驻AGENTS.md + 本文 + im-queue-outbound-invariants.md
2 按需docs/architecture-overview.mddocs/architecture/*
3 深读具体包内源码、docs/advanced/*

基于 MIT 许可发布