CMDC.Agent.SystemPrompt (cmdc v0.4.0)

Copy Markdown View Source

系统提示词组装器 — 编译 Agent 最终的 system prompt。

组装层级(从底到顶)

  1. BasePrompt — 核心行为准则 + 可用工具列表
  2. 用户 system_prompt — Blueprint 或直接传入的自定义指令
  3. Blueprint Identity — name / purpose(若有 Blueprint 配置)
  4. Skills 列表 — 渐进式技能清单(name + description)
  5. Memory 内容 — AGENTS.md 等持久记忆内容

PromptMode 门控(v0.2 Phase 10B)

通过 state.prompt_mode 控制注入哪些段落:

模式user_promptBasePromptIdentitySkillsMemory
:full(默认)完整 BasePrompt.build/1
:task精简 BasePrompt.for_mode(:task)
:minimal仅 tools 名称列表
:none

:task 模式相比 :full 典型省 30-50% system prompt token。

用法

prompt = CMDC.Agent.SystemPrompt.build(state)

与旧项目的差异

  • 新增 Skills 注入(对标 DeepAgents SkillsMiddleware)
  • 新增 Memory 注入(对标 DeepAgents MemoryMiddleware)
  • BasePrompt 独立模块化(旧项目直接硬编码在 SystemPrompt 中)
  • Blueprint Identity 信息从 config 中提取

Summary

Functions

从 Agent State 编译完整的系统提示词。

Functions

build(state)

@spec build(CMDC.Agent.State.t()) :: String.t()

从 Agent State 编译完整的系统提示词。

state.prompt_mode 门控:各模式注入的段落见模块 @moduledoc 表格。 空段自动跳过,段间用双换行分隔。