kernl 0.8.4 → 0.9.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 +30 -0
- package/dist/agent/base.d.ts +73 -0
- package/dist/agent/base.d.ts.map +1 -0
- package/dist/agent/base.js +137 -0
- package/dist/agent/index.d.ts +2 -0
- package/dist/agent/index.d.ts.map +1 -1
- package/dist/agent/index.js +2 -1
- package/dist/agent/types.d.ts +4 -0
- package/dist/agent/types.d.ts.map +1 -1
- package/dist/agent.d.ts +10 -90
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +5 -171
- package/dist/api/resources/agents/agents.d.ts +11 -7
- package/dist/api/resources/agents/agents.d.ts.map +1 -1
- package/dist/api/resources/agents/agents.js +14 -8
- package/dist/kernl/kernl.d.ts +2 -2
- package/dist/kernl/kernl.d.ts.map +1 -1
- package/dist/kernl/kernl.js +6 -6
- package/dist/kernl/types.d.ts +3 -3
- package/dist/kernl/types.d.ts.map +1 -1
- package/dist/lib/env.d.ts +2 -2
- package/dist/mcp/__tests__/utils.test.js +4 -2
- package/dist/mcp/utils.d.ts +1 -1
- package/dist/mcp/utils.js +1 -1
- package/dist/realtime/agent.d.ts +17 -0
- package/dist/realtime/agent.d.ts.map +1 -0
- package/dist/realtime/agent.js +17 -0
- package/dist/realtime/channel.d.ts +30 -0
- package/dist/realtime/channel.d.ts.map +1 -0
- package/dist/realtime/channel.js +1 -0
- package/dist/realtime/index.d.ts +5 -0
- package/dist/realtime/index.d.ts.map +1 -0
- package/dist/realtime/index.js +4 -0
- package/dist/realtime/session.d.ts +98 -0
- package/dist/realtime/session.d.ts.map +1 -0
- package/dist/realtime/session.js +203 -0
- package/dist/realtime/types.d.ts +58 -0
- package/dist/realtime/types.d.ts.map +1 -0
- package/dist/realtime/types.js +1 -0
- package/dist/storage/in-memory.d.ts.map +1 -1
- package/dist/storage/in-memory.js +5 -1
- package/dist/tool/__tests__/toolkit.test.js +2 -2
- package/dist/tool/tool.d.ts +2 -1
- package/dist/tool/tool.d.ts.map +1 -1
- package/dist/tool/toolkit.d.ts +4 -4
- package/dist/tool/toolkit.d.ts.map +1 -1
- package/dist/tool/toolkit.js +2 -1
- package/dist/tool/types.d.ts +4 -4
- package/dist/tool/types.d.ts.map +1 -1
- package/package.json +9 -6
- package/src/agent/base.ts +220 -0
- package/src/agent/index.ts +2 -0
- package/src/agent/types.ts +5 -0
- package/src/agent.ts +12 -231
- package/src/api/resources/agents/agents.ts +19 -13
- package/src/kernl/kernl.ts +9 -9
- package/src/kernl/types.ts +3 -3
- package/src/mcp/__tests__/utils.test.ts +4 -2
- package/src/mcp/utils.ts +1 -1
- package/src/realtime/agent.ts +24 -0
- package/src/realtime/channel.ts +32 -0
- package/src/realtime/index.ts +4 -0
- package/src/realtime/session.ts +259 -0
- package/src/realtime/types.ts +73 -0
- package/src/storage/in-memory.ts +9 -1
- package/src/tool/__tests__/toolkit.test.ts +2 -2
- package/src/tool/tool.ts +2 -1
- package/src/tool/toolkit.ts +6 -5
- package/src/tool/types.ts +4 -4
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { RealtimeModel, RealtimeTransport, RealtimeConnectOptions } from "@kernl-sdk/protocol";
|
|
2
|
+
import { Context, UnknownContext } from "../context.js";
|
|
3
|
+
import type { BaseAgentConfig } from "../agent/base.js";
|
|
4
|
+
import type { RealtimeChannel } from "./channel.js";
|
|
5
|
+
/**
|
|
6
|
+
* Configuration for a realtime agent.
|
|
7
|
+
*/
|
|
8
|
+
export interface RealtimeAgentConfig<TContext = UnknownContext> extends BaseAgentConfig<TContext> {
|
|
9
|
+
/**
|
|
10
|
+
* The realtime model to use for this agent.
|
|
11
|
+
*/
|
|
12
|
+
model: RealtimeModel;
|
|
13
|
+
/**
|
|
14
|
+
* Voice configuration for the agent.
|
|
15
|
+
*/
|
|
16
|
+
voice?: RealtimeAgentVoiceConfig;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Voice configuration for a realtime agent.
|
|
20
|
+
*/
|
|
21
|
+
export interface RealtimeAgentVoiceConfig {
|
|
22
|
+
/**
|
|
23
|
+
* Voice ID to use for audio output.
|
|
24
|
+
*/
|
|
25
|
+
voiceId: string;
|
|
26
|
+
/**
|
|
27
|
+
* Playback speed multiplier.
|
|
28
|
+
*/
|
|
29
|
+
speed?: number;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Options for creating a realtime session.
|
|
33
|
+
*/
|
|
34
|
+
export interface RealtimeSessionOptions<TContext = UnknownContext> {
|
|
35
|
+
/**
|
|
36
|
+
* Override the agent's default model for this session.
|
|
37
|
+
*/
|
|
38
|
+
model?: RealtimeModel;
|
|
39
|
+
/**
|
|
40
|
+
* Audio I/O channel (e.g., BrowserChannel, TwilioChannel).
|
|
41
|
+
* Not used with WebRTC transport.
|
|
42
|
+
*/
|
|
43
|
+
channel?: RealtimeChannel;
|
|
44
|
+
/**
|
|
45
|
+
* Custom transport (e.g., WebRTCTransport).
|
|
46
|
+
* If not provided, model.connect() creates the default transport.
|
|
47
|
+
*/
|
|
48
|
+
transport?: RealtimeTransport;
|
|
49
|
+
/**
|
|
50
|
+
* Context for this session.
|
|
51
|
+
*/
|
|
52
|
+
context?: Context<TContext>;
|
|
53
|
+
/**
|
|
54
|
+
* Options passed to model.connect() or transport.connect().
|
|
55
|
+
*/
|
|
56
|
+
connectOptions?: RealtimeConnectOptions;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/realtime/types.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,iBAAiB,EACjB,sBAAsB,EACvB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAEpD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAEjD;;GAEG;AACH,MAAM,WAAW,mBAAmB,CAAC,QAAQ,GAAG,cAAc,CAC5D,SAAQ,eAAe,CAAC,QAAQ,CAAC;IACjC;;OAEG;IACH,KAAK,EAAE,aAAa,CAAC;IAErB;;OAEG;IACH,KAAK,CAAC,EAAE,wBAAwB,CAAC;CAClC;AAED;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB,CAAC,QAAQ,GAAG,cAAc;IAC/D;;OAEG;IACH,KAAK,CAAC,EAAE,aAAa,CAAC;IAEtB;;;OAGG;IACH,OAAO,CAAC,EAAE,eAAe,CAAC;IAE1B;;;OAGG;IACH,SAAS,CAAC,EAAE,iBAAiB,CAAC;IAE9B;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;IAE5B;;OAEG;IACH,cAAc,CAAC,EAAE,sBAAsB,CAAC;CACzC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"in-memory.d.ts","sourceRoot":"","sources":["../../src/storage/in-memory.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;
|
|
1
|
+
{"version":3,"file":"in-memory.d.ts","sourceRoot":"","sources":["../../src/storage/in-memory.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAKlC,OAAO,KAAK,EACV,YAAY,EACZ,WAAW,EACX,WAAW,EACX,SAAS,EACT,YAAY,EACZ,aAAa,EACb,iBAAiB,EACjB,oBAAoB,EAGrB,MAAM,WAAW,CAAC;AACnB,OAAO,KAAK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E,MAAM,EAAE,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC;IAgBzD,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAKlC,OAAO,CACX,GAAG,EAAE,MAAM,EACX,IAAI,CAAC,EAAE,oBAAoB,GAC1B,OAAO,CAAC,WAAW,EAAE,CAAC;IAInB,MAAM,CAAC,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IA+BlD;;OAEG;IACH,OAAO,CAAC,OAAO;IAuCf;;OAEG;IACH,OAAO,CAAC,aAAa;IAyCrB;;OAEG;IACH,OAAO,CAAC,YAAY;IA2CpB;;OAEG;IACH,OAAO,CAAC,YAAY;CA6BrB;AAED;;GAEG;AACH,qBAAa,mBAAoB,YAAW,WAAW;IACrD,OAAO,CAAC,QAAQ,CAAmC;IAE7C,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC;IAI7C,IAAI,CAAC,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC;IAkB1D,MAAM,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC,YAAY,CAAC;IAoBhD,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,kBAAkB,GAAG,OAAO,CAAC,YAAY,CAAC;IAoBpE,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIjC,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAM3C;;OAEG;IACH,OAAO,CAAC,YAAY;IAmEpB;;OAEG;IACH,OAAO,CAAC,YAAY;CASrB"}
|
|
@@ -166,8 +166,12 @@ export class InMemoryThreadStore {
|
|
|
166
166
|
if (!agent || !model) {
|
|
167
167
|
throw new Error(`Thread ${data.tid} references non-existent agent/model (agent: ${data.agentId}, model: ${data.model})`);
|
|
168
168
|
}
|
|
169
|
+
// safety: threads only exist for llm agents
|
|
170
|
+
if (agent.kind !== "llm") {
|
|
171
|
+
throw new Error(`Thread ${data.tid} references non-llm agent ${data.agentId} (kind: ${agent.kind})`);
|
|
172
|
+
}
|
|
169
173
|
return new Thread({
|
|
170
|
-
agent,
|
|
174
|
+
agent: agent,
|
|
171
175
|
tid: data.tid,
|
|
172
176
|
context: new Context(data.namespace, data.context),
|
|
173
177
|
model,
|
|
@@ -127,10 +127,10 @@ describe("FunctionToolkit", () => {
|
|
|
127
127
|
const serialized = (await toolkit.list()).map((tool) => tool.serialize());
|
|
128
128
|
expect(serialized).toHaveLength(1);
|
|
129
129
|
expect(serialized[0]).toEqual({
|
|
130
|
-
|
|
130
|
+
kind: "provider-defined",
|
|
131
131
|
id: anotherHostedTool.id,
|
|
132
132
|
name: anotherHostedTool.name,
|
|
133
|
-
|
|
133
|
+
args: {},
|
|
134
134
|
});
|
|
135
135
|
});
|
|
136
136
|
});
|
package/dist/tool/tool.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Context, UnknownContext } from "../context.js";
|
|
2
|
+
import type { BaseAgent } from "../agent/base.js";
|
|
2
3
|
import { type LanguageModelTool } from "@kernl-sdk/protocol";
|
|
3
4
|
import type { ToolConfig, ToolApprovalFunction, ToolEnabledFunction, ToolErrorFunction, ToolInputParameters, ToolResult } from "./types.js";
|
|
4
5
|
/**
|
|
@@ -26,7 +27,7 @@ export declare abstract class BaseTool<TContext = UnknownContext> {
|
|
|
26
27
|
/**
|
|
27
28
|
* Determines whether the tool should be exposed to the model for the current run.
|
|
28
29
|
*/
|
|
29
|
-
abstract isEnabled(context: Context<TContext>, agent:
|
|
30
|
+
abstract isEnabled(context: Context<TContext>, agent: BaseAgent<TContext>): Promise<boolean>;
|
|
30
31
|
/**
|
|
31
32
|
* Serialize this tool for sending to the model
|
|
32
33
|
*/
|
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;AACpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAK9C,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,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAEhC;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,iBAAiB,GAAG,IAAI,CAAC;IAE3C;;OAEG;IACH,QAAQ,CAAC,gBAAgB,EAAE,oBAAoB,CAAC,GAAG,CAAC,CAAC;IAErD;;OAEG;IACH,QAAQ,CAAC,SAAS,CAAC,OAAO,EAAE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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/toolkit.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { BaseAgent } from "../agent/base.js";
|
|
2
2
|
import type { Context, UnknownContext } from "../context.js";
|
|
3
3
|
import type { Tool } from "./index.js";
|
|
4
4
|
import type { FunctionToolkitConfig, MCPToolkitConfig } from "./types.js";
|
|
@@ -20,12 +20,12 @@ export declare abstract class BaseToolkit<TContext = UnknownContext> {
|
|
|
20
20
|
/**
|
|
21
21
|
* The agent this toolkit is bound to (if any)
|
|
22
22
|
*/
|
|
23
|
-
protected agent?:
|
|
23
|
+
protected agent?: BaseAgent<TContext>;
|
|
24
24
|
/**
|
|
25
25
|
* Bind this toolkit to an agent.
|
|
26
|
-
* Called by
|
|
26
|
+
* Called by agent constructor.
|
|
27
27
|
*/
|
|
28
|
-
bind(agent:
|
|
28
|
+
bind(agent: BaseAgent<TContext>): void;
|
|
29
29
|
/**
|
|
30
30
|
* Get a specific tool by its ID.
|
|
31
31
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toolkit.d.ts","sourceRoot":"","sources":["../../src/tool/toolk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an agent.
|
|
16
|
-
* Called by
|
|
16
|
+
* Called by agent constructor.
|
|
17
17
|
*/
|
|
18
18
|
bind(agent) {
|
|
19
19
|
this.agent = agent;
|
|
@@ -159,6 +159,7 @@ export class MCPToolkit extends BaseToolkit {
|
|
|
159
159
|
if (!this.cached) {
|
|
160
160
|
const mcpTools = await this.server.listTools();
|
|
161
161
|
for (const mcpTool of mcpTools) {
|
|
162
|
+
// safety: MCP tools are context-agnostic (external servers)
|
|
162
163
|
const tool = mcpToFunctionTool(this.server, mcpTool);
|
|
163
164
|
this.cache.set(tool.id, tool);
|
|
164
165
|
}
|
package/dist/tool/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z, type ZodType } from "zod";
|
|
2
|
-
import {
|
|
2
|
+
import type { BaseAgent } from "../agent/base.js";
|
|
3
3
|
import { Context, UnknownContext } from "../context.js";
|
|
4
4
|
import { MCPServer } from "../mcp/base.js";
|
|
5
5
|
import type { ToolCallState } from "@kernl-sdk/protocol";
|
|
@@ -60,7 +60,7 @@ export type ToolConfig<TContext = UnknownContext, TParameters extends ToolInputP
|
|
|
60
60
|
*/
|
|
61
61
|
export interface ToolkitFilterContext<TContext = UnknownContext> {
|
|
62
62
|
context: Context<TContext>;
|
|
63
|
-
agent:
|
|
63
|
+
agent: BaseAgent<TContext>;
|
|
64
64
|
toolkitId: string;
|
|
65
65
|
}
|
|
66
66
|
/**
|
|
@@ -176,10 +176,10 @@ export type ToolExecuteFunction<TContext = UnknownContext, TParameters extends T
|
|
|
176
176
|
* @returns True if the tool call should be approved, false otherwise
|
|
177
177
|
*/
|
|
178
178
|
export type ToolApprovalFunction<TParameters extends ToolInputParameters> = (context: Context, input: ToolExecuteArgument<TParameters>, callId?: string) => Promise<boolean>;
|
|
179
|
-
export type ToolEnabledFunction<TContext = UnknownContext> = (context: Context<TContext>, agent:
|
|
179
|
+
export type ToolEnabledFunction<TContext = UnknownContext> = (context: Context<TContext>, agent: BaseAgent<TContext>) => Promise<boolean>;
|
|
180
180
|
export type ToolEnabledPredicate<TContext = UnknownContext> = (args: {
|
|
181
181
|
context: Context<TContext>;
|
|
182
|
-
agent:
|
|
182
|
+
agent: BaseAgent<TContext>;
|
|
183
183
|
}) => boolean | Promise<boolean>;
|
|
184
184
|
type ToolEnabledOption<Context = UnknownContext> = boolean | ToolEnabledPredicate<Context>;
|
|
185
185
|
/**
|
package/dist/tool/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/tool/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,KAAK,OAAO,EAAE,MAAM,KAAK,CAAC;AAEtC,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/tool/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,KAAK,OAAO,EAAE,MAAM,KAAK,CAAC;AAEtC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEzD,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAEvD;;;GAGG;AACH,MAAM,MAAM,IAAI,CAAC,QAAQ,GAAG,cAAc,IACtC,YAAY,CAAC,QAAQ,EAAE,GAAG,EAAE,GAAG,CAAC,GAChC,UAAU,CAAC;AAEf;;;;;;GAMG;AACH,MAAM,MAAM,UAAU,CACpB,QAAQ,GAAG,cAAc,EACzB,WAAW,SAAS,mBAAmB,GAAG,SAAS,EACnD,OAAO,GAAG,OAAO,IACf;IACF;;OAEG;IACH,EAAE,EAAE,MAAM,CAAC;IAEX;;OAEG;IACH,IAAI,CAAC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cAAc,IAAI,CAC3D,OAAO,EAAE,OAAO,CAAC,QAAQ,CAAC,EAC1B,KAAK,EAAE,SAAS,CAAC,QAAQ,CAAC,KACvB,OAAO,CAAC,OAAO,CAAC,CAAC;AAEtB,MAAM,MAAM,oBAAoB,CAAC,QAAQ,GAAG,cAAc,IAAI,CAAC,IAAI,EAAE;IACnE,OAAO,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC3B,KAAK,EAAE,SAAS,CAAC,QAAQ,CAAC,CAAC;CAC5B,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;AAEjC,KAAK,iBAAiB,CAAC,OAAO,GAAG,cAAc,IAC3C,OAAO,GACP,oBAAoB,CAAC,OAAO,CAAC,CAAC;AAElC;;;;;;;GAOG;AACH,MAAM,MAAM,iBAAiB,GAAG,CAC9B,OAAO,EAAE,OAAO,EAChB,KAAK,EAAE,KAAK,GAAG,OAAO,KACnB,MAAM,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kernl",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.1",
|
|
4
4
|
"description": "A modern AI agent framework",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"kernl",
|
|
@@ -34,10 +34,12 @@
|
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@modelcontextprotocol/sdk": "^1.20.2",
|
|
36
36
|
"yaml": "^2.8.2",
|
|
37
|
-
"
|
|
38
|
-
"@kernl-sdk/
|
|
39
|
-
"@kernl-sdk/
|
|
40
|
-
|
|
37
|
+
"@kernl-sdk/protocol": "0.3.1",
|
|
38
|
+
"@kernl-sdk/retrieval": "0.1.5",
|
|
39
|
+
"@kernl-sdk/shared": "^0.3.1"
|
|
40
|
+
},
|
|
41
|
+
"peerDependencies": {
|
|
42
|
+
"zod": "^4.1.8"
|
|
41
43
|
},
|
|
42
44
|
"devDependencies": {
|
|
43
45
|
"@ai-sdk/openai": "3.0.0-beta.57",
|
|
@@ -45,7 +47,8 @@
|
|
|
45
47
|
"tsc-alias": "^1.8.10",
|
|
46
48
|
"typescript": "5.9.2",
|
|
47
49
|
"vitest": "^4.0.8",
|
|
48
|
-
"
|
|
50
|
+
"zod": "^4.1.8",
|
|
51
|
+
"@kernl-sdk/ai": "0.3.2"
|
|
49
52
|
},
|
|
50
53
|
"scripts": {
|
|
51
54
|
"clean": "rm -rf dist",
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import { randomID } from "@kernl-sdk/shared/lib";
|
|
2
|
+
|
|
3
|
+
import type { Context, UnknownContext } from "@/context";
|
|
4
|
+
import type { Tool, BaseToolkit } from "@/tool";
|
|
5
|
+
import { memory } from "@/tool";
|
|
6
|
+
import { MisconfiguredError } from "@/lib/error";
|
|
7
|
+
import { AgentHooks } from "@/lifecycle";
|
|
8
|
+
import type { Kernl } from "@/kernl";
|
|
9
|
+
import type {
|
|
10
|
+
AgentMemoryCreate,
|
|
11
|
+
AgentMemoryUpdate,
|
|
12
|
+
MemoryListOptions,
|
|
13
|
+
MemorySearchQuery,
|
|
14
|
+
} from "@/memory";
|
|
15
|
+
|
|
16
|
+
import type { AgentKind, AgentMemoryConfig, AgentOutputType } from "./types";
|
|
17
|
+
import type { TextOutput } from "@/thread/types";
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Base configuration shared by all agent types.
|
|
21
|
+
*/
|
|
22
|
+
export interface BaseAgentConfig<TContext = UnknownContext> {
|
|
23
|
+
id: string;
|
|
24
|
+
name: string;
|
|
25
|
+
description?: string;
|
|
26
|
+
instructions:
|
|
27
|
+
| string
|
|
28
|
+
| ((context: Context<TContext>) => Promise<string> | string);
|
|
29
|
+
toolkits?: BaseToolkit<TContext>[];
|
|
30
|
+
memory?: AgentMemoryConfig;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Common model interface shared by all model types.
|
|
35
|
+
*/
|
|
36
|
+
export interface BaseModel {
|
|
37
|
+
readonly provider: string;
|
|
38
|
+
readonly modelId: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Abstract base class for all agent types.
|
|
43
|
+
*
|
|
44
|
+
* Provides common functionality shared between text-based agents (Agent)
|
|
45
|
+
* and realtime agents (RealtimeAgent).
|
|
46
|
+
*/
|
|
47
|
+
export abstract class BaseAgent<
|
|
48
|
+
TContext = UnknownContext,
|
|
49
|
+
TOutput extends AgentOutputType = TextOutput,
|
|
50
|
+
> extends AgentHooks<TContext, TOutput> {
|
|
51
|
+
protected kernl?: Kernl;
|
|
52
|
+
|
|
53
|
+
abstract readonly kind: AgentKind;
|
|
54
|
+
abstract readonly model: BaseModel;
|
|
55
|
+
|
|
56
|
+
readonly id: string;
|
|
57
|
+
readonly name: string;
|
|
58
|
+
readonly description?: string;
|
|
59
|
+
readonly instructions: (
|
|
60
|
+
context: Context<TContext>,
|
|
61
|
+
) => Promise<string> | string;
|
|
62
|
+
readonly toolkits: BaseToolkit<TContext>[];
|
|
63
|
+
readonly systools: BaseToolkit<TContext>[];
|
|
64
|
+
readonly memory: AgentMemoryConfig;
|
|
65
|
+
|
|
66
|
+
constructor(config: BaseAgentConfig<TContext>) {
|
|
67
|
+
super();
|
|
68
|
+
|
|
69
|
+
if (config.id.trim() === "") {
|
|
70
|
+
throw new MisconfiguredError("Agent must have an id.");
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
this.id = config.id;
|
|
74
|
+
this.name = config.name;
|
|
75
|
+
this.description = config.description;
|
|
76
|
+
this.instructions =
|
|
77
|
+
typeof config.instructions === "function"
|
|
78
|
+
? config.instructions
|
|
79
|
+
: () => config.instructions as string;
|
|
80
|
+
this.toolkits = config.toolkits ?? [];
|
|
81
|
+
this.systools = [];
|
|
82
|
+
this.memory = config.memory ?? { enabled: false };
|
|
83
|
+
|
|
84
|
+
for (const toolkit of this.toolkits) {
|
|
85
|
+
toolkit.bind(this);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Bind this agent to a kernl instance. Called by kernl.register().
|
|
91
|
+
*/
|
|
92
|
+
bind(kernl: Kernl): void {
|
|
93
|
+
this.kernl = kernl;
|
|
94
|
+
|
|
95
|
+
// initialize system toolkits
|
|
96
|
+
if (this.memory.enabled) {
|
|
97
|
+
// safety: system tools only rely on ctx.agent, not ctx.context
|
|
98
|
+
const toolkit = memory as unknown as BaseToolkit<TContext>;
|
|
99
|
+
this.systools.push(toolkit);
|
|
100
|
+
toolkit.bind(this);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Get a specific tool by ID from systools and toolkits.
|
|
106
|
+
*/
|
|
107
|
+
tool(id: string): Tool<TContext> | undefined {
|
|
108
|
+
// check systools first
|
|
109
|
+
for (const toolkit of this.systools) {
|
|
110
|
+
const tool = toolkit.get(id);
|
|
111
|
+
if (tool) return tool;
|
|
112
|
+
}
|
|
113
|
+
// then user toolkits
|
|
114
|
+
for (const toolkit of this.toolkits) {
|
|
115
|
+
const tool = toolkit.get(id);
|
|
116
|
+
if (tool) return tool;
|
|
117
|
+
}
|
|
118
|
+
return undefined;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Get all tools available from systools and toolkits for the given context.
|
|
123
|
+
*/
|
|
124
|
+
async tools(context: Context<TContext>): Promise<Tool<TContext>[]> {
|
|
125
|
+
const all: Tool<TContext>[] = [];
|
|
126
|
+
|
|
127
|
+
for (const toolkit of [...this.systools, ...this.toolkits]) {
|
|
128
|
+
all.push(...(await toolkit.list(context)));
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const ids = all.map((t) => t.id);
|
|
132
|
+
const duplicates = ids.filter((id, i) => ids.indexOf(id) !== i);
|
|
133
|
+
|
|
134
|
+
if (duplicates.length > 0) {
|
|
135
|
+
throw new MisconfiguredError(
|
|
136
|
+
`Duplicate tool IDs found: ${[...new Set(duplicates)].join(", ")}`,
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return all;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Memory management scoped to this agent.
|
|
145
|
+
*/
|
|
146
|
+
get memories() {
|
|
147
|
+
if (!this.kernl) {
|
|
148
|
+
throw new MisconfiguredError(
|
|
149
|
+
`Agent ${this.id} not bound to kernl. Call kernl.register(agent) first.`,
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const agentId = this.id;
|
|
154
|
+
const kmem = this.kernl.memories;
|
|
155
|
+
|
|
156
|
+
return {
|
|
157
|
+
list: (
|
|
158
|
+
params?: Omit<MemoryListOptions, "filter"> & {
|
|
159
|
+
collection?: string;
|
|
160
|
+
limit?: number;
|
|
161
|
+
},
|
|
162
|
+
) =>
|
|
163
|
+
kmem.list({
|
|
164
|
+
filter: {
|
|
165
|
+
scope: { agentId },
|
|
166
|
+
collections: params?.collection ? [params.collection] : undefined,
|
|
167
|
+
},
|
|
168
|
+
limit: params?.limit,
|
|
169
|
+
}),
|
|
170
|
+
|
|
171
|
+
create: (params: AgentMemoryCreate) =>
|
|
172
|
+
kmem.create({
|
|
173
|
+
id: params.id ?? `mem_${randomID()}`,
|
|
174
|
+
scope: {
|
|
175
|
+
namespace: params.namespace,
|
|
176
|
+
entityId: params.entityId,
|
|
177
|
+
agentId,
|
|
178
|
+
},
|
|
179
|
+
kind: "semantic",
|
|
180
|
+
collection: params.collection,
|
|
181
|
+
content: params.content,
|
|
182
|
+
wmem: params.wmem,
|
|
183
|
+
smem: params.smem,
|
|
184
|
+
timestamp: params.timestamp,
|
|
185
|
+
metadata: params.metadata,
|
|
186
|
+
}),
|
|
187
|
+
|
|
188
|
+
update: (params: AgentMemoryUpdate) =>
|
|
189
|
+
kmem.update({
|
|
190
|
+
id: params.id,
|
|
191
|
+
content: params.content,
|
|
192
|
+
collection: params.collection,
|
|
193
|
+
wmem: params.wmem,
|
|
194
|
+
smem: params.smem,
|
|
195
|
+
metadata: params.metadata,
|
|
196
|
+
}),
|
|
197
|
+
|
|
198
|
+
search: (
|
|
199
|
+
params: Omit<MemorySearchQuery, "filter"> & {
|
|
200
|
+
filter?: Omit<NonNullable<MemorySearchQuery["filter"]>, "scope"> & {
|
|
201
|
+
scope?: Omit<
|
|
202
|
+
NonNullable<NonNullable<MemorySearchQuery["filter"]>["scope"]>,
|
|
203
|
+
"agentId"
|
|
204
|
+
>;
|
|
205
|
+
};
|
|
206
|
+
},
|
|
207
|
+
) =>
|
|
208
|
+
kmem.search({
|
|
209
|
+
...params,
|
|
210
|
+
filter: {
|
|
211
|
+
...params.filter,
|
|
212
|
+
scope: {
|
|
213
|
+
...params.filter?.scope,
|
|
214
|
+
agentId,
|
|
215
|
+
},
|
|
216
|
+
},
|
|
217
|
+
}),
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
}
|
package/src/agent/index.ts
CHANGED