@aigne/core 1.62.0 → 1.63.0-beta

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.63.0-beta](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.62.0...core-v1.63.0-beta) (2025-10-07)
4
+
5
+
6
+ ### Features
7
+
8
+ * **afs:** add basic AFS(AIGNE File System) support ([#505](https://github.com/AIGNE-io/aigne-framework/issues/505)) ([ac2a18a](https://github.com/AIGNE-io/aigne-framework/commit/ac2a18a82470a2f31c466f329386525eb1cdab6d))
9
+
10
+
11
+ ### Dependencies
12
+
13
+ * The following workspace dependencies were updated
14
+ * dependencies
15
+ * @aigne/afs bumped to 1.0.0
16
+ * @aigne/observability-api bumped to 0.11.2-beta
17
+
3
18
  ## [1.62.0](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.62.0-beta.6...core-v1.62.0) (2025-10-04)
4
19
 
5
20
 
@@ -1,3 +1,4 @@
1
+ import { AFS, type AFSOptions } from "@aigne/afs";
1
2
  import { nodejs } from "@aigne/platform-helpers/nodejs/index.js";
2
3
  import type * as prompts from "@inquirer/prompts";
3
4
  import { type ZodObject, type ZodType } from "zod";
@@ -120,6 +121,7 @@ export interface AgentOptions<I extends Message = Message, O extends Message = M
120
121
  * One or more memory agents this agent can use
121
122
  */
122
123
  memory?: MemoryAgent | MemoryAgent[];
124
+ afs?: true | AFSOptions | AFS | ((afs: AFS) => AFS);
123
125
  asyncMemoryRecord?: boolean;
124
126
  /**
125
127
  * Maximum number of memory items to retrieve
@@ -205,8 +207,11 @@ export declare abstract class Agent<I extends Message = any, O extends Message =
205
207
  constructor(options?: AgentOptions<I, O>);
206
208
  /**
207
209
  * List of memories this agent can use
210
+ *
211
+ * @deprecated use afs instead
208
212
  */
209
213
  readonly memories: MemoryAgent[];
214
+ afs?: AFS;
210
215
  asyncMemoryRecord?: boolean;
211
216
  tag?: string;
212
217
  /**
@@ -46,6 +46,7 @@ exports.isAgentResponseProgress = isAgentResponseProgress;
46
46
  exports.textDelta = textDelta;
47
47
  exports.jsonDelta = jsonDelta;
48
48
  exports.agentProcessResultToObject = agentProcessResultToObject;
49
+ const afs_1 = require("@aigne/afs");
49
50
  const index_js_1 = require("@aigne/platform-helpers/nodejs/index.js");
50
51
  const fast_deep_equal_1 = __importDefault(require("fast-deep-equal"));
51
52
  const nunjucks_1 = __importDefault(require("nunjucks"));
@@ -151,6 +152,15 @@ class Agent {
151
152
  else if (options.memory) {
152
153
  this.memories.push(options.memory);
153
154
  }
155
+ this.afs = !options.afs
156
+ ? undefined
157
+ : options.afs === true
158
+ ? new afs_1.AFS()
159
+ : typeof options.afs === "function"
160
+ ? options.afs(new afs_1.AFS())
161
+ : options.afs instanceof afs_1.AFS
162
+ ? options.afs
163
+ : new afs_1.AFS(options.afs);
154
164
  this.asyncMemoryRecord = options.asyncMemoryRecord;
155
165
  this.maxRetrieveMemoryCount = options.maxRetrieveMemoryCount;
156
166
  this.hooks = (0, type_utils_js_1.flat)(options.hooks);
@@ -164,8 +174,11 @@ class Agent {
164
174
  }
165
175
  /**
166
176
  * List of memories this agent can use
177
+ *
178
+ * @deprecated use afs instead
167
179
  */
168
180
  memories = [];
181
+ afs;
169
182
  asyncMemoryRecord;
170
183
  tag;
171
184
  /**
@@ -537,6 +550,7 @@ class Agent {
537
550
  const o = await this.callHooks(["onSuccess", "onEnd"], { input, output: finalOutput }, options);
538
551
  if (o?.output)
539
552
  finalOutput = o.output;
553
+ this.afs?.emit("agentSucceed", { input, output: finalOutput });
540
554
  if (!this.disableEvents)
541
555
  context.emit("agentSucceed", { agent: this, output: finalOutput });
542
556
  return finalOutput;
@@ -1,6 +1,6 @@
1
1
  import { type ZodObject, type ZodType, z } from "zod";
2
2
  import { PromptBuilder } from "../prompt/prompt-builder.js";
3
- import { Agent, type AgentInvokeOptions, type AgentOptions, type AgentProcessAsyncGenerator, type Message } from "./agent.js";
3
+ import { Agent, type AgentInvokeOptions, type AgentOptions, type AgentProcessAsyncGenerator, type AgentProcessResult, type Message } from "./agent.js";
4
4
  import type { ChatModel, ChatModelInput } from "./chat-model.js";
5
5
  import type { GuideRailAgentOutput } from "./guide-rail-agent.js";
6
6
  import type { FileType } from "./model.js";
@@ -304,7 +304,8 @@ export declare class AIAgent<I extends Message = any, O extends Message = any> e
304
304
  *
305
305
  * @protected
306
306
  */
307
- process(input: I, options: AgentInvokeOptions): AgentProcessAsyncGenerator<O>;
307
+ process(input: I, options: AgentInvokeOptions): AgentProcessResult<O>;
308
+ private _process;
308
309
  protected onGuideRailError(error: GuideRailAgentOutput): Promise<O | GuideRailAgentOutput>;
309
310
  /**
310
311
  * Process router mode requests
@@ -235,7 +235,10 @@ class AIAgent extends agent_js_1.Agent {
235
235
  *
236
236
  * @protected
237
237
  */
238
- async *process(input, options) {
238
+ process(input, options) {
239
+ return this._process(input, options);
240
+ }
241
+ async *_process(input, options) {
239
242
  const model = this.model || options.model || options.context.model;
240
243
  if (!model)
241
244
  throw new Error("model is required to run AIAgent");
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PromptBuilder = void 0;
4
+ const afs_1 = require("@aigne/afs");
4
5
  const index_js_1 = require("@aigne/platform-helpers/nodejs/index.js");
5
6
  const yaml_1 = require("yaml");
6
7
  const zod_1 = require("zod");
@@ -98,6 +99,18 @@ class PromptBuilder {
98
99
  if (options.agent?.useMemoriesFromContext && options.context?.memories?.length) {
99
100
  memories.push(...options.context.memories);
100
101
  }
102
+ if (options.agent?.afs) {
103
+ const history = await options.agent.afs.list(afs_1.AFSHistory.Path, {
104
+ limit: options.agent.maxRetrieveMemoryCount || 1,
105
+ orderBy: [["createdAt", "desc"]],
106
+ });
107
+ if (message) {
108
+ const result = await options.agent.afs.search("/", message);
109
+ const ms = result.list.map((entry) => ({ content: (0, yaml_1.stringify)(entry.content) }));
110
+ memories.push(...ms);
111
+ }
112
+ memories.push(...history.list.filter((i) => (0, type_utils_js_1.isNonNullable)(i.content)));
113
+ }
101
114
  if (memories.length)
102
115
  messages.push(...(await this.convertMemoriesToMessages(memories, options)));
103
116
  // if the agent is using structured stream mode, add the instructions
@@ -1,4 +1,4 @@
1
- import type { AgentHooks } from "../agents/agent.ts";
1
+ import type { AgentHooks } from "../agents/agent.js";
2
2
  import type { AIGNECLIAgents } from "../aigne/type.js";
3
3
  export declare function sortHooks(hooks: AgentHooks[]): AgentHooks[];
4
4
  export interface CLIAgent<T> {
@@ -9,4 +9,4 @@ export interface CLIAgent<T> {
9
9
  agents?: CLIAgent<T>[];
10
10
  }
11
11
  export declare function mapCliAgent<A, O>({ agent, agents, ...input }: CLIAgent<A>, transform: (input: A) => O): CLIAgent<O>;
12
- export declare function findCliAgent(cli: AIGNECLIAgents, parent: string[] | "*", name: string): import("../agents/agent.ts").Agent<any, any> | undefined;
12
+ export declare function findCliAgent(cli: AIGNECLIAgents, parent: string[] | "*", name: string): import("../agents/agent.js").Agent<any, any> | undefined;
@@ -1,3 +1,4 @@
1
+ import { AFS, type AFSOptions } from "@aigne/afs";
1
2
  import { nodejs } from "@aigne/platform-helpers/nodejs/index.js";
2
3
  import type * as prompts from "@inquirer/prompts";
3
4
  import { type ZodObject, type ZodType } from "zod";
@@ -120,6 +121,7 @@ export interface AgentOptions<I extends Message = Message, O extends Message = M
120
121
  * One or more memory agents this agent can use
121
122
  */
122
123
  memory?: MemoryAgent | MemoryAgent[];
124
+ afs?: true | AFSOptions | AFS | ((afs: AFS) => AFS);
123
125
  asyncMemoryRecord?: boolean;
124
126
  /**
125
127
  * Maximum number of memory items to retrieve
@@ -205,8 +207,11 @@ export declare abstract class Agent<I extends Message = any, O extends Message =
205
207
  constructor(options?: AgentOptions<I, O>);
206
208
  /**
207
209
  * List of memories this agent can use
210
+ *
211
+ * @deprecated use afs instead
208
212
  */
209
213
  readonly memories: MemoryAgent[];
214
+ afs?: AFS;
210
215
  asyncMemoryRecord?: boolean;
211
216
  tag?: string;
212
217
  /**
@@ -1,6 +1,6 @@
1
1
  import { type ZodObject, type ZodType, z } from "zod";
2
2
  import { PromptBuilder } from "../prompt/prompt-builder.js";
3
- import { Agent, type AgentInvokeOptions, type AgentOptions, type AgentProcessAsyncGenerator, type Message } from "./agent.js";
3
+ import { Agent, type AgentInvokeOptions, type AgentOptions, type AgentProcessAsyncGenerator, type AgentProcessResult, type Message } from "./agent.js";
4
4
  import type { ChatModel, ChatModelInput } from "./chat-model.js";
5
5
  import type { GuideRailAgentOutput } from "./guide-rail-agent.js";
6
6
  import type { FileType } from "./model.js";
@@ -304,7 +304,8 @@ export declare class AIAgent<I extends Message = any, O extends Message = any> e
304
304
  *
305
305
  * @protected
306
306
  */
307
- process(input: I, options: AgentInvokeOptions): AgentProcessAsyncGenerator<O>;
307
+ process(input: I, options: AgentInvokeOptions): AgentProcessResult<O>;
308
+ private _process;
308
309
  protected onGuideRailError(error: GuideRailAgentOutput): Promise<O | GuideRailAgentOutput>;
309
310
  /**
310
311
  * Process router mode requests
@@ -1,4 +1,4 @@
1
- import type { AgentHooks } from "../agents/agent.ts";
1
+ import type { AgentHooks } from "../agents/agent.js";
2
2
  import type { AIGNECLIAgents } from "../aigne/type.js";
3
3
  export declare function sortHooks(hooks: AgentHooks[]): AgentHooks[];
4
4
  export interface CLIAgent<T> {
@@ -9,4 +9,4 @@ export interface CLIAgent<T> {
9
9
  agents?: CLIAgent<T>[];
10
10
  }
11
11
  export declare function mapCliAgent<A, O>({ agent, agents, ...input }: CLIAgent<A>, transform: (input: A) => O): CLIAgent<O>;
12
- export declare function findCliAgent(cli: AIGNECLIAgents, parent: string[] | "*", name: string): import("../agents/agent.ts").Agent<any, any> | undefined;
12
+ export declare function findCliAgent(cli: AIGNECLIAgents, parent: string[] | "*", name: string): import("../agents/agent.js").Agent<any, any> | undefined;
@@ -1,3 +1,4 @@
1
+ import { AFS, type AFSOptions } from "@aigne/afs";
1
2
  import { nodejs } from "@aigne/platform-helpers/nodejs/index.js";
2
3
  import type * as prompts from "@inquirer/prompts";
3
4
  import { type ZodObject, type ZodType } from "zod";
@@ -120,6 +121,7 @@ export interface AgentOptions<I extends Message = Message, O extends Message = M
120
121
  * One or more memory agents this agent can use
121
122
  */
122
123
  memory?: MemoryAgent | MemoryAgent[];
124
+ afs?: true | AFSOptions | AFS | ((afs: AFS) => AFS);
123
125
  asyncMemoryRecord?: boolean;
124
126
  /**
125
127
  * Maximum number of memory items to retrieve
@@ -205,8 +207,11 @@ export declare abstract class Agent<I extends Message = any, O extends Message =
205
207
  constructor(options?: AgentOptions<I, O>);
206
208
  /**
207
209
  * List of memories this agent can use
210
+ *
211
+ * @deprecated use afs instead
208
212
  */
209
213
  readonly memories: MemoryAgent[];
214
+ afs?: AFS;
210
215
  asyncMemoryRecord?: boolean;
211
216
  tag?: string;
212
217
  /**
@@ -1,3 +1,4 @@
1
+ import { AFS } from "@aigne/afs";
1
2
  import { nodejs } from "@aigne/platform-helpers/nodejs/index.js";
2
3
  import equal from "fast-deep-equal";
3
4
  import nunjucks from "nunjucks";
@@ -103,6 +104,15 @@ export class Agent {
103
104
  else if (options.memory) {
104
105
  this.memories.push(options.memory);
105
106
  }
107
+ this.afs = !options.afs
108
+ ? undefined
109
+ : options.afs === true
110
+ ? new AFS()
111
+ : typeof options.afs === "function"
112
+ ? options.afs(new AFS())
113
+ : options.afs instanceof AFS
114
+ ? options.afs
115
+ : new AFS(options.afs);
106
116
  this.asyncMemoryRecord = options.asyncMemoryRecord;
107
117
  this.maxRetrieveMemoryCount = options.maxRetrieveMemoryCount;
108
118
  this.hooks = flat(options.hooks);
@@ -116,8 +126,11 @@ export class Agent {
116
126
  }
117
127
  /**
118
128
  * List of memories this agent can use
129
+ *
130
+ * @deprecated use afs instead
119
131
  */
120
132
  memories = [];
133
+ afs;
121
134
  asyncMemoryRecord;
122
135
  tag;
123
136
  /**
@@ -489,6 +502,7 @@ export class Agent {
489
502
  const o = await this.callHooks(["onSuccess", "onEnd"], { input, output: finalOutput }, options);
490
503
  if (o?.output)
491
504
  finalOutput = o.output;
505
+ this.afs?.emit("agentSucceed", { input, output: finalOutput });
492
506
  if (!this.disableEvents)
493
507
  context.emit("agentSucceed", { agent: this, output: finalOutput });
494
508
  return finalOutput;
@@ -1,6 +1,6 @@
1
1
  import { type ZodObject, type ZodType, z } from "zod";
2
2
  import { PromptBuilder } from "../prompt/prompt-builder.js";
3
- import { Agent, type AgentInvokeOptions, type AgentOptions, type AgentProcessAsyncGenerator, type Message } from "./agent.js";
3
+ import { Agent, type AgentInvokeOptions, type AgentOptions, type AgentProcessAsyncGenerator, type AgentProcessResult, type Message } from "./agent.js";
4
4
  import type { ChatModel, ChatModelInput } from "./chat-model.js";
5
5
  import type { GuideRailAgentOutput } from "./guide-rail-agent.js";
6
6
  import type { FileType } from "./model.js";
@@ -304,7 +304,8 @@ export declare class AIAgent<I extends Message = any, O extends Message = any> e
304
304
  *
305
305
  * @protected
306
306
  */
307
- process(input: I, options: AgentInvokeOptions): AgentProcessAsyncGenerator<O>;
307
+ process(input: I, options: AgentInvokeOptions): AgentProcessResult<O>;
308
+ private _process;
308
309
  protected onGuideRailError(error: GuideRailAgentOutput): Promise<O | GuideRailAgentOutput>;
309
310
  /**
310
311
  * Process router mode requests
@@ -232,7 +232,10 @@ export class AIAgent extends Agent {
232
232
  *
233
233
  * @protected
234
234
  */
235
- async *process(input, options) {
235
+ process(input, options) {
236
+ return this._process(input, options);
237
+ }
238
+ async *_process(input, options) {
236
239
  const model = this.model || options.model || options.context.model;
237
240
  if (!model)
238
241
  throw new Error("model is required to run AIAgent");
@@ -1,3 +1,4 @@
1
+ import { AFSHistory } from "@aigne/afs";
1
2
  import { nodejs } from "@aigne/platform-helpers/nodejs/index.js";
2
3
  import { stringify } from "yaml";
3
4
  import { ZodObject } from "zod";
@@ -7,7 +8,7 @@ import { DEFAULT_OUTPUT_FILE_KEY, DEFAULT_OUTPUT_KEY } from "../agents/ai-agent.
7
8
  import { fileUnionContentsSchema } from "../agents/model.js";
8
9
  import { optionalize } from "../loader/schema.js";
9
10
  import { outputSchemaToResponseFormatSchema } from "../utils/json-schema.js";
10
- import { checkArguments, flat, isRecord, unique } from "../utils/type-utils.js";
11
+ import { checkArguments, flat, isNonNullable, isRecord, unique } from "../utils/type-utils.js";
11
12
  import { MEMORY_MESSAGE_TEMPLATE } from "./prompts/memory-message-template.js";
12
13
  import { STRUCTURED_STREAM_INSTRUCTIONS } from "./prompts/structured-stream-instructions.js";
13
14
  import { AgentMessageTemplate, ChatMessagesTemplate, PromptTemplate, SystemMessageTemplate, UserMessageTemplate, } from "./template.js";
@@ -95,6 +96,18 @@ export class PromptBuilder {
95
96
  if (options.agent?.useMemoriesFromContext && options.context?.memories?.length) {
96
97
  memories.push(...options.context.memories);
97
98
  }
99
+ if (options.agent?.afs) {
100
+ const history = await options.agent.afs.list(AFSHistory.Path, {
101
+ limit: options.agent.maxRetrieveMemoryCount || 1,
102
+ orderBy: [["createdAt", "desc"]],
103
+ });
104
+ if (message) {
105
+ const result = await options.agent.afs.search("/", message);
106
+ const ms = result.list.map((entry) => ({ content: stringify(entry.content) }));
107
+ memories.push(...ms);
108
+ }
109
+ memories.push(...history.list.filter((i) => isNonNullable(i.content)));
110
+ }
98
111
  if (memories.length)
99
112
  messages.push(...(await this.convertMemoriesToMessages(memories, options)));
100
113
  // if the agent is using structured stream mode, add the instructions
@@ -1,4 +1,4 @@
1
- import type { AgentHooks } from "../agents/agent.ts";
1
+ import type { AgentHooks } from "../agents/agent.js";
2
2
  import type { AIGNECLIAgents } from "../aigne/type.js";
3
3
  export declare function sortHooks(hooks: AgentHooks[]): AgentHooks[];
4
4
  export interface CLIAgent<T> {
@@ -9,4 +9,4 @@ export interface CLIAgent<T> {
9
9
  agents?: CLIAgent<T>[];
10
10
  }
11
11
  export declare function mapCliAgent<A, O>({ agent, agents, ...input }: CLIAgent<A>, transform: (input: A) => O): CLIAgent<O>;
12
- export declare function findCliAgent(cli: AIGNECLIAgents, parent: string[] | "*", name: string): import("../agents/agent.ts").Agent<any, any> | undefined;
12
+ export declare function findCliAgent(cli: AIGNECLIAgents, parent: string[] | "*", name: string): import("../agents/agent.js").Agent<any, any> | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aigne/core",
3
- "version": "1.62.0",
3
+ "version": "1.63.0-beta",
4
4
  "description": "The functional core of agentic AI",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -92,8 +92,9 @@
92
92
  "zod": "^3.25.67",
93
93
  "zod-from-json-schema": "^0.0.5",
94
94
  "zod-to-json-schema": "^3.24.6",
95
- "@aigne/observability-api": "^0.11.1",
96
- "@aigne/platform-helpers": "^0.6.3"
95
+ "@aigne/observability-api": "^0.11.2-beta",
96
+ "@aigne/platform-helpers": "^0.6.3",
97
+ "@aigne/afs": "^1.0.0"
97
98
  },
98
99
  "devDependencies": {
99
100
  "@types/bun": "^1.2.22",