kernl 0.6.3 → 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.
- package/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +14 -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 +42 -13
- 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 +1 -1
- 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/.turbo/turbo-build.log
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @kernl/core
|
|
2
2
|
|
|
3
|
+
## 0.7.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 13545a5: Add memory system tools and agents public API
|
|
8
|
+
- Add system tools infrastructure (`agent.systools`) for built-in agent capabilities
|
|
9
|
+
- Add memory toolkit with `memories.search`, `memories.create`, `memories.list` tools
|
|
10
|
+
- Add `memory: { enabled: true }` agent config to enable memory tools
|
|
11
|
+
- Add `ctx.agent` reference for tools to access agent APIs
|
|
12
|
+
- Add `kernl.agents` public API with `get`, `list`, `has`, `unregister` methods
|
|
13
|
+
- Add `Memory.list()` method for listing memories with filters
|
|
14
|
+
- Add `agent.description` field for agent metadata
|
|
15
|
+
- Fix: exclude metadata from thread checkpoint to prevent race conditions
|
|
16
|
+
|
|
3
17
|
## 0.6.3
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"systools.test.d.ts","sourceRoot":"","sources":["../../../src/agent/__tests__/systools.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { Agent } from "../../agent.js";
|
|
3
|
+
import { Kernl } from "../../kernl/index.js";
|
|
4
|
+
import { Context } from "../../context.js";
|
|
5
|
+
import { createMockModel } from "../../thread/__tests__/fixtures/mock-model.js";
|
|
6
|
+
import { message } from "@kernl-sdk/protocol";
|
|
7
|
+
describe("Agent systools", () => {
|
|
8
|
+
const model = createMockModel(async () => ({
|
|
9
|
+
content: [message({ role: "assistant", text: "Done" })],
|
|
10
|
+
finishReason: "stop",
|
|
11
|
+
usage: { inputTokens: 2, outputTokens: 2, totalTokens: 4 },
|
|
12
|
+
warnings: [],
|
|
13
|
+
}));
|
|
14
|
+
describe("memory toolkit", () => {
|
|
15
|
+
it("adds memory toolkit when memory.enabled is true", () => {
|
|
16
|
+
const agent = new Agent({
|
|
17
|
+
id: "test-agent",
|
|
18
|
+
name: "Test",
|
|
19
|
+
instructions: "Test",
|
|
20
|
+
model,
|
|
21
|
+
memory: { enabled: true },
|
|
22
|
+
});
|
|
23
|
+
const kernl = new Kernl();
|
|
24
|
+
kernl.register(agent);
|
|
25
|
+
expect(agent.systools.length).toBe(1);
|
|
26
|
+
expect(agent.systools[0].id).toBe("sys.memory");
|
|
27
|
+
});
|
|
28
|
+
it("has no systools when memory not configured", () => {
|
|
29
|
+
const agent = new Agent({
|
|
30
|
+
id: "test-agent",
|
|
31
|
+
name: "Test",
|
|
32
|
+
instructions: "Test",
|
|
33
|
+
model,
|
|
34
|
+
});
|
|
35
|
+
const kernl = new Kernl();
|
|
36
|
+
kernl.register(agent);
|
|
37
|
+
expect(agent.systools.length).toBe(0);
|
|
38
|
+
});
|
|
39
|
+
it("has no systools when memory.enabled is false", () => {
|
|
40
|
+
const agent = new Agent({
|
|
41
|
+
id: "test-agent",
|
|
42
|
+
name: "Test",
|
|
43
|
+
instructions: "Test",
|
|
44
|
+
model,
|
|
45
|
+
memory: { enabled: false },
|
|
46
|
+
});
|
|
47
|
+
const kernl = new Kernl();
|
|
48
|
+
kernl.register(agent);
|
|
49
|
+
expect(agent.systools.length).toBe(0);
|
|
50
|
+
});
|
|
51
|
+
it("can retrieve memory tools via agent.tool()", () => {
|
|
52
|
+
const agent = new Agent({
|
|
53
|
+
id: "test-agent",
|
|
54
|
+
name: "Test",
|
|
55
|
+
instructions: "Test",
|
|
56
|
+
model,
|
|
57
|
+
memory: { enabled: true },
|
|
58
|
+
});
|
|
59
|
+
const kernl = new Kernl();
|
|
60
|
+
kernl.register(agent);
|
|
61
|
+
expect(agent.tool("memories.search")).toBeDefined();
|
|
62
|
+
expect(agent.tool("memories.create")).toBeDefined();
|
|
63
|
+
expect(agent.tool("memories.list")).toBeDefined();
|
|
64
|
+
});
|
|
65
|
+
it("includes memory tools in agent.tools() output", async () => {
|
|
66
|
+
const agent = new Agent({
|
|
67
|
+
id: "test-agent",
|
|
68
|
+
name: "Test",
|
|
69
|
+
instructions: "Test",
|
|
70
|
+
model,
|
|
71
|
+
memory: { enabled: true },
|
|
72
|
+
});
|
|
73
|
+
const kernl = new Kernl();
|
|
74
|
+
kernl.register(agent);
|
|
75
|
+
const ctx = new Context("test");
|
|
76
|
+
const tools = await agent.tools(ctx);
|
|
77
|
+
const ids = tools.map((t) => t.id);
|
|
78
|
+
expect(ids).toContain("memories.search");
|
|
79
|
+
expect(ids).toContain("memories.create");
|
|
80
|
+
expect(ids).toContain("memories.list");
|
|
81
|
+
});
|
|
82
|
+
it("systools appear before user toolkits in tools() output", async () => {
|
|
83
|
+
const agent = new Agent({
|
|
84
|
+
id: "test-agent",
|
|
85
|
+
name: "Test",
|
|
86
|
+
instructions: "Test",
|
|
87
|
+
model,
|
|
88
|
+
memory: { enabled: true },
|
|
89
|
+
});
|
|
90
|
+
const kernl = new Kernl();
|
|
91
|
+
kernl.register(agent);
|
|
92
|
+
const ctx = new Context("test");
|
|
93
|
+
const tools = await agent.tools(ctx);
|
|
94
|
+
// Memory tools should be first (from systools)
|
|
95
|
+
expect(tools[0].id).toBe("memories.search");
|
|
96
|
+
expect(tools[1].id).toBe("memories.create");
|
|
97
|
+
expect(tools[2].id).toBe("memories.list");
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
describe("memory config defaults", () => {
|
|
101
|
+
it("defaults memory to { enabled: false }", () => {
|
|
102
|
+
const agent = new Agent({
|
|
103
|
+
id: "test-agent",
|
|
104
|
+
name: "Test",
|
|
105
|
+
instructions: "Test",
|
|
106
|
+
model,
|
|
107
|
+
});
|
|
108
|
+
expect(agent.memory).toEqual({ enabled: false });
|
|
109
|
+
});
|
|
110
|
+
it("preserves memory config when provided", () => {
|
|
111
|
+
const agent = new Agent({
|
|
112
|
+
id: "test-agent",
|
|
113
|
+
name: "Test",
|
|
114
|
+
instructions: "Test",
|
|
115
|
+
model,
|
|
116
|
+
memory: { enabled: true },
|
|
117
|
+
});
|
|
118
|
+
expect(agent.memory).toEqual({ enabled: true });
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
});
|
package/dist/agent/types.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ import { TextResponse } from "../thread/types.js";
|
|
|
10
10
|
export interface AgentConfig<TContext = UnknownContext, TResponse extends AgentResponseType = TextResponse> {
|
|
11
11
|
id: string;
|
|
12
12
|
name: string;
|
|
13
|
+
description?: string;
|
|
13
14
|
/**
|
|
14
15
|
* The instructions for the agent. Will be used as the "system prompt" when this agent is
|
|
15
16
|
* invoked. Describes what the agent should do, and how it responds.
|
|
@@ -53,6 +54,13 @@ export interface AgentConfig<TContext = UnknownContext, TResponse extends AgentR
|
|
|
53
54
|
* ```
|
|
54
55
|
*/
|
|
55
56
|
toolkits?: BaseToolkit<TContext>[];
|
|
57
|
+
/**
|
|
58
|
+
* Memory configuration for this agent.
|
|
59
|
+
* Enables memory system tools (memories.search, memories.create, memories.list).
|
|
60
|
+
*
|
|
61
|
+
* Requires kernl to be configured with memory storage.
|
|
62
|
+
*/
|
|
63
|
+
memory?: AgentMemoryConfig;
|
|
56
64
|
/**
|
|
57
65
|
* A list of checks that run in parallel to the agent's execution on the input + output for the agent,
|
|
58
66
|
* depending on the configuration.
|
|
@@ -88,4 +96,13 @@ export interface AgentGuardrails<TResponse extends AgentResponseType = TextRespo
|
|
|
88
96
|
* 'text' is a special type that indicates the output will be a string.
|
|
89
97
|
*/
|
|
90
98
|
export type AgentResponseType = TextResponse | ZodType;
|
|
99
|
+
/**
|
|
100
|
+
* Memory configuration for an agent.
|
|
101
|
+
*/
|
|
102
|
+
export interface AgentMemoryConfig {
|
|
103
|
+
/**
|
|
104
|
+
* Enable memory system tools for this agent.
|
|
105
|
+
*/
|
|
106
|
+
enabled: boolean;
|
|
107
|
+
}
|
|
91
108
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/agent/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,KAAK,CAAC;AAEnC,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,EACL,aAAa,EACb,4BAA4B,EAC7B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAErC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C;;GAEG;AACH,MAAM,WAAW,WAAW,CAC1B,QAAQ,GAAG,cAAc,EACzB,SAAS,SAAS,iBAAiB,GAAG,YAAY;IAGlD,EAAE,EAAE,MAAM,CAAC;IAGX,IAAI,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/agent/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,KAAK,CAAC;AAEnC,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,EACL,aAAa,EACb,4BAA4B,EAC7B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CA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@ import { Tool } from "./tool/index.js";
|
|
|
6
6
|
import { BaseToolkit } from "./tool/toolkit.js";
|
|
7
7
|
import { InputGuardrail, OutputGuardrail, type ResolvedAgentResponse } from "./guardrail.js";
|
|
8
8
|
import { AgentHooks } from "./lifecycle.js";
|
|
9
|
-
import type { AgentConfig, AgentResponseType } from "./agent/types.js";
|
|
9
|
+
import type { AgentConfig, AgentMemoryConfig, AgentResponseType } from "./agent/types.js";
|
|
10
10
|
import type { TextResponse, ThreadExecuteOptions, ThreadExecuteResult, ThreadStreamEvent } from "./thread/types.js";
|
|
11
|
-
import type { AgentMemoryCreate, MemorySearchQuery } from "./memory/index.js";
|
|
11
|
+
import type { AgentMemoryCreate, MemoryListOptions, MemorySearchQuery } from "./memory/index.js";
|
|
12
12
|
export declare class Agent<TContext = UnknownContext, TResponse extends AgentResponseType = TextResponse> extends AgentHooks<TContext, TResponse> implements AgentConfig<TContext, TResponse> {
|
|
13
13
|
private kernl?;
|
|
14
14
|
id: string;
|
|
15
15
|
name: string;
|
|
16
|
+
description?: string;
|
|
16
17
|
instructions: (context: Context<TContext>) => Promise<string> | string;
|
|
17
18
|
model: LanguageModel;
|
|
18
19
|
modelSettings: LanguageModelRequestSettings;
|
|
19
20
|
toolkits: BaseToolkit<TContext>[];
|
|
21
|
+
systools: BaseToolkit<TContext>[];
|
|
22
|
+
memory: AgentMemoryConfig;
|
|
20
23
|
guardrails: {
|
|
21
24
|
input: InputGuardrail[];
|
|
22
25
|
output: OutputGuardrail<AgentResponseType>[];
|
|
@@ -47,7 +50,7 @@ export declare class Agent<TContext = UnknownContext, TResponse extends AgentRes
|
|
|
47
50
|
/**
|
|
48
51
|
* @internal
|
|
49
52
|
*
|
|
50
|
-
* Get a specific tool by ID from
|
|
53
|
+
* Get a specific tool by ID from systools and toolkits.
|
|
51
54
|
*
|
|
52
55
|
* @param id The tool ID to look up
|
|
53
56
|
* @returns The tool if found, undefined otherwise
|
|
@@ -56,7 +59,7 @@ export declare class Agent<TContext = UnknownContext, TResponse extends AgentRes
|
|
|
56
59
|
/**
|
|
57
60
|
* @internal
|
|
58
61
|
*
|
|
59
|
-
* Get all tools available from
|
|
62
|
+
* Get all tools available from systools and toolkits for the given context.
|
|
60
63
|
* Checks for duplicate tool IDs across toolkits and throws an error if found.
|
|
61
64
|
*
|
|
62
65
|
* (TODO): Consider returning toolkits alongside tools so we can serialize them
|
|
@@ -98,6 +101,13 @@ export declare class Agent<TContext = UnknownContext, TResponse extends AgentRes
|
|
|
98
101
|
* ```
|
|
99
102
|
*/
|
|
100
103
|
get memories(): {
|
|
104
|
+
/**
|
|
105
|
+
* List memories scoped to this agent.
|
|
106
|
+
*/
|
|
107
|
+
list: (params?: Omit<MemoryListOptions, "filter"> & {
|
|
108
|
+
collection?: string;
|
|
109
|
+
limit?: number;
|
|
110
|
+
}) => Promise<import("./memory/index.js").MemoryRecord[]>;
|
|
101
111
|
/**
|
|
102
112
|
* Create a new memory scoped to this agent.
|
|
103
113
|
*/
|
package/dist/agent.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,aAAa,EACb,iBAAiB,EACjB,4BAA4B,EAC7B,MAAM,qBAAqB,CAAC;AAG7B,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,KAAK,EACV,kBAAkB,EAClB,mBAAmB,EACnB,iBAAiB,EACjB,oBAAoB,EACpB,mBAAmB,EACpB,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AACzD,OAAO,EAAE,IAAI,
|
|
1
|
+
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,aAAa,EACb,iBAAiB,EACjB,4BAA4B,EAC7B,MAAM,qBAAqB,CAAC;AAG7B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jD,MAAM,SAAS,mBAAmB;MAGnD;IAED;;;;;;;;;;;;;;;;OAgBG;IACH,IAAI,QAAQ;QAWR;;WAEG;wBAEQ,IAAI,CAAC,iBAAiB,EAAE,QAAQ,CAAC,GAAG;YAC3C,UAAU,CAAC,EAAE,MAAM,CAAC;YACpB,KAAK,CAAC,EAAE,MAAM,CAAC;SAEhB;QAUH;;WAEG;yBACc,iBAAiB;QAiBlC;;WAEG;yBAEO,IAAI,CAAC,iBAAiB,EAAE,QAAQ,CAAC,GAAG;YAE1C,MAAM,CAAC,EAAE,IAAI,CAAC,WAAW,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC,EAAE,OAAO,CAAC,GAAG;gBACjE,KAAK,CAAC,EAAE,IAAI,CACV,WAAW,CAAC,WAAW,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,EAC9D,SAAS,CACV,CAAC;aACH,CAAC;SACH;MAaN;CACF"}
|
package/dist/agent.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { message, } from "@kernl-sdk/protocol";
|
|
2
2
|
import { Thread } from "./thread/index.js";
|
|
3
|
+
import { memory } from "./tool/index.js";
|
|
3
4
|
import { AgentHooks } from "./lifecycle.js";
|
|
4
5
|
import { MisconfiguredError, RuntimeError } from "./lib/error.js";
|
|
5
6
|
import { randomID } from "@kernl-sdk/shared/lib";
|
|
@@ -7,10 +8,13 @@ export class Agent extends AgentHooks {
|
|
|
7
8
|
kernl;
|
|
8
9
|
id;
|
|
9
10
|
name;
|
|
11
|
+
description;
|
|
10
12
|
instructions;
|
|
11
13
|
model;
|
|
12
14
|
modelSettings;
|
|
13
15
|
toolkits;
|
|
16
|
+
systools;
|
|
17
|
+
memory;
|
|
14
18
|
// actions: ActionSet; /* TODO */
|
|
15
19
|
guardrails;
|
|
16
20
|
responseType = "text";
|
|
@@ -34,6 +38,7 @@ export class Agent extends AgentHooks {
|
|
|
34
38
|
}
|
|
35
39
|
this.id = config.id;
|
|
36
40
|
this.name = config.name;
|
|
41
|
+
this.description = config.description;
|
|
37
42
|
this.instructions =
|
|
38
43
|
typeof config.instructions === "function"
|
|
39
44
|
? config.instructions
|
|
@@ -41,6 +46,8 @@ export class Agent extends AgentHooks {
|
|
|
41
46
|
this.model = config.model; // (TODO): include optional default setting for convenience like env.DEFAULT_LLM = "gpt-5"
|
|
42
47
|
this.modelSettings = config.modelSettings ?? {};
|
|
43
48
|
this.toolkits = config.toolkits ?? [];
|
|
49
|
+
this.systools = [];
|
|
50
|
+
this.memory = config.memory ?? { enabled: false };
|
|
44
51
|
for (const toolkit of this.toolkits) {
|
|
45
52
|
toolkit.bind(this);
|
|
46
53
|
}
|
|
@@ -69,6 +76,13 @@ export class Agent extends AgentHooks {
|
|
|
69
76
|
*/
|
|
70
77
|
bind(kernl) {
|
|
71
78
|
this.kernl = kernl;
|
|
79
|
+
// initialize system toolkits
|
|
80
|
+
if (this.memory.enabled) {
|
|
81
|
+
// safety: system tools only rely on ctx.agent, not ctx.context
|
|
82
|
+
const toolkit = memory;
|
|
83
|
+
this.systools.push(toolkit);
|
|
84
|
+
toolkit.bind(this);
|
|
85
|
+
}
|
|
72
86
|
}
|
|
73
87
|
/**
|
|
74
88
|
* Blocking execution - spawns or resumes thread and waits for completion
|
|
@@ -168,12 +182,19 @@ export class Agent extends AgentHooks {
|
|
|
168
182
|
/**
|
|
169
183
|
* @internal
|
|
170
184
|
*
|
|
171
|
-
* Get a specific tool by ID from
|
|
185
|
+
* Get a specific tool by ID from systools and toolkits.
|
|
172
186
|
*
|
|
173
187
|
* @param id The tool ID to look up
|
|
174
188
|
* @returns The tool if found, undefined otherwise
|
|
175
189
|
*/
|
|
176
190
|
tool(id) {
|
|
191
|
+
// Check systools first
|
|
192
|
+
for (const toolkit of this.systools) {
|
|
193
|
+
const tool = toolkit.get(id);
|
|
194
|
+
if (tool)
|
|
195
|
+
return tool;
|
|
196
|
+
}
|
|
197
|
+
// Then user toolkits
|
|
177
198
|
for (const toolkit of this.toolkits) {
|
|
178
199
|
const tool = toolkit.get(id);
|
|
179
200
|
if (tool)
|
|
@@ -184,7 +205,7 @@ export class Agent extends AgentHooks {
|
|
|
184
205
|
/**
|
|
185
206
|
* @internal
|
|
186
207
|
*
|
|
187
|
-
* Get all tools available from
|
|
208
|
+
* Get all tools available from systools and toolkits for the given context.
|
|
188
209
|
* Checks for duplicate tool IDs across toolkits and throws an error if found.
|
|
189
210
|
*
|
|
190
211
|
* (TODO): Consider returning toolkits alongside tools so we can serialize them
|
|
@@ -195,18 +216,16 @@ export class Agent extends AgentHooks {
|
|
|
195
216
|
* @throws {MisconfiguredError} If duplicate tool IDs are found across toolkits
|
|
196
217
|
*/
|
|
197
218
|
async tools(context) {
|
|
198
|
-
const
|
|
199
|
-
const
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
}
|
|
206
|
-
tools.forEach((t) => toolIds.add(t.id));
|
|
207
|
-
allTools.push(...tools);
|
|
219
|
+
const all = [];
|
|
220
|
+
for (const toolkit of [...this.systools, ...this.toolkits]) {
|
|
221
|
+
all.push(...(await toolkit.list(context)));
|
|
222
|
+
}
|
|
223
|
+
const ids = all.map((t) => t.id);
|
|
224
|
+
const duplicates = ids.filter((id, i) => ids.indexOf(id) !== i);
|
|
225
|
+
if (duplicates.length > 0) {
|
|
226
|
+
throw new MisconfiguredError(`Duplicate tool IDs found: ${[...new Set(duplicates)].join(", ")}`);
|
|
208
227
|
}
|
|
209
|
-
return
|
|
228
|
+
return all;
|
|
210
229
|
}
|
|
211
230
|
/**
|
|
212
231
|
* Thread management scoped to this agent.
|
|
@@ -259,6 +278,16 @@ export class Agent extends AgentHooks {
|
|
|
259
278
|
const agentId = this.id;
|
|
260
279
|
const kmem = this.kernl.memories;
|
|
261
280
|
return {
|
|
281
|
+
/**
|
|
282
|
+
* List memories scoped to this agent.
|
|
283
|
+
*/
|
|
284
|
+
list: (params) => kmem.list({
|
|
285
|
+
filter: {
|
|
286
|
+
scope: { agentId },
|
|
287
|
+
collections: params?.collection ? [params.collection] : undefined,
|
|
288
|
+
},
|
|
289
|
+
limit: params?.limit,
|
|
290
|
+
}),
|
|
262
291
|
/**
|
|
263
292
|
* Create a new memory scoped to this agent.
|
|
264
293
|
*/
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { Agent } from "../../../agent.js";
|
|
2
|
+
import type { AgentResponseType } from "../../../agent/types.js";
|
|
3
|
+
import type { UnknownContext } from "../../../context.js";
|
|
4
|
+
import type { TextResponse } from "../../../thread/types.js";
|
|
5
|
+
/**
|
|
6
|
+
* Agents resource.
|
|
7
|
+
*
|
|
8
|
+
* Thin facade over the in-process agent registry, returning live Agent instances.
|
|
9
|
+
*
|
|
10
|
+
* Note: agents are code, not persisted data; this is process-local.
|
|
11
|
+
*/
|
|
12
|
+
export declare class RAgents {
|
|
13
|
+
private readonly registry;
|
|
14
|
+
constructor(registry: Map<string, Agent>);
|
|
15
|
+
/**
|
|
16
|
+
* Get a live Agent instance by id.
|
|
17
|
+
*
|
|
18
|
+
* Callers are expected to know the concrete TContext/TResponse types
|
|
19
|
+
* for their own agents and can specify them via generics.
|
|
20
|
+
*/
|
|
21
|
+
get<TContext = UnknownContext, TResponse extends AgentResponseType = TextResponse>(id: string): Agent<TContext, TResponse> | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* Check if an agent with the given id is registered.
|
|
24
|
+
*/
|
|
25
|
+
has(id: string): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* List all registered agents as live instances.
|
|
28
|
+
*
|
|
29
|
+
* Since this is a heterogeneous collection, we expose the widest safe
|
|
30
|
+
* type parameters here.
|
|
31
|
+
*/
|
|
32
|
+
list(): Agent<UnknownContext, AgentResponseType>[];
|
|
33
|
+
/**
|
|
34
|
+
* Unregister an agent at runtime.
|
|
35
|
+
*/
|
|
36
|
+
unregister(id: string): boolean;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=agents.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agents.d.ts","sourceRoot":"","sources":["../../../../src/api/resources/agents/agents.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAEnD;;;;;;GAMG;AACH,qBAAa,OAAO;IACN,OAAO,CAAC,QAAQ,CAAC,QAAQ;gBAAR,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC;IAEzD;;;;;OAKG;IACH,GAAG,CACD,QAAQ,GAAG,cAAc,EACzB,SAAS,SAAS,iBAAiB,GAAG,YAAY,EAClD,EAAE,EAAE,MAAM,GAAG,KAAK,CAAC,QAAQ,EAAE,SAAS,CAAC,GAAG,SAAS;IAKrD;;OAEG;IACH,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO;IAIxB;;;;;OAKG;IACH,IAAI,IAAI,KAAK,CAAC,cAAc,EAAE,iBAAiB,CAAC,EAAE;IAOlD;;OAEG;IACH,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO;CAGhC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agents resource.
|
|
3
|
+
*
|
|
4
|
+
* Thin facade over the in-process agent registry, returning live Agent instances.
|
|
5
|
+
*
|
|
6
|
+
* Note: agents are code, not persisted data; this is process-local.
|
|
7
|
+
*/
|
|
8
|
+
export class RAgents {
|
|
9
|
+
registry;
|
|
10
|
+
constructor(registry) {
|
|
11
|
+
this.registry = registry;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Get a live Agent instance by id.
|
|
15
|
+
*
|
|
16
|
+
* Callers are expected to know the concrete TContext/TResponse types
|
|
17
|
+
* for their own agents and can specify them via generics.
|
|
18
|
+
*/
|
|
19
|
+
get(id) {
|
|
20
|
+
const agent = this.registry.get(id);
|
|
21
|
+
return agent;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Check if an agent with the given id is registered.
|
|
25
|
+
*/
|
|
26
|
+
has(id) {
|
|
27
|
+
return this.registry.has(id);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* List all registered agents as live instances.
|
|
31
|
+
*
|
|
32
|
+
* Since this is a heterogeneous collection, we expose the widest safe
|
|
33
|
+
* type parameters here.
|
|
34
|
+
*/
|
|
35
|
+
list() {
|
|
36
|
+
return Array.from(this.registry.values());
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Unregister an agent at runtime.
|
|
40
|
+
*/
|
|
41
|
+
unregister(id) {
|
|
42
|
+
return this.registry.delete(id);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/api/resources/agents/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { RAgents } from "./agents.js";
|
package/dist/context.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Agent } from "./agent.js";
|
|
1
2
|
/**
|
|
2
3
|
* Context that is being passed around as part of the session is unknown
|
|
3
4
|
*/
|
|
@@ -15,6 +16,11 @@ export declare class Context<TContext = UnknownContext> {
|
|
|
15
16
|
* The inner context object.
|
|
16
17
|
*/
|
|
17
18
|
context: TContext;
|
|
19
|
+
/**
|
|
20
|
+
* The agent executing this context.
|
|
21
|
+
* Set by the thread during execution.
|
|
22
|
+
*/
|
|
23
|
+
agent?: Agent<TContext, any>;
|
|
18
24
|
/**
|
|
19
25
|
* Map of tool call IDs to their approval status.
|
|
20
26
|
* (TEMPORARY) Used until the actions system is refined.
|
package/dist/context.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,OAAO,CAAC;AAErC;;;GAGG;AACH,qBAAa,OAAO,CAAC,QAAQ,GAAG,cAAc;IAC5C;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,OAAO,EAAE,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAErC;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,OAAO,CAAC;AAErC;;;GAGG;AACH,qBAAa,OAAO,CAAC,QAAQ,GAAG,cAAc;IAC5C;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,OAAO,EAAE,QAAQ,CAAC;IAElB;;;OAGG;IACH,KAAK,CAAC,EAAE,KAAK,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;IAM7B;;;OAGG;IACH,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IAEvC;;;OAGG;IACH,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAI7B;;;OAGG;IACH,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;gBAwBhB,SAAS,GAAE,MAAgB,EAAE,OAAO,GAAE,QAAyB;IAS3E;;OAEG;IACH,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,QAAQ,CAAC,GAAG,MAAM;IAevC;;;;;;;;;;;;;;OAcG;IACH,EAAE,IAAI,MAAM;IAIZ;;;;;;;;;;OAUG;IACH,IAAI,IAAI,MAAM;IAId,MAAM,IAAI;QACR,OAAO,EAAE,GAAG,CAAC;KAGd;CAOF;AAED;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,UAAU,GAAG,UAAU,GAAG,SAAS,CAAC"}
|
package/dist/context.js
CHANGED
|
@@ -11,6 +11,11 @@ export class Context {
|
|
|
11
11
|
* The inner context object.
|
|
12
12
|
*/
|
|
13
13
|
context;
|
|
14
|
+
/**
|
|
15
|
+
* The agent executing this context.
|
|
16
|
+
* Set by the thread during execution.
|
|
17
|
+
*/
|
|
18
|
+
agent;
|
|
14
19
|
// ----------------------
|
|
15
20
|
// TEMPORARY: Tool approval tracking until actions system is refined
|
|
16
21
|
// ----------------------
|
package/dist/kernl/kernl.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import type { Thread } from "../thread/index.js";
|
|
|
5
5
|
import type { ResolvedAgentResponse } from "../guardrail.js";
|
|
6
6
|
import { type KernlStorage } from "../storage/index.js";
|
|
7
7
|
import { RThreads } from "../api/resources/threads/index.js";
|
|
8
|
+
import { RAgents } from "../api/resources/agents/index.js";
|
|
8
9
|
import { Memory } from "../memory/index.js";
|
|
9
10
|
import type { ThreadExecuteResult, ThreadStreamEvent } from "../thread/types.js";
|
|
10
11
|
import type { AgentResponseType } from "../agent/types.js";
|
|
@@ -16,11 +17,12 @@ import type { KernlOptions } from "./types.js";
|
|
|
16
17
|
* tracing.
|
|
17
18
|
*/
|
|
18
19
|
export declare class Kernl extends KernlHooks<UnknownContext, AgentResponseType> {
|
|
19
|
-
private
|
|
20
|
-
private
|
|
20
|
+
private readonly _agents;
|
|
21
|
+
private readonly _models;
|
|
21
22
|
readonly storage: KernlStorage;
|
|
22
23
|
athreads: Map<string, Thread<any, any>>;
|
|
23
24
|
readonly threads: RThreads;
|
|
25
|
+
readonly agents: RAgents;
|
|
24
26
|
readonly memories: Memory;
|
|
25
27
|
constructor(options?: KernlOptions);
|
|
26
28
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kernl.d.ts","sourceRoot":"","sources":["../../src/kernl/kernl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C,QAAQ,EAAE,SAAS,CAAC,GAClC,aAAa,CAAC,iBAAiB,CAAC;IASnC;;;;OAIG;IACI,cAAc,CAAC,QAAQ,EAAE,SAAS,SAAS,iBAAiB,EACjE,MAAM,EAAE,MAAM,CAAC,QAAQ,EAAE,SAAS,CAAC,GAClC,aAAa,CAAC,iBAAiB,CAAC;CAQpC"}
|
package/dist/kernl/kernl.js
CHANGED
|
@@ -2,6 +2,7 @@ import { resolveEmbeddingModel } from "@kernl-sdk/retrieval";
|
|
|
2
2
|
import { KernlHooks } from "../lifecycle.js";
|
|
3
3
|
import { InMemoryStorage } from "../storage/index.js";
|
|
4
4
|
import { RThreads } from "../api/resources/threads/index.js";
|
|
5
|
+
import { RAgents } from "../api/resources/agents/index.js";
|
|
5
6
|
import { Memory, MemoryByteEncoder, MemoryIndexHandle, buildMemoryIndexSchema, } from "../memory/index.js";
|
|
6
7
|
/**
|
|
7
8
|
* The kernl - manages agent processes, scheduling, and task lifecycle.
|
|
@@ -10,18 +11,20 @@ import { Memory, MemoryByteEncoder, MemoryIndexHandle, buildMemoryIndexSchema, }
|
|
|
10
11
|
* tracing.
|
|
11
12
|
*/
|
|
12
13
|
export class Kernl extends KernlHooks {
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
_agents = new Map();
|
|
15
|
+
_models = new Map();
|
|
15
16
|
storage;
|
|
16
17
|
athreads = new Map(); /* active threads */
|
|
17
18
|
// --- public API ---
|
|
18
|
-
threads;
|
|
19
|
-
|
|
19
|
+
threads;
|
|
20
|
+
agents;
|
|
21
|
+
memories;
|
|
20
22
|
constructor(options = {}) {
|
|
21
23
|
super();
|
|
22
24
|
this.storage = options.storage?.db ?? new InMemoryStorage();
|
|
23
|
-
this.storage.bind({ agents: this.
|
|
25
|
+
this.storage.bind({ agents: this._agents, models: this._models });
|
|
24
26
|
this.threads = new RThreads(this.storage.threads);
|
|
27
|
+
this.agents = new RAgents(this._agents);
|
|
25
28
|
// initialize memory
|
|
26
29
|
const embeddingModel = options.memory?.embeddingModel ?? "openai/text-embedding-3-small";
|
|
27
30
|
const embedder = typeof embeddingModel === "string"
|
|
@@ -49,14 +52,14 @@ export class Kernl extends KernlHooks {
|
|
|
49
52
|
* Registers a new agent with the kernl instance.
|
|
50
53
|
*/
|
|
51
54
|
register(agent) {
|
|
52
|
-
this.
|
|
55
|
+
this._agents.set(agent.id, agent);
|
|
53
56
|
agent.bind(this);
|
|
54
57
|
// (TODO): implement exhaustive model registry in protocol/ package
|
|
55
58
|
//
|
|
56
59
|
// auto-populate model registry for storage hydration
|
|
57
60
|
const key = `${agent.model.provider}/${agent.model.modelId}`;
|
|
58
|
-
if (!this.
|
|
59
|
-
this.
|
|
61
|
+
if (!this._models.has(key)) {
|
|
62
|
+
this._models.set(key, agent.model);
|
|
60
63
|
}
|
|
61
64
|
}
|
|
62
65
|
/**
|
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,EACV,SAAS,EACT,YAAY,EACZ,kBAAkB,EAClB,WAAW,EACX,YAAY,EACZ,iBAAiB,EAEjB,iBAAiB,EACjB,qBAAqB,EACrB,uBAAuB,EACvB,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,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"}
|
|
1
|
+
{"version":3,"file":"memory.d.ts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