import { Agent, createTool, createPineconeStore } from 'praisonai';
const vectorStore = createPineconeStore({
apiKey: process.env.PINECONE_API_KEY!
});
const addToKnowledge = createTool({
name: 'add_to_knowledge',
description: 'Add new information to the knowledge base',
parameters: {
type: 'object',
properties: {
content: { type: 'string', description: 'Content to store' },
source: { type: 'string', description: 'Source of the information' }
},
required: ['content', 'source']
},
execute: async ({ content, source }) => {
const embedding = await getEmbedding(content);
await vectorStore.upsert({
indexName: 'documents',
vectors: [{
id: `doc-${Date.now()}`,
vector: embedding,
content,
metadata: { source, addedAt: new Date().toISOString() }
}]
});
return `Added to knowledge base from ${source}`;
}
});
const learningAgent = new Agent({
name: 'Learning Agent',
instructions: 'Learn new information and store it in the knowledge base.',
tools: [addToKnowledge]
});