kernl 0.8.3 → 0.9.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.
Files changed (87) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/CHANGELOG.md +21 -0
  3. package/dist/agent/base.d.ts +73 -0
  4. package/dist/agent/base.d.ts.map +1 -0
  5. package/dist/agent/base.js +137 -0
  6. package/dist/agent/index.d.ts +2 -0
  7. package/dist/agent/index.d.ts.map +1 -1
  8. package/dist/agent/index.js +2 -1
  9. package/dist/agent/types.d.ts +4 -0
  10. package/dist/agent/types.d.ts.map +1 -1
  11. package/dist/agent.d.ts +10 -90
  12. package/dist/agent.d.ts.map +1 -1
  13. package/dist/agent.js +5 -171
  14. package/dist/api/resources/agents/agents.d.ts +11 -7
  15. package/dist/api/resources/agents/agents.d.ts.map +1 -1
  16. package/dist/api/resources/agents/agents.js +14 -8
  17. package/dist/kernl/__tests__/memory-config.test.d.ts +2 -0
  18. package/dist/kernl/__tests__/memory-config.test.d.ts.map +1 -0
  19. package/dist/kernl/__tests__/memory-config.test.js +157 -0
  20. package/dist/kernl/kernl.d.ts +11 -2
  21. package/dist/kernl/kernl.d.ts.map +1 -1
  22. package/dist/kernl/kernl.js +62 -28
  23. package/dist/kernl/types.d.ts +6 -5
  24. package/dist/kernl/types.d.ts.map +1 -1
  25. package/dist/lib/env.d.ts +2 -2
  26. package/dist/mcp/__tests__/utils.test.js +4 -2
  27. package/dist/mcp/utils.d.ts +1 -1
  28. package/dist/mcp/utils.js +1 -1
  29. package/dist/memory/__tests__/encoder.test.js +46 -0
  30. package/dist/memory/codecs/domain.js +1 -2
  31. package/dist/memory/encoder.d.ts +7 -7
  32. package/dist/memory/encoder.d.ts.map +1 -1
  33. package/dist/memory/encoder.js +15 -7
  34. package/dist/memory/memory.js +1 -1
  35. package/dist/memory/types.d.ts +6 -2
  36. package/dist/memory/types.d.ts.map +1 -1
  37. package/dist/realtime/agent.d.ts +17 -0
  38. package/dist/realtime/agent.d.ts.map +1 -0
  39. package/dist/realtime/agent.js +17 -0
  40. package/dist/realtime/channel.d.ts +30 -0
  41. package/dist/realtime/channel.d.ts.map +1 -0
  42. package/dist/realtime/channel.js +1 -0
  43. package/dist/realtime/index.d.ts +5 -0
  44. package/dist/realtime/index.d.ts.map +1 -0
  45. package/dist/realtime/index.js +4 -0
  46. package/dist/realtime/session.d.ts +98 -0
  47. package/dist/realtime/session.d.ts.map +1 -0
  48. package/dist/realtime/session.js +203 -0
  49. package/dist/realtime/types.d.ts +58 -0
  50. package/dist/realtime/types.d.ts.map +1 -0
  51. package/dist/realtime/types.js +1 -0
  52. package/dist/storage/in-memory.d.ts.map +1 -1
  53. package/dist/storage/in-memory.js +5 -1
  54. package/dist/tool/__tests__/toolkit.test.js +2 -2
  55. package/dist/tool/tool.d.ts +2 -1
  56. package/dist/tool/tool.d.ts.map +1 -1
  57. package/dist/tool/toolkit.d.ts +4 -4
  58. package/dist/tool/toolkit.d.ts.map +1 -1
  59. package/dist/tool/toolkit.js +2 -1
  60. package/dist/tool/types.d.ts +4 -4
  61. package/dist/tool/types.d.ts.map +1 -1
  62. package/package.json +4 -4
  63. package/src/agent/base.ts +220 -0
  64. package/src/agent/index.ts +2 -0
  65. package/src/agent/types.ts +5 -0
  66. package/src/agent.ts +12 -231
  67. package/src/api/resources/agents/agents.ts +19 -13
  68. package/src/kernl/__tests__/memory-config.test.ts +203 -0
  69. package/src/kernl/kernl.ts +81 -39
  70. package/src/kernl/types.ts +6 -5
  71. package/src/mcp/__tests__/utils.test.ts +4 -2
  72. package/src/mcp/utils.ts +1 -1
  73. package/src/memory/__tests__/encoder.test.ts +63 -0
  74. package/src/memory/codecs/domain.ts +1 -1
  75. package/src/memory/encoder.ts +18 -10
  76. package/src/memory/memory.ts +1 -1
  77. package/src/memory/types.ts +6 -2
  78. package/src/realtime/agent.ts +24 -0
  79. package/src/realtime/channel.ts +32 -0
  80. package/src/realtime/index.ts +4 -0
  81. package/src/realtime/session.ts +259 -0
  82. package/src/realtime/types.ts +73 -0
  83. package/src/storage/in-memory.ts +9 -1
  84. package/src/tool/__tests__/toolkit.test.ts +2 -2
  85. package/src/tool/tool.ts +2 -1
  86. package/src/tool/toolkit.ts +6 -5
  87. package/src/tool/types.ts +4 -4
