@aigne/core 1.72.0-beta.13 → 1.72.0-beta.16

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,36 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.72.0-beta.16](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.72.0-beta.15...core-v1.72.0-beta.16) (2026-01-12)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * **afs:** show gitignored files with marker instead of filtering ([c2bdea1](https://github.com/AIGNE-io/aigne-framework/commit/c2bdea155f47c9420f2fe810cdfed79ef70ef899))
9
+ * **core:** afs_read skill return pure text result first ([d42e67c](https://github.com/AIGNE-io/aigne-framework/commit/d42e67c33bb211202e9ba579afec2cf4abacbdb5))
10
+
11
+
12
+ ### Dependencies
13
+
14
+ * The following workspace dependencies were updated
15
+ * dependencies
16
+ * @aigne/afs bumped to 1.4.0-beta.8
17
+ * @aigne/afs-history bumped to 1.2.0-beta.9
18
+
19
+ ## [1.72.0-beta.15](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.72.0-beta.14...core-v1.72.0-beta.15) (2026-01-10)
20
+
21
+
22
+ ### Bug Fixes
23
+
24
+ * **core:** simplify token-estimator logic for remaining characters ([45d43cc](https://github.com/AIGNE-io/aigne-framework/commit/45d43ccd3afd636cfb459eea2e6551e8f9c53765))
25
+
26
+ ## [1.72.0-beta.14](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.72.0-beta.13...core-v1.72.0-beta.14) (2026-01-09)
27
+
28
+
29
+ ### Bug Fixes
30
+
31
+ * **core:** correct session schema for AIAgent ([30b1deb](https://github.com/AIGNE-io/aigne-framework/commit/30b1deb54ac20287580e0a85ef150b95010f8201))
32
+ * **core:** default enable auto breakpoints for chat model ([d4a6b83](https://github.com/AIGNE-io/aigne-framework/commit/d4a6b8323d6c83be45669885b32febb545bdf797))
33
+
3
34
  ## [1.72.0-beta.13](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.72.0-beta.12...core-v1.72.0-beta.13) (2026-01-08)
4
35
 
5
36
 
@@ -51,6 +51,7 @@ const index_js_1 = require("@aigne/platform-helpers/nodejs/index.js");
51
51
  const fast_deep_equal_1 = __importDefault(require("fast-deep-equal"));
52
52
  const nunjucks_1 = __importDefault(require("nunjucks"));
53
53
  const ufo_1 = require("ufo");
54
+ const yaml_1 = require("yaml");
54
55
  const zod_1 = require("zod");
55
56
  const zod_to_json_schema_1 = require("zod-to-json-schema");
56
57
  const function_agent_js_1 = require("../loader/function-agent.js");
@@ -717,7 +718,7 @@ class Agent {
717
718
  }
718
719
  }
719
720
  formatOutput(output) {
720
- return JSON.stringify(output);
721
+ return (0, yaml_1.stringify)(output);
721
722
  }
722
723
  /**
723
724
  * Shut down the agent and clean up resources
@@ -126,7 +126,7 @@ class AIAgent extends agent_js_1.Agent {
126
126
  static schema({ filepath }) {
127
127
  const instructionsSchema = (0, schema_js_1.getInstructionsSchema)({ filepath });
128
128
  const nestAgentSchema = (0, agent_yaml_js_1.getNestAgentSchema)({ filepath });
129
- return (0, schema_js_1.camelizeSchema)(zod_1.z.object({
129
+ const schema = (0, schema_js_1.camelizeSchema)(zod_1.z.object({
130
130
  instructions: (0, schema_js_1.optionalize)(instructionsSchema),
131
131
  inputKey: (0, schema_js_1.optionalize)(zod_1.z.string()),
132
132
  outputKey: (0, schema_js_1.optionalize)(zod_1.z.string()),
@@ -137,14 +137,32 @@ class AIAgent extends agent_js_1.Agent {
137
137
  keepTextInToolUses: (0, schema_js_1.optionalize)(zod_1.z.boolean()),
138
138
  catchToolsError: (0, schema_js_1.optionalize)(zod_1.z.boolean()),
139
139
  structuredStreamMode: (0, schema_js_1.optionalize)(zod_1.z.boolean()),
140
- compact: (0, schema_js_1.camelizeSchema)((0, schema_js_1.optionalize)(zod_1.z.object({
140
+ session: (0, schema_js_1.optionalize)((0, schema_js_1.camelizeSchema)(zod_1.z.object({
141
141
  mode: (0, schema_js_1.optionalize)(zod_1.z.enum(["auto", "disabled"])),
142
- maxTokens: zod_1.z.number().int().min(0).optional(),
143
- keepRecentRatio: (0, schema_js_1.optionalize)(zod_1.z.number().min(0).max(1)),
144
- async: (0, schema_js_1.optionalize)(zod_1.z.boolean()),
145
- compactor: (0, schema_js_1.optionalize)(nestAgentSchema),
142
+ sessionMemory: (0, schema_js_1.optionalize)((0, schema_js_1.camelizeSchema)(zod_1.z.object({
143
+ mode: (0, schema_js_1.optionalize)(zod_1.z.enum(["auto", "disabled"])),
144
+ memoryRatio: (0, schema_js_1.optionalize)(zod_1.z.number().min(0).max(1)),
145
+ queryLimit: (0, schema_js_1.optionalize)(zod_1.z.number().int().min(0)),
146
+ async: (0, schema_js_1.optionalize)(zod_1.z.boolean()),
147
+ extractor: (0, schema_js_1.optionalize)(nestAgentSchema),
148
+ }))),
149
+ userMemory: (0, schema_js_1.optionalize)((0, schema_js_1.camelizeSchema)(zod_1.z.object({
150
+ mode: (0, schema_js_1.optionalize)(zod_1.z.enum(["auto", "disabled"])),
151
+ memoryRatio: (0, schema_js_1.optionalize)(zod_1.z.number().min(0).max(1)),
152
+ queryLimit: (0, schema_js_1.optionalize)(zod_1.z.number().int().min(0)),
153
+ async: (0, schema_js_1.optionalize)(zod_1.z.boolean()),
154
+ extractor: (0, schema_js_1.optionalize)(nestAgentSchema),
155
+ }))),
156
+ compact: (0, schema_js_1.optionalize)((0, schema_js_1.camelizeSchema)(zod_1.z.object({
157
+ mode: (0, schema_js_1.optionalize)(zod_1.z.enum(["auto", "disabled"])),
158
+ maxTokens: zod_1.z.number().int().min(0).optional(),
159
+ keepRecentRatio: (0, schema_js_1.optionalize)(zod_1.z.number().min(0).max(1)),
160
+ async: (0, schema_js_1.optionalize)(zod_1.z.boolean()),
161
+ compactor: (0, schema_js_1.optionalize)(nestAgentSchema),
162
+ }))),
146
163
  }))),
147
164
  }));
165
+ return schema;
148
166
  }
149
167
  static async load(options) {
150
168
  const schema = AIAgent.schema(options);
@@ -57,7 +57,9 @@ export declare abstract class ChatModel extends Model<ChatModelInput, ChatModelO
57
57
  getModelCapabilities(): {
58
58
  supportsParallelToolCalls: boolean;
59
59
  };
60
+ getModelOptions(input: Message, options: AgentInvokeOptions): Promise<ChatModelInputOptions>;
60
61
  private validateToolNames;
62
+ countTokens(input: ChatModelInput): Promise<number>;
61
63
  /**
62
64
  * Normalizes tool names to ensure compatibility with language models
63
65
  *
@@ -40,6 +40,7 @@ const zod_from_json_schema_1 = require("zod-from-json-schema");
40
40
  const schema_js_1 = require("../loader/schema.js");
41
41
  const json_schema_js_1 = require("../utils/json-schema.js");
42
42
  const logger_js_1 = require("../utils/logger.js");
43
+ const token_estimator_js_1 = require("../utils/token-estimator.js");
43
44
  const type_utils_js_1 = require("../utils/type-utils.js");
44
45
  const agent_js_1 = require("./agent.js");
45
46
  const model_js_1 = require("./model.js");
@@ -117,6 +118,19 @@ class ChatModel extends model_js_1.Model {
117
118
  supportsParallelToolCalls: this.supportsParallelToolCalls,
118
119
  };
119
120
  }
121
+ async getModelOptions(input, options) {
122
+ const modelOptions = (await super.getModelOptions(input, options));
123
+ return {
124
+ ...modelOptions,
125
+ cacheConfig: {
126
+ ...modelOptions.cacheConfig,
127
+ autoBreakpoints: {
128
+ ...modelOptions.cacheConfig?.autoBreakpoints,
129
+ lastMessage: modelOptions.cacheConfig?.autoBreakpoints?.lastMessage ?? true,
130
+ },
131
+ },
132
+ };
133
+ }
120
134
  validateToolNames(tools) {
121
135
  for (const tool of tools ?? []) {
122
136
  if (!/^[a-zA-Z0-9_]+$/.test(tool.function.name)) {
@@ -124,6 +138,9 @@ class ChatModel extends model_js_1.Model {
124
138
  }
125
139
  }
126
140
  }
141
+ async countTokens(input) {
142
+ return (0, token_estimator_js_1.estimateTokens)(JSON.stringify(input));
143
+ }
127
144
  /**
128
145
  * Normalizes tool names to ensure compatibility with language models
129
146
  *
@@ -238,7 +255,7 @@ class ChatModel extends model_js_1.Model {
238
255
  const files = zod_1.z.array(model_js_1.fileUnionContentSchema).parse(output.files);
239
256
  output = {
240
257
  ...output,
241
- files: await Promise.all(files.map((file) => this.transformFileType(input.outputFileType, file, options))),
258
+ files: await Promise.all(files.map((file) => this.transformFileType(input.outputFileType, file))),
242
259
  };
243
260
  }
244
261
  // Remove fields with `null` value for validation
@@ -70,7 +70,7 @@ class ImageModel extends model_js_1.Model {
70
70
  const images = zod_1.z.array(model_js_1.fileUnionContentSchema).parse(output.images);
71
71
  output = {
72
72
  ...output,
73
- images: await Promise.all(images.map((image) => this.transformFileType(input.outputFileType, image, options))),
73
+ images: await Promise.all(images.map((image) => this.transformFileType(input.outputFileType, image))),
74
74
  };
75
75
  }
76
76
  return super.processAgentOutput(input, output, options);
@@ -17,9 +17,9 @@ export declare abstract class Model<I extends Message = any, O extends Message =
17
17
  */
18
18
  getModelOptions(input: Message, options: AgentInvokeOptions): Promise<Record<string, unknown>>;
19
19
  protected preprocess(input: I, options: AgentInvokeOptions): Promise<void>;
20
- transformFileType(fileType: "file", data: FileUnionContent, options: AgentInvokeOptions): Promise<FileContent>;
21
- transformFileType(fileType: "local" | undefined, data: FileUnionContent, options: AgentInvokeOptions): Promise<LocalContent>;
22
- transformFileType(fileType: FileType | undefined, data: FileUnionContent, options: AgentInvokeOptions): Promise<FileUnionContent>;
20
+ transformFileType(fileType: "file", data: FileUnionContent): Promise<FileContent>;
21
+ transformFileType(fileType: "local" | undefined, data: FileUnionContent): Promise<LocalContent>;
22
+ transformFileType(fileType: FileType | undefined, data: FileUnionContent): Promise<FileUnionContent>;
23
23
  static getFileExtension(type: string): Promise<string | undefined>;
24
24
  static getMimeType(filename: string): Promise<string | undefined>;
25
25
  downloadFile(url: string): Promise<Response>;
@@ -89,13 +89,13 @@ class Model extends agent_js_1.Agent {
89
89
  Object.assign(input, { modelOptions: await this.getModelOptions(input, options) });
90
90
  return super.preprocess(input, options);
91
91
  }
92
- async transformFileType(fileType = "local", data, options) {
92
+ async transformFileType(fileType = "local", data) {
93
93
  if (fileType === data.type)
94
94
  return data;
95
95
  const common = (0, type_utils_js_1.pick)(data, "filename", "mimeType");
96
96
  switch (fileType) {
97
97
  case "local": {
98
- const dir = index_js_1.nodejs.path.join(index_js_1.nodejs.os.tmpdir(), options.context.id);
98
+ const dir = index_js_1.nodejs.path.join(index_js_1.nodejs.os.tmpdir(), (0, uuid_1.v7)());
99
99
  await index_js_1.nodejs.fs.mkdir(dir, { recursive: true });
100
100
  const ext = await Model.getFileExtension(data.mimeType || data.filename || "");
101
101
  const id = (0, uuid_1.v7)();
@@ -43,7 +43,7 @@ class VideoModel extends model_js_1.Model {
43
43
  const videos = zod_1.z.array(model_js_1.fileUnionContentSchema).parse(output.videos);
44
44
  output = {
45
45
  ...output,
46
- videos: await Promise.all(videos.map((video) => this.transformFileType(input.outputFileType, video, options))),
46
+ videos: await Promise.all(videos.map((video) => this.transformFileType(input.outputFileType, video))),
47
47
  };
48
48
  }
49
49
  return super.processAgentOutput(input, output, options);
@@ -1,5 +1,6 @@
1
1
  import type { AFSListOptions } from "@aigne/afs";
2
2
  import type { AgentInvokeOptions, AgentOptions, Message } from "../../../agents/agent.js";
3
+ import type { PromiseOrValue } from "../../../utils/type-utils.js";
3
4
  import { AFSSkillBase } from "./base.js";
4
5
  export interface AFSListInput extends Message {
5
6
  path: string;
@@ -18,5 +19,6 @@ export interface AFSListAgentOptions extends AgentOptions<AFSListInput, AFSListO
18
19
  }
19
20
  export declare class AFSListAgent extends AFSSkillBase<AFSListInput, AFSListOutput> {
20
21
  constructor(options: AFSListAgentOptions);
22
+ formatOutput(output: AFSListOutput): PromiseOrValue<string>;
21
23
  process(input: AFSListInput, _options: AgentInvokeOptions): Promise<AFSListOutput>;
22
24
  }
@@ -56,10 +56,18 @@ Usage:
56
56
  }),
57
57
  });
58
58
  }
59
+ formatOutput(output) {
60
+ if (typeof output.data === "string")
61
+ return output.data;
62
+ return super.formatOutput(output);
63
+ }
59
64
  async process(input, _options) {
60
65
  if (!this.afs)
61
66
  throw new Error("AFS is not configured for this agent.");
62
- const { data, message } = await this.afs.list(input.path, input.options);
67
+ const { data, message } = await this.afs.list(input.path, {
68
+ ...input.options,
69
+ format: "simple-list",
70
+ });
63
71
  return {
64
72
  status: "success",
65
73
  tool: "afs_list",
@@ -1,5 +1,6 @@
1
1
  import type { AFSEntry } from "@aigne/afs";
2
2
  import type { AgentInvokeOptions, AgentOptions, Message } from "../../../agents/agent.js";
3
+ import type { PromiseOrValue } from "../../../utils/type-utils.js";
3
4
  import { AFSSkillBase } from "./base.js";
4
5
  export interface AFSReadInput extends Message {
5
6
  path: string;
@@ -10,7 +11,7 @@ export interface AFSReadOutput extends Message {
10
11
  status: string;
11
12
  tool: string;
12
13
  path: string;
13
- data?: AFSEntry;
14
+ data?: AFSEntry | null;
14
15
  message?: string;
15
16
  totalLines?: number;
16
17
  returnedLines?: number;
@@ -22,5 +23,6 @@ export interface AFSReadAgentOptions extends AgentOptions<AFSReadInput, AFSReadO
22
23
  }
23
24
  export declare class AFSReadAgent extends AFSSkillBase<AFSReadInput, AFSReadOutput> {
24
25
  constructor(options: AFSReadAgentOptions);
26
+ formatOutput(output: AFSReadOutput): PromiseOrValue<string>;
25
27
  process(input: AFSReadInput, _options: AgentInvokeOptions): Promise<AFSReadOutput>;
26
28
  }
@@ -51,6 +51,11 @@ Usage:
51
51
  }),
52
52
  });
53
53
  }
54
+ formatOutput(output) {
55
+ if (typeof output.data?.content === "string" && output.data.content)
56
+ return output.data.content;
57
+ return super.formatOutput({ ...output, data: output.data || null });
58
+ }
54
59
  async process(input, _options) {
55
60
  if (!this.afs)
56
61
  throw new Error("AFS is not configured for this agent.");
@@ -8,7 +8,7 @@ exports.estimateTokens = estimateTokens;
8
8
  const CHAR_TYPE_RATIOS = {
9
9
  chinese: 1.5, // Chinese characters: ~1.5 characters per token
10
10
  word: 0.75, // English words: ~0.75 tokens per word (accounting for subword tokenization)
11
- other: 4, // Other characters (punctuation, numbers, etc.): ~4 characters per token
11
+ other: 1, // Other characters (punctuation, numbers, etc.): ~1 character per token
12
12
  };
13
13
  /**
14
14
  * Regular expressions for character type detection
@@ -57,7 +57,9 @@ export declare abstract class ChatModel extends Model<ChatModelInput, ChatModelO
57
57
  getModelCapabilities(): {
58
58
  supportsParallelToolCalls: boolean;
59
59
  };
60
+ getModelOptions(input: Message, options: AgentInvokeOptions): Promise<ChatModelInputOptions>;
60
61
  private validateToolNames;
62
+ countTokens(input: ChatModelInput): Promise<number>;
61
63
  /**
62
64
  * Normalizes tool names to ensure compatibility with language models
63
65
  *
@@ -17,9 +17,9 @@ export declare abstract class Model<I extends Message = any, O extends Message =
17
17
  */
18
18
  getModelOptions(input: Message, options: AgentInvokeOptions): Promise<Record<string, unknown>>;
19
19
  protected preprocess(input: I, options: AgentInvokeOptions): Promise<void>;
20
- transformFileType(fileType: "file", data: FileUnionContent, options: AgentInvokeOptions): Promise<FileContent>;
21
- transformFileType(fileType: "local" | undefined, data: FileUnionContent, options: AgentInvokeOptions): Promise<LocalContent>;
22
- transformFileType(fileType: FileType | undefined, data: FileUnionContent, options: AgentInvokeOptions): Promise<FileUnionContent>;
20
+ transformFileType(fileType: "file", data: FileUnionContent): Promise<FileContent>;
21
+ transformFileType(fileType: "local" | undefined, data: FileUnionContent): Promise<LocalContent>;
22
+ transformFileType(fileType: FileType | undefined, data: FileUnionContent): Promise<FileUnionContent>;
23
23
  static getFileExtension(type: string): Promise<string | undefined>;
24
24
  static getMimeType(filename: string): Promise<string | undefined>;
25
25
  downloadFile(url: string): Promise<Response>;
@@ -1,5 +1,6 @@
1
1
  import type { AFSListOptions } from "@aigne/afs";
2
2
  import type { AgentInvokeOptions, AgentOptions, Message } from "../../../agents/agent.js";
3
+ import type { PromiseOrValue } from "../../../utils/type-utils.js";
3
4
  import { AFSSkillBase } from "./base.js";
4
5
  export interface AFSListInput extends Message {
5
6
  path: string;
@@ -18,5 +19,6 @@ export interface AFSListAgentOptions extends AgentOptions<AFSListInput, AFSListO
18
19
  }
19
20
  export declare class AFSListAgent extends AFSSkillBase<AFSListInput, AFSListOutput> {
20
21
  constructor(options: AFSListAgentOptions);
22
+ formatOutput(output: AFSListOutput): PromiseOrValue<string>;
21
23
  process(input: AFSListInput, _options: AgentInvokeOptions): Promise<AFSListOutput>;
22
24
  }
@@ -1,5 +1,6 @@
1
1
  import type { AFSEntry } from "@aigne/afs";
2
2
  import type { AgentInvokeOptions, AgentOptions, Message } from "../../../agents/agent.js";
3
+ import type { PromiseOrValue } from "../../../utils/type-utils.js";
3
4
  import { AFSSkillBase } from "./base.js";
4
5
  export interface AFSReadInput extends Message {
5
6
  path: string;
@@ -10,7 +11,7 @@ export interface AFSReadOutput extends Message {
10
11
  status: string;
11
12
  tool: string;
12
13
  path: string;
13
- data?: AFSEntry;
14
+ data?: AFSEntry | null;
14
15
  message?: string;
15
16
  totalLines?: number;
16
17
  returnedLines?: number;
@@ -22,5 +23,6 @@ export interface AFSReadAgentOptions extends AgentOptions<AFSReadInput, AFSReadO
22
23
  }
23
24
  export declare class AFSReadAgent extends AFSSkillBase<AFSReadInput, AFSReadOutput> {
24
25
  constructor(options: AFSReadAgentOptions);
26
+ formatOutput(output: AFSReadOutput): PromiseOrValue<string>;
25
27
  process(input: AFSReadInput, _options: AgentInvokeOptions): Promise<AFSReadOutput>;
26
28
  }
@@ -3,6 +3,7 @@ import { nodejs } from "@aigne/platform-helpers/nodejs/index.js";
3
3
  import equal from "fast-deep-equal";
4
4
  import nunjucks from "nunjucks";
5
5
  import { joinURL } from "ufo";
6
+ import { stringify } from "yaml";
6
7
  import { z } from "zod";
7
8
  import { zodToJsonSchema } from "zod-to-json-schema";
8
9
  import { codeToFunctionAgentFn } from "../loader/function-agent.js";
@@ -669,7 +670,7 @@ export class Agent {
669
670
  }
670
671
  }
671
672
  formatOutput(output) {
672
- return JSON.stringify(output);
673
+ return stringify(output);
673
674
  }
674
675
  /**
675
676
  * Shut down the agent and clean up resources
@@ -90,7 +90,7 @@ export class AIAgent extends Agent {
90
90
  static schema({ filepath }) {
91
91
  const instructionsSchema = getInstructionsSchema({ filepath });
92
92
  const nestAgentSchema = getNestAgentSchema({ filepath });
93
- return camelizeSchema(z.object({
93
+ const schema = camelizeSchema(z.object({
94
94
  instructions: optionalize(instructionsSchema),
95
95
  inputKey: optionalize(z.string()),
96
96
  outputKey: optionalize(z.string()),
@@ -101,14 +101,32 @@ export class AIAgent extends Agent {
101
101
  keepTextInToolUses: optionalize(z.boolean()),
102
102
  catchToolsError: optionalize(z.boolean()),
103
103
  structuredStreamMode: optionalize(z.boolean()),
104
- compact: camelizeSchema(optionalize(z.object({
104
+ session: optionalize(camelizeSchema(z.object({
105
105
  mode: optionalize(z.enum(["auto", "disabled"])),
106
- maxTokens: z.number().int().min(0).optional(),
107
- keepRecentRatio: optionalize(z.number().min(0).max(1)),
108
- async: optionalize(z.boolean()),
109
- compactor: optionalize(nestAgentSchema),
106
+ sessionMemory: optionalize(camelizeSchema(z.object({
107
+ mode: optionalize(z.enum(["auto", "disabled"])),
108
+ memoryRatio: optionalize(z.number().min(0).max(1)),
109
+ queryLimit: optionalize(z.number().int().min(0)),
110
+ async: optionalize(z.boolean()),
111
+ extractor: optionalize(nestAgentSchema),
112
+ }))),
113
+ userMemory: optionalize(camelizeSchema(z.object({
114
+ mode: optionalize(z.enum(["auto", "disabled"])),
115
+ memoryRatio: optionalize(z.number().min(0).max(1)),
116
+ queryLimit: optionalize(z.number().int().min(0)),
117
+ async: optionalize(z.boolean()),
118
+ extractor: optionalize(nestAgentSchema),
119
+ }))),
120
+ compact: optionalize(camelizeSchema(z.object({
121
+ mode: optionalize(z.enum(["auto", "disabled"])),
122
+ maxTokens: z.number().int().min(0).optional(),
123
+ keepRecentRatio: optionalize(z.number().min(0).max(1)),
124
+ async: optionalize(z.boolean()),
125
+ compactor: optionalize(nestAgentSchema),
126
+ }))),
110
127
  }))),
111
128
  }));
129
+ return schema;
112
130
  }
113
131
  static async load(options) {
114
132
  const schema = AIAgent.schema(options);
@@ -57,7 +57,9 @@ export declare abstract class ChatModel extends Model<ChatModelInput, ChatModelO
57
57
  getModelCapabilities(): {
58
58
  supportsParallelToolCalls: boolean;
59
59
  };
60
+ getModelOptions(input: Message, options: AgentInvokeOptions): Promise<ChatModelInputOptions>;
60
61
  private validateToolNames;
62
+ countTokens(input: ChatModelInput): Promise<number>;
61
63
  /**
62
64
  * Normalizes tool names to ensure compatibility with language models
63
65
  *
@@ -4,6 +4,7 @@ import { convertJsonSchemaToZod } from "zod-from-json-schema";
4
4
  import { optionalize } from "../loader/schema.js";
5
5
  import { wrapAutoParseJsonSchema } from "../utils/json-schema.js";
6
6
  import { logger } from "../utils/logger.js";
7
+ import { estimateTokens } from "../utils/token-estimator.js";
7
8
  import { checkArguments, isNil, omitByDeep } from "../utils/type-utils.js";
8
9
  import { agentOptionsSchema, getterSchema, } from "./agent.js";
9
10
  import { fileContentSchema, fileUnionContentSchema, localContentSchema, Model, urlContentSchema, } from "./model.js";
@@ -80,6 +81,19 @@ export class ChatModel extends Model {
80
81
  supportsParallelToolCalls: this.supportsParallelToolCalls,
81
82
  };
82
83
  }
84
+ async getModelOptions(input, options) {
85
+ const modelOptions = (await super.getModelOptions(input, options));
86
+ return {
87
+ ...modelOptions,
88
+ cacheConfig: {
89
+ ...modelOptions.cacheConfig,
90
+ autoBreakpoints: {
91
+ ...modelOptions.cacheConfig?.autoBreakpoints,
92
+ lastMessage: modelOptions.cacheConfig?.autoBreakpoints?.lastMessage ?? true,
93
+ },
94
+ },
95
+ };
96
+ }
83
97
  validateToolNames(tools) {
84
98
  for (const tool of tools ?? []) {
85
99
  if (!/^[a-zA-Z0-9_]+$/.test(tool.function.name)) {
@@ -87,6 +101,9 @@ export class ChatModel extends Model {
87
101
  }
88
102
  }
89
103
  }
104
+ async countTokens(input) {
105
+ return estimateTokens(JSON.stringify(input));
106
+ }
90
107
  /**
91
108
  * Normalizes tool names to ensure compatibility with language models
92
109
  *
@@ -201,7 +218,7 @@ export class ChatModel extends Model {
201
218
  const files = z.array(fileUnionContentSchema).parse(output.files);
202
219
  output = {
203
220
  ...output,
204
- files: await Promise.all(files.map((file) => this.transformFileType(input.outputFileType, file, options))),
221
+ files: await Promise.all(files.map((file) => this.transformFileType(input.outputFileType, file))),
205
222
  };
206
223
  }
207
224
  // Remove fields with `null` value for validation
@@ -67,7 +67,7 @@ export class ImageModel extends Model {
67
67
  const images = z.array(fileUnionContentSchema).parse(output.images);
68
68
  output = {
69
69
  ...output,
70
- images: await Promise.all(images.map((image) => this.transformFileType(input.outputFileType, image, options))),
70
+ images: await Promise.all(images.map((image) => this.transformFileType(input.outputFileType, image))),
71
71
  };
72
72
  }
73
73
  return super.processAgentOutput(input, output, options);
@@ -17,9 +17,9 @@ export declare abstract class Model<I extends Message = any, O extends Message =
17
17
  */
18
18
  getModelOptions(input: Message, options: AgentInvokeOptions): Promise<Record<string, unknown>>;
19
19
  protected preprocess(input: I, options: AgentInvokeOptions): Promise<void>;
20
- transformFileType(fileType: "file", data: FileUnionContent, options: AgentInvokeOptions): Promise<FileContent>;
21
- transformFileType(fileType: "local" | undefined, data: FileUnionContent, options: AgentInvokeOptions): Promise<LocalContent>;
22
- transformFileType(fileType: FileType | undefined, data: FileUnionContent, options: AgentInvokeOptions): Promise<FileUnionContent>;
20
+ transformFileType(fileType: "file", data: FileUnionContent): Promise<FileContent>;
21
+ transformFileType(fileType: "local" | undefined, data: FileUnionContent): Promise<LocalContent>;
22
+ transformFileType(fileType: FileType | undefined, data: FileUnionContent): Promise<FileUnionContent>;
23
23
  static getFileExtension(type: string): Promise<string | undefined>;
24
24
  static getMimeType(filename: string): Promise<string | undefined>;
25
25
  downloadFile(url: string): Promise<Response>;
@@ -53,13 +53,13 @@ export class Model extends Agent {
53
53
  Object.assign(input, { modelOptions: await this.getModelOptions(input, options) });
54
54
  return super.preprocess(input, options);
55
55
  }
56
- async transformFileType(fileType = "local", data, options) {
56
+ async transformFileType(fileType = "local", data) {
57
57
  if (fileType === data.type)
58
58
  return data;
59
59
  const common = pick(data, "filename", "mimeType");
60
60
  switch (fileType) {
61
61
  case "local": {
62
- const dir = nodejs.path.join(nodejs.os.tmpdir(), options.context.id);
62
+ const dir = nodejs.path.join(nodejs.os.tmpdir(), v7());
63
63
  await nodejs.fs.mkdir(dir, { recursive: true });
64
64
  const ext = await Model.getFileExtension(data.mimeType || data.filename || "");
65
65
  const id = v7();
@@ -40,7 +40,7 @@ export class VideoModel extends Model {
40
40
  const videos = z.array(fileUnionContentSchema).parse(output.videos);
41
41
  output = {
42
42
  ...output,
43
- videos: await Promise.all(videos.map((video) => this.transformFileType(input.outputFileType, video, options))),
43
+ videos: await Promise.all(videos.map((video) => this.transformFileType(input.outputFileType, video))),
44
44
  };
45
45
  }
46
46
  return super.processAgentOutput(input, output, options);
@@ -1,5 +1,6 @@
1
1
  import type { AFSListOptions } from "@aigne/afs";
2
2
  import type { AgentInvokeOptions, AgentOptions, Message } from "../../../agents/agent.js";
3
+ import type { PromiseOrValue } from "../../../utils/type-utils.js";
3
4
  import { AFSSkillBase } from "./base.js";
4
5
  export interface AFSListInput extends Message {
5
6
  path: string;
@@ -18,5 +19,6 @@ export interface AFSListAgentOptions extends AgentOptions<AFSListInput, AFSListO
18
19
  }
19
20
  export declare class AFSListAgent extends AFSSkillBase<AFSListInput, AFSListOutput> {
20
21
  constructor(options: AFSListAgentOptions);
22
+ formatOutput(output: AFSListOutput): PromiseOrValue<string>;
21
23
  process(input: AFSListInput, _options: AgentInvokeOptions): Promise<AFSListOutput>;
22
24
  }
@@ -53,10 +53,18 @@ Usage:
53
53
  }),
54
54
  });
55
55
  }
56
+ formatOutput(output) {
57
+ if (typeof output.data === "string")
58
+ return output.data;
59
+ return super.formatOutput(output);
60
+ }
56
61
  async process(input, _options) {
57
62
  if (!this.afs)
58
63
  throw new Error("AFS is not configured for this agent.");
59
- const { data, message } = await this.afs.list(input.path, input.options);
64
+ const { data, message } = await this.afs.list(input.path, {
65
+ ...input.options,
66
+ format: "simple-list",
67
+ });
60
68
  return {
61
69
  status: "success",
62
70
  tool: "afs_list",
@@ -1,5 +1,6 @@
1
1
  import type { AFSEntry } from "@aigne/afs";
2
2
  import type { AgentInvokeOptions, AgentOptions, Message } from "../../../agents/agent.js";
3
+ import type { PromiseOrValue } from "../../../utils/type-utils.js";
3
4
  import { AFSSkillBase } from "./base.js";
4
5
  export interface AFSReadInput extends Message {
5
6
  path: string;
@@ -10,7 +11,7 @@ export interface AFSReadOutput extends Message {
10
11
  status: string;
11
12
  tool: string;
12
13
  path: string;
13
- data?: AFSEntry;
14
+ data?: AFSEntry | null;
14
15
  message?: string;
15
16
  totalLines?: number;
16
17
  returnedLines?: number;
@@ -22,5 +23,6 @@ export interface AFSReadAgentOptions extends AgentOptions<AFSReadInput, AFSReadO
22
23
  }
23
24
  export declare class AFSReadAgent extends AFSSkillBase<AFSReadInput, AFSReadOutput> {
24
25
  constructor(options: AFSReadAgentOptions);
26
+ formatOutput(output: AFSReadOutput): PromiseOrValue<string>;
25
27
  process(input: AFSReadInput, _options: AgentInvokeOptions): Promise<AFSReadOutput>;
26
28
  }
@@ -48,6 +48,11 @@ Usage:
48
48
  }),
49
49
  });
50
50
  }
51
+ formatOutput(output) {
52
+ if (typeof output.data?.content === "string" && output.data.content)
53
+ return output.data.content;
54
+ return super.formatOutput({ ...output, data: output.data || null });
55
+ }
51
56
  async process(input, _options) {
52
57
  if (!this.afs)
53
58
  throw new Error("AFS is not configured for this agent.");
@@ -5,7 +5,7 @@
5
5
  const CHAR_TYPE_RATIOS = {
6
6
  chinese: 1.5, // Chinese characters: ~1.5 characters per token
7
7
  word: 0.75, // English words: ~0.75 tokens per word (accounting for subword tokenization)
8
- other: 4, // Other characters (punctuation, numbers, etc.): ~4 characters per token
8
+ other: 1, // Other characters (punctuation, numbers, etc.): ~1 character per token
9
9
  };
10
10
  /**
11
11
  * Regular expressions for character type detection
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aigne/core",
3
- "version": "1.72.0-beta.13",
3
+ "version": "1.72.0-beta.16",
4
4
  "description": "The functional core of agentic AI",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -93,10 +93,10 @@
93
93
  "zod": "^3.25.67",
94
94
  "zod-from-json-schema": "^0.0.5",
95
95
  "zod-to-json-schema": "^3.24.6",
96
- "@aigne/afs": "^1.4.0-beta.7",
97
- "@aigne/afs-history": "^1.2.0-beta.8",
98
- "@aigne/observability-api": "^0.11.14-beta.2",
99
- "@aigne/platform-helpers": "^0.6.7-beta.1"
96
+ "@aigne/afs": "^1.4.0-beta.8",
97
+ "@aigne/afs-history": "^1.2.0-beta.9",
98
+ "@aigne/platform-helpers": "^0.6.7-beta.1",
99
+ "@aigne/observability-api": "^0.11.14-beta.2"
100
100
  },
101
101
  "devDependencies": {
102
102
  "@types/bun": "^1.2.22",