kernl 0.6.2 → 0.7.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.
Files changed (193) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/.turbo/turbo-check-types.log +1 -1
  3. package/CHANGELOG.md +44 -0
  4. package/dist/agent/__tests__/concurrency.test.js +1 -1
  5. package/dist/agent/__tests__/run.test.js +1 -1
  6. package/dist/agent/__tests__/systools.test.d.ts +2 -0
  7. package/dist/agent/__tests__/systools.test.d.ts.map +1 -0
  8. package/dist/agent/__tests__/systools.test.js +121 -0
  9. package/dist/{types/agent.d.ts → agent/types.d.ts} +19 -2
  10. package/dist/agent/types.d.ts.map +1 -0
  11. package/dist/agent.d.ts +48 -6
  12. package/dist/agent.d.ts.map +1 -1
  13. package/dist/agent.js +100 -13
  14. package/dist/api/models/thread.d.ts +1 -1
  15. package/dist/api/resources/agents/agents.d.ts +38 -0
  16. package/dist/api/resources/agents/agents.d.ts.map +1 -0
  17. package/dist/api/resources/agents/agents.js +44 -0
  18. package/dist/api/resources/agents/index.d.ts +2 -0
  19. package/dist/api/resources/agents/index.d.ts.map +1 -0
  20. package/dist/api/resources/agents/index.js +1 -0
  21. package/dist/api/resources/threads/threads.d.ts +1 -1
  22. package/dist/api/resources/threads/threads.d.ts.map +1 -1
  23. package/dist/api/resources/threads/threads.js +1 -1
  24. package/dist/api/resources/threads/types.d.ts +2 -2
  25. package/dist/api/resources/threads/types.d.ts.map +1 -1
  26. package/dist/context.d.ts +10 -4
  27. package/dist/context.d.ts.map +1 -1
  28. package/dist/context.js +5 -0
  29. package/dist/guardrail.d.ts +2 -2
  30. package/dist/index.d.ts +5 -3
  31. package/dist/index.d.ts.map +1 -1
  32. package/dist/index.js +4 -3
  33. package/dist/internal.d.ts +2 -2
  34. package/dist/internal.js +1 -1
  35. package/dist/kernl/index.d.ts +1 -1
  36. package/dist/kernl/index.d.ts.map +1 -1
  37. package/dist/kernl/index.js +0 -1
  38. package/dist/kernl/kernl.d.ts +11 -20
  39. package/dist/kernl/kernl.d.ts.map +1 -1
  40. package/dist/kernl/kernl.js +37 -34
  41. package/dist/kernl/types.d.ts +91 -0
  42. package/dist/kernl/types.d.ts.map +1 -0
  43. package/dist/lib/error.d.ts +2 -2
  44. package/dist/lifecycle.d.ts +2 -2
  45. package/dist/memory/codec.d.ts +32 -0
  46. package/dist/memory/codec.d.ts.map +1 -0
  47. package/dist/memory/codec.js +97 -0
  48. package/dist/memory/codecs/domain.d.ts +34 -0
  49. package/dist/memory/codecs/domain.d.ts.map +1 -0
  50. package/dist/memory/codecs/domain.js +99 -0
  51. package/dist/memory/codecs/identity.d.ts +12 -0
  52. package/dist/memory/codecs/identity.d.ts.map +1 -0
  53. package/dist/memory/codecs/identity.js +17 -0
  54. package/dist/memory/codecs/index.d.ts +31 -0
  55. package/dist/memory/codecs/index.d.ts.map +1 -0
  56. package/dist/memory/codecs/index.js +39 -0
  57. package/dist/memory/codecs/tpuf.d.ts +38 -0
  58. package/dist/memory/codecs/tpuf.d.ts.map +1 -0
  59. package/dist/memory/codecs/tpuf.js +90 -0
  60. package/dist/memory/encoder.d.ts +29 -0
  61. package/dist/memory/encoder.d.ts.map +1 -0
  62. package/dist/memory/encoder.js +45 -0
  63. package/dist/memory/handle.d.ts +89 -0
  64. package/dist/memory/handle.d.ts.map +1 -0
  65. package/dist/memory/handle.js +128 -0
  66. package/dist/memory/index.d.ts +12 -0
  67. package/dist/memory/index.d.ts.map +1 -0
  68. package/dist/memory/index.js +7 -0
  69. package/dist/memory/indexes.d.ts +91 -0
  70. package/dist/memory/indexes.d.ts.map +1 -0
  71. package/dist/memory/indexes.js +7 -0
  72. package/dist/memory/memory.d.ts +55 -0
  73. package/dist/memory/memory.d.ts.map +1 -0
  74. package/dist/memory/memory.js +113 -0
  75. package/dist/memory/schema.d.ts +41 -0
  76. package/dist/memory/schema.d.ts.map +1 -0
  77. package/dist/memory/schema.js +112 -0
  78. package/dist/memory/store.d.ts +36 -0
  79. package/dist/memory/store.d.ts.map +1 -0
  80. package/dist/memory/store.js +4 -0
  81. package/dist/memory/types.d.ts +250 -0
  82. package/dist/memory/types.d.ts.map +1 -0
  83. package/dist/memory/types.js +4 -0
  84. package/dist/storage/base.d.ts +6 -1
  85. package/dist/storage/base.d.ts.map +1 -1
  86. package/dist/storage/in-memory.d.ts +24 -2
  87. package/dist/storage/in-memory.d.ts.map +1 -1
  88. package/dist/storage/in-memory.js +131 -0
  89. package/dist/storage/thread.d.ts +1 -1
  90. package/dist/thread/__tests__/integration.test.js +1 -1
  91. package/dist/thread/__tests__/mock.d.ts +1 -1
  92. package/dist/thread/__tests__/namespace.test.js +1 -1
  93. package/dist/thread/__tests__/thread.test.js +1 -1
  94. package/dist/thread/thread.d.ts +2 -2
  95. package/dist/thread/thread.d.ts.map +1 -1
  96. package/dist/thread/thread.js +3 -1
  97. package/dist/{types/thread.d.ts → thread/types.d.ts} +2 -2
  98. package/dist/thread/types.d.ts.map +1 -0
  99. package/dist/thread/utils.d.ts +2 -2
  100. package/dist/thread/utils.d.ts.map +1 -1
  101. package/dist/tool/index.d.ts +1 -0
  102. package/dist/tool/index.d.ts.map +1 -1
  103. package/dist/tool/index.js +2 -0
  104. package/dist/tool/sys/index.d.ts +7 -0
  105. package/dist/tool/sys/index.d.ts.map +1 -0
  106. package/dist/tool/sys/index.js +6 -0
  107. package/dist/tool/sys/memory.d.ts +14 -0
  108. package/dist/tool/sys/memory.d.ts.map +1 -0
  109. package/dist/tool/sys/memory.js +103 -0
  110. package/dist/tool/tool.d.ts +1 -1
  111. package/dist/tool/tool.d.ts.map +1 -1
  112. package/dist/tool/tool.js +2 -2
  113. package/package.json +4 -2
  114. package/src/agent/__tests__/systools.test.ts +146 -0
  115. package/src/{types/agent.ts → agent/types.ts} +22 -1
  116. package/src/agent.ts +144 -36
  117. package/src/api/__tests__/threads.test.ts +2 -2
  118. package/src/api/models/thread.ts +1 -1
  119. package/src/api/resources/agents/agents.ts +56 -0
  120. package/src/api/resources/agents/index.ts +1 -0
  121. package/src/api/resources/threads/events.ts +1 -1
  122. package/src/api/resources/threads/threads.ts +2 -2
  123. package/src/api/resources/threads/types.ts +2 -2
  124. package/src/context.ts +14 -136
  125. package/src/guardrail.ts +2 -2
  126. package/src/index.ts +35 -6
  127. package/src/internal.ts +2 -2
  128. package/src/kernl/index.ts +8 -0
  129. package/src/{kernl.ts → kernl/kernl.ts} +50 -10
  130. package/src/kernl/types.ts +106 -0
  131. package/src/lib/error.ts +2 -2
  132. package/src/lifecycle.ts +2 -2
  133. package/src/memory/codecs/domain.ts +115 -0
  134. package/src/memory/codecs/identity.ts +28 -0
  135. package/src/memory/codecs/index.ts +61 -0
  136. package/src/memory/codecs/tpuf.ts +115 -0
  137. package/src/memory/encoder.ts +56 -0
  138. package/src/memory/handle.ts +189 -0
  139. package/src/memory/index.ts +49 -0
  140. package/src/memory/indexes.ts +108 -0
  141. package/src/memory/memory.ts +151 -0
  142. package/src/memory/schema.ts +142 -0
  143. package/src/memory/store.ts +47 -0
  144. package/src/memory/types.ts +282 -0
  145. package/src/storage/__tests__/in-memory.test.ts +1 -1
  146. package/src/storage/base.ts +7 -1
  147. package/src/storage/in-memory.ts +170 -2
  148. package/src/storage/thread.ts +1 -1
  149. package/src/thread/__tests__/integration.test.ts +1 -1
  150. package/src/thread/__tests__/mock.ts +1 -1
  151. package/src/thread/__tests__/thread.test.ts +1 -1
  152. package/src/thread/thread.ts +5 -3
  153. package/src/{types/thread.ts → thread/types.ts} +1 -1
  154. package/src/thread/utils.ts +2 -2
  155. package/src/tool/index.ts +3 -0
  156. package/src/tool/sys/index.ts +7 -0
  157. package/src/tool/sys/memory.ts +120 -0
  158. package/src/tool/tool.ts +8 -4
  159. package/tsconfig.tsbuildinfo +1 -0
  160. package/dist/api/__tests__/cursor-page.test.d.ts +0 -2
  161. package/dist/api/__tests__/cursor-page.test.d.ts.map +0 -1
  162. package/dist/api/__tests__/cursor-page.test.js +0 -414
  163. package/dist/api/__tests__/offset-page.test.d.ts +0 -2
  164. package/dist/api/__tests__/offset-page.test.d.ts.map +0 -1
  165. package/dist/api/__tests__/offset-page.test.js +0 -510
  166. package/dist/api/pagination/base.d.ts +0 -48
  167. package/dist/api/pagination/base.d.ts.map +0 -1
  168. package/dist/api/pagination/base.js +0 -45
  169. package/dist/api/pagination/cursor.d.ts +0 -44
  170. package/dist/api/pagination/cursor.d.ts.map +0 -1
  171. package/dist/api/pagination/cursor.js +0 -52
  172. package/dist/api/pagination/offset.d.ts +0 -42
  173. package/dist/api/pagination/offset.d.ts.map +0 -1
  174. package/dist/api/pagination/offset.js +0 -55
  175. package/dist/kernl/threads.d.ts +0 -110
  176. package/dist/kernl/threads.d.ts.map +0 -1
  177. package/dist/kernl/threads.js +0 -126
  178. package/dist/kernl.d.ts +0 -51
  179. package/dist/kernl.d.ts.map +0 -1
  180. package/dist/kernl.js +0 -91
  181. package/dist/types/agent.d.ts.map +0 -1
  182. package/dist/types/kernl.d.ts +0 -42
  183. package/dist/types/kernl.d.ts.map +0 -1
  184. package/dist/types/thread.d.ts.map +0 -1
  185. package/src/api/__tests__/cursor-page.test.ts +0 -512
  186. package/src/api/__tests__/offset-page.test.ts +0 -624
  187. package/src/api/pagination/base.ts +0 -79
  188. package/src/api/pagination/cursor.ts +0 -86
  189. package/src/api/pagination/offset.ts +0 -89
  190. package/src/types/kernl.ts +0 -51
  191. /package/dist/{types/agent.js → agent/types.js} +0 -0
  192. /package/dist/{types/kernl.js → kernl/types.js} +0 -0
  193. /package/dist/{types/thread.js → thread/types.js} +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/tool/sys/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * System toolkits.
