UNPKG

regent-ai

Version:

An AI multi-agent orchestration framework

71 lines 2.89 kB
import { getChatCompletion } from "../utils/ChatCompletionUtils"; import { verboseLog, logEntries } from "../utils/Logger"; export class BaseAgent { constructor(name, description, systemMessage) { this.name = name; this.description = description; this.systemMessage = systemMessage; } getToolsFromToolObjects(toolObjects) { return toolObjects.map((toolObject) => toolObject.tool); } async _getCompletion(messages, conversationId // HERE! ) { // completionResult const cr = await getChatCompletion({ messages: messages, ...this.options, tools: this.getTools(), }); const firstChoice = cr.choices[0]; const fcmessage = firstChoice.message; // Create a JSON object with the same information const logEntry = { conversationId, agent: this.name, lastInputMessage: messages[messages.length - 1], completionInfo: { completionChoicesCount: cr.choices.length ?? 0, finishReason: firstChoice.finish_reason || null, toolsCallCount: fcmessage.tool_calls?.length || 0, toolCall: fcmessage.tool_calls?.length > 0 ? { functionName: fcmessage.tool_calls[0].function.name, functionArguments: fcmessage.tool_calls[0].function.arguments, } : null, content: fcmessage.content || null, }, usage: cr.usage, _inputMessages: messages, // completion: cr, }; // Log the information verboseLog(`Agent:`, this.name); verboseLog(`Completion choices count:`, logEntry.completionInfo.completionChoicesCount); if (logEntry.completionInfo.finishReason) verboseLog(`Finish reason:`, logEntry.completionInfo.finishReason); verboseLog(`Tools call count:`, logEntry.completionInfo.toolsCallCount); if (logEntry.completionInfo.toolCall) verboseLog(`Tool call:`, logEntry.completionInfo.toolCall.functionName, logEntry.completionInfo.toolCall.functionArguments); if (logEntry.completionInfo.content) verboseLog(`Content:`, logEntry.completionInfo.content); if (!logEntries.has(conversationId)) { logEntries.set(conversationId, []); } logEntries.get(conversationId).push(logEntry); return { completion: cr, logEntry, }; } updateContextLog(currentContext, content) { if (!currentContext) currentContext = {}; if (!currentContext.log) currentContext.log = []; currentContext.log.push(content); return currentContext; } } //# sourceMappingURL=Agent.js.map