agentis
Version:
A TypeScript framework for building sophisticated multi-agent systems
85 lines (79 loc) • 3.22 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.GoalPlanner = void 0;
const OpenRouterTool_1 = require("../tools/OpenRouterTool");
const EnhancedMemoryClient_1 = require("../memory/EnhancedMemoryClient");
const ToolRegistry_1 = require("../tools/ToolRegistry");
class GoalPlanner {
constructor(id = 'goal-planner-1', name = 'GoalPlanner', lore = 'I am a strategic goal planner that analyzes user requests and determines whether to create new goals or use existing context.', role = 'Goal Planning Strategist', goals = ['Optimize agent responses', 'Maintain conversation context', 'Create efficient goals'], tools = [new OpenRouterTool_1.OpenRouterTool()]) {
this.middlewares = [];
this.id = id;
this.name = name;
this.lore = lore;
this.role = role;
this.goals = goals;
this.tools = tools;
this.shortTermMemory = {};
this.longTermMemory = {};
this.memoryClient = new EnhancedMemoryClient_1.EnhancedMemoryClient();
this.toolRegistry = new ToolRegistry_1.ToolRegistry({ defaultTools: tools });
}
async analyzeRequest(message, conversationContext) {
const tool = this.tools[0];
const planningPrompt = `
You are a strategic goal planner with access to real-time data and analysis capabilities.
Current date: ${new Date().toISOString()}
Previous conversation context:
${conversationContext.join('\n')}
New user message: ${message}
Analyze whether this message:
1. Requires a new research/analysis goal
2. Can be answered using existing conversation context
3. Is a follow-up question to previous discussion
You have the capability to analyze market data, research information, and provide concrete insights.
Don't be overly cautious - use your capabilities to provide meaningful analysis.
Return ONLY a JSON object in this format:
{
"requiresNewGoal": boolean,
"useExistingContext": boolean,
"suggestedGoal": string | null,
"reasoning": string,
"contextualResponse": string | null
}
`;
const response = await tool.execute(planningPrompt);
return JSON.parse(response.result);
}
// Implement required IAgent interface methods
async receiveMessage(message) {
return {
id: `msg-${Date.now()}`,
sender_id: this.id,
recipient_id: message.sender_id,
content: 'Goal planning complete',
timestamp: Date.now()
};
}
async executeTask(task) {
// Goal planner doesn't execute tasks directly
console.log('Task execution requested:', task);
}
async sendMessage(message) {
console.log('Message sent:', message);
}
async initializeMemory() {
// Initialize memory if needed
this.shortTermMemory = {};
this.longTermMemory = {};
}
useMiddleware(middleware) {
this.middlewares.push(middleware);
}
getMemoryClient() {
return this.memoryClient;
}
getToolRegistry() {
return this.toolRegistry;
}
}
exports.GoalPlanner = GoalPlanner;