kernl 0.8.4 → 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.
- package/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +15 -0
- package/dist/agent/base.d.ts +73 -0
- package/dist/agent/base.d.ts.map +1 -0
- package/dist/agent/base.js +137 -0
- package/dist/agent/index.d.ts +2 -0
- package/dist/agent/index.d.ts.map +1 -1
- package/dist/agent/index.js +2 -1
- package/dist/agent/types.d.ts +4 -0
- package/dist/agent/types.d.ts.map +1 -1
- package/dist/agent.d.ts +10 -90
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +5 -171
- package/dist/api/resources/agents/agents.d.ts +11 -7
- package/dist/api/resources/agents/agents.d.ts.map +1 -1
- package/dist/api/resources/agents/agents.js +14 -8
- package/dist/kernl/kernl.d.ts +2 -2
- package/dist/kernl/kernl.d.ts.map +1 -1
- package/dist/kernl/kernl.js +6 -6
- package/dist/kernl/types.d.ts +3 -3
- package/dist/kernl/types.d.ts.map +1 -1
- package/dist/lib/env.d.ts +2 -2
- package/dist/mcp/__tests__/utils.test.js +4 -2
- package/dist/mcp/utils.d.ts +1 -1
- package/dist/mcp/utils.js +1 -1
- package/dist/realtime/agent.d.ts +17 -0
- package/dist/realtime/agent.d.ts.map +1 -0
- package/dist/realtime/agent.js +17 -0
- package/dist/realtime/channel.d.ts +30 -0
- package/dist/realtime/channel.d.ts.map +1 -0
- package/dist/realtime/channel.js +1 -0
- package/dist/realtime/index.d.ts +5 -0
- package/dist/realtime/index.d.ts.map +1 -0
- package/dist/realtime/index.js +4 -0
- package/dist/realtime/session.d.ts +98 -0
- package/dist/realtime/session.d.ts.map +1 -0
- package/dist/realtime/session.js +203 -0
- package/dist/realtime/types.d.ts +58 -0
- package/dist/realtime/types.d.ts.map +1 -0
- package/dist/realtime/types.js +1 -0
- package/dist/storage/in-memory.d.ts.map +1 -1
- package/dist/storage/in-memory.js +5 -1
- package/dist/tool/__tests__/toolkit.test.js +2 -2
- package/dist/tool/tool.d.ts +2 -1
- package/dist/tool/tool.d.ts.map +1 -1
- package/dist/tool/toolkit.d.ts +4 -4
- package/dist/tool/toolkit.d.ts.map +1 -1
- package/dist/tool/toolkit.js +2 -1
- package/dist/tool/types.d.ts +4 -4
- package/dist/tool/types.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/agent/base.ts +220 -0
- package/src/agent/index.ts +2 -0
- package/src/agent/types.ts +5 -0
- package/src/agent.ts +12 -231
- package/src/api/resources/agents/agents.ts +19 -13
- package/src/kernl/kernl.ts +9 -9
- package/src/kernl/types.ts +3 -3
- package/src/mcp/__tests__/utils.test.ts +4 -2
- package/src/mcp/utils.ts +1 -1
- package/src/realtime/agent.ts +24 -0
- package/src/realtime/channel.ts +32 -0
- package/src/realtime/index.ts +4 -0
- package/src/realtime/session.ts +259 -0
- package/src/realtime/types.ts +73 -0
- package/src/storage/in-memory.ts +9 -1
- package/src/tool/__tests__/toolkit.test.ts +2 -2
- package/src/tool/tool.ts +2 -1
- package/src/tool/toolkit.ts +6 -5
- package/src/tool/types.ts +4 -4
package/.turbo/turbo-build.log
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @kernl/core
|
|
2
2
|
|
|
3
|
+
## 0.9.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 572ae80: Add realtime voice agent support with memory capabilities.
|
|
8
|
+
- **protocol**: Add realtime model and event types for voice agents
|
|
9
|
+
- **kernl**: Extract BaseAgent class shared by Agent and RealtimeAgent, enabling memory support for realtime agents. Add `kind` discriminator for type narrowing.
|
|
10
|
+
- **openai**: Add OpenAI realtime voice provider with WebSocket-based streaming
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- Updated dependencies [572ae80]
|
|
15
|
+
- @kernl-sdk/protocol@0.3.0
|
|
16
|
+
- @kernl-sdk/retrieval@0.1.4
|
|
17
|
+
|
|
3
18
|
## 0.8.4
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { Context, UnknownContext } from "../context.js";
|
|
2
|
+
import type { Tool, BaseToolkit } from "../tool/index.js";
|
|
3
|
+
import { AgentHooks } from "../lifecycle.js";
|
|
4
|
+
import type { Kernl } from "../kernl/index.js";
|
|
5
|
+
import type { AgentMemoryCreate, AgentMemoryUpdate, MemoryListOptions, MemorySearchQuery } from "../memory/index.js";
|
|
6
|
+
import type { AgentKind, AgentMemoryConfig, AgentOutputType } from "./types.js";
|
|
7
|
+
import type { TextOutput } from "../thread/types.js";
|
|
8
|
+
/**
|
|
9
|
+
* Base configuration shared by all agent types.
|
|
10
|
+
*/
|
|
11
|
+
export interface BaseAgentConfig<TContext = UnknownContext> {
|
|
12
|
+
id: string;
|
|
13
|
+
name: string;
|
|
14
|
+
description?: string;
|
|
15
|
+
instructions: string | ((context: Context<TContext>) => Promise<string> | string);
|
|
16
|
+
toolkits?: BaseToolkit<TContext>[];
|
|
17
|
+
memory?: AgentMemoryConfig;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Common model interface shared by all model types.
|
|
21
|
+
*/
|
|
22
|
+
export interface BaseModel {
|
|
23
|
+
readonly provider: string;
|
|
24
|
+
readonly modelId: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Abstract base class for all agent types.
|
|
28
|
+
*
|
|
29
|
+
* Provides common functionality shared between text-based agents (Agent)
|
|
30
|
+
* and realtime agents (RealtimeAgent).
|
|
31
|
+
*/
|
|
32
|
+
export declare abstract class BaseAgent<TContext = UnknownContext, TOutput extends AgentOutputType = TextOutput> extends AgentHooks<TContext, TOutput> {
|
|
33
|
+
protected kernl?: Kernl;
|
|
34
|
+
abstract readonly kind: AgentKind;
|
|
35
|
+
abstract readonly model: BaseModel;
|
|
36
|
+
readonly id: string;
|
|
37
|
+
readonly name: string;
|
|
38
|
+
readonly description?: string;
|
|
39
|
+
readonly instructions: (context: Context<TContext>) => Promise<string> | string;
|
|
40
|
+
readonly toolkits: BaseToolkit<TContext>[];
|
|
41
|
+
readonly systools: BaseToolkit<TContext>[];
|
|
42
|
+
readonly memory: AgentMemoryConfig;
|
|
43
|
+
constructor(config: BaseAgentConfig<TContext>);
|
|
44
|
+
/**
|
|
45
|
+
* Bind this agent to a kernl instance. Called by kernl.register().
|
|
46
|
+
*/
|
|
47
|
+
bind(kernl: Kernl): void;
|
|
48
|
+
/**
|
|
49
|
+
* Get a specific tool by ID from systools and toolkits.
|
|
50
|
+
*/
|
|
51
|
+
tool(id: string): Tool<TContext> | undefined;
|
|
52
|
+
/**
|
|
53
|
+
* Get all tools available from systools and toolkits for the given context.
|
|
54
|
+
*/
|
|
55
|
+
tools(context: Context<TContext>): Promise<Tool<TContext>[]>;
|
|
56
|
+
/**
|
|
57
|
+
* Memory management scoped to this agent.
|
|
58
|
+
*/
|
|
59
|
+
get memories(): {
|
|
60
|
+
list: (params?: Omit<MemoryListOptions, "filter"> & {
|
|
61
|
+
collection?: string;
|
|
62
|
+
limit?: number;
|
|
63
|
+
}) => Promise<import("../memory/index.js").MemoryRecord[]>;
|
|
64
|
+
create: (params: AgentMemoryCreate) => Promise<import("../memory/index.js").MemoryRecord>;
|
|
65
|
+
update: (params: AgentMemoryUpdate) => Promise<import("../memory/index.js").MemoryRecord>;
|
|
66
|
+
search: (params: Omit<MemorySearchQuery, "filter"> & {
|
|
67
|
+
filter?: Omit<NonNullable<MemorySearchQuery["filter"]>, "scope"> & {
|
|
68
|
+
scope?: Omit<NonNullable<NonNullable<MemorySearchQuery["filter"]>["scope"]>, "agentId">;
|
|
69
|
+
};
|
|
70
|
+
}) => Promise<import("@kernl-sdk/retrieval").SearchHit<import("../memory/index.js").IndexMemoryRecord>[]>;
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=base.d.ts.map
|
|
@@ -0,0 +1 @@
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CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC,EAAE,OAAO,CAAC,GAAG;gBACjE,KAAK,CAAC,EAAE,IAAI,CACV,WAAW,CAAC,WAAW,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,EAC9D,SAAS,CACV,CAAC;aACH,CAAC;SACH;MAaN;CACF"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { randomID } from "@kernl-sdk/shared/lib";
|
|
2
|
+
import { memory } from "../tool/index.js";
|
|
3
|
+
import { MisconfiguredError } from "../lib/error.js";
|
|
4
|
+
import { AgentHooks } from "../lifecycle.js";
|
|
5
|
+
/**
|
|
6
|
+
* Abstract base class for all agent types.
|
|
7
|
+
*
|
|
8
|
+
* Provides common functionality shared between text-based agents (Agent)
|
|
9
|
+
* and realtime agents (RealtimeAgent).
|
|
10
|
+
*/
|
|
11
|
+
export class BaseAgent extends AgentHooks {
|
|
12
|
+
kernl;
|
|
13
|
+
id;
|
|
14
|
+
name;
|
|
15
|
+
description;
|
|
16
|
+
instructions;
|
|
17
|
+
toolkits;
|
|
18
|
+
systools;
|
|
19
|
+
memory;
|
|
20
|
+
constructor(config) {
|
|
21
|
+
super();
|
|
22
|
+
if (config.id.trim() === "") {
|
|
23
|
+
throw new MisconfiguredError("Agent must have an id.");
|
|
24
|
+
}
|
|
25
|
+
this.id = config.id;
|
|
26
|
+
this.name = config.name;
|
|
27
|
+
this.description = config.description;
|
|
28
|
+
this.instructions =
|
|
29
|
+
typeof config.instructions === "function"
|
|
30
|
+
? config.instructions
|
|
31
|
+
: () => config.instructions;
|
|
32
|
+
this.toolkits = config.toolkits ?? [];
|
|
33
|
+
this.systools = [];
|
|
34
|
+
this.memory = config.memory ?? { enabled: false };
|
|
35
|
+
for (const toolkit of this.toolkits) {
|
|
36
|
+
toolkit.bind(this);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Bind this agent to a kernl instance. Called by kernl.register().
|
|
41
|
+
*/
|
|
42
|
+
bind(kernl) {
|
|
43
|
+
this.kernl = kernl;
|
|
44
|
+
// initialize system toolkits
|
|
45
|
+
if (this.memory.enabled) {
|
|
46
|
+
// safety: system tools only rely on ctx.agent, not ctx.context
|
|
47
|
+
const toolkit = memory;
|
|
48
|
+
this.systools.push(toolkit);
|
|
49
|
+
toolkit.bind(this);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Get a specific tool by ID from systools and toolkits.
|
|
54
|
+
*/
|
|
55
|
+
tool(id) {
|
|
56
|
+
// check systools first
|
|
57
|
+
for (const toolkit of this.systools) {
|
|
58
|
+
const tool = toolkit.get(id);
|
|
59
|
+
if (tool)
|
|
60
|
+
return tool;
|
|
61
|
+
}
|
|
62
|
+
// then user toolkits
|
|
63
|
+
for (const toolkit of this.toolkits) {
|
|
64
|
+
const tool = toolkit.get(id);
|
|
65
|
+
if (tool)
|
|
66
|
+
return tool;
|
|
67
|
+
}
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Get all tools available from systools and toolkits for the given context.
|
|
72
|
+
*/
|
|
73
|
+
async tools(context) {
|
|
74
|
+
const all = [];
|
|
75
|
+
for (const toolkit of [...this.systools, ...this.toolkits]) {
|
|
76
|
+
all.push(...(await toolkit.list(context)));
|
|
77
|
+
}
|
|
78
|
+
const ids = all.map((t) => t.id);
|
|
79
|
+
const duplicates = ids.filter((id, i) => ids.indexOf(id) !== i);
|
|
80
|
+
if (duplicates.length > 0) {
|
|
81
|
+
throw new MisconfiguredError(`Duplicate tool IDs found: ${[...new Set(duplicates)].join(", ")}`);
|
|
82
|
+
}
|
|
83
|
+
return all;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Memory management scoped to this agent.
|
|
87
|
+
*/
|
|
88
|
+
get memories() {
|
|
89
|
+
if (!this.kernl) {
|
|
90
|
+
throw new MisconfiguredError(`Agent ${this.id} not bound to kernl. Call kernl.register(agent) first.`);
|
|
91
|
+
}
|
|
92
|
+
const agentId = this.id;
|
|
93
|
+
const kmem = this.kernl.memories;
|
|
94
|
+
return {
|
|
95
|
+
list: (params) => kmem.list({
|
|
96
|
+
filter: {
|
|
97
|
+
scope: { agentId },
|
|
98
|
+
collections: params?.collection ? [params.collection] : undefined,
|
|
99
|
+
},
|
|
100
|
+
limit: params?.limit,
|
|
101
|
+
}),
|
|
102
|
+
create: (params) => kmem.create({
|
|
103
|
+
id: params.id ?? `mem_${randomID()}`,
|
|
104
|
+
scope: {
|
|
105
|
+
namespace: params.namespace,
|
|
106
|
+
entityId: params.entityId,
|
|
107
|
+
agentId,
|
|
108
|
+
},
|
|
109
|
+
kind: "semantic",
|
|
110
|
+
collection: params.collection,
|
|
111
|
+
content: params.content,
|
|
112
|
+
wmem: params.wmem,
|
|
113
|
+
smem: params.smem,
|
|
114
|
+
timestamp: params.timestamp,
|
|
115
|
+
metadata: params.metadata,
|
|
116
|
+
}),
|
|
117
|
+
update: (params) => kmem.update({
|
|
118
|
+
id: params.id,
|
|
119
|
+
content: params.content,
|
|
120
|
+
collection: params.collection,
|
|
121
|
+
wmem: params.wmem,
|
|
122
|
+
smem: params.smem,
|
|
123
|
+
metadata: params.metadata,
|
|
124
|
+
}),
|
|
125
|
+
search: (params) => kmem.search({
|
|
126
|
+
...params,
|
|
127
|
+
filter: {
|
|
128
|
+
...params.filter,
|
|
129
|
+
scope: {
|
|
130
|
+
...params.filter?.scope,
|
|
131
|
+
agentId,
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
}),
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
}
|
package/dist/agent/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/agent/index.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/agent/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC"}
|
package/dist/agent/index.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
export * from "./base.js";
|
|
2
|
+
export * from "./types.js";
|
package/dist/agent/types.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/agent/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,KAAK,CAAC;AAEnC,OAAO,EACL,aAAa,EACb,4BAA4B,EAC7B,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAErC,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C;;GAEG;AACH,MAAM,WAAW,WAAW,CAC1B,QAAQ,GAAG,cAAc,EACzB,OAAO,SAAS,eAAe,GAAG,UAAU;IAE5C,EAAE,EAAE,MAAM,CAA2C;IACrD,IAAI,EAAE,MAAM,CAA8D;IAC1E,WAAW,CAAC,EAAE,MAAM,CAAkD;IAEtE;;;;;;;OAOG;IACH,YAAY,EACR,MAAM,GACN,CAAC,CAAC,OAAO,EAAE,OAAO,CAAC,QAAQ,CAAC,KAAK,OAAO,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC;IAS/D;;;;OAIG;IACH,KAAK,EAAE,aAAa,CAAC;IAErB;;OAEG;IACH,aAAa,CAAC,EAAE,4BAA4B,CAAC;IAE7C;;;;;;;;;;OAUG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IAEjB;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,QAAQ,CAAC,EAAE,WAAW,CAAC,QAAQ,CAAC,EAA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E,OAAO,CAAC,QAAQ,CAAC,KAAK,OAAO,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC;IAS/D;;;;OAIG;IACH,KAAK,EAAE,aAAa,CAAC;IAErB;;OAEG;IACH,aAAa,CAAC,EAAE,4BAA4B,CAAC;IAE7C;;;;;;;;;;OAUG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IAEjB;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,QAAQ,CAAC,EAAE,WAAW,CAAC,QAAQ,CAAC,EAAE,CAAC;IAEnC;;;;;OAKG;IACH,MAAM,CAAC,EAAE,iBAAiB,CAAC;IAE3B;;;OAGG;IACH,UAAU,CAAC,EAAE,eAAe,CAAC,OAAO,CAAC,CAAC;IAsBtC;;;OAGG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,WAAW,eAAe,CAAC,OAAO,SAAS,eAAe,GAAG,UAAU;IAC3E;;;OAGG;IACH,KAAK,EAAE,cAAc,EAAE,CAAC;IACxB;;;OAGG;IACH,MAAM,EAAE,eAAe,CAAC,OAAO,CAAC,EAAE,CAAC;CACpC;AAED;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG,UAAU,GAAG,OAAO,CAAC;AAEnD;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC;;OAEG;IACH,OAAO,EAAE,OAAO,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,KAAK,GAAG,UAAU,CAAC"}
|
package/dist/agent.d.ts
CHANGED
|
@@ -1,36 +1,21 @@
|
|
|
1
1
|
import { LanguageModel, LanguageModelItem, LanguageModelRequestSettings } from "@kernl-sdk/protocol";
|
|
2
|
-
import type { Kernl } from "./kernl/index.js";
|
|
3
2
|
import type { RThreadsListParams, RThreadCreateParams, RThreadGetOptions, RThreadHistoryParams, RThreadUpdateParams } from "./api/resources/threads/types.js";
|
|
4
|
-
import type {
|
|
5
|
-
import { Tool } from "./tool/index.js";
|
|
6
|
-
import { BaseToolkit } from "./tool/toolkit.js";
|
|
3
|
+
import type { UnknownContext } from "./context.js";
|
|
7
4
|
import { InputGuardrail, OutputGuardrail, type ResolvedAgentResponse } from "./guardrail.js";
|
|
8
|
-
import {
|
|
9
|
-
import type {
|
|
10
|
-
import type { AgentConfig, AgentMemoryConfig, AgentOutputType } from "./agent/types.js";
|
|
5
|
+
import { BaseAgent } from "./agent/base.js";
|
|
6
|
+
import type { AgentConfig, AgentOutputType } from "./agent/types.js";
|
|
11
7
|
import type { TextOutput, ThreadExecuteOptions, ThreadExecuteResult, ThreadStreamEvent } from "./thread/types.js";
|
|
12
|
-
export declare class Agent<TContext = UnknownContext, TOutput extends AgentOutputType = TextOutput> extends
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
instructions: (context: Context<TContext>) => Promise<string> | string;
|
|
18
|
-
model: LanguageModel;
|
|
19
|
-
modelSettings: LanguageModelRequestSettings;
|
|
20
|
-
toolkits: BaseToolkit<TContext>[];
|
|
21
|
-
systools: BaseToolkit<TContext>[];
|
|
22
|
-
memory: AgentMemoryConfig;
|
|
23
|
-
guardrails: {
|
|
8
|
+
export declare class Agent<TContext = UnknownContext, TOutput extends AgentOutputType = TextOutput> extends BaseAgent<TContext, TOutput> implements AgentConfig<TContext, TOutput> {
|
|
9
|
+
readonly kind = "llm";
|
|
10
|
+
readonly model: LanguageModel;
|
|
11
|
+
readonly modelSettings: LanguageModelRequestSettings;
|
|
12
|
+
readonly guardrails: {
|
|
24
13
|
input: InputGuardrail[];
|
|
25
14
|
output: OutputGuardrail<AgentOutputType>[];
|
|
26
15
|
};
|
|
27
|
-
output: TOutput;
|
|
28
|
-
resetToolChoice: boolean;
|
|
16
|
+
readonly output: TOutput;
|
|
17
|
+
readonly resetToolChoice: boolean;
|
|
29
18
|
constructor(config: AgentConfig<TContext, TOutput>);
|
|
30
|
-
/**
|
|
31
|
-
* Bind this agent to a kernl instance. Called by kernl.register().
|
|
32
|
-
*/
|
|
33
|
-
bind(kernl: Kernl): void;
|
|
34
19
|
/**
|
|
35
20
|
* Blocking execution - spawns or resumes thread and waits for completion
|
|
36
21
|
*
|
|
@@ -47,29 +32,6 @@ export declare class Agent<TContext = UnknownContext, TOutput extends AgentOutpu
|
|
|
47
32
|
* @throws {MisconfiguredError} If the agent is not bound to a kernl instance
|
|
48
33
|
*/
|
|
49
34
|
stream(input: string | LanguageModelItem[], options?: ThreadExecuteOptions<TContext>): AsyncIterable<ThreadStreamEvent>;
|
|
50
|
-
/**
|
|
51
|
-
* @internal
|
|
52
|
-
*
|
|
53
|
-
* Get a specific tool by ID from systools and toolkits.
|
|
54
|
-
*
|
|
55
|
-
* @param id The tool ID to look up
|
|
56
|
-
* @returns The tool if found, undefined otherwise
|
|
57
|
-
*/
|
|
58
|
-
tool(id: string): Tool<TContext> | undefined;
|
|
59
|
-
/**
|
|
60
|
-
* @internal
|
|
61
|
-
*
|
|
62
|
-
* Get all tools available from systools and toolkits for the given context.
|
|
63
|
-
* Checks for duplicate tool IDs across toolkits and throws an error if found.
|
|
64
|
-
*
|
|
65
|
-
* (TODO): Consider returning toolkits alongside tools so we can serialize them
|
|
66
|
-
* together and give agents more options for dealing with tool groups.
|
|
67
|
-
*
|
|
68
|
-
* @param context The context to use for filtering tools
|
|
69
|
-
* @returns Array of all available tools
|
|
70
|
-
* @throws {MisconfiguredError} If duplicate tool IDs are found across toolkits
|
|
71
|
-
*/
|
|
72
|
-
tools(context: Context<TContext>): Promise<Tool<TContext>[]>;
|
|
73
35
|
/**
|
|
74
36
|
* Thread management scoped to this agent.
|
|
75
37
|
*
|
|
@@ -83,47 +45,5 @@ export declare class Agent<TContext = UnknownContext, TOutput extends AgentOutpu
|
|
|
83
45
|
create: (params: Omit<RThreadCreateParams, "agentId" | "model">) => Promise<import("./index.js").Thread>;
|
|
84
46
|
update: (tid: string, patch: RThreadUpdateParams) => Promise<import("./index.js").Thread | null>;
|
|
85
47
|
};
|
|
86
|
-
/**
|
|
87
|
-
* Memory management scoped to this agent.
|
|
88
|
-
*
|
|
89
|
-
* Provides a simplified API for creating memories with:
|
|
90
|
-
* - Auto-generated IDs
|
|
91
|
-
* - Flattened scope fields (namespace, entityId) - agentId is implicit
|
|
92
|
-
* - Default kind of "semantic"
|
|
93
|
-
*
|
|
94
|
-
* @example
|
|
95
|
-
* ```ts
|
|
96
|
-
* await agent.memories.create({
|
|
97
|
-
* namespace: "user-123",
|
|
98
|
-
* collection: "preferences",
|
|
99
|
-
* content: { text: "User prefers TypeScript" },
|
|
100
|
-
* });
|
|
101
|
-
* ```
|
|
102
|
-
*/
|
|
103
|
-
get memories(): {
|
|
104
|
-
/**
|
|
105
|
-
* List memories scoped to this agent.
|
|
106
|
-
*/
|
|
107
|
-
list: (params?: Omit<MemoryListOptions, "filter"> & {
|
|
108
|
-
collection?: string;
|
|
109
|
-
limit?: number;
|
|
110
|
-
}) => Promise<import("./memory/index.js").MemoryRecord[]>;
|
|
111
|
-
/**
|
|
112
|
-
* Create a new memory scoped to this agent.
|
|
113
|
-
*/
|
|
114
|
-
create: (params: AgentMemoryCreate) => Promise<import("./memory/index.js").MemoryRecord>;
|
|
115
|
-
/**
|
|
116
|
-
* Update an existing memory scoped to this agent.
|
|
117
|
-
*/
|
|
118
|
-
update: (params: AgentMemoryUpdate) => Promise<import("./memory/index.js").MemoryRecord>;
|
|
119
|
-
/**
|
|
120
|
-
* Search memories scoped to this agent.
|
|
121
|
-
*/
|
|
122
|
-
search: (params: Omit<MemorySearchQuery, "filter"> & {
|
|
123
|
-
filter?: Omit<NonNullable<MemorySearchQuery["filter"]>, "scope"> & {
|
|
124
|
-
scope?: Omit<NonNullable<NonNullable<MemorySearchQuery["filter"]>["scope"]>, "agentId">;
|
|
125
|
-
};
|
|
126
|
-
}) => Promise<import("@kernl-sdk/retrieval").SearchHit<import("./memory/index.js").IndexMemoryRecord>[]>;
|
|
127
|
-
};
|
|
128
48
|
}
|
|
129
49
|
//# sourceMappingURL=agent.d.ts.map
|
package/dist/agent.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,aAAa,EACb,iBAAiB,EACjB,4BAA4B,EAC7B,MAAM,qBAAqB,CAAC;AAG7B,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,aAAa,EACb,iBAAiB,EACjB,4BAA4B,EAC7B,MAAM,qBAAqB,CAAC;AAG7B,OAAO,KAAK,EACV,kBAAkB,EAClB,mBAAmB,EACnB,iBAAiB,EACjB,oBAAoB,EACpB,mBAAmB,EACpB,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAW,cAAc,EAAE,MAAM,WAAW,CAAC;AACzD,OAAO,EACL,cAAc,EACd,eAAe,EACf,KAAK,qBAAqB,EAC3B,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAIzC,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAClE,OAAO,KAAK,EACV,UAAU,EACV,oBAAoB,EACpB,mBAAmB,EACnB,iBAAiB,EAClB,MAAM,gBAAgB,CAAC;AAExB,qBAAa,KAAK,CACd,QAAQ,GAAG,cAAc,EACzB,OAAO,SAAS,eAAe,GAAG,UAAU,CAE9C,SAAQ,SAAS,CAAC,QAAQ,EAAE,OAAO,CACnC,YAAW,WAAW,CAAC,QAAQ,EAAE,OAAO,CAAC;IAEzC,QAAQ,CAAC,IAAI,SAAS;IACtB,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC;IAC9B,QAAQ,CAAC,aAAa,EAAE,4BAA4B,CAAC;IAErD,QAAQ,CAAC,UAAU,EAAE;QACnB,KAAK,EAAE,cAAc,EAAE,CAAC;QACxB,MAAM,EAAE,eAAe,CAAC,eAAe,CAAC,EAAE,CAAC;KAC5C,CAAC;IACF,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAqB;IAC7C,QAAQ,CAAC,eAAe,EAAE,OAAO,CAAC;gBAEtB,MAAM,EAAE,WAAW,CAAC,QAAQ,EAAE,OAAO,CAAC;IAYlD;;;;;OAKG;IACG,GAAG,CACP,KAAK,EAAE,MAAM,GAAG,iBAAiB,EAAE,EACnC,OAAO,CAAC,EAAE,oBAAoB,CAAC,QAAQ,CAAC,GACvC,OAAO,CAAC,mBAAmB,CAAC,qBAAqB,CAAC,OAAO,CAAC,CAAC,CAAC;IAkD/D;;;;;;;OAOG;IACI,MAAM,CACX,KAAK,EAAE,MAAM,GAAG,iBAAiB,EAAE,EACnC,OAAO,CAAC,EAAE,oBAAoB,CAAC,QAAQ,CAAC,GACvC,aAAa,CAAC,iBAAiB,CAAC;IAmDnC;;;;OAIG;IACH,IAAI,OAAO;mBAWI,MAAM,YAAY,iBAAiB;wBAE/B,IAAI,CAAC,kBAAkB,EAAE,SAAS,CAAC;sBAEpC,MAAM;uBACL,MAAM,WAAW,oBAAoB;yBAEnC,IAAI,CAAC,mBAAmB,EAAE,SAAS,GAAG,OAAO,CAAC;sBASjD,MAAM,SAAS,mBAAmB;MAGnD;CACF"}
|
package/dist/agent.js
CHANGED
|
@@ -1,63 +1,23 @@
|
|
|
1
1
|
import { message, } from "@kernl-sdk/protocol";
|
|
2
2
|
import { Thread } from "./thread/index.js";
|
|
3
|
-
import {
|
|
4
|
-
import { AgentHooks } from "./lifecycle.js";
|
|
5
|
-
import { randomID } from "@kernl-sdk/shared/lib";
|
|
3
|
+
import { BaseAgent } from "./agent/base.js";
|
|
6
4
|
import { MisconfiguredError, RuntimeError } from "./lib/error.js";
|
|
7
|
-
export class Agent extends
|
|
8
|
-
|
|
9
|
-
id;
|
|
10
|
-
name;
|
|
11
|
-
description;
|
|
12
|
-
instructions;
|
|
5
|
+
export class Agent extends BaseAgent {
|
|
6
|
+
kind = "llm";
|
|
13
7
|
model;
|
|
14
8
|
modelSettings;
|
|
15
|
-
// actions: ActionSet; /* TODO */
|
|
16
|
-
toolkits;
|
|
17
|
-
systools;
|
|
18
|
-
memory;
|
|
19
9
|
guardrails;
|
|
20
10
|
output = "text";
|
|
21
11
|
resetToolChoice;
|
|
22
12
|
constructor(config) {
|
|
23
|
-
super();
|
|
24
|
-
|
|
25
|
-
throw new MisconfiguredError("Agent must have an id.");
|
|
26
|
-
}
|
|
27
|
-
this.id = config.id;
|
|
28
|
-
this.name = config.name;
|
|
29
|
-
this.description = config.description;
|
|
30
|
-
this.instructions =
|
|
31
|
-
typeof config.instructions === "function"
|
|
32
|
-
? config.instructions
|
|
33
|
-
: () => config.instructions;
|
|
34
|
-
this.model = config.model; // (TODO): include optional default setting for convenience like env.DEFAULT_LLM = "gpt-5"
|
|
13
|
+
super(config);
|
|
14
|
+
this.model = config.model;
|
|
35
15
|
this.modelSettings = config.modelSettings ?? {};
|
|
36
|
-
this.toolkits = config.toolkits ?? [];
|
|
37
|
-
this.systools = [];
|
|
38
|
-
this.memory = config.memory ?? { enabled: false };
|
|
39
|
-
for (const toolkit of this.toolkits) {
|
|
40
|
-
toolkit.bind(this);
|
|
41
|
-
}
|
|
42
16
|
this.guardrails = config.guardrails ?? { input: [], output: [] };
|
|
43
17
|
if (config.output) {
|
|
44
18
|
this.output = config.output;
|
|
45
19
|
}
|
|
46
20
|
this.resetToolChoice = config.resetToolChoice ?? true;
|
|
47
|
-
// this.toolUseBehavior = config.toolUseBehavior ?? "run_llm_again";
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Bind this agent to a kernl instance. Called by kernl.register().
|
|
51
|
-
*/
|
|
52
|
-
bind(kernl) {
|
|
53
|
-
this.kernl = kernl;
|
|
54
|
-
// initialize system toolkits
|
|
55
|
-
if (this.memory.enabled) {
|
|
56
|
-
// safety: system tools only rely on ctx.agent, not ctx.context
|
|
57
|
-
const toolkit = memory;
|
|
58
|
-
this.systools.push(toolkit);
|
|
59
|
-
toolkit.bind(this);
|
|
60
|
-
}
|
|
61
21
|
}
|
|
62
22
|
/**
|
|
63
23
|
* Blocking execution - spawns or resumes thread and waits for completion
|
|
@@ -154,54 +114,6 @@ export class Agent extends AgentHooks {
|
|
|
154
114
|
thread.append(...items);
|
|
155
115
|
yield* this.kernl.scheduleStream(thread);
|
|
156
116
|
}
|
|
157
|
-
/**
|
|
158
|
-
* @internal
|
|
159
|
-
*
|
|
160
|
-
* Get a specific tool by ID from systools and toolkits.
|
|
161
|
-
*
|
|
162
|
-
* @param id The tool ID to look up
|
|
163
|
-
* @returns The tool if found, undefined otherwise
|
|
164
|
-
*/
|
|
165
|
-
tool(id) {
|
|
166
|
-
// Check systools first
|
|
167
|
-
for (const toolkit of this.systools) {
|
|
168
|
-
const tool = toolkit.get(id);
|
|
169
|
-
if (tool)
|
|
170
|
-
return tool;
|
|
171
|
-
}
|
|
172
|
-
// Then user toolkits
|
|
173
|
-
for (const toolkit of this.toolkits) {
|
|
174
|
-
const tool = toolkit.get(id);
|
|
175
|
-
if (tool)
|
|
176
|
-
return tool;
|
|
177
|
-
}
|
|
178
|
-
return undefined;
|
|
179
|
-
}
|
|
180
|
-
/**
|
|
181
|
-
* @internal
|
|
182
|
-
*
|
|
183
|
-
* Get all tools available from systools and toolkits for the given context.
|
|
184
|
-
* Checks for duplicate tool IDs across toolkits and throws an error if found.
|
|
185
|
-
*
|
|
186
|
-
* (TODO): Consider returning toolkits alongside tools so we can serialize them
|
|
187
|
-
* together and give agents more options for dealing with tool groups.
|
|
188
|
-
*
|
|
189
|
-
* @param context The context to use for filtering tools
|
|
190
|
-
* @returns Array of all available tools
|
|
191
|
-
* @throws {MisconfiguredError} If duplicate tool IDs are found across toolkits
|
|
192
|
-
*/
|
|
193
|
-
async tools(context) {
|
|
194
|
-
const all = [];
|
|
195
|
-
for (const toolkit of [...this.systools, ...this.toolkits]) {
|
|
196
|
-
all.push(...(await toolkit.list(context)));
|
|
197
|
-
}
|
|
198
|
-
const ids = all.map((t) => t.id);
|
|
199
|
-
const duplicates = ids.filter((id, i) => ids.indexOf(id) !== i);
|
|
200
|
-
if (duplicates.length > 0) {
|
|
201
|
-
throw new MisconfiguredError(`Duplicate tool IDs found: ${[...new Set(duplicates)].join(", ")}`);
|
|
202
|
-
}
|
|
203
|
-
return all;
|
|
204
|
-
}
|
|
205
117
|
/**
|
|
206
118
|
* Thread management scoped to this agent.
|
|
207
119
|
*
|
|
@@ -229,82 +141,4 @@ export class Agent extends AgentHooks {
|
|
|
229
141
|
update: (tid, patch) => kthreads.update(tid, patch),
|
|
230
142
|
};
|
|
231
143
|
}
|
|
232
|
-
/**
|
|
233
|
-
* Memory management scoped to this agent.
|
|
234
|
-
*
|
|
235
|
-
* Provides a simplified API for creating memories with:
|
|
236
|
-
* - Auto-generated IDs
|
|
237
|
-
* - Flattened scope fields (namespace, entityId) - agentId is implicit
|
|
238
|
-
* - Default kind of "semantic"
|
|
239
|
-
*
|
|
240
|
-
* @example
|
|
241
|
-
* ```ts
|
|
242
|
-
* await agent.memories.create({
|
|
243
|
-
* namespace: "user-123",
|
|
244
|
-
* collection: "preferences",
|
|
245
|
-
* content: { text: "User prefers TypeScript" },
|
|
246
|
-
* });
|
|
247
|
-
* ```
|
|
248
|
-
*/
|
|
249
|
-
get memories() {
|
|
250
|
-
if (!this.kernl) {
|
|
251
|
-
throw new MisconfiguredError(`Agent ${this.id} not bound to kernl. Call kernl.register(agent) first.`);
|
|
252
|
-
}
|
|
253
|
-
const agentId = this.id;
|
|
254
|
-
const kmem = this.kernl.memories;
|
|
255
|
-
return {
|
|
256
|
-
/**
|
|
257
|
-
* List memories scoped to this agent.
|
|
258
|
-
*/
|
|
259
|
-
list: (params) => kmem.list({
|
|
260
|
-
filter: {
|
|
261
|
-
scope: { agentId },
|
|
262
|
-
collections: params?.collection ? [params.collection] : undefined,
|
|
263
|
-
},
|
|
264
|
-
limit: params?.limit,
|
|
265
|
-
}),
|
|
266
|
-
/**
|
|
267
|
-
* Create a new memory scoped to this agent.
|
|
268
|
-
*/
|
|
269
|
-
create: (params) => kmem.create({
|
|
270
|
-
id: params.id ?? `mem_${randomID()}`,
|
|
271
|
-
scope: {
|
|
272
|
-
namespace: params.namespace,
|
|
273
|
-
entityId: params.entityId,
|
|
274
|
-
agentId,
|
|
275
|
-
},
|
|
276
|
-
kind: "semantic",
|
|
277
|
-
collection: params.collection,
|
|
278
|
-
content: params.content,
|
|
279
|
-
wmem: params.wmem,
|
|
280
|
-
smem: params.smem,
|
|
281
|
-
timestamp: params.timestamp,
|
|
282
|
-
metadata: params.metadata,
|
|
283
|
-
}),
|
|
284
|
-
/**
|
|
285
|
-
* Update an existing memory scoped to this agent.
|
|
286
|
-
*/
|
|
287
|
-
update: (params) => kmem.update({
|
|
288
|
-
id: params.id,
|
|
289
|
-
content: params.content,
|
|
290
|
-
collection: params.collection,
|
|
291
|
-
wmem: params.wmem,
|
|
292
|
-
smem: params.smem,
|
|
293
|
-
metadata: params.metadata,
|
|
294
|
-
}),
|
|
295
|
-
/**
|
|
296
|
-
* Search memories scoped to this agent.
|
|
297
|
-
*/
|
|
298
|
-
search: (params) => kmem.search({
|
|
299
|
-
...params,
|
|
300
|
-
filter: {
|
|
301
|
-
...params.filter,
|
|
302
|
-
scope: {
|
|
303
|
-
...params.filter?.scope,
|
|
304
|
-
agentId,
|
|
305
|
-
},
|
|
306
|
-
},
|
|
307
|
-
}),
|
|
308
|
-
};
|
|
309
|
-
}
|
|
310
144
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Agent } from "../../../agent.js";
|
|
2
|
+
import type { BaseAgent } from "../../../agent/base.js";
|
|
2
3
|
import type { AgentOutputType } from "../../../agent/types.js";
|
|
3
4
|
import type { UnknownContext } from "../../../context.js";
|
|
4
5
|
import type { TextOutput } from "../../../thread/types.js";
|
|
@@ -8,26 +9,29 @@ import type { TextOutput } from "../../../thread/types.js";
|
|
|
8
9
|
* Thin facade over the in-process agent registry, returning live Agent instances.
|
|
9
10
|
*
|
|
10
11
|
* Note: agents are code, not persisted data; this is process-local.
|
|
12
|
+
*
|
|
13
|
+
* Currently only exposes LLM agents (kind: "llm"). RealtimeAgents are stored
|
|
14
|
+
* in the internal registry but not returned by these methods. If public access
|
|
15
|
+
* to realtime agents is needed, add a separate `kernl.realtimeAgents` resource.
|
|
11
16
|
*/
|
|
12
17
|
export declare class RAgents {
|
|
13
18
|
private readonly registry;
|
|
14
|
-
constructor(registry: Map<string,
|
|
19
|
+
constructor(registry: Map<string, BaseAgent>);
|
|
15
20
|
/**
|
|
16
21
|
* Get a live Agent instance by id.
|
|
17
22
|
*
|
|
23
|
+
* Only returns LLM agents. Returns undefined for realtime agents.
|
|
24
|
+
*
|
|
18
25
|
* Callers are expected to know the concrete TContext/TOutput types
|
|
19
26
|
* for their own agents and can specify them via generics.
|
|
20
27
|
*/
|
|
21
28
|
get<TContext = UnknownContext, TOutput extends AgentOutputType = TextOutput>(id: string): Agent<TContext, TOutput> | undefined;
|
|
22
29
|
/**
|
|
23
|
-
* Check if an agent with the given id is registered.
|
|
30
|
+
* Check if an LLM agent with the given id is registered.
|
|
24
31
|
*/
|
|
25
32
|
has(id: string): boolean;
|
|
26
33
|
/**
|
|
27
|
-
* List all registered agents as live instances.
|
|
28
|
-
*
|
|
29
|
-
* Since this is a heterogeneous collection, we expose the widest safe
|
|
30
|
-
* type parameters here.
|
|
34
|
+
* List all registered LLM agents as live instances.
|
|
31
35
|
*/
|
|
32
36
|
list(): Agent<UnknownContext, AgentOutputType>[];
|
|
33
37
|
/**
|