3
+ *
4
+ * These are internal toolkits that can be enabled via agent config flags.
5
+ */
6
+ export { memory } from "./memory.js";
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Memory system toolkit.
3
+ *
4
+ * Provides tools for agents to store and retrieve memories.
5
+ * Enabled via `memory: true` in agent config.
6
+ */
7
+ import { Toolkit } from "../toolkit.js";
8
+ /**
9
+ * Memory system toolkit.
10
+ *
11
+ * Provides memories.search, memories.create, and memories.list tools.
12
+ */
13
+ export declare const memory: Toolkit<unknown>;
14
+ //# sourceMappingURL=memory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../../../src/tool/sys/memory.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAmGrC;;;;GAIG;AACH,eAAO,MAAM,MAAM,kBAIjB,CAAC"}
@@ -0,0 +1,103 @@
1
+ /**
2
+ * Memory system toolkit.
3
+ *
4
+ * Provides tools for agents to store and retrieve memories.
5
+ * Enabled via `memory: true` in agent config.
6
+ */
7
+ import assert from "assert";
8
+ import { z } from "zod";
9
+ import { tool } from "../tool.js";
10
+ import { Toolkit } from "../toolkit.js";
11
+ // --- Tools ---
12
+ /**
13
+ * Search memories for relevant information using natural language.
14
+ */
15
+ const search = tool({
16
+ id: "memories.search",
17
+ description: "Search your memories. " +
18
+ "Use this to recall facts, preferences, or context you've previously stored.",
19
+ parameters: z.object({
20
+ query: z.string().describe("Natural language search query"),
21
+ limit: z
22
+ .number()
23
+ .int()
24
+ .positive()
25
+ .optional()
26
+ .describe("Max results (default: 10)"),
27
+ }),
28
+ execute: async (ctx, { query, limit }) => {
29
+ assert(ctx.agent, "ctx.agent required for memory tools");
30
+ const mems = await ctx.agent.memories.search({
31
+ query,
32
+ limit: limit ?? 10,
33
+ });
34
+ return mems.map((h) => ({
35
+ id: h.document?.id,
36
+ text: h.document?.text,
37
+ score: h.score,
38
+ }));
39
+ },
40
+ });
41
+ /**
42
+ * Store a new memory to persist across conversations.
43
+ */
44
+ const create = tool({
45
+ id: "memories.create",
46
+ description: "Store a new memory. Use this to remember important facts, user preferences, " +
47
+ "or context that should persist across conversations.",
48
+ parameters: z.object({
49
+ content: z.string().describe("Text content to remember"),
50
+ collection: z
51
+ .string()
52
+ .optional()
53
+ .describe("Category for organizing memories (default: 'facts')"),
54
+ }),
55
+ execute: async (ctx, { content, collection }) => {
56
+ assert(ctx.agent, "ctx.agent required for memory tools");
57
+ const mem = await ctx.agent.memories.create({
58
+ collection: collection ?? "facts",
59
+ content: { text: content },
60
+ });
61
+ return { id: mem.id, stored: true };
62
+ },
63
+ });
64
+ /**
65
+ * List stored memories, optionally filtered by collection.
66
+ */
67
+ const list = tool({
68
+ id: "memories.list",
69
+ description: "List your stored memories. Use this to see what you've remembered, " +
70
+ "optionally filtered by collection.",
71
+ parameters: z.object({
72
+ collection: z.string().optional().describe("Filter by collection name"),
73
+ limit: z
74
+ .number()
75
+ .int()
76
+ .positive()
77
+ .optional()
78
+ .describe("Max results (default: 20)"),
79
+ }),
80
+ execute: async (ctx, { collection, limit }) => {
81
+ assert(ctx.agent, "ctx.agent required for memory tools");
82
+ const mems = await ctx.agent.memories.list({
83
+ collection,
84
+ limit: limit ?? 20,
85
+ });
86
+ return mems.map((r) => ({
87
+ id: r.id,
88
+ collection: r.collection,
89
+ text: r.content.text,
90
+ }));
91
+ },
92
+ });
93
+ // --- Toolkit ---
94
+ /**
95
+ * Memory system toolkit.
96
+ *
97
+ * Provides memories.search, memories.create, and memories.list tools.
98
+ */
99
+ export const memory = new Toolkit({
100
+ id: "sys.memory",
101
+ description: "Tools for storing and retrieving agent memories",
102
+ tools: [list, create, search],
103
+ });
@@ -1,5 +1,5 @@
1
1
  import { Context, UnknownContext } from "../context.js";
