@aigne/core 1.23.0 → 1.24.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 (38) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/lib/cjs/agents/agent.js +1 -7
  3. package/lib/cjs/agents/ai-agent.d.ts +2 -2
  4. package/lib/cjs/agents/ai-agent.js +3 -4
  5. package/lib/cjs/agents/mcp-agent.js +1 -1
  6. package/lib/cjs/aigne/aigne.d.ts +2 -2
  7. package/lib/cjs/aigne/aigne.js +5 -7
  8. package/lib/cjs/aigne/context.d.ts +1 -1
  9. package/lib/cjs/aigne/context.js +2 -2
  10. package/lib/cjs/memory/memory.js +1 -1
  11. package/lib/cjs/memory/recorder.d.ts +2 -6
  12. package/lib/cjs/memory/recorder.js +2 -2
  13. package/lib/cjs/memory/retriever.d.ts +4 -4
  14. package/lib/cjs/memory/retriever.js +1 -1
  15. package/lib/cjs/utils/type-utils.d.ts +2 -1
  16. package/lib/cjs/utils/type-utils.js +5 -0
  17. package/lib/dts/agents/ai-agent.d.ts +2 -2
  18. package/lib/dts/aigne/aigne.d.ts +2 -2
  19. package/lib/dts/aigne/context.d.ts +1 -1
  20. package/lib/dts/memory/recorder.d.ts +2 -6
  21. package/lib/dts/memory/retriever.d.ts +4 -4
  22. package/lib/dts/utils/type-utils.d.ts +2 -1
  23. package/lib/esm/agents/agent.js +1 -7
  24. package/lib/esm/agents/ai-agent.d.ts +2 -2
  25. package/lib/esm/agents/ai-agent.js +3 -4
  26. package/lib/esm/agents/mcp-agent.js +1 -1
  27. package/lib/esm/aigne/aigne.d.ts +2 -2
  28. package/lib/esm/aigne/aigne.js +5 -7
  29. package/lib/esm/aigne/context.d.ts +1 -1
  30. package/lib/esm/aigne/context.js +3 -3
  31. package/lib/esm/memory/memory.js +1 -1
  32. package/lib/esm/memory/recorder.d.ts +2 -6
  33. package/lib/esm/memory/recorder.js +2 -2
  34. package/lib/esm/memory/retriever.d.ts +4 -4
  35. package/lib/esm/memory/retriever.js +1 -1
  36. package/lib/esm/utils/type-utils.d.ts +2 -1
  37. package/lib/esm/utils/type-utils.js +4 -0
  38. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -12,6 +12,27 @@
12
12
  * dependencies
13
13
  * @aigne/observability bumped to 0.1.0
14
14
 
15
+ ## [1.24.0](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.23.1...core-v1.24.0) (2025-06-26)
16
+
17
+
18
+ ### Features
19
+
20
+ * **transport:** support invoke server side chat model ([#182](https://github.com/AIGNE-io/aigne-framework/issues/182)) ([f81a1bf](https://github.com/AIGNE-io/aigne-framework/commit/f81a1bf883abda1845ccee09b270e5f583e287ab))
21
+
22
+
23
+ ### Dependencies
24
+
25
+ * The following workspace dependencies were updated
26
+ * dependencies
27
+ * @aigne/observability bumped to 0.1.2
28
+
29
+ ## [1.23.1](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.23.0...core-v1.23.1) (2025-06-25)
30
+
31
+
32
+ ### Bug Fixes
33
+
34
+ * **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))
35
+
15
36
  ## [1.23.0](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.22.0...core-v1.23.0) (2025-06-25)
16
37
 
17
38
 
