diff options
-rw-r--r-- | src/client/views/nodes/chatbot/agentsystem/Agent.ts | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/src/client/views/nodes/chatbot/agentsystem/Agent.ts b/src/client/views/nodes/chatbot/agentsystem/Agent.ts index b166254bb..43faf5bf4 100644 --- a/src/client/views/nodes/chatbot/agentsystem/Agent.ts +++ b/src/client/views/nodes/chatbot/agentsystem/Agent.ts @@ -103,7 +103,14 @@ export class Agent { // Check if the question exceeds the maximum length if (question.length > MAX_QUERY_LENGTH) { - return { role: ASSISTANT_ROLE.ASSISTANT, content: [{ text: 'User query too long. Please shorten your question and try again.', index: 0, type: TEXT_TYPE.NORMAL, citation_ids: null }], processing_info: [] }; + const errorText = `Your query is too long (${question.length} characters). Please shorten it to ${MAX_QUERY_LENGTH} characters or less and try again.`; + console.warn(errorText); // Log the specific reason + return { + role: ASSISTANT_ROLE.ASSISTANT, + // Use ERROR type for clarity in the UI if handled differently + content: [{ text: errorText, index: 0, type: TEXT_TYPE.ERROR, citation_ids: null }], + processing_info: [], + }; } const sanitizedQuestion = escape(question); // Sanitized user input @@ -210,9 +217,25 @@ export class Agent { console.log(observation); this.interMessages.push({ role: 'user', content: nextPrompt }); this.processingNumber++; + console.log(`Tool ${currentAction} executed successfully. Observations:`, observation); + break; } catch (error) { - throw new Error(`Error processing action: ${error}`); + console.error(`Error during execution of tool '${currentAction}':`, error); + const errorMessage = error instanceof Error ? error.message : String(error); + // Return an error observation formatted for the LLM loop + return { + role: ASSISTANT_ROLE.USER, + content: [ + { + type: TEXT_TYPE.ERROR, + text: `<observation><error tool="${currentAction}">Execution failed: ${escape(errorMessage)}</error></observation>`, + index: 0, + citation_ids: null, + }, + ], + processing_info: [], + }; } } else { throw new Error('Error: Action input without a valid action'); |