kernl 0.7.4 → 0.8.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 +27 -1
- package/dist/agent/types.d.ts +20 -12
- package/dist/agent/types.d.ts.map +1 -1
- package/dist/agent.d.ts +7 -7
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +3 -14
- package/dist/api/resources/agents/agents.d.ts +5 -5
- package/dist/api/resources/agents/agents.d.ts.map +1 -1
- package/dist/api/resources/agents/agents.js +1 -1
- package/dist/guardrail.d.ts +19 -19
- package/dist/guardrail.d.ts.map +1 -1
- package/dist/kernl/kernl.d.ts +6 -6
- package/dist/kernl/kernl.d.ts.map +1 -1
- package/dist/lib/error.d.ts +3 -3
- package/dist/lib/error.d.ts.map +1 -1
- package/dist/lifecycle.d.ts +6 -6
- package/dist/lifecycle.d.ts.map +1 -1
- package/dist/memory/__tests__/encoder.test.d.ts +2 -0
- package/dist/memory/__tests__/encoder.test.d.ts.map +1 -0
- package/dist/memory/__tests__/encoder.test.js +121 -0
- package/dist/memory/codecs/domain.d.ts +6 -0
- package/dist/memory/codecs/domain.d.ts.map +1 -1
- package/dist/memory/codecs/domain.js +6 -0
- package/dist/memory/codecs/tpuf.d.ts.map +1 -1
- package/dist/memory/codecs/tpuf.js +2 -5
- package/dist/memory/encoder.d.ts +25 -2
- package/dist/memory/encoder.d.ts.map +1 -1
- package/dist/memory/encoder.js +46 -5
- package/dist/memory/index.d.ts +1 -1
- package/dist/memory/index.d.ts.map +1 -1
- package/dist/memory/index.js +1 -1
- package/dist/memory/schema.js +5 -4
- package/dist/memory/types.d.ts +2 -1
- package/dist/memory/types.d.ts.map +1 -1
- package/dist/thread/__tests__/integration.test.d.ts +1 -1
- package/dist/thread/__tests__/integration.test.d.ts.map +1 -1
- package/dist/thread/__tests__/integration.test.js +10 -5
- package/dist/thread/__tests__/thread.test.js +8 -8
- package/dist/thread/thread.d.ts +5 -5
- package/dist/thread/thread.d.ts.map +1 -1
- package/dist/thread/thread.js +13 -2
- package/dist/thread/types.d.ts +9 -6
- package/dist/thread/types.d.ts.map +1 -1
- package/dist/thread/utils.d.ts +7 -6
- package/dist/thread/utils.d.ts.map +1 -1
- package/dist/thread/utils.js +9 -8
- package/package.json +5 -4
- package/src/agent/types.ts +25 -29
- package/src/agent.ts +15 -28
- package/src/api/resources/agents/agents.ts +8 -8
- package/src/guardrail.ts +28 -28
- package/src/kernl/kernl.ts +12 -12
- package/src/lib/error.ts +3 -3
- package/src/lifecycle.ts +6 -6
- package/src/memory/__tests__/encoder.test.ts +154 -0
- package/src/memory/codecs/domain.ts +6 -0
- package/src/memory/codecs/tpuf.ts +2 -5
- package/src/memory/encoder.ts +51 -6
- package/src/memory/index.ts +1 -1
- package/src/memory/schema.ts +5 -5
- package/src/memory/types.ts +2 -1
- package/src/thread/__tests__/integration.test.ts +130 -146
- package/src/thread/__tests__/thread.test.ts +8 -8
- package/src/thread/thread.ts +21 -7
- package/src/thread/types.ts +9 -6
- package/src/thread/utils.ts +15 -14
package/dist/thread/types.d.ts
CHANGED
|
@@ -2,13 +2,16 @@ import { ToolCall, LanguageModel, LanguageModelItem, LanguageModelStreamEvent, R
|
|
|
2
2
|
import { Task } from "../task.js";
|
|
3
3
|
import { Context } from "../context.js";
|
|
4
4
|
import { Agent } from "../agent.js";
|
|
5
|
-
import type {
|
|
5
|
+
import type { AgentOutputType } from "../agent/types.js";
|
|
6
6
|
import type { ThreadStore } from "../storage/index.js";
|
|
7
7
|
/**
|
|
8
8
|
* Public/client-facing thread events (excludes internal system events).
|
|
9
9
|
*/
|
|
10
10
|
export type PublicThreadEvent = LanguageModelItem & ThreadEventBase;
|
|
11
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Text output type - indicates the agent returns a plain string.
|
|
13
|
+
*/
|
|
14
|
+
export type TextOutput = "text";
|
|
12
15
|
/**
|
|
13
16
|
* Thread state values as a const array (for zod schemas).
|
|
14
17
|
*/
|
|
@@ -27,9 +30,9 @@ export declare const REQUIRES_APPROVAL = "requires_approval";
|
|
|
27
30
|
*
|
|
28
31
|
* Represents the complete state of a Thread that can be stored and restored.
|
|
29
32
|
*/
|
|
30
|
-
export interface IThread<TContext = unknown,
|
|
33
|
+
export interface IThread<TContext = unknown, TOutput extends AgentOutputType = "text"> {
|
|
31
34
|
tid: string;
|
|
32
|
-
agent: Agent<TContext,
|
|
35
|
+
agent: Agent<TContext, TOutput>;
|
|
33
36
|
model: LanguageModel;
|
|
34
37
|
context: Context<TContext>;
|
|
35
38
|
input: LanguageModelItem[];
|
|
@@ -95,8 +98,8 @@ export interface ThreadExecuteResult<TResponse = unknown> {
|
|
|
95
98
|
/**
|
|
96
99
|
* Options for constructing a Thread.
|
|
97
100
|
*/
|
|
98
|
-
export interface ThreadOptions<TContext = unknown,
|
|
99
|
-
agent: Agent<TContext,
|
|
101
|
+
export interface ThreadOptions<TContext = unknown, TOutput extends AgentOutputType = "text"> {
|
|
102
|
+
agent: Agent<TContext, TOutput>;
|
|
100
103
|
input?: LanguageModelItem[];
|
|
101
104
|
history?: ThreadEvent[];
|
|
102
105
|
context?: Context<TContext>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/thread/types.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,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/thread/types.ts"],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AC9B"}
|
package/dist/thread/utils.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ResolvedAgentResponse } from "../guardrail.js";
|
|
2
2
|
import { ToolCall, LanguageModelItem } from "@kernl-sdk/protocol";
|
|
3
|
-
import type {
|
|
3
|
+
import type { AgentOutputType } from "../agent/types.js";
|
|
4
4
|
import type { ThreadEvent, ThreadStreamEvent, ActionSet, PublicThreadEvent } from "./types.js";
|
|
5
5
|
/**
|
|
6
6
|
* Create a ThreadEvent from a LanguageModelItem with thread metadata.
|
|
@@ -50,13 +50,14 @@ export declare function isPublicEvent(event: ThreadEvent): event is PublicThread
|
|
|
50
50
|
*/
|
|
51
51
|
export declare function getFinalResponse(items: LanguageModelItem[]): string | null;
|
|
52
52
|
/**
|
|
53
|
-
*
|
|
53
|
+
* Parse the final response according to the output type schema.
|
|
54
54
|
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
* - If
|
|
55
|
+
* This serves as a safety net validation after native structured output from the provider.
|
|
56
|
+
*
|
|
57
|
+
* - If output is "text", returns the text as-is
|
|
58
|
+
* - If output is a ZodType, parses and validates the text as JSON
|
|
58
59
|
*
|
|
59
60
|
* @throws {ModelBehaviorError} if structured output validation fails
|
|
60
61
|
*/
|
|
61
|
-
export declare function parseFinalResponse<
|
|
62
|
+
export declare function parseFinalResponse<TOutput extends AgentOutputType>(text: string, output: TOutput): ResolvedAgentResponse<TOutput>;
|
|
62
63
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/thread/utils.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAIzD,OAAO,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAIlE,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":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AI,EAAE,MAAM,EACZ,MAAM,EAAE,OAAO,GACd,qBAAqB,CAAC,OAAO,CAAC,CAsBhC"}
|
package/dist/thread/utils.js
CHANGED
|
@@ -95,22 +95,23 @@ export function getFinalResponse(items) {
|
|
|
95
95
|
return null;
|
|
96
96
|
}
|
|
97
97
|
/**
|
|
98
|
-
*
|
|
98
|
+
* Parse the final response according to the output type schema.
|
|
99
99
|
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
* - If
|
|
100
|
+
* This serves as a safety net validation after native structured output from the provider.
|
|
101
|
+
*
|
|
102
|
+
* - If output is "text", returns the text as-is
|
|
103
|
+
* - If output is a ZodType, parses and validates the text as JSON
|
|
103
104
|
*
|
|
104
105
|
* @throws {ModelBehaviorError} if structured output validation fails
|
|
105
106
|
*/
|
|
106
|
-
export function parseFinalResponse(text,
|
|
107
|
-
if (
|
|
107
|
+
export function parseFinalResponse(text, output) {
|
|
108
|
+
if (output === "text") {
|
|
108
109
|
return text; // text output - return as-is
|
|
109
110
|
}
|
|
110
111
|
// structured output - decode JSON and validate with schema
|
|
111
|
-
if (
|
|
112
|
+
if (output && typeof output === "object") {
|
|
112
113
|
// (TODO): prob better way of checking this here
|
|
113
|
-
const schema =
|
|
114
|
+
const schema = output;
|
|
114
115
|
try {
|
|
115
116
|
const validated = json(schema).decode(text); // (TODO): it would be nice if we could use `decodeSafe` here
|
|
116
117
|
return validated;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kernl",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.1",
|
|
4
4
|
"description": "A modern AI agent framework",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"kernl",
|
|
@@ -34,10 +34,11 @@
|
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@modelcontextprotocol/sdk": "^1.20.2",
|
|
36
36
|
"pino": "^9.6.0",
|
|
37
|
+
"yaml": "^2.8.2",
|
|
37
38
|
"zod": "^4.1.12",
|
|
39
|
+
"@kernl-sdk/protocol": "0.2.8",
|
|
38
40
|
"@kernl-sdk/retrieval": "0.1.3",
|
|
39
|
-
"@kernl-sdk/shared": "^0.3.0"
|
|
40
|
-
"@kernl-sdk/protocol": "0.2.8"
|
|
41
|
+
"@kernl-sdk/shared": "^0.3.0"
|
|
41
42
|
},
|
|
42
43
|
"devDependencies": {
|
|
43
44
|
"@ai-sdk/openai": "3.0.0-beta.57",
|
|
@@ -45,7 +46,7 @@
|
|
|
45
46
|
"tsc-alias": "^1.8.10",
|
|
46
47
|
"typescript": "5.9.2",
|
|
47
48
|
"vitest": "^4.0.8",
|
|
48
|
-
"@kernl-sdk/ai": "0.
|
|
49
|
+
"@kernl-sdk/ai": "0.3.0"
|
|
49
50
|
},
|
|
50
51
|
"scripts": {
|
|
51
52
|
"clean": "rm -rf dist",
|
package/src/agent/types.ts
CHANGED
|
@@ -1,30 +1,26 @@
|
|
|
1
1
|
import { type ZodType } from "zod";
|
|
2
2
|
|
|
3
|
-
import { Context, UnknownContext } from "@/context";
|
|
4
3
|
import {
|
|
5
4
|
LanguageModel,
|
|
6
5
|
LanguageModelRequestSettings,
|
|
7
6
|
} from "@kernl-sdk/protocol";
|
|
7
|
+
|
|
8
|
+
import { Context, UnknownContext } from "@/context";
|
|
8
9
|
import { InputGuardrail, OutputGuardrail } from "@/guardrail";
|
|
9
10
|
import { BaseToolkit } from "@/tool";
|
|
10
11
|
|
|
11
|
-
import {
|
|
12
|
+
import { TextOutput } from "@/thread/types";
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
15
|
* Configuration for an agent.
|
|
15
16
|
*/
|
|
16
17
|
export interface AgentConfig<
|
|
17
18
|
TContext = UnknownContext,
|
|
18
|
-
|
|
19
|
+
TOutput extends AgentOutputType = TextOutput,
|
|
19
20
|
> {
|
|
20
|
-
/* The unique identifier for the agent
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
/* The name of the agent (defaults to ID if not provided) */
|
|
24
|
-
name: string;
|
|
25
|
-
|
|
26
|
-
/* A brief description of the agent's purpose */
|
|
27
|
-
description?: string;
|
|
21
|
+
id: string /* The unique identifier for the agent */;
|
|
22
|
+
name: string /* The name of the agent (defaults to ID if not provided) */;
|
|
23
|
+
description?: string /* A brief description of the agent's purpose */;
|
|
28
24
|
|
|
29
25
|
/**
|
|
30
26
|
* The instructions for the agent. Will be used as the "system prompt" when this agent is
|
|
@@ -38,12 +34,6 @@ export interface AgentConfig<
|
|
|
38
34
|
| string
|
|
39
35
|
| ((context: Context<TContext>) => Promise<string> | string);
|
|
40
36
|
|
|
41
|
-
// /**
|
|
42
|
-
// * A description of the agent. This is used when the agent is used as a handoff, so that an LLM
|
|
43
|
-
// * knows what it does and when to invoke it.
|
|
44
|
-
// */
|
|
45
|
-
// handoffDescription: string;
|
|
46
|
-
|
|
47
37
|
// /**
|
|
48
38
|
// * Handoffs are sub-agents that the agent can delegate to. You can provide a list of handoffs,
|
|
49
39
|
// * and the agent can choose to delegate to them if relevant. Allows for separation of concerns
|
|
@@ -63,6 +53,19 @@ export interface AgentConfig<
|
|
|
63
53
|
*/
|
|
64
54
|
modelSettings?: LanguageModelRequestSettings;
|
|
65
55
|
|
|
56
|
+
/**
|
|
57
|
+
* The type of the output that the agent will return.
|
|
58
|
+
*
|
|
59
|
+
* Can be either:
|
|
60
|
+
* - `"text"` (default): The agent returns a plain string response
|
|
61
|
+
* - A Zod schema: The agent returns structured output validated against the schema
|
|
62
|
+
*
|
|
63
|
+
* When a Zod schema is provided, the output is converted to JSON Schema and sent to the
|
|
64
|
+
* model for native structured output support. The response is then validated against
|
|
65
|
+
* the Zod schema as a safety net.
|
|
66
|
+
*/
|
|
67
|
+
output?: TOutput;
|
|
68
|
+
|
|
66
69
|
/**
|
|
67
70
|
* A list of toolkits the agent can use. Toolkits are collections of related tools
|
|
68
71
|
* that can be static (Toolkit) or dynamic (MCPToolkit).
|
|
@@ -100,12 +103,7 @@ export interface AgentConfig<
|
|
|
100
103
|
* A list of checks that run in parallel to the agent's execution on the input + output for the agent,
|
|
101
104
|
* depending on the configuration.
|
|
102
105
|
*/
|
|
103
|
-
guardrails?: AgentGuardrails<
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* The type of the response that the agent will return. If not provided, response will be a string.
|
|
107
|
-
*/
|
|
108
|
-
responseType?: TResponse;
|
|
106
|
+
guardrails?: AgentGuardrails<TOutput>;
|
|
109
107
|
|
|
110
108
|
// /**
|
|
111
109
|
// * (TODO): Not sure if this is really necessary.. need to see use case examples
|
|
@@ -137,9 +135,7 @@ export interface AgentConfig<
|
|
|
137
135
|
/**
|
|
138
136
|
* Guardrails for an agent.
|
|
139
137
|
*/
|
|
140
|
-
export interface AgentGuardrails<
|
|
141
|
-
TResponse extends AgentResponseType = TextResponse,
|
|
142
|
-
> {
|
|
138
|
+
export interface AgentGuardrails<TOutput extends AgentOutputType = TextOutput> {
|
|
143
139
|
/**
|
|
144
140
|
* A list of checks that run in parallel to the agent's execution, before generating a response.
|
|
145
141
|
* Runs only if the agent is the first agent in the chain.
|
|
@@ -149,14 +145,14 @@ export interface AgentGuardrails<
|
|
|
149
145
|
* A list of checks that run on the final output of the agent, after generating a response. Runs
|
|
150
146
|
* only if the agent produces a final output.
|
|
151
147
|
*/
|
|
152
|
-
output: OutputGuardrail<
|
|
148
|
+
output: OutputGuardrail<TOutput>[];
|
|
153
149
|
}
|
|
154
150
|
|
|
155
151
|
/**
|
|
156
|
-
* The type of the output
|
|
152
|
+
* The type of the output. If not provided, the output will be a string.
|
|
157
153
|
* 'text' is a special type that indicates the output will be a string.
|
|
158
154
|
*/
|
|
159
|
-
export type
|
|
155
|
+
export type AgentOutputType = TextOutput | ZodType;
|
|
160
156
|
|
|
161
157
|
/**
|
|
162
158
|
* Memory configuration for an agent.
|
package/src/agent.ts
CHANGED
|
@@ -37,10 +37,10 @@ import { MisconfiguredError, RuntimeError } from "./lib/error";
|
|
|
37
37
|
import type {
|
|
38
38
|
AgentConfig,
|
|
39
39
|
AgentMemoryConfig,
|
|
40
|
-
|
|
40
|
+
AgentOutputType,
|
|
41
41
|
} from "./agent/types";
|
|
42
42
|
import type {
|
|
43
|
-
|
|
43
|
+
TextOutput,
|
|
44
44
|
ThreadExecuteOptions,
|
|
45
45
|
ThreadExecuteResult,
|
|
46
46
|
ThreadStreamEvent,
|
|
@@ -48,10 +48,10 @@ import type {
|
|
|
48
48
|
|
|
49
49
|
export class Agent<
|
|
50
50
|
TContext = UnknownContext,
|
|
51
|
-
|
|
51
|
+
TOutput extends AgentOutputType = TextOutput,
|
|
52
52
|
>
|
|
53
|
-
extends AgentHooks<TContext,
|
|
54
|
-
implements AgentConfig<TContext,
|
|
53
|
+
extends AgentHooks<TContext, TOutput>
|
|
54
|
+
implements AgentConfig<TContext, TOutput>
|
|
55
55
|
{
|
|
56
56
|
private kernl?: Kernl;
|
|
57
57
|
|
|
@@ -69,25 +69,12 @@ export class Agent<
|
|
|
69
69
|
|
|
70
70
|
guardrails: {
|
|
71
71
|
input: InputGuardrail[];
|
|
72
|
-
output: OutputGuardrail<
|
|
72
|
+
output: OutputGuardrail<AgentOutputType>[];
|
|
73
73
|
};
|
|
74
|
-
|
|
74
|
+
output: TOutput = "text" as TOutput;
|
|
75
75
|
resetToolChoice: boolean;
|
|
76
76
|
|
|
77
|
-
|
|
78
|
-
// toolUseBehavior: ToolUseBehavior;
|
|
79
|
-
// handoffs: (Agent<any, TResponse> | Handoff<any, TResponse>)[];
|
|
80
|
-
// ----------
|
|
81
|
-
|
|
82
|
-
// /* Process/thread-group–wide signal state shared by all threads in the group: shared pending signals, job control
|
|
83
|
-
// (stops/cont, group exit), rlimits, etc. */
|
|
84
|
-
// signal: *struct signal_struct;
|
|
85
|
-
//
|
|
86
|
-
// /* Table of signal handlers (sa_handler, sa_mask, flags) shared by threads
|
|
87
|
-
// (CLONE_SIGHAND). RCU-protected so readers can access it locklessly. */
|
|
88
|
-
// sighand: *struct sighand_struct __rcu;
|
|
89
|
-
|
|
90
|
-
constructor(config: AgentConfig<TContext, TResponse>) {
|
|
77
|
+
constructor(config: AgentConfig<TContext, TOutput>) {
|
|
91
78
|
super();
|
|
92
79
|
if (config.id.trim() === "") {
|
|
93
80
|
throw new MisconfiguredError("Agent must have an id.");
|
|
@@ -111,8 +98,8 @@ export class Agent<
|
|
|
111
98
|
}
|
|
112
99
|
|
|
113
100
|
this.guardrails = config.guardrails ?? { input: [], output: [] };
|
|
114
|
-
if (config.
|
|
115
|
-
this.
|
|
101
|
+
if (config.output) {
|
|
102
|
+
this.output = config.output;
|
|
116
103
|
}
|
|
117
104
|
this.resetToolChoice = config.resetToolChoice ?? true;
|
|
118
105
|
// this.toolUseBehavior = config.toolUseBehavior ?? "run_llm_again";
|
|
@@ -142,7 +129,7 @@ export class Agent<
|
|
|
142
129
|
async run(
|
|
143
130
|
input: string | LanguageModelItem[],
|
|
144
131
|
options?: ThreadExecuteOptions<TContext>,
|
|
145
|
-
): Promise<ThreadExecuteResult<ResolvedAgentResponse<
|
|
132
|
+
): Promise<ThreadExecuteResult<ResolvedAgentResponse<TOutput>>> {
|
|
146
133
|
if (!this.kernl) {
|
|
147
134
|
throw new MisconfiguredError(
|
|
148
135
|
`Agent ${this.id} not bound to kernl. Call kernl.register(agent) first.`,
|
|
@@ -155,7 +142,7 @@ export class Agent<
|
|
|
155
142
|
: input;
|
|
156
143
|
const tid = options?.threadId;
|
|
157
144
|
|
|
158
|
-
let thread: Thread<TContext,
|
|
145
|
+
let thread: Thread<TContext, TOutput> | null = null;
|
|
159
146
|
|
|
160
147
|
if (tid) {
|
|
161
148
|
// no concurrent execution of same thread - correctness contract
|
|
@@ -168,7 +155,7 @@ export class Agent<
|
|
|
168
155
|
if (this.kernl.storage?.threads) {
|
|
169
156
|
thread = (await this.kernl.storage.threads.get(tid, {
|
|
170
157
|
history: true,
|
|
171
|
-
})) as Thread<TContext,
|
|
158
|
+
})) as Thread<TContext, TOutput> | null;
|
|
172
159
|
}
|
|
173
160
|
}
|
|
174
161
|
|
|
@@ -216,7 +203,7 @@ export class Agent<
|
|
|
216
203
|
: input;
|
|
217
204
|
const tid = options?.threadId;
|
|
218
205
|
|
|
219
|
-
let thread: Thread<TContext,
|
|
206
|
+
let thread: Thread<TContext, TOutput> | null = null;
|
|
220
207
|
|
|
221
208
|
if (tid) {
|
|
222
209
|
// no concurrent execution of same thread - correctness contract
|
|
@@ -229,7 +216,7 @@ export class Agent<
|
|
|
229
216
|
if (this.kernl.storage?.threads) {
|
|
230
217
|
thread = (await this.kernl.storage.threads.get(tid, {
|
|
231
218
|
history: true,
|
|
232
|
-
})) as Thread<TContext,
|
|
219
|
+
})) as Thread<TContext, TOutput> | null;
|
|
233
220
|
}
|
|
234
221
|
}
|
|
235
222
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Agent } from "@/agent";
|
|
2
|
-
import type {
|
|
2
|
+
import type { AgentOutputType } from "@/agent/types";
|
|
3
3
|
import type { UnknownContext } from "@/context";
|
|
4
|
-
import type {
|
|
4
|
+
import type { TextOutput } from "@/thread/types";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Agents resource.
|
|
@@ -16,15 +16,15 @@ export class RAgents {
|
|
|
16
16
|
/**
|
|
17
17
|
* Get a live Agent instance by id.
|
|
18
18
|
*
|
|
19
|
-
* Callers are expected to know the concrete TContext/
|
|
19
|
+
* Callers are expected to know the concrete TContext/TOutput types
|
|
20
20
|
* for their own agents and can specify them via generics.
|
|
21
21
|
*/
|
|
22
22
|
get<
|
|
23
23
|
TContext = UnknownContext,
|
|
24
|
-
|
|
25
|
-
>(id: string): Agent<TContext,
|
|
24
|
+
TOutput extends AgentOutputType = TextOutput,
|
|
25
|
+
>(id: string): Agent<TContext, TOutput> | undefined {
|
|
26
26
|
const agent = this.registry.get(id);
|
|
27
|
-
return agent as Agent<TContext,
|
|
27
|
+
return agent as Agent<TContext, TOutput> | undefined;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
/**
|
|
@@ -40,10 +40,10 @@ export class RAgents {
|
|
|
40
40
|
* Since this is a heterogeneous collection, we expose the widest safe
|
|
41
41
|
* type parameters here.
|
|
42
42
|
*/
|
|
43
|
-
list(): Agent<UnknownContext,
|
|
43
|
+
list(): Agent<UnknownContext, AgentOutputType>[] {
|
|
44
44
|
return Array.from(this.registry.values()) as Agent<
|
|
45
45
|
UnknownContext,
|
|
46
|
-
|
|
46
|
+
AgentOutputType
|
|
47
47
|
>[];
|
|
48
48
|
}
|
|
49
49
|
|
package/src/guardrail.ts
CHANGED
|
@@ -4,19 +4,19 @@ import { LanguageModelResponse } from "@kernl-sdk/protocol";
|
|
|
4
4
|
|
|
5
5
|
import { Agent } from "./agent";
|
|
6
6
|
import { Context, UnknownContext } from "./context";
|
|
7
|
-
import type {
|
|
8
|
-
import type {
|
|
7
|
+
import type { AgentOutputType } from "@/agent/types";
|
|
8
|
+
import type { TextOutput, ThreadEvent } from "@/thread/types";
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Resolves the agent output type based on the response type.
|
|
12
|
-
* - If
|
|
13
|
-
* - If
|
|
12
|
+
* - If TOutput is "text" → output is string
|
|
13
|
+
* - If TOutput is a ZodType → output is the inferred type from that schema
|
|
14
14
|
*/
|
|
15
|
-
export type ResolvedAgentResponse<
|
|
16
|
-
|
|
15
|
+
export type ResolvedAgentResponse<TOutput extends AgentOutputType> =
|
|
16
|
+
TOutput extends TextOutput
|
|
17
17
|
? string
|
|
18
|
-
:
|
|
19
|
-
? z.infer<
|
|
18
|
+
: TOutput extends ZodType
|
|
19
|
+
? z.infer<TOutput>
|
|
20
20
|
: never;
|
|
21
21
|
|
|
22
22
|
/**
|
|
@@ -149,10 +149,10 @@ export function defineInputGuardrail({
|
|
|
149
149
|
*/
|
|
150
150
|
export interface OutputGuardrailFunctionArgs<
|
|
151
151
|
TContext = UnknownContext,
|
|
152
|
-
|
|
152
|
+
TOutput extends AgentOutputType = TextOutput,
|
|
153
153
|
> {
|
|
154
154
|
agent: Agent<any, any>;
|
|
155
|
-
agentOutput: ResolvedAgentResponse<
|
|
155
|
+
agentOutput: ResolvedAgentResponse<TOutput>; // ??
|
|
156
156
|
context: Context<TContext>;
|
|
157
157
|
/**
|
|
158
158
|
* Additional details about the agent output.
|
|
@@ -166,16 +166,16 @@ export interface OutputGuardrailFunctionArgs<
|
|
|
166
166
|
* A function that takes an output guardrail function arguments and returns a `GuardrailFunctionOutput`.
|
|
167
167
|
*/
|
|
168
168
|
export type OutputGuardrailFunction<
|
|
169
|
-
|
|
169
|
+
TOutput extends AgentOutputType = TextOutput,
|
|
170
170
|
> = (
|
|
171
|
-
args: OutputGuardrailFunctionArgs<UnknownContext,
|
|
171
|
+
args: OutputGuardrailFunctionArgs<UnknownContext, TOutput>,
|
|
172
172
|
) => Promise<GuardrailFunctionOutput>;
|
|
173
173
|
|
|
174
174
|
/**
|
|
175
175
|
* A guardrail that checks the output of the agent.
|
|
176
176
|
*/
|
|
177
177
|
export interface OutputGuardrail<
|
|
178
|
-
|
|
178
|
+
TOutput extends AgentOutputType = TextOutput,
|
|
179
179
|
> {
|
|
180
180
|
/**
|
|
181
181
|
* The name of the guardrail.
|
|
@@ -185,7 +185,7 @@ export interface OutputGuardrail<
|
|
|
185
185
|
/**
|
|
186
186
|
* The function that performs the guardrail check.
|
|
187
187
|
*/
|
|
188
|
-
execute: OutputGuardrailFunction<
|
|
188
|
+
execute: OutputGuardrailFunction<TOutput>;
|
|
189
189
|
}
|
|
190
190
|
|
|
191
191
|
/**
|
|
@@ -201,7 +201,7 @@ export interface OutputGuardrailMetadata {
|
|
|
201
201
|
*/
|
|
202
202
|
export interface OutputGuardrailResult<
|
|
203
203
|
TMeta = OutputGuardrailMetadata,
|
|
204
|
-
|
|
204
|
+
TOutput extends AgentOutputType = TextOutput,
|
|
205
205
|
> {
|
|
206
206
|
/**
|
|
207
207
|
* The metadata of the guardrail.
|
|
@@ -211,12 +211,12 @@ export interface OutputGuardrailResult<
|
|
|
211
211
|
/**
|
|
212
212
|
* The output of the agent that ran.
|
|
213
213
|
*/
|
|
214
|
-
agentOutput: ResolvedAgentResponse<
|
|
214
|
+
agentOutput: ResolvedAgentResponse<TOutput>; // ??
|
|
215
215
|
|
|
216
216
|
/**
|
|
217
217
|
* The agent that ran.
|
|
218
218
|
*/
|
|
219
|
-
agent: Agent<UnknownContext,
|
|
219
|
+
agent: Agent<UnknownContext, TOutput>;
|
|
220
220
|
|
|
221
221
|
/**
|
|
222
222
|
* The output of the guardrail.
|
|
@@ -229,43 +229,43 @@ export interface OutputGuardrailResult<
|
|
|
229
229
|
*/
|
|
230
230
|
export interface OutputGuardrailDefinition<
|
|
231
231
|
TMeta = OutputGuardrailMetadata,
|
|
232
|
-
|
|
232
|
+
TOutput extends AgentOutputType = TextOutput,
|
|
233
233
|
> extends OutputGuardrailMetadata {
|
|
234
|
-
guardrailFunction: OutputGuardrailFunction<
|
|
234
|
+
guardrailFunction: OutputGuardrailFunction<TOutput>;
|
|
235
235
|
run(
|
|
236
|
-
args: OutputGuardrailFunctionArgs<UnknownContext,
|
|
237
|
-
): Promise<OutputGuardrailResult<TMeta,
|
|
236
|
+
args: OutputGuardrailFunctionArgs<UnknownContext, TOutput>,
|
|
237
|
+
): Promise<OutputGuardrailResult<TMeta, TOutput>>;
|
|
238
238
|
}
|
|
239
239
|
|
|
240
240
|
/**
|
|
241
241
|
* Arguments for defining an output guardrail definition.
|
|
242
242
|
*/
|
|
243
243
|
export interface DefineOutputGuardrailArgs<
|
|
244
|
-
|
|
244
|
+
TOutput extends AgentOutputType = TextOutput,
|
|
245
245
|
> {
|
|
246
246
|
name: string;
|
|
247
|
-
execute: OutputGuardrailFunction<
|
|
247
|
+
execute: OutputGuardrailFunction<TOutput>;
|
|
248
248
|
}
|
|
249
249
|
|
|
250
250
|
/**
|
|
251
251
|
* Creates an output guardrail definition.
|
|
252
252
|
*/
|
|
253
253
|
export function defineOutputGuardrail<
|
|
254
|
-
|
|
254
|
+
TOutput extends AgentOutputType = TextOutput,
|
|
255
255
|
>({
|
|
256
256
|
name,
|
|
257
257
|
execute,
|
|
258
|
-
}: DefineOutputGuardrailArgs<
|
|
258
|
+
}: DefineOutputGuardrailArgs<TOutput>): OutputGuardrailDefinition<
|
|
259
259
|
OutputGuardrailMetadata,
|
|
260
|
-
|
|
260
|
+
TOutput
|
|
261
261
|
> {
|
|
262
262
|
return {
|
|
263
263
|
type: "output",
|
|
264
264
|
name,
|
|
265
265
|
guardrailFunction: execute,
|
|
266
266
|
async run(
|
|
267
|
-
args: OutputGuardrailFunctionArgs<UnknownContext,
|
|
268
|
-
): Promise<OutputGuardrailResult<OutputGuardrailMetadata,
|
|
267
|
+
args: OutputGuardrailFunctionArgs<UnknownContext, TOutput>,
|
|
268
|
+
): Promise<OutputGuardrailResult<OutputGuardrailMetadata, TOutput>> {
|
|
269
269
|
return {
|
|
270
270
|
guardrail: { type: "output", name },
|
|
271
271
|
agent: args.agent,
|
package/src/kernl/kernl.ts
CHANGED
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
} from "@/memory";
|
|
18
18
|
|
|
19
19
|
import type { ThreadExecuteResult, ThreadStreamEvent } from "@/thread/types";
|
|
20
|
-
import type {
|
|
20
|
+
import type { AgentOutputType } from "@/agent/types";
|
|
21
21
|
|
|
22
22
|
import type { KernlOptions } from "./types";
|
|
23
23
|
|
|
@@ -27,7 +27,7 @@ import type { KernlOptions } from "./types";
|
|
|
27
27
|
* Orchestrates agent execution, including guardrails, tool calls, session persistence, and
|
|
28
28
|
* tracing.
|
|
29
29
|
*/
|
|
30
|
-
export class Kernl extends KernlHooks<UnknownContext,
|
|
30
|
+
export class Kernl extends KernlHooks<UnknownContext, AgentOutputType> {
|
|
31
31
|
private readonly _agents: Map<string, Agent> = new Map();
|
|
32
32
|
private readonly _models: Map<string, LanguageModel> = new Map();
|
|
33
33
|
|
|
@@ -94,9 +94,9 @@ export class Kernl extends KernlHooks<UnknownContext, AgentResponseType> {
|
|
|
94
94
|
/**
|
|
95
95
|
* Spawn a new thread - blocking execution
|
|
96
96
|
*/
|
|
97
|
-
async spawn<TContext,
|
|
98
|
-
thread: Thread<TContext,
|
|
99
|
-
): Promise<ThreadExecuteResult<ResolvedAgentResponse<
|
|
97
|
+
async spawn<TContext, TOutput extends AgentOutputType>(
|
|
98
|
+
thread: Thread<TContext, TOutput>,
|
|
99
|
+
): Promise<ThreadExecuteResult<ResolvedAgentResponse<TOutput>>> {
|
|
100
100
|
this.athreads.set(thread.tid, thread);
|
|
101
101
|
try {
|
|
102
102
|
return await thread.execute();
|
|
@@ -110,9 +110,9 @@ export class Kernl extends KernlHooks<UnknownContext, AgentResponseType> {
|
|
|
110
110
|
*
|
|
111
111
|
* NOTE: just blocks for now
|
|
112
112
|
*/
|
|
113
|
-
async schedule<TContext,
|
|
114
|
-
thread: Thread<TContext,
|
|
115
|
-
): Promise<ThreadExecuteResult<ResolvedAgentResponse<
|
|
113
|
+
async schedule<TContext, TOutput extends AgentOutputType>(
|
|
114
|
+
thread: Thread<TContext, TOutput>,
|
|
115
|
+
): Promise<ThreadExecuteResult<ResolvedAgentResponse<TOutput>>> {
|
|
116
116
|
this.athreads.set(thread.tid, thread);
|
|
117
117
|
try {
|
|
118
118
|
return await thread.execute();
|
|
@@ -126,8 +126,8 @@ export class Kernl extends KernlHooks<UnknownContext, AgentResponseType> {
|
|
|
126
126
|
*
|
|
127
127
|
* Spawn a new thread - streaming execution
|
|
128
128
|
*/
|
|
129
|
-
async *spawnStream<TContext,
|
|
130
|
-
thread: Thread<TContext,
|
|
129
|
+
async *spawnStream<TContext, TOutput extends AgentOutputType>(
|
|
130
|
+
thread: Thread<TContext, TOutput>,
|
|
131
131
|
): AsyncIterable<ThreadStreamEvent> {
|
|
132
132
|
this.athreads.set(thread.tid, thread);
|
|
133
133
|
try {
|
|
@@ -142,8 +142,8 @@ export class Kernl extends KernlHooks<UnknownContext, AgentResponseType> {
|
|
|
142
142
|
*
|
|
143
143
|
* Schedule an existing thread - streaming execution
|
|
144
144
|
*/
|
|
145
|
-
async *scheduleStream<TContext,
|
|
146
|
-
thread: Thread<TContext,
|
|
145
|
+
async *scheduleStream<TContext, TOutput extends AgentOutputType>(
|
|
146
|
+
thread: Thread<TContext, TOutput>,
|
|
147
147
|
): AsyncIterable<ThreadStreamEvent> {
|
|
148
148
|
this.athreads.set(thread.tid, thread);
|
|
149
149
|
try {
|
package/src/lib/error.ts
CHANGED
|
@@ -9,8 +9,8 @@ import { randomID } from "@kernl-sdk/shared/lib";
|
|
|
9
9
|
// import { SerializedThread } from "@/lib/serde/thread";
|
|
10
10
|
type SerializedThread = any;
|
|
11
11
|
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
12
|
+
import { AgentOutputType } from "@/agent/types";
|
|
13
|
+
import { TextOutput } from "@/thread/types";
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* Abstract base class for all `kernl` errors
|
|
@@ -144,7 +144,7 @@ export class InputGuardrailTripwireTriggered extends AgentError {
|
|
|
144
144
|
*/
|
|
145
145
|
export class OutputGuardrailTripwireTriggered<
|
|
146
146
|
TMeta extends OutputGuardrailMetadata,
|
|
147
|
-
TOutputType extends
|
|
147
|
+
TOutputType extends AgentOutputType = TextOutput,
|
|
148
148
|
> extends AgentError {
|
|
149
149
|
result: OutputGuardrailResult<TMeta, TOutputType>;
|
|
150
150
|
constructor(
|