kernl 0.10.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +16 -0
- package/dist/agent/base.d.ts +5 -1
- package/dist/agent/base.d.ts.map +1 -1
- package/dist/agent/base.js +8 -0
- package/dist/agent.d.ts +1 -1
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +15 -2
- package/dist/context.d.ts +2 -0
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +2 -0
- package/dist/kernl/kernl.d.ts +1 -2
- package/dist/kernl/kernl.d.ts.map +1 -1
- package/dist/kernl/kernl.js +61 -1
- package/dist/lifecycle/__tests__/hooks.test.d.ts +2 -0
- package/dist/lifecycle/__tests__/hooks.test.d.ts.map +1 -0
- package/dist/lifecycle/__tests__/hooks.test.js +553 -0
- package/dist/lifecycle.d.ts +224 -107
- package/dist/lifecycle.d.ts.map +1 -1
- package/dist/lifecycle.js +2 -3
- package/dist/thread/__tests__/thread.test.js +2 -2
- package/dist/thread/thread.d.ts +2 -2
- package/dist/thread/thread.d.ts.map +1 -1
- package/dist/thread/thread.js +75 -8
- package/dist/thread/types.d.ts +1 -1
- package/dist/thread/types.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/agent/base.ts +13 -1
- package/src/agent.ts +17 -3
- package/src/context.ts +2 -0
- package/src/kernl/kernl.ts +67 -3
- package/src/lifecycle/__tests__/hooks.test.ts +668 -0
- package/src/lifecycle.ts +295 -119
- package/src/thread/__tests__/thread.test.ts +2 -2
- package/src/thread/thread.ts +88 -10
- package/src/thread/types.ts +1 -1
package/dist/lifecycle.d.ts
CHANGED
|
@@ -1,118 +1,235 @@
|
|
|
1
1
|
import { Emitter } from "@kernl-sdk/shared";
|
|
2
|
-
import {
|
|
3
|
-
import { Context
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
*
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
*
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
2
|
+
import type { LanguageModelUsage, LanguageModelFinishReason, LanguageModelRequestSettings, ToolCallState } from "@kernl-sdk/protocol";
|
|
3
|
+
import type { Context } from "./context.js";
|
|
4
|
+
import type { ThreadState } from "./thread/types.js";
|
|
5
|
+
/**
|
|
6
|
+
* Emitted when a thread starts execution.
|
|
7
|
+
*/
|
|
8
|
+
export interface ThreadStartEvent<TContext = unknown> {
|
|
9
|
+
readonly kind: "thread.start";
|
|
10
|
+
/**
|
|
11
|
+
* The thread ID.
|
|
12
|
+
*/
|
|
13
|
+
threadId: string;
|
|
14
|
+
/**
|
|
15
|
+
* The agent executing this thread.
|
|
16
|
+
*/
|
|
17
|
+
agentId: string;
|
|
18
|
+
/**
|
|
19
|
+
* The namespace of the thread.
|
|
20
|
+
*/
|
|
21
|
+
namespace: string;
|
|
22
|
+
/**
|
|
23
|
+
* The context for this execution.
|
|
24
|
+
*
|
|
25
|
+
* NOTE: Includes `context.agent` reference for tools - may be optimized in future.
|
|
26
|
+
*/
|
|
27
|
+
context: Context<TContext>;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Emitted when a thread stops execution.
|
|
31
|
+
*/
|
|
32
|
+
export interface ThreadStopEvent<TContext = unknown, TOutput = unknown> {
|
|
33
|
+
readonly kind: "thread.stop";
|
|
34
|
+
/**
|
|
35
|
+
* The thread ID.
|
|
36
|
+
*/
|
|
37
|
+
threadId: string;
|
|
38
|
+
/**
|
|
39
|
+
* The agent that executed this thread.
|
|
40
|
+
*/
|
|
41
|
+
agentId: string;
|
|
42
|
+
/**
|
|
43
|
+
* The namespace of the thread.
|
|
44
|
+
*/
|
|
45
|
+
namespace: string;
|
|
46
|
+
/**
|
|
47
|
+
* The context for this execution.
|
|
48
|
+
*
|
|
49
|
+
* NOTE: Includes `context.agent` reference for tools - may be optimized in future.
|
|
50
|
+
*/
|
|
51
|
+
context: Context<TContext>;
|
|
52
|
+
/**
|
|
53
|
+
* Final state of the thread.
|
|
54
|
+
*/
|
|
55
|
+
state: ThreadState;
|
|
56
|
+
/**
|
|
57
|
+
* The outcome of the execution.
|
|
58
|
+
*/
|
|
59
|
+
outcome: "success" | "error" | "cancelled";
|
|
60
|
+
/**
|
|
61
|
+
* The result if outcome is "success".
|
|
62
|
+
*/
|
|
63
|
+
result?: TOutput;
|
|
64
|
+
/**
|
|
65
|
+
* Error message if outcome is "error".
|
|
66
|
+
*/
|
|
67
|
+
error?: string;
|
|
68
|
+
}
|
|
45
69
|
/**
|
|
46
|
-
*
|
|
47
|
-
* of the agent.
|
|
70
|
+
* Emitted when a model call starts.
|
|
48
71
|
*/
|
|
49
|
-
export
|
|
72
|
+
export interface ModelCallStartEvent<TContext = unknown> {
|
|
73
|
+
readonly kind: "model.call.start";
|
|
74
|
+
/**
|
|
75
|
+
* The model provider.
|
|
76
|
+
*/
|
|
77
|
+
provider: string;
|
|
78
|
+
/**
|
|
79
|
+
* The model ID.
|
|
80
|
+
*/
|
|
81
|
+
modelId: string;
|
|
82
|
+
/**
|
|
83
|
+
* Request settings passed to the model.
|
|
84
|
+
*/
|
|
85
|
+
settings: LanguageModelRequestSettings;
|
|
86
|
+
/**
|
|
87
|
+
* Thread ID if called within a thread context.
|
|
88
|
+
*/
|
|
89
|
+
threadId?: string;
|
|
90
|
+
/**
|
|
91
|
+
* Agent ID if called within an agent context.
|
|
92
|
+
*/
|
|
93
|
+
agentId?: string;
|
|
94
|
+
/**
|
|
95
|
+
* Execution context if available.
|
|
96
|
+
*
|
|
97
|
+
* NOTE: Includes `context.agent` reference for tools - may be optimized in future.
|
|
98
|
+
*/
|
|
99
|
+
context?: Context<TContext>;
|
|
50
100
|
}
|
|
51
101
|
/**
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
* Unlike AgentHookEvents (which are emitted by individual agents with implicit context),
|
|
55
|
-
* KernlHookEvents explicitly include the agent reference in all events since it needs to
|
|
56
|
-
* coordinate multiple agents and listeners need to know which agent triggered each event.
|
|
102
|
+
* Emitted when a model call ends.
|
|
57
103
|
*/
|
|
58
|
-
export
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
*
|
|
62
|
-
*/
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
*
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
*
|
|
78
|
-
*/
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*/
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
*
|
|
102
|
-
*/
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
104
|
+
export interface ModelCallEndEvent<TContext = unknown> {
|
|
105
|
+
readonly kind: "model.call.end";
|
|
106
|
+
/**
|
|
107
|
+
* The model provider.
|
|
108
|
+
*/
|
|
109
|
+
provider: string;
|
|
110
|
+
/**
|
|
111
|
+
* The model ID.
|
|
112
|
+
*/
|
|
113
|
+
modelId: string;
|
|
114
|
+
/**
|
|
115
|
+
* Reason the model stopped generating.
|
|
116
|
+
*/
|
|
117
|
+
finishReason: LanguageModelFinishReason;
|
|
118
|
+
/**
|
|
119
|
+
* Token usage for this call.
|
|
120
|
+
*/
|
|
121
|
+
usage?: LanguageModelUsage;
|
|
122
|
+
/**
|
|
123
|
+
* Thread ID if called within a thread context.
|
|
124
|
+
*/
|
|
125
|
+
threadId?: string;
|
|
126
|
+
/**
|
|
127
|
+
* Agent ID if called within an agent context.
|
|
128
|
+
*/
|
|
129
|
+
agentId?: string;
|
|
130
|
+
/**
|
|
131
|
+
* Execution context if available.
|
|
132
|
+
*
|
|
133
|
+
* NOTE: Includes `context.agent` reference for tools - may be optimized in future.
|
|
134
|
+
*/
|
|
135
|
+
context?: Context<TContext>;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Emitted when a tool call starts.
|
|
139
|
+
*/
|
|
140
|
+
export interface ToolCallStartEvent<TContext = unknown> {
|
|
141
|
+
readonly kind: "tool.call.start";
|
|
142
|
+
/**
|
|
143
|
+
* The thread ID.
|
|
144
|
+
*/
|
|
145
|
+
threadId: string;
|
|
146
|
+
/**
|
|
147
|
+
* The agent executing this tool.
|
|
148
|
+
*/
|
|
149
|
+
agentId: string;
|
|
150
|
+
/**
|
|
151
|
+
* The context for this execution.
|
|
152
|
+
*
|
|
153
|
+
* NOTE: Includes `context.agent` reference for tools - may be optimized in future.
|
|
154
|
+
*/
|
|
155
|
+
context: Context<TContext>;
|
|
156
|
+
/**
|
|
157
|
+
* The tool being called.
|
|
158
|
+
*/
|
|
159
|
+
toolId: string;
|
|
160
|
+
/**
|
|
161
|
+
* Unique identifier for this call.
|
|
162
|
+
*/
|
|
163
|
+
callId: string;
|
|
164
|
+
/**
|
|
165
|
+
* Arguments passed to the tool (parsed JSON).
|
|
166
|
+
*/
|
|
167
|
+
args: Record<string, unknown>;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Emitted when a tool call ends.
|
|
171
|
+
*/
|
|
172
|
+
export interface ToolCallEndEvent<TContext = unknown> {
|
|
173
|
+
readonly kind: "tool.call.end";
|
|
174
|
+
/**
|
|
175
|
+
* The thread ID.
|
|
176
|
+
*/
|
|
177
|
+
threadId: string;
|
|
178
|
+
/**
|
|
179
|
+
* The agent that executed this tool.
|
|
180
|
+
*/
|
|
181
|
+
agentId: string;
|
|
182
|
+
/**
|
|
183
|
+
* The context for this execution.
|
|
184
|
+
*
|
|
185
|
+
* NOTE: Includes `context.agent` reference for tools - may be optimized in future.
|
|
186
|
+
*/
|
|
187
|
+
context: Context<TContext>;
|
|
188
|
+
/**
|
|
189
|
+
* The tool that was called.
|
|
190
|
+
*/
|
|
191
|
+
toolId: string;
|
|
192
|
+
/**
|
|
193
|
+
* Unique identifier for this call.
|
|
194
|
+
*/
|
|
195
|
+
callId: string;
|
|
196
|
+
/**
|
|
197
|
+
* Final state of the tool call.
|
|
198
|
+
*/
|
|
199
|
+
state: ToolCallState;
|
|
200
|
+
/**
|
|
201
|
+
* Result if state is "completed".
|
|
202
|
+
*/
|
|
203
|
+
result?: string;
|
|
204
|
+
/**
|
|
205
|
+
* Error message if state is "failed", null if successful.
|
|
206
|
+
*/
|
|
207
|
+
error: string | null;
|
|
208
|
+
}
|
|
209
|
+
export type LifecycleEvent<TContext = unknown, TOutput = unknown> = ThreadStartEvent<TContext> | ThreadStopEvent<TContext, TOutput> | ModelCallStartEvent<TContext> | ModelCallEndEvent<TContext> | ToolCallStartEvent<TContext> | ToolCallEndEvent<TContext>;
|
|
210
|
+
/**
|
|
211
|
+
* Event map for agent-level lifecycle hooks (typed).
|
|
212
|
+
*/
|
|
213
|
+
export type AgentHookEvents<TContext = unknown, TOutput = unknown> = {
|
|
214
|
+
"thread.start": [event: ThreadStartEvent<TContext>];
|
|
215
|
+
"thread.stop": [event: ThreadStopEvent<TContext, TOutput>];
|
|
216
|
+
"model.call.start": [event: ModelCallStartEvent<TContext>];
|
|
217
|
+
"model.call.end": [event: ModelCallEndEvent<TContext>];
|
|
218
|
+
"tool.call.start": [event: ToolCallStartEvent<TContext>];
|
|
219
|
+
"tool.call.end": [event: ToolCallEndEvent<TContext>];
|
|
112
220
|
};
|
|
113
221
|
/**
|
|
114
|
-
* Event
|
|
222
|
+
* Event map for Kernl-level lifecycle hooks (untyped).
|
|
223
|
+
*/
|
|
224
|
+
export type KernlHookEvents = AgentHookEvents<unknown, unknown>;
|
|
225
|
+
/**
|
|
226
|
+
* Event emitter for agent-level lifecycle events.
|
|
227
|
+
*/
|
|
228
|
+
export declare class AgentHooks<TContext = unknown, TOutput = unknown> extends Emitter<AgentHookEvents<TContext, TOutput>> {
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Event emitter for Kernl-level lifecycle events.
|
|
115
232
|
*/
|
|
116
|
-
export declare class KernlHooks
|
|
233
|
+
export declare class KernlHooks extends Emitter<KernlHookEvents> {
|
|
117
234
|
}
|
|
118
235
|
//# sourceMappingURL=lifecycle.d.ts.map
|
package/dist/lifecycle.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lifecycle.d.ts","sourceRoot":"","sources":["../src/lifecycle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAE5C,OAAO,
|
|
1
|
+
{"version":3,"file":"lifecycle.d.ts","sourceRoot":"","sources":["../src/lifecycle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAE5C,OAAO,KAAK,EACV,kBAAkB,EAClB,yBAAyB,EACzB,4BAA4B,EAC5B,aAAa,EACd,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC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AAU,CACrB,QAAQ,GAAG,OAAO,EAClB,OAAO,GAAG,OAAO,CACjB,SAAQ,OAAO,CAAC,eAAe,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;CAAG;AAExD;;GAEG;AACH,qBAAa,UAAW,SAAQ,OAAO,CAAC,eAAe,CAAC;CAAG"}
|
package/dist/lifecycle.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { Emitter } from "@kernl-sdk/shared";
|
|
2
2
|
/**
|
|
3
|
-
* Event emitter
|
|
4
|
-
* of the agent.
|
|
3
|
+
* Event emitter for agent-level lifecycle events.
|
|
5
4
|
*/
|
|
6
5
|
export class AgentHooks extends Emitter {
|
|
7
6
|
}
|
|
8
7
|
/**
|
|
9
|
-
* Event emitter
|
|
8
|
+
* Event emitter for Kernl-level lifecycle events.
|
|
10
9
|
*/
|
|
11
10
|
export class KernlHooks extends Emitter {
|
|
12
11
|
}
|
|
@@ -275,7 +275,7 @@ describe("Thread", () => {
|
|
|
275
275
|
toolId: "simple",
|
|
276
276
|
state: IN_PROGRESS,
|
|
277
277
|
callId: "call_1",
|
|
278
|
-
arguments: "first",
|
|
278
|
+
arguments: JSON.stringify({ value: "first" }),
|
|
279
279
|
},
|
|
280
280
|
],
|
|
281
281
|
finishReason: "stop",
|
|
@@ -301,7 +301,7 @@ describe("Thread", () => {
|
|
|
301
301
|
toolId: "simple",
|
|
302
302
|
state: IN_PROGRESS,
|
|
303
303
|
callId: "call_2",
|
|
304
|
-
arguments: "second",
|
|
304
|
+
arguments: JSON.stringify({ value: "second" }),
|
|
305
305
|
},
|
|
306
306
|
],
|
|
307
307
|
finishReason: "stop",
|
package/dist/thread/thread.d.ts
CHANGED
|
@@ -49,8 +49,8 @@ export declare class Thread<TContext = unknown, TOutput extends AgentOutputType
|
|
|
49
49
|
readonly tid: string;
|
|
50
50
|
readonly namespace: string;
|
|
51
51
|
readonly agent: Agent<TContext, TOutput>;
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
context: Context<TContext>;
|
|
53
|
+
model: LanguageModel;
|
|
54
54
|
readonly parent: Task<TContext> | null;
|
|
55
55
|
readonly createdAt: Date;
|
|
56
56
|
readonly updatedAt: Date;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"thread.d.ts","sourceRoot":"","sources":["../../src/thread/thread.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAKzD,OAAO,EAML,aAAa,
|
|
1
|
+
{"version":3,"file":"thread.d.ts","sourceRoot":"","sources":["../../src/thread/thread.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAKzD,OAAO,EAML,aAAa,EAKd,MAAM,qBAAqB,CAAC;AAG7B,OAAO,KAAK,EAEV,WAAW,EACX,WAAW,EACX,aAAa,EACb,gBAAgB,EAChB,iBAAiB,EACjB,mBAAmB,EAEpB,MAAM,SAAS,CAAC;AACjB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAWrD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,qBAAa,MAAM,CACjB,QAAQ,GAAG,OAAO,EAClB,OAAO,SAAS,eAAe,GAAG,MAAM;IAExC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,KAAK,EAAE,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() {
|
|
145
145
|
for (;;) {
|
|
146
|
-
let err =
|
|
146
|
+
let err = undefined;
|
|
147
147
|
if (this.abort?.signal.aborted) {
|
|
148
148
|
return;
|
|
149
149
|
}
|
|
150
150
|
const events = [];
|
|
151
151
|
for await (const e of this.tick()) {
|
|
152
152
|
if (e.kind === "error") {
|
|
153
|
-
err =
|
|
153
|
+
err = e.error;
|
|
154
154
|
logger.error(e.error); // (TODO): onError callback in options
|
|
155
155
|
}
|
|
156
156
|
// we don't want deltas in the history
|
|
@@ -160,9 +160,9 @@ export class Thread {
|
|
|
160
160
|
}
|
|
161
161
|
yield e;
|
|
162
162
|
}
|
|
163
|
-
// if an error event occurred →
|
|
163
|
+
// if an error event occurred → throw it
|
|
164
164
|
if (err) {
|
|
165
|
-
|
|
165
|
+
throw err;
|
|
166
166
|
}
|
|
167
167
|
// if model returns a message with no action intentions → terminal state
|
|
168
168
|
const intentions = getIntentions(events);
|
|
@@ -205,23 +205,57 @@ export class Thread {
|
|
|
205
205
|
// (TODO): check limits (if this._tick > this.limits.maxTicks)
|
|
206
206
|
// (TODO): run input guardrails on first tick (if this._tick === 1)
|
|
207
207
|
const req = await this.prepareModelRequest(this.history);
|
|
208
|
+
this.agent.emit("model.call.start", {
|
|
209
|
+
kind: "model.call.start",
|
|
210
|
+
provider: this.model.provider,
|
|
211
|
+
modelId: this.model.modelId,
|
|
212
|
+
settings: req.settings ?? {},
|
|
213
|
+
threadId: this.tid,
|
|
214
|
+
agentId: this.agent.id,
|
|
215
|
+
context: this.context,
|
|
216
|
+
});
|
|
217
|
+
let usage;
|
|
218
|
+
let finishReason = "unknown";
|
|
208
219
|
try {
|
|
209
220
|
if (this.model.stream) {
|
|
210
|
-
const
|
|
211
|
-
|
|
212
|
-
|
|
221
|
+
for await (const event of this.model.stream(req)) {
|
|
222
|
+
if (event.kind === "finish") {
|
|
223
|
+
usage = event.usage;
|
|
224
|
+
finishReason = event.finishReason;
|
|
225
|
+
}
|
|
226
|
+
yield event;
|
|
213
227
|
}
|
|
214
228
|
}
|
|
215
229
|
else {
|
|
216
230
|
// fallback: blocking generate, yield events as batch
|
|
217
231
|
const res = await this.model.generate(req);
|
|
232
|
+
usage = res.usage;
|
|
233
|
+
finishReason = res.finishReason;
|
|
218
234
|
for (const event of res.content) {
|
|
219
235
|
yield event;
|
|
220
236
|
}
|
|
221
|
-
// (TODO): this.stats.usage.add(res.usage)
|
|
222
237
|
}
|
|
238
|
+
this.agent.emit("model.call.end", {
|
|
239
|
+
kind: "model.call.end",
|
|
240
|
+
provider: this.model.provider,
|
|
241
|
+
modelId: this.model.modelId,
|
|
242
|
+
finishReason,
|
|
243
|
+
usage,
|
|
244
|
+
threadId: this.tid,
|
|
245
|
+
agentId: this.agent.id,
|
|
246
|
+
context: this.context,
|
|
247
|
+
});
|
|
223
248
|
}
|
|
224
249
|
catch (error) {
|
|
250
|
+
this.agent.emit("model.call.end", {
|
|
251
|
+
kind: "model.call.end",
|
|
252
|
+
provider: this.model.provider,
|
|
253
|
+
modelId: this.model.modelId,
|
|
254
|
+
finishReason: "error",
|
|
255
|
+
threadId: this.tid,
|
|
256
|
+
agentId: this.agent.id,
|
|
257
|
+
context: this.context,
|
|
258
|
+
});
|
|
225
259
|
yield {
|
|
226
260
|
kind: "error",
|
|
227
261
|
error: error instanceof Error ? error : new Error(String(error)),
|
|
@@ -343,6 +377,16 @@ export class Thread {
|
|
|
343
377
|
*/
|
|
344
378
|
async executeTools(calls) {
|
|
345
379
|
return await Promise.all(calls.map(async (call) => {
|
|
380
|
+
const parsedArgs = JSON.parse(call.arguments || "{}");
|
|
381
|
+
this.agent.emit("tool.call.start", {
|
|
382
|
+
kind: "tool.call.start",
|
|
383
|
+
threadId: this.tid,
|
|
384
|
+
agentId: this.agent.id,
|
|
385
|
+
context: this.context,
|
|
386
|
+
toolId: call.toolId,
|
|
387
|
+
callId: call.callId,
|
|
388
|
+
args: parsedArgs,
|
|
389
|
+
});
|
|
346
390
|
try {
|
|
347
391
|
const tool = this.agent.tool(call.toolId);
|
|
348
392
|
if (!tool) {
|
|
@@ -356,6 +400,19 @@ export class Thread {
|
|
|
356
400
|
ctx.agent = this.agent;
|
|
357
401
|
ctx.approve(call.callId); // mark this call as approved
|
|
358
402
|
const res = await tool.invoke(ctx, call.arguments, call.callId);
|
|
403
|
+
this.agent.emit("tool.call.end", {
|
|
404
|
+
kind: "tool.call.end",
|
|
405
|
+
threadId: this.tid,
|
|
406
|
+
agentId: this.agent.id,
|
|
407
|
+
context: this.context,
|
|
408
|
+
toolId: call.toolId,
|
|
409
|
+
callId: call.callId,
|
|
410
|
+
state: res.state,
|
|
411
|
+
result: typeof res.result === "string"
|
|
412
|
+
? res.result
|
|
413
|
+
: JSON.stringify(res.result),
|
|
414
|
+
error: res.error,
|
|
415
|
+
});
|
|
359
416
|
return {
|
|
360
417
|
kind: "tool-result",
|
|
361
418
|
callId: call.callId,
|
|
@@ -366,6 +423,16 @@ export class Thread {
|
|
|
366
423
|
};
|
|
367
424
|
}
|
|
368
425
|
catch (error) {
|
|
426
|
+
this.agent.emit("tool.call.end", {
|
|
427
|
+
kind: "tool.call.end",
|
|
428
|
+
threadId: this.tid,
|
|
429
|
+
agentId: this.agent.id,
|
|
430
|
+
context: this.context,
|
|
431
|
+
toolId: call.toolId,
|
|
432
|
+
callId: call.callId,
|
|
433
|
+
state: FAILED,
|
|
434
|
+
error: error instanceof Error ? error.message : String(error),
|
|
435
|
+
});
|
|
369
436
|
return {
|
|
370
437
|
kind: "tool-result",
|
|
371
438
|
callId: call.callId,
|
package/dist/thread/types.d.ts
CHANGED
|
@@ -124,7 +124,7 @@ export interface ThreadOptions<TContext = unknown, TOutput extends AgentOutputTy
|
|
|
124
124
|
* Options passed to agent.execute() and agent.stream().
|
|
125
125
|
*/
|
|
126
126
|
export interface ThreadExecuteOptions<TContext> {
|
|
127
|
-
context?:
|
|
127
|
+
context?: TContext;
|
|
128
128
|
model?: LanguageModel;
|
|
129
129
|
task?: Task<TContext>;
|
|
130
130
|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CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB,SAAS,CAAC,EAAE,IAAI,CAAC;IACjB,SAAS,CAAC,EAAE,IAAI,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IAC1C;;;;OAIG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB,CAAC,QAAQ;IAC5C,OAAO,CAAC,EAAE,QAAQ,CAAC;IACnB,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,IAAI,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,WAAW,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,SAAS,EAAE,QAAQ,EAAE,CAAC;CAEvB;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC;;OAEG;IACH,OAAO,EAAE,gBAAgB,EAAE,CAAC;IAC5B;;OAEG;IACH,gBAAgB,EAAE,QAAQ,EAAE,CAAC;CAC9B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kernl",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"description": "A modern AI agent framework",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"kernl",
|
|
@@ -34,8 +34,8 @@
|
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@modelcontextprotocol/sdk": "^1.20.2",
|
|
36
36
|
"yaml": "^2.8.2",
|
|
37
|
-
"@kernl-sdk/protocol": "0.4.
|
|
38
|
-
"@kernl-sdk/retrieval": "0.1.
|
|
37
|
+
"@kernl-sdk/protocol": "0.4.1",
|
|
38
|
+
"@kernl-sdk/retrieval": "0.1.7",
|
|
39
39
|
"@kernl-sdk/shared": "^0.3.1"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"typescript": "5.9.2",
|
|
49
49
|
"vitest": "^4.0.8",
|
|
50
50
|
"zod": "^4.1.8",
|
|
51
|
-
"@kernl-sdk/ai": "0.3.
|
|
51
|
+
"@kernl-sdk/ai": "0.3.4"
|
|
52
52
|
},
|
|
53
53
|
"scripts": {
|
|
54
54
|
"clean": "rm -rf dist",
|
package/src/agent/base.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type { Context, UnknownContext } from "@/context";
|
|
|
4
4
|
import type { Tool, BaseToolkit } from "@/tool";
|
|
5
5
|
import { memory } from "@/tool";
|
|
6
6
|
import { MisconfiguredError } from "@/lib/error";
|
|
7
|
-
import { AgentHooks } from "@/lifecycle";
|
|
7
|
+
import { AgentHooks, type AgentHookEvents } from "@/lifecycle";
|
|
8
8
|
import type { Kernl } from "@/kernl";
|
|
9
9
|
import type {
|
|
10
10
|
AgentMemoryCreate,
|
|
@@ -101,6 +101,18 @@ export abstract class BaseAgent<
|
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
+
/**
|
|
105
|
+
* Emit a lifecycle event to agent and kernl listeners.
|
|
106
|
+
*/
|
|
107
|
+
emit<K extends keyof AgentHookEvents<TContext, TOutput>>(
|
|
108
|
+
event: K,
|
|
109
|
+
...args: AgentHookEvents<TContext, TOutput>[K]
|
|
110
|
+
): boolean {
|
|
111
|
+
const result = super.emit(event, ...args);
|
|
112
|
+
this.kernl?.emit(event, ...(args as any));
|
|
113
|
+
return result;
|
|
114
|
+
}
|
|
115
|
+
|
|
104
116
|
/**
|
|
105
117
|
* Get a specific tool by ID from systools and toolkits.
|
|
106
118
|
*/
|