mirror of
https://gitcode.com/JianFeeeee/homeagent-sdk.git
synced 2026-10-01 06:43:18 +00:00
本次一并提交工作区此前累积的改动(均已验证),并接入工具并发调度所需的 声明项。 把「谁来反代谁」从内核硬编码变成插件可声明。设备网关(remotedevice) 这类**编译进内核、没有独立插件目录与 plugin.json** 的服务,静态扫描扫不到, 此前只能靠约定。新增 DeclareProxy 让它们能自己声明反代路由。 ParallelSafe 的**反向**声明项。判据优先级:Serial 胜出,显式声明不允许被 ParallelSafe 或任何默认值覆盖。 为什么需要它:ParallelSafe 零值 false 已表达「安全/串行」,插件无法区分 「我没想过」和「我确认过必须串行」。没有这个区分,工具作者只能靠命名约定 传递意图,那不是契约。 ParallelSafe 本身也补齐了注释,明确其零值语义(默认串行、保守)与理由 (新语义下并发会改变工具的行为前提,让存量插件意外并发比慢一点危险得多)。 配套 ScenePolicy 声明项的使用说明。 remotedevice/ 整目录(C 实现的设备网关,已由 Go 侧 DeclareProxy 路径取代)。 - sdk/knowledge.go:随场面策略配套调整 - docs/api/*、docs/assets/api-index.json、docs/llms.txt、mkdocs.yml: 由 tools/apidoc/build.sh 从源码重新生成(行号随 plugin.go 变动漂移)
78 lines
2.4 KiB
Markdown
78 lines
2.4 KiB
Markdown
<!-- 本页由 tools/apidoc/gensite 从源码生成,请勿手改;要改文档就改 sdk/*.go 的注释。 -->
|
||
|
||
# 工具(Tools)
|
||
|
||
注册 LLM 可调用的工具。工具是插件最主要的能力形态:模型看到 `ToolDef` 的说明后决定是否调用,调用时执行你的 `ToolHandler`。
|
||
|
||
### `ContentBlock`
|
||
|
||
```go
|
||
type ContentBlock struct { Type string `json:"type"` Text string `json:"text,omitempty"` ImageURL *ImageURL `json:"image_url,omitempty"` AudioURL *AudioURL `jso …
|
||
```
|
||
|
||
ContentBlock 是多模态内容块(OpenAI 格式:text/image_url/audio_url)。
|
||
插件工具返回结果时可用 PluginSDK.SetToolBlocks 注入,让下一轮 LLM
|
||
请求在 tool message 的 content 数组里带上图片/音频,实现"模型看图/听音频"。
|
||
|
||
<small>`plugin.go:954`</small>
|
||
|
||
### `PluginSDK.RegisterTool`
|
||
|
||
```go
|
||
func (s *PluginSDK) RegisterTool(name string, def ToolDef, handler ToolHandler) error
|
||
```
|
||
|
||
RegisterTool registers a tool that the LLM can call.
|
||
|
||
**示例插件里的真实用法**
|
||
|
||
| 插件 | 位置 | 代码 |
|
||
|---|---|---|
|
||
| [`a2a`](../examples/index.md#a2a) | `example/a2a/plugin.go:76` | `s.RegisterTool(tp+"a2a_query", sdk.ToolDef{` |
|
||
| [`acp`](../examples/index.md#acp) | `example/acp/plugin.go:70` | `s.RegisterTool(tp+"acp_query", sdk.ToolDef{` |
|
||
| [`ai_image`](../examples/index.md#ai_image) | `example/ai_image/plugin.go:159` | `s.RegisterTool(tp+"generate", sdk.ToolDef{` |
|
||
| [`bili`](../examples/index.md#bili) | `example/bili/plugin.go:47` | `s.RegisterTool(tp+"video", sdk.ToolDef{` |
|
||
|
||
<small>`plugin.go:557`</small>
|
||
|
||
### `ToolCall`
|
||
|
||
```go
|
||
type ToolCall struct { ID string `json:"id"` Name string `json:"name"` Plugin string `json:"plugin,omitempty …
|
||
```
|
||
|
||
ToolCall represents a model's request to call a tool.
|
||
|
||
<small>`plugin.go:227`</small>
|
||
|
||
### `ToolDef`
|
||
|
||
```go
|
||
type ToolDef struct { Name string `json:"name"` Plugin string `json:"plugin,omitempty"` Description string …
|
||
```
|
||
|
||
ToolDef describes a tool that the plugin exposes.
|
||
|
||
<small>`plugin.go:279`</small>
|
||
|
||
### `ToolHandler`
|
||
|
||
```go
|
||
type ToolHandler func(args map[string]interface{}) (interface{}, error)
|
||
```
|
||
|
||
ToolHandler is a function that handles a tool call.
|
||
|
||
<small>`plugin.go:20`</small>
|
||
|
||
### `ToolResult`
|
||
|
||
```go
|
||
type ToolResult struct { CallID string `json:"call_id"` Name string `json:"name"` Plugin string `json:"plugin,omitempty"` Success bool `json:"suc …
|
||
```
|
||
|
||
ToolResult represents the result of a tool call.
|
||
|
||
<small>`plugin.go:235`</small>
|
||
|