@@ -1,4 +1,4 @@
1
- import type { Agent } from "../agent.js";
1
+ import type { BaseAgent } from "../agent/base.js";
2
2
  import type { Context, UnknownContext } from "../context.js";
3
3
  import type { Tool } from "./index.js";
4
4
  import type { FunctionToolkitConfig, MCPToolkitConfig } from "./types.js";
@@ -20,12 +20,12 @@ export declare abstract class BaseToolkit<TContext = UnknownContext> {
20
20
  /**
21
21
  * The agent this toolkit is bound to (if any)
22
22
  */
23
- protected agent?: Agent<TContext, any>;
23
+ protected agent?: BaseAgent<TContext>;
24
24
  /**
25
25
  * Bind this toolkit to an agent.
26
- * Called by Agent constructor.
26
+ * Called by agent constructor.
27
27
  */
28
- bind(agent: Agent<TContext, any>): void;
28
+ bind(agent: BaseAgent<TContext>): void;
29
29
  /**
30
30
  * Get a specific tool by its ID.
31
31
  *
@@ -1 +1 @@
1
- {"version":3,"file":"toolkit.d.ts","sourceRoot":"","sources":["../../src/tool/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,CAAC,WAAW,EAAE,MAAM,CAAC;IAEtC;;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M,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;IAgClE;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CAQ/B"}
@@ -13,7 +13,7 @@ export class BaseToolkit {
13
13
  agent;
14
14
  /**
15
15
  * Bind this toolkit to an agent.
16
- * Called by Agent constructor.
16
+ * Called by agent constructor.
17
17
  */
18
18
  bind(agent) {
19
19
  this.agent = agent;
@@ -159,6 +159,7 @@ export class MCPToolkit extends BaseToolkit {
159
159
  if (!this.cached) {
160
160
  const mcpTools = await this.server.listTools();
161
161
  for (const mcpTool of mcpTools) {
162
+ // safety: MCP tools are context-agnostic (external servers)
162
163
  const tool = mcpToFunctionTool(this.server, mcpTool);
163
164
  this.cache.set(tool.id, tool);
164
165
  }
@@ -1,5 +1,5 @@
1
1
  import { z, type ZodType } from "zod";
2
- import { Agent } from "../agent.js";
2
+ import type { BaseAgent } from "../agent/base.js";
3
3
  import { Context, UnknownContext } from "../context.js";
4
4
  import { MCPServer } from "../mcp/base.js";
5
5
  import type { ToolCallState } from "@kernl-sdk/protocol";
@@ -60,7 +60,7 @@ export type ToolConfig<TContext = UnknownContext, TParameters extends ToolInputP
60
60
  */
61
61
  export interface ToolkitFilterContext<TContext = UnknownContext> {
62
62
  context: Context<TContext>;
63
- agent: Agent<TContext, any>;
63
+ agent: BaseAgent<TContext>;
64
64
  toolkitId: string;
65
65
  }
66
66
  /**
@@ -176,10 +176,10 @@ export type ToolExecuteFunction<TContext = UnknownContext, TParameters extends T
176
176
  * @returns True if the tool call should be approved, false otherwise
177
177
  */
178
178
  export type ToolApprovalFunction<TParameters extends ToolInputParameters> = (context: Context, input: ToolExecuteArgument<TParameters>, callId?: string) => Promise<boolean>;
179
- export type ToolEnabledFunction<TContext = UnknownContext> = (context: Context<TContext>, agent: Agent<any, any>) => Promise<boolean>;
179
+ export type ToolEnabledFunction<TContext = UnknownContext> = (context: Context<TContext>, agent: BaseAgent<TContext>) => Promise<boolean>;
180
180
  export type ToolEnabledPredicate<TContext = UnknownContext> = (args: {
181
181
  context: Context<TContext>;
182
- agent: Agent<any, any>;
182
+ agent: BaseAgent<TContext>;
183
183
  }) => boolean | Promise<boolean>;
184
184
  type ToolEnabledOption<Context = UnknownContext> = boolean | ToolEnabledPredicate<Context>;
185
185
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/tool/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,KAAK,OAAO,EAAE,MAAM,KAAK,CAAC;AAEtC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEzD,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAEvD;;;GAGG;AACH,MAAM,MAAM,IAAI,CAAC,QAAQ,GAAG,cAAc,IACtC,YAAY,CAAC,QAAQ,EAAE,GAAG,EAAE,GAAG,CAAC,GAChC,UAAU,CAAC;AAEf;;;;;;GAMG;AACH,MAAM,MAAM,UAAU,CACpB,QAAQ,GAAG,cAAc,EACzB,WAAW,SAAS,mBAAmB,GAAG,SAAS,EACnD,OAAO,GAAG,OAAO,IACf;IACF;;OAEG;IACH,EAAE,EAAE,MAAM,CAAC;IAEX;;OAEG;IACH,IAAI,CAAC,EAA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O,EAChB,KAAK,EAAE,mBAAmB,CAAC,WAAW,CAAC,EACvC,MAAM,CAAC,EAAE,MAAM,KACZ,OAAO,CAAC,OAAO,CAAC,CAAC;AAEtB,MAAM,MAAM,mBAAmB,CAAC,QAAQ,GAAG,cAAc,IAAI,CAC3D,OAAO,EAAE,OAAO,CAAC,QAAQ,CAAC,EAC1B,KAAK,EAAE,SAAS,CAAC,QAAQ,CAAC,KACvB,OAAO,CAAC,OAAO,CAAC,CAAC;AAEtB,MAAM,MAAM,oBAAoB,CAAC,QAAQ,GAAG,cAAc,IAAI,CAAC,IAAI,EAAE;IACnE,OAAO,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC3B,KAAK,EAAE,SAAS,CAAC,QAAQ,CAAC,CAAC;CAC5B,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;AAEjC,KAAK,iBAAiB,CAAC,OAAO,GAAG,cAAc,IAC3C,OAAO,GACP,oBAAoB,CAAC,OAAO,CAAC,CAAC;AAElC;;;;;;;GAOG;AACH,MAAM,MAAM,iBAAiB,GAAG,CAC9B,OAAO,EAAE,OAAO,EAChB,KAAK,EAAE,KAAK,GAAG,OAAO,KACnB,MAAM,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kernl",
3
- "version": "0.8.3",
3
+ "version": "0.9.0",
4
4
  "description": "A modern AI agent framework",
5
5
  "keywords": [
6
6
  "kernl",
@@ -35,8 +35,8 @@
35
35
  "@modelcontextprotocol/sdk": "^1.20.2",
36
36
  "yaml": "^2.8.2",
37
37
  "zod": "^4.1.12",
38
- "@kernl-sdk/protocol": "0.2.8",
39
- "@kernl-sdk/retrieval": "0.1.3",
38
+ "@kernl-sdk/protocol": "0.3.0",
39
+ "@kernl-sdk/retrieval": "0.1.4",
40
40
  "@kernl-sdk/shared": "^0.3.0"
41
41
  },
42
42
  "devDependencies": {
@@ -45,7 +45,7 @@
45
45
  "tsc-alias": "^1.8.10",
46
46
  "typescript": "5.9.2",
47
47
  "vitest": "^4.0.8",
48
- "@kernl-sdk/ai": "0.3.0"
48
+ "@kernl-sdk/ai": "0.3.1"
49
49
  },
50
50
  "scripts": {
51
51
  "clean": "rm -rf dist",
@@ -0,0 +1,220 @@
1
+ import { randomID } from "@kernl-sdk/shared/lib";
2
+
3
+ import type { Context, UnknownContext } from "@/context";
4
+ import type { Tool, BaseToolkit } from "@/tool";
5
+ import { memory } from "@/tool";
6
+ import { MisconfiguredError } from "@/lib/error";
7
+ import { AgentHooks } from "@/lifecycle";
8
+ import type { Kernl } from "@/kernl";
9
+ import type {
10
+ AgentMemoryCreate,
11
+ AgentMemoryUpdate,
12
+ MemoryListOptions,
13
+ MemorySearchQuery,
14
+ } from "@/memory";
15
+
16
+ import type { AgentKind, AgentMemoryConfig, AgentOutputType } from "./types";
17
+ import type { TextOutput } from "@/thread/types";
18
+
19
+ /**
20
+ * Base configuration shared by all agent types.
21
+ */
22
+ export interface BaseAgentConfig<TContext = UnknownContext> {
23
+ id: string;
24
+ name: string;
25
+ description?: string;
26
+ instructions:
27
+ | string
28
+ | ((context: Context<TContext>) => Promise<string> | string);
29
+ toolkits?: BaseToolkit<TContext>[];
30
+ memory?: AgentMemoryConfig;
31
+ }
32
+
33
+ /**
34
+ * Common model interface shared by all model types.
35
+ */
36
+ export interface BaseModel {
37
+ readonly provider: string;
38
+ readonly modelId: string;
39
+ }
40
+
41
+ /**
42
+ * Abstract base class for all agent types.
43
+ *
44
+ * Provides common functionality shared between text-based agents (Agent)
45
+ * and realtime agents (RealtimeAgent).
46
+ */
47
+ export abstract class BaseAgent<
48
+ TContext = UnknownContext,
49
+ TOutput extends AgentOutputType = TextOutput,
50
+ > extends AgentHooks<TContext, TOutput> {
51
+ protected kernl?: Kernl;
52
+
53
+ abstract readonly kind: AgentKind;
54
+ abstract readonly model: BaseModel;
55
+
56
+ readonly id: string;
57
+ readonly name: string;
58
+ readonly description?: string;
59
+ readonly instructions: (
60
+ context: Context<TContext>,
61
+ ) => Promise<string> | string;
62
+ readonly toolkits: BaseToolkit<TContext>[];
63
+ readonly systools: BaseToolkit<TContext>[];
64
+ readonly memory: AgentMemoryConfig;
65
+
66
+ constructor(config: BaseAgentConfig<TContext>) {
67
+ super();
68
+
69
+ if (config.id.trim() === "") {
70
+ throw new MisconfiguredError("Agent must have an id.");
71
+ }
72
+
73
+ this.id = config.id;
74
+ this.name = config.name;
75
+ this.description = config.description;
76
+ this.instructions =
77
+ typeof config.instructions === "function"
78
+ ? config.instructions
79
+ : () => config.instructions as string;
80
+ this.toolkits = config.toolkits ?? [];
81
+ this.systools = [];
82
+ this.memory = config.memory ?? { enabled: false };
83
+
84
+ for (const toolkit of this.toolkits) {
85
+ toolkit.bind(this);
86
+ }
87
+ }
88
+
89
+ /**
90
+ * Bind this agent to a kernl instance. Called by kernl.register().
91
+ */
92
+ bind(kernl: Kernl): void {
93
+ this.kernl = kernl;
94
+
95
+ // initialize system toolkits
96
+ if (this.memory.enabled) {
97
+ // safety: system tools only rely on ctx.agent, not ctx.context
98
+ const toolkit = memory as unknown as BaseToolkit<TContext>;
99
+ this.systools.push(toolkit);
100
+ toolkit.bind(this);
101
+ }
102
+ }
103
+
104
+ /**
105
+ * Get a specific tool by ID from systools and toolkits.
106
+ */
107
+ tool(id: string): Tool<TContext> | undefined {
108
+ // check systools first
109
+ for (const toolkit of this.systools) {
110
+ const tool = toolkit.get(id);
111
+ if (tool) return tool;
112
+ }
113
+ // then user toolkits
114
+ for (const toolkit of this.toolkits) {
115
+ const tool = toolkit.get(id);
116
+ if (tool) return tool;
117
+ }
118
+ return undefined;
119
+ }
120
+
121
+ /**
122
+ * Get all tools available from systools and toolkits for the given context.
123
+ */
124
+ async tools(context: Context<TContext>): Promise<Tool<TContext>[]> {
125
+ const all: Tool<TContext>[] = [];
126
+
127
+ for (const toolkit of [...this.systools, ...this.toolkits]) {
128
+ all.push(...(await toolkit.list(context)));
129
+ }
130
+
131
+ const ids = all.map((t) => t.id);
132
+ const duplicates = ids.filter((id, i) => ids.indexOf(id) !== i);
133
+
134
+ if (duplicates.length > 0) {
135
+ throw new MisconfiguredError(
136
+ `Duplicate tool IDs found: ${[...new Set(duplicates)].join(", ")}`,
137
+ );
138
+ }
139
+
140
+ return all;
141
+ }
142
+
143
+ /**
144
+ * Memory management scoped to this agent.
145
+ */
146
+ get memories() {
147
+ if (!this.kernl) {
148
+ throw new MisconfiguredError(
149
+ `Agent ${this.id} not bound to kernl. Call kernl.register(agent) first.`,
150
+ );
151
+ }
152
+
153
+ const agentId = this.id;
154
+ const kmem = this.kernl.memories;
155
+
156
+ return {
157
+ list: (
158
+ params?: Omit<MemoryListOptions, "filter"> & {
159
+ collection?: string;
160
+ limit?: number;
161
+ },
162
+ ) =>
163
+ kmem.list({
164
+ filter: {
165
+ scope: { agentId },
166
+ collections: params?.collection ? [params.collection] : undefined,
167
+ },
168
+ limit: params?.limit,
169
+ }),
170
+
171
+ create: (params: AgentMemoryCreate) =>
172
+ kmem.create({
173
+ id: params.id ?? `mem_${randomID()}`,
174
+ scope: {
175
+ namespace: params.namespace,
176
+ entityId: params.entityId,
177
+ agentId,
178
+ },
179
+ kind: "semantic",
180
+ collection: params.collection,
181
+ content: params.content,
182
+ wmem: params.wmem,
183
+ smem: params.smem,
184
+ timestamp: params.timestamp,
185
+ metadata: params.metadata,
186
+ }),
187
+
188
+ update: (params: AgentMemoryUpdate) =>
189
+ kmem.update({
190
+ id: params.id,
191
+ content: params.content,
192
+ collection: params.collection,
193
+ wmem: params.wmem,
194
+ smem: params.smem,
195
+ metadata: params.metadata,
196
+ }),
197
+
198
+ search: (
199
+ params: Omit<MemorySearchQuery, "filter"> & {
200
+ filter?: Omit<NonNullable<MemorySearchQuery["filter"]>, "scope"> & {
201
+ scope?: Omit<
202
+ NonNullable<NonNullable<MemorySearchQuery["filter"]>["scope"]>,
203
+ "agentId"
204
+ >;
205
+ };
206
+ },
207
+ ) =>
208
+ kmem.search({
209
+ ...params,
210
+ filter: {
211
+ ...params.filter,
212
+ scope: {
213
+ ...params.filter?.scope,
214
+ agentId,
215
+ },
216
+ },
217
+ }),
218
+ };
219
+ }
220
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./base";
2
+ export * from "./types";
@@ -163,3 +163,8 @@ export interface AgentMemoryConfig {
163
163
  */
164
164
  enabled: boolean;
165
165
  }
166
+
167
+ /**
168
+ * Agent kind discriminator.
169
+ */
170
+ export type AgentKind = "llm" | "realtime";
package/src/agent.ts CHANGED
@@ -6,7 +6,6 @@ import {
6
6
  } from "@kernl-sdk/protocol";
7
7
 
8
8
  import { Thread } from "./thread";
9
- import type { Kernl } from "./kernl";
10
9
  import type {
11
10
  RThreadsListParams,
12
11
  RThreadCreateParams,
@@ -15,30 +14,16 @@ import type {
15
14
  RThreadUpdateParams,
16
15
  } from "@/api/resources/threads/types";
17
16
  import type { Context, UnknownContext } from "./context";
18
- import { Tool, memory } from "./tool";
19
- import { BaseToolkit } from "./tool/toolkit";
20
17
  import {
21
18
  InputGuardrail,
22
19
  OutputGuardrail,
23
20
  type ResolvedAgentResponse,
24
21
  } from "./guardrail";
25
- import { AgentHooks } from "./lifecycle";
26
- import type {
27
- AgentMemoryCreate,
28
- AgentMemoryUpdate,
29
- MemoryListOptions,
30
- MemorySearchQuery,
31
- } from "./memory";
22
+ import { BaseAgent } from "./agent/base";
32
23
 
33
- import { randomID } from "@kernl-sdk/shared/lib";
34
24
  import { MisconfiguredError, RuntimeError } from "./lib/error";
35
25
 
36
- /* types */
37
- import type {
38
- AgentConfig,
39
- AgentMemoryConfig,
40
- AgentOutputType,
41
- } from "./agent/types";
26
+ import type { AgentConfig, AgentOutputType } from "./agent/types";
42
27
  import type {
43
28
  TextOutput,
44
29
  ThreadExecuteOptions,
@@ -50,74 +35,30 @@ export class Agent<
50
35
  TContext = UnknownContext,
51
36
  TOutput extends AgentOutputType = TextOutput,
52
37
  >
53
- extends AgentHooks<TContext, TOutput>
38
+ extends BaseAgent<TContext, TOutput>
54
39
  implements AgentConfig<TContext, TOutput>
55
40
  {
56
- private kernl?: Kernl;
57
-
58
- id: string;
59
- name: string;
60
- description?: string;
61
- instructions: (context: Context<TContext>) => Promise<string> | string;
41
+ readonly kind = "llm";
42
+ readonly model: LanguageModel;
43
+ readonly modelSettings: LanguageModelRequestSettings;
62
44
 
63
- model: LanguageModel;
64
- modelSettings: LanguageModelRequestSettings;
65
- // actions: ActionSet; /* TODO */
66
- toolkits: BaseToolkit<TContext>[];
67
- systools: BaseToolkit<TContext>[];
68
- memory: AgentMemoryConfig;
69
-
70
- guardrails: {
45
+ readonly guardrails: {
71
46
  input: InputGuardrail[];
72
47
  output: OutputGuardrail<AgentOutputType>[];
73
48
  };
74
- output: TOutput = "text" as TOutput;
75
- resetToolChoice: boolean;
49
+ readonly output: TOutput = "text" as TOutput;
50
+ readonly resetToolChoice: boolean;
76
51
 
77
52
  constructor(config: AgentConfig<TContext, TOutput>) {
78
- super();
79
- if (config.id.trim() === "") {
80
- throw new MisconfiguredError("Agent must have an id.");
81
- }
82
- this.id = config.id;
83
- this.name = config.name;
84
- this.description = config.description;
85
- this.instructions =
86
- typeof config.instructions === "function"
87
- ? config.instructions
88
- : () => config.instructions as string;
89
- this.model = config.model; // (TODO): include optional default setting for convenience like env.DEFAULT_LLM = "gpt-5"
90
- this.modelSettings = config.modelSettings ?? {};
91
-
92
- this.toolkits = config.toolkits ?? [];
93
- this.systools = [];
94
- this.memory = config.memory ?? { enabled: false };
95
-
96
- for (const toolkit of this.toolkits) {
97
- toolkit.bind(this);
98
- }
53
+ super(config);
99
54
 
55
+ this.model = config.model;
56
+ this.modelSettings = config.modelSettings ?? {};
100
57
  this.guardrails = config.guardrails ?? { input: [], output: [] };
101
58
  if (config.output) {
102
59
  this.output = config.output;
103
60
  }
104
61
  this.resetToolChoice = config.resetToolChoice ?? true;
105
- // this.toolUseBehavior = config.toolUseBehavior ?? "run_llm_again";
106
- }
107
-
108
- /**
109
- * Bind this agent to a kernl instance. Called by kernl.register().
110
- */
111
- bind(kernl: Kernl): void {
112
- this.kernl = kernl;
113
-
114
- // initialize system toolkits
115
- if (this.memory.enabled) {
116
- // safety: system tools only rely on ctx.agent, not ctx.context
117
- const toolkit = memory as unknown as BaseToolkit<TContext>;
118
- this.systools.push(toolkit);
119
- toolkit.bind(this);
120
- }
121
62
  }
122
63
 
123
64
  /**
@@ -241,60 +182,6 @@ export class Agent<
241
182
  yield* this.kernl.scheduleStream(thread);
242
183
  }
243
184
 
244
- /**
245
- * @internal
246
- *
247
- * Get a specific tool by ID from systools and toolkits.
248
- *
249
- * @param id The tool ID to look up
250
- * @returns The tool if found, undefined otherwise
251
- */
252
- tool(id: string): Tool<TContext> | undefined {
253
- // Check systools first
254
- for (const toolkit of this.systools) {
255
- const tool = toolkit.get(id);
256
- if (tool) return tool;
257
- }
258
- // Then user toolkits
259
- for (const toolkit of this.toolkits) {
260
- const tool = toolkit.get(id);
261
- if (tool) return tool;
262
- }
263
- return undefined;
264
- }
265
-
266
- /**
267
- * @internal
268
- *
269
- * Get all tools available from systools and toolkits for the given context.
270
- * Checks for duplicate tool IDs across toolkits and throws an error if found.
271
- *
272
- * (TODO): Consider returning toolkits alongside tools so we can serialize them
273
- * together and give agents more options for dealing with tool groups.
274
- *
275
- * @param context The context to use for filtering tools
276
- * @returns Array of all available tools
277
- * @throws {MisconfiguredError} If duplicate tool IDs are found across toolkits
278
- */
279
- async tools(context: Context<TContext>): Promise<Tool<TContext>[]> {
280
- const all: Tool<TContext>[] = [];
281
-
282
- for (const toolkit of [...this.systools, ...this.toolkits]) {
283
- all.push(...(await toolkit.list(context)));
284
- }
285
-
286
- const ids = all.map((t) => t.id);
287
- const duplicates = ids.filter((id, i) => ids.indexOf(id) !== i);
288
-
289
- if (duplicates.length > 0) {
290
- throw new MisconfiguredError(
291
- `Duplicate tool IDs found: ${[...new Set(duplicates)].join(", ")}`,
292
- );
293
- }
294
-
295
- return all;
296
- }
297
-
298
185
  /**
299
186
  * Thread management scoped to this agent.
300
187
  *
@@ -331,110 +218,4 @@ export class Agent<
331
218
  kthreads.update(tid, patch),
332
219
  };
333
220
  }
334
-
335
- /**
336
- * Memory management scoped to this agent.
337
- *
338
- * Provides a simplified API for creating memories with:
339
- * - Auto-generated IDs
340
- * - Flattened scope fields (namespace, entityId) - agentId is implicit
341
- * - Default kind of "semantic"
342
- *
343
- * @example
344
- * ```ts
345
- * await agent.memories.create({
346
- * namespace: "user-123",
347
- * collection: "preferences",
348
- * content: { text: "User prefers TypeScript" },
349
- * });
350
- * ```
351
- */
352
- get memories() {
353
- if (!this.kernl) {
354
- throw new MisconfiguredError(
355
- `Agent ${this.id} not bound to kernl. Call kernl.register(agent) first.`,
356
- );
357
- }
358
-
359
- const agentId = this.id;
360
- const kmem = this.kernl.memories;
361
-
362
- return {
363
- /**
364
- * List memories scoped to this agent.
365
- */
366
- list: (
367
- params?: Omit<MemoryListOptions, "filter"> & {
368
- collection?: string;
369
- limit?: number;
370
- // (TODO): we might want to add the filter back here
371
- },
372
- ) =>
373
- kmem.list({
374
- filter: {
375
- scope: { agentId },
376
- collections: params?.collection ? [params.collection] : undefined,
377
- },
378
- limit: params?.limit,
379
- }),
380
-
381
- /**
382
- * Create a new memory scoped to this agent.
383
- */
384
- create: (params: AgentMemoryCreate) =>
385
- kmem.create({
386
- id: params.id ?? `mem_${randomID()}`,
387
- scope: {
388
- namespace: params.namespace,
389
- entityId: params.entityId,
390
- agentId,
391
- },
392
- kind: "semantic",
393
- collection: params.collection,
394
- content: params.content,
395
- wmem: params.wmem,
396
- smem: params.smem,
397
- timestamp: params.timestamp,
398
- metadata: params.metadata,
399
- }),
400
-
401
- /**
402
- * Update an existing memory scoped to this agent.
403
- */
404
- update: (params: AgentMemoryUpdate) =>
405
- kmem.update({
406
- id: params.id,
407
- content: params.content,
408
- collection: params.collection,
409
- wmem: params.wmem,
410
- smem: params.smem,
411
- metadata: params.metadata,
412
- }),
413
-
414
- /**
415
- * Search memories scoped to this agent.
416
- */
417
- search: (
418
- params: Omit<MemorySearchQuery, "filter"> & {
419
- // (TODO): is this correct?
420
- filter?: Omit<NonNullable<MemorySearchQuery["filter"]>, "scope"> & {
421
- scope?: Omit<
422
- NonNullable<NonNullable<MemorySearchQuery["filter"]>["scope"]>,
423
- "agentId"
424
- >;
425
- };
426
- },
427
- ) =>
428
- kmem.search({
429
- ...params,
430
- filter: {
431
- ...params.filter,
432
- scope: {
433
- ...params.filter?.scope,
434
- agentId,
435
- },
436
- },
437
- }),
438
- };
439
- }
440
221
  }