@avee1234/agent-kit 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # agent-kit
2
2
 
3
+ [![CI](https://github.com/abhid1234/agent-kit/actions/workflows/ci.yml/badge.svg)](https://github.com/abhid1234/agent-kit/actions/workflows/ci.yml)
4
+ [![npm version](https://img.shields.io/npm/v/@avee1234/agent-kit)](https://www.npmjs.com/package/@avee1234/agent-kit)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
6
+
3
7
  TypeScript-first library for building stateful, persistent AI agents.
4
8
 
5
9
  <p align="center">
package/dist/cli.cjs ADDED
@@ -0,0 +1,100 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
18
+ // If the importer is in node compatibility mode or this is not an ESM
19
+ // file that has been converted to a CommonJS file using a Babel-
20
+ // compatible transform (i.e. "__esModule" has not been set), then set
21
+ // "default" to the CommonJS "module.exports" for node compatibility.
22
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
23
+ mod
24
+ ));
25
+
26
+ // src/cli.ts
27
+ var import_fs = __toESM(require("fs"), 1);
28
+ var import_path = __toESM(require("path"), 1);
29
+ var args = process.argv.slice(2);
30
+ var command = args[0];
31
+ var projectName = args[1] ?? "my-agent";
32
+ if (command !== "init") {
33
+ console.error(`Unknown command: ${command}`);
34
+ console.error("Usage: agent-kit init [project-name]");
35
+ process.exit(1);
36
+ }
37
+ var targetDir = import_path.default.resolve(process.cwd(), projectName);
38
+ if (import_fs.default.existsSync(targetDir)) {
39
+ console.error(`Directory already exists: ${targetDir}`);
40
+ process.exit(1);
41
+ }
42
+ import_fs.default.mkdirSync(targetDir, { recursive: true });
43
+ var packageJson = {
44
+ name: projectName,
45
+ version: "1.0.0",
46
+ private: true,
47
+ type: "module",
48
+ scripts: {
49
+ start: "npx tsx agent.ts"
50
+ },
51
+ dependencies: {
52
+ "@avee1234/agent-kit": "^0.2.0"
53
+ },
54
+ devDependencies: {
55
+ tsx: "^4.0.0"
56
+ }
57
+ };
58
+ var agentTs = `import { Agent, Tool, Memory } from '@avee1234/agent-kit';
59
+
60
+ const greet = Tool.create({
61
+ name: 'greet',
62
+ description: 'Greet someone by name',
63
+ parameters: {
64
+ name: { type: 'string', description: 'Name to greet' },
65
+ },
66
+ execute: async ({ name }) => \`Hello, \${name}!\`,
67
+ });
68
+
69
+ const agent = new Agent({
70
+ name: 'my-agent',
71
+ memory: new Memory({ store: 'sqlite', path: './memory.db' }),
72
+ tools: [greet],
73
+ system: 'You are a helpful assistant.',
74
+ });
75
+
76
+ const response = await agent.chat(process.argv[2] ?? 'Hello!');
77
+ console.log(response.content);
78
+ `;
79
+ var readmeMd = `# ${projectName}
80
+
81
+ Built with [agent-kit](https://github.com/abhid1234/agent-kit).
82
+
83
+ ## Quick Start
84
+
85
+ \`\`\`bash
86
+ npm install
87
+ npm start "Hello, what can you do?"
88
+ \`\`\`
89
+ `;
90
+ import_fs.default.writeFileSync(import_path.default.join(targetDir, "package.json"), JSON.stringify(packageJson, null, 2) + "\n");
91
+ import_fs.default.writeFileSync(import_path.default.join(targetDir, "agent.ts"), agentTs);
92
+ import_fs.default.writeFileSync(import_path.default.join(targetDir, "README.md"), readmeMd);
93
+ console.log(`
94
+ Scaffolded project: ${projectName}
95
+ `);
96
+ console.log("Next steps:\n");
97
+ console.log(` cd ${projectName}`);
98
+ console.log(" npm install");
99
+ console.log(' npm start "Hello, what can you do?"\n');
100
+ //# sourceMappingURL=cli.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport fs from 'fs';\nimport path from 'path';\n\nconst args = process.argv.slice(2);\nconst command = args[0];\nconst projectName = args[1] ?? 'my-agent';\n\nif (command !== 'init') {\n console.error(`Unknown command: ${command}`);\n console.error('Usage: agent-kit init [project-name]');\n process.exit(1);\n}\n\nconst targetDir = path.resolve(process.cwd(), projectName);\n\nif (fs.existsSync(targetDir)) {\n console.error(`Directory already exists: ${targetDir}`);\n process.exit(1);\n}\n\nfs.mkdirSync(targetDir, { recursive: true });\n\nconst packageJson = {\n name: projectName,\n version: '1.0.0',\n private: true,\n type: 'module',\n scripts: {\n start: 'npx tsx agent.ts',\n },\n dependencies: {\n '@avee1234/agent-kit': '^0.2.0',\n },\n devDependencies: {\n tsx: '^4.0.0',\n },\n};\n\nconst agentTs = `import { Agent, Tool, Memory } from '@avee1234/agent-kit';\n\nconst greet = Tool.create({\n name: 'greet',\n description: 'Greet someone by name',\n parameters: {\n name: { type: 'string', description: 'Name to greet' },\n },\n execute: async ({ name }) => \\`Hello, \\${name}!\\`,\n});\n\nconst agent = new Agent({\n name: 'my-agent',\n memory: new Memory({ store: 'sqlite', path: './memory.db' }),\n tools: [greet],\n system: 'You are a helpful assistant.',\n});\n\nconst response = await agent.chat(process.argv[2] ?? 'Hello!');\nconsole.log(response.content);\n`;\n\nconst readmeMd = `# ${projectName}\n\nBuilt with [agent-kit](https://github.com/abhid1234/agent-kit).\n\n## Quick Start\n\n\\`\\`\\`bash\nnpm install\nnpm start \"Hello, what can you do?\"\n\\`\\`\\`\n`;\n\nfs.writeFileSync(path.join(targetDir, 'package.json'), JSON.stringify(packageJson, null, 2) + '\\n');\nfs.writeFileSync(path.join(targetDir, 'agent.ts'), agentTs);\nfs.writeFileSync(path.join(targetDir, 'README.md'), readmeMd);\n\nconsole.log(`\\nScaffolded project: ${projectName}\\n`);\nconsole.log('Next steps:\\n');\nconsole.log(` cd ${projectName}`);\nconsole.log(' npm install');\nconsole.log(' npm start \"Hello, what can you do?\"\\n');\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,gBAAe;AACf,kBAAiB;AAEjB,IAAM,OAAO,QAAQ,KAAK,MAAM,CAAC;AACjC,IAAM,UAAU,KAAK,CAAC;AACtB,IAAM,cAAc,KAAK,CAAC,KAAK;AAE/B,IAAI,YAAY,QAAQ;AACtB,UAAQ,MAAM,oBAAoB,OAAO,EAAE;AAC3C,UAAQ,MAAM,sCAAsC;AACpD,UAAQ,KAAK,CAAC;AAChB;AAEA,IAAM,YAAY,YAAAA,QAAK,QAAQ,QAAQ,IAAI,GAAG,WAAW;AAEzD,IAAI,UAAAC,QAAG,WAAW,SAAS,GAAG;AAC5B,UAAQ,MAAM,6BAA6B,SAAS,EAAE;AACtD,UAAQ,KAAK,CAAC;AAChB;AAEA,UAAAA,QAAG,UAAU,WAAW,EAAE,WAAW,KAAK,CAAC;AAE3C,IAAM,cAAc;AAAA,EAClB,MAAM;AAAA,EACN,SAAS;AAAA,EACT,SAAS;AAAA,EACT,MAAM;AAAA,EACN,SAAS;AAAA,IACP,OAAO;AAAA,EACT;AAAA,EACA,cAAc;AAAA,IACZ,uBAAuB;AAAA,EACzB;AAAA,EACA,iBAAiB;AAAA,IACf,KAAK;AAAA,EACP;AACF;AAEA,IAAM,UAAU;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAsBhB,IAAM,WAAW,KAAK,WAAW;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAYjC,UAAAA,QAAG,cAAc,YAAAD,QAAK,KAAK,WAAW,cAAc,GAAG,KAAK,UAAU,aAAa,MAAM,CAAC,IAAI,IAAI;AAClG,UAAAC,QAAG,cAAc,YAAAD,QAAK,KAAK,WAAW,UAAU,GAAG,OAAO;AAC1D,UAAAC,QAAG,cAAc,YAAAD,QAAK,KAAK,WAAW,WAAW,GAAG,QAAQ;AAE5D,QAAQ,IAAI;AAAA,sBAAyB,WAAW;AAAA,CAAI;AACpD,QAAQ,IAAI,eAAe;AAC3B,QAAQ,IAAI,QAAQ,WAAW,EAAE;AACjC,QAAQ,IAAI,eAAe;AAC3B,QAAQ,IAAI,yCAAyC;","names":["path","fs"]}
package/dist/cli.d.cts ADDED
@@ -0,0 +1 @@
1
+ #!/usr/bin/env node
package/dist/cli.d.ts ADDED
@@ -0,0 +1 @@
1
+ #!/usr/bin/env node
package/dist/cli.js ADDED
@@ -0,0 +1,77 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/cli.ts
4
+ import fs from "fs";
5
+ import path from "path";
6
+ var args = process.argv.slice(2);
7
+ var command = args[0];
8
+ var projectName = args[1] ?? "my-agent";
9
+ if (command !== "init") {
10
+ console.error(`Unknown command: ${command}`);
11
+ console.error("Usage: agent-kit init [project-name]");
12
+ process.exit(1);
13
+ }
14
+ var targetDir = path.resolve(process.cwd(), projectName);
15
+ if (fs.existsSync(targetDir)) {
16
+ console.error(`Directory already exists: ${targetDir}`);
17
+ process.exit(1);
18
+ }
19
+ fs.mkdirSync(targetDir, { recursive: true });
20
+ var packageJson = {
21
+ name: projectName,
22
+ version: "1.0.0",
23
+ private: true,
24
+ type: "module",
25
+ scripts: {
26
+ start: "npx tsx agent.ts"
27
+ },
28
+ dependencies: {
29
+ "@avee1234/agent-kit": "^0.2.0"
30
+ },
31
+ devDependencies: {
32
+ tsx: "^4.0.0"
33
+ }
34
+ };
35
+ var agentTs = `import { Agent, Tool, Memory } from '@avee1234/agent-kit';
36
+
37
+ const greet = Tool.create({
38
+ name: 'greet',
39
+ description: 'Greet someone by name',
40
+ parameters: {
41
+ name: { type: 'string', description: 'Name to greet' },
42
+ },
43
+ execute: async ({ name }) => \`Hello, \${name}!\`,
44
+ });
45
+
46
+ const agent = new Agent({
47
+ name: 'my-agent',
48
+ memory: new Memory({ store: 'sqlite', path: './memory.db' }),
49
+ tools: [greet],
50
+ system: 'You are a helpful assistant.',
51
+ });
52
+
53
+ const response = await agent.chat(process.argv[2] ?? 'Hello!');
54
+ console.log(response.content);
55
+ `;
56
+ var readmeMd = `# ${projectName}
57
+
58
+ Built with [agent-kit](https://github.com/abhid1234/agent-kit).
59
+
60
+ ## Quick Start
61
+
62
+ \`\`\`bash
63
+ npm install
64
+ npm start "Hello, what can you do?"
65
+ \`\`\`
66
+ `;
67
+ fs.writeFileSync(path.join(targetDir, "package.json"), JSON.stringify(packageJson, null, 2) + "\n");
68
+ fs.writeFileSync(path.join(targetDir, "agent.ts"), agentTs);
69
+ fs.writeFileSync(path.join(targetDir, "README.md"), readmeMd);
70
+ console.log(`
71
+ Scaffolded project: ${projectName}
72
+ `);
73
+ console.log("Next steps:\n");
74
+ console.log(` cd ${projectName}`);
75
+ console.log(" npm install");
76
+ console.log(' npm start "Hello, what can you do?"\n');
77
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport fs from 'fs';\nimport path from 'path';\n\nconst args = process.argv.slice(2);\nconst command = args[0];\nconst projectName = args[1] ?? 'my-agent';\n\nif (command !== 'init') {\n console.error(`Unknown command: ${command}`);\n console.error('Usage: agent-kit init [project-name]');\n process.exit(1);\n}\n\nconst targetDir = path.resolve(process.cwd(), projectName);\n\nif (fs.existsSync(targetDir)) {\n console.error(`Directory already exists: ${targetDir}`);\n process.exit(1);\n}\n\nfs.mkdirSync(targetDir, { recursive: true });\n\nconst packageJson = {\n name: projectName,\n version: '1.0.0',\n private: true,\n type: 'module',\n scripts: {\n start: 'npx tsx agent.ts',\n },\n dependencies: {\n '@avee1234/agent-kit': '^0.2.0',\n },\n devDependencies: {\n tsx: '^4.0.0',\n },\n};\n\nconst agentTs = `import { Agent, Tool, Memory } from '@avee1234/agent-kit';\n\nconst greet = Tool.create({\n name: 'greet',\n description: 'Greet someone by name',\n parameters: {\n name: { type: 'string', description: 'Name to greet' },\n },\n execute: async ({ name }) => \\`Hello, \\${name}!\\`,\n});\n\nconst agent = new Agent({\n name: 'my-agent',\n memory: new Memory({ store: 'sqlite', path: './memory.db' }),\n tools: [greet],\n system: 'You are a helpful assistant.',\n});\n\nconst response = await agent.chat(process.argv[2] ?? 'Hello!');\nconsole.log(response.content);\n`;\n\nconst readmeMd = `# ${projectName}\n\nBuilt with [agent-kit](https://github.com/abhid1234/agent-kit).\n\n## Quick Start\n\n\\`\\`\\`bash\nnpm install\nnpm start \"Hello, what can you do?\"\n\\`\\`\\`\n`;\n\nfs.writeFileSync(path.join(targetDir, 'package.json'), JSON.stringify(packageJson, null, 2) + '\\n');\nfs.writeFileSync(path.join(targetDir, 'agent.ts'), agentTs);\nfs.writeFileSync(path.join(targetDir, 'README.md'), readmeMd);\n\nconsole.log(`\\nScaffolded project: ${projectName}\\n`);\nconsole.log('Next steps:\\n');\nconsole.log(` cd ${projectName}`);\nconsole.log(' npm install');\nconsole.log(' npm start \"Hello, what can you do?\"\\n');\n"],"mappings":";;;AAEA,OAAO,QAAQ;AACf,OAAO,UAAU;AAEjB,IAAM,OAAO,QAAQ,KAAK,MAAM,CAAC;AACjC,IAAM,UAAU,KAAK,CAAC;AACtB,IAAM,cAAc,KAAK,CAAC,KAAK;AAE/B,IAAI,YAAY,QAAQ;AACtB,UAAQ,MAAM,oBAAoB,OAAO,EAAE;AAC3C,UAAQ,MAAM,sCAAsC;AACpD,UAAQ,KAAK,CAAC;AAChB;AAEA,IAAM,YAAY,KAAK,QAAQ,QAAQ,IAAI,GAAG,WAAW;AAEzD,IAAI,GAAG,WAAW,SAAS,GAAG;AAC5B,UAAQ,MAAM,6BAA6B,SAAS,EAAE;AACtD,UAAQ,KAAK,CAAC;AAChB;AAEA,GAAG,UAAU,WAAW,EAAE,WAAW,KAAK,CAAC;AAE3C,IAAM,cAAc;AAAA,EAClB,MAAM;AAAA,EACN,SAAS;AAAA,EACT,SAAS;AAAA,EACT,MAAM;AAAA,EACN,SAAS;AAAA,IACP,OAAO;AAAA,EACT;AAAA,EACA,cAAc;AAAA,IACZ,uBAAuB;AAAA,EACzB;AAAA,EACA,iBAAiB;AAAA,IACf,KAAK;AAAA,EACP;AACF;AAEA,IAAM,UAAU;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAsBhB,IAAM,WAAW,KAAK,WAAW;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAYjC,GAAG,cAAc,KAAK,KAAK,WAAW,cAAc,GAAG,KAAK,UAAU,aAAa,MAAM,CAAC,IAAI,IAAI;AAClG,GAAG,cAAc,KAAK,KAAK,WAAW,UAAU,GAAG,OAAO;AAC1D,GAAG,cAAc,KAAK,KAAK,WAAW,WAAW,GAAG,QAAQ;AAE5D,QAAQ,IAAI;AAAA,sBAAyB,WAAW;AAAA,CAAI;AACpD,QAAQ,IAAI,eAAe;AAC3B,QAAQ,IAAI,QAAQ,WAAW,EAAE;AACjC,QAAQ,IAAI,eAAe;AAC3B,QAAQ,IAAI,yCAAyC;","names":[]}
package/dist/index.cjs CHANGED
@@ -25,6 +25,7 @@ __export(index_exports, {
25
25
  InMemoryStore: () => InMemoryStore,
26
26
  Memory: () => Memory,
27
27
  MockAdapter: () => MockAdapter,
28
+ OllamaEmbeddingAdapter: () => OllamaEmbeddingAdapter,
28
29
  OpenAICompatibleAdapter: () => OpenAICompatibleAdapter,
29
30
  SQLiteStore: () => SQLiteStore,
30
31
  Team: () => Team,
@@ -724,10 +725,27 @@ var Team = class {
724
725
  }
725
726
  };
726
727
 
728
+ // src/store/cosine.ts
729
+ function cosineSimilarity(a, b) {
730
+ let dot = 0;
731
+ let normA = 0;
732
+ let normB = 0;
733
+ for (let i = 0; i < a.length; i++) {
734
+ dot += a[i] * b[i];
735
+ normA += a[i] * a[i];
736
+ normB += b[i] * b[i];
737
+ }
738
+ const denom = Math.sqrt(normA) * Math.sqrt(normB);
739
+ if (denom === 0) return 0;
740
+ return dot / denom;
741
+ }
742
+
727
743
  // src/store/in-memory.ts
728
744
  var InMemoryStore = class {
729
745
  messages = /* @__PURE__ */ new Map();
730
746
  summaries = /* @__PURE__ */ new Map();
747
+ // agentId -> (summaryId -> embedding vector)
748
+ embeddings = /* @__PURE__ */ new Map();
731
749
  async saveMessages(agentId, messages) {
732
750
  const existing = this.messages.get(agentId) ?? [];
733
751
  existing.push(...messages);
@@ -748,6 +766,28 @@ var InMemoryStore = class {
748
766
  const matches = all.filter((s) => s.content.toLowerCase().includes(queryLower)).sort((a, b) => b.timestamp - a.timestamp).slice(0, limit);
749
767
  return matches;
750
768
  }
769
+ async saveEmbedding(agentId, summaryId, embedding) {
770
+ let agentMap = this.embeddings.get(agentId);
771
+ if (!agentMap) {
772
+ agentMap = /* @__PURE__ */ new Map();
773
+ this.embeddings.set(agentId, agentMap);
774
+ }
775
+ agentMap.set(summaryId, embedding);
776
+ }
777
+ async searchByEmbedding(agentId, embedding, limit) {
778
+ const agentMap = this.embeddings.get(agentId);
779
+ if (!agentMap || agentMap.size === 0) return [];
780
+ const summaries = this.summaries.get(agentId) ?? [];
781
+ const summaryById = new Map(summaries.map((s) => [s.id, s]));
782
+ const scored = [];
783
+ for (const [summaryId, storedEmbedding] of agentMap) {
784
+ const summary = summaryById.get(summaryId);
785
+ if (!summary) continue;
786
+ const score = cosineSimilarity(embedding, storedEmbedding);
787
+ scored.push({ summary, score });
788
+ }
789
+ return scored.sort((a, b) => b.score - a.score).slice(0, limit).map((entry) => entry.summary);
790
+ }
751
791
  };
752
792
 
753
793
  // src/store/sqlite.ts
@@ -781,8 +821,14 @@ var SQLiteStore = class {
781
821
  message_range_from INTEGER NOT NULL,
782
822
  message_range_to INTEGER NOT NULL
783
823
  );
824
+ CREATE TABLE IF NOT EXISTS embeddings (
825
+ summary_id TEXT PRIMARY KEY,
826
+ agent_id TEXT NOT NULL,
827
+ embedding BLOB NOT NULL
828
+ );
784
829
  CREATE INDEX IF NOT EXISTS idx_messages_agent ON messages(agent_id);
785
830
  CREATE INDEX IF NOT EXISTS idx_summaries_agent ON summaries(agent_id);
831
+ CREATE INDEX IF NOT EXISTS idx_embeddings_agent ON embeddings(agent_id);
786
832
  `);
787
833
  }
788
834
  async saveMessages(agentId, messages) {
@@ -842,6 +888,34 @@ var SQLiteStore = class {
842
888
  messageRange: { from: row.message_range_from, to: row.message_range_to }
843
889
  }));
844
890
  }
891
+ async saveEmbedding(agentId, summaryId, embedding) {
892
+ this.db.prepare(
893
+ "INSERT OR REPLACE INTO embeddings (summary_id, agent_id, embedding) VALUES (?, ?, ?)"
894
+ ).run(summaryId, agentId, JSON.stringify(embedding));
895
+ }
896
+ async searchByEmbedding(agentId, embedding, limit) {
897
+ const rows = this.db.prepare(
898
+ `SELECT e.summary_id, s.content, s.timestamp, s.message_range_from, s.message_range_to, e.embedding
899
+ FROM embeddings e
900
+ JOIN summaries s ON e.summary_id = s.id
901
+ WHERE e.agent_id = ?`
902
+ ).all(agentId);
903
+ if (rows.length === 0) return [];
904
+ const scored = rows.map((row) => {
905
+ const storedEmbedding = JSON.parse(row.embedding);
906
+ const score = cosineSimilarity(embedding, storedEmbedding);
907
+ return {
908
+ summary: {
909
+ id: row.summary_id,
910
+ content: row.content,
911
+ timestamp: row.timestamp,
912
+ messageRange: { from: row.message_range_from, to: row.message_range_to }
913
+ },
914
+ score
915
+ };
916
+ });
917
+ return scored.sort((a, b) => b.score - a.score).slice(0, limit).map((entry) => entry.summary);
918
+ }
845
919
  close() {
846
920
  this.db.close();
847
921
  }
@@ -853,10 +927,12 @@ var Memory = class {
853
927
  windowSize;
854
928
  summarizeAfter;
855
929
  model;
930
+ embeddingAdapter;
856
931
  messageCount = /* @__PURE__ */ new Map();
857
932
  constructor(config = {}) {
858
933
  this.windowSize = config.windowSize ?? 20;
859
934
  this.summarizeAfter = config.summarizeAfter ?? 20;
935
+ this.embeddingAdapter = config.embedding;
860
936
  if (!config.store || config.store === "memory") {
861
937
  this.store = new InMemoryStore();
862
938
  } else if (config.store === "sqlite") {
@@ -882,7 +958,13 @@ var Memory = class {
882
958
  }
883
959
  async getContext(agentId, query) {
884
960
  const recentMessages = await this.store.getRecentMessages(agentId, this.windowSize);
885
- const relevantSummaries = await this.store.searchSummaries(agentId, query, 3);
961
+ let relevantSummaries;
962
+ if (this.embeddingAdapter && this.store.searchByEmbedding) {
963
+ const queryEmbedding = await this.embeddingAdapter.embed(query);
964
+ relevantSummaries = await this.store.searchByEmbedding(agentId, queryEmbedding, 3);
965
+ } else {
966
+ relevantSummaries = await this.store.searchSummaries(agentId, query, 3);
967
+ }
886
968
  return { recentMessages, relevantSummaries };
887
969
  }
888
970
  async summarize(agentId) {
@@ -905,6 +987,10 @@ var Memory = class {
905
987
  }
906
988
  });
907
989
  await this.store.saveSummary(agentId, summary);
990
+ if (this.embeddingAdapter && this.store.saveEmbedding) {
991
+ const embedding = await this.embeddingAdapter.embed(summary.content);
992
+ await this.store.saveEmbedding(agentId, summary.id, embedding);
993
+ }
908
994
  }
909
995
  close() {
910
996
  if ("close" in this.store && typeof this.store.close === "function") {
@@ -912,6 +998,36 @@ var Memory = class {
912
998
  }
913
999
  }
914
1000
  };
1001
+
1002
+ // src/model/ollama-embedding.ts
1003
+ var OllamaEmbeddingAdapter = class {
1004
+ baseURL;
1005
+ model;
1006
+ constructor(config = {}) {
1007
+ this.baseURL = config.baseURL ?? "http://localhost:11434";
1008
+ this.model = config.model ?? "nomic-embed-text";
1009
+ }
1010
+ async embed(text) {
1011
+ const [vector] = await this.request(text);
1012
+ return vector;
1013
+ }
1014
+ async embedBatch(texts) {
1015
+ if (texts.length === 0) return [];
1016
+ return this.request(texts);
1017
+ }
1018
+ async request(input) {
1019
+ const response = await fetch(`${this.baseURL}/api/embed`, {
1020
+ method: "POST",
1021
+ headers: { "Content-Type": "application/json" },
1022
+ body: JSON.stringify({ model: this.model, input })
1023
+ });
1024
+ if (!response.ok) {
1025
+ throw new Error(`Ollama embedding request failed: ${response.status} ${response.statusText}`);
1026
+ }
1027
+ const data = await response.json();
1028
+ return data.embeddings;
1029
+ }
1030
+ };
915
1031
  // Annotate the CommonJS export names for ESM import in node:
916
1032
  0 && (module.exports = {
917
1033
  Agent,
@@ -919,6 +1035,7 @@ var Memory = class {
919
1035
  InMemoryStore,
920
1036
  Memory,
921
1037
  MockAdapter,
1038
+ OllamaEmbeddingAdapter,
922
1039
  OpenAICompatibleAdapter,
923
1040
  SQLiteStore,
924
1041
  Team,