mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-10-30 04:15:45 +08:00
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:
@@ -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に変換する必要があります。
|
||||
|
||||
@@ -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,
|
||||
)
|
||||
```
|
||||
|
||||
## 次のステップ
|
||||
|
||||
このチュートリアルでは、プラグイン機能を段階的に完成させる方法を案内します。
|
||||
|
||||
Reference in New Issue
Block a user