2
- import type { LanguageModelTool } from "@kernl-sdk/protocol";
2
+ import { type LanguageModelTool } from "@kernl-sdk/protocol";
3
3
  import type { ToolConfig, ToolApprovalFunction, ToolEnabledFunction, ToolErrorFunction, ToolInputParameters, ToolResult } from "./types.js";
4
4
  /**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,SAAQ,QAAQ;IACtC,QAAQ,CAAC,IAAI,EAAG,aAAa,CAAU;IACvC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAE5C;;OAEG;IACH,OAAO,EAAE,iBAAiB,GAAG,IAAI,CAA4B;IAE7D;;OAEG;IACH,gBAAgB,EAAE,oBAAoB,CAAC,GAAG,CAAC,CAAqB;gBAEpD,MAAM,EAAE;QAClB,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;KACpC;IAOD;;OAEG;IACG,SAAS,IAAI,OAAO,CAAC,OAAO,CAAC;IAInC;;OAEG;IACH,SAAS,IAAI,iBAAiB;CAQ/B"}
package/dist/tool/tool.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import { z } from "zod";
2
2
  import { ModelBehaviorError } from "../lib/error.js";
3
3
  import { logger } from "../lib/logger.js";
4
+ import { FAILED, COMPLETED, INTERRUPTIBLE, } from "@kernl-sdk/protocol";
4
5
  import { json } from "@kernl-sdk/shared/lib";
5
- import { FAILED, COMPLETED, INTERRUPTIBLE } from "@kernl-sdk/protocol";
6
6
  /**
7
7
  * Exposes a function to the agent as a tool to be called
8
8
  *
@@ -122,7 +122,7 @@ export class FunctionTool extends BaseTool {
122
122
  description: this.description,
123
123
  parameters: z.toJSONSchema(this.parameters ?? z.object({}), {
124
124
  target: "draft-7",
125
- }), // Use empty object if no parameters (matches AI SDK)
125
+ }), // use empty object if no parameters (matches AI SDK)
126
126
  };
127
127
  }
128
128
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kernl",
3
- "version": "0.6.2",
3
+ "version": "0.7.0",
4
4
  "description": "A modern AI agent framework",
5
5
  "keywords": [
6
6
  "kernl",
@@ -36,6 +36,7 @@
36
36
  "pino": "^9.6.0",
37
37
  "zod": "^4.1.12",
38
38
  "@kernl-sdk/protocol": "0.2.5",
39
+ "@kernl-sdk/retrieval": "0.1.0",
39
40
  "@kernl-sdk/shared": "^0.1.6"
40
41
  },
41
42
  "devDependencies": {
@@ -44,9 +45,10 @@
44
45
  "tsc-alias": "^1.8.10",
45
46
  "typescript": "5.9.2",
46
47
  "vitest": "^4.0.8",
47
- "@kernl-sdk/ai": "0.2.6"
48
+ "@kernl-sdk/ai": "0.2.7"
48
49
  },
49
50
  "scripts": {
51
+ "clean": "rm -rf dist",
50
52
  "build": "tsc && tsc-alias --resolve-full-paths",
51
53
  "dev": "tsc --watch",
52
54
  "lint": "eslint src/",
@@ -0,0 +1,146 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import { Agent } from "@/agent";
3
+ import { Kernl } from "@/kernl";
4
+ import { Context } from "@/context";
5
+ import { createMockModel } from "@/thread/__tests__/fixtures/mock-model";
6
+ import { message } from "@kernl-sdk/protocol";
7
+
8
+ describe("Agent systools", () => {
9
+ const model = createMockModel(async () => ({
10
+ content: [message({ role: "assistant", text: "Done" })],
11
+ finishReason: "stop",
12
+ usage: { inputTokens: 2, outputTokens: 2, totalTokens: 4 },
13
+ warnings: [],
14
+ }));
15
+
16
+ describe("memory toolkit", () => {
17
+ it("adds memory toolkit when memory.enabled is true", () => {
18
+ const agent = new Agent({
19
+ id: "test-agent",
20
+ name: "Test",
21
+ instructions: "Test",
22
+ model,
23
+ memory: { enabled: true },
24
+ });
25
+
26
+ const kernl = new Kernl();
27
+ kernl.register(agent);
28
+
29
+ expect(agent.systools.length).toBe(1);
30
+ expect(agent.systools[0].id).toBe("sys.memory");
31
+ });
32
+
33
+ it("has no systools when memory not configured", () => {
34
+ const agent = new Agent({
35
+ id: "test-agent",
36
+ name: "Test",
37
+ instructions: "Test",
38
+ model,
39
+ });
40
+
41
+ const kernl = new Kernl();
42
+ kernl.register(agent);
43
+
44
+ expect(agent.systools.length).toBe(0);
45
+ });
46
+
47
+ it("has no systools when memory.enabled is false", () => {
48
+ const agent = new Agent({
49
+ id: "test-agent",
50
+ name: "Test",
51
+ instructions: "Test",
52
+ model,
53
+ memory: { enabled: false },
54
+ });
55
+
56
+ const kernl = new Kernl();
57
+ kernl.register(agent);
58
+
59
+ expect(agent.systools.length).toBe(0);
60
+ });
61
+
62
+ it("can retrieve memory tools via agent.tool()", () => {
63
+ const agent = new Agent({
64
+ id: "test-agent",
65
+ name: "Test",
66
+ instructions: "Test",
67
+ model,
68
+ memory: { enabled: true },
69
+ });
70
+
71
+ const kernl = new Kernl();
72
+ kernl.register(agent);
73
+
74
+ expect(agent.tool("memories.search")).toBeDefined();
75
+ expect(agent.tool("memories.create")).toBeDefined();
76
+ expect(agent.tool("memories.list")).toBeDefined();
77
+ });
78
+
79
+ it("includes memory tools in agent.tools() output", async () => {
80
+ const agent = new Agent({
81
+ id: "test-agent",
82
+ name: "Test",
83
+ instructions: "Test",
84
+ model,
85
+ memory: { enabled: true },
86
+ });
87
+
88
+ const kernl = new Kernl();
89
+ kernl.register(agent);
90
+
91
+ const ctx = new Context("test");
92
+ const tools = await agent.tools(ctx);
93
+ const ids = tools.map((t) => t.id);
94
+
95
+ expect(ids).toContain("memories.search");
96
+ expect(ids).toContain("memories.create");
97
+ expect(ids).toContain("memories.list");
98
+ });
99
+
100
+ it("systools appear before user toolkits in tools() output", async () => {
101
+ const agent = new Agent({
102
+ id: "test-agent",
103
+ name: "Test",
104
+ instructions: "Test",
105
+ model,
106
+ memory: { enabled: true },
107
+ });
108
+
109
+ const kernl = new Kernl();
110
+ kernl.register(agent);
111
+
112
+ const ctx = new Context("test");
113
+ const tools = await agent.tools(ctx);
114
+
115
+ // Memory tools should be first (from systools)
116
+ expect(tools[0].id).toBe("memories.search");
117
+ expect(tools[1].id).toBe("memories.create");
118
+ expect(tools[2].id).toBe("memories.list");
119
+ });
120
+ });
121
+
122
+ describe("memory config defaults", () => {
123
+ it("defaults memory to { enabled: false }", () => {
124
+ const agent = new Agent({
125
+ id: "test-agent",
126
+ name: "Test",
127
+ instructions: "Test",
128
+ model,
129
+ });
130
+
131
+ expect(agent.memory).toEqual({ enabled: false });
132
+ });
133
+
134
+ it("preserves memory config when provided", () => {
135
+ const agent = new Agent({
136
+ id: "test-agent",
137
+ name: "Test",
138
+ instructions: "Test",
139
+ model,
140
+ memory: { enabled: true },
141
+ });
142
+
143
+ expect(agent.memory).toEqual({ enabled: true });
144
+ });
145
+ });
146
+ });
@@ -8,7 +8,7 @@ import {
8
8
  import { InputGuardrail, OutputGuardrail } from "@/guardrail";
9
9
  import { BaseToolkit } from "@/tool";
10
10
 
11
- import { TextResponse } from "./thread";
11
+ import { TextResponse } from "@/thread/types";
12
12
 
13
13
  /**
14
14
  * Configuration for an agent.
@@ -23,6 +23,9 @@ export interface AgentConfig<
23
23
  /* The name of the agent (defaults to ID if not provided) */
