@aigne/core 1.20.1 → 1.22.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 (75) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/lib/cjs/agents/agent.d.ts +6 -4
  3. package/lib/cjs/agents/agent.js +2 -0
  4. package/lib/cjs/agents/ai-agent.d.ts +8 -10
  5. package/lib/cjs/agents/ai-agent.js +6 -5
  6. package/lib/cjs/agents/chat-model.d.ts +1 -0
  7. package/lib/cjs/agents/chat-model.js +1 -0
  8. package/lib/cjs/agents/mcp-agent.d.ts +5 -0
  9. package/lib/cjs/agents/mcp-agent.js +5 -0
  10. package/lib/cjs/agents/team-agent.d.ts +1 -0
  11. package/lib/cjs/agents/team-agent.js +1 -0
  12. package/lib/cjs/agents/user-agent.d.ts +1 -0
  13. package/lib/cjs/agents/user-agent.js +6 -3
  14. package/lib/cjs/aigne/aigne.d.ts +15 -6
  15. package/lib/cjs/aigne/aigne.js +19 -2
  16. package/lib/cjs/aigne/context.d.ts +31 -10
  17. package/lib/cjs/aigne/context.js +86 -14
  18. package/lib/cjs/loader/agent-js.d.ts +2 -2
  19. package/lib/cjs/loader/agent-js.js +3 -0
  20. package/lib/cjs/loader/agent-yaml.d.ts +23 -6
  21. package/lib/cjs/loader/agent-yaml.js +38 -2
  22. package/lib/cjs/loader/index.d.ts +1 -1
  23. package/lib/cjs/loader/index.js +16 -4
  24. package/lib/cjs/memory/memory.d.ts +1 -0
  25. package/lib/cjs/memory/memory.js +1 -0
  26. package/lib/cjs/memory/recorder.d.ts +1 -0
  27. package/lib/cjs/memory/recorder.js +1 -0
  28. package/lib/cjs/memory/retriever.d.ts +1 -0
  29. package/lib/cjs/memory/retriever.js +1 -0
  30. package/lib/cjs/prompt/prompt-builder.d.ts +1 -1
  31. package/lib/dts/agents/agent.d.ts +6 -4
  32. package/lib/dts/agents/ai-agent.d.ts +8 -10
  33. package/lib/dts/agents/chat-model.d.ts +1 -0
  34. package/lib/dts/agents/mcp-agent.d.ts +5 -0
  35. package/lib/dts/agents/team-agent.d.ts +1 -0
  36. package/lib/dts/agents/user-agent.d.ts +1 -0
  37. package/lib/dts/aigne/aigne.d.ts +15 -6
  38. package/lib/dts/aigne/context.d.ts +31 -10
  39. package/lib/dts/loader/agent-js.d.ts +2 -2
  40. package/lib/dts/loader/agent-yaml.d.ts +23 -6
  41. package/lib/dts/loader/index.d.ts +1 -1
  42. package/lib/dts/memory/memory.d.ts +1 -0
  43. package/lib/dts/memory/recorder.d.ts +1 -0
  44. package/lib/dts/memory/retriever.d.ts +1 -0
  45. package/lib/dts/prompt/prompt-builder.d.ts +1 -1
  46. package/lib/esm/agents/agent.d.ts +6 -4
  47. package/lib/esm/agents/agent.js +2 -0
  48. package/lib/esm/agents/ai-agent.d.ts +8 -10
  49. package/lib/esm/agents/ai-agent.js +3 -2
  50. package/lib/esm/agents/chat-model.d.ts +1 -0
  51. package/lib/esm/agents/chat-model.js +1 -0
  52. package/lib/esm/agents/mcp-agent.d.ts +5 -0
  53. package/lib/esm/agents/mcp-agent.js +5 -0
  54. package/lib/esm/agents/team-agent.d.ts +1 -0
  55. package/lib/esm/agents/team-agent.js +1 -0
  56. package/lib/esm/agents/user-agent.d.ts +1 -0
  57. package/lib/esm/agents/user-agent.js +6 -3
  58. package/lib/esm/aigne/aigne.d.ts +15 -6
  59. package/lib/esm/aigne/aigne.js +19 -2
  60. package/lib/esm/aigne/context.d.ts +31 -10
  61. package/lib/esm/aigne/context.js +86 -14
  62. package/lib/esm/loader/agent-js.d.ts +2 -2
  63. package/lib/esm/loader/agent-js.js +3 -0
  64. package/lib/esm/loader/agent-yaml.d.ts +23 -6
  65. package/lib/esm/loader/agent-yaml.js +38 -2
  66. package/lib/esm/loader/index.d.ts +1 -1
  67. package/lib/esm/loader/index.js +17 -5
  68. package/lib/esm/memory/memory.d.ts +1 -0
  69. package/lib/esm/memory/memory.js +1 -0
  70. package/lib/esm/memory/recorder.d.ts +1 -0
  71. package/lib/esm/memory/recorder.js +1 -0
  72. package/lib/esm/memory/retriever.d.ts +1 -0
  73. package/lib/esm/memory/retriever.js +1 -0
  74. package/lib/esm/prompt/prompt-builder.d.ts +1 -1
  75. package/package.json +2 -1
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.AIGNEContext = void 0;
7
+ const api_1 = require("@opentelemetry/api");
7
8
  const fast_deep_equal_1 = __importDefault(require("fast-deep-equal"));
