@vinhnt-sdk/core 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +149 -87
- package/dist/index.d.ts +5 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/kernel/handoff.d.ts +136 -0
- package/dist/kernel/handoff.d.ts.map +1 -0
- package/dist/kernel/handoff.js +144 -0
- package/dist/kernel/handoff.js.map +1 -0
- package/dist/kernel/kernel-types.d.ts +112 -13
- package/dist/kernel/kernel-types.d.ts.map +1 -1
- package/dist/kernel/kernel-types.js.map +1 -1
- package/dist/kernel/kernel.d.ts +13 -0
- package/dist/kernel/kernel.d.ts.map +1 -1
- package/dist/kernel/kernel.js +82 -11
- package/dist/kernel/kernel.js.map +1 -1
- package/dist/kernel/run-context.d.ts +130 -22
- package/dist/kernel/run-context.d.ts.map +1 -1
- package/dist/kernel/run-context.js +169 -11
- package/dist/kernel/run-context.js.map +1 -1
- package/dist/kernel/run-loop.d.ts +39 -1
- package/dist/kernel/run-loop.d.ts.map +1 -1
- package/dist/kernel/run-loop.js +151 -6
- package/dist/kernel/run-loop.js.map +1 -1
- package/dist/tool/bridge.js +1 -1
- package/dist/tool/bridge.js.map +1 -1
- package/dist/tool/runtime.d.ts +18 -1
- package/dist/tool/runtime.d.ts.map +1 -1
- package/dist/tool/runtime.js +62 -4
- package/dist/tool/runtime.js.map +1 -1
- package/package.json +7 -7
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Handoff — signal that transfers control to another agent.
|
|
3
|
+
*
|
|
4
|
+
* When a tool returns a `Handoff`, the run loop detects it and swaps the
|
|
5
|
+
* active agent. The new agent takes over the conversation from the next step.
|
|
6
|
+
*
|
|
7
|
+
* Follows the OpenAI Agents SDK pattern: handoff is a special tool return
|
|
8
|
+
* value that the runner intercepts, not a regular tool output.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { handoff, type Handoff } from '@vinhnt-sdk/core';
|
|
13
|
+
*
|
|
14
|
+
* // Define a handoff tool
|
|
15
|
+
* const transferToBilling = handoff({
|
|
16
|
+
* agentId: 'billing-agent',
|
|
17
|
+
* toolName: 'transfer_to_billing',
|
|
18
|
+
* toolDescription: 'Transfer to billing specialist for payment issues',
|
|
19
|
+
* });
|
|
20
|
+
*
|
|
21
|
+
* // Register on agent
|
|
22
|
+
* const triageAgent = createAgent({
|
|
23
|
+
* id: 'triage',
|
|
24
|
+
* tools: [transferToBilling, ...otherTools],
|
|
25
|
+
* });
|
|
26
|
+
*
|
|
27
|
+
* // When LLM calls transfer_to_billing, run loop detects Handoff
|
|
28
|
+
* // and swaps active agent to billing-agent.
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
import { z } from "zod";
|
|
32
|
+
import { defineTool } from "@vinhnt-sdk/tools";
|
|
33
|
+
/**
|
|
34
|
+
* Symbol used to identify handoff results in tool output.
|
|
35
|
+
* The run loop checks for this symbol to detect agent transfers.
|
|
36
|
+
*/
|
|
37
|
+
export const HANDOFF_SYMBOL = Symbol.for("@vinhnt-sdk/core/handoff");
|
|
38
|
+
/**
|
|
39
|
+
* Check if a value is a Handoff.
|
|
40
|
+
*/
|
|
41
|
+
export function isHandoff(value) {
|
|
42
|
+
return (typeof value === "object" &&
|
|
43
|
+
value !== null &&
|
|
44
|
+
value.__handoff === true);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Create a Handoff result.
|
|
48
|
+
*/
|
|
49
|
+
export function createHandoff(options) {
|
|
50
|
+
return {
|
|
51
|
+
[HANDOFF_SYMBOL]: true,
|
|
52
|
+
__handoff: true,
|
|
53
|
+
targetAgentId: options.targetAgentId,
|
|
54
|
+
reason: options.reason,
|
|
55
|
+
summary: options.summary,
|
|
56
|
+
context: options.context,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Create a handoff tool — when LLM calls it, control transfers to target agent.
|
|
61
|
+
*
|
|
62
|
+
* Unlike `agentAsTool` (parent keeps control), handoff gives full control
|
|
63
|
+
* to the target agent. The original agent pauses until the target completes
|
|
64
|
+
* or transfers back.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```ts
|
|
68
|
+
* const handoffTool = createHandoffTool({
|
|
69
|
+
* agentId: 'billing' as AgentId,
|
|
70
|
+
* toolDescription: 'Transfer to billing specialist for payment issues',
|
|
71
|
+
* onHandoff: (reason) => console.log('Transferring:', reason),
|
|
72
|
+
* });
|
|
73
|
+
*
|
|
74
|
+
* // Register on triage agent
|
|
75
|
+
* triageAgent.tools.push(handoffTool);
|
|
76
|
+
*
|
|
77
|
+
* // When LLM calls transfer_to_billing:
|
|
78
|
+
* // 1. Run loop executes the tool
|
|
79
|
+
* // 2. Tool returns Handoff object
|
|
80
|
+
* // 3. Run loop detects Handoff
|
|
81
|
+
* // 4. Active agent swaps to billing-agent
|
|
82
|
+
* // 5. Billing agent continues the conversation
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
export function createHandoffTool(options) {
|
|
86
|
+
const { agentId, toolName = `transfer_to_${agentId}`, toolDescription, onHandoff, } = options;
|
|
87
|
+
return defineTool({
|
|
88
|
+
name: toolName,
|
|
89
|
+
description: toolDescription,
|
|
90
|
+
risk: "write",
|
|
91
|
+
input: z.object({
|
|
92
|
+
reason: z.string().describe("Reason for the handoff — why this agent is better suited"),
|
|
93
|
+
summary: z.string().optional().describe("Summary of conversation so far for context transfer"),
|
|
94
|
+
}),
|
|
95
|
+
execute: async (input, ctx) => {
|
|
96
|
+
if (onHandoff) {
|
|
97
|
+
await onHandoff(input.reason);
|
|
98
|
+
}
|
|
99
|
+
// Return a Handoff object — run loop will intercept this
|
|
100
|
+
return createHandoff({
|
|
101
|
+
targetAgentId: agentId,
|
|
102
|
+
reason: input.reason,
|
|
103
|
+
summary: input.summary,
|
|
104
|
+
});
|
|
105
|
+
},
|
|
106
|
+
}).toDefinition();
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Track handoff history for a run (cycle detection, debugging).
|
|
110
|
+
*/
|
|
111
|
+
export class HandoffTracker {
|
|
112
|
+
history = [];
|
|
113
|
+
maxDepth;
|
|
114
|
+
constructor(maxDepth = 10) {
|
|
115
|
+
this.maxDepth = maxDepth;
|
|
116
|
+
}
|
|
117
|
+
/** Record a handoff. Returns false if cycle detected or max depth exceeded. */
|
|
118
|
+
record(record) {
|
|
119
|
+
// Cycle detection: check if target agent is already in the chain
|
|
120
|
+
const recentAgents = this.history.slice(-this.maxDepth).map((r) => r.toAgentId);
|
|
121
|
+
if (recentAgents.includes(record.toAgentId)) {
|
|
122
|
+
return false; // Cycle detected
|
|
123
|
+
}
|
|
124
|
+
// Depth check
|
|
125
|
+
if (this.history.length >= this.maxDepth) {
|
|
126
|
+
return false; // Max depth exceeded
|
|
127
|
+
}
|
|
128
|
+
this.history.push(record);
|
|
129
|
+
return true;
|
|
130
|
+
}
|
|
131
|
+
/** Get the full handoff history. */
|
|
132
|
+
getHistory() {
|
|
133
|
+
return this.history;
|
|
134
|
+
}
|
|
135
|
+
/** Get the chain of agent IDs in this handoff chain. */
|
|
136
|
+
getAgentChain() {
|
|
137
|
+
return this.history.map((r) => r.toAgentId);
|
|
138
|
+
}
|
|
139
|
+
/** Check if an agent has already been visited (cycle detection). */
|
|
140
|
+
hasVisited(agentId) {
|
|
141
|
+
return this.history.some((r) => r.toAgentId === agentId);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
//# sourceMappingURL=handoff.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handoff.js","sourceRoot":"","sources":["../../src/kernel/handoff.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAGH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,E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E;IACpE,UAAU,CAAC,OAAgB;QACzB,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,KAAK,OAAO,CAAC,CAAC;IAC3D,CAAC;CACF"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { RunId, AgentEvent } from "@vinhnt-sdk/schema";
|
|
1
|
+
import type { RunId, AgentEvent, ToolChoice, ResponseFormat } from "@vinhnt-sdk/schema";
|
|
2
2
|
import type { ModelProvider, ModelRegistry } from "../model.js";
|
|
3
3
|
import type { SessionRuntimeState } from "@vinhnt-sdk/session";
|
|
4
4
|
import type { RunEventStore, SessionStore } from "@vinhnt-sdk/session";
|
|
@@ -10,6 +10,7 @@ import type { ContextRegistry } from "../system-context/types.js";
|
|
|
10
10
|
import type { ApprovalStore } from "@vinhnt-sdk/permission";
|
|
11
11
|
import type { EventBus } from "@vinhnt-sdk/event";
|
|
12
12
|
import type { CircuitBreaker, CircuitBreakerOptions, TerminationPolicy } from "@vinhnt-sdk/step-executor";
|
|
13
|
+
import type { z } from "zod";
|
|
13
14
|
/** Sandbox configuration for shell command execution. */
|
|
14
15
|
export interface KernelSandboxConfig {
|
|
15
16
|
/** Sandbox mode: "host" (default), "process", or "container". */
|
|
@@ -50,6 +51,42 @@ export interface HookConfig {
|
|
|
50
51
|
/** Custom hook handlers keyed by hook name. */
|
|
51
52
|
readonly hooks?: Record<string, unknown>;
|
|
52
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* Model settings — controls sampling, tool behavior, and output format.
|
|
56
|
+
*
|
|
57
|
+
* Grouped into a single object to avoid namespace pollution at the kernel config level.
|
|
58
|
+
* Follows the industry-standard nested pattern (OpenAI Agents SDK, Mastra, Google ADK).
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```ts
|
|
62
|
+
* const kernel = new AgentKernel({
|
|
63
|
+
* model: openaiProvider,
|
|
64
|
+
* store: eventStore,
|
|
65
|
+
* modelSettings: {
|
|
66
|
+
* temperature: 0.7,
|
|
67
|
+
* topP: 0.9,
|
|
68
|
+
* toolChoice: 'auto',
|
|
69
|
+
* parallelToolCalls: true,
|
|
70
|
+
* },
|
|
71
|
+
* });
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
export interface ModelSettings {
|
|
75
|
+
/** Sampling temperature (0-2). Higher = more random, lower = more deterministic. */
|
|
76
|
+
readonly temperature?: number;
|
|
77
|
+
/** Nucleus sampling threshold (0-1). Alternative to temperature. */
|
|
78
|
+
readonly topP?: number;
|
|
79
|
+
/** Penalizes tokens based on frequency in output (-2 to 2). */
|
|
80
|
+
readonly frequencyPenalty?: number;
|
|
81
|
+
/** Penalizes tokens based on presence in output (-2 to 2). */
|
|
82
|
+
readonly presencePenalty?: number;
|
|
83
|
+
/** Controls tool calling behavior. 'auto' = model decides, 'required' = must call, 'none' = no tools. */
|
|
84
|
+
readonly toolChoice?: ToolChoice;
|
|
85
|
+
/** Allow the model to call multiple tools in parallel. Default: true. */
|
|
86
|
+
readonly parallelToolCalls?: boolean;
|
|
87
|
+
/** Response format constraint (e.g., JSON mode). */
|
|
88
|
+
readonly responseFormat?: ResponseFormat;
|
|
89
|
+
}
|
|
53
90
|
/**
|
|
54
91
|
* Configuration for AgentKernel — the core agent orchestration engine.
|
|
55
92
|
*
|
|
@@ -72,7 +109,7 @@ export interface AgentKernelConfig {
|
|
|
72
109
|
readonly tools?: readonly ToolDefinition[];
|
|
73
110
|
/** ToolProviderRegistry — single source of truth for all tools. */
|
|
74
111
|
readonly toolProviderRegistry?: ToolProviderRegistry;
|
|
75
|
-
/** Maximum number of steps (LLM calls) per run. Default:
|
|
112
|
+
/** Maximum number of steps (LLM calls) per run. Default: 25. */
|
|
76
113
|
readonly maxSteps?: number;
|
|
77
114
|
/** Maximum tool calls per step. Default: 10. */
|
|
78
115
|
readonly maxToolCallsPerStep?: number;
|
|
@@ -134,6 +171,36 @@ export interface AgentKernelConfig {
|
|
|
134
171
|
readonly noStore?: boolean;
|
|
135
172
|
/** Termination policy for advanced stop conditions. */
|
|
136
173
|
readonly termination?: TerminationPolicy;
|
|
174
|
+
/** Model settings — temperature, topP, toolChoice, etc. */
|
|
175
|
+
readonly modelSettings?: ModelSettings;
|
|
176
|
+
/**
|
|
177
|
+
* Structured output type — controls what the agent returns.
|
|
178
|
+
*
|
|
179
|
+
* - `'text'` (default): Returns plain text string.
|
|
180
|
+
* - A Zod object schema: Returns validated, typed output.
|
|
181
|
+
*
|
|
182
|
+
* When a Zod schema is provided, the kernel:
|
|
183
|
+
* 1. Converts it to JSON Schema and sends via `response_format`
|
|
184
|
+
* 2. Validates the model's JSON response against the schema
|
|
185
|
+
* 3. Returns the typed output (or throws on validation failure)
|
|
186
|
+
*
|
|
187
|
+
* @example
|
|
188
|
+
* ```ts
|
|
189
|
+
* const kernel = new AgentKernel({
|
|
190
|
+
* model: provider,
|
|
191
|
+
* store: eventStore,
|
|
192
|
+
* outputType: z.object({
|
|
193
|
+
* name: z.string(),
|
|
194
|
+
* date: z.string(),
|
|
195
|
+
* participants: z.array(z.string()),
|
|
196
|
+
* }),
|
|
197
|
+
* });
|
|
198
|
+
*
|
|
199
|
+
* const result = await kernel.run('Extract event from "Meeting with Alice on March 5"');
|
|
200
|
+
* // result.output is typed as { name: string; date: string; participants: string[] }
|
|
201
|
+
* ```
|
|
202
|
+
*/
|
|
203
|
+
readonly outputType?: 'text' | z.ZodTypeAny;
|
|
137
204
|
/** Sandbox configuration for shell execution. */
|
|
138
205
|
readonly sandbox?: KernelSandboxConfig;
|
|
139
206
|
/** Permission configuration for tool execution. */
|
|
@@ -142,6 +209,10 @@ export interface AgentKernelConfig {
|
|
|
142
209
|
readonly modelRouting?: ModelRoutingConfig;
|
|
143
210
|
/** Hook configuration for plugin system. */
|
|
144
211
|
readonly hooks?: HookConfig;
|
|
212
|
+
/** Input guardrails — run before model calls. */
|
|
213
|
+
readonly inputGuardrails?: readonly import("@vinhnt-sdk/guardrails").Guardrail[];
|
|
214
|
+
/** Output guardrails — run after model responses. */
|
|
215
|
+
readonly outputGuardrails?: readonly import("@vinhnt-sdk/guardrails").Guardrail[];
|
|
145
216
|
/** Enterprise managed configuration. */
|
|
146
217
|
readonly managedConfig?: Record<string, unknown>;
|
|
147
218
|
/** Logger for kernel events. */
|
|
@@ -203,18 +274,13 @@ export interface AgentRunHandle {
|
|
|
203
274
|
onEvent(handler: (event: AgentEvent) => void): () => void;
|
|
204
275
|
}
|
|
205
276
|
/**
|
|
206
|
-
*
|
|
277
|
+
* Usage metrics for a completed agent run.
|
|
278
|
+
*
|
|
279
|
+
* Follows the industry-standard nested usage pattern (OpenAI, Vercel AI SDK, Mastra, LangChain).
|
|
280
|
+
* All token/cost metrics are grouped here instead of being flat on AgentRunResult.
|
|
207
281
|
*/
|
|
208
|
-
export interface
|
|
209
|
-
/**
|
|
210
|
-
readonly runId: RunId;
|
|
211
|
-
/** Final status. */
|
|
212
|
-
readonly status: "succeeded" | "failed" | "cancelled";
|
|
213
|
-
/** Output text if successful. */
|
|
214
|
-
readonly output?: string;
|
|
215
|
-
/** Error message if failed. */
|
|
216
|
-
readonly error?: string;
|
|
217
|
-
/** Total number of steps executed. */
|
|
282
|
+
export interface RunUsage {
|
|
283
|
+
/** Total number of steps (LLM calls) executed. */
|
|
218
284
|
readonly totalSteps: number;
|
|
219
285
|
/** Total duration in milliseconds. */
|
|
220
286
|
readonly durationMs?: number;
|
|
@@ -222,10 +288,43 @@ export interface AgentRunResult {
|
|
|
222
288
|
readonly inputTokens?: number;
|
|
223
289
|
/** Output tokens used. */
|
|
224
290
|
readonly outputTokens?: number;
|
|
291
|
+
/** Reasoning/thinking tokens used. */
|
|
292
|
+
readonly reasoningTokens?: number;
|
|
293
|
+
/** Cache read tokens (prompt caching). */
|
|
294
|
+
readonly cacheReadTokens?: number;
|
|
295
|
+
/** Cache write tokens (prompt caching). */
|
|
296
|
+
readonly cacheWriteTokens?: number;
|
|
297
|
+
/** Total tokens (input + output + reasoning). */
|
|
298
|
+
readonly totalTokens?: number;
|
|
225
299
|
/** Total cost in USD. */
|
|
226
300
|
readonly cost?: number;
|
|
227
301
|
/** Number of tool calls executed. */
|
|
228
302
|
readonly toolCallsCount?: number;
|
|
303
|
+
/** Model used for this run. */
|
|
304
|
+
readonly model?: string;
|
|
305
|
+
/** Provider used for this run. */
|
|
306
|
+
readonly provider?: string;
|
|
307
|
+
/** Stop reason from the LLM. */
|
|
308
|
+
readonly stopReason?: string;
|
|
309
|
+
/** Provider-specific raw usage data. */
|
|
310
|
+
readonly raw?: Record<string, unknown>;
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Result of a completed agent run.
|
|
314
|
+
*/
|
|
315
|
+
export interface AgentRunResult {
|
|
316
|
+
/** Run identifier. */
|
|
317
|
+
readonly runId: RunId;
|
|
318
|
+
/** Final status. */
|
|
319
|
+
readonly status: "succeeded" | "failed" | "cancelled";
|
|
320
|
+
/** Output text if successful. */
|
|
321
|
+
readonly output?: string;
|
|
322
|
+
/** Validated structured output (when outputType is Zod schema). */
|
|
323
|
+
readonly structuredOutput?: unknown;
|
|
324
|
+
/** Error message if failed. */
|
|
325
|
+
readonly error?: string;
|
|
326
|
+
/** Usage metrics (tokens, cost, duration). */
|
|
327
|
+
readonly usage?: RunUsage;
|
|
229
328
|
}
|
|
230
329
|
/**
|
|
231
330
|
* Normalize a legacy flat config object into the new nested structure.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kernel-types.d.ts","sourceRoot":"","sources":["../../src/kernel/kernel-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"kernel-types.d.ts","sourceRoot":"","sources":["../../src/kernel/kernel-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,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,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,kCAAkC;IAClC,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,gCAAgC;IAChC,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,wCAAwC;IACxC,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACxC;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,sBAAsB;IACtB,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;IACtB,oBAAoB;IACpB,QAAQ,CAAC,MAAM,EAAE,WAAW,GAAG,QAAQ,GAAG,WAAW,CAAC;IACtD,iCAAiC;IACjC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,mEAAmE;IACnE,QAAQ,CAAC,gBAAgB,CAAC,EAAE,OAAO,CAAC;IACpC,+BAA+B;IAC/B,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,8CAA8C;IAC9C,QAAQ,CAAC,KAAK,CAAC,EAAE,QAAQ,CAAC;CAC3B;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,iBAAiB,CAoDlF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kernel-types.js","sourceRoot":"","sources":["../../src/kernel/kernel-types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"kernel-types.js","sourceRoot":"","sources":["../../src/kernel/kernel-types.ts"],"names":[],"mappings":"AAuVA;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,eAAe,CAAC,MAA+B;IAC7D,MAAM,UAAU,GAA4B,EAAE,GAAG,MAAM,EAAE,CAAC;IAE1D,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC;QACxB,UAAU,CAAC,OAAO,GAA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AAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;QACtB,UAAU,CAAC,KAAK,GAAG;YACjB,KAAK,EAAE,UAAU,CAAC,WAAW;SAC9B,CAAC;QACF,OAAO,UAAU,CAAC,WAAW,CAAC;IAChC,CAAC;IAED,OAAO,UAA0C,CAAC;AACpD,CAAC"}
|
package/dist/kernel/kernel.d.ts
CHANGED
|
@@ -7,6 +7,16 @@ import type { SubAgentParams } from "../agent/agent-factory.js";
|
|
|
7
7
|
import type { DomainManifest } from "@vinhnt-sdk/tools";
|
|
8
8
|
/** Default thinking prompt for reasoning steps. Exported for user override. */
|
|
9
9
|
export declare const DEFAULT_THINKING_PROMPT = "Analyze the user's request and the conversation context. Think step by step about what needs to be done. Output your reasoning.";
|
|
10
|
+
/** Default maximum tokens per LLM response. */
|
|
11
|
+
export declare const DEFAULT_MAX_TOKENS = 4096;
|
|
12
|
+
/** Default per-step timeout in ms. */
|
|
13
|
+
export declare const DEFAULT_STEP_TIMEOUT = 120000;
|
|
14
|
+
/** Default maximum self-correction attempts per step. */
|
|
15
|
+
export declare const DEFAULT_MAX_SELF_CORRECT_ATTEMPTS = 3;
|
|
16
|
+
/** Default maximum sub-agent nesting depth. */
|
|
17
|
+
export declare const DEFAULT_MAX_SUB_AGENT_DEPTH = 3;
|
|
18
|
+
/** Default compaction threshold ratio (0-1). */
|
|
19
|
+
export declare const DEFAULT_COMPACTION_THRESHOLD = 0.75;
|
|
10
20
|
import type { RunState } from "@vinhnt-sdk/step-executor";
|
|
11
21
|
import { PermissionGate } from "@vinhnt-sdk/step-executor";
|
|
12
22
|
import { ModelCaller } from "@vinhnt-sdk/llm";
|
|
@@ -61,6 +71,9 @@ export declare class AgentKernel {
|
|
|
61
71
|
private compactionThreshold;
|
|
62
72
|
private readonly termination;
|
|
63
73
|
private circuitBreaker;
|
|
74
|
+
private readonly inputGuardrails;
|
|
75
|
+
private readonly outputGuardrails;
|
|
76
|
+
private readonly outputType;
|
|
64
77
|
private readonly sessionDeps;
|
|
65
78
|
private readonly subAgentDeps;
|
|
66
79
|
private readonly runSessionStates;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kernel.d.ts","sourceRoot":"","sources":["../../src/kernel/kernel.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,aAAa,EAAc,MAAM,oBAAoB,CAAC;AAErI,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAItD,OAAO,KAAK,EAAE,aAAa,EAAgB,MAAM,qBAAqB,CAAC;AACvE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,KAAK,EAAE,cAAc,EAAsC,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"kernel.d.ts","sourceRoot":"","sources":["../../src/kernel/kernel.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,aAAa,EAAc,MAAM,oBAAoB,CAAC;AAErI,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAItD,OAAO,KAAK,EAAE,aAAa,EAAgB,MAAM,qBAAqB,CAAC;AACvE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,KAAK,EAAE,cAAc,EAAsC,MAAM,mBAAmB,CAAC;AAO5F,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAOxD,+EAA+E;AAC/E,eAAO,MAAM,uBAAuB,oIAAoI,CAAC;AAEzK,+CAA+C;AAC/C,eAAO,MAAM,kBAAkB,OAAO,CAAC;AACvC,sCAAsC;AACtC,eAAO,MAAM,oBAAoB,SAAU,CAAC;AAC5C,y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iBAAiB,IAAI,cAAc;IAInC,2EAA2E;IAC3E,WAAW,CAAC,KAAK,EAAE,KAAK,GAAG,QAAQ,GAAG,SAAS;IAI/C,wEAAwE;IACxE,gBAAgB,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,KAAK,IAAI,GAAG,MAAM,IAAI;IAI/E,2EAA2E;IAC3E,SAAS,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI;IAK3C,kGAAkG;IAClG,OAAO,CAAC,iBAAiB;IAWzB,yFAAyF;IACzF,OAAO,CAAC,mBAAmB;YAgBb,cAAc;IAU5B;;;OAGG;YACW,oBAAoB;IAyBlC,uFAAuF;YACzE,kBAAkB;IAiBhC,4CAA4C;IAC5C,gBAAgB,IAAI,IAAI;IAIxB,2DAA2D;IAC3D,yBAAyB,CAAC,QAAQ,EAAE,iBAAiB,GAAG,IAAI;IAI5D,uCAAuC;IACvC,2BAA2B,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI;IAI7C,+DAA+D;IACzD,QAAQ,IAAI,OAAO,CAAC;QAAE,OAAO,EAAE,MAAM,EAAE,CAAC;QAAC,MAAM,EAAE;YAAE,EAAE,EAAE,MAAM,CAAC;YAAC,KAAK,EAAE,OAAO,CAAA;SAAE,EAAE,CAAA;KAAE,CAAC;YAK5E,OAAO;IAgIrB,OAAO,CAAC,aAAa;IAIrB,OAAO,CAAC,QAAQ;CAIjB"}
|
package/dist/kernel/kernel.js
CHANGED
|
@@ -1,11 +1,22 @@
|
|
|
1
1
|
import { ValidationError, AgentNotFoundError, ConfigurationError } from "@vinhnt-sdk/schema";
|
|
2
2
|
import { restoreRunFromStore, findActiveSessionIds } from "@vinhnt-sdk/session";
|
|
3
|
+
import { zodSchemaToNestedJsonSchema } from "@vinhnt-sdk/tools";
|
|
3
4
|
import { createRedactingLogger } from "@vinhnt-sdk/guard";
|
|
4
5
|
import { wildcardMatch } from "@vinhnt-sdk/schema";
|
|
5
6
|
import { getBehaviourProfile } from "../agent/behaviour-profiles.js";
|
|
6
7
|
import { DEFAULT_MAX_STEPS, DEFAULT_MAX_TOOL_CALLS_PER_STEP, DOOM_LOOP_THRESHOLD } from "@vinhnt-sdk/step-executor";
|
|
7
8
|
/** Default thinking prompt for reasoning steps. Exported for user override. */
|
|
8
9
|
export const DEFAULT_THINKING_PROMPT = "Analyze the user's request and the conversation context. Think step by step about what needs to be done. Output your reasoning.";
|
|
10
|
+
/** Default maximum tokens per LLM response. */
|
|
11
|
+
export const DEFAULT_MAX_TOKENS = 4096;
|
|
12
|
+
/** Default per-step timeout in ms. */
|
|
13
|
+
export const DEFAULT_STEP_TIMEOUT = 120_000;
|
|
14
|
+
/** Default maximum self-correction attempts per step. */
|
|
15
|
+
export const DEFAULT_MAX_SELF_CORRECT_ATTEMPTS = 3;
|
|
16
|
+
/** Default maximum sub-agent nesting depth. */
|
|
17
|
+
export const DEFAULT_MAX_SUB_AGENT_DEPTH = 3;
|
|
18
|
+
/** Default compaction threshold ratio (0-1). */
|
|
19
|
+
export const DEFAULT_COMPACTION_THRESHOLD = 0.75;
|
|
9
20
|
import { RunStateMachine } from "@vinhnt-sdk/step-executor";
|
|
10
21
|
import { PermissionGate } from "@vinhnt-sdk/step-executor";
|
|
11
22
|
import { ModelCaller } from "@vinhnt-sdk/llm";
|
|
@@ -63,6 +74,9 @@ export class AgentKernel {
|
|
|
63
74
|
compactionThreshold;
|
|
64
75
|
termination;
|
|
65
76
|
circuitBreaker;
|
|
77
|
+
inputGuardrails;
|
|
78
|
+
outputGuardrails;
|
|
79
|
+
outputType;
|
|
66
80
|
sessionDeps;
|
|
67
81
|
subAgentDeps;
|
|
68
82
|
runSessionStates = new Map();
|
|
@@ -105,8 +119,8 @@ export class AgentKernel {
|
|
|
105
119
|
this.systemContext = normalized.systemContext;
|
|
106
120
|
this.thinkingBudget = normalized.thinkingBudget ?? 0;
|
|
107
121
|
this.selfCorrectOnFailure = normalized.selfCorrectOnFailure ?? false;
|
|
108
|
-
this.maxSelfCorrectAttempts = normalized.maxSelfCorrectAttempts ??
|
|
109
|
-
this.maxSubAgentDepth = normalized.maxSubAgentDepth ??
|
|
122
|
+
this.maxSelfCorrectAttempts = normalized.maxSelfCorrectAttempts ?? DEFAULT_MAX_SELF_CORRECT_ATTEMPTS;
|
|
123
|
+
this.maxSubAgentDepth = normalized.maxSubAgentDepth ?? DEFAULT_MAX_SUB_AGENT_DEPTH;
|
|
110
124
|
this.sessionStore = normalized.sessionStore;
|
|
111
125
|
this.agentRegistry = normalized.agentRegistry;
|
|
112
126
|
this.pluginManager = normalized.pluginManager;
|
|
@@ -115,7 +129,7 @@ export class AgentKernel {
|
|
|
115
129
|
this.toolRegistry = normalized.toolRegistry;
|
|
116
130
|
this.toolProviderRegistry = normalized.toolProviderRegistry;
|
|
117
131
|
this.sessionTitleGenerator = normalized.sessionTitleGenerator;
|
|
118
|
-
this.stepTimeout = normalized.stepTimeout ??
|
|
132
|
+
this.stepTimeout = normalized.stepTimeout ?? DEFAULT_STEP_TIMEOUT;
|
|
119
133
|
this.doomLoopThreshold = normalized.doomLoopThreshold ?? DOOM_LOOP_THRESHOLD;
|
|
120
134
|
this.compactionThreshold = normalized.compactionThreshold;
|
|
121
135
|
this.termination = normalized.termination;
|
|
@@ -135,8 +149,25 @@ export class AgentKernel {
|
|
|
135
149
|
: normalized.circuitBreakerOptions?.maxBackoffMs !== undefined
|
|
136
150
|
? { maxBackoffMs: normalized.circuitBreakerOptions.maxBackoffMs }
|
|
137
151
|
: {}),
|
|
138
|
-
...normalized.circuitBreakerOptions,
|
|
139
152
|
});
|
|
153
|
+
this.inputGuardrails = normalized.inputGuardrails ?? [];
|
|
154
|
+
this.outputGuardrails = normalized.outputGuardrails ?? [];
|
|
155
|
+
this.outputType = normalized.outputType ?? 'text';
|
|
156
|
+
// Derive responseFormat from outputType if it's a Zod schema
|
|
157
|
+
let effectiveResponseFormat = normalized.modelSettings?.responseFormat;
|
|
158
|
+
if (this.outputType !== 'text' && !effectiveResponseFormat) {
|
|
159
|
+
const jsonSchema = zodSchemaToNestedJsonSchema(this.outputType);
|
|
160
|
+
if (jsonSchema) {
|
|
161
|
+
effectiveResponseFormat = {
|
|
162
|
+
type: "json_schema",
|
|
163
|
+
jsonSchema: { name: "structured_output", schema: jsonSchema, strict: true },
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
// Fallback: basic json_object format
|
|
168
|
+
effectiveResponseFormat = { type: "json_object" };
|
|
169
|
+
}
|
|
170
|
+
}
|
|
140
171
|
this.saga = new ToolSaga();
|
|
141
172
|
this.stateMachine = new RunStateMachine();
|
|
142
173
|
this.permissionGate = new PermissionGate({
|
|
@@ -159,7 +190,7 @@ export class AgentKernel {
|
|
|
159
190
|
if (normalized.permissions?.topLevelPermissionRules) {
|
|
160
191
|
this.permissionGate.setTopLevelRules(normalized.permissions.topLevelPermissionRules);
|
|
161
192
|
}
|
|
162
|
-
this.maxTokens = normalized.maxTokens ??
|
|
193
|
+
this.maxTokens = normalized.maxTokens ?? DEFAULT_MAX_TOKENS;
|
|
163
194
|
const maxTokens = this.maxTokens;
|
|
164
195
|
const thinkingPrompt = normalized.thinkingPrompt ?? DEFAULT_THINKING_PROMPT;
|
|
165
196
|
// P1-N: wire the redacting logger into the kernel so every log line that
|
|
@@ -179,6 +210,9 @@ export class AgentKernel {
|
|
|
179
210
|
maxTokens,
|
|
180
211
|
thinkingBudget: this.thinkingBudget,
|
|
181
212
|
thinkingPrompt,
|
|
213
|
+
// LLM generation settings (from nested modelSettings)
|
|
214
|
+
...(normalized.modelSettings?.temperature !== undefined ? { temperature: normalized.modelSettings.temperature } : {}),
|
|
215
|
+
...(normalized.modelSettings?.topP !== undefined ? { topP: normalized.modelSettings.topP } : {}),
|
|
182
216
|
// Core's PluginManager structurally satisfies the model-caller hook
|
|
183
217
|
// contract (named generic fireHook — castable, matches by design).
|
|
184
218
|
pluginManager: normalized.pluginManager,
|
|
@@ -187,6 +221,11 @@ export class AgentKernel {
|
|
|
187
221
|
modelForRun: (runId) => this.stateMachine.getModelForRun(runId),
|
|
188
222
|
setModelForRun: (runId, model) => this.stateMachine.setModelForRun(runId, model),
|
|
189
223
|
getAvailableTools: (runId) => this.getAvailableTools(runId),
|
|
224
|
+
...(normalized.modelSettings?.toolChoice !== undefined ? { toolChoice: normalized.modelSettings.toolChoice } : {}),
|
|
225
|
+
...(normalized.modelSettings?.parallelToolCalls !== undefined ? { parallelToolCalls: normalized.modelSettings.parallelToolCalls } : {}),
|
|
226
|
+
...(normalized.modelSettings?.presencePenalty !== undefined ? { presencePenalty: normalized.modelSettings.presencePenalty } : {}),
|
|
227
|
+
...(normalized.modelSettings?.frequencyPenalty !== undefined ? { frequencyPenalty: normalized.modelSettings.frequencyPenalty } : {}),
|
|
228
|
+
...(effectiveResponseFormat !== undefined ? { responseFormat: effectiveResponseFormat } : {}),
|
|
190
229
|
});
|
|
191
230
|
// Validate default model has non-empty model string (fail-closed)
|
|
192
231
|
const defaultModel = this.modelCaller.getDefaultModel();
|
|
@@ -640,7 +679,7 @@ export class AgentKernel {
|
|
|
640
679
|
};
|
|
641
680
|
eventHandlers.forEach(h => h(startEvent));
|
|
642
681
|
// Run the loop — it reports its terminal status through the return value.
|
|
643
|
-
const { totalSteps, status: runStatus, totalInputTokens, totalOutputTokens, durationMs: loopDurationMs } = await this.runLoop(prompt, runId, ctx, abort, sessionId, userContentParts, agentOverride, runSaga, undefined, systemPrompt);
|
|
682
|
+
const { totalSteps, status: runStatus, totalInputTokens, totalOutputTokens, durationMs: loopDurationMs, structuredOutput } = await this.runLoop(prompt, runId, ctx, abort, sessionId, userContentParts, agentOverride, runSaga, undefined, systemPrompt);
|
|
644
683
|
completed = true;
|
|
645
684
|
result = {
|
|
646
685
|
runId,
|
|
@@ -650,10 +689,13 @@ export class AgentKernel {
|
|
|
650
689
|
status: cancelled || runStatus === "cancelled"
|
|
651
690
|
? "cancelled"
|
|
652
691
|
: runStatus === "failed" ? "failed" : "succeeded",
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
692
|
+
...(structuredOutput !== undefined ? { structuredOutput } : {}),
|
|
693
|
+
usage: {
|
|
694
|
+
totalSteps,
|
|
695
|
+
...(totalInputTokens !== undefined ? { inputTokens: totalInputTokens } : {}),
|
|
696
|
+
...(totalOutputTokens !== undefined ? { outputTokens: totalOutputTokens } : {}),
|
|
697
|
+
...(loopDurationMs !== undefined ? { durationMs: loopDurationMs } : {}),
|
|
698
|
+
},
|
|
657
699
|
};
|
|
658
700
|
// Emit agent.completed event
|
|
659
701
|
const completeEvent = {
|
|
@@ -671,7 +713,7 @@ export class AgentKernel {
|
|
|
671
713
|
runId,
|
|
672
714
|
status: "failed",
|
|
673
715
|
error: err instanceof Error ? err.message : String(err),
|
|
674
|
-
totalSteps: 0,
|
|
716
|
+
usage: { totalSteps: 0 },
|
|
675
717
|
};
|
|
676
718
|
// Emit agent.error event
|
|
677
719
|
const errorEvent = {
|
|
@@ -1006,6 +1048,9 @@ export class AgentKernel {
|
|
|
1006
1048
|
...(this.termination ? { termination: this.termination } : {}),
|
|
1007
1049
|
...(judgeModel ? { judgeModel } : {}),
|
|
1008
1050
|
...(currentAgent ? { currentAgent } : {}),
|
|
1051
|
+
...(this.inputGuardrails.length > 0 ? { inputGuardrails: this.inputGuardrails } : {}),
|
|
1052
|
+
...(this.outputGuardrails.length > 0 ? { outputGuardrails: this.outputGuardrails } : {}),
|
|
1053
|
+
...(this.outputType !== 'text' ? { outputType: this.outputType } : {}),
|
|
1009
1054
|
addSessionMessage: (sid, role, content, extra) => this.addSessionMessage(sid, role, content, extra),
|
|
1010
1055
|
beforeRun: async () => {
|
|
1011
1056
|
const parentRunId = this.stateMachine.runIdStack.at(-2);
|
|
@@ -1030,6 +1075,32 @@ export class AgentKernel {
|
|
|
1030
1075
|
emitCompleted: (event, sid, rid, totalIn, totalOut, status) => this.emitCompleted(event, sid, rid, totalIn, totalOut, status),
|
|
1031
1076
|
emitFail: (rid, c, reason, steps, sid, totalIn, totalOut, dur, cancelled) => this.emitFail(rid, c, reason, steps, sid, totalIn, totalOut, dur, cancelled),
|
|
1032
1077
|
});
|
|
1078
|
+
// Handle handoff — swap agent and continue the run
|
|
1079
|
+
if (result.handoff && this.agentRegistry) {
|
|
1080
|
+
const targetAgentId = result.handoff.targetAgentId;
|
|
1081
|
+
const targetAgent = await this.agentRegistry.get(targetAgentId);
|
|
1082
|
+
if (targetAgent) {
|
|
1083
|
+
// Swap the active agent for this run
|
|
1084
|
+
const rc = this.runContexts.get(runId);
|
|
1085
|
+
if (rc) {
|
|
1086
|
+
rc.agent = targetAgent;
|
|
1087
|
+
rc.depth++;
|
|
1088
|
+
}
|
|
1089
|
+
// Update the step executor's current agent
|
|
1090
|
+
this.stepExecutor.setCurrentAgent(targetAgent);
|
|
1091
|
+
// Rebuild system prompt for new agent
|
|
1092
|
+
const newSystemPrompt = this.buildSystemPrompt(targetAgent);
|
|
1093
|
+
// Resolve model for new agent
|
|
1094
|
+
this.modelCaller.resolveAgentModel(targetAgent, runId);
|
|
1095
|
+
const newRunModel = this.modelCaller.getActiveModel(runId);
|
|
1096
|
+
// Continue the run with the new agent
|
|
1097
|
+
return this.runLoop(result.handoff.summary ?? prompt, runId, ctx, runAbort, sessionId, userContentParts, targetAgent, runSaga, resume, newSystemPrompt);
|
|
1098
|
+
}
|
|
1099
|
+
else {
|
|
1100
|
+
// Target agent not found — log warning and continue with current agent
|
|
1101
|
+
console.warn(`[kernel] Handoff target agent "${targetAgentId}" not found — continuing with current agent`);
|
|
1102
|
+
}
|
|
1103
|
+
}
|
|
1033
1104
|
return result;
|
|
1034
1105
|
}
|
|
1035
1106
|
finally {
|