Documentation
¶
Overview ¶
Package prompt 生成发给模型的内置提示文本:系统提示里的各个块、工具说明,以及插进对话的通知。
Index ¶
- Constants
- func FormatAgentMessage(sender defs.SessionID, agentSender defs.AgentSender, textParts []string) string
- func FormatAgentsInstruction(instruction defs.AgentsInstruction) 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 FormatModelChange(change defs.ModelChange) string
- func FormatModelError(modelError defs.ModelError) string
- func FormatOmittedOlderImage(alt string, maxImages int) 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 */ )
local 和内置 Executor 给模型看的说明。
const ( DefaultAgentDescription = "通用助手" DefaultAgentInstructions = "" /* 155-byte string literal not displayed */ )
内置 default Agent 的用途说明和系统指令;配置里没有 default Agent 时使用,agents/default.yaml 没写的字段也沿用它们。
const ( SendMessageDescription = "向已知后代或直接父 Agent 发送任务、补充要求或信息。" + "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 选择通信、等待或中断的目标;这是查询时的工作快照,不等待任务完成、不领取结果正文,也不启动历史任务。" 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;不返回正文。" + "消息正文会在下一次模型请求中读入;超时不会取消子任务,子任务每轮结束后的结果都会自动通知。" 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 */ )
内置协作工具和工作区工具给模型看的用途说明。
const ContextCompactionInstructions = "" /* 264-byte string literal not displayed */
ContextCompactionInstructions 是压缩上下文时交给摘要模型的指令。
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 FormatContextSummary ¶
func FormatContextSummary(summary defs.ContextSummary) string
FormatContextSummary 生成放进上下文的历史摘要块。
func FormatExecutorInstructions ¶
func FormatExecutorInstructions(executors []ExecutorEntry) string
FormatExecutorInstructions 生成系统提示里的 Executor 列表,第一项是默认 Executor;没有 Executor 时返回空串。
func FormatExecutorParameterDescription ¶
FormatExecutorParameterDescription 生成工具 executor 参数的说明,写明默认 Executor。
func FormatExecutorsChange ¶
func FormatExecutorsChange(change defs.ExecutorsChange) string
FormatExecutorsChange 生成可用 Executor 变化的通知。
func FormatHookRun ¶
FormatHookRun 把 hook 运行结果里要给模型看的内容生成通知;没有这样的内容时返回空串。
func FormatModelChange ¶
func FormatModelChange(change defs.ModelChange) string
FormatModelChange 生成对话换了模型的通知。
func FormatModelError ¶
func FormatModelError(modelError defs.ModelError) string
FormatModelError 生成上一轮模型请求失败的通知。
func FormatOmittedOlderImage ¶
FormatOmittedOlderImage 生成较早的图片被省略时代替它的文字。
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。