Skip to content

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

对应 packages/im/agent/src/zhin-agent/prompt.ts 中精简分层架构(与文件头注释一致)。

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

ID(debug)章节稳定性说明
§1_contextContext每轮重建persona、CWD、Node、时区、内存文件提示
§2_styleStyle固定模板简洁、先给答案或结果
§3_toolsTools固定模板工具边界;toolSearch 为通用编排纪律
§4_safetySafety固定模板只读/破坏性分界、Owner 信号、注入防护
§6c_platformPlatform动态适配器 AgentPromptContributor(按 toolContext.platform
§6b_deferredDeferred Tools动态toolSearch 域统计
§8_skillsAvailable Skills动态有技能 XML 或 registry 时出现
§9_active_skillsActive Skills动态已激活技能上下文
§10_memoryMemory动态文件记忆 MEMORY.md / 当日笔记
§11_bootstrapBootstrap动态额外注入

平台专属文案(icqq/github 等)见 agent-prompt-contributors.md不再写入 agent 包内 prompt.ts

块之间使用 SECTION_SEPpackages/im/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 + 本文
2 按需docs/architecture-overview.mddocs/architecture/*
3 深读具体包内源码、docs/advanced/*

基于 MIT 许可发布