ARTICLE DETAIL

资讯详情

深耕网站视觉设计与运营推广的一线实战洞察。

Agent Zero Tiny Local 的 response 工具详解:小模型最终的“收尾应答”契约

Agent Zero Tiny Local 的 response 工具详解:小模型最终的“收尾应答”契约 Agent Zero Tiny Local 的 response 工具详解小模型最终的“收尾应答”契约【免费下载链接】agent-zeroAgent Zero AI framework项目地址: https://gitcode.com/GitHub_Trending/ag/agent-zero导读在 Agent Zero 框架中response是每个 Agent 面向用户输出最终结论的唯一专用工具。而在tiny-localTiny Local这一专为本地小模型设计的 Agent Profile 里response的使用规则被进一步收紧调用格式必须是最简 JSON、不允许携带thoughts或headline并且严禁用“我会继续”这类敷衍文字代替真实的工具调用。本文以 agents/tiny-local/prompts/agent.system.tool.response.md 为骨架结合框架源码 tools/response.py 与 Tiny Local Profile 的整套提示词契约讲解response工具的定位、调用时机、参数规范与底层实现帮助你为 Ollama、LM Studio、Qwen 等本地小模型正确编写“行动优先”的工具调用协议。response 工具是什么Agent 与用户之间的“最终应答”通道在原文档 agents/tiny-local/prompts/agent.system.tool.response.md 中response被精确定义为用途向用户输出最终答案Final answer to the user触发条件仅在任务已完成done、任务受阻blocked或当前任务根本不需要任何工具no tool is needed时使用核心参数tool_args中唯一的参数text用于承载简洁的最终应答文本。换句话说response是 Agent 每轮工作流的“句号”。它不代表一次中间汇报而是代表该轮任务的收束Agent 要么给出了结果要么明确报告了阻塞原因。在 Tiny Local 的通信契约 agents/tiny-local/prompts/agent.system.main.communication.md 中也同样强调“For a final user-facing answer, use theresponsetool”并且“Useresponseonly when the work is complete, blocked, or the user is only acknowledging completed work.”仅在任务完成、受阻或用户只是确认已完成工作时使用。使用时机什么情况下调用什么情况下绝对不能调用这是本工具最容易被误用的地方原文档专门用一个独立段落给出了“禁止清单”Do not use this tool for proceed, continue, go ahead, or similar continuation requests when there is an unfinished next step. Call a real tool instead.即当用户说出proceed、continue、go ahead等“继续推进”类指令而当前仍有未完成的下一步时严禁用response回复“好的我继续”之类的承诺或状态更新而应当直接调用下一个真正执行任务的工具。这一规则在 Tiny Local 的多个提示词文件中被反复强调形成一致性契约agents/tiny-local/prompts/agent.system.main.solving.mdContinuation words such as proceed, continue, go ahead, do it, and excellent proceed mean execute the next unfinished step. Do not respond by saying you will begin, continue, start, proceed, or investigate.agents/tiny-local/prompts/agent.system.main.communication.mdIf the user says proceed, continue, go ahead, do it, excellent proceed or similar after you named a next step or there is unfinished work, do not answer with a promise or status update. Call the next appropriate tool.可以归纳出如下“可用/禁用”对照表场景是否调用 response正确做法任务全部完成向用户交付结果✅ 调用{tool_name:response,tool_args:{text:...}}任务受阻、无法继续blocked✅ 调用在text中简述阻塞原因任务简单到无需任何工具✅ 调用直接在text中作答用户只是确认已完成的工作✅ 调用简短确认即可用户说“proceed/continue/go ahead/do it”且还有未完成的下一步❌ 禁止立即调用下一个真实工具用户说“proceed”但任务确已完成✅ 调用用 response 简短收尾参数与调用示例最简 JSON 契约原文档给出了唯一的参数说明与示例Tiny Local 版本中调用体形如{tool_name:response,tool_args:{text:There are 24 files in /tmp.}}要点如下顶层字段只有两个tool_name与tool_args不允许任何其他顶层字段text是唯一参数要求是简洁的最终应答文本concise final answer text应答风格虽然原文档对 Tiny Local 版本未展开但默认 Profile 的 prompts/agent.system.tool.response.md 给出了同一参数text的风格基准——“default to balanced, concise answers: informative but tight, not terse and not verbose”默认保持均衡简洁的答案信息充分但紧凑既不敷衍也不冗长Tiny Local 同样沿用这一准则。值得一提的是text参数在源码层接受text与message两个键见下文实现解析因此写成message也是合法的但按提示词契约应统一使用text。源码级实现response 如何真正“结束”一轮循环仅看提示词还不够response的行为由框架源码 tools/response.py 决定。其核心逻辑非常短可以逐段拆解class ResponseTool(Tool): async def execute(self, **kwargs): for key in (text, message): message self.args.get(key) if isinstance(message, str) and message.strip(): return Response(messagemessage, break_loopTrue) raise RepairableException( response tool requires a non-empty top-level text or message string argument )从源码结构可以得出三个关键实现事实break_loopTrue是“收尾”的引擎execute返回的Response对象携带break_loopTrue这会中断 Agent 主循环使本轮处理结束——这正是提示词中“Final answer to the user / ends task processing”的底层机制text与message双键兼容实现会依次检查text和message两个键任一是非空字符串即视为有效应答提升了与不同 Profile 提示词模板的兼容性空参数会被框架自动修复若两个键都缺失、为空字符串或非字符串类型execute会抛出RepairableException可修复异常框架会据此要求模型重新生成一次合法的工具调用而不是直接崩溃——这保证了即使小模型偶尔漏填参数也能进入修复流程而非产生静默错误。另外before_execution与after_execution均不做额外处理before_execution中相关日志代码已被注释交由 live_response 扩展处理after_execution仅当存在log_item_response临时参数时将该日志条目标记为 finished说明response工具本身不向历史记录注入多余内容保持输出干净。Tiny Local 与默认 Profile 的差异去掉 thoughts 与 headline将 Tiny Local 版本与默认版本的同一工具提示词对照能直观看出该 Profile 的“瘦身”设计默认版本 prompts/agent.system.tool.response.md 给出的调用示例带有thoughts思考过程数组与headline简要标题两个字段并额外通过{{ include agent.system.response_tool_tips.md }}引入一条复用技巧对已存在的长文本使用§§include(path)而非重写Tiny Local 版本 agents/tiny-local/prompts/agent.system.tool.response.md去掉了这两个字段只保留tool_name与tool_args。原因在 Tiny Local 的输出规则 agents/tiny-local/prompts/agent.system.tools.md 中写明Some inherited tool examples may showthoughtsorheadline. Ignore that shape for this profile. Do not includethoughts,headline, analysis, markdown fences, or prose outside the JSON object.即Tiny Local 继承到的示例中若出现thoughts/headline一律忽略该形态输出必须是纯粹的 JSON 对象不得出现 markdown 代码围栏、围栏外的正文、隐藏推理或标题。这一设计面向小参数模型推理字段会占用宝贵的上下文预算且小模型更容易在 JSON 外“跑题”输出散文因此被彻底移除。协同契约response 与 Tiny Local 整套提示词的关系response不是孤立工具它位于 Tiny Local Profile 的行为闭环之中。根据 agents/tiny-local/AGENTS.md 的职责划分该 Profile 的提示词文件各司其职提示词文件职责与 response 的关系agents/tiny-local/prompts/agent.system.main.communication.md本地模型通信契约规定“面向用户的最终答复必须走 response”并给出最终应答的标准形态示例agents/tiny-local/prompts/agent.system.main.solving.md本地模型问题解决契约规定简单问题直接 answer with theresponsetool、任务结束用 response 交付结果agents/tiny-local/prompts/agent.system.tools.md工具列表包装与最终输出形态提醒强制“一个 JSON 对象、仅 tool_name 与 tool_args、无 thoughts/headline”agents/tiny-local/prompts/agent.system.tool.response.md本工具专属示例本文主体定义调用时机与 text 参数agents/tiny-local/prompts/fw.msg_repeat.md重复消息恢复指令当框架检测到重复消息时若上一份 JSON 在仍有工作时误用了response要求改用下一个真实工具若确实无其他可行动作才允许“useresponsewith a brief blocker”其中 agents/tiny-local/prompts/fw.msg_repeat.md 与 response 的“禁止误用”规则形成闭环一旦模型重复发送相同 JSON恢复指令会明确提示“If your previous JSON usedresponsewhile work remains, replace it with the next real tool call”即把“误用 response 当续期”当作需要修复的典型错误并要求“Output exactly one JSON object withtool_nameandtool_args. No prose or markdown.”——与 response 工具的格式契约完全一致。Profile 的元信息 agents/tiny-local/agent.yaml 也佐证了这一设计意图Tiny Local 是“Action-first profile for small local models that need a minimal tool-call contract”适用场景是“running small local chat models through Ollama, LM Studio, or similar providers and the model tends to explain actions instead of calling tools”模型倾向于解释行动而不是调用工具时。response的收紧规则正是这套“最小工具调用契约”在收尾环节的落地。实战要点与自查清单结合原文档与源码面向使用 Tiny Local Profile 接入本地小模型的开发者给出如下可操作建议把 response 当作“终态机”而非“汇报器”只有任务结束、受阻或根本不需要工具三种状态才输出 response中间任何推进动作都必须是真实工具调用严格遵循 JSON 形态只输出{tool_name:response,tool_args:{text:...}}不要添加thoughts、headline、markdown 围栏或围栏外散文否则会被 Tiny Local 输出规则视为格式违规text 参数必须非空源码要求text或message为非空字符串缺失或为空会触发RepairableException进入修复流程额外消耗一次模型调用把“继续类”指令映射为行动遇到proceed、continue、go ahead、do it时若存在未完成步骤应调用下一个工具只有任务已彻底完成时才可用 response 收尾善用阻塞报告任务受阻如命令超时无法确认结果时用 response 简要报告 blocker而不是谎称成功——agents/tiny-local/prompts/agent.system.main.solving.md 明确要求“never claim success from timeout output or a still-running command”遇到重复消息警告时改变行为若框架提示发送了相同 JSON参照 agents/tiny-local/prompts/fw.msg_repeat.md 选择不同的下一步动作仅在确实无其他动作可做时才用 response 报告阻塞。通过以上契约response在 Tiny Local 中既保证了“任务必须真实推进到终点才收尾”又保证了“收尾动作永远干净、简短、可被框架稳定解析”是从提示词到源码完整闭环的最终应答规范。【免费下载链接】agent-zeroAgent Zero AI framework项目地址: https://gitcode.com/GitHub_Trending/ag/agent-zero创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
返回列表