import { createAgent } from '@vibing-ai/sdk/agent';
import { memory } from '@vibing-ai/sdk/memory';
import * as intents from './intents';
import * as tools from './tools';
import { analyzeUserQuery, formatResponse } from './utils';
// Create the agent
const domainExpert = createAgent({
// Configuration from vibe.config.js is automatically included
// Intent handlers
handles: {
'analyze_domain_topic': intents.analyzeDomainTopic,
'explain_domain_concept': intents.explainDomainConcept,
'recommend_resources': intents.recommendResources
},
// Agent-specific tools
tools: {
'domain_knowledge_search': tools.domainKnowledgeSearch,
'concept_graph_lookup': tools.conceptGraphLookup,
'reference_finder': tools.referenceFinder
},
// General message handler for natural language input
onMessage: async (message, context) => {
// Analyze the message to understand user's query
const { intent, parameters } = await analyzeUserQuery(message.text);
// Get agent settings (use defaults if not set)
const settings = await memory.get('private:agent-settings') || {
responseStyle: 'conversational',
detailLevel: 'intermediate',
includeReferences: true
};
let response;
// Handle the intent if recognized
if (intent && this.handles[intent]) {
response = await this.handles[intent](parameters, context);
} else {
// Default handling for unrecognized intents
response = await handleGeneralQuery(message.text, context);
}
// Format the response according to settings
return formatResponse(response, settings);
},
// Handle explicit invocation from Vibing Super Agent
onInvoke: async (request, context) => {
const { intent, parameters } = request;
// Verify this agent can handle the requested intent
if (!this.handles[intent]) {
return {
success: false,
error: `Intent "${intent}" not supported by this agent`
};
}
// Process the request
try {
const result = await this.handles[intent](parameters, context);
return {
success: true,
data: result
};
} catch (error) {
return {
success: false,
error: error.message
};
}
},
// Lifecycle hooks
onInstall: async () => {
// Initialize agent data and settings
await memory.set('private:agent-settings', {
responseStyle: 'conversational',
detailLevel: 'intermediate',
includeReferences: true
});
console.log('Agent installed successfully');
},
onUninstall: async () => {
// Clean up agent data
await memory.delete('private:agent-settings');
console.log('Agent uninstalled successfully');
}
});
// Helper function for general queries
async function handleGeneralQuery(query, context) {
// Implement general query handling
// This might use LLM capabilities, knowledge base, etc.
return {
text: `I'll help you with: "${query}"`,
references: []
};
}
// Export the agent
export default domainExpert;