kernl 0.1.4 → 0.2.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 +5 -4
- package/CHANGELOG.md +12 -0
- package/dist/agent.d.ts +20 -3
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +60 -41
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/kernl.d.ts +27 -1
- package/dist/kernl.d.ts.map +1 -1
- package/dist/kernl.js +36 -2
- package/dist/mcp/__tests__/integration.test.js +16 -0
- package/dist/thread/__tests__/fixtures/mock-model.d.ts +7 -0
- package/dist/thread/__tests__/fixtures/mock-model.d.ts.map +1 -0
- package/dist/thread/__tests__/fixtures/mock-model.js +59 -0
- package/dist/thread/__tests__/integration.test.d.ts +2 -0
- package/dist/thread/__tests__/integration.test.d.ts.map +1 -0
- package/dist/thread/__tests__/integration.test.js +247 -0
- package/dist/thread/__tests__/stream.test.d.ts +2 -0
- package/dist/thread/__tests__/stream.test.d.ts.map +1 -0
- package/dist/thread/__tests__/stream.test.js +244 -0
- package/dist/thread/__tests__/thread.test.js +612 -763
- package/dist/thread/thread.d.ts +30 -25
- package/dist/thread/thread.d.ts.map +1 -1
- package/dist/thread/thread.js +114 -314
- package/dist/thread/utils.d.ts +16 -1
- package/dist/thread/utils.d.ts.map +1 -1
- package/dist/thread/utils.js +30 -0
- package/dist/tool/index.d.ts +1 -1
- package/dist/tool/index.d.ts.map +1 -1
- package/dist/tool/index.js +1 -1
- package/dist/tool/tool.d.ts.map +1 -1
- package/dist/tool/tool.js +6 -2
- package/dist/tool/toolkit.d.ts +7 -3
- package/dist/tool/toolkit.d.ts.map +1 -1
- package/dist/tool/toolkit.js +7 -3
- package/dist/types/agent.d.ts +5 -5
- package/dist/types/agent.d.ts.map +1 -1
- package/dist/types/thread.d.ts +10 -16
- package/dist/types/thread.d.ts.map +1 -1
- package/package.json +7 -5
- package/src/agent.ts +97 -86
- package/src/index.ts +1 -1
- package/src/kernl.ts +51 -2
- package/src/mcp/__tests__/integration.test.ts +17 -0
- package/src/thread/__tests__/fixtures/mock-model.ts +71 -0
- package/src/thread/__tests__/integration.test.ts +349 -0
- package/src/thread/__tests__/thread.test.ts +625 -775
- package/src/thread/thread.ts +134 -381
- package/src/thread/utils.ts +36 -1
- package/src/tool/index.ts +1 -1
- package/src/tool/tool.ts +6 -2
- package/src/tool/toolkit.ts +10 -3
- package/src/types/agent.ts +9 -6
- package/src/types/thread.ts +25 -17
package/dist/tool/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { BaseTool, FunctionTool, HostedTool, tool } from "./tool";
|
|
2
|
-
export { Toolkit, FunctionToolkit, MCPToolkit } from "./toolkit";
|
|
2
|
+
export { BaseToolkit, Toolkit, FunctionToolkit, MCPToolkit } from "./toolkit";
|
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":"
|
|
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;AAMpD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAE7D,OAAO,KAAK,EAEV,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,QAA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AAC,QAAQ,CAAC,CAAC;gBAE7B,MAAM,EAAE,UAAU,CAAC,QAAQ,EAAE,WAAW,EAAE,OAAO,CAAC;IAqC9D;;;;OAIG;IACG,MAAM,CACV,OAAO,EAAE,OAAO,CAAC,QAAQ,CAAC,EAC1B,IAAI,EAAE,MAAM,EACZ,MAAM,CAAC,EAAE,MAAM,GACd,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;IAgB/B;;OAEG;YACW,OAAO;IAuCrB;;OAEG;IACH,SAAS,IAAI,iBAAiB;CAU/B;AAED;;GAEG;AACH,qBAAa,UAAW,SAAQ,QAAQ;IACtC,QAAQ,CAAC,IAAI,EAAG,aAAa,CAAU;IACvC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAE5C;;OAEG;IACH,OAAO,EAAE,iBAAiB,GAAG,IAAI,CAA4B;IAE7D;;OAEG;IACH,gBAAgB,EAAE,oBAAoB,CAAC,GAAG,CAAC,CAAqB;gBAEpD,MAAM,EAAE;QAClB,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;KACpC;IAOD;;OAEG;IACG,SAAS,IAAI,OAAO,CAAC,OAAO,CAAC;IAInC;;OAEG;IACH,SAAS,IAAI,iBAAiB;CAQ/B"}
|
package/dist/tool/tool.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
1
2
|
import { ModelBehaviorError } from "../lib/error";
|
|
2
3
|
import { logger } from "../lib/logger";
|
|
3
4
|
import { json } from "@kernl-sdk/shared/lib";
|
|
@@ -93,9 +94,10 @@ export class FunctionTool extends BaseTool {
|
|
|
93
94
|
throw new ModelBehaviorError("Invalid JSON input for tool");
|
|
94
95
|
}
|
|
95
96
|
}
|
|
96
|
-
//
|
|
97
|
+
// check if approval is required
|
|
97
98
|
const needsApproval = await this.requiresApproval(context, parsed, callId);
|
|
98
99
|
const approvalStatus = callId ? context.approvals.get(callId) : undefined;
|
|
100
|
+
// (TODO): this will become a more detailed action.approval event
|
|
99
101
|
if (needsApproval && approvalStatus !== "approved") {
|
|
100
102
|
return {
|
|
101
103
|
state: INTERRUPTIBLE,
|
|
@@ -118,7 +120,9 @@ export class FunctionTool extends BaseTool {
|
|
|
118
120
|
kind: "function",
|
|
119
121
|
name: this.id,
|
|
120
122
|
description: this.description,
|
|
121
|
-
parameters: this.parameters
|
|
123
|
+
parameters: (this.parameters
|
|
124
|
+
? z.toJSONSchema(this.parameters, { target: "draft-7" })
|
|
125
|
+
: {}), // JSONSchema7 - target: 'draft-7' produces this
|
|
122
126
|
};
|
|
123
127
|
}
|
|
124
128
|
}
|
package/dist/tool/toolkit.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ import type { FunctionToolkitConfig, MCPToolkitConfig } from "./types";
|
|
|
8
8
|
* Toolkits can be static (FunctionToolkit) or dynamic (MCPToolkit), and provide
|
|
9
9
|
* a unified interface for tool discovery and management.
|
|
10
10
|
*/
|
|
11
|
-
export declare abstract class
|
|
11
|
+
export declare abstract class BaseToolkit<TContext = UnknownContext> {
|
|
12
12
|
/**
|
|
13
13
|
* Unique identifier for this toolkit
|
|
14
14
|
*/
|
|
@@ -59,7 +59,7 @@ export declare abstract class Toolkit<TContext = UnknownContext> {
|
|
|
59
59
|
* });
|
|
60
60
|
* ```
|
|
61
61
|
*/
|
|
62
|
-
export declare class FunctionToolkit<TContext = UnknownContext> extends
|
|
62
|
+
export declare class FunctionToolkit<TContext = UnknownContext> extends BaseToolkit<TContext> {
|
|
63
63
|
readonly id: string;
|
|
64
64
|
readonly description: string;
|
|
65
65
|
private tools;
|
|
@@ -84,7 +84,11 @@ export declare class FunctionToolkit<TContext = UnknownContext> extends Toolkit<
|
|
|
84
84
|
*/
|
|
85
85
|
list(context?: Context<TContext>): Promise<Tool<TContext>[]>;
|
|
86
86
|
}
|
|
87
|
-
|
|
87
|
+
/**
|
|
88
|
+
* Convenience alias for FunctionToolkit - the default toolkit implementation.
|
|
89
|
+
*/
|
|
90
|
+
export { FunctionToolkit as Toolkit };
|
|
91
|
+
export declare class MCPToolkit<TContext = UnknownContext> extends BaseToolkit<TContext> {
|
|
88
92
|
readonly id: string;
|
|
89
93
|
readonly description: string;
|
|
90
94
|
private server;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toolkit.d.ts","sourceRoot":"","sources":["../../src/tool/toolkit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAMzD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,GAAG,CAAC;AAC9B,OAAO,KAAK,EACV,qBAAqB,EACrB,gBAAgB,EAEjB,MAAM,SAAS,CAAC;AAEjB;;;;;GAKG;AACH,8BAAsB,
|
|
1
|
+
{"version":3,"file":"toolkit.d.ts","sourceRoot":"","sources":["../../src/tool/toolkit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAMzD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,GAAG,CAAC;AAC9B,OAAO,KAAK,EACV,qBAAqB,EACrB,gBAAgB,EAEjB,MAAM,SAAS,CAAC;AAEjB;;;;;GAKG;AACH,8BAAsB,WAAW,CAAC,QAAQ,GAAG,cAAc;IACzD;;OAEG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IAE7B;;OAEG;IACH,QAAQ,CAAC,QAAQ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E,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,OAAO,CAAC,MAAM,CAAY;IAC1B,OAAO,CAAC,KAAK,CAA8B;IAC3C,OAAO,CAAC,MAAM,CAA0B;IAExC,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,MAAM,CAAS;IAEvB;;;;OAIG;gBACS,MAAM,EAAE,gBAAgB,CAAC,QAAQ,CAAC;IAS9C;;;;;;;;OAQG;IACH,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,SAAS;IAI3C;;;;;;;;;OASG;IACG,IAAI,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;IA+BlE;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CAQ/B"}
|
package/dist/tool/toolkit.js
CHANGED
|
@@ -6,7 +6,7 @@ import { filter } from "@kernl-sdk/shared/lib";
|
|
|
6
6
|
* Toolkits can be static (FunctionToolkit) or dynamic (MCPToolkit), and provide
|
|
7
7
|
* a unified interface for tool discovery and management.
|
|
8
8
|
*/
|
|
9
|
-
export class
|
|
9
|
+
export class BaseToolkit {
|
|
10
10
|
/**
|
|
11
11
|
* The agent this toolkit is bound to (if any)
|
|
12
12
|
*/
|
|
@@ -38,7 +38,7 @@ export class Toolkit {
|
|
|
38
38
|
* });
|
|
39
39
|
* ```
|
|
40
40
|
*/
|
|
41
|
-
export class FunctionToolkit extends
|
|
41
|
+
export class FunctionToolkit extends BaseToolkit {
|
|
42
42
|
id;
|
|
43
43
|
description;
|
|
44
44
|
tools;
|
|
@@ -72,6 +72,10 @@ export class FunctionToolkit extends Toolkit {
|
|
|
72
72
|
return Array.from(this.tools.values());
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* Convenience alias for FunctionToolkit - the default toolkit implementation.
|
|
77
|
+
*/
|
|
78
|
+
export { FunctionToolkit as Toolkit };
|
|
75
79
|
/*
|
|
76
80
|
* A toolkit that wraps an MCP server and provides tools from it.
|
|
77
81
|
*
|
|
@@ -103,7 +107,7 @@ export class FunctionToolkit extends Toolkit {
|
|
|
103
107
|
* });
|
|
104
108
|
* ```
|
|
105
109
|
*/
|
|
106
|
-
export class MCPToolkit extends
|
|
110
|
+
export class MCPToolkit extends BaseToolkit {
|
|
107
111
|
id;
|
|
108
112
|
description;
|
|
109
113
|
server;
|
package/dist/types/agent.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { type ZodType } from "zod";
|
|
|
2
2
|
import { Context, UnknownContext } from "../context";
|
|
3
3
|
import { LanguageModel, LanguageModelRequestSettings } from "@kernl-sdk/protocol";
|
|
4
4
|
import { InputGuardrail, OutputGuardrail } from "../guardrail";
|
|
5
|
-
import {
|
|
5
|
+
import { BaseToolkit } from "../tool";
|
|
6
6
|
import { TextResponse } from "./thread";
|
|
7
7
|
/**
|
|
8
8
|
* Configuration for an agent.
|
|
@@ -24,18 +24,18 @@ export interface AgentConfig<TContext = UnknownContext, TResponse extends AgentR
|
|
|
24
24
|
*
|
|
25
25
|
* By default, if not set, the agent will use a default model that throws an error when called.
|
|
26
26
|
*/
|
|
27
|
-
model
|
|
27
|
+
model: LanguageModel;
|
|
28
28
|
/**
|
|
29
29
|
* Configures model-specific tuning parameters (e.g. temperature, top_p, etc.)
|
|
30
30
|
*/
|
|
31
31
|
modelSettings?: LanguageModelRequestSettings;
|
|
32
32
|
/**
|
|
33
33
|
* A list of toolkits the agent can use. Toolkits are collections of related tools
|
|
34
|
-
* that can be static (
|
|
34
|
+
* that can be static (Toolkit) or dynamic (MCPToolkit).
|
|
35
35
|
*
|
|
36
36
|
* @example
|
|
37
37
|
* ```typescript
|
|
38
|
-
* const myTools = new
|
|
38
|
+
* const myTools = new Toolkit({
|
|
39
39
|
* id: "custom",
|
|
40
40
|
* tools: [tool1, tool2]
|
|
41
41
|
* });
|
|
@@ -52,7 +52,7 @@ export interface AgentConfig<TContext = UnknownContext, TResponse extends AgentR
|
|
|
52
52
|
* });
|
|
53
53
|
* ```
|
|
54
54
|
*/
|
|
55
|
-
toolkits?:
|
|
55
|
+
toolkits?: BaseToolkit<TContext>[];
|
|
56
56
|
/**
|
|
57
57
|
* A list of checks that run in parallel to the agent's execution on the input + output for the agent,
|
|
58
58
|
* depending on the configuration.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../../src/types/agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,KAAK,CAAC;AAEnC,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,
|
|
1
|
+
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../../src/types/agent.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,UAAU,CAAC;AAExC;;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;IAEb;;;;;;;OAOG;IACH,YAAY,EACR,MAAM,GACN,CAAC,CAAC,OAAO,EAAE,OAAO,CAAC,QAAQ,CAAC,KAAK,OAAO,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC;IAe/D;;;;OAIG;IACH,KAAK,EAAE,aAAa,CAAC;IAErB;;OAEG;IACH,aAAa,CAAC,EAAE,4BAA4B,CAAC;IAE7C;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,QAAQ,CAAC,EAAE,WAAW,CAAC,QAAQ,CAAC,EAAE,CAAC;IAEnC;;;OAGG;IACH,UAAU,CAAC,EAAE,eAAe,CAAC,SAAS,CAAC,CAAC;IAExC;;OAEG;IACH,YAAY,CAAC,EAAE,SAAS,CAAC;IAsBzB;;;OAGG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,WAAW,eAAe,CAC9B,SAAS,SAAS,iBAAiB,GAAG,YAAY;IAElD;;;OAGG;IACH,KAAK,EAAE,cAAc,EAAE,CAAC;IACxB;;;OAGG;IACH,MAAM,EAAE,eAAe,CAAC,SAAS,CAAC,EAAE,CAAC;CACtC;AAED;;;GAGG;AACH,MAAM,MAAM,iBAAiB,GAAG,YAAY,GAAG,OAAO,CAAC"}
|
package/dist/types/thread.d.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
import { ToolCall, LanguageModel, LanguageModelItem, LanguageModelStreamEvent } from "@kernl-sdk/protocol";
|
|
1
|
+
import { ToolCall, LanguageModel, LanguageModelItem, LanguageModelStreamEvent, RUNNING, STOPPED, INTERRUPTIBLE, UNINTERRUPTIBLE, ZOMBIE, DEAD } from "@kernl-sdk/protocol";
|
|
2
2
|
import { Task } from "../task";
|
|
3
3
|
import { Context } from "../context";
|
|
4
|
+
export type TextResponse = "text";
|
|
5
|
+
/**
|
|
6
|
+
* Thread state discriminated union
|
|
7
|
+
*/
|
|
8
|
+
export type ThreadState = typeof RUNNING | typeof STOPPED | typeof INTERRUPTIBLE | typeof UNINTERRUPTIBLE | typeof ZOMBIE | typeof DEAD;
|
|
4
9
|
/**
|
|
5
10
|
* Thread-specific tool call state for approval workflow.
|
|
6
11
|
* This extends the protocol states for internal thread use.
|
|
@@ -23,19 +28,6 @@ export type ThreadStreamEvent = LanguageModelStreamEvent;
|
|
|
23
28
|
export interface ActionSet {
|
|
24
29
|
toolCalls: ToolCall[];
|
|
25
30
|
}
|
|
26
|
-
/**
|
|
27
|
-
* Result of a single tick of execution
|
|
28
|
-
*/
|
|
29
|
-
export interface TickResult {
|
|
30
|
-
/**
|
|
31
|
-
* Events to add to thread history
|
|
32
|
-
*/
|
|
33
|
-
events: ThreadEvent[];
|
|
34
|
-
/**
|
|
35
|
-
* Action intentions that need to be performed as a result of this tick
|
|
36
|
-
*/
|
|
37
|
-
intentions: ActionSet | null;
|
|
38
|
-
}
|
|
39
31
|
/**
|
|
40
32
|
* Result of performing actions, including both executed results and pending approvals
|
|
41
33
|
*/
|
|
@@ -64,8 +56,10 @@ export interface ThreadExecuteResult<TResponse = any> {
|
|
|
64
56
|
}
|
|
65
57
|
export interface ThreadOptions<TContext> {
|
|
66
58
|
context: Context<TContext>;
|
|
67
|
-
task?: Task<TContext>;
|
|
68
59
|
model?: LanguageModel;
|
|
60
|
+
task?: Task<TContext>;
|
|
61
|
+
threadId?: string;
|
|
62
|
+
maxTicks?: number;
|
|
63
|
+
abort?: AbortSignal;
|
|
69
64
|
}
|
|
70
|
-
export type TextResponse = "text";
|
|
71
65
|
//# sourceMappingURL=thread.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"thread.d.ts","sourceRoot":"","sources":["../../src/types/thread.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,aAAa,EACb,iBAAiB,EACjB,wBAAwB,
|
|
1
|
+
{"version":3,"file":"thread.d.ts","sourceRoot":"","sources":["../../src/types/thread.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,aAAa,EACb,iBAAiB,EACjB,wBAAwB,EACxB,OAAO,EACP,OAAO,EACP,aAAa,EACb,eAAe,EACf,MAAM,EACN,IAAI,EACL,MAAM,qBAAqB,CAAC;AAE7B,OAAO,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
4
|
-
"description": "A modern AI agent framework
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "A modern AI agent framework",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"kernl",
|
|
7
7
|
"ai",
|
|
@@ -31,14 +31,16 @@
|
|
|
31
31
|
"@modelcontextprotocol/sdk": "^1.20.2",
|
|
32
32
|
"pino": "^9.6.0",
|
|
33
33
|
"zod": "^4.1.12",
|
|
34
|
-
"@kernl-sdk/
|
|
35
|
-
"@kernl-sdk/
|
|
34
|
+
"@kernl-sdk/protocol": "0.2.0",
|
|
35
|
+
"@kernl-sdk/shared": "^0.1.1"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
+
"@ai-sdk/openai": "3.0.0-beta.57",
|
|
38
39
|
"@types/node": "^24.10.0",
|
|
39
40
|
"tsc-alias": "^1.8.10",
|
|
40
41
|
"typescript": "5.9.2",
|
|
41
|
-
"vitest": "^4.0.8"
|
|
42
|
+
"vitest": "^4.0.8",
|
|
43
|
+
"@kernl-sdk/ai": "0.1.1"
|
|
42
44
|
},
|
|
43
45
|
"scripts": {
|
|
44
46
|
"build": "tsc && tsc-alias",
|
package/src/agent.ts
CHANGED
|
@@ -1,16 +1,27 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
LanguageModel,
|
|
3
|
+
LanguageModelRequestSettings,
|
|
4
|
+
message,
|
|
5
|
+
} from "@kernl-sdk/protocol";
|
|
2
6
|
|
|
3
7
|
import type { Context, UnknownContext } from "./context";
|
|
4
8
|
import { InputGuardrail, OutputGuardrail } from "./guardrail";
|
|
5
9
|
import { AgentHooks } from "./lifecycle";
|
|
6
|
-
import {
|
|
10
|
+
import { BaseToolkit } from "./tool/toolkit";
|
|
7
11
|
import { Tool } from "./tool";
|
|
8
|
-
|
|
12
|
+
import { Thread } from "./thread";
|
|
9
13
|
|
|
10
14
|
import { MisconfiguredError } from "./lib/error";
|
|
11
15
|
|
|
12
16
|
import type { AgentConfig, AgentResponseType } from "./types/agent";
|
|
13
|
-
import {
|
|
17
|
+
import type {
|
|
18
|
+
TextResponse,
|
|
19
|
+
ThreadOptions,
|
|
20
|
+
ThreadExecuteResult,
|
|
21
|
+
ThreadStreamEvent,
|
|
22
|
+
} from "./types/thread";
|
|
23
|
+
import type { Kernl } from "./kernl";
|
|
24
|
+
import type { ResolvedAgentResponse } from "./guardrail";
|
|
14
25
|
|
|
15
26
|
export class Agent<
|
|
16
27
|
TContext = UnknownContext,
|
|
@@ -19,13 +30,22 @@ export class Agent<
|
|
|
19
30
|
extends AgentHooks<TContext, TResponse>
|
|
20
31
|
implements AgentConfig<TContext, TResponse>
|
|
21
32
|
{
|
|
33
|
+
private kernl?: Kernl;
|
|
34
|
+
|
|
22
35
|
id: string;
|
|
23
36
|
name: string;
|
|
24
37
|
instructions: (context: Context<TContext>) => Promise<string> | string;
|
|
25
38
|
|
|
26
39
|
model: LanguageModel;
|
|
27
40
|
modelSettings: LanguageModelRequestSettings;
|
|
28
|
-
toolkits:
|
|
41
|
+
toolkits: BaseToolkit<TContext>[];
|
|
42
|
+
guardrails: {
|
|
43
|
+
input: InputGuardrail[];
|
|
44
|
+
output: OutputGuardrail<AgentResponseType>[];
|
|
45
|
+
};
|
|
46
|
+
responseType: TResponse = "text" as TResponse;
|
|
47
|
+
resetToolChoice: boolean;
|
|
48
|
+
// toolUseBehavior: ToolUseBehavior; (TODO)
|
|
29
49
|
|
|
30
50
|
// --- (TODO) ---
|
|
31
51
|
// handoffDescription: string; // ??
|
|
@@ -35,36 +55,11 @@ export class Agent<
|
|
|
35
55
|
// /* Process/thread-group–wide signal state shared by all threads in the group: shared pending signals, job control
|
|
36
56
|
// (stops/cont, group exit), rlimits, etc. */
|
|
37
57
|
// signal: *struct signal_struct;
|
|
38
|
-
//
|
|
58
|
+
//
|
|
59
|
+
// /* Table of signal handlers (sa_handler, sa_mask, flags) shared by threads
|
|
60
|
+
// (CLONE_SIGHAND). RCU-protected so readers can access it locklessly. */
|
|
39
61
|
// sighand: *struct sighand_struct __rcu;
|
|
40
62
|
|
|
41
|
-
guardrails: {
|
|
42
|
-
input: InputGuardrail[];
|
|
43
|
-
output: OutputGuardrail<AgentResponseType>[];
|
|
44
|
-
};
|
|
45
|
-
responseType: TResponse = "text" as TResponse;
|
|
46
|
-
resetToolChoice: boolean;
|
|
47
|
-
// toolUseBehavior: ToolUseBehavior; (TODO)
|
|
48
|
-
|
|
49
|
-
// /**
|
|
50
|
-
// * Create an Agent with handoffs and automatically infer the union type for TResponse from the handoff agents' response types.
|
|
51
|
-
// */
|
|
52
|
-
// static create<
|
|
53
|
-
// TResponse extends AgentResponseType = TextResponse,
|
|
54
|
-
// Handoffs extends readonly (Agent<any, any> | Handoff<any, any>)[] = [],
|
|
55
|
-
// >(
|
|
56
|
-
// config: AgentConfigWithHandoffs<TResponse, Handoffs>,
|
|
57
|
-
// ): Agent<UnknownContext, TResponse | HandoffsOutputUnion<Handoffs>> {
|
|
58
|
-
// return new Agent<UnknownContext, TResponse | HandoffsOutputUnion<Handoffs>>(
|
|
59
|
-
// {
|
|
60
|
-
// ...config,
|
|
61
|
-
// handoffs: config.handoffs as any,
|
|
62
|
-
// responseType: config.responseType,
|
|
63
|
-
// handoffresponseTypeWarningEnabled: false,
|
|
64
|
-
// },
|
|
65
|
-
// );
|
|
66
|
-
// }
|
|
67
|
-
|
|
68
63
|
constructor(config: AgentConfig<TContext, TResponse>) {
|
|
69
64
|
super();
|
|
70
65
|
if (config.id.trim() === "") {
|
|
@@ -76,7 +71,7 @@ export class Agent<
|
|
|
76
71
|
typeof config.instructions === "function"
|
|
77
72
|
? config.instructions
|
|
78
73
|
: () => config.instructions as string;
|
|
79
|
-
this.model = config.model
|
|
74
|
+
this.model = config.model; // (TODO): include optional default setting for convenience like env.DEFAULT_LLM = "gpt-5"
|
|
80
75
|
this.modelSettings = config.modelSettings ?? {};
|
|
81
76
|
|
|
82
77
|
this.toolkits = config.toolkits ?? [];
|
|
@@ -95,30 +90,82 @@ export class Agent<
|
|
|
95
90
|
// this.handoffs = config.handoffs ?? [];
|
|
96
91
|
|
|
97
92
|
// --- Runtime warning for handoff response type compatibility ---
|
|
98
|
-
// if (
|
|
99
|
-
//
|
|
100
|
-
// config.handoffresponseTypeWarningEnabled
|
|
101
|
-
// ) {
|
|
102
|
-
// if (this.handoffs && this.responseType) {
|
|
103
|
-
// const responseTypes = new Set<string>([
|
|
104
|
-
// JSON.stringify(this.responseType),
|
|
105
|
-
// ]);
|
|
106
|
-
// for (const h of this.handoffs) {
|
|
107
|
-
// if ("responseType" in h && h.responseType) {
|
|
108
|
-
// responseTypes.add(JSON.stringify(h.responseType));
|
|
109
|
-
// } else if ("agent" in h && h.agent.responseType) {
|
|
110
|
-
// responseTypes.add(JSON.stringify(h.agent.responseType));
|
|
111
|
-
// }
|
|
112
|
-
// }
|
|
93
|
+
// if (config.handoffresponseTypeWarningEnabled) {
|
|
94
|
+
// ...
|
|
113
95
|
// if (responseTypes.size > 1) {
|
|
114
96
|
// logger.warn(
|
|
115
|
-
// `[Agent] Warning: Handoff agents have different response types: ${Array.from(responseTypes).join(", ")}.
|
|
97
|
+
// `[Agent] Warning: Handoff agents have different response types: ${Array.from(responseTypes).join(", ")}.
|
|
98
|
+
// You can make it type-safe by using Agent.create({ ... }) method instead.`,
|
|
116
99
|
// );
|
|
117
100
|
// }
|
|
118
101
|
// }
|
|
119
102
|
// }
|
|
120
103
|
}
|
|
121
104
|
|
|
105
|
+
/**
|
|
106
|
+
* Bind this agent to a kernl instance. Called by kernl.register().
|
|
107
|
+
*/
|
|
108
|
+
bind(kernl: Kernl): void {
|
|
109
|
+
this.kernl = kernl;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Blocking execution - spawns or resumes thread and waits for completion
|
|
114
|
+
*/
|
|
115
|
+
async run(
|
|
116
|
+
instructions: string,
|
|
117
|
+
options?: ThreadOptions<TContext>,
|
|
118
|
+
): Promise<ThreadExecuteResult<ResolvedAgentResponse<TResponse>>> {
|
|
119
|
+
if (!this.kernl) {
|
|
120
|
+
throw new MisconfiguredError(
|
|
121
|
+
`Agent ${this.id} not bound to kernl. Call kernl.register(agent) first.`,
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const m = message({ role: "user", text: instructions });
|
|
126
|
+
const tid = options?.threadId;
|
|
127
|
+
|
|
128
|
+
// NOTE: may end up moving this to the kernl
|
|
129
|
+
let thread = tid ? this.kernl.threads.get(tid) : null;
|
|
130
|
+
if (!thread) {
|
|
131
|
+
thread = new Thread(this.kernl, this, [m], options);
|
|
132
|
+
return this.kernl.spawn(thread);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
thread.append(m);
|
|
136
|
+
return this.kernl.schedule(thread);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Streaming execution - spawns or resumes thread and returns async iterator
|
|
141
|
+
*
|
|
142
|
+
* NOTE: streaming probably won't make sense in scheduling contexts so spawnStream etc. won't make sense
|
|
143
|
+
*/
|
|
144
|
+
async *stream(
|
|
145
|
+
instructions: string,
|
|
146
|
+
options?: ThreadOptions<TContext>,
|
|
147
|
+
): AsyncIterable<ThreadStreamEvent> {
|
|
148
|
+
if (!this.kernl) {
|
|
149
|
+
throw new MisconfiguredError(
|
|
150
|
+
`Agent ${this.id} not bound to kernl. Call kernl.register(agent) first.`,
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const m = message({ role: "user", text: instructions });
|
|
155
|
+
const tid = options?.threadId;
|
|
156
|
+
|
|
157
|
+
// NOTE: may end up moving this to the kernl
|
|
158
|
+
let thread = tid ? this.kernl.threads.get(tid) : null;
|
|
159
|
+
if (!thread) {
|
|
160
|
+
thread = new Thread(this.kernl, this, [m], options);
|
|
161
|
+
yield* this.kernl.spawnStream(thread);
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
thread.append(m);
|
|
166
|
+
yield* this.kernl.scheduleStream(thread);
|
|
167
|
+
}
|
|
168
|
+
|
|
122
169
|
/**
|
|
123
170
|
* Get a specific tool by ID from all toolkits.
|
|
124
171
|
*
|
|
@@ -164,40 +211,4 @@ export class Agent<
|
|
|
164
211
|
|
|
165
212
|
return allTools;
|
|
166
213
|
}
|
|
167
|
-
|
|
168
|
-
// async run<TContext>(
|
|
169
|
-
// input: string,
|
|
170
|
-
// options: SharedRunOptions<TContext>,
|
|
171
|
-
// ): Promise<RunResult<TContext>> {
|
|
172
|
-
// // TODO
|
|
173
|
-
// // ...
|
|
174
|
-
// }
|
|
175
|
-
|
|
176
|
-
// async stream<TContext>(
|
|
177
|
-
// input: string,
|
|
178
|
-
// options: StreamOptions<TContext>,
|
|
179
|
-
// ): Promise<StreamedRunResult<TContext>> {
|
|
180
|
-
// // TODO
|
|
181
|
-
// // ...
|
|
182
|
-
// }
|
|
183
|
-
//
|
|
184
|
-
|
|
185
|
-
// ----------------------
|
|
186
|
-
// Events
|
|
187
|
-
// ----------------------
|
|
188
|
-
|
|
189
|
-
// on(event: any, handler: Function): void {
|
|
190
|
-
// // TODO
|
|
191
|
-
// // ...
|
|
192
|
-
// }
|
|
193
|
-
|
|
194
|
-
// once(event: any, handler: Function): void {
|
|
195
|
-
// // TODO
|
|
196
|
-
// // ...
|
|
197
|
-
// }
|
|
198
|
-
|
|
199
|
-
// off(event: any, handler: Function): void {
|
|
200
|
-
// // TODO
|
|
201
|
-
// // ...
|
|
202
|
-
// }
|
|
203
214
|
}
|
package/src/index.ts
CHANGED
package/src/kernl.ts
CHANGED
|
@@ -1,22 +1,71 @@
|
|
|
1
1
|
import { Agent } from "./agent";
|
|
2
2
|
import { UnknownContext } from "./context";
|
|
3
3
|
import { KernlHooks } from "./lifecycle";
|
|
4
|
+
import type { Thread } from "./thread";
|
|
4
5
|
|
|
5
6
|
import type { AgentResponseType } from "./types/agent";
|
|
7
|
+
import type { ThreadExecuteResult, ThreadStreamEvent } from "./types/thread";
|
|
8
|
+
import type { ResolvedAgentResponse } from "./guardrail";
|
|
6
9
|
|
|
7
10
|
/**
|
|
8
|
-
*
|
|
11
|
+
* The kernl - manages agent processes, scheduling, and task lifecycle
|
|
9
12
|
*
|
|
10
13
|
* Orchestrates agent execution, including guardrails, tool calls, session persistence, and
|
|
11
14
|
* tracing.
|
|
12
15
|
*/
|
|
13
16
|
export class Kernl extends KernlHooks<UnknownContext, AgentResponseType> {
|
|
14
17
|
private agents: Map<string, Agent> = new Map();
|
|
18
|
+
threads: Map<string, Thread<any, any>> = new Map();
|
|
15
19
|
|
|
16
20
|
/**
|
|
17
21
|
* Registers a new agent with the kernl instance.
|
|
18
22
|
*/
|
|
19
23
|
register(agent: Agent): void {
|
|
20
|
-
|
|
24
|
+
this.agents.set(agent.id, agent);
|
|
25
|
+
agent.bind(this);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Spawn a new thread - blocking execution
|
|
30
|
+
*/
|
|
31
|
+
async spawn<TContext, TResponse extends AgentResponseType>(
|
|
32
|
+
thread: Thread<TContext, TResponse>,
|
|
33
|
+
): Promise<ThreadExecuteResult<ResolvedAgentResponse<TResponse>>> {
|
|
34
|
+
this.threads.set(thread.id, thread);
|
|
35
|
+
return await thread.execute();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Schedule an existing thread - blocking execution
|
|
40
|
+
*
|
|
41
|
+
* NOTE: just blocks for now
|
|
42
|
+
*/
|
|
43
|
+
async schedule<TContext, TResponse extends AgentResponseType>(
|
|
44
|
+
thread: Thread<TContext, TResponse>,
|
|
45
|
+
): Promise<ThreadExecuteResult<ResolvedAgentResponse<TResponse>>> {
|
|
46
|
+
return await thread.execute();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* (TMP) - probably won't make sense with assync scheduling contexts
|
|
51
|
+
*
|
|
52
|
+
* Spawn a new thread - streaming execution
|
|
53
|
+
*/
|
|
54
|
+
async *spawnStream<TContext, TResponse extends AgentResponseType>(
|
|
55
|
+
thread: Thread<TContext, TResponse>,
|
|
56
|
+
): AsyncIterable<ThreadStreamEvent> {
|
|
57
|
+
this.threads.set(thread.id, thread);
|
|
58
|
+
yield* thread.stream();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* (TMP) - probably won't make sense with assync scheduling contexts
|
|
63
|
+
*
|
|
64
|
+
* Schedule an existing thread - streaming execution
|
|
65
|
+
*/
|
|
66
|
+
async *scheduleStream<TContext, TResponse extends AgentResponseType>(
|
|
67
|
+
thread: Thread<TContext, TResponse>,
|
|
68
|
+
): AsyncIterable<ThreadStreamEvent> {
|
|
69
|
+
yield* thread.stream();
|
|
21
70
|
}
|
|
22
71
|
}
|
|
@@ -9,9 +9,18 @@ import { tool } from "@/tool";
|
|
|
9
9
|
import { z } from "zod";
|
|
10
10
|
import { Thread } from "@/thread";
|
|
11
11
|
import { createMCPToolStaticFilter } from "../utils";
|
|
12
|
+
import { createMockModel } from "@/thread/__tests__/fixtures/mock-model";
|
|
12
13
|
|
|
13
14
|
const TEST_SERVER = path.join(__dirname, "fixtures", "server.ts");
|
|
14
15
|
|
|
16
|
+
// Mock model for tests that only need toolkit functionality
|
|
17
|
+
const mockModel = createMockModel(async () => ({
|
|
18
|
+
content: [],
|
|
19
|
+
finishReason: "stop",
|
|
20
|
+
usage: { inputTokens: 0, outputTokens: 0, totalTokens: 0 },
|
|
21
|
+
warnings: [],
|
|
22
|
+
}));
|
|
23
|
+
|
|
15
24
|
describe("MCP Integration Tests", () => {
|
|
16
25
|
describe("MCPToolkit Integration", () => {
|
|
17
26
|
let server: MCPServerStdio;
|
|
@@ -158,6 +167,7 @@ describe("MCP Integration Tests", () => {
|
|
|
158
167
|
id: "test-agent",
|
|
159
168
|
name: "Test Agent",
|
|
160
169
|
instructions: "Test",
|
|
170
|
+
model: mockModel,
|
|
161
171
|
toolkits: [toolkit],
|
|
162
172
|
});
|
|
163
173
|
|
|
@@ -194,6 +204,7 @@ describe("MCP Integration Tests", () => {
|
|
|
194
204
|
id: "test-agent",
|
|
195
205
|
name: "Test Agent",
|
|
196
206
|
instructions: "Test",
|
|
207
|
+
model: mockModel,
|
|
197
208
|
toolkits: [toolkit],
|
|
198
209
|
});
|
|
199
210
|
|
|
@@ -232,6 +243,7 @@ describe("MCP Integration Tests", () => {
|
|
|
232
243
|
id: "test-agent",
|
|
233
244
|
name: "Test Agent",
|
|
234
245
|
instructions: "Test",
|
|
246
|
+
model: mockModel,
|
|
235
247
|
toolkits: [toolkit],
|
|
236
248
|
});
|
|
237
249
|
|
|
@@ -265,6 +277,7 @@ describe("MCP Integration Tests", () => {
|
|
|
265
277
|
id: "test-agent",
|
|
266
278
|
name: "Test Agent",
|
|
267
279
|
instructions: "Test",
|
|
280
|
+
model: mockModel,
|
|
268
281
|
toolkits: [mcpToolkit],
|
|
269
282
|
});
|
|
270
283
|
|
|
@@ -294,6 +307,7 @@ describe("MCP Integration Tests", () => {
|
|
|
294
307
|
id: "test-agent",
|
|
295
308
|
name: "Test Agent",
|
|
296
309
|
instructions: "Test",
|
|
310
|
+
model: mockModel,
|
|
297
311
|
toolkits: [mcpToolkit],
|
|
298
312
|
});
|
|
299
313
|
|
|
@@ -325,6 +339,7 @@ describe("MCP Integration Tests", () => {
|
|
|
325
339
|
id: "test-agent",
|
|
326
340
|
name: "Test Agent",
|
|
327
341
|
instructions: "Test",
|
|
342
|
+
model: mockModel,
|
|
328
343
|
toolkits: [mcpToolkit],
|
|
329
344
|
});
|
|
330
345
|
|
|
@@ -382,6 +397,7 @@ describe("MCP Integration Tests", () => {
|
|
|
382
397
|
id: "test-agent",
|
|
383
398
|
name: "Test Agent",
|
|
384
399
|
instructions: "Test",
|
|
400
|
+
model: mockModel,
|
|
385
401
|
toolkits: [mcpToolkit, functionToolkit],
|
|
386
402
|
});
|
|
387
403
|
|
|
@@ -431,6 +447,7 @@ describe("MCP Integration Tests", () => {
|
|
|
431
447
|
id: "test-agent",
|
|
432
448
|
name: "Test Agent",
|
|
433
449
|
instructions: "Test",
|
|
450
|
+
model: mockModel,
|
|
434
451
|
toolkits: [mcpToolkit, functionToolkit],
|
|
435
452
|
});
|
|
436
453
|
|