24
24
  name: string;
25
25
 
26
+ /* A brief description of the agent's purpose */
27
+ description?: string;
28
+
26
29
  /**
27
30
  * The instructions for the agent. Will be used as the "system prompt" when this agent is
28
31
  * invoked. Describes what the agent should do, and how it responds.
@@ -85,6 +88,14 @@ export interface AgentConfig<
85
88
  */
86
89
  toolkits?: BaseToolkit<TContext>[];
87
90
 
91
+ /**
92
+ * Memory configuration for this agent.
93
+ * Enables memory system tools (memories.search, memories.create, memories.list).
94
+ *
95
+ * Requires kernl to be configured with memory storage.
96
+ */
97
+ memory?: AgentMemoryConfig;
98
+
88
99
  /**
89
100
  * A list of checks that run in parallel to the agent's execution on the input + output for the agent,
90
101
  * depending on the configuration.
@@ -146,3 +157,13 @@ export interface AgentGuardrails<
146
157
  * 'text' is a special type that indicates the output will be a string.
147
158
  */
148
159
  export type AgentResponseType = TextResponse | ZodType;
160
+
161
+ /**
162
+ * Memory configuration for an agent.
163
+ */
164
+ export interface AgentMemoryConfig {
165
+ /**
166
+ * Enable memory system tools for this agent.
167
+ */
168
+ enabled: boolean;
169
+ }
package/src/agent.ts CHANGED
@@ -15,7 +15,7 @@ import type {
15
15
  RThreadUpdateParams,
16
16
  } from "@/api/resources/threads/types";
