Files
beaver_project/projcet_review/backend_blueprint/tools.html
steven_li 6e9e74d1ee feat(engine): 添加运行时上下文支持并重构工具迭代限制
添加 RuntimeContext 类用于捕获模型运行时的日期时间信息,
包括UTC时间、本地时间和时区信息,并在系统提示中显示这些信息。

同时增加最大上下文消息数和工具迭代次数的配置选项,
将验证服务从引擎加载器中移除,并更新相关的数据结构和接口。

BREAKING CHANGE: 移除了验证服务,相关字段被替换为证据状态和接受状态。

- 添加 RuntimeContext 类和相关渲染方法
- 增加 max_context_messages 和 max_tool_iterations 配置
- 移除 ValidationService 相关代码
- 更新消息记录中的验证状态字段
- 添加原始工具调用检测和回退处理
2026-05-26 11:18:35 +08:00

80 lines
4.2 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!doctype html>
<html lang="zh-CN">
<head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>Tools 模块蓝图</title><link rel="stylesheet" href="blueprint.css"></head>
<body><main class="page">
<header class="topbar"><h1>Tools</h1><p>Tools 模块定义 Beaver 可调用工具的规格、注册、选择和执行。它把内置工具与 MCP 工具统一成 provider tool schema再把模型返回的 tool_calls 安全地执行成 tool result。</p></header>
<nav class="nav"><a href="index.html">索引</a><a href="engine.html">Engine</a><a href="skills.html">Skills</a><a href="prompt-atlas.html">Prompt Atlas</a></nav>
<section class="content">
<h2>大模块流程</h2>
<div class="flow">
<div class="step"><strong>注册</strong>内置工具 + MCP wrapper</div><div class="arrow">-&gt;</div>
<div class="step"><strong>选择</strong>always + skill hints + embedding top-k</div><div class="arrow">-&gt;</div>
<div class="step"><strong>导出 schema</strong>provider function/tool schema</div><div class="arrow">-&gt;</div>
<div class="step"><strong>执行</strong>ToolExecutor 执行 tool_call</div><div class="arrow">-&gt;</div>
<div class="step"><strong>回填</strong>tool message + session event</div>
</div>
<h2>小模块拆分</h2>
<article class="module">
<h3>base</h3>
<p><code>ToolSpec</code> 描述 name、description、input schema、always flag<code>ToolContext</code> 携带 workspace、session、user、services<code>ToolResult</code> 统一 success/content/error。</p>
<div class="subflow">
<div>工具实现暴露成 BaseTool 或 ObjectBackedTool。</div>
<div>ToolSpec 同时可转 MCP descriptor、provider schema、embedding candidate。</div>
<div>执行结果必须是 ToolResultAgentLoop 再转成 provider tool message。</div>
</div>
</article>
<article class="module">
<h3>registry</h3>
<p>ToolRegistry 是工具目录。EngineLoader 会注册内置工具MCP manager connect_all 后也把外部 MCP 工具注册进来。</p>
<div class="subflow">
<div>register tool spec 与 callable。</div>
<div>list_specs/list_always_specs/get_specs 供 ToolAssembler 使用。</div>
<div>export_selected_provider_schemas 输出本轮模型可见工具。</div>
</div>
</article>
<article class="module">
<h3>ToolAssembler</h3>
<p>按 run 选择工具,不做 LLM prompt。选择顺序固定always tools、配置里的默认 always names、activated skills 的 tool hints、embedding top-k。</p>
<div class="subflow">
<div>先加入 registry.list_always_specs。</div>
<div>再加入默认 <code>memory</code><code>session_search</code></div>
<div>收集 activated skill 的 <code>tool_hints</code> 或 loader 中的 skill tool hints。</div>
<div>对剩余工具做 embedding retrieve补充 top-k。</div>
</div>
</article>
<article class="module">
<h3>runtime executor</h3>
<p>ToolExecutor 接收 provider 返回的 ToolCallRequest查 registry解析 arguments传入 ToolContext捕获异常并返回 ToolResult。</p>
<div class="subflow">
<div>模型返回 tool_calls。</div>
<div>AgentLoop 序列化并记录 assistant tool call。</div>
<div>ToolExecutor 执行对应工具。</div>
<div>AgentLoop 把 result.content 追加为 role=tool message。</div>
</div>
</article>
<article class="module">
<h3>builtins</h3>
<p>内置工具包括 terminal、filesystem、web、memory、session_search、skill_view、skills_admin、cron、utility、echo。它们覆盖本地开发、记忆、会话检索、skill 管理和定时任务。</p>
<div class="subflow">
<div>工具从 ToolContext 取 workspace/services。</div>
<div>执行具体 IO 或服务动作。</div>
<div>返回文本结果,进入下一轮模型上下文。</div>
</div>
</article>
<article class="module">
<h3>mcp wrapper</h3>
<p>把外部 MCP tool 适配成 Beaver ToolSpec/callable使外部工具和内置工具对 AgentLoop 呈现同一种接口。</p>
<div class="subflow">
<div>MCP manager connect_all。</div>
<div>为每个外部 tool 建 wrapper。</div>
<div>注册进 ToolRegistry后续由 ToolAssembler 选择。</div>
</div>
</article>
</section></main></body></html>