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.
- package/.turbo/turbo-build.log +1 -1
- package/.turbo/turbo-check-types.log +1 -1
- package/CHANGELOG.md +44 -0
- package/dist/agent/__tests__/concurrency.test.js +1 -1
- package/dist/agent/__tests__/run.test.js +1 -1
- 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/{types/agent.d.ts → agent/types.d.ts} +19 -2
- package/dist/agent/types.d.ts.map +1 -0
- package/dist/agent.d.ts +48 -6
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +100 -13
- package/dist/api/models/thread.d.ts +1 -1
- 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/api/resources/threads/threads.d.ts +1 -1
- package/dist/api/resources/threads/threads.d.ts.map +1 -1
- package/dist/api/resources/threads/threads.js +1 -1
- package/dist/api/resources/threads/types.d.ts +2 -2
- package/dist/api/resources/threads/types.d.ts.map +1 -1
- package/dist/context.d.ts +10 -4
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +5 -0
- package/dist/guardrail.d.ts +2 -2
- package/dist/index.d.ts +5 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -3
- package/dist/internal.d.ts +2 -2
- package/dist/internal.js +1 -1
- package/dist/kernl/index.d.ts +1 -1
- package/dist/kernl/index.d.ts.map +1 -1
- package/dist/kernl/index.js +0 -1
- package/dist/kernl/kernl.d.ts +11 -20
- package/dist/kernl/kernl.d.ts.map +1 -1
- package/dist/kernl/kernl.js +37 -34
- package/dist/kernl/types.d.ts +91 -0
- package/dist/kernl/types.d.ts.map +1 -0
- package/dist/lib/error.d.ts +2 -2
- package/dist/lifecycle.d.ts +2 -2
- package/dist/memory/codec.d.ts +32 -0
- package/dist/memory/codec.d.ts.map +1 -0
- package/dist/memory/codec.js +97 -0
- package/dist/memory/codecs/domain.d.ts +34 -0
- package/dist/memory/codecs/domain.d.ts.map +1 -0
- package/dist/memory/codecs/domain.js +99 -0
- package/dist/memory/codecs/identity.d.ts +12 -0
- package/dist/memory/codecs/identity.d.ts.map +1 -0
- package/dist/memory/codecs/identity.js +17 -0
- package/dist/memory/codecs/index.d.ts +31 -0
- package/dist/memory/codecs/index.d.ts.map +1 -0
- package/dist/memory/codecs/index.js +39 -0
- package/dist/memory/codecs/tpuf.d.ts +38 -0
- package/dist/memory/codecs/tpuf.d.ts.map +1 -0
- package/dist/memory/codecs/tpuf.js +90 -0
- package/dist/memory/encoder.d.ts +29 -0
- package/dist/memory/encoder.d.ts.map +1 -0
- package/dist/memory/encoder.js +45 -0
- package/dist/memory/handle.d.ts +89 -0
- package/dist/memory/handle.d.ts.map +1 -0
- package/dist/memory/handle.js +128 -0
- package/dist/memory/index.d.ts +12 -0
- package/dist/memory/index.d.ts.map +1 -0
- package/dist/memory/index.js +7 -0
- package/dist/memory/indexes.d.ts +91 -0
- package/dist/memory/indexes.d.ts.map +1 -0
- package/dist/memory/indexes.js +7 -0
- package/dist/memory/memory.d.ts +55 -0
- package/dist/memory/memory.d.ts.map +1 -0
- package/dist/memory/memory.js +113 -0
- package/dist/memory/schema.d.ts +41 -0
- package/dist/memory/schema.d.ts.map +1 -0
- package/dist/memory/schema.js +112 -0
- package/dist/memory/store.d.ts +36 -0
- package/dist/memory/store.d.ts.map +1 -0
- package/dist/memory/store.js +4 -0
- package/dist/memory/types.d.ts +250 -0
- package/dist/memory/types.d.ts.map +1 -0
- package/dist/memory/types.js +4 -0
- package/dist/storage/base.d.ts +6 -1
- package/dist/storage/base.d.ts.map +1 -1
- package/dist/storage/in-memory.d.ts +24 -2
- package/dist/storage/in-memory.d.ts.map +1 -1
- package/dist/storage/in-memory.js +131 -0
- package/dist/storage/thread.d.ts +1 -1
- package/dist/thread/__tests__/integration.test.js +1 -1
- package/dist/thread/__tests__/mock.d.ts +1 -1
- package/dist/thread/__tests__/namespace.test.js +1 -1
- package/dist/thread/__tests__/thread.test.js +1 -1
- package/dist/thread/thread.d.ts +2 -2
- package/dist/thread/thread.d.ts.map +1 -1
- package/dist/thread/thread.js +3 -1
- package/dist/{types/thread.d.ts → thread/types.d.ts} +2 -2
- package/dist/thread/types.d.ts.map +1 -0
- package/dist/thread/utils.d.ts +2 -2
- package/dist/thread/utils.d.ts.map +1 -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 +4 -2
- package/src/agent/__tests__/systools.test.ts +146 -0
- package/src/{types/agent.ts → agent/types.ts} +22 -1
- package/src/agent.ts +144 -36
- package/src/api/__tests__/threads.test.ts +2 -2
- package/src/api/models/thread.ts +1 -1
- package/src/api/resources/agents/agents.ts +56 -0
- package/src/api/resources/agents/index.ts +1 -0
- package/src/api/resources/threads/events.ts +1 -1
- package/src/api/resources/threads/threads.ts +2 -2
- package/src/api/resources/threads/types.ts +2 -2
- package/src/context.ts +14 -136
- package/src/guardrail.ts +2 -2
- package/src/index.ts +35 -6
- package/src/internal.ts +2 -2
- package/src/kernl/index.ts +8 -0
- package/src/{kernl.ts → kernl/kernl.ts} +50 -10
- package/src/kernl/types.ts +106 -0
- package/src/lib/error.ts +2 -2
- package/src/lifecycle.ts +2 -2
- package/src/memory/codecs/domain.ts +115 -0
- package/src/memory/codecs/identity.ts +28 -0
- package/src/memory/codecs/index.ts +61 -0
- package/src/memory/codecs/tpuf.ts +115 -0
- package/src/memory/encoder.ts +56 -0
- package/src/memory/handle.ts +189 -0
- package/src/memory/index.ts +49 -0
- package/src/memory/indexes.ts +108 -0
- package/src/memory/memory.ts +151 -0
- package/src/memory/schema.ts +142 -0
- package/src/memory/store.ts +47 -0
- package/src/memory/types.ts +282 -0
- package/src/storage/__tests__/in-memory.test.ts +1 -1
- package/src/storage/base.ts +7 -1
- package/src/storage/in-memory.ts +170 -2
- package/src/storage/thread.ts +1 -1
- package/src/thread/__tests__/integration.test.ts +1 -1
- package/src/thread/__tests__/mock.ts +1 -1
- package/src/thread/__tests__/thread.test.ts +1 -1
- package/src/thread/thread.ts +5 -3
- package/src/{types/thread.ts → thread/types.ts} +1 -1
- package/src/thread/utils.ts +2 -2
- 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/tsconfig.tsbuildinfo +1 -0
- package/dist/api/__tests__/cursor-page.test.d.ts +0 -2
- package/dist/api/__tests__/cursor-page.test.d.ts.map +0 -1
- package/dist/api/__tests__/cursor-page.test.js +0 -414
- package/dist/api/__tests__/offset-page.test.d.ts +0 -2
- package/dist/api/__tests__/offset-page.test.d.ts.map +0 -1
- package/dist/api/__tests__/offset-page.test.js +0 -510
- package/dist/api/pagination/base.d.ts +0 -48
- package/dist/api/pagination/base.d.ts.map +0 -1
- package/dist/api/pagination/base.js +0 -45
- package/dist/api/pagination/cursor.d.ts +0 -44
- package/dist/api/pagination/cursor.d.ts.map +0 -1
- package/dist/api/pagination/cursor.js +0 -52
- package/dist/api/pagination/offset.d.ts +0 -42
- package/dist/api/pagination/offset.d.ts.map +0 -1
- package/dist/api/pagination/offset.js +0 -55
- package/dist/kernl/threads.d.ts +0 -110
- package/dist/kernl/threads.d.ts.map +0 -1
- package/dist/kernl/threads.js +0 -126
- package/dist/kernl.d.ts +0 -51
- package/dist/kernl.d.ts.map +0 -1
- package/dist/kernl.js +0 -91
- package/dist/types/agent.d.ts.map +0 -1
- package/dist/types/kernl.d.ts +0 -42
- package/dist/types/kernl.d.ts.map +0 -1
- package/dist/types/thread.d.ts.map +0 -1
- package/src/api/__tests__/cursor-page.test.ts +0 -512
- package/src/api/__tests__/offset-page.test.ts +0 -624
- package/src/api/pagination/base.ts +0 -79
- package/src/api/pagination/cursor.ts +0 -86
- package/src/api/pagination/offset.ts +0 -89
- package/src/types/kernl.ts +0 -51
- /package/dist/{types/agent.js → agent/types.js} +0 -0
- /package/dist/{types/kernl.js → kernl/types.js} +0 -0
- /package/dist/{types/thread.js → thread/types.js} +0 -0
package/.turbo/turbo-build.log
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,49 @@
|
|
|
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
|
+
|
|
17
|
+
## 0.6.3
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- a7d6138: Add agent.memories API and memory integration with vector backends
|
|
22
|
+
|
|
23
|
+
**@kernl-sdk/retrieval**
|
|
24
|
+
- Add `planQuery()` for adapting queries based on backend capabilities
|
|
25
|
+
- Add `SearchCapabilities` interface to describe backend features
|
|
26
|
+
- Gracefully degrade hybrid queries when not supported
|
|
27
|
+
|
|
28
|
+
**@kernl-sdk/pg**
|
|
29
|
+
- Add `capabilities()` method to PGVectorSearchIndex
|
|
30
|
+
- Fix hit decoding to include id in document
|
|
31
|
+
|
|
32
|
+
**@kernl-sdk/turbopuffer**
|
|
33
|
+
- Add `capabilities()` method describing supported search modes
|
|
34
|
+
- Add bigint type mapping for timestamps
|
|
35
|
+
- Fix hit decoding to include id in document
|
|
36
|
+
- Add memory integration tests
|
|
37
|
+
|
|
38
|
+
**kernl**
|
|
39
|
+
- Add `agent.memories.create()` with simplified syntax (auto-generated IDs, flattened scope)
|
|
40
|
+
- Add `agent.memories.search()` scoped to agent
|
|
41
|
+
- Add backend-aware codecs for Turbopuffer field mapping (tvec → vector)
|
|
42
|
+
- Default `include: true` for Turbopuffer queries to return all attributes
|
|
43
|
+
|
|
44
|
+
- Updated dependencies [a7d6138]
|
|
45
|
+
- @kernl-sdk/retrieval@0.1.0
|
|
46
|
+
|
|
3
47
|
## 0.6.2
|
|
4
48
|
|
|
5
49
|
### Patch Changes
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { describe, it, expect } from "vitest";
|
|
2
2
|
import { Agent } from "../../agent.js";
|
|
3
|
-
import { Kernl } from "../../kernl.js";
|
|
3
|
+
import { Kernl } from "../../kernl/index.js";
|
|
4
4
|
import { createMockModel } from "../../thread/__tests__/fixtures/mock-model.js";
|
|
5
5
|
import { RuntimeError } from "../../lib/error.js";
|
|
6
6
|
import { message } from "@kernl-sdk/protocol";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { describe, it, expect } from "vitest";
|
|
2
2
|
import { Agent } from "../../agent.js";
|
|
3
|
-
import { Kernl } from "../../kernl.js";
|
|
3
|
+
import { Kernl } from "../../kernl/index.js";
|
|
4
4
|
import { createMockModel } from "../../thread/__tests__/fixtures/mock-model.js";
|
|
5
5
|
import { MisconfiguredError } from "../../lib/error.js";
|
|
6
6
|
import { message } from "@kernl-sdk/protocol";
|
|
@@ -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
|
+
});
|
|
@@ -3,13 +3,14 @@ import { Context, UnknownContext } from "../context.js";
|
|
|
3
3
|
import { LanguageModel, LanguageModelRequestSettings } from "@kernl-sdk/protocol";
|
|
4
4
|
import { InputGuardrail, OutputGuardrail } from "../guardrail.js";
|
|
5
5
|
import { BaseToolkit } from "../tool/index.js";
|
|
6
|
-
import { TextResponse } from "
|
|
6
|
+
import { TextResponse } from "../thread/types.js";
|
|
7
7
|
/**
|
|
8
8
|
* Configuration for an agent.
|
|
9
9
|
*/
|
|
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;
|
|
91
|
-
|
|
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
|
+
}
|
|
108
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +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,OA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iB;IAChC;;OAEG;IACH,OAAO,EAAE,OAAO,CAAC;CAClB"}
|
package/dist/agent.d.ts
CHANGED
|
@@ -1,21 +1,25 @@
|
|
|
1
1
|
import { LanguageModel, LanguageModelItem, LanguageModelRequestSettings } from "@kernl-sdk/protocol";
|
|
2
|
-
import type { Kernl } from "./kernl.js";
|
|
2
|
+
import type { Kernl } from "./kernl/index.js";
|
|
3
3
|
import type { RThreadsListParams, RThreadCreateParams, RThreadGetOptions, RThreadHistoryParams, RThreadUpdateParams } from "./api/resources/threads/types.js";
|
|
4
4
|
import type { Context, UnknownContext } from "./context.js";
|
|
5
5
|
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 "./types
|
|
10
|
-
import type { TextResponse, ThreadExecuteOptions, ThreadExecuteResult, ThreadStreamEvent } from "./types
|
|
9
|
+
import type { AgentConfig, AgentMemoryConfig, AgentResponseType } from "./agent/types.js";
|
|
10
|
+
import type { TextResponse, ThreadExecuteOptions, ThreadExecuteResult, ThreadStreamEvent } from "./thread/types.js";
|
|
11
|
+
import type { AgentMemoryCreate, MemoryListOptions, MemorySearchQuery } from "./memory/index.js";
|
|
11
12
|
export declare class Agent<TContext = UnknownContext, TResponse extends AgentResponseType = TextResponse> extends AgentHooks<TContext, TResponse> implements AgentConfig<TContext, TResponse> {
|
|
12
13
|
private kernl?;
|
|
13
14
|
id: string;
|
|
14
15
|
name: string;
|
|
16
|
+
description?: string;
|
|
15
17
|
instructions: (context: Context<TContext>) => Promise<string> | string;
|
|
16
18
|
model: LanguageModel;
|
|
17
19
|
modelSettings: LanguageModelRequestSettings;
|
|
18
20
|
toolkits: BaseToolkit<TContext>[];
|
|
21
|
+
systools: BaseToolkit<TContext>[];
|
|
22
|
+
memory: AgentMemoryConfig;
|
|
19
23
|
guardrails: {
|
|
20
24
|
input: InputGuardrail[];
|
|
21
25
|
output: OutputGuardrail<AgentResponseType>[];
|
|
@@ -46,7 +50,7 @@ export declare class Agent<TContext = UnknownContext, TResponse extends AgentRes
|
|
|
46
50
|
/**
|
|
47
51
|
* @internal
|
|
48
52
|
*
|
|
49
|
-
* Get a specific tool by ID from
|
|
53
|
+
* Get a specific tool by ID from systools and toolkits.
|
|
50
54
|
*
|
|
51
55
|
* @param id The tool ID to look up
|
|
52
56
|
* @returns The tool if found, undefined otherwise
|
|
@@ -55,7 +59,7 @@ export declare class Agent<TContext = UnknownContext, TResponse extends AgentRes
|
|
|
55
59
|
/**
|
|
56
60
|
* @internal
|
|
57
61
|
*
|
|
58
|
-
* Get all tools available from
|
|
62
|
+
* Get all tools available from systools and toolkits for the given context.
|
|
59
63
|
* Checks for duplicate tool IDs across toolkits and throws an error if found.
|
|
60
64
|
*
|
|
61
65
|
* (TODO): Consider returning toolkits alongside tools so we can serialize them
|
|
@@ -73,11 +77,49 @@ export declare class Agent<TContext = UnknownContext, TResponse extends AgentRes
|
|
|
73
77
|
*/
|
|
74
78
|
get threads(): {
|
|
75
79
|
get: (tid: string, options?: RThreadGetOptions) => Promise<import("./index.js").Thread | null>;
|
|
76
|
-
list: (params?: Omit<RThreadsListParams, "agentId">) => Promise<import("
|
|
80
|
+
list: (params?: Omit<RThreadsListParams, "agentId">) => Promise<import("@kernl-sdk/shared").CursorPage<import("./index.js").Thread, RThreadsListParams>>;
|
|
77
81
|
delete: (tid: string) => Promise<void>;
|
|
78
82
|
history: (tid: string, params?: RThreadHistoryParams) => Promise<import("./index.js").ThreadEvent[]>;
|
|
79
83
|
create: (params: Omit<RThreadCreateParams, "agentId" | "model">) => Promise<import("./index.js").Thread>;
|
|
80
84
|
update: (tid: string, patch: RThreadUpdateParams) => Promise<import("./index.js").Thread | null>;
|
|
81
85
|
};
|
|
86
|
+
/**
|
|
87
|
+
* Memory management scoped to this agent.
|
|
88
|
+
*
|
|
89
|
+
* Provides a simplified API for creating memories with:
|
|
90
|
+
* - Auto-generated IDs
|
|
91
|
+
* - Flattened scope fields (namespace, entityId) - agentId is implicit
|
|
92
|
+
* - Default kind of "semantic"
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```ts
|
|
96
|
+
* await agent.memories.create({
|
|
97
|
+
* namespace: "user-123",
|
|
98
|
+
* collection: "preferences",
|
|
99
|
+
* content: { text: "User prefers TypeScript" },
|
|
100
|
+
* });
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
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[]>;
|
|
111
|
+
/**
|
|
112
|
+
* Create a new memory scoped to this agent.
|
|
113
|
+
*/
|
|
114
|
+
create: (params: AgentMemoryCreate) => Promise<import("./memory/index.js").MemoryRecord>;
|
|
115
|
+
/**
|
|
116
|
+
* Search memories scoped to this agent.
|
|
117
|
+
*/
|
|
118
|
+
search: (params: Omit<MemorySearchQuery, "filter"> & {
|
|
119
|
+
filter?: Omit<NonNullable<MemorySearchQuery["filter"]>, "scope"> & {
|
|
120
|
+
scope?: Omit<NonNullable<NonNullable<MemorySearchQuery["filter"]>["scope"]>, "agentId">;
|
|
121
|
+
};
|
|
122
|
+
}) => Promise<import("@kernl-sdk/retrieval").SearchHit<import("./memory/index.js").IndexMemoryRecord>[]>;
|
|
123
|
+
};
|
|
82
124
|
}
|
|
83
125
|
//# sourceMappingURL=agent.d.ts.map
|
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,EAC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
|
import { AgentHooks } from "./lifecycle.js";
|
|
4
5
|
import { MisconfiguredError, RuntimeError } from "./lib/error.js";
|
|
6
|
+
import { randomID } from "@kernl-sdk/shared/lib";
|
|
5
7
|
export class Agent extends AgentHooks {
|
|
6
8
|
kernl;
|
|
7
9
|
id;
|
|
8
10
|
name;
|
|
11
|
+
description;
|
|
9
12
|
instructions;
|
|
10
13
|
model;
|
|
11
14
|
modelSettings;
|
|
12
15
|
toolkits;
|
|
16
|
+
systools;
|
|
17
|
+
memory;
|
|
13
18
|
// actions: ActionSet; /* TODO */
|
|
14
19
|
guardrails;
|
|
15
20
|
responseType = "text";
|
|
@@ -33,6 +38,7 @@ export class Agent extends AgentHooks {
|
|
|
33
38
|
}
|
|
34
39
|
this.id = config.id;
|
|
35
40
|
this.name = config.name;
|
|
41
|
+
this.description = config.description;
|
|
36
42
|
this.instructions =
|
|
37
43
|
typeof config.instructions === "function"
|
|
38
44
|
? config.instructions
|
|
@@ -40,6 +46,8 @@ export class Agent extends AgentHooks {
|
|
|
40
46
|
this.model = config.model; // (TODO): include optional default setting for convenience like env.DEFAULT_LLM = "gpt-5"
|
|
41
47
|
this.modelSettings = config.modelSettings ?? {};
|
|
42
48
|
this.toolkits = config.toolkits ?? [];
|
|
49
|
+
this.systools = [];
|
|
50
|
+
this.memory = config.memory ?? { enabled: false };
|
|
43
51
|
for (const toolkit of this.toolkits) {
|
|
44
52
|
toolkit.bind(this);
|
|
45
53
|
}
|
|
@@ -68,6 +76,13 @@ export class Agent extends AgentHooks {
|
|
|
68
76
|
*/
|
|
69
77
|
bind(kernl) {
|
|
70
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
|
+
}
|
|
71
86
|
}
|
|
72
87
|
/**
|
|
73
88
|
* Blocking execution - spawns or resumes thread and waits for completion
|
|
@@ -167,12 +182,19 @@ export class Agent extends AgentHooks {
|
|
|
167
182
|
/**
|
|
168
183
|
* @internal
|
|
169
184
|
*
|
|
170
|
-
* Get a specific tool by ID from
|
|
185
|
+
* Get a specific tool by ID from systools and toolkits.
|
|
171
186
|
*
|
|
172
187
|
* @param id The tool ID to look up
|
|
173
188
|
* @returns The tool if found, undefined otherwise
|
|
174
189
|
*/
|
|
175
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
|
|
176
198
|
for (const toolkit of this.toolkits) {
|
|
177
199
|
const tool = toolkit.get(id);
|
|
178
200
|
if (tool)
|
|
@@ -183,7 +205,7 @@ export class Agent extends AgentHooks {
|
|
|
183
205
|
/**
|
|
184
206
|
* @internal
|
|
185
207
|
*
|
|
186
|
-
* Get all tools available from
|
|
208
|
+
* Get all tools available from systools and toolkits for the given context.
|
|
187
209
|
* Checks for duplicate tool IDs across toolkits and throws an error if found.
|
|
188
210
|
*
|
|
189
211
|
* (TODO): Consider returning toolkits alongside tools so we can serialize them
|
|
@@ -194,18 +216,16 @@ export class Agent extends AgentHooks {
|
|
|
194
216
|
* @throws {MisconfiguredError} If duplicate tool IDs are found across toolkits
|
|
195
217
|
*/
|
|
196
218
|
async tools(context) {
|
|
197
|
-
const
|
|
198
|
-
const
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
}
|
|
205
|
-
tools.forEach((t) => toolIds.add(t.id));
|
|
206
|
-
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(", ")}`);
|
|
207
227
|
}
|
|
208
|
-
return
|
|
228
|
+
return all;
|
|
209
229
|
}
|
|
210
230
|
/**
|
|
211
231
|
* Thread management scoped to this agent.
|
|
@@ -234,4 +254,71 @@ export class Agent extends AgentHooks {
|
|
|
234
254
|
update: (tid, patch) => kthreads.update(tid, patch),
|
|
235
255
|
};
|
|
236
256
|
}
|
|
257
|
+
/**
|
|
258
|
+
* Memory management scoped to this agent.
|
|
259
|
+
*
|
|
260
|
+
* Provides a simplified API for creating memories with:
|
|
261
|
+
* - Auto-generated IDs
|
|
262
|
+
* - Flattened scope fields (namespace, entityId) - agentId is implicit
|
|
263
|
+
* - Default kind of "semantic"
|
|
264
|
+
*
|
|
265
|
+
* @example
|
|
266
|
+
* ```ts
|
|
267
|
+
* await agent.memories.create({
|
|
268
|
+
* namespace: "user-123",
|
|
269
|
+
* collection: "preferences",
|
|
270
|
+
* content: { text: "User prefers TypeScript" },
|
|
271
|
+
* });
|
|
272
|
+
* ```
|
|
273
|
+
*/
|
|
274
|
+
get memories() {
|
|
275
|
+
if (!this.kernl) {
|
|
276
|
+
throw new MisconfiguredError(`Agent ${this.id} not bound to kernl. Call kernl.register(agent) first.`);
|
|
277
|
+
}
|
|
278
|
+
const agentId = this.id;
|
|
279
|
+
const kmem = this.kernl.memories;
|
|
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
|
+
}),
|
|
291
|
+
/**
|
|
292
|
+
* Create a new memory scoped to this agent.
|
|
293
|
+
*/
|
|
294
|
+
create: (params) => kmem.create({
|
|
295
|
+
id: params.id ?? `mem_${randomID()}`,
|
|
296
|
+
scope: {
|
|
297
|
+
namespace: params.namespace,
|
|
298
|
+
entityId: params.entityId,
|
|
299
|
+
agentId,
|
|
300
|
+
},
|
|
301
|
+
kind: "semantic",
|
|
302
|
+
collection: params.collection,
|
|
303
|
+
content: params.content,
|
|
304
|
+
wmem: params.wmem,
|
|
305
|
+
smem: params.smem,
|
|
306
|
+
timestamp: params.timestamp,
|
|
307
|
+
metadata: params.metadata,
|
|
308
|
+
}),
|
|
309
|
+
/**
|
|
310
|
+
* Search memories scoped to this agent.
|
|
311
|
+
*/
|
|
312
|
+
search: (params) => kmem.search({
|
|
313
|
+
...params,
|
|
314
|
+
filter: {
|
|
315
|
+
...params.filter,
|
|
316
|
+
scope: {
|
|
317
|
+
...params.filter?.scope,
|
|
318
|
+
agentId,
|
|
319
|
+
},
|
|
320
|
+
},
|
|
321
|
+
}),
|
|
322
|
+
};
|
|
323
|
+
}
|
|
237
324
|
}
|
|
@@ -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";
|