17
17
  import type { Context, UnknownContext } from "./context";
18
- import { Tool } from "./tool";
18
+ import { Tool, memory } from "./tool";
19
19
  import { BaseToolkit } from "./tool/toolkit";
20
20
  import {
21
21
  InputGuardrail,
@@ -23,15 +23,27 @@ import {
23
23
  type ResolvedAgentResponse,
24
24
  } from "./guardrail";
25
25
  import { AgentHooks } from "./lifecycle";
26
+ import type {
27
+ AgentMemoryCreate,
28
+ MemoryListOptions,
29
+ MemorySearchQuery,
30
+ } from "./memory";
26
31
 
32
+ import { randomID } from "@kernl-sdk/shared/lib";
27
33
  import { MisconfiguredError, RuntimeError } from "./lib/error";
28
- import type { AgentConfig, AgentResponseType } from "./types/agent";
34
+
35
+ /* types */
36
+ import type {
37
+ AgentConfig,
38
+ AgentMemoryConfig,
39
+ AgentResponseType,
40
+ } from "./agent/types";
29
41
  import type {
30
42
  TextResponse,
31
43
  ThreadExecuteOptions,
32
44
  ThreadExecuteResult,
33
45
  ThreadStreamEvent,
34
- } from "./types/thread";
46
+ } from "./thread/types";
35
47
 