@@ -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);
@@ -521,12 +520,7 @@ class Agent {
521
520
  async postprocess(input, output, options) {
522
521
  this.checkContextStatus(options);
523
522
  this.publishToTopics(output, options);
524
- await this.recordMemories({
525
- content: [
526
- { role: "user", content: input },
527
- { role: "agent", content: (0, types_js_1.replaceTransferAgentToName)(output), source: this.name },
528
- ],
529
- }, options);
523
+ await this.recordMemories({ content: [{ input, output: (0, types_js_1.replaceTransferAgentToName)(output), source: this.name }] }, options);
530
524
  }
531
525
  async publishToTopics(output, options) {
532
526
  const publishTopics = typeof this.publishTopic === "function" ? await this.publishTopic(output) : this.publishTopic;
@@ -1,7 +1,7 @@
1
1
  import { type ZodObject, type ZodType, z } from "zod";
2
2
  import { PromptBuilder } from "../prompt/prompt-builder.js";
3
3
  import { Agent, type AgentInvokeOptions, type AgentOptions, type AgentProcessAsyncGenerator, type Message } from "./agent.js";
4
- import { ChatModel, type ChatModelInput } from "./chat-model.js";
4
+ import type { ChatModel, ChatModelInput } from "./chat-model.js";
5
5
  import type { GuideRailAgentOutput } from "./guide-rail-agent.js";
6
6
  export declare const DEFAULT_OUTPUT_KEY = "message";
7
7
  /**
@@ -100,7 +100,7 @@ export declare enum AIAgentToolChoice {
100
100
  *
101
101
  * @hidden
102
102
  */
103
- export declare const aiAgentToolChoiceSchema: z.ZodUnion<[z.ZodNativeEnum<typeof AIAgentToolChoice>, ZodType<Agent<Message, Message>, z.ZodTypeDef, Agent<Message, Message>>]>;
103
+ export declare const aiAgentToolChoiceSchema: z.ZodUnion<[z.ZodNativeEnum<typeof AIAgentToolChoice>, ZodType<Agent<any, any>, z.ZodTypeDef, Agent<any, any>>]>;
104
104
  /**
105
105
  * Zod schema for validating AIAgentOptions
106
106
  *
@@ -6,7 +6,6 @@ const prompt_builder_js_1 = require("../prompt/prompt-builder.js");
6
6
  const template_js_1 = require("../prompt/template.js");
7
7
  const type_utils_js_1 = require("../utils/type-utils.js");
8
8
  const agent_js_1 = require("./agent.js");
9
- const chat_model_js_1 = require("./chat-model.js");
10
9
  const types_js_1 = require("./types.js");
11
10
  exports.DEFAULT_OUTPUT_KEY = "message";
12
11
  /**
@@ -40,7 +39,7 @@ var AIAgentToolChoice;
40
39
  *
41
40
  * @hidden
42
41
  */
43
- exports.aiAgentToolChoiceSchema = zod_1.z.union([zod_1.z.nativeEnum(AIAgentToolChoice), zod_1.z.instanceof(agent_js_1.Agent)], {
42
+ exports.aiAgentToolChoiceSchema = zod_1.z.union([zod_1.z.nativeEnum(AIAgentToolChoice), zod_1.z.custom()], {
44
43
  message: `aiAgentToolChoice must be ${Object.values(AIAgentToolChoice).join(", ")}, or an Agent`,
45
44
  });
46
45
  /**
@@ -51,8 +50,8 @@ exports.aiAgentToolChoiceSchema = zod_1.z.union([zod_1.z.nativeEnum(AIAgentToolC
51
50
  * @hidden
52
51
  */
53
52
  exports.aiAgentOptionsSchema = agent_js_1.agentOptionsSchema.extend({
54
- model: zod_1.z.instanceof(chat_model_js_1.ChatModel).optional(),
55
- instructions: zod_1.z.union([zod_1.z.string(), zod_1.z.instanceof(prompt_builder_js_1.PromptBuilder)]).optional(),
53
+ model: zod_1.z.custom().optional(),
54
+ instructions: zod_1.z.union([zod_1.z.string(), zod_1.z.custom()]).optional(),
56
55
  inputKey: zod_1.z.string().optional(),
57
56
  outputKey: zod_1.z.string().optional(),
58
57
  toolChoice: exports.aiAgentToolChoiceSchema.optional(),
@@ -308,7 +308,7 @@ const mcpAgentOptionsSchema = zod_1.z.union([
308
308
  opts: zod_1.z.object({}).optional(),
309
309
  timeout: zod_1.z.number().optional(),
310
310
  maxReconnects: zod_1.z.number().optional(),
311
- shouldReconnect: zod_1.z.function().args(zod_1.z.instanceof(Error)).returns(zod_1.z.boolean()).optional(),
311
+ shouldReconnect: zod_1.z.custom().optional(),
312
312
  }),
313
313
  zod_1.z.object({
314
314
  command: zod_1.z.string(),
@@ -1,6 +1,6 @@
1
1
  import { AIGNEObserver } from "@aigne/observability";
2
- import { Agent, type AgentResponse, type AgentResponseStream, type Message } from "../agents/agent.js";
3
- import { ChatModel } from "../agents/chat-model.js";
2
+ import type { Agent, AgentResponse, AgentResponseStream, Message } from "../agents/agent.js";
3
+ import type { ChatModel } from "../agents/chat-model.js";
4
4
  import type { UserAgent } from "../agents/user-agent.js";
5
5
  import { type LoadOptions } from "../loader/index.js";
6
6
  import { AIGNEContext, type Context, type InvokeOptions, type UserContext } from "./context.js";
@@ -3,8 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AIGNE = void 0;
4
4
  const observability_1 = require("@aigne/observability");
5
5
  const zod_1 = require("zod");
6
- const agent_js_1 = require("../agents/agent.js");
7
- const chat_model_js_1 = require("../agents/chat-model.js");
8
6
  const index_js_1 = require("../loader/index.js");
9
7
  const type_utils_js_1 = require("../utils/type-utils.js");
10
8
  const context_js_1 = require("./context.js");
@@ -207,9 +205,9 @@ class AIGNE {
207
205
  }
208
206
  exports.AIGNE = AIGNE;
209
207
  const aigneOptionsSchema = zod_1.z.object({
210
- model: zod_1.z.instanceof(chat_model_js_1.ChatModel).optional(),
211
- skills: zod_1.z.array(zod_1.z.instanceof(agent_js_1.Agent)).optional(),
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(),
208
+ model: zod_1.z.custom().optional(),
209
+ skills: zod_1.z.array(zod_1.z.custom()).optional(),
210
+ agents: zod_1.z.array(zod_1.z.custom()).optional(),
211
+ observer: zod_1.z.custom().optional(),
214
212
  });
215
- const aigneAddAgentArgsSchema = zod_1.z.array(zod_1.z.instanceof(agent_js_1.Agent));
213
+ const aigneAddAgentArgsSchema = zod_1.z.array(zod_1.z.custom());
@@ -1,7 +1,7 @@
1
1
  import type { AIGNEObserver } from "@aigne/observability";
2
2
  import type { Span } from "@opentelemetry/api";
3
3
  import { Emitter } from "strict-event-emitter";
4
- import { Agent, type AgentInvokeOptions, type AgentProcessAsyncGenerator, type AgentResponse, type AgentResponseStream, type Message } from "../agents/agent.js";
4
+ import { type Agent, type AgentInvokeOptions, type AgentProcessAsyncGenerator, type AgentResponse, type AgentResponseStream, type Message } from "../agents/agent.js";
5
5
  import type { ChatModel } from "../agents/chat-model.js";
6
6
  import { UserAgent } from "../agents/user-agent.js";
7
7
  import type { Memory } from "../memory/memory.js";
@@ -34,7 +34,7 @@ class AIGNEContext {
34
34
  this.span = tracer?.startSpan("childAIGNEContext", undefined, parentContext);
35
35
  }
36
36
  else {
37
- if (!process.env.AIGNE_OBSERVABILITY_DISABLED) {
37
+ if (parent.observer && !process.env.AIGNE_OBSERVABILITY_DISABLED) {
38
38
  throw new Error("parent span is not set");
39
39
  }
40
40
  }
@@ -369,7 +369,7 @@ async function* withAbortSignal(signal, error, fn) {
369
369
  }
370
370
  }
371
371
  const aigneContextInvokeArgsSchema = zod_1.z.object({
372
- agent: zod_1.z.union([zod_1.z.function(), zod_1.z.instanceof(agent_js_1.Agent)]),
372
+ agent: zod_1.z.union([zod_1.z.custom(), zod_1.z.custom()]),
373
373
  message: zod_1.z.union([zod_1.z.record(zod_1.z.unknown()), zod_1.z.string()]).optional(),
374
374
  options: zod_1.z.object({ returnActiveAgent: zod_1.z.boolean().optional() }).optional(),
375
375
  });
@@ -134,7 +134,7 @@ class MemoryAgent extends agent_js_1.Agent {
134
134
  return context.invoke(this.recorder, input);
135
135
  }
136
136
  async onMessage({ role, source, message, context }) {
137
- this.record({ content: [{ role, source, content: message }] }, context);
137
+ this.record({ content: [role === "user" ? { input: message } : { output: message, source }] }, context);
138
138
  }
139
139
  }
140
140
  exports.MemoryAgent = MemoryAgent;
@@ -10,13 +10,9 @@ import type { Memory } from "./memory.js";
10
10
  * should be stored as memories.
11
11
  */
12
12
  export interface MemoryRecorderInput extends Message {
13
- /**
14
- * Array of content items to record as memories.
15
- * Each item in this array will typically be converted into a separate memory entry.
16
- */
17
13
  content: {
18
- role: "user" | "agent";
19
- content: Message;
14
+ input?: Message;
15
+ output?: Message;
20
16
  source?: string;
21
17
  }[];
22
18
  }
@@ -8,8 +8,8 @@ const agent_js_1 = require("../agents/agent.js");
8
8
  */
9
9
  exports.memoryRecorderInputSchema = zod_1.z.object({
10
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()),
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
13
  source: zod_1.z.string().optional(),
14
14
  })),
15
15
  });
@@ -18,7 +18,7 @@ export interface MemoryRetrieverInput extends Message {
18
18
  * Search term to filter memories by.
19
19
  * How the search is implemented depends on the specific retriever implementation.
20
20
  */
21
- search?: string;
21
+ search?: string | Message;
22
22
  }
23
23
  /**
24
24
  * Output from memory retrieval operations.
@@ -38,12 +38,12 @@ export interface MemoryRetrieverOutput extends Message {
38
38
  */
39
39
  export declare const memoryRetrieverInputSchema: z.ZodObject<{
40
40
  limit: z.ZodOptional<z.ZodNumber>;
41
- search: z.ZodOptional<z.ZodString>;
41
+ search: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodRecord<z.ZodString, z.ZodUnknown>]>>;
42
42
  }, "strip", z.ZodTypeAny, {
43
- search?: string | undefined;
43
+ search?: string | Record<string, unknown> | undefined;
44
44
  limit?: number | undefined;
45
45
  }, {
46
- search?: string | undefined;
46
+ search?: string | Record<string, unknown> | undefined;
47
47
  limit?: number | undefined;
48
48
  }>;
49
49
  /**
@@ -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
@@ -15,7 +15,8 @@ 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 omit<T extends Record<string, unknown>, K extends keyof T>(obj: T, ...keys: (K | K[])[]): Omit<T, K>;
18
+ export declare function pick<T extends object, K extends keyof T>(obj: T, ...keys: (K | K[])[]): Pick<T, K>;
19
+ export declare function omit<T extends object, 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>;
21
22
  export declare function orArrayToArray<T>(value?: T | T[]): 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)));
@@ -1,7 +1,7 @@
1
1
  import { type ZodObject, type ZodType, z } from "zod";
2
2
  import { PromptBuilder } from "../prompt/prompt-builder.js";
3
3
  import { Agent, type AgentInvokeOptions, type AgentOptions, type AgentProcessAsyncGenerator, type Message } from "./agent.js";
4
- import { ChatModel, type ChatModelInput } from "./chat-model.js";
4
+ import type { ChatModel, ChatModelInput } from "./chat-model.js";
5
5
  import type { GuideRailAgentOutput } from "./guide-rail-agent.js";
6
6
  export declare const DEFAULT_OUTPUT_KEY = "message";
7
7
  /**
@@ -100,7 +100,7 @@ export declare enum AIAgentToolChoice {
100
100
  *
101
101
  * @hidden
102
102
  */
103
- export declare const aiAgentToolChoiceSchema: z.ZodUnion<[z.ZodNativeEnum<typeof AIAgentToolChoice>, ZodType<Agent<Message, Message>, z.ZodTypeDef, Agent<Message, Message>>]>;
103
+ export declare const aiAgentToolChoiceSchema: z.ZodUnion<[z.ZodNativeEnum<typeof AIAgentToolChoice>, ZodType<Agent<any, any>, z.ZodTypeDef, Agent<any, any>>]>;
104
104
  /**
105
105
  * Zod schema for validating AIAgentOptions
106
106
  *
@@ -1,6 +1,6 @@
1
1
  import { AIGNEObserver } from "@aigne/observability";
2
- import { Agent, type AgentResponse, type AgentResponseStream, type Message } from "../agents/agent.js";
3
- import { ChatModel } from "../agents/chat-model.js";
2
+ import type { Agent, AgentResponse, AgentResponseStream, Message } from "../agents/agent.js";
3
+ import type { ChatModel } from "../agents/chat-model.js";
4
4
  import type { UserAgent } from "../agents/user-agent.js";
5
5
  import { type LoadOptions } from "../loader/index.js";
6
6
  import { AIGNEContext, type Context, type InvokeOptions, type UserContext } from "./context.js";
@@ -1,7 +1,7 @@
1
1
  import type { AIGNEObserver } from "@aigne/observability";
2
2
  import type { Span } from "@opentelemetry/api";
3
3
  import { Emitter } from "strict-event-emitter";
4
- import { Agent, type AgentInvokeOptions, type AgentProcessAsyncGenerator, type AgentResponse, type AgentResponseStream, type Message } from "../agents/agent.js";
4
+ import { type Agent, type AgentInvokeOptions, type AgentProcessAsyncGenerator, type AgentResponse, type AgentResponseStream, type Message } from "../agents/agent.js";
5
5
  import type { ChatModel } from "../agents/chat-model.js";
6
6
  import { UserAgent } from "../agents/user-agent.js";
7
7
  import type { Memory } from "../memory/memory.js";
@@ -10,13 +10,9 @@ import type { Memory } from "./memory.js";
10
10
  * should be stored as memories.
11
11
  */
12
12
  export interface MemoryRecorderInput extends Message {
13
- /**
14
- * Array of content items to record as memories.
15
- * Each item in this array will typically be converted into a separate memory entry.
16
- */
17
13
  content: {
18
- role: "user" | "agent";
19
- content: Message;
14
+ input?: Message;
15
+ output?: Message;
20
16
  source?: string;
21
17
  }[];
22
18
  }
@@ -18,7 +18,7 @@ export interface MemoryRetrieverInput extends Message {
18
18
  * Search term to filter memories by.
19
19
  * How the search is implemented depends on the specific retriever implementation.
20
20
  */
21
- search?: string;
21
+ search?: string | Message;
22
22
  }
23
23
  /**
24
24
  * Output from memory retrieval operations.
@@ -38,12 +38,12 @@ export interface MemoryRetrieverOutput extends Message {
38
38
  */
39
39
  export declare const memoryRetrieverInputSchema: z.ZodObject<{
40
40
  limit: z.ZodOptional<z.ZodNumber>;
41
- search: z.ZodOptional<z.ZodString>;
41
+ search: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodRecord<z.ZodString, z.ZodUnknown>]>>;
42
42
  }, "strip", z.ZodTypeAny, {
43
- search?: string | undefined;
43
+ search?: string | Record<string, unknown> | undefined;
44
44
  limit?: number | undefined;
45
45
  }, {
46
- search?: string | undefined;
46
+ search?: string | Record<string, unknown> | undefined;
47
47
  limit?: number | undefined;
48
48
  }>;
49
49
  /**
@@ -15,7 +15,8 @@ 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 omit<T extends Record<string, unknown>, K extends keyof T>(obj: T, ...keys: (K | K[])[]): Omit<T, K>;
18
+ export declare function pick<T extends object, K extends keyof T>(obj: T, ...keys: (K | K[])[]): Pick<T, K>;
19
+ export declare function omit<T extends object, 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>;
21
22
  export declare function orArrayToArray<T>(value?: T | T[]): T[];
@@ -273,7 +273,6 @@ export class Agent {
273
273
  for (const memory of this.memories) {
274
274
  const ms = (await memory.retrieve({
275
275
  ...input,
276
- search: typeof input.search === "string" ? input.search : JSON.stringify(input.search),
277
276
  limit: input.limit ?? this.maxRetrieveMemoryCount,
278
277
  }, options.context)).memories;
279
278
  memories.push(...ms);
@@ -477,12 +476,7 @@ export class Agent {
477
476
  async postprocess(input, output, options) {
478
477
  this.checkContextStatus(options);
479
478
  this.publishToTopics(output, options);
480
- await this.recordMemories({
481
- content: [
482
- { role: "user", content: input },
483
- { role: "agent", content: replaceTransferAgentToName(output), source: this.name },
484
- ],
485
- }, options);
479
+ await this.recordMemories({ content: [{ input, output: replaceTransferAgentToName(output), source: this.name }] }, options);
486
480
  }
487
481
  async publishToTopics(output, options) {
488
482
  const publishTopics = typeof this.publishTopic === "function" ? await this.publishTopic(output) : this.publishTopic;
@@ -1,7 +1,7 @@
1
1
  import { type ZodObject, type ZodType, z } from "zod";
2
2
  import { PromptBuilder } from "../prompt/prompt-builder.js";
3
3
  import { Agent, type AgentInvokeOptions, type AgentOptions, type AgentProcessAsyncGenerator, type Message } from "./agent.js";
4
- import { ChatModel, type ChatModelInput } from "./chat-model.js";
4
+ import type { ChatModel, ChatModelInput } from "./chat-model.js";
5
5
  import type { GuideRailAgentOutput } from "./guide-rail-agent.js";
6
6
  export declare const DEFAULT_OUTPUT_KEY = "message";
7
7
  /**
@@ -100,7 +100,7 @@ export declare enum AIAgentToolChoice {
100
100
  *
101
101
  * @hidden
102
102
  */
103
- export declare const aiAgentToolChoiceSchema: z.ZodUnion<[z.ZodNativeEnum<typeof AIAgentToolChoice>, ZodType<Agent<Message, Message>, z.ZodTypeDef, Agent<Message, Message>>]>;
103
+ export declare const aiAgentToolChoiceSchema: z.ZodUnion<[z.ZodNativeEnum<typeof AIAgentToolChoice>, ZodType<Agent<any, any>, z.ZodTypeDef, Agent<any, any>>]>;
104
104
  /**
105
105
  * Zod schema for validating AIAgentOptions
106
106
  *
@@ -3,7 +3,6 @@ import { PromptBuilder } from "../prompt/prompt-builder.js";
3
3
  import { AgentMessageTemplate, ToolMessageTemplate } from "../prompt/template.js";
4
4
  import { checkArguments, isEmpty } from "../utils/type-utils.js";
5
5
  import { Agent, agentOptionsSchema, isAgentResponseDelta, } from "./agent.js";
6
- import { ChatModel, } from "./chat-model.js";
7
6
  import { isTransferAgentOutput } from "./types.js";
8
7
  export const DEFAULT_OUTPUT_KEY = "message";
9
8
  /**
@@ -37,7 +36,7 @@ export var AIAgentToolChoice;
37
36
  *
38
37
  * @hidden
39
38
  */
40
- export const aiAgentToolChoiceSchema = z.union([z.nativeEnum(AIAgentToolChoice), z.instanceof(Agent)], {
39
+ export const aiAgentToolChoiceSchema = z.union([z.nativeEnum(AIAgentToolChoice), z.custom()], {
41
40
  message: `aiAgentToolChoice must be ${Object.values(AIAgentToolChoice).join(", ")}, or an Agent`,
42
41
  });
43
42
  /**
@@ -48,8 +47,8 @@ export const aiAgentToolChoiceSchema = z.union([z.nativeEnum(AIAgentToolChoice),
48
47
  * @hidden
49
48
  */
50
49
  export const aiAgentOptionsSchema = agentOptionsSchema.extend({
51
- model: z.instanceof(ChatModel).optional(),
52
- instructions: z.union([z.string(), z.instanceof(PromptBuilder)]).optional(),
50
+ model: z.custom().optional(),
51
+ instructions: z.union([z.string(), z.custom()]).optional(),
53
52
  inputKey: z.string().optional(),
54
53
  outputKey: z.string().optional(),
55
54
  toolChoice: aiAgentToolChoiceSchema.optional(),
@@ -297,7 +297,7 @@ const mcpAgentOptionsSchema = z.union([
297
297
  opts: z.object({}).optional(),
298
298
  timeout: z.number().optional(),
299
299
  maxReconnects: z.number().optional(),
300
- shouldReconnect: z.function().args(z.instanceof(Error)).returns(z.boolean()).optional(),
300
+ shouldReconnect: z.custom().optional(),
301
301
  }),
302
302
  z.object({
303
303
  command: z.string(),
@@ -1,6 +1,6 @@
1
1
  import { AIGNEObserver } from "@aigne/observability";
2
- import { Agent, type AgentResponse, type AgentResponseStream, type Message } from "../agents/agent.js";
3
- import { ChatModel } from "../agents/chat-model.js";
2
+ import type { Agent, AgentResponse, AgentResponseStream, Message } from "../agents/agent.js";
3
+ import type { ChatModel } from "../agents/chat-model.js";
4
4
  import type { UserAgent } from "../agents/user-agent.js";
5
5
  import { type LoadOptions } from "../loader/index.js";
6
6
  import { AIGNEContext, type Context, type InvokeOptions, type UserContext } from "./context.js";
@@ -1,7 +1,5 @@
1
1
  import { AIGNEObserver } from "@aigne/observability";
2
2
  import { z } from "zod";
3
- import { Agent, } from "../agents/agent.js";
4
- import { ChatModel } from "../agents/chat-model.js";
5
3
  import { load } from "../loader/index.js";
6
4
  import { checkArguments, createAccessorArray } from "../utils/type-utils.js";
7
5
  import { AIGNEContext } from "./context.js";
@@ -203,9 +201,9 @@ export class AIGNE {
203
201
  }
204
202
  }
205
203
  const aigneOptionsSchema = z.object({
206
- model: z.instanceof(ChatModel).optional(),
207
- skills: z.array(z.instanceof(Agent)).optional(),
208
- agents: z.array(z.instanceof(Agent)).optional(),
209
- observer: z.instanceof(AIGNEObserver).optional(),
204
+ model: z.custom().optional(),
205
+ skills: z.array(z.custom()).optional(),
206
+ agents: z.array(z.custom()).optional(),
207
+ observer: z.custom().optional(),
210
208
  });
211
- const aigneAddAgentArgsSchema = z.array(z.instanceof(Agent));
209
+ const aigneAddAgentArgsSchema = z.array(z.custom());
@@ -1,7 +1,7 @@
1
1
  import type { AIGNEObserver } from "@aigne/observability";
2
2
  import type { Span } from "@opentelemetry/api";
3
3
  import { Emitter } from "strict-event-emitter";
4
- import { Agent, type AgentInvokeOptions, type AgentProcessAsyncGenerator, type AgentResponse, type AgentResponseStream, type Message } from "../agents/agent.js";
4
+ import { type Agent, type AgentInvokeOptions, type AgentProcessAsyncGenerator, type AgentResponse, type AgentResponseStream, type Message } from "../agents/agent.js";
5
5
  import type { ChatModel } from "../agents/chat-model.js";
6
6
  import { UserAgent } from "../agents/user-agent.js";
7
7
  import type { Memory } from "../memory/memory.js";
@@ -3,7 +3,7 @@ import equal from "fast-deep-equal";
3
3
  import { Emitter } from "strict-event-emitter";
4
4
  import { v7 } from "uuid";
5
5
  import { z } from "zod";
6
- import { Agent, isAgentResponseDelta, isEmptyChunk, } from "../agents/agent.js";
6
+ import { isAgentResponseDelta, isEmptyChunk, } from "../agents/agent.js";
7
7
  import { isTransferAgentOutput, transferAgentOutputKey, } from "../agents/types.js";
8
8
  import { UserAgent } from "../agents/user-agent.js";
9
9
  import { AgentResponseProgressStream } from "../utils/event-stream.js";
@@ -28,7 +28,7 @@ export class AIGNEContext {
28
28
  this.span = tracer?.startSpan("childAIGNEContext", undefined, parentContext);
29
29
  }
30
30
  else {
31
- if (!process.env.AIGNE_OBSERVABILITY_DISABLED) {
31
+ if (parent.observer && !process.env.AIGNE_OBSERVABILITY_DISABLED) {
32
32
  throw new Error("parent span is not set");
33
33
  }
34
34
  }
@@ -362,7 +362,7 @@ async function* withAbortSignal(signal, error, fn) {
362
362
  }
363
363
  }
364
364
  const aigneContextInvokeArgsSchema = z.object({
365
- agent: z.union([z.function(), z.instanceof(Agent)]),
365
+ agent: z.union([z.custom(), z.custom()]),
366
366
  message: z.union([z.record(z.unknown()), z.string()]).optional(),
367
367
  options: z.object({ returnActiveAgent: z.boolean().optional() }).optional(),
368
368
  });
@@ -130,7 +130,7 @@ export class MemoryAgent extends Agent {
130
130
  return context.invoke(this.recorder, input);
131
131
  }
132
132
  async onMessage({ role, source, message, context }) {
133
- this.record({ content: [{ role, source, content: message }] }, context);
133
+ this.record({ content: [role === "user" ? { input: message } : { output: message, source }] }, context);
134
134
  }
135
135
  }
136
136
  const memoryAgentOptionsSchema = z.object({
@@ -10,13 +10,9 @@ import type { Memory } from "./memory.js";
10
10
  * should be stored as memories.
11
11
  */
12
12
  export interface MemoryRecorderInput extends Message {
13
- /**
14
- * Array of content items to record as memories.
15
- * Each item in this array will typically be converted into a separate memory entry.
16
- */
17
13
  content: {
18
- role: "user" | "agent";
19
- content: Message;
14
+ input?: Message;
15
+ output?: Message;
20
16
  source?: string;
21
17
  }[];
22
18
  }
@@ -5,8 +5,8 @@ import { Agent, } from "../agents/agent.js";
5
5
  */
6
6
  export const memoryRecorderInputSchema = z.object({
7
7
  content: z.array(z.object({
8
- role: z.union([z.literal("user"), z.literal("agent")]),
9
- content: z.record(z.string(), z.unknown()),
8
+ input: z.record(z.string(), z.unknown()).optional(),
9
+ output: z.record(z.string(), z.unknown()).optional(),
10
10
  source: z.string().optional(),
11
11
  })),
12
12
  });
@@ -18,7 +18,7 @@ export interface MemoryRetrieverInput extends Message {
18
18
  * Search term to filter memories by.
19
19
  * How the search is implemented depends on the specific retriever implementation.
20
20
  */
21
- search?: string;
21
+ search?: string | Message;
22
22
  }
23
23
  /**
24
24
  * Output from memory retrieval operations.
@@ -38,12 +38,12 @@ export interface MemoryRetrieverOutput extends Message {
38
38
  */
39
39
  export declare const memoryRetrieverInputSchema: z.ZodObject<{
40
40
  limit: z.ZodOptional<z.ZodNumber>;
41
- search: z.ZodOptional<z.ZodString>;
41
+ search: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodRecord<z.ZodString, z.ZodUnknown>]>>;
42
42
  }, "strip", z.ZodTypeAny, {
43
- search?: string | undefined;
43
+ search?: string | Record<string, unknown> | undefined;
44
44
  limit?: number | undefined;
45
45
  }, {
46
- search?: string | undefined;
46
+ search?: string | Record<string, unknown> | undefined;
47
47
  limit?: number | undefined;
48
48
  }>;
49
49
  /**
@@ -5,7 +5,7 @@ import { Agent, } from "../agents/agent.js";
5
5
  */
6
6
  export const memoryRetrieverInputSchema = z.object({
7
7
  limit: z.number().optional(),
8
- search: z.string().optional(),
8
+ search: z.union([z.string(), z.record(z.string(), z.unknown())]).optional(),
9
9
  });
10
10
  /**
11
11
  * @hidden
@@ -15,7 +15,8 @@ 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 omit<T extends Record<string, unknown>, K extends keyof T>(obj: T, ...keys: (K | K[])[]): Omit<T, K>;
18
+ export declare function pick<T extends object, K extends keyof T>(obj: T, ...keys: (K | K[])[]): Pick<T, K>;
19
+ export declare function omit<T extends object, 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>;
21
22
  export declare function orArrayToArray<T>(value?: T | T[]): T[];
@@ -58,6 +58,10 @@ export function unique(arr, key = (item) => item) {
58
58
  return true;
59
59
  });
60
60
  }
61
+ export function pick(obj, ...keys) {
62
+ const flattenedKeys = new Set(keys.flat());
63
+ return Object.fromEntries(Object.entries(obj).filter(([key]) => flattenedKeys.has(key)));
64
+ }
61
65
  export function omit(obj, ...keys) {
62
66
  const flattenedKeys = new Set(keys.flat());
63
67
  return Object.fromEntries(Object.entries(obj).filter(([key]) => !flattenedKeys.has(key)));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aigne/core",
3
- "version": "1.23.0",
3
+ "version": "1.24.0",
4
4
  "description": "AIGNE core library for building AI-powered applications",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -82,7 +82,7 @@
82
82
  "zod": "^3.24.4",
83
83
  "zod-to-json-schema": "^3.24.5",
84
84
  "@aigne/platform-helpers": "^0.1.2",
85
- "@aigne/observability": "^0.1.1"
85
+ "@aigne/observability": "^0.1.2"
86
86
  },
87
87
  "devDependencies": {
88
88
  "@types/bun": "^1.2.12",