diff options
| author | sharkiecodes <lanyi_stroud@brown.edu> | 2025-07-02 20:33:37 -0400 |
|---|---|---|
| committer | sharkiecodes <lanyi_stroud@brown.edu> | 2025-07-02 20:33:37 -0400 |
| commit | f0807c6f6c31ac9ae2e6fb581f19a760f8e5687e (patch) | |
| tree | 2e12315621bb361210ce5b6beaa7165da7ddc5ab /src/client/views/nodes/chatbot/agentsystem | |
| parent | f49fa5010ac53eb87925d1cd40e3be145d441ea6 (diff) | |
Implementing replacement of GPTPopup
Diffstat (limited to 'src/client/views/nodes/chatbot/agentsystem')
| -rw-r--r-- | src/client/views/nodes/chatbot/agentsystem/Agent.ts | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/src/client/views/nodes/chatbot/agentsystem/Agent.ts b/src/client/views/nodes/chatbot/agentsystem/Agent.ts index 3acdc6aa8..d7aee51e6 100644 --- a/src/client/views/nodes/chatbot/agentsystem/Agent.ts +++ b/src/client/views/nodes/chatbot/agentsystem/Agent.ts @@ -30,6 +30,7 @@ import { CreateNewTool } from '../tools/CreateNewTool'; import { SortDocsTool} from '../tools/SortDocsTool'; import { TagDocsTool } from '../tools/TagDocsTool'; import { GPTTutorialTool } from '../tools/TutorialTool'; +import { DocumentView } from '../../DocumentView'; dotenv.config(); @@ -53,6 +54,7 @@ export class Agent { private tools: Record<string, BaseTool<ReadonlyArray<Parameter>>>; private _docManager: AgentDocumentManager; private is_dash_doc_assistant: boolean; + private parentView: DocumentView; // Dynamic tool registry for tools created at runtime private dynamicToolRegistry: Map<string, BaseTool<ReadonlyArray<Parameter>>> = new Map(); // Callback for notifying when tools are created and need reload @@ -83,6 +85,7 @@ export class Agent { // Initialize OpenAI client with API key from environment this.client = new OpenAI({ apiKey: process.env.OPENAI_KEY, dangerouslyAllowBrowser: true }); this.vectorstore = _vectorstore; + this.parentView = docManager.parentViewDocument; // Get the parent DocumentView this._history = history; this._csvData = csvData; this._docManager = docManager; @@ -106,7 +109,7 @@ export class Agent { fileContent: new FileContentTool(this.vectorstore), fileNames: new FileNamesTool(this.vectorstore), generateTutorialNode: new GPTTutorialTool(this._docManager), - sortDocs: new SortDocsTool(this._docManager), + sortDocs: new SortDocsTool(this._docManager, this.parentView), tagDocs: new TagDocsTool(this._docManager), }; @@ -346,13 +349,25 @@ 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}`); // Check both static tools and dynamic registry const tool = this.tools[currentAction] || this.dynamicToolRegistry.get(currentAction); - + if (currentAction === 'noTool') { + // Immediately ask for clarification in plain text, not as a tool prompt + this.interMessages.push({ + role: 'user', + 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>` + }); + break; + } if (tool) { // Prepare the next action based on the current tool const nextPrompt = [ |