36
48
  export class Agent<
37
49
  TContext = UnknownContext,
@@ -44,12 +56,15 @@ export class Agent<
44
56
 
45
57
  id: string;
46
58
  name: string;
59
+ description?: string;
47
60
  instructions: (context: Context<TContext>) => Promise<string> | string;
48
61
 
49
62
  model: LanguageModel;
50
63
  modelSettings: LanguageModelRequestSettings;
51
- toolkits: BaseToolkit<TContext>[];
52
64
  // actions: ActionSet; /* TODO */
65
+ toolkits: BaseToolkit<TContext>[];
66
+ systools: BaseToolkit<TContext>[];
67
+ memory: AgentMemoryConfig;
53
68
 
54
69
  guardrails: {
55
70
  input: InputGuardrail[];
@@ -57,10 +72,9 @@ export class Agent<
57
72
  };
58
73
  responseType: TResponse = "text" as TResponse;
59
74
  resetToolChoice: boolean;
60
- // toolUseBehavior: ToolUseBehavior; (TODO)
61
75
 
62
76
  // --- (TODO) ---
63
- // handoffDescription: string; // ??
77
+ // toolUseBehavior: ToolUseBehavior;
64
78
  // handoffs: (Agent<any, TResponse> | Handoff<any, TResponse>)[];
