Skip to content

Commit e8ba25f

Browse files
author
mike dupont
committed
now the memory manager is being loaded
1 parent 63ac45a commit e8ba25f

File tree

6 files changed

+3044
-5092
lines changed

6 files changed

+3044
-5092
lines changed

.github/workflows/ci.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
check:
99
runs-on: ubuntu-latest
1010
env:
11-
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
11+
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
1212
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
1313
TURBO_TEAM: ${{ vars.TURBO_TEAM }}
1414
TURBO_REMOTE_ONLY: true

pnpm-lock.yaml

+2,955-4,996
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/jsdoc-automation/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"start": "node dist/index.js",
1313
"dbg": "node --inspect-brk --loader ts-node/esm src/index.ts",
1414
"dbg2": "node --inspect --loader ts-node/esm src/index.ts",
15-
"ts": "node --trace-warnings --trace-deprecation --loader ts-node/esm src/index.ts",
15+
"dbg3": "npx --node-options=--inspect-brk tsx ./src/index",
16+
"ts": "npx tsx src/index",
1617
"clean": "rm -rf node_modules dist"
1718
},
1819
"keywords": [],

scripts/jsdoc-automation/src/AIService/AIService.ts

+67-94
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import dotenv from "dotenv";
1+
import * as dotenv from "dotenv";
22
const de = dotenv.config();
33
console.log("DEBUG",de)
44