8
9
  const strict_event_emitter_1 = require("strict-event-emitter");
9
10
  const uuid_1 = require("uuid");
@@ -12,6 +13,7 @@ const agent_js_1 = require("../agents/agent.js");
12
13
  const types_js_1 = require("../agents/types.js");
13
14
  const user_agent_js_1 = require("../agents/user-agent.js");
14
15
  const event_stream_js_1 = require("../utils/event-stream.js");
16
+ const logger_js_1 = require("../utils/logger.js");
15
17
  const promise_js_1 = require("../utils/promise.js");
16
18
  const stream_utils_js_1 = require("../utils/stream-utils.js");
17
19
  const type_utils_js_1 = require("../utils/type-utils.js");
@@ -21,24 +23,47 @@ const usage_js_1 = require("./usage.js");
21
23
  * @hidden
22
24
  */
23
25
  class AIGNEContext {
24
- constructor(...[parent, ...args]) {
25
- if (parent instanceof AIGNEContext) {
26
- this.parentId = parent.id;
26
+ constructor(parent, { reset } = {}) {
27
+ const tracer = parent?.observer?.tracer;
28
+ if (parent instanceof AIGNEContext && !reset) {
27
29
  this.internal = parent.internal;
30
+ this.parentId = parent.id;
31
+ this.rootId = parent.rootId;
32
+ if (parent.span) {
33
+ const parentContext = api_1.trace.setSpan(api_1.context.active(), parent.span);
34
+ this.span = tracer?.startSpan("childAIGNEContext", undefined, parentContext);
35
+ }
36
+ else {
37
+ if (!process.env.AIGNE_OBSERVABILITY_DISABLED) {
38
+ throw new Error("parent span is not set");
39
+ }
40
+ }
28
41
  }
29
42
  else {
30
- this.internal = new AIGNEContextShared(parent, ...args);
43
+ this.internal = new AIGNEContextShared(parent);
44
+ this.span = tracer?.startSpan("AIGNEContext");
45
+ // 修改了 rootId 是否会之前的有影响?,之前为 this.id
46
+ this.rootId = this.span?.spanContext?.().traceId ?? (0, uuid_1.v7)();
31
47
  }
48
+ this.id = this.span?.spanContext()?.spanId ?? (0, uuid_1.v7)();
32
49
  }
50
+ id;
33
51
  parentId;
34
- id = (0, uuid_1.v7)();
52
+ rootId;
53
+ span;
35
54
  internal;
55
+ get messageQueue() {
56
+ return this.internal.messageQueue;
57
+ }
36
58
  get model() {
37
59
  return this.internal.model;
38
60
  }
39
61
  get skills() {
40
62
  return this.internal.skills;
41
63
  }
64
+ get observer() {
65
+ return this.internal.observer;
66
+ }
42
67
  get limits() {
43
68
  return this.internal.limits;
44
69
  }
@@ -61,9 +86,7 @@ class AIGNEContext {
61
86
  this.internal.memories = memories;
62
87
  }
63
88
  newContext({ reset } = {}) {
64
- if (reset)
65
- return new AIGNEContext(this, { userContext: {} });
66
- return new AIGNEContext(this);
89
+ return new AIGNEContext(this, { reset });
67
90
  }
68
91
  invoke = ((agent, message, options) => {
69
92
  (0, type_utils_js_1.checkArguments)("AIGNEContext.invoke", aigneContextInvokeArgsSchema, {
@@ -85,7 +108,7 @@ class AIGNEContext {
85
108
  activeAgent: agent,
86
109
  });
87
110
  }
88
- const newContext = this.newContext();
111
+ const newContext = options?.newContext === false ? this : this.newContext();
89
112
  return Promise.resolve(newContext.internal.invoke(agent, message, newContext, options)).then(async (response) => {
90
113
  if (!options?.streaming) {
91
114
  let { __activeAgent__: activeAgent, ...output } = await (0, stream_utils_js_1.agentResponseStreamToObject)(response);
@@ -162,8 +185,55 @@ class AIGNEContext {
162
185
  timestamp: Date.now(),
163
186
  };
164
187
  const newArgs = [b, ...args.slice(1)];
188
+ this.trace(eventName, args, b);
165
189
  return this.internal.events.emit(eventName, ...newArgs);
166
190
  }
191
+ async trace(eventName, args, b) {
192
+ const span = this.span;
193
+ if (!span)
194
+ return;
195
+ try {
196
+ switch (eventName) {
197
+ case "agentStarted": {
198
+ const { agent, input } = args[0];
199
+ span.updateName(agent.name);
200
+ span.setAttribute("custom.trace_id", this.rootId);
201
+ span.setAttribute("custom.span_id", this.id);
202
+ if (this.parentId) {
203
+ span.setAttribute("custom.parent_id", this.parentId);
204
+ }
205
+ span.setAttribute("custom.started_at", b.timestamp);
206
+ span.setAttribute("input", JSON.stringify(input));
207
+ span.setAttribute("agentTag", agent.tag ?? "UnknownAgent");
208
+ break;
209
+ }
210
+ case "agentSucceed": {
211
+ const { output } = args[0];
212
+ try {
213
+ span.setAttribute("output", JSON.stringify(output));
214
+ }
215
+ catch (_e) {
216
+ logger_js_1.logger.error("parse output error", _e.message);
217
+ span.setAttribute("output", JSON.stringify({}));
218
+ }
219
+ span.setStatus({ code: api_1.SpanStatusCode.OK, message: "Agent succeed" });
220
+ span.end();
221
+ await this.observer?.traceExporter?.forceFlush?.();
222
+ break;
223
+ }
224
+ case "agentFailed": {
225
+ const { error } = args[0];
226
+ span.setStatus({ code: api_1.SpanStatusCode.ERROR, message: error.message });
227
+ span.end();
228
+ await this.observer?.traceExporter?.forceFlush?.();
229
+ break;
230
+ }
231
+ }
232
+ }
233
+ catch (err) {
234
+ logger_js_1.logger.error("AIGNEContext.trace observer error", { eventName, error: err });
235
+ }
236
+ }
167
237
  on(eventName, listener) {
168
238
  this.internal.events.on(eventName, listener);
169
239
  return this;
@@ -180,11 +250,10 @@ class AIGNEContext {
180
250
  exports.AIGNEContext = AIGNEContext;
181
251
  class AIGNEContextShared {
182
252
  parent;
183
- constructor(parent, overrides) {
253
+ span;
254
+ constructor(parent) {
184
255
  this.parent = parent;
185
256
  this.messageQueue = this.parent?.messageQueue ?? new message_queue_js_1.MessageQueue();
186
- this.userContext = overrides?.userContext ?? {};
187
- this.memories = overrides?.memories ?? [];
188
257
  }
189
258
  messageQueue;
190
259
  events = new strict_event_emitter_1.Emitter();
@@ -194,12 +263,15 @@ class AIGNEContextShared {
194
263
  get skills() {
195
264
  return this.parent?.skills;
196
265
  }
266
+ get observer() {
267
+ return this.parent?.observer;
268
+ }
197
269
  get limits() {
198
270
  return this.parent?.limits;
199
271
  }
200
272
  usage = (0, usage_js_1.newEmptyContextUsage)();
201
- userContext;
202
- memories;
273
+ userContext = {};
274
+ memories = [];
203
275
  abortController = new AbortController();
204
276
  timer;
205
277
  initTimeout() {
@@ -1,6 +1,6 @@
1
1
  import { type ZodObject, type ZodType, z } from "zod";
2
- import type { Message } from "../agents/agent.js";
3
- export declare function loadAgentFromJsFile(path: string): Promise<{
2
+ import { Agent, type Message } from "../agents/agent.js";
3
+ export declare function loadAgentFromJsFile(path: string): Promise<Agent<any, any> | {
4
4
  process: (args_0: Message) => Message;
5
5
  name: string;
6
6
  description?: string | undefined;
@@ -36,6 +36,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.loadAgentFromJsFile = loadAgentFromJsFile;
37
37
  const json_schema_to_zod_1 = require("@aigne/json-schema-to-zod");
38
38
  const zod_1 = require("zod");
39
+ const agent_js_1 = require("../agents/agent.js");
39
40
  const camelize_js_1 = require("../utils/camelize.js");
40
41
  const type_utils_js_1 = require("../utils/type-utils.js");
41
42
  const schema_js_1 = require("./schema.js");
@@ -55,6 +56,8 @@ const agentJsFileSchema = zod_1.z.object({
55
56
  });
56
57
  async function loadAgentFromJsFile(path) {
57
58
  const { default: agent } = await (0, type_utils_js_1.tryOrThrow)(() => Promise.resolve(`${path}`).then(s => __importStar(require(s))), (error) => new Error(`Failed to load agent definition from ${path}: ${error.message}`));
59
+ if (agent instanceof agent_js_1.Agent)
60
+ return agent;
58
61
  if (typeof agent !== "function") {
59
62
  throw new Error(`Agent file ${path} must export a default function, but got ${typeof agent}`);
60
63
  }
@@ -1,6 +1,29 @@
1
1
  import { type ZodObject, type ZodType, z } from "zod";
2
2
  import { AIAgentToolChoice } from "../agents/ai-agent.js";
3
+ import { ProcessMode } from "../agents/team-agent.js";
3
4
  export declare function loadAgentFromYamlFile(path: string): Promise<{
5
+ type: "mcp";
6
+ url?: string | undefined;
7
+ command?: string | undefined;
8
+ args?: string[] | undefined;
9
+ } | {
10
+ type: "team";
11
+ name: string;
12
+ description?: string | undefined;
13
+ skills?: string[] | undefined;
14
+ mode?: ProcessMode | undefined;
15
+ inputSchema?: ZodObject<Record<string, ZodType<any, z.ZodTypeDef, any>>, z.UnknownKeysParam, z.ZodTypeAny, {
16
+ [x: string]: any;
17
+ }, {
18
+ [x: string]: any;
19
+ }> | undefined;
20
+ outputSchema?: ZodObject<Record<string, ZodType<any, z.ZodTypeDef, any>>, z.UnknownKeysParam, z.ZodTypeAny, {
21
+ [x: string]: any;
22
+ }, {
23
+ [x: string]: any;
24
+ }> | undefined;
25
+ } | {
26
+ instructions: string | undefined;
4
27
  type: "ai";
5
28
  name: string;
6
29
  description?: string | undefined;
@@ -9,7 +32,6 @@ export declare function loadAgentFromYamlFile(path: string): Promise<{
9
32
  provider: string;
10
33
  subscribeTopic?: string[] | undefined;
11
34
  } | undefined;
12
- instructions?: string | undefined;
13
35
  inputSchema?: ZodObject<Record<string, ZodType<any, z.ZodTypeDef, any>>, z.UnknownKeysParam, z.ZodTypeAny, {
14
36
  [x: string]: any;
15
37
  }, {
@@ -23,9 +45,4 @@ export declare function loadAgentFromYamlFile(path: string): Promise<{
23
45
  inputKey?: string | undefined;
24
46
  outputKey?: string | undefined;
25
47
  toolChoice?: AIAgentToolChoice | undefined;
26
- } | {
27
- type: "mcp";
28
- url?: string | undefined;
29
- args?: string[] | undefined;
30
- command?: string | undefined;
31
48
  }>;
@@ -6,6 +6,7 @@ const index_js_1 = require("@aigne/platform-helpers/nodejs/index.js");
6
6
  const yaml_1 = require("yaml");
7
7
  const zod_1 = require("zod");
8
8
  const ai_agent_js_1 = require("../agents/ai-agent.js");
9
+ const team_agent_js_1 = require("../agents/team-agent.js");
9
10
  const camelize_js_1 = require("../utils/camelize.js");
10
11
  const type_utils_js_1 = require("../utils/type-utils.js");
11
12
  const schema_js_1 = require("./schema.js");
@@ -18,7 +19,12 @@ const agentFileSchema = zod_1.z.discriminatedUnion("type", [
18
19
  .nullish()
19
20
  .transform((v) => v ?? undefined),
20
21
  instructions: zod_1.z
21
- .string()
22
+ .union([
23
+ zod_1.z.string(),
24
+ zod_1.z.object({
25
+ url: zod_1.z.string(),
26
+ }),
27
+ ])
22
28
  .nullish()
23
29
  .transform((v) => v ?? undefined),
24
30
  input_key: zod_1.z
@@ -72,16 +78,46 @@ const agentFileSchema = zod_1.z.discriminatedUnion("type", [
72
78
  .nullish()
73
79
  .transform((v) => v ?? undefined),
74
80
  }),
81
+ zod_1.z.object({
82
+ type: zod_1.z.literal("team"),
83
+ name: zod_1.z.string(),
84
+ description: zod_1.z
85
+ .string()
86
+ .nullish()
87
+ .transform((v) => v ?? undefined),
88
+ input_schema: schema_js_1.inputOutputSchema
89
+ .nullish()
90
+ .transform((v) => (v ? (0, json_schema_to_zod_1.jsonSchemaToZod)(v) : undefined)),
91
+ output_schema: schema_js_1.inputOutputSchema
92
+ .nullish()
93
+ .transform((v) => (v ? (0, json_schema_to_zod_1.jsonSchemaToZod)(v) : undefined)),
94
+ skills: zod_1.z
95
+ .array(zod_1.z.string())
96
+ .nullish()
97
+ .transform((v) => v ?? undefined),
98
+ mode: zod_1.z
99
+ .nativeEnum(team_agent_js_1.ProcessMode)
100
+ .nullish()
101
+ .transform((v) => v ?? undefined),
102
+ }),
75
103
  ]);
76
104
  async function loadAgentFromYamlFile(path) {
77
105
  const raw = await (0, type_utils_js_1.tryOrThrow)(() => index_js_1.nodejs.fs.readFile(path, "utf8"), (error) => new Error(`Failed to load agent definition from ${path}: ${error.message}`));
78
106
  const json = await (0, type_utils_js_1.tryOrThrow)(() => (0, yaml_1.parse)(raw), (error) => new Error(`Failed to parse agent definition from ${path}: ${error.message}`));
79
- const agent = (0, type_utils_js_1.tryOrThrow)(() => (0, camelize_js_1.customCamelize)(agentFileSchema.parse({
107
+ const agent = await (0, type_utils_js_1.tryOrThrow)(async () => (0, camelize_js_1.customCamelize)(await agentFileSchema.parseAsync({
80
108
  ...json,
81
109
  type: json.type ?? "ai",
82
110
  skills: json.skills ?? json.tools,
83
111
  }), {
84
112
  shallowKeys: ["input_schema", "output_schema"],
85
113
  }), (error) => new Error(`Failed to validate agent definition from ${path}: ${error.message}`));
114
+ if (agent.type === "ai") {
115
+ return {
116
+ ...agent,
117
+ instructions: typeof agent.instructions === "object" && "url" in agent.instructions
118
+ ? await index_js_1.nodejs.fs.readFile(index_js_1.nodejs.path.join(index_js_1.nodejs.path.dirname(path), agent.instructions.url), "utf8")
119
+ : agent.instructions,
120
+ };
121
+ }
86
122
  return agent;
87
123
  }
@@ -1,6 +1,6 @@
1
1
  import type { Camelize } from "camelize-ts";
2
2
  import { z } from "zod";
3
- import { type Agent } from "../agents/agent.js";
3
+ import { Agent } from "../agents/agent.js";
4
4
  import type { ChatModel, ChatModelOptions } from "../agents/chat-model.js";
5
5
  import type { MemoryAgent, MemoryAgentOptions } from "../memory/memory.js";
6
6
  export interface LoadOptions {
@@ -10,6 +10,7 @@ const zod_1 = require("zod");
10
10
  const agent_js_1 = require("../agents/agent.js");
11
11
  const ai_agent_js_1 = require("../agents/ai-agent.js");
12
12
  const mcp_agent_js_1 = require("../agents/mcp-agent.js");
13
+ const team_agent_js_1 = require("../agents/team-agent.js");
13
14
  const type_utils_js_1 = require("../utils/type-utils.js");
14
15
  const agent_js_js_1 = require("./agent-js.js");
15
16
  const agent_yaml_js_1 = require("./agent-yaml.js");
@@ -28,20 +29,25 @@ async function load(options) {
28
29
  };
29
30
  }
30
31
  async function loadAgent(path, options) {
31
- if (index_js_1.nodejs.path.extname(path) === ".js") {
32
+ if ([".js", ".mjs", ".ts", ".mts"].includes(index_js_1.nodejs.path.extname(path))) {
32
33
  const agent = await (0, agent_js_js_1.loadAgentFromJsFile)(path);
34
+ if (agent instanceof agent_js_1.Agent)
35
+ return agent;
33
36
  return agent_js_1.FunctionAgent.from(agent);
34
37
  }
35
- if (index_js_1.nodejs.path.extname(path) === ".yaml" || index_js_1.nodejs.path.extname(path) === ".yml") {
38
+ if ([".yml", ".yaml"].includes(index_js_1.nodejs.path.extname(path))) {
36
39
  const agent = await (0, agent_yaml_js_1.loadAgentFromYamlFile)(path);
40
+ const skills = "skills" in agent
41
+ ? agent.skills &&
42
+ (await Promise.all(agent.skills.map((filename) => loadAgent(index_js_1.nodejs.path.join(index_js_1.nodejs.path.dirname(path), filename), options))))
43
+ : undefined;
37
44
  if (agent.type === "ai") {
38
45
  return ai_agent_js_1.AIAgent.from({
39
46
  ...agent,
40
47
  memory: !options?.memories?.length || !agent.memory
41
48
  ? undefined
42
49
  : await loadMemory(options.memories, typeof agent.memory === "object" ? agent.memory.provider : undefined, typeof agent.memory === "object" ? agent.memory : {}),
43
- skills: agent.skills &&
44
- (await Promise.all(agent.skills.map((filename) => loadAgent(index_js_1.nodejs.path.join(index_js_1.nodejs.path.dirname(path), filename), options)))),
50
+ skills,
45
51
  });
46
52
  }
47
53
  if (agent.type === "mcp") {
@@ -58,6 +64,12 @@ async function loadAgent(path, options) {
58
64
  }
59
65
  throw new Error(`Missing url or command in mcp agent: ${path}`);
60
66
  }
67
+ if (agent.type === "team") {
68
+ return team_agent_js_1.TeamAgent.from({
69
+ ...agent,
70
+ skills,
71
+ });
72
+ }
61
73
  }
62
74
  throw new Error(`Unsupported agent file type: ${path}`);
63
75
  }
@@ -21,6 +21,7 @@ export interface MemoryAgentOptions extends Partial<Pick<MemoryAgent, "recorder"
21
21
  * instead provides memory management capabilities to the system.
22
22
  */
23
23
  export declare class MemoryAgent extends Agent {
24
+ tag: string;
24
25
  /**
25
26
  * Creates a new MemoryAgent instance.
26
27
  */
@@ -16,6 +16,7 @@ exports.newMemoryId = newMemoryId;
16
16
  * instead provides memory management capabilities to the system.
17
17
  */
18
18
  class MemoryAgent extends agent_js_1.Agent {
19
+ tag = "MemoryAgent";
19
20
  /**
20
21
  * Creates a new MemoryAgent instance.
21
22
  */
@@ -77,6 +77,7 @@ export declare const memoryRecorderOutputSchema: z.ZodObject<{
77
77
  * implementations of the process method to handle the actual storage logic.
78
78
  */
79
79
  export declare abstract class MemoryRecorder extends Agent<MemoryRecorderInput, MemoryRecorderOutput> {
80
+ tag: string;
80
81
  /**
81
82
  * Creates a new MemoryRecorder instance with predefined input and output schemas.
82
83
  *
@@ -34,6 +34,7 @@ exports.memoryRecorderOutputSchema = zod_1.z.object({
34
34
  * implementations of the process method to handle the actual storage logic.
35
35
  */
36
36
  class MemoryRecorder extends agent_js_1.Agent {
37
+ tag = "MemoryRecorderAgent";
37
38
  /**
38
39
  * Creates a new MemoryRecorder instance with predefined input and output schemas.
39
40
  *
@@ -90,6 +90,7 @@ export declare const memoryRetrieverOutputSchema: z.ZodObject<{
90
90
  * implementations of the process method to handle the actual retrieval logic.
91
91
  */
92
92
  export declare abstract class MemoryRetriever extends Agent<MemoryRetrieverInput, MemoryRetrieverOutput> {
93
+ tag: string;
93
94
  /**
94
95
  * Creates a new MemoryRetriever instance with predefined input and output schemas.
95
96
  *
@@ -35,6 +35,7 @@ exports.memoryRetrieverOutputSchema = zod_1.z.object({
35
35
  * implementations of the process method to handle the actual retrieval logic.
36
36
  */
37
37
  class MemoryRetriever extends agent_js_1.Agent {
38
+ tag = "MemoryRetrieverAgent";
38
39
  /**
39
40
  * Creates a new MemoryRetriever instance with predefined input and output schemas.
40
41
  *
@@ -7,7 +7,7 @@ export interface PromptBuilderOptions {
7
7
  instructions?: string | ChatMessagesTemplate;
8
8
  }
9
9
  export interface PromptBuildOptions extends Pick<AgentInvokeOptions, "context"> {
10
- agent?: AIAgent<any, any, any>;
10
+ agent?: AIAgent;
11
11
  input?: Message;
12
12
  model?: ChatModel;
13
13
  outputSchema?: Agent["outputSchema"];
@@ -176,6 +176,7 @@ export declare abstract class Agent<I extends Message = Message, O extends Messa
176
176
  * List of memories this agent can use
177
177
  */
178
178
  readonly memories: MemoryAgent[];
179
+ tag?: string;
179
180
  /**
180
181
  * Maximum number of memory items to retrieve
181
182
  */
@@ -341,7 +342,7 @@ export declare abstract class Agent<I extends Message = Message, O extends Messa
341
342
  * Here's an example of invoking an agent with regular mode:
342
343
  * {@includeCode ../../test/agents/agent.test.ts#example-invoke}
343
344
  */
344
- invoke(input: I, options?: Partial<AgentInvokeOptions> & {
345
+ invoke(input: I & Message, options?: Partial<AgentInvokeOptions> & {
345
346
  streaming?: false;
346
347
  }): Promise<O>;
347
348
  /**
@@ -359,7 +360,7 @@ export declare abstract class Agent<I extends Message = Message, O extends Messa
359
360
  * Here's an example of invoking an agent with streaming response:
360
361
  * {@includeCode ../../test/agents/agent.test.ts#example-invoke-streaming}
361
362
  */
362
- invoke(input: I, options: Partial<AgentInvokeOptions> & {
363
+ invoke(input: I & Message, options: Partial<AgentInvokeOptions> & {
363
364
  streaming: true;
364
365
  }): Promise<AgentResponseStream<O>>;
365
366
  /**
@@ -371,8 +372,8 @@ export declare abstract class Agent<I extends Message = Message, O extends Messa
371
372
  * @param options Invocation options
372
373
  * @returns Agent response (streaming or regular)
373
374
  */
374
- invoke(input: I, options?: Partial<AgentInvokeOptions>): Promise<AgentResponse<O>>;
375
- protected invokeSkill<I extends Message, O extends Message>(skill: Agent<I, O>, input: I, options: AgentInvokeOptions): Promise<O>;
375
+ invoke(input: I & Message, options?: Partial<AgentInvokeOptions>): Promise<AgentResponse<O>>;
376
+ protected invokeSkill<I extends Message, O extends Message>(skill: Agent<I, O>, input: I & Message, options: AgentInvokeOptions): Promise<O>;
376
377
  /**
377
378
  * Process agent output
378
379
  *
@@ -723,6 +724,7 @@ export interface FunctionAgentOptions<I extends Message = Message, O extends Mes
723
724
  * {@includeCode ../../test/agents/agent.test.ts#example-function-agent}
724
725
  */
725
726
  export declare class FunctionAgent<I extends Message = Message, O extends Message = Message> extends Agent<I, O> {
727
+ tag: string;
726
728
  /**
727
729
  * Create a function agent from a function or options
728
730
  *
@@ -3,6 +3,7 @@ import { PromptBuilder } from "../prompt/prompt-builder.js";
3
3
  import { Agent, type AgentInvokeOptions, type AgentOptions, type AgentProcessAsyncGenerator, type Message } from "./agent.js";
4
4
  import { ChatModel, type ChatModelInput } from "./chat-model.js";
5
5
  import type { GuideRailAgentOutput } from "./guide-rail-agent.js";
6
+ export declare const DEFAULT_OUTPUT_KEY = "message";
6
7
  /**
7
8
  * Configuration options for an AI Agent
8
9
  *
@@ -12,7 +13,7 @@ import type { GuideRailAgentOutput } from "./guide-rail-agent.js";
12
13
  * @template I The input message type the agent accepts
13
14
  * @template O The output message type the agent returns
14
15
  */
15
- export interface AIAgentOptions<InputKey extends string = string, I extends Message & InputMessage<InputKey> = Message & InputMessage<InputKey>, O extends Message = Message> extends AgentOptions<Omit<I, InputKey> & Partial<InputMessage<InputKey>>, O> {
16
+ export interface AIAgentOptions<I extends Message = Message, O extends Message = Message> extends AgentOptions<I, O> {
16
17
  /**
17
18
  * The language model to use for this agent
18
19
  *
@@ -29,7 +30,7 @@ export interface AIAgentOptions<InputKey extends string = string, I extends Mess
29
30
  /**
30
31
  * Pick a message from input to use as the user's message
31
32
  */
32
- inputKey?: InputKey;
33
+ inputKey?: string;
33
34
  /**
34
35
  * Custom key to use for text output in the response
35
36
  *
@@ -110,9 +111,6 @@ export declare const aiAgentToolChoiceSchema: z.ZodUnion<[z.ZodNativeEnum<typeof
110
111
  export declare const aiAgentOptionsSchema: ZodObject<{
111
112
  [key in keyof AIAgentOptions]: ZodType<AIAgentOptions[key]>;
112
113
  }>;
113
- type InputMessage<K> = K extends string ? {
114
- [key in K]: string;
115
- } : Message;
116
114
  /**
117
115
  * AI-powered agent that leverages language models
118
116
  *
@@ -133,7 +131,8 @@ type InputMessage<K> = K extends string ? {
133
131
  * Basic AIAgent creation:
134
132
  * {@includeCode ../../test/agents/ai-agent.test.ts#example-ai-agent-basic}
135
133
  */
136
- export declare class AIAgent<InputKey extends string = string, I extends Message & InputMessage<InputKey> = Message & InputMessage<InputKey>, O extends Message = Message> extends Agent<I, O> {
134
+ export declare class AIAgent<I extends Message = Message, O extends Message = Message> extends Agent<I, O> {
135
+ tag: string;
137
136
  /**
138
137
  * Create an AIAgent with the specified options
139
138
  *
@@ -146,13 +145,13 @@ export declare class AIAgent<InputKey extends string = string, I extends Message
146
145
  * AI agent with custom instructions:
147
146
  * {@includeCode ../../test/agents/ai-agent.test.ts#example-ai-agent-instructions}
148
147
  */
149
- static from<InputKey extends string, I extends Message & InputMessage<InputKey>, O extends Message>(options: AIAgentOptions<InputKey, I, O>): AIAgent<InputKey, I, O>;
148
+ static from<I extends Message, O extends Message>(options: AIAgentOptions<I, O>): AIAgent<I, O>;
150
149
  /**
151
150
  * Create an AIAgent instance
152
151
  *
153
152
  * @param options Configuration options for the AI agent
154
153
  */
155
- constructor(options: AIAgentOptions<InputKey, I, O>);
154
+ constructor(options: AIAgentOptions<I, O>);
156
155
  /**
157
156
  * The language model used by this agent
158
157
  *
@@ -173,7 +172,7 @@ export declare class AIAgent<InputKey extends string = string, I extends Message
173
172
  /**
174
173
  * Pick a message from input to use as the user's message
175
174
  */
176
- inputKey?: InputKey;
175
+ inputKey?: string;
177
176
  /**
178
177
  * Custom key to use for text output in the response
179
178
  *
@@ -235,4 +234,3 @@ export declare class AIAgent<InputKey extends string = string, I extends Message
235
234
  */
236
235
  _processRouter(input: I, model: ChatModel, modelInput: ChatModelInput, options: AgentInvokeOptions, toolsMap: Map<string, Agent>): AgentProcessAsyncGenerator<O>;
237
236
  }
238
- export {};
@@ -24,6 +24,7 @@ import { Agent, type AgentInvokeOptions, type AgentProcessResult, type Message }
24
24
  * {@includeCode ../../test/agents/chat-model.test.ts#example-chat-model-tools}
25
25
  */
26
26
  export declare abstract class ChatModel extends Agent<ChatModelInput, ChatModelOutput> {
27
+ tag: string;
27
28
  constructor();
28
29
  /**
29
30
  * Indicates whether the model supports parallel tool calls
@@ -57,6 +57,7 @@ export type SSEServerParameters = {
57
57
  * {@includeCode ../../test/agents/mcp-agent.test.ts#example-mcp-agent-from-sse}
58
58
  */
59
59
  export declare class MCPAgent extends Agent {
60
+ tag: string;
60
61
  /**
61
62
  * Create an MCPAgent from a connection to an SSE server.
62
63
  *
@@ -186,22 +187,26 @@ export interface MCPBaseOptions<I extends Message = Message, O extends Message =
186
187
  client: ClientWithReconnect;
187
188
  }
188
189
  export declare abstract class MCPBase<I extends Message, O extends Message> extends Agent<I, O> {
190
+ tag: string;
189
191
  constructor(options: MCPBaseOptions<I, O>);
190
192
  protected client: ClientWithReconnect;
191
193
  }
192
194
  export declare class MCPTool extends MCPBase<Message, CallToolResult> {
195
+ tag: string;
193
196
  process(input: Message): Promise<CallToolResult>;
194
197
  }
195
198
  export interface MCPPromptInput extends Record<string, unknown> {
196
199
  [key: string]: string;
197
200
  }
198
201
  export declare class MCPPrompt extends MCPBase<MCPPromptInput, GetPromptResult> {
202
+ tag: string;
199
203
  process(input: MCPPromptInput): Promise<GetPromptResult>;
200
204
  }
201
205
  export interface MCPResourceOptions extends MCPBaseOptions<MCPPromptInput, ReadResourceResult> {
202
206
  uri: string;
203
207
  }
204
208
  export declare class MCPResource extends MCPBase<MCPPromptInput, ReadResourceResult> {
209
+ tag: string;
205
210
  constructor(options: MCPResourceOptions);
206
211
  uri: string;
207
212
  process(input: MCPPromptInput): Promise<ReadResourceResult>;
@@ -52,6 +52,7 @@ export interface TeamAgentOptions<I extends Message, O extends Message> extends
52
52
  * {@includeCode ../../test/agents/team-agent.test.ts#example-team-agent-sequential}
53
53
  */
54
54
  export declare class TeamAgent<I extends Message, O extends Message> extends Agent<I, O> {
55
+ tag: string;
55
56
  /**
56
57
  * Create a TeamAgent from the provided options.
57
58
  *
@@ -7,6 +7,7 @@ export interface UserAgentOptions<I extends Message = Message, O extends Message
7
7
  activeAgent?: Agent;
8
8
  }
9
9
  export declare class UserAgent<I extends Message = Message, O extends Message = Message> extends Agent<I, O> {
10
+ tag: string;
10
11
  static from<I extends Message, O extends Message>(options: UserAgentOptions<I, O>): UserAgent<I, O>;
11
12
  constructor(options: UserAgentOptions<I, O>);
12
13
  context: Context;