65
79
  // ----------
66
80
 
@@ -79,6 +93,7 @@ export class Agent<
79
93
  }
80
94
  this.id = config.id;
81
95
  this.name = config.name;
96
+ this.description = config.description;
82
97
  this.instructions =
83
98
  typeof config.instructions === "function"
84
99
  ? config.instructions
@@ -87,6 +102,9 @@ export class Agent<
87
102
  this.modelSettings = config.modelSettings ?? {};
88
103
 
89
104
  this.toolkits = config.toolkits ?? [];
105
+ this.systools = [];
106
+ this.memory = config.memory ?? { enabled: false };
107
+
90
108
  for (const toolkit of this.toolkits) {
91
109
  toolkit.bind(this);
92
110
  }
@@ -97,21 +115,6 @@ export class Agent<
97
115
  }
98
116
  this.resetToolChoice = config.resetToolChoice ?? true;
99
117
  // this.toolUseBehavior = config.toolUseBehavior ?? "run_llm_again";
100
-
101
- // this.handoffDescription = config.handoffDescription ?? "";
102
- // this.handoffs = config.handoffs ?? [];
103
-
104
- // --- Runtime warning for handoff response type compatibility ---
105
- // if (config.handoffresponseTypeWarningEnabled) {
106
- // ...
107
- // if (responseTypes.size > 1) {
108
- // logger.warn(
109
- // `[Agent] Warning: Handoff agents have different response types: ${Array.from(responseTypes).join(", ")}.
110
- // You can make it type-safe by using Agent.create({ ... }) method instead.`,
111
- // );
112
- // }
113
- // }
114
- // }
115
118
  }
116
119
 
117
120
  /**
@@ -119,6 +122,14 @@ export class Agent<
119
122
  */
120
123
  bind(kernl: Kernl): void {
121
124
  this.kernl = kernl;
125
+
126
+ // initialize system toolkits
127
+ if (this.memory.enabled) {
128
+ // safety: system tools only rely on ctx.agent, not ctx.context
129
+ const toolkit = memory as unknown as BaseToolkit<TContext>;
130
+ this.systools.push(toolkit);
131
+ toolkit.bind(this);
132
+ }
122
133
  }
123
134
 
124
135
  /**
@@ -245,12 +256,18 @@ export class Agent<
245
256
  /**
246
257
  * @internal
247
258
  *
248
- * Get a specific tool by ID from all toolkits.
259
+ * Get a specific tool by ID from systools and toolkits.
249
260
  *
250
261
  * @param id The tool ID to look up
251
262
  * @returns The tool if found, undefined otherwise
252
263
  */
