当前位置: 首页 > news >正文

内置工具开发_builtin-tool

以下为本文档的中文说明

LobeHub内置工具包构建指南,专门用于开发和集成LobeHub平台中可被代理调用的工具。该技能定义了内置工具的五大核心组件:Manifest与类型定义(为LLM提供工具规范和系统提示)、ExecutionRuntime执行运行时(负责服务器端和桌面端的实际调用)、Executor执行器(客户端侧的交互逻辑)、Inspector检查器(用于调试和验证工具行为)、以及Render渲染器(负责工具输出在界面中的呈现)。此外还涵盖流式处理、干预机制、Portal集成和工具注册表等高级功能。使用场景主要包括:为LobeHub平台添加新的Agent可调用工具、开发工具包的各面层组件、配置工具的Manifest和类型系统、实现工具的流式响应处理、以及将工具注册到工具注册表中供代理发现和使用。核心原则强调"五面一体"的架构设计——每个工具由五个独立但协同的组件构成,分别服务于LLM、运行时、客户端、调试和UI渲染等不同层面。这种分层架构确保了工具的灵活性、可测试性和可维护性。


Builtin Tool Authoring Guide

A builtin tool is a package the agent runtime can call. It shipsfive faces:

FaceLives inAudience
Manifest + typessrc/{manifest,types,systemRole}.tsThe LLM (tool spec + system prompt)
ExecutionRuntimesrc/ExecutionRuntime/Server / desktop / any runtime caller
Executorsrc/client/executor/Frontend (wraps stores/services)
Client UIsrc/client/{Inspector,Render,…}/Chat UI
Registry wiringpackages/builtin-tools/src/*.ts+src/store/tool/slices/builtin/executors/index.tsFramework

Read These First

QuestionDoc
Where do files live? What does each face do? Wiring?architecture.md
How do I name the tool, design APIs, write the manifest, executor, ExecutionRuntime?tool-design.md
How do I build Inspector / Render / Placeholder / Streaming / Intervention / Portal?ui/

When to Use This Skill

  • Creating a newpackages/builtin-tool-<name>/package
  • Adding a new API method to an existing builtin tool
  • Building or restyling any of the 6 client surfaces for a tool
  • Wiring a tool into the central registries
  • Debugging “tool not found / API not found / render not showing / placeholder stuck” errors

Top-Level Design Principles

  1. lobe-<domain>identifier is permanent.It’s stored in message history. Renames need@deprecatedaliases (seepackages/builtin-tools/src/inspectors.ts:88-89). Get it right the first time.
  2. ApiName is anas constobject, not a TS enum. It doubles as the runtime listBaseExecutoriterates over.
  3. Three result fields, three audiences:
    • content: string→ the LLM reads it
    • state: Record<…>→ the UI’spluginState;result-domain only, never echo all params back
    • error: { type, message, body? }→ both LLM and UI;typeis a stable code
  4. Split execution from frontend wiring.
    • src/ExecutionRuntime/— pure runtime, no React, no Zustand, accepts services via constructor.The default place for new logic.
    • src/client/executor/BaseExecutorsubclass that callsExecutionRuntime(or stores/services directly when frontend-only).
  5. UI defaults to “do nothing”.Inspector is required (the header strip). Render/Placeholder/Streaming/Intervention/Portal are addedonly when there’s something specific to show— empty registries are fine.
  6. Style withcreateStaticStyles + cssVar.*(zero-runtime). Fall back tocreateStyles + tokenonly when you genuinely need runtime values. Use@lobehub/uicomponents, not raw antd.
  7. i18n keys live insrc/locales/default/plugin.ts.Inspector titles must come fromt('builtins.<identifier>.apiName.<api>')so something renders while args stream.

Package Layout (preferred, post-2026 convention)

packages/builtin-tool-<name>/ ├── package.json └── src/ ├── index.ts # exports manifest + types + systemRole + Identifier (no React, no stores) ├── manifest.ts # BuiltinToolManifest with JSON Schema for every API ├── types.ts # ApiName const + Params/State interfaces per API ├── systemRole.ts # System prompt teaching the model when/how to use the APIs ├── ExecutionRuntime/ # ✅ Default home for runtime logic (server- or anywhere-callable) │ └── index.ts └── client/ ├── index.ts # Re-exports for the registries ├── executor/ # ✅ Frontend executor — extends BaseExecutor, often delegates to ExecutionRuntime │ └── index.ts ├── Inspector/ # required — header chip per API ├── Render/ # optional — rich result card ├── Placeholder/ # optional — skeleton during streaming/execution ├── Streaming/ # optional — live output renderer (e.g. RunCommand, WriteFile) ├── Intervention/ # optional — approval / edit-before-run UI ├── Portal/ # optional — full-screen detail view └── components/ # shared subcomponents used by the surfaces above

Older packages(builtin-tool-task,builtin-tool-calculator, etc.) still havesrc/executor/as a sibling ofsrc/client/. That’s grandfathered;don’t relocate without a deliberate refactor. New packages and new APIs added to existing packages should follow the layout above.

package.jsonexports map:

"exports":{".":"./src/index.ts","./client":"./src/client/index.ts","./executor":"./src/client/executor/index.ts","./executionRuntime":"./src/ExecutionRuntime/index.ts"}

Authoring Checklist

Before opening the PR:

  • Identifier followslobe-<domain>and isstable(lives in message history).
  • Every<Name>ApiNamevalue has: a manifestapi[]entry, an executor method, an Inspector, an i18napiName.*key.
  • Paramsinterfaces match the JSON Schema;Stateinterfaces match what the executor returns and what the UI surfaces read.
  • System prompt disambiguates confusable APIs and points to batch variants.
  • Runtime logic lives inExecutionRuntime/; theclient/executor/only wires stores/services and delegates.
  • Executor returns{ success, content, state, error? }via a singletoResult()funnel —contentalways non-empty (default toerror.message).
  • Inspector handlesisArgumentsStreaming,isLoading,partialArgs, missingpluginState.
  • Render returnsnulluntil it has data; only created for APIs with rich results.
  • Placeholder added if the API has a perceivable execution lag (search, list, crawl).
  • Streaming added for APIs that emit incremental output (run command, write file, code execution).
  • Intervention added ifhumanInterventionis set in the manifest.
  • All registry files updated (see architecture.md → Registry wiring).
  • i18n keys insrc/locales/default/plugin.tsplus dev seeds inen-US/zh-CN.
  • bunx vitest run --silent='passed-only' 'packages/builtin-tool-<name>'passes.
  • bun run type-checkpasses.

Reference Tools

Pick the closest neighbor and copy:

If your tool is…Read first
Pure-compute, no UI statepackages/builtin-tool-calculator/ExecutionRuntimereuses executor (mathjs/nerdamer work everywhere)
CRUD over a domain entitypackages/builtin-tool-task/— full Inspector + Render set, batch variants
Heavy UI (Inspector/Render/Placeho
lder/Portal)packages/builtin-tool-web-browsing/— search-style result UI, Portal for detail view
Desktop / filesystem with all surfaces (incl. Streaming + Intervention)packages/builtin-tool-local-system/ExecutionRuntimeinjects anILocalSystemService, executor calls it
Server-side pure (no client executor)packages/builtin-tool-web-browsing/— onlyExecutionRuntimeis exported; the chat client doesn’t run it
Needs human approval before runningpackages/builtin-tool-local-system/src/client/Intervention/— per-API approval components
http://www.jsqmd.com/news/1220737/

相关文章:

  • CSS 自定义高亮 API(Highlight API)实现代码语法高亮的纯前端方案
  • 直播 AI 实时美颜与特效的端上推理优化:从 1080p@30fps 到移动端 720p@60fps 的工程实践
  • 为什么选择librw?重构RenderWare引擎的5大技术优势
  • Larq生态系统详解:Zoo预训练模型与Compute Engine部署工具链
  • 鸿蒙开发入门:以 Text 组件为例,掌握内置组件用法
  • 从配置到部署:mlx-community/gemma-4-31b-it-5bit模型参数全解析
  • 【苏州吴江】吴江基坑降水井施工哪家专业?工地降水靠谱队伍联系方式,吴江打井推荐 - 瑞溪泉水利
  • 把 Microsoft MarkItDown 做成本地文档转换 API:PDF/Office 转 Markdown 后,用 cpolar 接收远程上传
  • 文心做 excel 表格,AI 导出鸭助力高效文档导出
  • AI数字人直播话术优化实战手册(实时情绪识别+动态脚本生成)
  • 【网络基础系列】07手撕“子网划分”软考真题,终于搞懂 AWS VPC 怎么建了!
  • 又新又“夯“的小程序测试工具
  • 解放AI绘画创作力:OpenPose Editor如何让你轻松掌控人物姿态
  • CANN启航营提交规范详解:从Fork到PR的完整流程
  • CodeGraph 使用指南
  • 【2018-10-17】【转】Linux常用命令笔记 scp
  • 青囊智康体检预约系统核心功能与场景落地指南
  • Intern-S2-Preview-397B-FP8:革命性3970亿参数多模态AI模型完整指南
  • GordenPPTSkill自动更新机制详解:让你的PPT工具永远保持最新状态
  • 2026 北京钻石高价回收优选品牌|16 区全覆盖 实时报价 - 奢侈品回收实体店
  • 【Claude高效工作流秘籍】:20年AI工程师亲授5个不为人知的提示词工程技巧,90%用户从未用过
  • nginx编译安装+平滑升级实战
  • TMS320F28003x DAC与CMPSS模块实战:从寄存器配置到电机驱动应用
  • 【通义千问 × 即梦创作实战指南】:20年AI内容架构师亲授3步工作流,97%新手当天产出高质量短视频脚本
  • 技能质量审计_skills-audit
  • YOLOv10热力图终极指南:5分钟构建实时人群密度分析系统
  • AI 打击乐生成的力度建模:从 velocity 到 ghost note 的表达力
  • 2026年7月积家官方售后网点全网公告:中国区60+门店地址优化升级、服务热线同步启用 - 积家中国服务中心
  • Remount核心功能解析:从自定义元素到Shadow DOM的完整实现指南
  • MCP:AI时代的USB-C标准