@aigne/core 1.22.0 → 1.23.1

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 (44) hide show
  1. package/CHANGELOG.md +33 -87
  2. package/lib/cjs/agents/agent.d.ts +15 -10
  3. package/lib/cjs/agents/agent.js +6 -10
  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 +17 -3
  12. package/lib/cjs/memory/recorder.d.ts +14 -8
  13. package/lib/cjs/memory/recorder.js +13 -1
  14. package/lib/cjs/memory/retriever.d.ts +13 -7
  15. package/lib/cjs/memory/retriever.js +9 -1
  16. package/lib/cjs/utils/type-utils.d.ts +1 -0
  17. package/lib/cjs/utils/type-utils.js +5 -0
  18. package/lib/dts/agents/agent.d.ts +15 -10
  19. package/lib/dts/agents/ai-agent.d.ts +1 -1
  20. package/lib/dts/agents/mcp-agent.d.ts +1 -1
  21. package/lib/dts/aigne/aigne.d.ts +4 -4
  22. package/lib/dts/aigne/context.d.ts +2 -2
  23. package/lib/dts/loader/index.d.ts +2 -2
  24. package/lib/dts/memory/memory.d.ts +5 -3
  25. package/lib/dts/memory/recorder.d.ts +14 -8
  26. package/lib/dts/memory/retriever.d.ts +13 -7
  27. package/lib/dts/utils/type-utils.d.ts +1 -0
  28. package/lib/esm/agents/agent.d.ts +15 -10
  29. package/lib/esm/agents/agent.js +6 -10
  30. package/lib/esm/agents/ai-agent.d.ts +1 -1
  31. package/lib/esm/agents/mcp-agent.d.ts +1 -1
  32. package/lib/esm/aigne/aigne.d.ts +4 -4
  33. package/lib/esm/aigne/aigne.js +2 -0
  34. package/lib/esm/aigne/context.d.ts +2 -2
  35. package/lib/esm/loader/index.d.ts +2 -2
  36. package/lib/esm/memory/memory.d.ts +5 -3
  37. package/lib/esm/memory/memory.js +17 -3
  38. package/lib/esm/memory/recorder.d.ts +14 -8
  39. package/lib/esm/memory/recorder.js +14 -2
  40. package/lib/esm/memory/retriever.d.ts +13 -7
  41. package/lib/esm/memory/retriever.js +10 -2
  42. package/lib/esm/utils/type-utils.d.ts +1 -0
  43. package/lib/esm/utils/type-utils.js +4 -0
  44. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -1,23 +1,42 @@
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.1](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.23.0...core-v1.23.1) (2025-06-25)
16
+
17
+
18
+ ### Bug Fixes
19
+
20
+ * **core:** pass input/output to MemoryAgent directily ([#178](https://github.com/AIGNE-io/aigne-framework/issues/178)) ([3b20e33](https://github.com/AIGNE-io/aigne-framework/commit/3b20e33f1eefc81ac1e009b1afff14fca46644b1))
21
+
22
+ ## [1.23.0](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.22.0...core-v1.23.0) (2025-06-25)
9
23
 
10
24
 
11
25
  ### Features
12
26
 
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))
27
+ * 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))
28
+
29
+
30
+ ### Bug Fixes
31
+
32
+ * **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
33
 
15
34
 
16
35
  ### Dependencies
17
36
 
18
37
  * The following workspace dependencies were updated
19
38
  * dependencies
20
- * @aigne/observability bumped to 0.1.0
39
+ * @aigne/observability bumped to 0.1.1
21
40
 
22
41
  ## [1.21.0](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.20.1...core-v1.21.0) (2025-06-20)
23
42
 
@@ -118,6 +137,15 @@
118
137
  * dependencies
119
138
  * @aigne/platform-helpers bumped to 0.1.0
120
139
 
