@aigne/core 1.21.0 → 1.23.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 (63) hide show
  1. package/CHANGELOG.md +37 -84
  2. package/lib/cjs/agents/agent.d.ts +17 -10
  3. package/lib/cjs/agents/agent.js +7 -3
  4. package/lib/cjs/agents/ai-agent.d.ts +2 -1
  5. package/lib/cjs/agents/ai-agent.js +1 -0
  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 +6 -1
  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 +14 -5
  15. package/lib/cjs/aigne/aigne.js +21 -2
  16. package/lib/cjs/aigne/context.d.ts +27 -6
  17. package/lib/cjs/aigne/context.js +86 -14
  18. package/lib/cjs/loader/agent-yaml.d.ts +1 -1
  19. package/lib/cjs/loader/index.d.ts +2 -2
  20. package/lib/cjs/memory/memory.d.ts +6 -3
  21. package/lib/cjs/memory/memory.js +17 -2
  22. package/lib/cjs/memory/recorder.d.ts +15 -4
  23. package/lib/cjs/memory/recorder.js +14 -1
  24. package/lib/cjs/memory/retriever.d.ts +12 -5
  25. package/lib/cjs/memory/retriever.js +9 -0
  26. package/lib/dts/agents/agent.d.ts +17 -10
  27. package/lib/dts/agents/ai-agent.d.ts +2 -1
  28. package/lib/dts/agents/chat-model.d.ts +1 -0
  29. package/lib/dts/agents/mcp-agent.d.ts +6 -1
  30. package/lib/dts/agents/team-agent.d.ts +1 -0
  31. package/lib/dts/agents/user-agent.d.ts +1 -0
  32. package/lib/dts/aigne/aigne.d.ts +14 -5
  33. package/lib/dts/aigne/context.d.ts +27 -6
  34. package/lib/dts/loader/agent-yaml.d.ts +1 -1
  35. package/lib/dts/loader/index.d.ts +2 -2
  36. package/lib/dts/memory/memory.d.ts +6 -3
  37. package/lib/dts/memory/recorder.d.ts +15 -4
  38. package/lib/dts/memory/retriever.d.ts +12 -5
  39. package/lib/esm/agents/agent.d.ts +17 -10
  40. package/lib/esm/agents/agent.js +7 -3
  41. package/lib/esm/agents/ai-agent.d.ts +2 -1
  42. package/lib/esm/agents/ai-agent.js +1 -0
  43. package/lib/esm/agents/chat-model.d.ts +1 -0
  44. package/lib/esm/agents/chat-model.js +1 -0
  45. package/lib/esm/agents/mcp-agent.d.ts +6 -1
  46. package/lib/esm/agents/mcp-agent.js +5 -0
  47. package/lib/esm/agents/team-agent.d.ts +1 -0
  48. package/lib/esm/agents/team-agent.js +1 -0
  49. package/lib/esm/agents/user-agent.d.ts +1 -0
  50. package/lib/esm/agents/user-agent.js +6 -3
  51. package/lib/esm/aigne/aigne.d.ts +14 -5
  52. package/lib/esm/aigne/aigne.js +21 -2
  53. package/lib/esm/aigne/context.d.ts +27 -6
  54. package/lib/esm/aigne/context.js +86 -14
  55. package/lib/esm/loader/agent-yaml.d.ts +1 -1
  56. package/lib/esm/loader/index.d.ts +2 -2
  57. package/lib/esm/memory/memory.d.ts +6 -3
  58. package/lib/esm/memory/memory.js +17 -2
  59. package/lib/esm/memory/recorder.d.ts +15 -4
  60. package/lib/esm/memory/recorder.js +15 -2
  61. package/lib/esm/memory/retriever.d.ts +12 -5
  62. package/lib/esm/memory/retriever.js +10 -1
  63. package/package.json +3 -2
package/CHANGELOG.md CHANGED
@@ -1,9 +1,35 @@
1
- ## [1.17.0](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.16.0...core-v1.17.0) (2025-05-25)
1
+ ## [1.22.0](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.21.0...core-v1.22.0) (2025-06-24)
2
2
 
3
3
 
4
4
  ### Features
5
5
 