@@ -49,6 +49,8 @@ import {
4949
stringToUuid,
5050
getEmbeddingZeroVector,
5151
composeActionExamples,
52+
MemoryManager,
53+
IMemoryManager,
5254
// validateCharacterConfig,
5355
} from "@elizaos/core";
5456
//import { defaultCharacter } from "./defaultCharacter.ts";
@@ -129,6 +131,7 @@ Response format should be formatted in a JSON block like this:
129131
// import { TypeScriptParser } from "../TypeScriptParser.js";
130132
// This is the retriever we will use in RAG
131133
import { CodeFormatter } from "./utils/CodeFormatter.js";
134+
import { run } from "node:test";
132135
//import { CustomErrorParams, InputTypeOfTupleWithRest, IssueData, OutputTypeOfTupleWithRest, ParseParams, ParsePathComponent, ParseStatus, RefinementCtx, RefinementEffect, SafeParseReturnType, z, ZodBranded, ZodCatch, ZodCustomIssue, ZodDefault, ZodEffects, ZodError, ZodIntersection, ZodInvalidArgumentsIssue, ZodInvalidDateIssue, ZodInvalidEnumValueIssue, ZodInvalidIntersectionTypesIssue, ZodInvalidLiteralIssue, ZodInvalidReturnTypeIssue, ZodInvalidStringIssue, ZodInvalidUnionDiscriminatorIssue, ZodInvalidUnionIssue, ZodIssueBase, ZodIssueCode, ZodNotFiniteIssue, ZodNotMultipleOfIssue, ZodOptionalDef, ZodParsedType, ZodPipeline, ZodPromise, ZodReadonly, ZodTooBigIssue, ZodTooSmallIssue, ZodTupleDef, ZodUnion, ZodUnrecognizedKeysIssue } from "zod";
133136
//import { StructuredToolInterface, StructuredToolParams } from "@langchain/core/tools.js";
134137
//import { ToolChoice } from "@langchain/core/language_models/chat_models.js";
@@ -175,9 +178,10 @@ export class AIService {
175178
private chatModel: ChatWrapper; //<ChatOpenAICallOptions>
176179
private codeFormatter: CodeFormatter;
177180
private chatModelFAQ: ChatWrapper;// <ChatOpenAICallOptions>
178-
//runtime: AgentRuntime;
181+
179182
private agents: Map<string, IAgentRuntime>; // container management
180183
runtime: AgentRuntime;
184+
knowledgeManager: IMemoryManager;
181185

182186
/**
183187
* Constructor for initializing the ChatOpenAI instance.
@@ -213,51 +217,36 @@ export class AIService {
213217
// this.chatModelFAQ = new FakeListChatModel({ responses: [] });
214218
this.codeFormatter = new CodeFormatter();
215219

220+
221+
216222
this.agents = new Map();
217223
const token = "token";
218224
const character = defaultCharacter;
225+
226+
219227
this.runtime = new AgentRuntime({token,
220228
modelProvider: character.modelProvider,
221229
evaluators: [],
222230
character,
231+
223232
// character.plugins are handled when clients are added
224233
plugins: [bootstrapPlugin].flat().filter(Boolean),
225234
providers: [],
226-
managers: [],
235+
managers: [
236+
// memeory menages
237+
238+
],
227239
fetch: logFetch,})
228-
//{
229-
// agentId: "00000000-0000-0000-0000-000000000000",
230-
// serverUrl: "http://localhost",
231-
// databaseAdapter: {} as IDatabaseAdapter,
232-
// token: "token",
233-
// function getMemoryManager(manager: string): IMemoryManager | null {
234-
// if (manager === 'someCondition') {
235-
// return {
236-
// runtime: 'someRuntime',
237-
// tableName: 'someTableName',
238-
// getMemories: async () => {
239-
// // Implementation here
240-
// return [];
241-
// },
242-
// getCachedEmbeddings: async () => {
243-
// // Implementation here
244-
// return [];
245-
// },
246-
// addEmbeddingToMemory: async (data: any) => {
247-
// // Implementation here
248-
// return {};
249-
// },
250-
// createMemory: async (memory: any) => {
251-
// // Implementation here
252-
// },
253-
// // Add other properties and methods as required
254-
// };
255-
// }
256-
// return null;
257-
// }
258-
// };
259-
// }
260-
}
240+
this.knowledgeManager = new MemoryManager({
241+
runtime: this.runtime,
242+
tableName: "lore",
243+
});
244+
console.log("KM",this.runtime.knowledgeManager)
245+
console.log("Before",this.runtime.memoryManagers)
246+
this.runtime.memoryManagers.set(this.runtime.knowledgeManager.tableName, this.runtime.knowledgeManager);
247+
console.log("After",this.runtime.memoryManagers)
248+
}
249+
261250

262251
/**
263252
* Generates a comment based on the specified prompt by invoking the chat model.
@@ -278,32 +267,14 @@ export class AIService {
278267

279268
//characters = new Character()
280269

281-
let runtime = this.agents.get(agentId);
270+
//let runtime = this.agents.get(agentId);
271+
let runtime = this.runtime;
282272
if (!runtime) {
283-
const character = defaultCharacter;
284-
runtime = new AgentRuntime({
285-
token,
286-
modelProvider: character.modelProvider,
287-
evaluators: [],
288-
character,
289-
// character.plugins are handled when clients are added
290-
plugins: [
291-
//bootstrapPlugin
292-
].flat().filter(Boolean),
293-
providers: [],
294-
managers: [],
295-
// fetch: logFetch,
296-
// agentId: agentId,
297-
// serverUrl: "XXXXXXXXXXXXXXXX",
298-
// databaseAdapter: {} as IDatabaseAdapter,
299-
// token: "token",
300-
// modelProvider: "defaultModelProvider", // Add the modelProvider property
301-
});
302273
this.agents.set(agentId, runtime);
303274
}
304275
if (runtime) {
305276
console.log("Runtime found for agentId:", agentId);
306-
await processChunk(finalPrompt, "chat", runtime);
277+
await processChunk(finalPrompt, "fragments", runtime);
307278
} else {
308279
console.warn("No runtime found for agentId:", agentId);
309280
}
@@ -333,12 +304,14 @@ export class AIService {
333304
}
334305
}
335306

336-
async function processChunk(prompt: string, manager: string, runtime: IAgentRuntime): Promise<string> {
307+
async function processChunk(prompt: string, manager: string, runtime: AgentRuntime): Promise<string> {
337308
console.log("process chunk");
338309
try {
339310
const mm = runtime.getMemoryManager(manager);
340311
if (!mm) {
341-
throw new Error("Memory manager not found");
312+
console.log("manager",manager);
313+
console.log("memoryManagers",runtime.memoryManagers);
314+
throw new Error("Memory manager not found", manager);
342315
}
343316
const memory = await mm.addEmbeddingToMemory({
344317
agentId: runtime.agentId,
@@ -513,38 +486,38 @@ async function process_text(this: any, agentId: string, userName: string, name:
513486
}
514487
}
515488

516-
interface IMemoryManager {
517-
runtime: string;
518-
tableName: string;
519-
getMemories: () => Promise<any[]>;
520-
getCachedEmbeddings: () => Promise<any[]>;
521-
addEmbeddingToMemory: (data: any) => Promise<{}>;
522-
createMemory: (memory: any) => Promise<void>;
523-
// Add other properties and methods as required
524-
}
525-
526-
function getMemoryManager(manager: string): IMemoryManager | null {
527-
if (manager === 'someCondition') {
528-
return {
529-
runtime: 'someRuntime',
530-
tableName: 'someTableName',
531-
getMemories: async () => {
532-
// Implementation here
533-
return [];
534-
},
535-
getCachedEmbeddings: async () => {
536-
// Implementation here
537-
return [];
538-
},
539-
addEmbeddingToMemory: async (data: any) => {
540-
// Implementation here
541-
return {};
542-
},
543-
createMemory: async (memory: any) => {
544-
// Implementation here
545-
},
546-
// Add other properties and methods as required
547-
};
548-
}
549-
return null;
550-
}
489+
// interface IMemoryManager {
490+
// runtime: string;
491+
// tableName: string;
492+
// getMemories: () => Promise<any[]>;
493+
// getCachedEmbeddings: () => Promise<any[]>;
494+
// addEmbeddingToMemory: (data: any) => Promise<{}>;
495+
// createMemory: (memory: any) => Promise<void>;
496+
// // Add other properties and methods as required
497+
// }
498+
499+
// function getMemoryManager(manager: string): IMemoryManager | null {
500+
// if (manager === 'someCondition') {
501+
// return {
502+
// runtime: 'someRuntime',
503+
// tableName: 'someTableName',
504+
// getMemories: async () => {
505+
// // Implementation here
506+
// return [];
507+
// },
508+
// getCachedEmbeddings: async () => {
509+
// // Implementation here
510+
// return [];
511+
// },
512+
// addEmbeddingToMemory: async (data: any) => {
513+
// // Implementation here
514+
// return {};
515+
// },
516+
// createMemory: async (memory: any) => {
517+
// // Implementation here
518+
// },
519+
// // Add other properties and methods as required
520+
// };
521+
// }
522+
// return null;
523+
// }

scripts/jsdoc-automation/tsconfig.json

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
"noEmitOnError": true,
1313
//"noImplicitAny": true,
1414
// "noImplicitReturns": true,
15+
// "checkJs": true,
16+
"diagnostics": true,
17+
//"inlineSourceMap": true,
18+
"inlineSources": true,
1519

1620
"typeRoots":["./node_modules/@types"],
1721
"module": "NodeNext",

scripts/jsdoc-automation/tsup.config.ts

+15
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,21 @@ export default defineConfig({
1010
target: "node20",
1111
// logErrors: true,
1212
minify: false,
13+
minifyWhitespace: false,
14+
minifySyntax: false,
15+
minifyIdentifiers: false,
16+
keepNames: true,
17+
//watch: true,
18+
bundle: true,
19+
platform: "node",
20+
metafile: true,
21+
external: ["dotenv"],
22+
//noExternal: ["dotenv"],
23+
esbuildOptions: (options) => {
24+
options.banner = {
25+
js: `import { createRequire } from 'module';const require = createRequire(import.meta.url);`,
26+
};
27+
},
1328
outDir: "dist",
1429
treeshake: true,
1530
});

0 commit comments

Comments
 (0)