@aigne/core 1.22.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 (39) hide show
  1. package/CHANGELOG.md +26 -87
  2. package/lib/cjs/agents/agent.d.ts +15 -10
  3. package/lib/cjs/agents/agent.js +5 -3
  4. package/lib/cjs/agents/ai-agent.d.ts +1 -1
  5. package/lib/cjs/agents/mcp-agent.d.ts +1 -1
  6. package/lib/cjs/aigne/aigne.d.ts +4 -4
  7. package/lib/cjs/aigne/aigne.js +2 -0
  8. package/lib/cjs/aigne/context.d.ts +2 -2
  9. package/lib/cjs/loader/index.d.ts +2 -2
  10. package/lib/cjs/memory/memory.d.ts +5 -3
  11. package/lib/cjs/memory/memory.js +16 -2
  12. package/lib/cjs/memory/recorder.d.ts +14 -4
  13. package/lib/cjs/memory/recorder.js +13 -1
  14. package/lib/cjs/memory/retriever.d.ts +11 -5
  15. package/lib/cjs/memory/retriever.js +8 -0
  16. package/lib/dts/agents/agent.d.ts +15 -10
  17. package/lib/dts/agents/ai-agent.d.ts +1 -1
  18. package/lib/dts/agents/mcp-agent.d.ts +1 -1
  19. package/lib/dts/aigne/aigne.d.ts +4 -4
  20. package/lib/dts/aigne/context.d.ts +2 -2
  21. package/lib/dts/loader/index.d.ts +2 -2
  22. package/lib/dts/memory/memory.d.ts +5 -3
  23. package/lib/dts/memory/recorder.d.ts +14 -4
  24. package/lib/dts/memory/retriever.d.ts +11 -5
  25. package/lib/esm/agents/agent.d.ts +15 -10
  26. package/lib/esm/agents/agent.js +5 -3
  27. package/lib/esm/agents/ai-agent.d.ts +1 -1
  28. package/lib/esm/agents/mcp-agent.d.ts +1 -1
  29. package/lib/esm/aigne/aigne.d.ts +4 -4
  30. package/lib/esm/aigne/aigne.js +2 -0
  31. package/lib/esm/aigne/context.d.ts +2 -2
  32. package/lib/esm/loader/index.d.ts +2 -2
  33. package/lib/esm/memory/memory.d.ts +5 -3
  34. package/lib/esm/memory/memory.js +16 -2
  35. package/lib/esm/memory/recorder.d.ts +14 -4
  36. package/lib/esm/memory/recorder.js +14 -2
  37. package/lib/esm/memory/retriever.d.ts +11 -5
  38. package/lib/esm/memory/retriever.js +9 -1
  39. package/package.json +3 -3
package/CHANGELOG.md CHANGED
@@ -1,23 +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
7
 
8
- ## [1.22.0](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.21.0...core-v1.22.0) (2025-06-24)
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)
9
16
 
10
17
 
11
18
  ### Features
12
19
 
13
- * 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))
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))
14
26
 
15
27
 
16
28
  ### Dependencies
17
29
 
18
30
  * The following workspace dependencies were updated
19
31
  * dependencies
20
- * @aigne/observability bumped to 0.1.0
32
+ * @aigne/observability bumped to 0.1.1
21
33
 
22
34
  ## [1.21.0](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.20.1...core-v1.21.0) (2025-06-20)
23
35
 
@@ -118,6 +130,15 @@
118
130
  * dependencies
119
131
  * @aigne/platform-helpers bumped to 0.1.0
120
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
+
121
142
  ## [1.16.0](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.15.0...core-v1.16.0) (2025-05-23)
122
143
 
123
144
 
