Files
Agent-System-Core/prompts.go
weichenandCursor 9b8cf79c96 Add optional tools, model, and maxTurns to prompt modules
Why: User overrides of a subagent profile need a place on the shared contract, and empty fields must stay omitted so older modules keep their meaning.
Evidence: go test ./... passed, including the new prompt_module_subagent golden.
Impact: Existing modules serialize the same. Frontend and UI contracts still need a copy of the type.
Refs: feature/agent-harness-p3b
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-01 15:21:47 +00:00

76 lines
3.5 KiB
Go

package core
// 提示词模块契约(prompt-library):提示词从代码移入数据,按层组装、按触发注入。
//
// 分层(Layer):
// - base 常驻基座块(身份/行为/谨慎/工具/风格),始终组装
// - env 动态环境段(占位符填充:日期/模型/附件清单)
// - task 任务技能(触发命中才注入;同层只注入优先级最高者)
// - agent 子代理/小队角色提示词(派生 run 时取用)
// - tool 工具描述文案(ToolDecl.description 的数据来源)
// - aux 辅助模板(压缩摘要/标题生成等;入库先行,接线随功能走)
// - style 输出风格(叠加在基座之上的表达方式变体)
type PromptModule struct {
ID string `json:"id"` // "base.identity" / "task.doc-minutes"
Layer string `json:"layer"` // base|env|task|agent|tool|aux|style
Version int `json:"version"` // 内置升级判定
Title string `json:"title"`
Description string `json:"description"` // 给人看(设置界面/命令菜单)
Priority int `json:"priority,omitempty"` // task 层多命中时的取舍;缺省 50,大者优先
Triggers []PromptTrigger `json:"triggers,omitempty"` // 空 = 基座,始终组装
RequiresAttachments bool `json:"requiresAttachments,omitempty"` // 命中还需本轮有附件
Body string `json:"body"` // 模板正文,{{placeholder}} 占位
OutputContract string `json:"outputContract,omitempty"` // 期望产出形态(注入模型 + 供验收)
Source string `json:"source,omitempty"` // builtin | plugin | user
Owner string `json:"owner,omitempty"`
BasedOnVersion int `json:"basedOnVersion,omitempty"` // 用户副本基于的内置版本
Drifted bool `json:"drifted,omitempty"` // 用户副本落后于当前内置版本(提示用,不阻断)
Disabled bool `json:"disabled,omitempty"` // 用户停用
// 子代理 profile。只对 agent.sub.* 有意义;空字段表示沿用内置。
Tools []string `json:"tools,omitempty"`
Model string `json:"model,omitempty"` // lightweight | chat
MaxTurns int `json:"maxTurns,omitempty"`
}
// PromptTrigger 触发条件;模块命中 = 任一 trigger 命中(再过 RequiresAttachments)。
type PromptTrigger struct {
Kind string `json:"kind"` // intent | command | attachment | manual
Keywords []string `json:"keywords,omitempty"`
Command string `json:"command,omitempty"` // "/minutes"
}
// 触发 Kind 常量。
const (
TriggerIntent = "intent"
TriggerCommand = "command"
TriggerAttachment = "attachment"
TriggerManual = "manual"
)
// 层常量。
const (
LayerBase = "base"
LayerEnv = "env"
LayerTask = "task"
LayerAgent = "agent"
LayerTool = "tool"
LayerAux = "aux"
LayerStyle = "style"
)
// PromptBlock 组装产物:一个已解析占位符的 system 段。
type PromptBlock struct {
ModuleID string `json:"moduleId"`
Version int `json:"version"`
Layer string `json:"layer"`
Body string `json:"body"`
}
// PromptHitRecord 触发判定记录(可观测:哪个技能因何种原因注入/让位)。
type PromptHitRecord struct {
ModuleID string `json:"moduleId"`
Layer string `json:"layer"`
Reason string `json:"reason"` // "intent:纪要" / "command:/minutes" / "always" / "superseded-by:<id>"
Injected bool `json:"injected"`
}