6
- * add user context support ([#131](https://github.com/AIGNE-io/aigne-framework/issues/131)) ([4dd9d20](https://github.com/AIGNE-io/aigne-framework/commit/4dd9d20953f6ac33933723db56efd9b44bafeb02))
6
+ * support observability for cli and blocklet ([#155](https://github.com/AIGNE-io/aigne-framework/issues/155)) ([5baa705](https://github.com/AIGNE-io/aigne-framework/commit/5baa705a33cfdba1efc5ccbe18674c27513ca97d))
7
+
8
+
9
+ ### Dependencies
10
+
11
+ * The following workspace dependencies were updated
12
+ * dependencies
13
+ * @aigne/observability bumped to 0.1.0
14
+
15
+ ## [1.23.0](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.22.0...core-v1.23.0) (2025-06-25)
16
+
17
+
18
+ ### Features
19
+
20
+ * support remember custom fields from message ([#174](https://github.com/AIGNE-io/aigne-framework/issues/174)) ([664069d](https://github.com/AIGNE-io/aigne-framework/commit/664069d343137f69d0c103b2b5eff545ab0051fb))
21
+
22
+
23
+ ### Bug Fixes
24
+
25
+ * **blocklet:** ensure only admins can access traces ([#173](https://github.com/AIGNE-io/aigne-framework/issues/173)) ([9c5cc06](https://github.com/AIGNE-io/aigne-framework/commit/9c5cc06c5841b9684d16c5c60af764d8c98c9c3e))
26
+
27
+
28
+ ### Dependencies
29
+
30
+ * The following workspace dependencies were updated
31
+ * dependencies
32
+ * @aigne/observability bumped to 0.1.1
7
33
 
8
34
  ## [1.21.0](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.20.1...core-v1.21.0) (2025-06-20)
9
35
 
@@ -104,6 +130,15 @@
104
130
  * dependencies
105
131
  * @aigne/platform-helpers bumped to 0.1.0
106
132
 
133
+
134
+ ## [1.17.0](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.16.0...core-v1.17.0) (2025-05-25)
135
+
136
+
137
+ ### Features
138
+
139
+ * add user context support ([#131](https://github.com/AIGNE-io/aigne-framework/issues/131)) ([4dd9d20](https://github.com/AIGNE-io/aigne-framework/commit/4dd9d20953f6ac33933723db56efd9b44bafeb02))
140
+
141
+
107
142
  ## [1.16.0](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.15.0...core-v1.16.0) (2025-05-23)
108
143
 
109
144
 
@@ -306,85 +341,3 @@
306
341
  * **MCP:** catch list resource error treat as empty list ([1885fab](https://github.com/AIGNE-io/aigne-framework/commit/1885fab3585e0dd1467b127e5b47cd0b98282bab))
307
342
  * rename @aigne/core-next to @aigne/core ([3a81009](https://github.com/AIGNE-io/aigne-framework/commit/3a8100962c81813217b687ae28e8de604419c622))
308
343
  * use text resource from MCP correctly ([8b9eba8](https://github.com/AIGNE-io/aigne-framework/commit/8b9eba83352ec096a2a5d4f410d4c4bde7420bce))
309
-
310
- ## [1.2.0](https://github.com/AIGNE-io/aigne-framework/compare/core-next-v1.1.0...core-next-v1.2.0) (2025-03-18)
311
-
312
- - chore: release v1.2.0
313
-
314
- ## 1.1.0-beta.17 (2025-3-18)
315
-
316
- - chore: add support for esm module
317
-
318
-
319
- ## 1.1.0-beta.16 (2025-3-18)
320
-
321
- - chore: add puppeteer in linux need docker_container
322
-
323
- ## 1.1.0-beta.15 (2025-3-18)
324
-
325
- - chore: make coverage report as text to terminal
326
- - chore: update contributing docs
327
-
328
- ## 1.1.0-beta.14 (2025-3-18)
329
-
330
- - chore(example): add code-execution example
331
-
332
- ## 1.1.0-beta.13 (2025-3-18)
333
-
334
- - feat: add OrchestratorAgent in agent library
335
-
336
- ## 1.1.0-beta.12 (2025-3-14)
337
-
338
- - chore(example): add concurrency reflection handoff workflow examples
339
-
340
- ## 1.1.0-beta.11 (2025-3-14)
341
-
342
- - feat(core): add sequential and parallel helper function
343
- - chore(examples): add workflow-sequential example
344
-
345
- ## 1.1.0-beta.10 (2025-3-13)
346
-
347
- - chore: ensure required environment variables have values
348
-
349
- ## 1.1.0-beta.9 (2025-3-13)
350
-
351
- - fix(MCP): catch list resource error treat as empty list
352
-
353
- ## 1.1.0-beta.8 (2025-3-13)
354
-
355
- - fix(AIAgent): should pass both arguments (model generated) and input (user input) to tool
356
- - chore(examples): add workflow-router example
357
- - chore(examples): rename examples puppeteer-mcp-server and sqlite-mcp-server to mcp-server-puppeteer and mcp-server-sqlite
358
-
359
- ## 1.1.0-beta.7 (2025-3-13)
360
-
361
- - chore: rename @aigne/core to @aigne/core
362
-
363
- ## 1.1.0-beta.6 (2025-3-13)
364
-
365
- - chore(examples): default enable mcp debug message for examples
366
-
367
- ## 1.1.0-beta.5 (2025-3-13)
368
-
369
- - feat: support chat history in PromptBuilder
370
- - feat: add `prompts` for MCPAgent to consume prompts from MCP server
371
- - chore: add sqlite-mcp-server example
372
- - test: add more unit test cases
373
-
374
- ## 1.1.0-beta.4 (2025-3-12)
375
-
376
- - feat: support run puppeteer example chat loop in terminal
377
-
378
- ## 1.1.0-beta.3 (2025-3-11)
379
-
380
- - chore: set module type for core package
381
-
382
- ## 1.1.0-beta.2 (2025-3-11)
383
-
384
- - feat: use PromptBuilder instead of string instructions
385
- - refactor: use tools instead of skills
386
- - chore(examples): add puppeteer-mcp-server example
387
-
388
- ## 1.1.0-beta.1 (2025-3-11)
389
-
390
- - feat: add Agent FunctionAgent AIAgent MCPAgent and ExecutionEngine
@@ -37,7 +37,7 @@ export type PublishTopic<O extends Message> = string | string[] | ((output: O) =
37
37
  * @template I The agent input message type
38
38
  * @template O The agent output message type
39
39
  */
40
- export interface AgentOptions<I extends Message = Message, O extends Message = Message> extends Partial<Pick<Agent, "guideRails" | "hooks">> {
40
+ export interface AgentOptions<I extends Message = Message, O extends Message = Message> extends Partial<Pick<Agent, "guideRails">> {
41
41
  /**
42
42
  * Topics the agent should subscribe to
43
43
  *
@@ -106,6 +106,7 @@ export interface AgentOptions<I extends Message = Message, O extends Message = M
106
106
  * Maximum number of memory items to retrieve
107
107
  */
108
108
  maxRetrieveMemoryCount?: number;
109
+ hooks?: AgentHooks<I, O>;
109
110
  }
110
111
  export declare const agentOptionsSchema: ZodObject<{
111
112
  [key in keyof AgentOptions]: ZodType<AgentOptions[key]>;
@@ -161,7 +162,7 @@ export interface AgentInvokeOptions<U extends UserContext = UserContext> {
161
162
  * Here's an example of how to create a custom agent:
162
163
  * {@includeCode ../../test/agents/agent.test.ts#example-custom-agent}
163
164
  */
164
- export declare abstract class Agent<I extends Message = Message, O extends Message = Message> {
165
+ export declare abstract class Agent<I extends Message = any, O extends Message = any> {
165
166
  /**
166
167
  * Custom object inspection behavior
167
168
  *
@@ -176,6 +177,7 @@ export declare abstract class Agent<I extends Message = Message, O extends Messa
176
177
  * List of memories this agent can use
177
178
  */
178
179
  readonly memories: MemoryAgent[];
180
+ tag?: string;
179
181
  /**
180
182
  * Maximum number of memory items to retrieve
181
183
  */
@@ -190,7 +192,7 @@ export declare abstract class Agent<I extends Message = Message, O extends Messa
190
192
  * Here's an example of using hooks:
191
193
  * {@includeCode ../../test/agents/agent.test.ts#example-agent-hooks}
192
194
  */
193
- readonly hooks: AgentHooks;
195
+ readonly hooks: AgentHooks<I, O>;
194
196
  /**
195
197
  * List of GuideRail agents applied to this agent
196
198
  *
@@ -276,8 +278,8 @@ export declare abstract class Agent<I extends Message = Message, O extends Messa
276
278
  * Skills can be accessed by name or by array index, allowing
277
279
  * the agent to delegate tasks to specialized sub-agents
278
280
  */
279
- readonly skills: Agent<Message, Message>[] & {
280
- [key: string]: Agent<Message, Message>;
281
+ readonly skills: Agent<any, any>[] & {
282
+ [key: string]: Agent<any, any>;
281
283
  };
282
284
  /**
283
285
  * Whether to disable emitting events for agent actions
@@ -518,7 +520,9 @@ export interface AgentHooks<I extends Message = Message, O extends Message = Mes
518
520
  onStart?: (event: {
519
521
  context: Context;
520
522
  input: I;
521
- }) => PromiseOrValue<void>;
523
+ }) => PromiseOrValue<void | {
524
+ input?: I;
525
+ }>;
522
526
  /**
523
527
  * Called when agent processing completes or fails
524
528
  *
@@ -533,7 +537,9 @@ export interface AgentHooks<I extends Message = Message, O extends Message = Mes
533
537
  input: I;
534
538
  output: O;
535
539
  error: Error;
536
- }, "output", "error">) => PromiseOrValue<void>;
540
+ }, "output", "error">) => PromiseOrValue<void | {
541
+ output?: O;
542
+ }>;
537
543
  /**
538
544
  * Called before a skill (sub-agent) is invoked
539
545
  *
@@ -545,7 +551,7 @@ export interface AgentHooks<I extends Message = Message, O extends Message = Mes
545
551
  onSkillStart?: (event: {
546
552
  context: Context;
547
553
  skill: Agent;
548
- input: I;
554
+ input: Message;
549
555
  }) => PromiseOrValue<void>;
550
556
  /**
551
557
  * Called after a skill (sub-agent) completes or fails
@@ -559,8 +565,8 @@ export interface AgentHooks<I extends Message = Message, O extends Message = Mes
559
565
  onSkillEnd?: (event: XOr<{
560
566
  context: Context;
561
567
  skill: Agent;
562
- input: I;
563
- output: O;
568
+ input: Message;
569
+ output: Message;
564
570
  error: Error;
565
571
  }, "output", "error">) => PromiseOrValue<void>;
566
572
  /**
@@ -723,6 +729,7 @@ export interface FunctionAgentOptions<I extends Message = Message, O extends Mes
723
729
  * {@includeCode ../../test/agents/agent.test.ts#example-function-agent}
724
730
  */
725
731
  export declare class FunctionAgent<I extends Message = Message, O extends Message = Message> extends Agent<I, O> {
732
+ tag: string;
726
733
  /**
727
734
  * Create a function agent from a function or options
728
735
  *
@@ -127,6 +127,7 @@ class Agent {
127
127
  * List of memories this agent can use
128
128
  */
129
129
  memories = [];
130
+ tag;
130
131
  /**
131
132
  * Maximum number of memory items to retrieve
132
133
  */
@@ -347,8 +348,8 @@ class Agent {
347
348
  if (!this.disableEvents)
348
349
  opts.context.emit("agentStarted", { agent: this, input });
349
350
  try {
350
- await this.hooks.onStart?.({ context: opts.context, input });
351
- const parsedInput = (0, type_utils_js_1.checkArguments)(`Agent ${this.name} input`, this.inputSchema, input);
351
+ let parsedInput = (await this.hooks.onStart?.({ context: opts.context, input }))?.input ?? input;
352
+ parsedInput = (0, type_utils_js_1.checkArguments)(`Agent ${this.name} input`, this.inputSchema, input);
352
353
  await this.preprocess(parsedInput, opts);
353
354
  this.checkContextStatus(opts);
354
355
  let response = await this.process(parsedInput, opts);
@@ -411,7 +412,9 @@ class Agent {
411
412
  logger_js_1.logger.debug("Invoke agent %s succeed with output: %O", this.name, finalOutput);
412
413
  if (!this.disableEvents)
413
414
  context.emit("agentSucceed", { agent: this, output: finalOutput });
414
- await this.hooks.onEnd?.({ context, input, output: finalOutput });
415
+ const o = (await this.hooks.onEnd?.({ context, input, output: finalOutput }))?.output;
416
+ if (o)
417
+ return o;
415
418
  return finalOutput;
416
419
  }
417
420
  /**
@@ -641,6 +644,7 @@ function checkAgentInputOutputSchema(schema) {
641
644
  * {@includeCode ../../test/agents/agent.test.ts#example-function-agent}
642
645
  */
643
646
  class FunctionAgent extends Agent {
647
+ tag = "FunctionAgent";
644
648
  /**
645
649
  * Create a function agent from a function or options
646
650
  *
@@ -131,7 +131,8 @@ export declare const aiAgentOptionsSchema: ZodObject<{
131
131
  * Basic AIAgent creation:
132
132
  * {@includeCode ../../test/agents/ai-agent.test.ts#example-ai-agent-basic}
133
133
  */
134
- export declare class AIAgent<I extends Message = Message, O extends Message = Message> extends Agent<I, O> {
134
+ export declare class AIAgent<I extends Message = any, O extends Message = any> extends Agent<I, O> {
135
+ tag: string;
135
136
  /**
136
137
  * Create an AIAgent with the specified options
137
138
  *
@@ -80,6 +80,7 @@ exports.aiAgentOptionsSchema = agent_js_1.agentOptionsSchema.extend({
80
80
  * {@includeCode ../../test/agents/ai-agent.test.ts#example-ai-agent-basic}
81
81
  */
82
82
  class AIAgent extends agent_js_1.Agent {
83
+ tag = "AIAgent";
83
84
  /**
84
85
  * Create an AIAgent with the specified options
85
86
  *
@@ -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
@@ -27,6 +27,7 @@ const agent_js_1 = require("./agent.js");
27
27
  * {@includeCode ../../test/agents/chat-model.test.ts#example-chat-model-tools}
28
28
  */
29
29
  class ChatModel extends agent_js_1.Agent {
30
+ tag = "ChatModelAgent";
30
31
  constructor() {
31
32
  super({
32
33
  inputSchema: chatModelInputSchema,
@@ -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
  *
@@ -182,26 +183,30 @@ declare class ClientWithReconnect extends Client {
182
183
  private reconnect;
183
184
  request<T extends ZodType<object>>(request: Request, resultSchema: T, options?: RequestOptions): Promise<z.infer<T>>;
184
185
  }
185
- export interface MCPBaseOptions<I extends Message = Message, O extends Message = Message> extends AgentOptions<I, O> {
186
+ export interface MCPBaseOptions<I extends Message = any, O extends Message = any> extends AgentOptions<I, O> {
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>;
@@ -55,6 +55,7 @@ function getMCPServerString(options) {
55
55
  * {@includeCode ../../test/agents/mcp-agent.test.ts#example-mcp-agent-from-sse}
56
56
  */
57
57
  class MCPAgent extends agent_js_1.Agent {
58
+ tag = "MCPAgent";
58
59
  static from(options) {
59
60
  (0, type_utils_js_1.checkArguments)("MCPAgent.from", mcpAgentOptionsSchema, options);
60
61
  if (isSSEServerParameters(options)) {
@@ -251,6 +252,7 @@ class ClientWithReconnect extends index_js_2.Client {
251
252
  }
252
253
  }
253
254
  class MCPBase extends agent_js_1.Agent {
255
+ tag = "MCPBase";
254
256
  constructor(options) {
255
257
  super(options);
256
258
  this.client = options.client;
@@ -259,6 +261,7 @@ class MCPBase extends agent_js_1.Agent {
259
261
  }
260
262
  exports.MCPBase = MCPBase;
261
263
  class MCPTool extends MCPBase {
264
+ tag = "MCPTool";
262
265
  async process(input) {
263
266
  const result = await this.client.callTool({ name: this.name, arguments: input });
264
267
  return result;
@@ -266,6 +269,7 @@ class MCPTool extends MCPBase {
266
269
  }
267
270
  exports.MCPTool = MCPTool;
268
271
  class MCPPrompt extends MCPBase {
272
+ tag = "MCPPrompt";
269
273
  async process(input) {
270
274
  const result = await this.client.getPrompt({ name: this.name, arguments: input });
271
275
  return result;
@@ -273,6 +277,7 @@ class MCPPrompt extends MCPBase {
273
277
  }
274
278
  exports.MCPPrompt = MCPPrompt;
275
279
  class MCPResource extends MCPBase {
280
+ tag = "MCPResource";
276
281
  constructor(options) {
277
282
  super(options);
278
283
  this.uri = options.uri;
@@ -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
  *
@@ -45,6 +45,7 @@ var ProcessMode;
45
45
  * {@includeCode ../../test/agents/team-agent.test.ts#example-team-agent-sequential}
46
46
  */
47
47
  class TeamAgent extends agent_js_1.Agent {
48
+ tag = "TeamAgent";
48
49
  /**
49
50
  * Create a TeamAgent from the provided options.
50
51
  *
@@ -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;
@@ -5,6 +5,7 @@ const message_queue_js_1 = require("../aigne/message-queue.js");
5
5
  const type_utils_js_1 = require("../utils/type-utils.js");
6
6
  const agent_js_1 = require("./agent.js");
7
7
  class UserAgent extends agent_js_1.Agent {
8
+ tag = "UserAgent";
8
9
  static from(options) {
9
10
  return new UserAgent(options);
10
11
  }
@@ -26,9 +27,8 @@ class UserAgent extends agent_js_1.Agent {
26
27
  super.publishToTopics(output, options);
27
28
  }
28
29
  invoke = ((input, options = {}) => {
29
- if (!options.context)
30
- this.context = this.context.newContext({ reset: true });
31
- return super.invoke(input, { ...options, context: this.context });
30
+ options.context ??= this.context.newContext({ reset: true });
31
+ return super.invoke(input, options);
32
32
  });
33
33
  async process(input, options) {
34
34
  if (this._process) {
@@ -38,6 +38,9 @@ class UserAgent extends agent_js_1.Agent {
38
38
  const [output, agent] = await options.context.invoke(this.activeAgent, input, {
39
39
  returnActiveAgent: true,
40
40
  streaming: true,
41
+ // Do not create a new context for the nested agent invocation,
42
+ // We are resetting the context in the override invoke method
43
+ newContext: false,
41
44
  });
42
45
  agent.then((agent) => {
43
46
  this.activeAgent = agent;
@@ -1,3 +1,4 @@
1
+ import { AIGNEObserver } from "@aigne/observability";
1
2
  import { Agent, type AgentResponse, type AgentResponseStream, type Message } from "../agents/agent.js";
2
3
  import { ChatModel } from "../agents/chat-model.js";
3
4
  import type { UserAgent } from "../agents/user-agent.js";
@@ -33,6 +34,10 @@ export interface AIGNEOptions {
33
34
  * Limits for the AIGNE instance, such as timeout, max tokens, max invocations, etc.
34
35
  */
35
36
  limits?: ContextLimits;
37
+ /**
38
+ * Observer for the AIGNE instance.
39
+ */
40
+ observer?: AIGNEObserver;
36
41
  }
37
42
  /**
38
43
  * AIGNE is a class that orchestrates multiple agents to build complex AI applications.
@@ -88,16 +93,20 @@ export declare class AIGNE<U extends UserContext = UserContext> {
88
93
  * Collection of skill agents available to this AIGNE instance.
89
94
  * Provides indexed access by skill name.
90
95
  */
91
- readonly skills: Agent<Message, Message>[] & {
92
- [key: string]: Agent<Message, Message>;
96
+ readonly skills: Agent<any, any>[] & {
97
+ [key: string]: Agent<any, any>;
93
98
  };
94
99
  /**
95
100
  * Collection of primary agents managed by this AIGNE instance.
96
101
  * Provides indexed access by agent name.
97
102
  */
98
- readonly agents: Agent<Message, Message>[] & {
99
- [key: string]: Agent<Message, Message>;
103
+ readonly agents: Agent<any, any>[] & {
104
+ [key: string]: Agent<any, any>;
100
105
  };
106
+ /**
107
+ * Observer for the AIGNE instance.
108
+ */
109
+ readonly observer?: AIGNEObserver;
101
110
  /**
102
111
  * Adds one or more agents to this AIGNE instance.
103
112
  * Each agent is attached to this AIGNE instance, allowing it to access the AIGNE's resources.
@@ -111,7 +120,7 @@ export declare class AIGNE<U extends UserContext = UserContext> {
111
120
  *
112
121
  * @returns A new AIGNEContext instance bound to this AIGNE.
113
122
  */
114
- newContext(options?: Partial<Context>): AIGNEContext;
123
+ newContext(options?: Partial<Pick<Context, "userContext" | "memories">>): AIGNEContext;
115
124
  /**
116
125
  * Creates a user agent for consistent interactions with a specified agent.
117
126
  * This method allows you to create a wrapper around an agent for repeated invocations.
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AIGNE = void 0;
4
+ const observability_1 = require("@aigne/observability");
4
5
  const zod_1 = require("zod");
5
6
  const agent_js_1 = require("../agents/agent.js");
6
7
  const chat_model_js_1 = require("../agents/chat-model.js");
@@ -52,10 +53,15 @@ class AIGNE {
52
53
  this.description = options?.description;
53
54
  this.model = options?.model;
54
55
  this.limits = options?.limits;
56
+ this.observer =
57
+ process.env.AIGNE_OBSERVABILITY_DISABLED === "true"
58
+ ? undefined
59
+ : (options?.observer ?? new observability_1.AIGNEObserver());
55
60
  if (options?.skills?.length)
56
61
  this.skills.push(...options.skills);
57
62
  if (options?.agents?.length)
58
63
  this.addAgent(...options.agents);
64
+ this.observer?.serve();
59
65
  this.initProcessExitHandler();
60
66
  }
61
67
  /**
@@ -90,6 +96,10 @@ class AIGNE {
90
96
  * Provides indexed access by agent name.
91
97
  */
92
98
  agents = (0, type_utils_js_1.createAccessorArray)([], (arr, name) => arr.find((i) => i.name === name));
99
+ /**
100
+ * Observer for the AIGNE instance.
101
+ */
102
+ observer;
93
103
  /**
94
104
  * Adds one or more agents to this AIGNE instance.
95
105
  * Each agent is attached to this AIGNE instance, allowing it to access the AIGNE's resources.
@@ -110,10 +120,17 @@ class AIGNE {
110
120
  * @returns A new AIGNEContext instance bound to this AIGNE.
111
121
  */
112
122
  newContext(options) {
113
- return new context_js_1.AIGNEContext(this, options);
123
+ const context = new context_js_1.AIGNEContext(this);
124
+ if (options?.userContext)
125
+ context.userContext = options.userContext;
126
+ if (options?.memories)
127
+ context.memories = options.memories;
128
+ return context;
114
129
  }
115
130
  invoke(agent, message, options) {
116
- return new context_js_1.AIGNEContext(this).invoke(agent, message, options);
131
+ this.observer?.serve();
132
+ const context = new context_js_1.AIGNEContext(this);
133
+ return context.invoke(agent, message, { ...options, newContext: false });
117
134
  }
118
135
  /**
119
136
  * Publishes a message to the message queue for inter-agent communication.
@@ -129,6 +146,7 @@ class AIGNE {
129
146
  * {@includeCode ../../test/aigne/aigne.test.ts#example-publish-message}
130
147
  */
131
148
  publish(topic, payload, options) {
149
+ this.observer?.serve();
132
150
  return new context_js_1.AIGNEContext(this).publish(topic, payload, options);
133
151
  }
134
152
  subscribe(topic, listener) {
@@ -192,5 +210,6 @@ const aigneOptionsSchema = zod_1.z.object({
192
210
  model: zod_1.z.instanceof(chat_model_js_1.ChatModel).optional(),
193
211
  skills: zod_1.z.array(zod_1.z.instanceof(agent_js_1.Agent)).optional(),
194
212
  agents: zod_1.z.array(zod_1.z.instanceof(agent_js_1.Agent)).optional(),
213
+ observer: zod_1.z.instanceof(observability_1.AIGNEObserver).optional(),
195
214
  });
196
215
  const aigneAddAgentArgsSchema = zod_1.z.array(zod_1.z.instanceof(agent_js_1.Agent));
@@ -1,3 +1,5 @@
1
+ import type { AIGNEObserver } from "@aigne/observability";
2
+ import type { Span } from "@opentelemetry/api";
1
3
  import { Emitter } from "strict-event-emitter";
2
4
  import { Agent, type AgentInvokeOptions, type AgentProcessAsyncGenerator, type AgentResponse, type AgentResponseStream, type Message } from "../agents/agent.js";
3
5
  import type { ChatModel } from "../agents/chat-model.js";
@@ -45,6 +47,13 @@ export interface InvokeOptions<U extends UserContext = UserContext> extends Part
45
47
  returnMetadata?: boolean;
46
48
  disableTransfer?: boolean;
47
49
  sourceAgent?: Agent;
50
+ /**
51
+ * Whether to create a new context for this invocation.
52
+ * If false, the invocation will use the current context.
53
+ *
54
+ * @default true
55
+ */
56
+ newContext?: boolean;
48
57
  }
49
58
  /**
50
59
  * @hidden
@@ -57,8 +66,11 @@ export interface UserContext extends Record<string, unknown> {
57
66
  export interface Context<U extends UserContext = UserContext> extends TypedEventEmitter<ContextEventMap, ContextEmitEventMap> {
58
67
  id: string;
59
68
  parentId?: string;
69
+ rootId: string;
60
70
  model?: ChatModel;
61
71
  skills?: Agent[];
72
+ observer?: AIGNEObserver;
73
+ span?: Span;
62
74
  usage: ContextUsage;
63
75
  limits?: ContextLimits;
64
76
  status?: "normal" | "timeout";
@@ -126,12 +138,18 @@ export interface Context<U extends UserContext = UserContext> extends TypedEvent
126
138
  * @hidden
127
139
  */
128
140
  export declare class AIGNEContext implements Context {
129
- constructor(...[parent, ...args]: ConstructorParameters<typeof AIGNEContextShared>);
130
- parentId?: string;
141
+ constructor(parent?: ConstructorParameters<typeof AIGNEContextShared>[0], { reset }?: {
142
+ reset?: boolean;
143
+ });
131
144
  id: string;
145
+ parentId?: string;
146
+ rootId: string;
147
+ span?: Span;
132
148
  readonly internal: AIGNEContextShared;
149
+ get messageQueue(): MessageQueue;
133
150
  get model(): ChatModel | undefined;
134
- get skills(): Agent<Message, Message>[] | undefined;
151
+ get skills(): Agent<any, any>[] | undefined;
152
+ get observer(): AIGNEObserver | undefined;
135
153
  get limits(): ContextLimits | undefined;
136
154
  get status(): "normal" | "timeout";
137
155
  get usage(): ContextUsage;
@@ -148,19 +166,22 @@ export declare class AIGNEContext implements Context {
148
166
  subscribe: Context["subscribe"];
149
167
  unsubscribe: Context["unsubscribe"];
150
168
  emit<K extends keyof ContextEmitEventMap>(eventName: K, ...args: Args<K, ContextEmitEventMap>): boolean;
169
+ private trace;
151
170
  on<K extends keyof ContextEventMap>(eventName: K, listener: Listener<K, ContextEventMap>): this;
152
171
  once<K extends keyof ContextEventMap>(eventName: K, listener: Listener<K, ContextEventMap>): this;
153
172
  off<K extends keyof ContextEventMap>(eventName: K, listener: Listener<K, ContextEventMap>): this;
154
173
  }
155
174
  declare class AIGNEContextShared {
156
175
  private readonly parent?;
157
- constructor(parent?: (Pick<Context, "model" | "skills" | "limits"> & {
176
+ span?: Span;
177
+ constructor(parent?: (Pick<Context, "model" | "skills" | "limits" | "observer"> & {
158
178
  messageQueue?: MessageQueue;
159
- }) | undefined, overrides?: Partial<Context>);
179
+ }) | undefined);
160
180
  readonly messageQueue: MessageQueue;
161
181
  readonly events: Emitter<any>;
162
182
  get model(): ChatModel | undefined;
163
- get skills(): Agent<Message, Message>[] | undefined;
183
+ get skills(): Agent<any, any>[] | undefined;
184
+ get observer(): AIGNEObserver | undefined;
164
185
  get limits(): ContextLimits | undefined;
165
186
  usage: ContextUsage;
166
187
  userContext: Context["userContext"];