feat: tool loader abstraction

This commit is contained in:
Junyan Qin
2025-03-19 09:36:03 +08:00
parent dea5cc9c0c
commit 97603e8441
5 changed files with 118 additions and 58 deletions
+13 -3
View File
@@ -3,11 +3,11 @@ from __future__ import annotations
import abc
import typing
from ...core import app
from ...core import app, entities as core_entities
from . import entities as tools_entities
preregistered_loaders = []
preregistered_loaders: list[typing.Type[ToolLoader]] = []
def loader_class(name: str):
"""注册一个工具加载器
@@ -34,6 +34,16 @@ class ToolLoader(abc.ABC):
pass
@abc.abstractmethod
def get_tools(self) -> list[tools_entities.LLMFunction]:
async def get_tools(self, enabled: bool=True) -> list[tools_entities.LLMFunction]:
"""获取所有工具"""
pass
@abc.abstractmethod
async def has_tool(self, name: str) -> bool:
"""检查工具是否存在"""
pass
@abc.abstractmethod
async def invoke_tool(self, query: core_entities.Query, name: str, parameters: dict) -> typing.Any:
"""执行工具调用"""
pass