taskforce-aiagent
Version:
TaskForce is a modular, open-source, production-ready TypeScript agent framework for orchestrating AI agents, LLM-powered autonomous agents, task pipelines, dynamic toolchains, RAG workflows and memory/retrieval systems.
49 lines (48 loc) • 1.85 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.LangChainVectorMemoryProvider = void 0;
const memory_1 = require("langchain/vectorstores/memory");
const openai_1 = require("@langchain/openai");
const document_1 = require("langchain/document");
const enum_js_1 = require("../../../configs/enum.js");
class LangChainVectorMemoryProvider {
constructor() {
this.records = [];
this.vectorStore = new memory_1.MemoryVectorStore(new openai_1.OpenAIEmbeddings());
}
async storeMemory(record) {
const isDuplicate = this.records.some((r) => r.output === record.output && r.taskId === record.taskId);
if (isDuplicate)
return;
const doc = new document_1.Document({
pageContent: record.output,
metadata: {
taskId: record.taskId,
input: record.input,
...record.metadata,
},
});
await this.vectorStore.addDocuments([doc]);
this.records.push(record);
}
async loadRelevantMemory(query, limit = 3, filter) {
const results = await this.vectorStore.similaritySearch(query, limit);
return results
.map((res) => ({
taskId: res.metadata.taskId,
input: res.metadata.input,
output: res.pageContent,
metadata: res.metadata,
}))
.filter((r) => (!filter?.agent || r.metadata?.agent === filter.agent) &&
(!filter?.taskId || r.taskId === filter.taskId));
}
async clearMemory() {
this.vectorStore = new memory_1.MemoryVectorStore(new openai_1.OpenAIEmbeddings());
this.records = [];
}
getMemoryScope() {
return enum_js_1.MemoryScope.Short;
}
}
exports.LangChainVectorMemoryProvider = LangChainVectorMemoryProvider;