diff options
Diffstat (limited to 'src/client/views/nodes/chatbot/agentsystem/Agent.ts')
-rw-r--r-- | src/client/views/nodes/chatbot/agentsystem/Agent.ts | 37 |
1 files changed, 17 insertions, 20 deletions
diff --git a/src/client/views/nodes/chatbot/agentsystem/Agent.ts b/src/client/views/nodes/chatbot/agentsystem/Agent.ts index 6ef52c0f5..6c48820aa 100644 --- a/src/client/views/nodes/chatbot/agentsystem/Agent.ts +++ b/src/client/views/nodes/chatbot/agentsystem/Agent.ts @@ -7,31 +7,31 @@ import { AnswerParser } from '../response_parsers/AnswerParser'; import { StreamedAnswerParser } from '../response_parsers/StreamedAnswerParser'; import { BaseTool } from '../tools/BaseTool'; import { CalculateTool } from '../tools/CalculateTool'; +//import { CreateAnyDocumentTool } from '../tools/CreateAnyDocTool'; import { DataAnalysisTool } from '../tools/DataAnalysisTool'; import { DocumentMetadataTool } from '../tools/DocumentMetadataTool'; +import { ImageCreationTool } from '../tools/ImageCreationTool'; import { NoTool } from '../tools/NoTool'; import { SearchTool } from '../tools/SearchTool'; import { Parameter, ParametersType, TypeMap } from '../types/tool_types'; import { AgentMessage, ASSISTANT_ROLE, AssistantMessage, Observation, PROCESSING_TYPE, ProcessingInfo, TEXT_TYPE } from '../types/types'; import { Vectorstore } from '../vectorstore/Vectorstore'; import { getReactPrompt } from './prompts'; +//import { DictionaryTool } from '../tools/DictionaryTool'; import { ChatCompletionMessageParam } from 'openai/resources'; -import { Doc } from '../../../../../fields/Doc'; -import { ChatBox, parsedDoc } from '../chatboxcomponents/ChatBox'; -import { WebsiteInfoScraperTool } from '../tools/WebsiteInfoScraperTool'; import { Upload } from '../../../../../server/SharedMediaTypes'; -import { RAGTool } from '../tools/RAGTool'; -import { AgentDocumentManager } from '../utils/AgentDocumentManager'; -import { CreateLinksTool } from '../tools/CreateLinksTool'; +import { DocumentView } from '../../DocumentView'; import { CodebaseSummarySearchTool } from '../tools/CodebaseSummarySearchTool'; +import { CreateLinksTool } from '../tools/CreateLinksTool'; +import { CreateNewTool } from '../tools/CreateNewTool'; import { FileContentTool } from '../tools/FileContentTool'; import { FileNamesTool } from '../tools/FileNamesTool'; -import { CreateNewTool } from '../tools/CreateNewTool'; -import { SortDocsTool} from '../tools/SortDocsTool'; +import { RAGTool } from '../tools/RAGTool'; +import { SortDocsTool } from '../tools/SortDocsTool'; import { TagDocsTool } from '../tools/TagDocsTool'; import { GPTTutorialTool } from '../tools/TutorialTool'; -import { ImageCreationTool } from '../tools/ImageCreationTool'; -import { DocumentView } from '../../DocumentView'; +import { WebsiteInfoScraperTool } from '../tools/WebsiteInfoScraperTool'; +import { AgentDocumentManager } from '../utils/AgentDocumentManager'; dotenv.config(); @@ -80,8 +80,7 @@ export class Agent { csvData: () => { filename: string; id: string; text: string }[], createImage: (result: Upload.FileInformation & Upload.InspectionResults, options: DocumentOptions) => void, createCSVInDash: (url: string, title: string, id: string, data: string) => void, - docManager: AgentDocumentManager, - isDashDocAssistant: boolean + docManager: AgentDocumentManager ) { // Initialize OpenAI client with API key from environment this.client = new OpenAI({ apiKey: process.env.OPENAI_KEY, dangerouslyAllowBrowser: true }); @@ -90,7 +89,6 @@ export class Agent { this._history = history; this._csvData = csvData; this._docManager = docManager; - this.is_dash_doc_assistant = isDashDocAssistant; // Initialize dynamic tool registry this.dynamicToolRegistry = new Map(); @@ -151,7 +149,7 @@ export class Agent { const instance: BaseTool<ReadonlyArray<Parameter>> = new ToolClass(); - // Prefer the tool's self-declared name (matches <action> tag) + // Prefer the tool’s self-declared name (matches <action> tag) const key = (instance.name || '').trim() || legacyKey; // Check for duplicates @@ -306,7 +304,7 @@ export class Agent { ignoreAttributes: false, attributeNamePrefix: '@_', textNodeName: '_text', - isArray: name => name === 'url', + isArray: name => ['query', 'url'].indexOf(name) !== -1, processEntities: false, // Disable processing of entities stopNodes: ['*.entity'], // Do not process any entities }); @@ -350,7 +348,6 @@ export class Agent { console.log(`Thought: ${stage[key]}`); this.processingNumber++; } else if (key === 'action') { - // Handle action stage currentAction = stage[key] as string; console.log(`Action: ${currentAction}`); @@ -361,14 +358,14 @@ export class Agent { // Immediately ask for clarification in plain text, not as a tool prompt this.interMessages.push({ role: 'user', - content: `<stage number="${i+1}" role="assistant"> + content: `<stage number="${i + 1}" role="assistant"> <answer> I’m not sure what you’d like me to do. Could you clarify your request? </answer> - </stage>` + </stage>`, }); break; - } + } if (tool) { // Prepare the next action based on the current tool const nextPrompt = [ @@ -780,7 +777,7 @@ export class Agent { const docSummaries = () => JSON.stringify(this._docManager.listDocs); const chatHistory = this._history(); - return getReactPrompt(allTools, docSummaries, chatHistory, this.is_dash_doc_assistant); + return getReactPrompt(allTools, docSummaries, chatHistory); } /** |