docs: add tools API, tools-selector config type, and OpenAPI tools endpoints

- Plugin SDK APIs: list_tools, get_tool_detail, call_tool (zh/en/ja)
- Config type: tools-selector for multi-select tool picker (zh/en/ja)
- OpenAPI: GET /api/v1/tools, GET /api/v1/tools/{tool_name} (zh/en/ja)
This commit is contained in:
RockChinQ
2026-04-03 17:25:16 +08:00
parent f8ec71299e
commit 47ae62c8bf
9 changed files with 1945 additions and 335 deletions
+81
View File
@@ -249,6 +249,87 @@ parsers = await self.plugin.list_parsers(mime_type="application/pdf")
# Each item includes plugin_id, plugin_author, plugin_name, name, description, supported_mime_types
```
### List All Available Tools
List all available tools in the current LangBot instance (including plugin tools and MCP tools).
```python
async def list_tools(self) -> list[dict[str, Any]]:
"""List all available tools
Returns:
A list of tool dicts, each containing:
- name: Tool name
- label: Display label (i18n)
- description: Tool description (i18n)
- icon: Tool icon
- spec: Tool specification (includes llm_prompt and parameters)
"""
# Example
tools = await self.plugin.list_tools()
for tool in tools:
print(f"Tool: {tool['name']}")
```
### Get Tool Detail
Get detailed information about a specific tool.
```python
async def get_tool_detail(self, tool_name: str) -> dict[str, Any]:
"""Get detailed information about a specific tool
Args:
tool_name: Tool name (metadata.name, e.g. "get_weather_alerts")
Returns:
Tool detail dict containing name, label, description, spec (with parameters and llm_prompt)
"""
# Example
detail = await self.plugin.get_tool_detail("get_weather_alerts")
print(detail['spec']['parameters'])
```
### Call Tool
Call a specific tool.
```python
async def call_tool(
self,
tool_name: str,
parameters: dict[str, Any],
session: dict[str, Any],
query_id: int,
) -> dict[str, Any]:
"""Call a specific tool
Args:
tool_name: Tool name (metadata.name)
parameters: Tool parameters
session: Session info
query_id: Query ID
Returns:
Tool response dict
"""
# Example
result = await self.plugin.call_tool(
tool_name="get_weather_alerts",
parameters={"state": "CA"},
session={},
query_id=0,
)
print(result)
```
<Tip>
Tool names use `metadata.name` (e.g. `echo_tool`, `get_weather_alerts`), without author or plugin name prefix.
</Tip>
### Set Plugin Persistent Data
Persistently store plugin data. Data stored through this interface can only be accessed by this plugin. Values need to be converted to bytes manually.
+28 -1
View File
@@ -50,7 +50,7 @@ For example:
spec:
config:
- name: github_token # Required; configuration item name, used for retrieval in the plugin
type: string # Required; configuration item type, supports string, integer, float, boolean, select, prompt-editor, llm-model-selector, bot-selector, etc.
type: string # Required; configuration item type, supports string, integer, float, boolean, select, prompt-editor, llm-model-selector, bot-selector, tools-selector, etc.
label: # Required; configuration item display name, supports multilingual. Language codes follow RFC 4646 standard.
en_US: Github Token
zh_Hans: Github Token
@@ -274,6 +274,33 @@ bot_uuid = self.get_config()['bot']
print(bot_uuid) # Output: '550e8400-e29b-41d4-a716-446655440000'
```
### type: tools-selector
Tool selector. Displays a multi-select tool selector where you can choose registered tools (plugin tools and MCP tools), with the final result represented as an array of tool names.
```yaml
- name: selected_tools
type: tools-selector
...
```
Using the selected tool names in the plugin:
```python
# Get selected tool names from config
selected_tools = self.get_config()['selected_tools']
print(selected_tools) # Output: ['get_weather_alerts', 'web_search']
# Call selected tools
for tool_name in selected_tools:
result = await self.plugin.call_tool(
tool_name=tool_name,
parameters={"query": "hello"},
session={},
query_id=0,
)
```
## What's Next
This tutorial will guide you through step-by-step completion of plugin functionality.
+81
View File
@@ -249,6 +249,87 @@ parsers = await self.plugin.list_parsers(mime_type="application/pdf")
# 各要素には plugin_id、plugin_author、plugin_name、name、description、supported_mime_types が含まれます
```
### 利用可能なツール一覧を取得
現在の LangBot インスタンスで利用可能なすべてのツール(プラグインツールおよび MCP ツール)を取得します。
```python
async def list_tools(self) -> list[dict[str, Any]]:
"""利用可能なすべてのツールを取得
Returns:
ツールのリスト。各要素に以下が含まれます:
- name: ツール名
- label: 表示名(多言語)
- description: ツールの説明(多言語)
- icon: ツールアイコン
- spec: ツール仕様(llm_prompt と parameters を含む)
"""
# 使用例
tools = await self.plugin.list_tools()
for tool in tools:
print(f"Tool: {tool['name']}")
```
### ツール詳細を取得
特定のツールの詳細情報を取得します。
```python
async def get_tool_detail(self, tool_name: str) -> dict[str, Any]:
"""特定のツールの詳細情報を取得
Args:
tool_name: ツール名(metadata.name、例: "get_weather_alerts")
Returns:
ツール詳細 dict(name、label、description、spec を含む)
"""
# 使用例
detail = await self.plugin.get_tool_detail("get_weather_alerts")
print(detail['spec']['parameters'])
```
### ツールを呼び出す
指定されたツールを呼び出します。
```python
async def call_tool(
self,
tool_name: str,
parameters: dict[str, Any],
session: dict[str, Any],
query_id: int,
) -> dict[str, Any]:
"""特定のツールを呼び出す
Args:
tool_name: ツール名(metadata.name)
parameters: ツールパラメータ
session: セッション情報
query_id: クエリ ID
Returns:
ツールの応答 dict
"""
# 使用例
result = await self.plugin.call_tool(
tool_name="get_weather_alerts",
parameters={"state": "CA"},
session={},
query_id=0,
)
print(result)
```
<Tip>
ツール名は `metadata.name`(例: `echo_tool`、`get_weather_alerts`)を使用します。作者やプラグイン名のプレフィックスは不要です。
</Tip>
### プラグイン永続データの設定
プラグインデータを永続的に保存します。このインターフェースを通じて保存されたデータは、このプラグインのみがアクセスできます。値は手動でbytesに変換する必要があります。
+28 -1
View File
@@ -50,7 +50,7 @@ execution:
spec:
config:
- name: github_token # 必須; 設定項目名、プラグイン内での取得に使用
type: string # 必須; 設定項目タイプ、string、integer、float、boolean、select、prompt-editor、llm-model-selector、bot-selectorなどをサポート
type: string # 必須; 設定項目タイプ、string、integer、float、boolean、select、prompt-editor、llm-model-selector、bot-selector、tools-selectorなどをサポート
label: # 必須; 設定項目表示名、多言語サポート。言語コードはRFC 4646標準に従います。
en_US: Github Token
zh_Hans: Github Token
@@ -274,6 +274,33 @@ bot_uuid = self.get_config()['bot']
print(bot_uuid) # 出力: '550e8400-e29b-41d4-a716-446655440000'
```
### type: tools-selector
ツールセレクター。登録済みのツール(プラグインツールおよび MCP ツール)を複数選択できるセレクターを表示します。最終結果はツール名の配列として表現されます。
```yaml
- name: selected_tools
type: tools-selector
...
```
プラグインで選択されたツール名を使用する:
```python
# 設定から選択されたツール名リストを取得
selected_tools = self.get_config()['selected_tools']
print(selected_tools) # 出力: ['get_weather_alerts', 'web_search']
# 選択されたツールを呼び出す
for tool_name in selected_tools:
result = await self.plugin.call_tool(
tool_name=tool_name,
parameters={"query": "hello"},
session={},
query_id=0,
)
```
## 次のステップ
このチュートリアルでは、プラグイン機能を段階的に完成させる方法を案内します。
+147
View File
@@ -2750,6 +2750,113 @@
}
}
}
},
"/api/v1/tools": {
"get": {
"tags": [
"Tools"
],
"summary": "List all available tools",
"description": "List all available tools in the current LangBot instance, including plugin tools and MCP tools.",
"operationId": "listTools",
"security": [
{
"BearerAuth": []
}
],
"responses": {
"200": {
"description": "Success",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"code": {
"type": "integer",
"example": 0
},
"msg": {
"type": "string",
"example": "ok"
},
"data": {
"type": "object",
"properties": {
"tools": {
"type": "array",
"items": {
"$ref": "#/components/schemas/ToolSummary"
}
}
}
}
}
}
}
}
}
}
}
},
"/api/v1/tools/{tool_name}": {
"get": {
"tags": [
"Tools"
],
"summary": "Get tool detail",
"description": "Get detailed information about a specific tool.",
"operationId": "getToolDetail",
"security": [
{
"BearerAuth": []
}
],
"parameters": [
{
"name": "tool_name",
"in": "path",
"required": true,
"schema": {
"type": "string"
},
"description": "Tool name"
}
],
"responses": {
"200": {
"description": "Success",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"code": {
"type": "integer",
"example": 0
},
"msg": {
"type": "string",
"example": "ok"
},
"data": {
"type": "object",
"properties": {
"tool": {
"$ref": "#/components/schemas/ToolSummary"
}
}
}
}
}
}
}
},
"404": {
"description": "Tool not found"
}
}
}
}
},
"components": {
@@ -3175,6 +3282,46 @@
"type": "string"
}
}
},
"ToolSummary": {
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "Tool name"
},
"label": {
"type": "object",
"description": "Display label (i18n)",
"additionalProperties": {
"type": "string"
}
},
"description": {
"type": "object",
"description": "Tool description (i18n)",
"additionalProperties": {
"type": "string"
}
},
"icon": {
"type": "string",
"description": "Tool icon"
},
"spec": {
"type": "object",
"description": "Tool specification",
"properties": {
"llm_prompt": {
"type": "string"
},
"parameters": {
"type": "object",
"description": "JSON Schema for tool parameters"
}
}
}
}
}
},
"responses": {
+147
View File
@@ -2750,6 +2750,113 @@
}
}
}
},
"/api/v1/tools": {
"get": {
"tags": [
"ツール"
],
"summary": "利用可能なツール一覧を取得",
"description": "現在の LangBot インスタンスで利用可能なすべてのツール(プラグインツールおよび MCP ツール)を取得します。",
"operationId": "listTools",
"security": [
{
"BearerAuth": []
}
],
"responses": {
"200": {
"description": "Success",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"code": {
"type": "integer",
"example": 0
},
"msg": {
"type": "string",
"example": "ok"
},
"data": {
"type": "object",
"properties": {
"tools": {
"type": "array",
"items": {
"$ref": "#/components/schemas/ToolSummary"
}
}
}
}
}
}
}
}
}
}
}
},
"/api/v1/tools/{tool_name}": {
"get": {
"tags": [
"ツール"
],
"summary": "ツール詳細を取得",
"description": "指定されたツールの詳細情報を取得します。",
"operationId": "getToolDetail",
"security": [
{
"BearerAuth": []
}
],
"parameters": [
{
"name": "tool_name",
"in": "path",
"required": true,
"schema": {
"type": "string"
},
"description": "ツール名"
}
],
"responses": {
"200": {
"description": "Success",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"code": {
"type": "integer",
"example": 0
},
"msg": {
"type": "string",
"example": "ok"
},
"data": {
"type": "object",
"properties": {
"tool": {
"$ref": "#/components/schemas/ToolSummary"
}
}
}
}
}
}
}
},
"404": {
"description": "Tool not found"
}
}
}
}
},
"components": {
@@ -3175,6 +3282,46 @@
"type": "string"
}
}
},
"ToolSummary": {
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "Tool name"
},
"label": {
"type": "object",
"description": "Display label (i18n)",
"additionalProperties": {
"type": "string"
}
},
"description": {
"type": "object",
"description": "Tool description (i18n)",
"additionalProperties": {
"type": "string"
}
},
"icon": {
"type": "string",
"description": "Tool icon"
},
"spec": {
"type": "object",
"description": "Tool specification",
"properties": {
"llm_prompt": {
"type": "string"
},
"parameters": {
"type": "object",
"description": "JSON Schema for tool parameters"
}
}
}
}
}
},
"responses": {
+1324 -332
View File
File diff suppressed because it is too large Load Diff
+81
View File
@@ -249,6 +249,87 @@ parsers = await self.plugin.list_parsers(mime_type="application/pdf")
# 返回的每项包含 plugin_id、plugin_author、plugin_name、name、description、supported_mime_types
```
### 获取所有可用工具
列出当前 LangBot 实例中所有可用的工具(包括插件工具和 MCP 工具)。
```python
async def list_tools(self) -> list[dict[str, Any]]:
"""List all available tools
Returns:
工具列表,每个元素包含:
- name: 工具名称
- label: 工具显示名称(多语言)
- description: 工具描述(多语言)
- icon: 工具图标
- spec: 工具规格(包含 llm_prompt 和 parameters)
"""
# 调用示例
tools = await self.plugin.list_tools()
for tool in tools:
print(f"Tool: {tool['name']}")
```
### 获取工具详情
获取特定工具的详细信息。
```python
async def get_tool_detail(self, tool_name: str) -> dict[str, Any]:
"""Get detailed information about a specific tool
Args:
tool_name: 工具名称(metadata.name,例如 "get_weather_alerts")
Returns:
工具详情 dict,包含 name、label、description、spec(含 parameters 和 llm_prompt)
"""
# 调用示例
detail = await self.plugin.get_tool_detail("get_weather_alerts")
print(detail['spec']['parameters'])
```
### 调用工具
调用指定的工具。
```python
async def call_tool(
self,
tool_name: str,
parameters: dict[str, Any],
session: dict[str, Any],
query_id: int,
) -> dict[str, Any]:
"""Call a specific tool
Args:
tool_name: 工具名称(metadata.name)
parameters: 工具参数
session: 会话信息
query_id: 查询 ID
Returns:
工具返回的结果 dict
"""
# 调用示例
result = await self.plugin.call_tool(
tool_name="get_weather_alerts",
parameters={"state": "CA"},
session={},
query_id=0,
)
print(result)
```
<Tip>
工具名称使用 `metadata.name`(如 `echo_tool`、`get_weather_alerts`),不需要包含作者或插件名前缀。
</Tip>
### 设置插件持久化数据
持久化存储插件数据。通过这个接口存储的数据,仅可被该插件访问。值需要自行转换为字节。
+28 -1
View File
@@ -50,7 +50,7 @@ execution:
spec:
config:
- name: github_token # 必填;配置项名称,用于在插件中获取
type: string # 必填;配置项类型,支持 string, integer, float, boolean, select, prompt-editor, llm-model-selector, bot-selector 等
type: string # 必填;配置项类型,支持 string, integer, float, boolean, select, prompt-editor, llm-model-selector, bot-selector, tools-selector 等
label: # 必填;配置项显示名称,支持多语言。语言代码采用 RFC 4646 标准。
en_US: Github Token
zh_Hans: Github Token
@@ -274,6 +274,33 @@ bot_uuid = self.get_config()['bot']
print(bot_uuid) # 输出: '550e8400-e29b-41d4-a716-446655440000'
```
### type: tools-selector
工具选择器。会展示一个多选工具选择器,可选择已注册的工具(插件工具和 MCP 工具),最终结果表示为工具名称数组。
```yaml
- name: selected_tools
type: tools-selector
...
```
在插件中使用选中的工具名称:
```python
# 从配置中获取选中的工具名称列表
selected_tools = self.get_config()['selected_tools']
print(selected_tools) # 输出: ['get_weather_alerts', 'web_search']
# 调用选中的工具
for tool_name in selected_tools:
result = await self.plugin.call_tool(
tool_name=tool_name,
parameters={"query": "hello"},
session={},
query_id=0,
)
```
## 接下来做什么
该教程将指引您逐步完善插件功能。