Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.
Python agentagentic-aiagentic-frameworkagentic-workflowaiautomationclaudedeepseekgenaigptllmlow-codemcpnextjsno-codeopenaipythonskillsworkflow
fix: api tool encoding (#2296)
Yeuoly6d24a2cb87e3
diff --git a/api/core/tools/tool/api_tool.py b/api/core/tools/tool/api_tool.pyindex 4328c7d1e94..442109437a1 100644--- a/api/core/tools/tool/api_tool.py+++ b/api/core/tools/tool/api_tool.py@@ -8,6 +8,7 @@ from core.tools.errors import ToolProviderCredentialValidationErrorimport httpximport requests+import jsonclass ApiTool(Tool):api_bundle: ApiBasedToolBundle@@ -79,11 +80,29 @@ class ApiTool(Tool):if isinstance(response, httpx.Response):if response.status_code >= 400:raise ToolProviderCredentialValidationError(f"Request failed with status code {response.status_code}")- return response.text+ if not response.content:+ return 'Empty response from the tool, please check your parameters and try again.'+ try:+ response = response.json()+ try:+ return json.dumps(response, ensure_ascii=False)+ except Exception as e:+ return json.dumps(response)+ except Exception as e:+ return response.textelif isinstance(response, requests.Response):if not response.ok:raise ToolProviderCredentialValidationError(f"Request failed with status code {response.status_code}")- return response.text+ if not response.content:+ return 'Empty response from the tool, please check your parameters and try again.'+ try:+ response = response.json()+ try:+ return json.dumps(response, ensure_ascii=False)+ except Exception as e:+ return json.dumps(response)+ except Exception as e:+ return response.textelse:raise ValueError(f'Invalid response type {type(response)}')diff --git a/api/core/tools/utils/parser.py b/api/core/tools/utils/parser.pyindex f61ac1cbfad..b37ea58a424 100644--- a/api/core/tools/utils/parser.py+++ b/api/core/tools/utils/parser.py@@ -114,6 +114,10 @@ class ApiBasedToolSchemaParser:if count > 1:warning['duplicated_parameter'] = f'Parameter {name} is duplicated.'+ # check if there is a operation id, use $path_$method as operation id if not+ if 'operationId' not in interface['operation']:+ interface['operation']['operationId'] = f'{interface["path"]}_{interface["method"]}'+bundles.append(ApiBasedToolBundle(server_url=server_url + interface['path'],method=interface['method'],diff --git a/api/services/tools_manage_service.py b/api/services/tools_manage_service.pyindex e6348f6ca80..f541957adff 100644--- a/api/services/tools_manage_service.py+++ b/api/services/tools_manage_service.py@@ -485,10 +485,10 @@ class ToolManageService:if schema_type not in [member.value for member in ApiProviderSchemaType]:raise ValueError(f'invalid schema type {schema_type}')- if schema_type == ApiProviderSchemaType.OPENAPI.value:- tool_bundles = ApiBasedToolSchemaParser.parse_openapi_yaml_to_tool_bundle(schema)- else:- raise ValueError(f'invalid schema type {schema_type}')+ try:+ tool_bundles, _ = ApiBasedToolSchemaParser.auto_parse_to_tool_bundle(schema)+ except Exception as e:+ raise ValueError(f'invalid schema')# get tool bundletool_bundle = next(filter(lambda tb: tb.operation_id == tool_name, tool_bundles), None)