Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

🐛 fix: return structured error from invokeBuiltinTool instead of undefined (#13020)

Arvin Xu69accd11dff2
diff --git a/src/store/chat/agents/createAgentExecutors.ts b/src/store/chat/agents/createAgentExecutors.ts
index b5376c4a94d..f3421cc91bc 100644
--- a/src/store/chat/agents/createAgentExecutors.ts
+++ b/src/store/chat/agents/createAgentExecutors.ts
@@ -817,6 +817,28 @@ export const createAgentExecutors = (context: {
context.get().completeOperation(executeToolOpId);
const executionTime = Math.round(performance.now() - startTime);
+
+ // Fallback for undefined result (e.g. tool executor not found or returned nothing)
+ if (result === undefined || result === null) {
+ const fallbackResult = {
+ content: `Tool ${toolName} execution failed: no result returned`,
+ error: { type: 'ToolExecutionError', message: 'Tool returned no result' },
+ success: false,
+ };
+
+ if (toolOperationId) {
+ context.get().failOperation(toolOperationId, {
+ message: 'Tool returned no result',
+ type: 'ToolExecutionError',
+ });
+ }
+
+ events.push({ id: chatToolPayload.id, result: fallbackResult, type: 'tool_result' });
+
+ const updatedMessages = context.get().dbMessagesMap[context.messageKey] || [];
+ return { events, newState: { ...state, messages: updatedMessages } };
+ }
+
const isSuccess = result && !result.error;
log(
diff --git a/src/store/chat/slices/plugin/actions/pluginTypes.ts b/src/store/chat/slices/plugin/actions/pluginTypes.ts
index e10771371d3..2cc69b5348e 100644
--- a/src/store/chat/slices/plugin/actions/pluginTypes.ts
+++ b/src/store/chat/slices/plugin/actions/pluginTypes.ts
@@ -178,7 +178,11 @@ export class PluginTypesActionImpl {
console.error(
`[invokeBuiltinTool] No executor found for: ${payload.identifier}/${payload.apiName}`,
);
- return;
+ return {
+ content: `Tool ${payload.identifier}/${payload.apiName} is not available`,
+ error: { type: 'ToolNotFound', message: 'No executor found' },
+ success: false,
+ };
};
invokeDefaultTypePlugin = async (id: string, payload: any): Promise<string | undefined> => {