import { Agent, PraisonAIAgents, createCohereReranker, createPineconeStore } from 'praisonai';
const vectorStore = createPineconeStore({ apiKey: process.env.PINECONE_API_KEY! });
const reranker = createCohereReranker({ apiKey: process.env.COHERE_API_KEY! });
// Agent 1: Retrieves documents
const retriever = new Agent({
name: 'Retriever',
instructions: 'Search the knowledge base and retrieve relevant documents.',
knowledge: { vectorStore, indexName: 'docs' }
});
// Agent 2: Reranks and filters
const ranker = new Agent({
name: 'Ranker',
instructions: 'Evaluate document relevance and select the best ones.',
tools: [createTool({
name: 'rerank_documents',
description: 'Rerank documents by relevance',
parameters: {
type: 'object',
properties: {
query: { type: 'string' },
documents: { type: 'array', items: { type: 'object' } }
},
required: ['query', 'documents']
},
execute: async ({ query, documents }) => {
const reranked = await reranker.rerank(query, documents, { topK: 3 });
return reranked;
}
})]
});
// Agent 3: Answers based on reranked results
const answerer = new Agent({
name: 'Answerer',
instructions: 'Provide accurate answers based on the provided documents.'
});
const agents = new PraisonAIAgents({
agents: [retriever, ranker, answerer],
tasks: [
{ agent: retriever, description: 'Retrieve documents for: {query}' },
{ agent: ranker, description: 'Rerank the retrieved documents' },
{ agent: answerer, description: 'Answer the question using the top documents' }
]
});
await agents.start({ query: 'What are the system requirements?' });