import SimpleRAG from './rag.js';
class RAGAgent {
constructor() {
this.name = "RAG Agent";
this.rag = new SimpleRAG();
this.initialized = false;
}
async init() {
if (!this.initialized) {
await this.rag.init();
this.initialized = true;
}
}
async setupKnowledgeBase(filePaths) {
await this.init();
return await this.rag.addKnowledgeBase(filePaths);
}
async addDocument(filePath) {
await this.init();
return await this.rag.addDocument(filePath);
}
async addWebPage(url) {
await this.init();
return await this.rag.addWebPage(url);
}
async addWebPages(urls) {
await this.init();
return await this.rag.addWebPages(urls);
}
async run(query) {
await this.init();
try {
const result = await this.rag.query(query);
return {
agent: this.name,
success: true,
...result
};
} catch (error) {
return {
agent: this.name,
success: false,
query,
error: error.message
};
}
}
async clearKnowledgeBase() {
await this.init();
return await this.rag.clearKnowledgeBase();
}
toString() {
return this.name;
}
}
export default RAGAgent;