Documentation
¶
Overview ¶
Package prompt 生成发给模型的内置提示文本:系统提示里的各个块、工具说明,以及插进对话的通知。
Index ¶
- Constants
- func FormatAgentMessage(sender defs.SessionID, agentSender defs.AgentSender, textParts []string) string
- func FormatAgentsInstruction(instruction defs.AgentsInstruction) string
- func FormatClientInstruction(instruction defs.ClientInstruction) string
- func FormatContextSummary(summary defs.ContextSummary) string
- func FormatExecutorInstructions(executors []ExecutorEntry) string
- func FormatExecutorParameterDescription(defaultExecutorID string) string
- func FormatExecutorsChange(change defs.ExecutorsChange) string
- func FormatHookRun(run defs.HookRun) string
- func FormatMemoryIndex(index defs.MemoryIndex) string
- func FormatMemoryInstructions() string
- func FormatModelChange(change defs.ModelChange) string
- func FormatModelError(modelError defs.ModelError) string
- func FormatOmittedOlderImage(alt string, maxImages int) string
- func FormatRequiredExecutorParameterDescription() string
- func FormatSessionIdentity(session defs.Session) string
- func FormatSkillInstruction(instruction defs.SkillInstruction) string
- func FormatSkillInstructions(skills []*skill.Skill) string
- func FormatSpawnAgentDescription(agents []AgentEntry, models []*defs.ModelDefinition) string
- func FormatSubagentNotification(sender defs.SessionID, notification defs.SubagentNotification, ...) string
- func FormatToolResultImages(callID string, alts []string) string
- func FormatTurnInterrupted() string
- type AgentEntry
- type ExecutorEntry
Constants ¶
const ( LocalExecutorDescription = "Agent 本机当前目录" BuiltinExecutorDescription = "" /* 189-byte string literal not displayed */ MemoryExecutorDescription = "" /* 210-byte string literal not displayed */ )
local、内置和 memory Executor 给模型看的说明。
const ( DefaultAgentDescription = "通用助手" DefaultAgentInstructions = "" /* 155-byte string literal not displayed */ )
内置 default Agent 的用途说明和系统指令;配置里没有 default Agent 时使用,agents/default.yaml 没写的字段也沿用它们。
const ( SendMessageDescription = "向已知后代或直接父 Agent 发送任务、补充要求或信息;重开对话后,发到原 SessionID 会先续跑其未完成轮次。" + "normal 安排新 Turn,忙碌时排队;steer 补充活动 Turn,在下一次模型请求前读入,无可接收 Turn 时自动按 normal 安排。" + "进度汇报、提问和对当前任务的补充要求应显式设置 mode: \"steer\";独立的后续任务用 normal。" + "返回 accepted 只表示已接收;steer 不会中断正在执行的模型或工具,需要中断时使用 interrupt_agent。" + "给后代发送时可以用 model、reasoning_effort 换它的模型,可选值见 spawn_agent 的 model 列表;不能改直接父方的模型。" InterruptAgentDescription = "请求取消指定后代当前正在执行的 Turn。" + "返回 cancel_requested 和选定的 turn_id,或无活动 Turn 时返回 no_active_turn;不等待取消完成。" + "排队输入和它的子任务继续运行;可通过 wait_agent 或 list_agents 查看后续结果与状态。" ListAgentsDescription = "使用空参数对象读取全部后代;sessions 中每项的 session 保存身份与父子关系,status 保存活动 Turn、排队数量和最近 Turn 状态," + "usage 是已保存 Turn 的累计 token 用量,context_window 是该 Session 所选模型的上下文窗口。" + "使用 session.id 选择通信、等待或中断的目标;这是查询时的工作快照,不等待任务完成、不领取结果正文,也不启动历史任务。" ListExecutorsDescription = "无参数时只查询当前在线的全部 Executor(含服务端与已连接客户端),返回默认标记、说明、工作目录和可用工具名,不影响前缀缓存。" + "传入 refresh_tools: true 会在下一次模型请求前重建工具表,导致前缀缓存失效。仅在当前 Turn 确实需要立刻调用新上线的工具时使用,不要高频调用。" ReadSessionHistoryDescription = "需要子任务的详细执行过程时,读取指定后代在 fork 之后自身已保存的消息、工具调用与结果。" + "从最新内容向更早历史分页,每页 Items 按时间正序返回;使用非零 next_cursor 继续,为 0 时结束。" + "返回资料省略加密推理、provider RawJSON 和图片 base64;查询不启动执行,也不影响结果通知。" WaitAgentDescription = "暂停当前工作,直到收到 steer 消息(Agent 消息或用户补充输入)、子任务结果通知或超时。normal 消息排队等待新 Turn,不会唤醒本次等待。" + "返回 reason:user_steer、subagent_result、agent_message 或 timeout(同时存在时按此顺序),from 为发送消息的 Agent SessionID;不返回正文。" + "可选 wait_for: \"subagent_result\" 优先返回已有未读补充;没有未读补充且没有运行中的后代时立即返回 no_running_subagents,可用 list_agents 查看状态。" + "消息正文会在下一次模型请求中读入;省略参数默认等待 30 秒,超时不会取消子任务。" BashDescription = "在工作区后台启动一条 Bash 命令(省略 cwd 时在工作区根目录运行),最多等 wait_seconds 秒后返回 command_id、status 和从头开始的第一页输出(stdout、stderr 合并)。" + "wait_seconds 到期时命令不会停,status 为 running、exit_code 为 null,命令继续在后台运行;之后用 read_command_output 带上 next_cursor 续读,用 stop_command 停止。" + "命令结束后 status 为 exited 并给出 exit_code,退出码非 0 不算工具出错;无法确认命令结果时 status 为 failed,原因在 error。" + "timeout_seconds 从启动起计,到期停止命令,0 表示不限。" + "interactive 使用 PTY,之后可以用 write_stdin 输入。命令跨轮次保留,被中断后没拿到 command_id 时用 list_commands 找回。" ReadCommandOutputDescription = "读取 bash 启动的命令从 cursor 起的一页输出(最多 64 KiB)和命令当前的 status、exit_code。" + "已有输出时立即返回,否则最多等 wait_seconds 秒,直到有新输出或命令结束。读取不取走内容,同一个 cursor 可以重读;" + "用结果的 next_cursor 续读,has_more 为 true 表示还有已产生的输出没读完。每条命令只保留最后 1 MiB 输出,cursor 处的内容已被丢弃时从最早保留的位置读并标 truncated。" WriteStdinDescription = "把 chars 原样写进以 interactive=true 启动的命令的终端,不会自动加换行,需要回车时自己带上 \\n;普通命令的 stdin 是空的,不能写入。" + "返回实际写入的字节数,只写入一部分时不会自动重发。写入后用 read_command_output 查看命令的回显和输出。" StopCommandDescription = "终止 bash 启动的命令及其派生的整个进程组(不是发送 Ctrl-C),等到确认停止后返回最终 status、exit_code 和 stop_reason。" + "没能确认停止时返回错误,命令可能仍在运行,可以再试。" ListCommandsDescription = "按启动先后列出本 Session 在所选 Executor 上启动的命令,含 command_id、命令、工作目录、status 和 exit_code;" + "用来找回没拿到或忘记的 command_id。" ReadFileDescription = "按行读取 UTF-8 文本文件:offset 是从 1 开始的起始行号(默认 1),limit 是最多读取的行数(默认 200,最多 2000)。" + "content 中每行以“行号: ”开头,该前缀不属于原文件;相对路径以工作区为基准,也可使用绝对路径。" + "每页正文最多 64 KiB,按完整行返回;字节数超限时标 truncated,使用 next_offset 行号续读,eof 表示已到文件末尾。单行过长时报错,可用 bash 查看。" + "PNG、JPEG、GIF、WebP 图片会直接作为图片交给你查看,此时 offset、limit 不起作用。" ApplyPatchDescription = "" /* 139-byte string literal not displayed */ GlobDescription = "按通配符列出工作区里的文件路径,不读文件内容:pattern 相对 path,例如 **/*.go、src/**/test_*.py;path 省略时从工作区根目录开始。" + "跳过 .git 和以 . 开头的文件、目录;在 git 仓库里还跳过 .gitignore 忽略的文件。结果按路径排序,最多 limit 条(默认 100,最多 1000),超出时 truncated 为 true。" GrepDescription = "用正则逐行搜索文件内容,返回 path、line(从 1 开始)和这一行的文本(超过 500 个字符截断)。" + "pattern 只用 rg 和 POSIX 扩展正则共有的写法:\\d、\\w、\\s 和它们的大写会自动换成等价的字符类;不支持 (?i) 这类内联标记,忽略大小写用 ignore_case。" + "glob 只搜路径匹配的文件,例如 *.go。跳过二进制文件,其余跳过规则同 glob。结果按路径和行号排序,最多 limit 条(默认 100,最多 1000)。" )
内置协作工具和工作区工具给模型看的用途说明。
const ContextCompactionInstructions = "" /* 264-byte string literal not displayed */
ContextCompactionInstructions 是压缩上下文时交给摘要模型的指令。
const MaxStepsReachedInstructions = "" /* 213-byte string literal not displayed */
MaxStepsReachedInstructions 是单轮模型调用次数到达上限时追加在请求末尾的指令。
const OmittedImageUnsupportedText = "[图片已省略:当前模型不能接收图片]"
OmittedImageUnsupportedText 是模型不能接收图片时代替图片的文字。
Variables ¶
This section is empty.
Functions ¶
func FormatAgentMessage ¶
func FormatAgentMessage(sender defs.SessionID, agentSender defs.AgentSender, textParts []string) string
FormatAgentMessage 生成其他 Agent 发来的消息。
func FormatAgentsInstruction ¶
func FormatAgentsInstruction(instruction defs.AgentsInstruction) string
FormatAgentsInstruction 生成一份 AGENTS.md 的适用范围和正文说明。
func FormatClientInstruction ¶ added in v0.3.0
func FormatClientInstruction(instruction defs.ClientInstruction) string
FormatClientInstruction 生成客户端指令的标题和正文。
func FormatContextSummary ¶
func FormatContextSummary(summary defs.ContextSummary) string
FormatContextSummary 生成放进上下文的历史摘要块。
func FormatExecutorInstructions ¶
func FormatExecutorInstructions(executors []ExecutorEntry) string
FormatExecutorInstructions 生成系统提示里的稳定 Executor 列表,第一项是默认 Executor。列表为空时返回空串。
func FormatExecutorParameterDescription ¶
FormatExecutorParameterDescription 生成工具 executor 参数的说明,写明默认 Executor。
func FormatExecutorsChange ¶
func FormatExecutorsChange(change defs.ExecutorsChange) string
FormatExecutorsChange 生成可用 Executor 变化的通知。
func FormatHookRun ¶
FormatHookRun 把 hook 运行结果里要给模型看的内容生成通知;没有这样的内容时返回空串。
func FormatMemoryIndex ¶ added in v0.3.0
func FormatMemoryIndex(index defs.MemoryIndex) string
FormatMemoryIndex 生成一份记忆目录的说明:适用范围、截断提示和正文。
func FormatMemoryInstructions ¶ added in v0.3.0
func FormatMemoryInstructions() string
FormatMemoryInstructions 生成 memory 可用时追加到系统指令里的记忆规则。
func FormatModelChange ¶
func FormatModelChange(change defs.ModelChange) string
FormatModelChange 生成对话换了模型的通知。
func FormatModelError ¶
func FormatModelError(modelError defs.ModelError) string
FormatModelError 生成上一轮模型请求失败的通知。
func FormatOmittedOlderImage ¶
FormatOmittedOlderImage 生成较早的图片被省略时代替它的文字。
func FormatRequiredExecutorParameterDescription ¶ added in v0.6.0
func FormatRequiredExecutorParameterDescription() string
FormatRequiredExecutorParameterDescription 生成必须指定 Executor 时的参数说明。
func FormatSessionIdentity ¶
FormatSessionIdentity 生成系统提示中的 Session 身份块。
func FormatSkillInstruction ¶
func FormatSkillInstruction(instruction defs.SkillInstruction) string
FormatSkillInstruction 生成用户这次选中的 skill 的正文说明。
func FormatSkillInstructions ¶
FormatSkillInstructions 生成系统提示里的 skill 列表;没有 skill 时返回空串。
func FormatSpawnAgentDescription ¶
func FormatSpawnAgentDescription(agents []AgentEntry, models []*defs.ModelDefinition) string
FormatSpawnAgentDescription 生成 spawn_agent 的说明,附上可选的 Agent 和模型列表。
func FormatSubagentNotification ¶
func FormatSubagentNotification(sender defs.SessionID, notification defs.SubagentNotification, textParts []string) string
FormatSubagentNotification 生成子 Agent 一个 Turn 结束后的结果通知。
func FormatToolResultImages ¶
FormatToolResultImages 生成说明工具调用读到了哪些图片的系统信息块。
Types ¶
type AgentEntry ¶
AgentEntry 是 spawn_agent 说明里列出的一个可选 Agent:名字和用途说明。
type ExecutorEntry ¶
ExecutorEntry 是系统提示里列出的一个 Executor;传入列表的第一项是默认 Executor。