140
+
141
+ ## [1.17.0](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.16.0...core-v1.17.0) (2025-05-25)
142
+
143
+
144
+ ### Features
145
+
146
+ * add user context support ([#131](https://github.com/AIGNE-io/aigne-framework/issues/131)) ([4dd9d20](https://github.com/AIGNE-io/aigne-framework/commit/4dd9d20953f6ac33933723db56efd9b44bafeb02))
147
+
148
+
121
149
  ## [1.16.0](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.15.0...core-v1.16.0) (2025-05-23)
122
150
 
123
151
 
@@ -320,85 +348,3 @@
320
348
  * **MCP:** catch list resource error treat as empty list ([1885fab](https://github.com/AIGNE-io/aigne-framework/commit/1885fab3585e0dd1467b127e5b47cd0b98282bab))
321
349
  * rename @aigne/core-next to @aigne/core ([3a81009](https://github.com/AIGNE-io/aigne-framework/commit/3a8100962c81813217b687ae28e8de604419c622))
322
350
  * 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
  /**
@@ -317,7 +317,6 @@ class Agent {
317
317
  for (const memory of this.memories) {
318
318
  const ms = (await memory.retrieve({
319
319
  ...input,
320
- search: typeof input.search === "string" ? input.search : JSON.stringify(input.search),
321
320
  limit: input.limit ?? this.maxRetrieveMemoryCount,
322
321
  }, options.context)).memories;
323
322
  memories.push(...ms);
@@ -348,8 +347,8 @@ class Agent {
348
347
  if (!this.disableEvents)
349
348
  opts.context.emit("agentStarted", { agent: this, input });
350
349
  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);
350
+ let parsedInput = (await this.hooks.onStart?.({ context: opts.context, input }))?.input ?? input;
351
+ parsedInput = (0, type_utils_js_1.checkArguments)(`Agent ${this.name} input`, this.inputSchema, input);
353
352
  await this.preprocess(parsedInput, opts);
354
353
  this.checkContextStatus(opts);
355
354
  let response = await this.process(parsedInput, opts);
@@ -412,7 +411,9 @@ class Agent {
412
411
  logger_js_1.logger.debug("Invoke agent %s succeed with output: %O", this.name, finalOutput);
413
412
  if (!this.disableEvents)
414
413
  context.emit("agentSucceed", { agent: this, output: finalOutput });
415
- await this.hooks.onEnd?.({ context, input, output: finalOutput });
414
+ const o = (await this.hooks.onEnd?.({ context, input, output: finalOutput }))?.output;
415
+ if (o)
416
+ return o;
416
417
  return finalOutput;
417
418
  }
418
419
  /**
@@ -519,12 +520,7 @@ class Agent {
519
520
  async postprocess(input, output, options) {
520
521
  this.checkContextStatus(options);
521
522
  this.publishToTopics(output, options);
522
- await this.recordMemories({
523
- content: [
524
- { role: "user", content: input },
525
- { role: "agent", content: (0, types_js_1.replaceTransferAgentToName)(output), source: this.name },
526
- ],
527
- }, options);
523
+ await this.recordMemories({ content: [{ input, output: (0, types_js_1.replaceTransferAgentToName)(output), source: this.name }] }, options);
528
524
  }
529
525
  async publishToTopics(output, options) {
530
526
  const publishTopics = typeof this.publishTopic === "function" ? await this.publishTopic(output) : this.publishTopic;
@@ -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;
@@ -120,7 +134,7 @@ class MemoryAgent extends agent_js_1.Agent {
120
134
  return context.invoke(this.recorder, input);
121
135
  }
122
136
  async onMessage({ role, source, message, context }) {
123
- this.record({ content: [{ role, source, content: message }] }, context);
137
+ this.record({ content: [role === "user" ? { input: message } : { output: message, source }] }, context);
124
138
  }
125
139
  }
126
140
  exports.MemoryAgent = MemoryAgent;
@@ -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.
@@ -9,11 +10,11 @@ import type { Memory } from "./memory.js";
9
10
  * should be stored as memories.
10
11
  */
11
12
  export interface MemoryRecorderInput extends Message {
12
- /**
13
- * Array of content items to record as memories.
14
- * Each item in this array will typically be converted into a separate memory entry.
15
- */
16
- content: unknown[];
13
+ content: {
14
+ input?: Message;
15
+ output?: Message;
16
+ source?: string;
17
+ }[];
17
18
  }
18
19
  /**
19
20
  * @hidden
@@ -62,6 +63,9 @@ export declare const memoryRecorderOutputSchema: z.ZodObject<{
62
63
  createdAt: string;
63
64
  }[];
64
65
  }>;
66
+ export interface MemoryRecorderOptions extends Omit<AgentOptions<MemoryRecorderInput, MemoryRecorderOutput>, "inputSchema" | "outputSchema"> {
67
+ process?: FunctionAgentFn<MemoryRecorderInput, MemoryRecorderOutput>;
68
+ }
65
69
  /**
66
70
  * Abstract base class for agents that record and store memories.
67
71
  *
@@ -76,12 +80,14 @@ export declare const memoryRecorderOutputSchema: z.ZodObject<{
76
80
  * Custom implementations should extend this class and provide concrete
77
81
  * implementations of the process method to handle the actual storage logic.
78
82
  */
79
- export declare abstract class MemoryRecorder extends Agent<MemoryRecorderInput, MemoryRecorderOutput> {
83
+ export declare class MemoryRecorder extends Agent<MemoryRecorderInput, MemoryRecorderOutput> {
80
84
  tag: string;
81
85
  /**
82
86
  * Creates a new MemoryRecorder instance with predefined input and output schemas.
83
87
  *
84
88
  * @param options - Configuration options for the memory recorder agent
85
89
  */
86
- constructor(options: Omit<AgentOptions<MemoryRecorderInput, MemoryRecorderOutput>, "inputSchema" | "outputSchema">);
90
+ constructor(options: MemoryRecorderOptions);
91
+ private _process?;
92
+ process(input: MemoryRecorderInput, options: AgentInvokeOptions): PromiseOrValue<AgentProcessResult<MemoryRecorderOutput>>;
87
93
  }
@@ -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
+ input: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()).optional(),
12
+ output: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()).optional(),
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.
@@ -17,7 +18,7 @@ export interface MemoryRetrieverInput extends Message {
17
18
  * Search term to filter memories by.
18
19
  * How the search is implemented depends on the specific retriever implementation.
19
20
  */
20
- search?: string;
21
+ search?: string | Message;
21
22
  }
22
23
  /**
23
24
  * Output from memory retrieval operations.
@@ -37,13 +38,13 @@ export interface MemoryRetrieverOutput extends Message {
37
38
  */
38
39
  export declare const memoryRetrieverInputSchema: z.ZodObject<{
39
40
  limit: z.ZodOptional<z.ZodNumber>;
40
- search: z.ZodOptional<z.ZodString>;
41
+ search: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodRecord<z.ZodString, z.ZodUnknown>]>>;
41
42
  }, "strip", z.ZodTypeAny, {
43
+ search?: string | Record<string, unknown> | undefined;
42
44
  limit?: number | undefined;
43
- search?: string | undefined;
44
45
  }, {
46
+ search?: string | Record<string, unknown> | undefined;
45
47
  limit?: number | undefined;
46
- search?: string | 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
  }
@@ -8,7 +8,7 @@ const agent_js_1 = require("../agents/agent.js");
8
8
  */
9
9
  exports.memoryRetrieverInputSchema = zod_1.z.object({
10
10
  limit: zod_1.z.number().optional(),
11
- search: zod_1.z.string().optional(),
11
+ search: zod_1.z.union([zod_1.z.string(), zod_1.z.record(zod_1.z.string(), zod_1.z.unknown())]).optional(),
12
12
  });
13
13
  /**
14
14
  * @hidden
@@ -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;
@@ -15,6 +15,7 @@ export declare function isNotEmpty<T>(arr: T[]): arr is [T, ...T[]];
15
15
  export declare function duplicates<T>(arr: T[], key?: (item: T) => unknown): T[];
16
16
  export declare function remove<T>(arr: T[], remove: T[] | ((item: T) => boolean)): T[];
17
17
  export declare function unique<T>(arr: T[], key?: (item: T) => unknown): T[];
18
+ export declare function pick<T extends Record<string, unknown>, K extends keyof T | string>(obj: T, ...keys: (K | K[])[]): Pick<T, Extract<K, keyof T>> & Partial<Record<Exclude<K, keyof T>, unknown>>;
18
19
  export declare function omit<T extends Record<string, unknown>, K extends keyof T>(obj: T, ...keys: (K | K[])[]): Omit<T, K>;
19
20
  export declare function omitDeep<T, K>(obj: T, ...keys: (K | K[])[]): unknown;
20
21
  export declare function omitBy<T extends Record<string, unknown>, K extends keyof T>(obj: T, predicate: (value: T[K], key: K) => boolean): Partial<T>;
@@ -8,6 +8,7 @@ exports.isNotEmpty = isNotEmpty;
8
8
  exports.duplicates = duplicates;
9
9
  exports.remove = remove;
10
10
  exports.unique = unique;
11
+ exports.pick = pick;
11
12
  exports.omit = omit;
12
13
  exports.omitDeep = omitDeep;
13
14
  exports.omitBy = omitBy;
@@ -75,6 +76,10 @@ function unique(arr, key = (item) => item) {
75
76
  return true;
76
77
  });
77
78
  }
79
+ function pick(obj, ...keys) {
80
+ const flattenedKeys = new Set(keys.flat());
81
+ return Object.fromEntries(Object.entries(obj).filter(([key]) => flattenedKeys.has(key)));
82
+ }
78
83
  function omit(obj, ...keys) {
79
84
  const flattenedKeys = new Set(keys.flat());
80
85
  return Object.fromEntries(Object.entries(obj).filter(([key]) => !flattenedKeys.has(key)));