kernl 0.6.3 → 0.7.1
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/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +23 -0
- package/dist/agent/__tests__/systools.test.d.ts +2 -0
- package/dist/agent/__tests__/systools.test.d.ts.map +1 -0
- package/dist/agent/__tests__/systools.test.js +121 -0
- package/dist/agent/types.d.ts +17 -0
- package/dist/agent/types.d.ts.map +1 -1
- package/dist/agent.d.ts +14 -4
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +45 -30
- package/dist/api/resources/agents/agents.d.ts +38 -0
- package/dist/api/resources/agents/agents.d.ts.map +1 -0
- package/dist/api/resources/agents/agents.js +44 -0
- package/dist/api/resources/agents/index.d.ts +2 -0
- package/dist/api/resources/agents/index.d.ts.map +1 -0
- package/dist/api/resources/agents/index.js +1 -0
- package/dist/context.d.ts +6 -0
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +5 -0
- package/dist/kernl/kernl.d.ts +4 -2
- package/dist/kernl/kernl.d.ts.map +1 -1
- package/dist/kernl/kernl.js +11 -8
- package/dist/memory/memory.d.ts +5 -1
- package/dist/memory/memory.d.ts.map +1 -1
- package/dist/memory/memory.js +6 -0
- package/dist/thread/thread.d.ts.map +1 -1
- package/dist/thread/thread.js +3 -1
- package/dist/tool/index.d.ts +1 -0
- package/dist/tool/index.d.ts.map +1 -1
- package/dist/tool/index.js +2 -0
- package/dist/tool/sys/index.d.ts +7 -0
- package/dist/tool/sys/index.d.ts.map +1 -0
- package/dist/tool/sys/index.js +6 -0
- package/dist/tool/sys/memory.d.ts +14 -0
- package/dist/tool/sys/memory.d.ts.map +1 -0
- package/dist/tool/sys/memory.js +103 -0
- package/dist/tool/tool.d.ts +1 -1
- package/dist/tool/tool.d.ts.map +1 -1
- package/dist/tool/tool.js +2 -2
- package/package.json +5 -5
- package/src/agent/__tests__/systools.test.ts +146 -0
- package/src/agent/types.ts +21 -0
- package/src/agent.ts +70 -38
- package/src/api/resources/agents/agents.ts +56 -0
- package/src/api/resources/agents/index.ts +1 -0
- package/src/context.ts +8 -0
- package/src/kernl/kernl.ts +11 -8
- package/src/memory/memory.ts +8 -0
- package/src/thread/thread.ts +3 -1
- package/src/tool/index.ts +3 -0
- package/src/tool/sys/index.ts +7 -0
- package/src/tool/sys/memory.ts +120 -0
- package/src/tool/tool.ts +8 -4
package/dist/memory/memory.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { SearchHit } from "@kernl-sdk/retrieval";
|
|
2
|
-
import type { NewMemory, MemoryRecord, MemoryRecordUpdate, MemoryScope, MemoryConfig, MemorySearchQuery, IndexMemoryRecord, WorkingMemorySnapshot, ShortTermMemorySnapshot, MemoryReindexParams } from "./types.js";
|
|
2
|
+
import type { NewMemory, MemoryRecord, MemoryRecordUpdate, MemoryScope, MemoryConfig, MemorySearchQuery, MemoryListOptions, IndexMemoryRecord, WorkingMemorySnapshot, ShortTermMemorySnapshot, MemoryReindexParams } from "./types.js";
|
|
3
3
|
/**
|
|
4
4
|
* Memory is the primary memory abstraction for agents.
|
|
5
5
|
*
|
|
@@ -35,6 +35,10 @@ export declare class Memory {
|
|
|
35
35
|
* adapts based on backend capabilities (e.g. drops text for pgvector).
|
|
36
36
|
*/
|
|
37
37
|
search(q: MemorySearchQuery): Promise<SearchHit<IndexMemoryRecord>[]>;
|
|
38
|
+
/**
|
|
39
|
+
* List memories matching the filter.
|
|
40
|
+
*/
|
|
41
|
+
list(options?: MemoryListOptions): Promise<MemoryRecord[]>;
|
|
38
42
|
/**
|
|
39
43
|
* Repair indexing for a memory without modifying the DB row.
|
|
40
44
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../../src/memory/memory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAe,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAInE,OAAO,KAAK,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,mBAAmB,EACpB,MAAM,SAAS,CAAC;AAGjB;;;;;;;;;;;GAWG;AACH,qBAAa,MAAM;IACjB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAc;IACpC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAwC;IAEhE,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAkB;IAC1C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA8C;gBAEzD,MAAM,EAAE,YAAY;IAShC;;;OAGG;IACG,MAAM,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC,YAAY,CAAC;IAYtD;;;OAGG;IACG,MAAM,CAAC,MAAM,EAAE,kBAAkB,GAAG,OAAO,CAAC,YAAY,CAAC;IAe/D;;;;;OAKG;IACG,MAAM,CAAC,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,SAAS,CAAC,iBAAiB,CAAC,EAAE,CAAC;IAc3E;;OAEG;IACG,IAAI,CAAC,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC;IAIhE;;OAEG;IACG,OAAO,CAAC,MAAM,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;IAgBzD;;OAEG;IACG,iBAAiB,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAO3E;;OAEG;IACG,mBAAmB,CACvB,KAAK,EAAE,WAAW,GACjB,OAAO,CAAC,uBAAuB,CAAC;CAMpC"}
|
package/dist/memory/memory.js
CHANGED
|
@@ -71,6 +71,12 @@ export class Memory {
|
|
|
71
71
|
topK: q.limit ?? 20,
|
|
72
72
|
});
|
|
73
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* List memories matching the filter.
|
|
76
|
+
*/
|
|
77
|
+
async list(options) {
|
|
78
|
+
return this.store.list(options);
|
|
79
|
+
}
|
|
74
80
|
/**
|
|
75
81
|
* Repair indexing for a memory without modifying the DB row.
|
|
76
82
|
*/
|
|
@@ -1 +1 @@
|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C,QAAQ,CAAC,GAAG,IAAI,CAAC;IACvC,QAAQ,CAAC,SAAS,EAAE,IAAI,CAAC;IACzB,QAAQ,CAAC,SAAS,EAAE,IAAI,CAAC;IACzB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IAIlD,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,WAAW,CAAC;IACnB,OAAO,CAAC,KAAK,CAAgB;IAC7B,OAAO,CAAC,SAAS,CAAU;IAC3B,OAAO,CAAC,OAAO,CAAwE;IAEvF,OAAO,CAAC,KAAK,CAAC,CAAkB;IAChC,OAAO,CAAC,OAAO,CAAC,CAAc;gBAElB,OAAO,EAAE,aAAa,CAAC,QAAQ,EAAE,SAAS,CAAC;IAgCvD;;OAEG;IACG,OAAO,IAAI,OAAO,CACtB,mBAAmB,CAAC,qBAAqB,CAAC,SAAS,CAAC,CAAC,CACtD;IAoBD;;OAEG;IACI,MAAM,IAAI,aAAa,CAAC,iBAAiB,CAAC;IAuBjD;;;;;OAKG;YACY,QAAQ;IAgEvB;;;;;OAKG;YACY,IAAI;IA8BnB;;;;;OAKG;YACW,UAAU;IAuCxB;;;;;;OAMG;IACH,MAAM,CAAC,GAAG,KAAK,EAAE,gBAAgB,EAAE,GAAG,WAAW,EAAE;IAiBnD;;OAEG;IACH,MAAM;IAQN;;OAEG;YACW,cAAc;IAyC5B;;;;OAIG;YACW,YAAY;IA4C1B;;OAEG;YACW,mBAAmB;CA2ClC"}
|
package/dist/thread/thread.js
CHANGED
|
@@ -70,6 +70,7 @@ export class Thread {
|
|
|
70
70
|
this.agent = options.agent;
|
|
71
71
|
this.context =
|
|
72
72
|
options.context ?? new Context(this.namespace, {});
|
|
73
|
+
this.context.agent = options.agent;
|
|
73
74
|
this.parent = options.task ?? null;
|
|
74
75
|
this.model = options.model ?? options.agent.model;
|
|
75
76
|
this.storage = options.storage;
|
|
@@ -262,7 +263,7 @@ export class Thread {
|
|
|
262
263
|
state: this.state,
|
|
263
264
|
tick: this._tick,
|
|
264
265
|
context: this.context,
|
|
265
|
-
metadata
|
|
266
|
+
// no metadata - not owned by checkpoint
|
|
266
267
|
});
|
|
267
268
|
}
|
|
268
269
|
/**
|
|
@@ -351,6 +352,7 @@ export class Thread {
|
|
|
351
352
|
// (TMP) - passing the approval status through the context until actions system
|
|
352
353
|
// is refined
|
|
353
354
|
const ctx = new Context(this.namespace, this.context.context);
|
|
355
|
+
ctx.agent = this.agent;
|
|
354
356
|
ctx.approve(call.callId); // mark this call as approved
|
|
355
357
|
const res = await tool.invoke(ctx, call.arguments, call.callId);
|
|
356
358
|
return {
|
package/dist/tool/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { BaseTool, FunctionTool, HostedTool, tool } from "./tool.js";
|
|
2
2
|
export { BaseToolkit, Toolkit, FunctionToolkit, MCPToolkit } from "./toolkit.js";
|
|
3
3
|
export type { Tool, ToolResult, FunctionToolkitConfig, MCPToolkitConfig, ToolkitFilter, ToolkitFilterContext, } from "./types.js";
|
|
4
|
+
export { memory } from "./sys/index.js";
|
|
4
5
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/tool/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tool/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAC9E,YAAY,EACV,IAAI,EACJ,UAAU,EACV,qBAAqB,EACrB,gBAAgB,EAChB,aAAa,EACb,oBAAoB,GACrB,MAAM,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tool/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAC9E,YAAY,EACV,IAAI,EACJ,UAAU,EACV,qBAAqB,EACrB,gBAAgB,EAChB,aAAa,EACb,oBAAoB,GACrB,MAAM,SAAS,CAAC;AAGjB,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC"}
|
package/dist/tool/index.js
CHANGED
|
@@ -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,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
|
+
});
|
package/dist/tool/tool.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Context, UnknownContext } from "../context.js";
|
|
2
|
-
import type
|
|
2
|
+
import { type LanguageModelTool } from "@kernl-sdk/protocol";
|
|
3
3
|
import type { ToolConfig, ToolApprovalFunction, ToolEnabledFunction, ToolErrorFunction, ToolInputParameters, ToolResult } from "./types.js";
|
|
4
4
|
/**
|
|
5
5
|
* Exposes a function to the agent as a tool to be called
|
package/dist/tool/tool.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool.d.ts","sourceRoot":"","sources":["../../src/tool/tool.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"tool.d.ts","sourceRoot":"","sources":["../../src/tool/tool.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAKpD,OAAO,EAIL,KAAK,iBAAiB,EACvB,MAAM,qBAAqB,CAAC;AAG7B,OAAO,KAAK,EACV,UAAU,EACV,oBAAoB,EACpB,mBAAmB,EAEnB,iBAAiB,EAGjB,mBAAmB,EACnB,UAAU,EACX,MAAM,SAAS,CAAC;AAEjB;;;;;GAKG;AACH,wBAAgB,IAAI,CAClB,QAAQ,GAAG,cAAc,EACzB,WAAW,SAAS,mBAAmB,GAAG,SAAS,EACnD,OAAO,GAAG,MAAM,EAEhB,MAAM,EAAE,UAAU,CAAC,QAAQ,EAAE,WAAW,EAAE,OAAO,CAAC,GACjD,YAAY,CAAC,QAAQ,EAAE,WAAW,EAAE,OAAO,CAAC,CAE9C;AAED;;GAEG;AACH,8BAAsB,QAAQ,CAAC,QAAQ,GAAG,cAAc;IACtD,QAAQ,CAAC,QAAQ,CAAC,IAAI,EAAE,UAAU,GAAG,aAAa,CAAC;IACnD,QAAQ,CAAC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAA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,CAAC,OAAO,CAAC,CAAC;IAgB/B;;OAEG;YACW,OAAO;IAuCrB;;OAEG;IACH,SAAS,IAAI,iBAAiB;CAU/B;AAED;;GAEG;AACH,qBAAa,UAAW,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
|
-
}), //
|
|
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.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"description": "A modern AI agent framework",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"kernl",
|
|
@@ -35,9 +35,9 @@
|
|
|
35
35
|
"@modelcontextprotocol/sdk": "^1.20.2",
|
|
36
36
|
"pino": "^9.6.0",
|
|
37
37
|
"zod": "^4.1.12",
|
|
38
|
-
"@kernl-sdk/protocol": "0.2.
|
|
39
|
-
"@kernl-sdk/
|
|
40
|
-
"@kernl-sdk/
|
|
38
|
+
"@kernl-sdk/protocol": "0.2.6",
|
|
39
|
+
"@kernl-sdk/shared": "^0.2.0",
|
|
40
|
+
"@kernl-sdk/retrieval": "0.1.1"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@ai-sdk/openai": "3.0.0-beta.57",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"tsc-alias": "^1.8.10",
|
|
46
46
|
"typescript": "5.9.2",
|
|
47
47
|
"vitest": "^4.0.8",
|
|
48
|
-
"@kernl-sdk/ai": "0.2.
|
|
48
|
+
"@kernl-sdk/ai": "0.2.8"
|
|
49
49
|
},
|
|
50
50
|
"scripts": {
|
|
51
51
|
"clean": "rm -rf dist",
|
|
@@ -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
|
+
});
|
package/src/agent/types.ts
CHANGED
|
@@ -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
|
+
}
|