feat: backwards invoke tools

This commit is contained in:
Yeuoly
2024-10-10 18:09:06 +08:00
parent 699d41deec
commit 118fa66567
7 changed files with 99 additions and 16 deletions

View File

@ -378,6 +378,7 @@ class ToolInvokeFrom(Enum):
WORKFLOW = "workflow"
AGENT = "agent"
PLUGIN = "plugin"
class ToolProviderID:

View File

@ -131,7 +131,7 @@ class ToolEngine:
return error_response, [], ToolInvokeMeta.error_instance(error_response)
@staticmethod
def workflow_invoke(
def generic_invoke(
tool: Tool,
tool_parameters: dict[str, Any],
user_id: str,

View File

@ -365,6 +365,40 @@ class ToolManager:
tool_runtime.runtime.runtime_parameters.update(runtime_parameters)
return tool_runtime
@classmethod
def get_tool_runtime_from_plugin(
cls,
tool_type: ToolProviderType,
tenant_id: str,
provider: str,
tool_name: str,
tool_parameters: dict[str, Any],
) -> Tool:
"""
get tool runtime from plugin
"""
tool_entity = cls.get_tool_runtime(
provider_type=tool_type,
provider_id=provider,
tool_name=tool_name,
tenant_id=tenant_id,
invoke_from=InvokeFrom.SERVICE_API,
tool_invoke_from=ToolInvokeFrom.PLUGIN,
)
runtime_parameters = {}
parameters = tool_entity.get_merged_runtime_parameters()
for parameter in parameters:
if parameter.form == ToolParameter.ToolParameterForm.FORM:
# save tool parameter to tool entity memory
value = cls._init_runtime_parameter(parameter, tool_parameters)
runtime_parameters[parameter.name] = value
if not tool_entity.runtime:
raise Exception("tool missing runtime")
tool_entity.runtime.runtime_parameters.update(runtime_parameters)
return tool_entity
@classmethod
def get_builtin_provider_icon(cls, provider: str, tenant_id: str) -> tuple[str, str]:
"""