mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-08-12 13:50:59 +00:00
feat: switch tool entities and format
This commit is contained in:
@@ -7,8 +7,9 @@ from mcp import ClientSession, StdioServerParameters
|
||||
from mcp.client.stdio import stdio_client
|
||||
from mcp.client.sse import sse_client
|
||||
|
||||
from .. import loader, entities as tools_entities
|
||||
from .. import loader
|
||||
from ....core import app, entities as core_entities
|
||||
import langbot_plugin.api.entities.builtin.resource.tool as resource_tool
|
||||
|
||||
|
||||
class RuntimeMCPSession:
|
||||
@@ -24,7 +25,7 @@ class RuntimeMCPSession:
|
||||
|
||||
exit_stack: AsyncExitStack
|
||||
|
||||
functions: list[tools_entities.LLMFunction] = []
|
||||
functions: list[resource_tool.LLMTool] = []
|
||||
|
||||
def __init__(self, server_name: str, server_config: dict, ap: app.Application):
|
||||
self.server_name = server_name
|
||||
@@ -91,7 +92,7 @@ class RuntimeMCPSession:
|
||||
func.__name__ = tool.name
|
||||
|
||||
self.functions.append(
|
||||
tools_entities.LLMFunction(
|
||||
resource_tool.LLMTool(
|
||||
name=tool.name,
|
||||
human_desc=tool.description,
|
||||
description=tool.description,
|
||||
@@ -114,7 +115,7 @@ class MCPLoader(loader.ToolLoader):
|
||||
|
||||
sessions: dict[str, RuntimeMCPSession] = {}
|
||||
|
||||
_last_listed_functions: list[tools_entities.LLMFunction] = []
|
||||
_last_listed_functions: list[resource_tool.LLMTool] = []
|
||||
|
||||
def __init__(self, ap: app.Application):
|
||||
super().__init__(ap)
|
||||
@@ -130,7 +131,7 @@ class MCPLoader(loader.ToolLoader):
|
||||
# self.ap.event_loop.create_task(session.initialize())
|
||||
self.sessions[server_config['name']] = session
|
||||
|
||||
async def get_tools(self, enabled: bool = True) -> list[tools_entities.LLMFunction]:
|
||||
async def get_tools(self, enabled: bool = True) -> list[resource_tool.LLMTool]:
|
||||
all_functions = []
|
||||
|
||||
for session in self.sessions.values():
|
||||
|
||||
@@ -3,9 +3,10 @@ from __future__ import annotations
|
||||
import typing
|
||||
import traceback
|
||||
|
||||
from .. import loader, entities as tools_entities
|
||||
from .. import loader
|
||||
from ....core import entities as core_entities
|
||||
from ....plugin import context as plugin_context
|
||||
import langbot_plugin.api.entities.builtin.resource.tool as resource_tool
|
||||
|
||||
|
||||
@loader.loader_class('plugin-tool-loader')
|
||||
@@ -15,9 +16,9 @@ class PluginToolLoader(loader.ToolLoader):
|
||||
本加载器中不存储工具信息,仅负责从插件系统中获取工具信息。
|
||||
"""
|
||||
|
||||
async def get_tools(self, enabled: bool = True) -> list[tools_entities.LLMFunction]:
|
||||
async def get_tools(self, enabled: bool = True) -> list[resource_tool.LLMTool]:
|
||||
# 从插件系统获取工具(内容函数)
|
||||
all_functions: list[tools_entities.LLMFunction] = []
|
||||
all_functions: list[resource_tool.LLMTool] = []
|
||||
|
||||
for plugin in self.ap.plugin_mgr.plugins(
|
||||
enabled=enabled, status=plugin_context.RuntimeContainerStatus.INITIALIZED
|
||||
@@ -38,7 +39,7 @@ class PluginToolLoader(loader.ToolLoader):
|
||||
|
||||
async def _get_function_and_plugin(
|
||||
self, name: str
|
||||
) -> typing.Tuple[tools_entities.LLMFunction, plugin_context.BasePlugin]:
|
||||
) -> typing.Tuple[resource_tool.LLMTool, plugin_context.BasePlugin]:
|
||||
"""获取函数和插件实例"""
|
||||
for plugin in self.ap.plugin_mgr.plugins(
|
||||
enabled=True, status=plugin_context.RuntimeContainerStatus.INITIALIZED
|
||||
|
||||
Reference in New Issue
Block a user