253
264
  tool(id: string): Tool<TContext> | undefined {
265
+ // Check systools first
266
+ for (const toolkit of this.systools) {
267
+ const tool = toolkit.get(id);
268
+ if (tool) return tool;
269
+ }
270
+ // Then user toolkits
254
271
  for (const toolkit of this.toolkits) {
255
272
  const tool = toolkit.get(id);
256
273
  if (tool) return tool;
@@ -261,7 +278,7 @@ export class Agent<
261
278
  /**
262
279
  * @internal
263
280
  *
264
- * Get all tools available from all toolkits for the given context.
281
+ * Get all tools available from systools and toolkits for the given context.
265
282
  * Checks for duplicate tool IDs across toolkits and throws an error if found.
266
283
  *
267
284
  * (TODO): Consider returning toolkits alongside tools so we can serialize them
@@ -272,24 +289,22 @@ export class Agent<
272
289
  * @throws {MisconfiguredError} If duplicate tool IDs are found across toolkits
273
290
  */
274
291
  async tools(context: Context<TContext>): Promise<Tool<TContext>[]> {
275
- const allTools: Tool<TContext>[] = [];
276
- const toolIds = new Set<string>();
292
+ const all: Tool<TContext>[] = [];
277
293
 
278
- for (const toolkit of this.toolkits) {
279
- const tools = await toolkit.list(context);
294
+ for (const toolkit of [...this.systools, ...this.toolkits]) {
295
+ all.push(...(await toolkit.list(context)));
296
+ }
280
297
 
281
- const duplicates = tools.map((t) => t.id).filter((id) => toolIds.has(id));
282
- if (duplicates.length > 0) {
283
- throw new MisconfiguredError(
284
- `Duplicate tool IDs found across toolkits: ${duplicates.join(", ")}`,
285
- );
286
- }
298
+ const ids = all.map((t) => t.id);
299
+ const duplicates = ids.filter((id, i) => ids.indexOf(id) !== i);
287
300
 
288
- tools.forEach((t) => toolIds.add(t.id));
289
- allTools.push(...tools);
301
+ if (duplicates.length > 0) {
302
+ throw new MisconfiguredError(
303
+ `Duplicate tool IDs found: ${[...new Set(duplicates)].join(", ")}`,
304
+ );
290
305
  }
291
306
 
292
- return allTools;
307
+ return all;
293
308
  }
294
309
 
295
310
  /**
@@ -328,4 +343,97 @@ export class Agent<
328
343
  kthreads.update(tid, patch),
329
344
  };
330
345
  }
346
+
347
+ /**
348
+ * Memory management scoped to this agent.
349
+ *
350
+ * Provides a simplified API for creating memories with:
351
+ * - Auto-generated IDs
352
+ * - Flattened scope fields (namespace, entityId) - agentId is implicit
353
+ * - Default kind of "semantic"
354
+ *
355
+ * @example
356
+ * ```ts
357
+ * await agent.memories.create({
358
+ * namespace: "user-123",
359
+ * collection: "preferences",
360
+ * content: { text: "User prefers TypeScript" },
361
+ * });
362
+ * ```
363
+ */
364
+ get memories() {
365
+ if (!this.kernl) {
366
+ throw new MisconfiguredError(
367
+ `Agent ${this.id} not bound to kernl. Call kernl.register(agent) first.`,
368
+ );
369
+ }
370
+
371
+ const agentId = this.id;
372
+ const kmem = this.kernl.memories;
373
+
374
+ return {
375
+ /**
376
+ * List memories scoped to this agent.
377
+ */
378
+ list: (
379
+ params?: Omit<MemoryListOptions, "filter"> & {
380
+ collection?: string;
381
+ limit?: number;
382
+ // (TODO): we might want to add the filter back here
383
+ },
384
+ ) =>
385
+ kmem.list({
386
+ filter: {
387
+ scope: { agentId },
388
+ collections: params?.collection ? [params.collection] : undefined,
389
+ },
390
+ limit: params?.limit,
391
+ }),
392
+
393
+ /**
394
+ * Create a new memory scoped to this agent.
395
+ */
396
+ create: (params: AgentMemoryCreate) =>
397
+ kmem.create({
398
+ id: params.id ?? `mem_${randomID()}`,
399
+ scope: {
400
+ namespace: params.namespace,
401
+ entityId: params.entityId,
402
+ agentId,
403
+ },
404
+ kind: "semantic",
405
+ collection: params.collection,
406
+ content: params.content,
407
+ wmem: params.wmem,
408
+ smem: params.smem,
409
+ timestamp: params.timestamp,
410
+ metadata: params.metadata,
411
+ }),
412
+
413
+ /**
414
+ * Search memories scoped to this agent.
415
+ */
416
+ search: (
417
+ params: Omit<MemorySearchQuery, "filter"> & {
418
+ // (TODO): is this correct?
419
+ filter?: Omit<NonNullable<MemorySearchQuery["filter"]>, "scope"> & {
420
+ scope?: Omit<
421
+ NonNullable<NonNullable<MemorySearchQuery["filter"]>["scope"]>,
422
+ "agentId"
423
+ >;
424
+ };
425
+ },
426
+ ) =>
427
+ kmem.search({
428
+ ...params,
429
+ filter: {
430
+ ...params.filter,
431
+ scope: {
432
+ ...params.filter?.scope,
433
+ agentId,
434
+ },
435
+ },
436
+ }),
437
+ };
438
+ }
331
439
  }
@@ -4,10 +4,10 @@ import { message, RUNNING } from "@kernl-sdk/protocol";
4
4
 
5
5
  import { Agent } from "@/agent";
6
6
  import { InMemoryThreadStore } from "@/storage/in-memory";
7
- import type { AgentRegistry, ModelRegistry } from "@/types/kernl";
7
+ import type { AgentRegistry, ModelRegistry } from "@/kernl/types";
8
8
  import type { NewThread } from "@/storage";
9
9
  import { tevent } from "@/thread/utils";
10
- import type { ThreadEvent } from "@/types/thread";
10
+ import type { ThreadEvent } from "@/thread/types";
11
11
  import { RThreads } from "@/api/resources/threads";
12
12
  import type { MThread } from "@/api/models";
13
13