@@ -320,85 +341,3 @@
320
341
  * **MCP:** catch list resource error treat as empty list ([1885fab](https://github.com/AIGNE-io/aigne-framework/commit/1885fab3585e0dd1467b127e5b47cd0b98282bab))
321
342
  * rename @aigne/core-next to @aigne/core ([3a81009](https://github.com/AIGNE-io/aigne-framework/commit/3a8100962c81813217b687ae28e8de604419c622))
322
343
  * use text resource from MCP correctly ([8b9eba8](https://github.com/AIGNE-io/aigne-framework/commit/8b9eba83352ec096a2a5d4f410d4c4bde7420bce))
323
-
324
- ## [1.2.0](https://github.com/AIGNE-io/aigne-framework/compare/core-next-v1.1.0...core-next-v1.2.0) (2025-03-18)
325
-
326
- - chore: release v1.2.0
327
-
328
- ## 1.1.0-beta.17 (2025-3-18)
329
-
330
- - chore: add support for esm module
331
-
332
-
333
- ## 1.1.0-beta.16 (2025-3-18)
334
-
335
- - chore: add puppeteer in linux need docker_container
336
-
337
- ## 1.1.0-beta.15 (2025-3-18)
338
-
339
- - chore: make coverage report as text to terminal
340
- - chore: update contributing docs
341
-
342
- ## 1.1.0-beta.14 (2025-3-18)
343
-
344
- - chore(example): add code-execution example
345
-
346
- ## 1.1.0-beta.13 (2025-3-18)
347
-
348
- - feat: add OrchestratorAgent in agent library
349
-
350
- ## 1.1.0-beta.12 (2025-3-14)
351
-
352
- - chore(example): add concurrency reflection handoff workflow examples
353
-
354
- ## 1.1.0-beta.11 (2025-3-14)
355
-
356
- - feat(core): add sequential and parallel helper function
357
- - chore(examples): add workflow-sequential example
358
-
359
- ## 1.1.0-beta.10 (2025-3-13)
360
-
361
- - chore: ensure required environment variables have values
362
-
363
- ## 1.1.0-beta.9 (2025-3-13)
364
-
365
- - fix(MCP): catch list resource error treat as empty list
366
-
367
- ## 1.1.0-beta.8 (2025-3-13)
368
-
369
- - fix(AIAgent): should pass both arguments (model generated) and input (user input) to tool
370
- - chore(examples): add workflow-router example
371
- - chore(examples): rename examples puppeteer-mcp-server and sqlite-mcp-server to mcp-server-puppeteer and mcp-server-sqlite
372
-
373
- ## 1.1.0-beta.7 (2025-3-13)
374
-
375
- - chore: rename @aigne/core to @aigne/core
376
-
377
- ## 1.1.0-beta.6 (2025-3-13)
378
-
379
- - chore(examples): default enable mcp debug message for examples
380
-
381
- ## 1.1.0-beta.5 (2025-3-13)
382
-
383
- - feat: support chat history in PromptBuilder
384
- - feat: add `prompts` for MCPAgent to consume prompts from MCP server
385
- - chore: add sqlite-mcp-server example
386
- - test: add more unit test cases
387
-
388
- ## 1.1.0-beta.4 (2025-3-12)
389
-
390
- - feat: support run puppeteer example chat loop in terminal
391
-
392
- ## 1.1.0-beta.3 (2025-3-11)
393
-
394
- - chore: set module type for core package
395
-
396
- ## 1.1.0-beta.2 (2025-3-11)
397
-
398
- - feat: use PromptBuilder instead of string instructions
399
- - refactor: use tools instead of skills
400
- - chore(examples): add puppeteer-mcp-server example
401
-
402
- ## 1.1.0-beta.1 (2025-3-11)
403
-
404
- - 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
  *
@@ -191,7 +192,7 @@ export declare abstract class Agent<I extends Message = Message, O extends Messa
191
192
  * Here's an example of using hooks:
192
193
  * {@includeCode ../../test/agents/agent.test.ts#example-agent-hooks}
193
194
  */
194
- readonly hooks: AgentHooks;
195
+ readonly hooks: AgentHooks<I, O>;
195
196
  /**
196
197
  * List of GuideRail agents applied to this agent
197
198
  *
@@ -277,8 +278,8 @@ export declare abstract class Agent<I extends Message = Message, O extends Messa
277
278
  * Skills can be accessed by name or by array index, allowing
278
279
  * the agent to delegate tasks to specialized sub-agents
279
280
  */
280
- readonly skills: Agent<Message, Message>[] & {
281
- [key: string]: Agent<Message, Message>;
281
+ readonly skills: Agent<any, any>[] & {
282
+ [key: string]: Agent<any, any>;
282
283
  };
283
284
  /**
284
285
  * Whether to disable emitting events for agent actions
@@ -519,7 +520,9 @@ export interface AgentHooks<I extends Message = Message, O extends Message = Mes
519
520
  onStart?: (event: {
520
521
  context: Context;
521
522
  input: I;
522
- }) => PromiseOrValue<void>;
523
+ }) => PromiseOrValue<void | {
524
+ input?: I;
525
+ }>;
523
526
  /**
524
527
  * Called when agent processing completes or fails
525
528
  *
@@ -534,7 +537,9 @@ export interface AgentHooks<I extends Message = Message, O extends Message = Mes
534
537
  input: I;
535
538
  output: O;
536
539
  error: Error;
537
- }, "output", "error">) => PromiseOrValue<void>;
540
+ }, "output", "error">) => PromiseOrValue<void | {
541
+ output?: O;
542
+ }>;
538
543
  /**
539
544
  * Called before a skill (sub-agent) is invoked
540
545
  *
@@ -546,7 +551,7 @@ export interface AgentHooks<I extends Message = Message, O extends Message = Mes
546
551
  onSkillStart?: (event: {
547
552
  context: Context;
548
553
  skill: Agent;
549
- input: I;
554
+ input: Message;
550
555
  }) => PromiseOrValue<void>;
551
556
  /**
552
557
  * Called after a skill (sub-agent) completes or fails
@@ -560,8 +565,8 @@ export interface AgentHooks<I extends Message = Message, O extends Message = Mes
560
565
  onSkillEnd?: (event: XOr<{
561
566
  context: Context;
562
567
  skill: Agent;
563
- input: I;
564
- output: O;
568
+ input: Message;
569
+ output: Message;
565
570
  error: Error;
566
571
  }, "output", "error">) => PromiseOrValue<void>;
567
572
  /**
@@ -348,8 +348,8 @@ class Agent {
348
348
  if (!this.disableEvents)
349
349
  opts.context.emit("agentStarted", { agent: this, input });
350
350
  try {
351
- await this.hooks.onStart?.({ context: opts.context, input });
352
- 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);
353
353
  await this.preprocess(parsedInput, opts);
354
354
  this.checkContextStatus(opts);
355
355
  let response = await this.process(parsedInput, opts);
@@ -412,7 +412,9 @@ class Agent {
412
412
  logger_js_1.logger.debug("Invoke agent %s succeed with output: %O", this.name, finalOutput);
413
413
  if (!this.disableEvents)
414
414
  context.emit("agentSucceed", { agent: this, output: finalOutput });
415
- 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;
416
418
  return finalOutput;
417
419
  }
418
420
  /**
@@ -131,7 +131,7 @@ 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
135
  tag: string;
136
136
  /**
137
137
  * Create an AIAgent with the specified options
@@ -183,7 +183,7 @@ declare class ClientWithReconnect extends Client {
183
183
  private reconnect;
184
184
  request<T extends ZodType<object>>(request: Request, resultSchema: T, options?: RequestOptions): Promise<z.infer<T>>;
185
185
  }
186
- 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> {
187
187
  client: ClientWithReconnect;
188
188
  }
189
189
  export declare abstract class MCPBase<I extends Message, O extends Message> extends Agent<I, O> {
@@ -93,15 +93,15 @@ export declare class AIGNE<U extends UserContext = UserContext> {
93
93
  * Collection of skill agents available to this AIGNE instance.
94
94
  * Provides indexed access by skill name.
95
95
  */
96
- readonly skills: Agent<Message, Message>[] & {
97
- [key: string]: Agent<Message, Message>;
96
+ readonly skills: Agent<any, any>[] & {
97
+ [key: string]: Agent<any, any>;
98
98
  };
99
99
  /**
100
100
  * Collection of primary agents managed by this AIGNE instance.
101
101
  * Provides indexed access by agent name.
102
102
  */
103
- readonly agents: Agent<Message, Message>[] & {
104
- [key: string]: Agent<Message, Message>;
103
+ readonly agents: Agent<any, any>[] & {
104
+ [key: string]: Agent<any, any>;
105
105
  };
106
106
  /**
107
107
  * Observer for the AIGNE instance.
@@ -128,6 +128,7 @@ class AIGNE {
128
128
  return context;
129
129
  }
130
130
  invoke(agent, message, options) {
131
+ this.observer?.serve();
131
132
  const context = new context_js_1.AIGNEContext(this);
132
133
  return context.invoke(agent, message, { ...options, newContext: false });
133
134
  }
@@ -145,6 +146,7 @@ class AIGNE {
145
146
  * {@includeCode ../../test/aigne/aigne.test.ts#example-publish-message}
146
147
  */
147
148
  publish(topic, payload, options) {
149
+ this.observer?.serve();
148
150
  return new context_js_1.AIGNEContext(this).publish(topic, payload, options);
149
151
  }
150
152
  subscribe(topic, listener) {
@@ -148,7 +148,7 @@ export declare class AIGNEContext implements Context {
148
148
  readonly internal: AIGNEContextShared;
149
149
  get messageQueue(): MessageQueue;
150
150
  get model(): ChatModel | undefined;
151
- get skills(): Agent<Message, Message>[] | undefined;
151
+ get skills(): Agent<any, any>[] | undefined;
152
152
  get observer(): AIGNEObserver | undefined;
153
153
  get limits(): ContextLimits | undefined;
154
154
  get status(): "normal" | "timeout";
@@ -180,7 +180,7 @@ declare class AIGNEContextShared {
180
180
  readonly messageQueue: MessageQueue;
181
181
  readonly events: Emitter<any>;
182
182
  get model(): ChatModel | undefined;
183
- get skills(): Agent<Message, Message>[] | undefined;
183
+ get skills(): Agent<any, any>[] | undefined;
184
184
  get observer(): AIGNEObserver | undefined;
185
185
  get limits(): ContextLimits | undefined;
186
186
  usage: ContextUsage;
@@ -17,8 +17,8 @@ export interface LoadOptions {
17
17
  }
18
18
  export declare function load(options: LoadOptions): Promise<{
19
19
  model: ChatModel | undefined;
20
- agents: Agent<import("../agents/agent.js").Message, import("../agents/agent.js").Message>[];
21
- skills: Agent<import("../agents/agent.js").Message, import("../agents/agent.js").Message>[];
20
+ agents: Agent<any, any>[];
21
+ skills: Agent<any, any>[];
22
22
  name?: string | null | undefined;
23
23
  description?: string | null | undefined;
24
24
  chat_model?: {
@@ -1,8 +1,8 @@
1
1
  import { Agent, type AgentInvokeOptions, type AgentOptions, type Message } from "../agents/agent.js";
2
2
  import type { Context } from "../aigne/context.js";
3
3
  import type { MessagePayload } from "../aigne/message-queue.js";
4
- import type { MemoryRecorder, MemoryRecorderInput, MemoryRecorderOutput } from "./recorder.js";
5
- import type { MemoryRetriever, MemoryRetrieverInput, MemoryRetrieverOutput } from "./retriever.js";
4
+ import { MemoryRecorder, type MemoryRecorderInput, type MemoryRecorderOptions, type MemoryRecorderOutput } from "./recorder.js";
5
+ import { MemoryRetriever, type MemoryRetrieverInput, type MemoryRetrieverOptions, type MemoryRetrieverOutput } from "./retriever.js";
6
6
  export interface Memory {
7
7
  id: string;
8
8
  sessionId?: string | null;
@@ -10,7 +10,9 @@ export interface Memory {
10
10
  createdAt: string;
11
11
  }
12
12
  export declare const newMemoryId: () => string;
13
- export interface MemoryAgentOptions extends Partial<Pick<MemoryAgent, "recorder" | "retriever" | "autoUpdate">>, Pick<AgentOptions, "subscribeTopic" | "skills"> {
13
+ export interface MemoryAgentOptions extends Partial<Pick<MemoryAgent, "autoUpdate">>, Pick<AgentOptions, "subscribeTopic" | "skills"> {
14
+ recorder?: MemoryRecorder | MemoryRecorderOptions["process"] | MemoryRecorderOptions;
15
+ retriever?: MemoryRetriever | MemoryRetrieverOptions["process"] | MemoryRetrieverOptions;
14
16
  }
15
17
  /**
16
18
  * A specialized agent responsible for managing, storing, and retrieving memories within the agent system.
@@ -5,6 +5,8 @@ const uuid_1 = require("uuid");
5
5
  const zod_1 = require("zod");
6
6
  const agent_js_1 = require("../agents/agent.js");
7
7
  const type_utils_js_1 = require("../utils/type-utils.js");
8
+ const recorder_js_1 = require("./recorder.js");
9
+ const retriever_js_1 = require("./retriever.js");
8
10
  const newMemoryId = () => (0, uuid_1.v7)();
9
11
  exports.newMemoryId = newMemoryId;
10
12
  /**
@@ -26,8 +28,20 @@ class MemoryAgent extends agent_js_1.Agent {
26
28
  subscribeTopic: options.subscribeTopic,
27
29
  skills: options.skills,
28
30
  });
29
- this.recorder = options.recorder;
30
- this.retriever = options.retriever;
31
+ this.recorder =
32
+ options.recorder instanceof recorder_js_1.MemoryRecorder
33
+ ? options.recorder
34
+ : options.recorder &&
35
+ new recorder_js_1.MemoryRecorder(typeof options.recorder === "function"
36
+ ? { process: options.recorder }
37
+ : options.recorder);
38
+ this.retriever =
39
+ options.retriever instanceof retriever_js_1.MemoryRetriever
40
+ ? options.retriever
41
+ : options.retriever &&
42
+ new retriever_js_1.MemoryRetriever(typeof options.retriever === "function"
43
+ ? { process: options.retriever }
44
+ : options.retriever);
31
45
  this.autoUpdate = options.autoUpdate;
32
46
  }
33
47
  _retriever;
@@ -1,5 +1,6 @@
1
1
  import { type ZodType, z } from "zod";
2
- import { Agent, type AgentOptions, type Message } from "../agents/agent.js";
2
+ import { Agent, type AgentInvokeOptions, type AgentOptions, type AgentProcessResult, type FunctionAgentFn, type Message } from "../agents/agent.js";
3
+ import type { PromiseOrValue } from "../utils/type-utils.js";
3
4
  import type { Memory } from "./memory.js";
4
5
  /**
5
6
  * Input for memory recording operations.
@@ -13,7 +14,11 @@ export interface MemoryRecorderInput extends Message {
13
14
  * Array of content items to record as memories.
14
15
  * Each item in this array will typically be converted into a separate memory entry.
15
16
  */
16
- content: unknown[];
17
+ content: {
18
+ role: "user" | "agent";
19
+ content: Message;
20
+ source?: string;
21
+ }[];
17
22
  }
18
23
  /**
19
24
  * @hidden
@@ -62,6 +67,9 @@ export declare const memoryRecorderOutputSchema: z.ZodObject<{
62
67
  createdAt: string;
63
68
  }[];
64
69
  }>;
70
+ export interface MemoryRecorderOptions extends Omit<AgentOptions<MemoryRecorderInput, MemoryRecorderOutput>, "inputSchema" | "outputSchema"> {
71
+ process?: FunctionAgentFn<MemoryRecorderInput, MemoryRecorderOutput>;
72
+ }
65
73
  /**
66
74
  * Abstract base class for agents that record and store memories.
67
75
  *
@@ -76,12 +84,14 @@ export declare const memoryRecorderOutputSchema: z.ZodObject<{
76
84
  * Custom implementations should extend this class and provide concrete
77
85
  * implementations of the process method to handle the actual storage logic.
78
86
  */
79
- export declare abstract class MemoryRecorder extends Agent<MemoryRecorderInput, MemoryRecorderOutput> {
87
+ export declare class MemoryRecorder extends Agent<MemoryRecorderInput, MemoryRecorderOutput> {
80
88
  tag: string;
81
89
  /**
82
90
  * Creates a new MemoryRecorder instance with predefined input and output schemas.
83
91
  *
84
92
  * @param options - Configuration options for the memory recorder agent
85
93
  */
86
- constructor(options: Omit<AgentOptions<MemoryRecorderInput, MemoryRecorderOutput>, "inputSchema" | "outputSchema">);
94
+ constructor(options: MemoryRecorderOptions);
95
+ private _process?;
96
+ process(input: MemoryRecorderInput, options: AgentInvokeOptions): PromiseOrValue<AgentProcessResult<MemoryRecorderOutput>>;
87
97
  }
@@ -7,7 +7,11 @@ const agent_js_1 = require("../agents/agent.js");
7
7
  * @hidden
8
8
  */
9
9
  exports.memoryRecorderInputSchema = zod_1.z.object({
10
- content: zod_1.z.array(zod_1.z.unknown()),
10
+ content: zod_1.z.array(zod_1.z.object({
11
+ role: zod_1.z.union([zod_1.z.literal("user"), zod_1.z.literal("agent")]),
12
+ content: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()),
13
+ source: zod_1.z.string().optional(),
14
+ })),
11
15
  });
12
16
  /**
13
17
  * @hidden
@@ -46,6 +50,14 @@ class MemoryRecorder extends agent_js_1.Agent {
46
50
  inputSchema: exports.memoryRecorderInputSchema,
47
51
  outputSchema: exports.memoryRecorderOutputSchema,
48
52
  });
53
+ this._process = options.process;
54
+ }
55
+ _process;
56
+ process(input, options) {
57
+ if (!this._process) {
58
+ throw new Error("MemoryRecorder process function is not defined.");
59
+ }
60
+ return this._process(input, options);
49
61
  }
50
62
  }
51
63
  exports.MemoryRecorder = MemoryRecorder;
@@ -1,5 +1,6 @@
1
1
  import { z } from "zod";
2
- import { Agent, type AgentOptions, type Message } from "../agents/agent.js";
2
+ import { Agent, type AgentInvokeOptions, type AgentOptions, type AgentProcessResult, type FunctionAgentFn, type Message } from "../agents/agent.js";
3
+ import type { PromiseOrValue } from "../utils/type-utils.js";
3
4
  import type { Memory } from "./memory.js";
4
5
  /**
5
6
  * Input for memory retrieval operations.
@@ -39,11 +40,11 @@ export declare const memoryRetrieverInputSchema: z.ZodObject<{
39
40
  limit: z.ZodOptional<z.ZodNumber>;
40
41
  search: z.ZodOptional<z.ZodString>;
41
42
  }, "strip", z.ZodTypeAny, {
42
- limit?: number | undefined;
43
43
  search?: string | undefined;
44
- }, {
45
44
  limit?: number | undefined;
45
+ }, {
46
46
  search?: string | undefined;
47
+ limit?: number | undefined;
47
48
  }>;
48
49
  /**
49
50
  * @hidden
@@ -75,6 +76,9 @@ export declare const memoryRetrieverOutputSchema: z.ZodObject<{
75
76
  createdAt: string;
76
77
  }[];
77
78
  }>;
79
+ export interface MemoryRetrieverOptions extends Omit<AgentOptions<MemoryRetrieverInput, MemoryRetrieverOutput>, "inputSchema" | "outputSchema"> {
80
+ process?: FunctionAgentFn<MemoryRetrieverInput, MemoryRetrieverOutput>;
81
+ }
78
82
  /**
79
83
  * Abstract base class for agents that retrieve memories from storage.
80
84
  *
@@ -89,12 +93,14 @@ export declare const memoryRetrieverOutputSchema: z.ZodObject<{
89
93
  * Custom implementations should extend this class and provide concrete
90
94
  * implementations of the process method to handle the actual retrieval logic.
91
95
  */
92
- export declare abstract class MemoryRetriever extends Agent<MemoryRetrieverInput, MemoryRetrieverOutput> {
96
+ export declare class MemoryRetriever extends Agent<MemoryRetrieverInput, MemoryRetrieverOutput> {
93
97
  tag: string;
94
98
  /**
95
99
  * Creates a new MemoryRetriever instance with predefined input and output schemas.
96
100
  *
97
101
  * @param options - Configuration options for the memory retriever agent
98
102
  */
99
- constructor(options: Omit<AgentOptions<MemoryRetrieverInput, MemoryRetrieverOutput>, "inputSchema" | "outputSchema">);
103
+ constructor(options: MemoryRetrieverOptions);
104
+ private _process?;
105
+ process(input: MemoryRetrieverInput, options: AgentInvokeOptions): PromiseOrValue<AgentProcessResult<MemoryRetrieverOutput>>;
100
106
  }
@@ -47,6 +47,14 @@ class MemoryRetriever extends agent_js_1.Agent {
47
47
  inputSchema: exports.memoryRetrieverInputSchema,
48
48
  outputSchema: exports.memoryRetrieverOutputSchema,
49
49
  });
50
+ this._process = options.process;
51
+ }
52
+ _process;
53
+ process(input, options) {
54
+ if (!this._process) {
55
+ throw new Error("MemoryRetriever process function is not implemented.");
56
+ }
57
+ return this._process(input, options);
50
58
  }
51
59
  }
52
60
  exports.MemoryRetriever = MemoryRetriever;
@@ -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
  *
@@ -191,7 +192,7 @@ export declare abstract class Agent<I extends Message = Message, O extends Messa
191
192
  * Here's an example of using hooks:
192
193
  * {@includeCode ../../test/agents/agent.test.ts#example-agent-hooks}
193
194
  */
194
- readonly hooks: AgentHooks;
195
+ readonly hooks: AgentHooks<I, O>;
195
196
  /**
196
197
  * List of GuideRail agents applied to this agent
197
198
  *
@@ -277,8 +278,8 @@ export declare abstract class Agent<I extends Message = Message, O extends Messa
277
278
  * Skills can be accessed by name or by array index, allowing
278
279
  * the agent to delegate tasks to specialized sub-agents
279
280
  */
280
- readonly skills: Agent<Message, Message>[] & {
281
- [key: string]: Agent<Message, Message>;
281
+ readonly skills: Agent<any, any>[] & {
282
+ [key: string]: Agent<any, any>;
282
283
  };
283
284
  /**
284
285
  * Whether to disable emitting events for agent actions
@@ -519,7 +520,9 @@ export interface AgentHooks<I extends Message = Message, O extends Message = Mes
519
520
  onStart?: (event: {
520
521
  context: Context;
521
522
  input: I;
522
- }) => PromiseOrValue<void>;
523
+ }) => PromiseOrValue<void | {
524
+ input?: I;
525
+ }>;
523
526
  /**
524
527
  * Called when agent processing completes or fails
525
528
  *
@@ -534,7 +537,9 @@ export interface AgentHooks<I extends Message = Message, O extends Message = Mes
534
537
  input: I;
535
538
  output: O;
536
539
  error: Error;
537
- }, "output", "error">) => PromiseOrValue<void>;
540
+ }, "output", "error">) => PromiseOrValue<void | {
541
+ output?: O;
542
+ }>;
538
543
  /**
539
544
  * Called before a skill (sub-agent) is invoked
540
545
  *
@@ -546,7 +551,7 @@ export interface AgentHooks<I extends Message = Message, O extends Message = Mes
546
551
  onSkillStart?: (event: {
547
552
  context: Context;
548
553
  skill: Agent;
549
- input: I;
554
+ input: Message;
550
555
  }) => PromiseOrValue<void>;
551
556
  /**
552
557
  * Called after a skill (sub-agent) completes or fails
@@ -560,8 +565,8 @@ export interface AgentHooks<I extends Message = Message, O extends Message = Mes
560
565
  onSkillEnd?: (event: XOr<{
561
566
  context: Context;
562
567
  skill: Agent;
563
- input: I;
564
- output: O;
568
+ input: Message;
569
+ output: Message;
565
570
  error: Error;
566
571
  }, "output", "error">) => PromiseOrValue<void>;
567
572
  /**
@@ -131,7 +131,7 @@ 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
135
  tag: string;
136
136
  /**
137
137
  * Create an AIAgent with the specified options
@@ -183,7 +183,7 @@ declare class ClientWithReconnect extends Client {
183
183
  private reconnect;
184
184
  request<T extends ZodType<object>>(request: Request, resultSchema: T, options?: RequestOptions): Promise<z.infer<T>>;
185
185
  }
186
- 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> {
187
187
  client: ClientWithReconnect;
188
188
  }
189
189
  export declare abstract class MCPBase<I extends Message, O extends Message> extends Agent<I, O> {
@@ -93,15 +93,15 @@ export declare class AIGNE<U extends UserContext = UserContext> {
93
93
  * Collection of skill agents available to this AIGNE instance.
94
94
  * Provides indexed access by skill name.
95
95
  */
96
- readonly skills: Agent<Message, Message>[] & {
97
- [key: string]: Agent<Message, Message>;
96
+ readonly skills: Agent<any, any>[] & {
97
+ [key: string]: Agent<any, any>;
98
98
  };
99
99
  /**
100
100
  * Collection of primary agents managed by this AIGNE instance.
101
101
  * Provides indexed access by agent name.
102
102
  */
103
- readonly agents: Agent<Message, Message>[] & {
104
- [key: string]: Agent<Message, Message>;
103
+ readonly agents: Agent<any, any>[] & {
104
+ [key: string]: Agent<any, any>;
105
105
  };
106
106
  /**
107
107
  * Observer for the AIGNE instance.
@@ -148,7 +148,7 @@ export declare class AIGNEContext implements Context {
148
148
  readonly internal: AIGNEContextShared;
149
149
  get messageQueue(): MessageQueue;
150
150
  get model(): ChatModel | undefined;
151
- get skills(): Agent<Message, Message>[] | undefined;
151
+ get skills(): Agent<any, any>[] | undefined;
152
152
  get observer(): AIGNEObserver | undefined;
153
153
  get limits(): ContextLimits | undefined;
154
154
  get status(): "normal" | "timeout";
@@ -180,7 +180,7 @@ declare class AIGNEContextShared {
180
180
  readonly messageQueue: MessageQueue;
181
181
  readonly events: Emitter<any>;
182
182
  get model(): ChatModel | undefined;
183
- get skills(): Agent<Message, Message>[] | undefined;
183
+ get skills(): Agent<any, any>[] | undefined;
184
184
  get observer(): AIGNEObserver | undefined;
185
185
  get limits(): ContextLimits | undefined;
186
186
  usage: ContextUsage;
@@ -17,8 +17,8 @@ export interface LoadOptions {
17
17
  }
18
18
  export declare function load(options: LoadOptions): Promise<{
19
19
  model: ChatModel | undefined;
20
- agents: Agent<import("../agents/agent.js").Message, import("../agents/agent.js").Message>[];
21
- skills: Agent<import("../agents/agent.js").Message, import("../agents/agent.js").Message>[];
20
+ agents: Agent<any, any>[];
21
+ skills: Agent<any, any>[];
22
22
  name?: string | null | undefined;
23
23
  description?: string | null | undefined;
24
24
  chat_model?: {
@@ -1,8 +1,8 @@
1
1
  import { Agent, type AgentInvokeOptions, type AgentOptions, type Message } from "../agents/agent.js";
2
2
  import type { Context } from "../aigne/context.js";
3
3
  import type { MessagePayload } from "../aigne/message-queue.js";
4
- import type { MemoryRecorder, MemoryRecorderInput, MemoryRecorderOutput } from "./recorder.js";
5
- import type { MemoryRetriever, MemoryRetrieverInput, MemoryRetrieverOutput } from "./retriever.js";
4
+ import { MemoryRecorder, type MemoryRecorderInput, type MemoryRecorderOptions, type MemoryRecorderOutput } from "./recorder.js";
5
+ import { MemoryRetriever, type MemoryRetrieverInput, type MemoryRetrieverOptions, type MemoryRetrieverOutput } from "./retriever.js";
6
6
  export interface Memory {
7
7
  id: string;
8
8
  sessionId?: string | null;
@@ -10,7 +10,9 @@ export interface Memory {
10
10
  createdAt: string;
11
11
  }
12
12
  export declare const newMemoryId: () => string;
13
- export interface MemoryAgentOptions extends Partial<Pick<MemoryAgent, "recorder" | "retriever" | "autoUpdate">>, Pick<AgentOptions, "subscribeTopic" | "skills"> {
13
+ export interface MemoryAgentOptions extends Partial<Pick<MemoryAgent, "autoUpdate">>, Pick<AgentOptions, "subscribeTopic" | "skills"> {
14
+ recorder?: MemoryRecorder | MemoryRecorderOptions["process"] | MemoryRecorderOptions;
15
+ retriever?: MemoryRetriever | MemoryRetrieverOptions["process"] | MemoryRetrieverOptions;
14
16
  }
15
17
  /**
16
18
  * A specialized agent responsible for managing, storing, and retrieving memories within the agent system.
@@ -1,5 +1,6 @@
1
1
  import { type ZodType, z } from "zod";
2
- import { Agent, type AgentOptions, type Message } from "../agents/agent.js";
2
+ import { Agent, type AgentInvokeOptions, type AgentOptions, type AgentProcessResult, type FunctionAgentFn, type Message } from "../agents/agent.js";
3
+ import type { PromiseOrValue } from "../utils/type-utils.js";
3
4
  import type { Memory } from "./memory.js";
4
5
  /**
5
6
  * Input for memory recording operations.
@@ -13,7 +14,11 @@ export interface MemoryRecorderInput extends Message {
13
14
  * Array of content items to record as memories.
14
15
  * Each item in this array will typically be converted into a separate memory entry.
15
16
  */
16
- content: unknown[];
17
+ content: {
18
+ role: "user" | "agent";
19
+ content: Message;
20
+ source?: string;
21
+ }[];
17
22
  }
18
23
  /**
19
24
  * @hidden
@@ -62,6 +67,9 @@ export declare const memoryRecorderOutputSchema: z.ZodObject<{
62
67
  createdAt: string;
63
68
  }[];
64
69
  }>;
70
+ export interface MemoryRecorderOptions extends Omit<AgentOptions<MemoryRecorderInput, MemoryRecorderOutput>, "inputSchema" | "outputSchema"> {
71
+ process?: FunctionAgentFn<MemoryRecorderInput, MemoryRecorderOutput>;
72
+ }
65
73
  /**
66
74
  * Abstract base class for agents that record and store memories.
67
75
  *
@@ -76,12 +84,14 @@ export declare const memoryRecorderOutputSchema: z.ZodObject<{
76
84
  * Custom implementations should extend this class and provide concrete
77
85
  * implementations of the process method to handle the actual storage logic.
78
86
  */
79
- export declare abstract class MemoryRecorder extends Agent<MemoryRecorderInput, MemoryRecorderOutput> {
87
+ export declare class MemoryRecorder extends Agent<MemoryRecorderInput, MemoryRecorderOutput> {
80
88
  tag: string;
81
89
  /**
82
90
  * Creates a new MemoryRecorder instance with predefined input and output schemas.
83
91
  *
84
92
  * @param options - Configuration options for the memory recorder agent
85
93
  */
86
- constructor(options: Omit<AgentOptions<MemoryRecorderInput, MemoryRecorderOutput>, "inputSchema" | "outputSchema">);
94
+ constructor(options: MemoryRecorderOptions);
95
+ private _process?;
96
+ process(input: MemoryRecorderInput, options: AgentInvokeOptions): PromiseOrValue<AgentProcessResult<MemoryRecorderOutput>>;
87
97
  }
@@ -1,5 +1,6 @@
1
1
  import { z } from "zod";
2
- import { Agent, type AgentOptions, type Message } from "../agents/agent.js";
2
+ import { Agent, type AgentInvokeOptions, type AgentOptions, type AgentProcessResult, type FunctionAgentFn, type Message } from "../agents/agent.js";
3
+ import type { PromiseOrValue } from "../utils/type-utils.js";
3
4
  import type { Memory } from "./memory.js";
4
5
  /**
5
6
  * Input for memory retrieval operations.
@@ -39,11 +40,11 @@ export declare const memoryRetrieverInputSchema: z.ZodObject<{
39
40
  limit: z.ZodOptional<z.ZodNumber>;
40
41
  search: z.ZodOptional<z.ZodString>;
41
42
  }, "strip", z.ZodTypeAny, {
42
- limit?: number | undefined;
43
43
  search?: string | undefined;
44
- }, {
45
44
  limit?: number | undefined;
45
+ }, {
46
46
  search?: string | undefined;
47
+ limit?: number | undefined;
47
48
  }>;
48
49
  /**
49
50
  * @hidden
@@ -75,6 +76,9 @@ export declare const memoryRetrieverOutputSchema: z.ZodObject<{
75
76
  createdAt: string;
76
77
  }[];
77
78
  }>;
79
+ export interface MemoryRetrieverOptions extends Omit<AgentOptions<MemoryRetrieverInput, MemoryRetrieverOutput>, "inputSchema" | "outputSchema"> {
80
+ process?: FunctionAgentFn<MemoryRetrieverInput, MemoryRetrieverOutput>;
81
+ }
78
82
  /**
79
83
  * Abstract base class for agents that retrieve memories from storage.
80
84
  *
@@ -89,12 +93,14 @@ export declare const memoryRetrieverOutputSchema: z.ZodObject<{
89
93
  * Custom implementations should extend this class and provide concrete
90
94
  * implementations of the process method to handle the actual retrieval logic.
91
95
  */
92
- export declare abstract class MemoryRetriever extends Agent<MemoryRetrieverInput, MemoryRetrieverOutput> {
96
+ export declare class MemoryRetriever extends Agent<MemoryRetrieverInput, MemoryRetrieverOutput> {
93
97
  tag: string;
94
98
  /**
95
99
  * Creates a new MemoryRetriever instance with predefined input and output schemas.
96
100
  *
97
101
  * @param options - Configuration options for the memory retriever agent
98
102
  */
99
- constructor(options: Omit<AgentOptions<MemoryRetrieverInput, MemoryRetrieverOutput>, "inputSchema" | "outputSchema">);
103
+ constructor(options: MemoryRetrieverOptions);
104
+ private _process?;
105
+ process(input: MemoryRetrieverInput, options: AgentInvokeOptions): PromiseOrValue<AgentProcessResult<MemoryRetrieverOutput>>;
100
106
  }
@@ -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
  *
@@ -191,7 +192,7 @@ export declare abstract class Agent<I extends Message = Message, O extends Messa
191
192
  * Here's an example of using hooks:
192
193
  * {@includeCode ../../test/agents/agent.test.ts#example-agent-hooks}
193
194
  */
194
- readonly hooks: AgentHooks;
195
+ readonly hooks: AgentHooks<I, O>;
195
196
  /**
196
197
  * List of GuideRail agents applied to this agent
197
198
  *
@@ -277,8 +278,8 @@ export declare abstract class Agent<I extends Message = Message, O extends Messa
277
278
  * Skills can be accessed by name or by array index, allowing
278
279
  * the agent to delegate tasks to specialized sub-agents
279
280
  */
280
- readonly skills: Agent<Message, Message>[] & {
281
- [key: string]: Agent<Message, Message>;
281
+ readonly skills: Agent<any, any>[] & {
282
+ [key: string]: Agent<any, any>;
282
283
  };
283
284
  /**
284
285
  * Whether to disable emitting events for agent actions
@@ -519,7 +520,9 @@ export interface AgentHooks<I extends Message = Message, O extends Message = Mes
519
520
  onStart?: (event: {
520
521
  context: Context;
521
522
  input: I;
522
- }) => PromiseOrValue<void>;
523
+ }) => PromiseOrValue<void | {
524
+ input?: I;
525
+ }>;
523
526
  /**
524
527
  * Called when agent processing completes or fails
525
528
  *
@@ -534,7 +537,9 @@ export interface AgentHooks<I extends Message = Message, O extends Message = Mes
534
537
  input: I;
535
538
  output: O;
536
539
  error: Error;
537
- }, "output", "error">) => PromiseOrValue<void>;
540
+ }, "output", "error">) => PromiseOrValue<void | {
541
+ output?: O;
542
+ }>;
538
543
  /**
539
544
  * Called before a skill (sub-agent) is invoked
540
545
  *
@@ -546,7 +551,7 @@ export interface AgentHooks<I extends Message = Message, O extends Message = Mes
546
551
  onSkillStart?: (event: {
547
552
  context: Context;
548
553
  skill: Agent;
549
- input: I;
554
+ input: Message;
550
555
  }) => PromiseOrValue<void>;
551
556
  /**
552
557
  * Called after a skill (sub-agent) completes or fails
@@ -560,8 +565,8 @@ export interface AgentHooks<I extends Message = Message, O extends Message = Mes
560
565
  onSkillEnd?: (event: XOr<{
561
566
  context: Context;
562
567
  skill: Agent;
563
- input: I;
564
- output: O;
568
+ input: Message;
569
+ output: Message;
565
570
  error: Error;
566
571
  }, "output", "error">) => PromiseOrValue<void>;
567
572
  /**
@@ -304,8 +304,8 @@ export class Agent {
304
304
  if (!this.disableEvents)
305
305
  opts.context.emit("agentStarted", { agent: this, input });
306
306
  try {
307
- await this.hooks.onStart?.({ context: opts.context, input });
308
- const parsedInput = checkArguments(`Agent ${this.name} input`, this.inputSchema, input);
307
+ let parsedInput = (await this.hooks.onStart?.({ context: opts.context, input }))?.input ?? input;
308
+ parsedInput = checkArguments(`Agent ${this.name} input`, this.inputSchema, input);
309
309
  await this.preprocess(parsedInput, opts);
310
310
  this.checkContextStatus(opts);
311
311
  let response = await this.process(parsedInput, opts);
@@ -368,7 +368,9 @@ export class Agent {
368
368
  logger.debug("Invoke agent %s succeed with output: %O", this.name, finalOutput);
369
369
  if (!this.disableEvents)
370
370
  context.emit("agentSucceed", { agent: this, output: finalOutput });
371
- await this.hooks.onEnd?.({ context, input, output: finalOutput });
371
+ const o = (await this.hooks.onEnd?.({ context, input, output: finalOutput }))?.output;
372
+ if (o)
373
+ return o;
372
374
  return finalOutput;
373
375
  }
374
376
  /**
@@ -131,7 +131,7 @@ 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
135
  tag: string;
136
136
  /**
137
137
  * Create an AIAgent with the specified options
@@ -183,7 +183,7 @@ declare class ClientWithReconnect extends Client {
183
183
  private reconnect;
184
184
  request<T extends ZodType<object>>(request: Request, resultSchema: T, options?: RequestOptions): Promise<z.infer<T>>;
185
185
  }
186
- 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> {
187
187
  client: ClientWithReconnect;
188
188
  }
189
189
  export declare abstract class MCPBase<I extends Message, O extends Message> extends Agent<I, O> {
@@ -93,15 +93,15 @@ export declare class AIGNE<U extends UserContext = UserContext> {
93
93
  * Collection of skill agents available to this AIGNE instance.
94
94
  * Provides indexed access by skill name.
95
95
  */
96
- readonly skills: Agent<Message, Message>[] & {
97
- [key: string]: Agent<Message, Message>;
96
+ readonly skills: Agent<any, any>[] & {
97
+ [key: string]: Agent<any, any>;
98
98
  };
99
99
  /**
100
100
  * Collection of primary agents managed by this AIGNE instance.
101
101
  * Provides indexed access by agent name.
102
102
  */
103
- readonly agents: Agent<Message, Message>[] & {
104
- [key: string]: Agent<Message, Message>;
103
+ readonly agents: Agent<any, any>[] & {
104
+ [key: string]: Agent<any, any>;
105
105
  };
106
106
  /**
107
107
  * Observer for the AIGNE instance.
@@ -125,6 +125,7 @@ export class AIGNE {
125
125
  return context;
126
126
  }
127
127
  invoke(agent, message, options) {
128
+ this.observer?.serve();
128
129
  const context = new AIGNEContext(this);
129
130
  return context.invoke(agent, message, { ...options, newContext: false });
130
131
  }
@@ -142,6 +143,7 @@ export class AIGNE {
142
143
  * {@includeCode ../../test/aigne/aigne.test.ts#example-publish-message}
143
144
  */
144
145
  publish(topic, payload, options) {
146
+ this.observer?.serve();
145
147
  return new AIGNEContext(this).publish(topic, payload, options);
146
148
  }
147
149
  subscribe(topic, listener) {
@@ -148,7 +148,7 @@ export declare class AIGNEContext implements Context {
148
148
  readonly internal: AIGNEContextShared;
149
149
  get messageQueue(): MessageQueue;
150
150
  get model(): ChatModel | undefined;
151
- get skills(): Agent<Message, Message>[] | undefined;
151
+ get skills(): Agent<any, any>[] | undefined;
152
152
  get observer(): AIGNEObserver | undefined;
153
153
  get limits(): ContextLimits | undefined;
154
154
  get status(): "normal" | "timeout";
@@ -180,7 +180,7 @@ declare class AIGNEContextShared {
180
180
  readonly messageQueue: MessageQueue;
181
181
  readonly events: Emitter<any>;
182
182
  get model(): ChatModel | undefined;
183
- get skills(): Agent<Message, Message>[] | undefined;
183
+ get skills(): Agent<any, any>[] | undefined;
184
184
  get observer(): AIGNEObserver | undefined;
185
185
  get limits(): ContextLimits | undefined;
186
186
  usage: ContextUsage;
@@ -17,8 +17,8 @@ export interface LoadOptions {
17
17
  }
18
18
  export declare function load(options: LoadOptions): Promise<{
19
19
  model: ChatModel | undefined;
20
- agents: Agent<import("../agents/agent.js").Message, import("../agents/agent.js").Message>[];
21
- skills: Agent<import("../agents/agent.js").Message, import("../agents/agent.js").Message>[];
20
+ agents: Agent<any, any>[];
21
+ skills: Agent<any, any>[];
22
22
  name?: string | null | undefined;
23
23
  description?: string | null | undefined;
24
24
  chat_model?: {
@@ -1,8 +1,8 @@
1
1
  import { Agent, type AgentInvokeOptions, type AgentOptions, type Message } from "../agents/agent.js";
2
2
  import type { Context } from "../aigne/context.js";
3
3
  import type { MessagePayload } from "../aigne/message-queue.js";
4
- import type { MemoryRecorder, MemoryRecorderInput, MemoryRecorderOutput } from "./recorder.js";
5
- import type { MemoryRetriever, MemoryRetrieverInput, MemoryRetrieverOutput } from "./retriever.js";
4
+ import { MemoryRecorder, type MemoryRecorderInput, type MemoryRecorderOptions, type MemoryRecorderOutput } from "./recorder.js";
5
+ import { MemoryRetriever, type MemoryRetrieverInput, type MemoryRetrieverOptions, type MemoryRetrieverOutput } from "./retriever.js";
6
6
  export interface Memory {
7
7
  id: string;
8
8
  sessionId?: string | null;
@@ -10,7 +10,9 @@ export interface Memory {
10
10
  createdAt: string;
11
11
  }
12
12
  export declare const newMemoryId: () => string;
13
- export interface MemoryAgentOptions extends Partial<Pick<MemoryAgent, "recorder" | "retriever" | "autoUpdate">>, Pick<AgentOptions, "subscribeTopic" | "skills"> {
13
+ export interface MemoryAgentOptions extends Partial<Pick<MemoryAgent, "autoUpdate">>, Pick<AgentOptions, "subscribeTopic" | "skills"> {
14
+ recorder?: MemoryRecorder | MemoryRecorderOptions["process"] | MemoryRecorderOptions;
15
+ retriever?: MemoryRetriever | MemoryRetrieverOptions["process"] | MemoryRetrieverOptions;
14
16
  }
15
17
  /**
16
18
  * A specialized agent responsible for managing, storing, and retrieving memories within the agent system.
@@ -2,6 +2,8 @@ import { v7 } from "uuid";
2
2
  import { z } from "zod";
3
3
  import { Agent, } from "../agents/agent.js";
4
4
  import { checkArguments, remove } from "../utils/type-utils.js";
5
+ import { MemoryRecorder, } from "./recorder.js";
6
+ import { MemoryRetriever, } from "./retriever.js";
5
7
  export const newMemoryId = () => v7();
6
8
  /**
7
9
  * A specialized agent responsible for managing, storing, and retrieving memories within the agent system.
@@ -22,8 +24,20 @@ export class MemoryAgent extends Agent {
22
24
  subscribeTopic: options.subscribeTopic,
23
25
  skills: options.skills,
24
26
  });
25
- this.recorder = options.recorder;
26
- this.retriever = options.retriever;
27
+ this.recorder =
28
+ options.recorder instanceof MemoryRecorder
29
+ ? options.recorder
30
+ : options.recorder &&
31
+ new MemoryRecorder(typeof options.recorder === "function"
32
+ ? { process: options.recorder }
33
+ : options.recorder);
34
+ this.retriever =
35
+ options.retriever instanceof MemoryRetriever
36
+ ? options.retriever
37
+ : options.retriever &&
38
+ new MemoryRetriever(typeof options.retriever === "function"
39
+ ? { process: options.retriever }
40
+ : options.retriever);
27
41
  this.autoUpdate = options.autoUpdate;
28
42
  }
29
43
  _retriever;
@@ -1,5 +1,6 @@
1
1
  import { type ZodType, z } from "zod";
2
- import { Agent, type AgentOptions, type Message } from "../agents/agent.js";
2
+ import { Agent, type AgentInvokeOptions, type AgentOptions, type AgentProcessResult, type FunctionAgentFn, type Message } from "../agents/agent.js";
3
+ import type { PromiseOrValue } from "../utils/type-utils.js";
3
4
  import type { Memory } from "./memory.js";
4
5
  /**
5
6
  * Input for memory recording operations.
@@ -13,7 +14,11 @@ export interface MemoryRecorderInput extends Message {
13
14
  * Array of content items to record as memories.
14
15
  * Each item in this array will typically be converted into a separate memory entry.
15
16
  */
16
- content: unknown[];
17
+ content: {
18
+ role: "user" | "agent";
19
+ content: Message;
20
+ source?: string;
21
+ }[];
17
22
  }
18
23
  /**
19
24
  * @hidden
@@ -62,6 +67,9 @@ export declare const memoryRecorderOutputSchema: z.ZodObject<{
62
67
  createdAt: string;
63
68
  }[];
64
69
  }>;
70
+ export interface MemoryRecorderOptions extends Omit<AgentOptions<MemoryRecorderInput, MemoryRecorderOutput>, "inputSchema" | "outputSchema"> {
71
+ process?: FunctionAgentFn<MemoryRecorderInput, MemoryRecorderOutput>;
72
+ }
65
73
  /**
66
74
  * Abstract base class for agents that record and store memories.
67
75
  *
@@ -76,12 +84,14 @@ export declare const memoryRecorderOutputSchema: z.ZodObject<{
76
84
  * Custom implementations should extend this class and provide concrete
77
85
  * implementations of the process method to handle the actual storage logic.
78
86
  */
79
- export declare abstract class MemoryRecorder extends Agent<MemoryRecorderInput, MemoryRecorderOutput> {
87
+ export declare class MemoryRecorder extends Agent<MemoryRecorderInput, MemoryRecorderOutput> {
80
88
  tag: string;
81
89
  /**
82
90
  * Creates a new MemoryRecorder instance with predefined input and output schemas.
83
91
  *
84
92
  * @param options - Configuration options for the memory recorder agent
85
93
  */
86
- constructor(options: Omit<AgentOptions<MemoryRecorderInput, MemoryRecorderOutput>, "inputSchema" | "outputSchema">);
94
+ constructor(options: MemoryRecorderOptions);
95
+ private _process?;
96
+ process(input: MemoryRecorderInput, options: AgentInvokeOptions): PromiseOrValue<AgentProcessResult<MemoryRecorderOutput>>;
87
97
  }
@@ -1,10 +1,14 @@
1
1
  import { z } from "zod";
2
- import { Agent } from "../agents/agent.js";
2
+ import { Agent, } from "../agents/agent.js";
3
3
  /**
4
4
  * @hidden
5
5
  */
6
6
  export const memoryRecorderInputSchema = z.object({
7
- content: z.array(z.unknown()),
7
+ content: z.array(z.object({
8
+ role: z.union([z.literal("user"), z.literal("agent")]),
9
+ content: z.record(z.string(), z.unknown()),
10
+ source: z.string().optional(),
11
+ })),
8
12
  });
9
13
  /**
10
14
  * @hidden
@@ -43,5 +47,13 @@ export class MemoryRecorder extends Agent {
43
47
  inputSchema: memoryRecorderInputSchema,
44
48
  outputSchema: memoryRecorderOutputSchema,
45
49
  });
50
+ this._process = options.process;
51
+ }
52
+ _process;
53
+ process(input, options) {
54
+ if (!this._process) {
55
+ throw new Error("MemoryRecorder process function is not defined.");
56
+ }
57
+ return this._process(input, options);
46
58
  }
47
59
  }
@@ -1,5 +1,6 @@
1
1
  import { z } from "zod";
2
- import { Agent, type AgentOptions, type Message } from "../agents/agent.js";
2
+ import { Agent, type AgentInvokeOptions, type AgentOptions, type AgentProcessResult, type FunctionAgentFn, type Message } from "../agents/agent.js";
3
+ import type { PromiseOrValue } from "../utils/type-utils.js";
3
4
  import type { Memory } from "./memory.js";
4
5
  /**
5
6
  * Input for memory retrieval operations.
@@ -39,11 +40,11 @@ export declare const memoryRetrieverInputSchema: z.ZodObject<{
39
40
  limit: z.ZodOptional<z.ZodNumber>;
40
41
  search: z.ZodOptional<z.ZodString>;
41
42
  }, "strip", z.ZodTypeAny, {
42
- limit?: number | undefined;
43
43
  search?: string | undefined;
44
- }, {
45
44
  limit?: number | undefined;
45
+ }, {
46
46
  search?: string | undefined;
47
+ limit?: number | undefined;
47
48
  }>;
48
49
  /**
49
50
  * @hidden
@@ -75,6 +76,9 @@ export declare const memoryRetrieverOutputSchema: z.ZodObject<{
75
76
  createdAt: string;
76
77
  }[];
77
78
  }>;
79
+ export interface MemoryRetrieverOptions extends Omit<AgentOptions<MemoryRetrieverInput, MemoryRetrieverOutput>, "inputSchema" | "outputSchema"> {
80
+ process?: FunctionAgentFn<MemoryRetrieverInput, MemoryRetrieverOutput>;
81
+ }
78
82
  /**
79
83
  * Abstract base class for agents that retrieve memories from storage.
80
84
  *
@@ -89,12 +93,14 @@ export declare const memoryRetrieverOutputSchema: z.ZodObject<{
89
93
  * Custom implementations should extend this class and provide concrete
90
94
  * implementations of the process method to handle the actual retrieval logic.
91
95
  */
92
- export declare abstract class MemoryRetriever extends Agent<MemoryRetrieverInput, MemoryRetrieverOutput> {
96
+ export declare class MemoryRetriever extends Agent<MemoryRetrieverInput, MemoryRetrieverOutput> {
93
97
  tag: string;
94
98
  /**
95
99
  * Creates a new MemoryRetriever instance with predefined input and output schemas.
96
100
  *
97
101
  * @param options - Configuration options for the memory retriever agent
98
102
  */
99
- constructor(options: Omit<AgentOptions<MemoryRetrieverInput, MemoryRetrieverOutput>, "inputSchema" | "outputSchema">);
103
+ constructor(options: MemoryRetrieverOptions);
104
+ private _process?;
105
+ process(input: MemoryRetrieverInput, options: AgentInvokeOptions): PromiseOrValue<AgentProcessResult<MemoryRetrieverOutput>>;
100
106
  }
@@ -1,5 +1,5 @@
1
1
  import { z } from "zod";
2
- import { Agent } from "../agents/agent.js";
2
+ import { Agent, } from "../agents/agent.js";
3
3
  /**
4
4
  * @hidden
5
5
  */
@@ -44,5 +44,13 @@ export class MemoryRetriever extends Agent {
44
44
  inputSchema: memoryRetrieverInputSchema,
45
45
  outputSchema: memoryRetrieverOutputSchema,
46
46
  });
47
+ this._process = options.process;
48
+ }
49
+ _process;
50
+ process(input, options) {
51
+ if (!this._process) {
52
+ throw new Error("MemoryRetriever process function is not implemented.");
53
+ }
54
+ return this._process(input, options);
47
55
  }
48
56
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aigne/core",
3
- "version": "1.22.0",
3
+ "version": "1.23.0",
4
4
  "description": "AIGNE core library for building AI-powered applications",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -81,8 +81,8 @@
81
81
  "yaml": "^2.7.1",
82
82
  "zod": "^3.24.4",
83
83
  "zod-to-json-schema": "^3.24.5",
84
- "@aigne/observability": "^0.1.0",
85
- "@aigne/platform-helpers": "^0.1.2"
84
+ "@aigne/platform-helpers": "^0.1.2",
85
+ "@aigne/observability": "^0.1.1"
86
86
  },
87
87
  "devDependencies": {
88
88
  "@types/bun": "^1.2.12",