@aigne/core 1.63.0-beta.4 → 1.63.0-beta.5

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,12 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.63.0-beta.5](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.63.0-beta.4...core-v1.63.0-beta.5) (2025-10-13)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * **core:** auto merge multiple system messages ([#619](https://github.com/AIGNE-io/aigne-framework/issues/619)) ([e9e62c0](https://github.com/AIGNE-io/aigne-framework/commit/e9e62c03c45f5a9b75d44a07588b2b179e262aad))
9
+
3
10
  ## [1.63.0-beta.4](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.63.0-beta.3...core-v1.63.0-beta.4) (2025-10-12)
4
11
 
5
12
 
@@ -31,6 +31,7 @@ export declare class PromptBuilder {
31
31
  prompt: string;
32
32
  }>;
33
33
  private buildMessages;
34
+ private mergeSystemMessages;
34
35
  private convertMemoriesToMessages;
35
36
  private buildResponseFormat;
36
37
  private buildTools;
@@ -138,7 +138,25 @@ class PromptBuilder {
138
138
  content.push(...files);
139
139
  messages.push({ role: "user", content });
140
140
  }
141
- return messages;
141
+ return this.mergeSystemMessages(messages);
142
+ }
143
+ mergeSystemMessages(messages) {
144
+ const [systemMessages, otherMessages] = (0, type_utils_js_1.partition)(messages, (m) => m.role === "system");
145
+ const result = [];
146
+ if (systemMessages.length) {
147
+ result.push({
148
+ role: "system",
149
+ content: systemMessages
150
+ .map((i) => typeof i.content === "string"
151
+ ? i.content
152
+ : i.content
153
+ ?.map((c) => (c.type === "text" ? c.text : null))
154
+ .filter(type_utils_js_1.isNonNullable)
155
+ .join("\n"))
156
+ .join("\n"),
157
+ });
158
+ }
159
+ return result.concat(otherMessages);
142
160
  }
143
161
  async convertMemoriesToMessages(memories, options) {
144
162
  const messages = [];
@@ -27,3 +27,4 @@ export declare function createAccessorArray<T>(array: T[], accessor: (array: T[]
27
27
  export declare function checkArguments<T extends ZodType>(prefix: string, schema: T, args: unknown): z.infer<T>;
28
28
  export declare function tryOrThrow<P extends PromiseOrValue<unknown>>(fn: () => P, error: string | Error | ((error: Error) => Error)): P;
29
29
  export declare function tryOrThrow<P extends PromiseOrValue<unknown>>(fn: () => P, error?: Nullish<string | Error | ((error: Error) => Nullish<Error>)>): P | undefined;
30
+ export declare function partition<T>(array: T[], predicate: (item: T) => boolean): [T[], T[]];
@@ -17,6 +17,7 @@ exports.flat = flat;
17
17
  exports.createAccessorArray = createAccessorArray;
18
18
  exports.checkArguments = checkArguments;
19
19
  exports.tryOrThrow = tryOrThrow;
20
+ exports.partition = partition;
20
21
  const zod_1 = require("zod");
21
22
  function isNil(value) {
22
23
  return value === null || value === undefined;
@@ -196,3 +197,16 @@ function tryOrThrow(fn, error) {
196
197
  throw error;
197
198
  }
198
199
  }
200
+ function partition(array, predicate) {
201
+ const pass = [];
202
+ const fail = [];
203
+ for (const item of array) {
204
+ if (predicate(item)) {
205
+ pass.push(item);
206
+ }
207
+ else {
208
+ fail.push(item);
209
+ }
210
+ }
211
+ return [pass, fail];
212
+ }
@@ -31,6 +31,7 @@ export declare class PromptBuilder {
31
31
  prompt: string;
32
32
  }>;
33
33
  private buildMessages;
34
+ private mergeSystemMessages;
34
35
  private convertMemoriesToMessages;
35
36
  private buildResponseFormat;
36
37
  private buildTools;
@@ -27,3 +27,4 @@ export declare function createAccessorArray<T>(array: T[], accessor: (array: T[]
27
27
  export declare function checkArguments<T extends ZodType>(prefix: string, schema: T, args: unknown): z.infer<T>;
28
28
  export declare function tryOrThrow<P extends PromiseOrValue<unknown>>(fn: () => P, error: string | Error | ((error: Error) => Error)): P;
29
29
  export declare function tryOrThrow<P extends PromiseOrValue<unknown>>(fn: () => P, error?: Nullish<string | Error | ((error: Error) => Nullish<Error>)>): P | undefined;
30
+ export declare function partition<T>(array: T[], predicate: (item: T) => boolean): [T[], T[]];
@@ -31,6 +31,7 @@ export declare class PromptBuilder {
31
31
  prompt: string;
32
32
  }>;
33
33
  private buildMessages;
34
+ private mergeSystemMessages;
34
35
  private convertMemoriesToMessages;
35
36
  private buildResponseFormat;
36
37
  private buildTools;
@@ -8,7 +8,7 @@ import { DEFAULT_OUTPUT_FILE_KEY, DEFAULT_OUTPUT_KEY } from "../agents/ai-agent.
8
8
  import { fileUnionContentsSchema } from "../agents/model.js";
9
9
  import { optionalize } from "../loader/schema.js";
10
10
  import { outputSchemaToResponseFormatSchema } from "../utils/json-schema.js";
11
- import { checkArguments, flat, isNonNullable, isRecord, unique } from "../utils/type-utils.js";
11
+ import { checkArguments, flat, isNonNullable, isRecord, partition, unique, } from "../utils/type-utils.js";
12
12
  import { getAFSSystemPrompt } from "./prompts/afs-builtin-prompt.js";
13
13
  import { MEMORY_MESSAGE_TEMPLATE } from "./prompts/memory-message-template.js";
14
14
  import { STRUCTURED_STREAM_INSTRUCTIONS } from "./prompts/structured-stream-instructions.js";
@@ -135,7 +135,25 @@ export class PromptBuilder {
135
135
  content.push(...files);
136
136
  messages.push({ role: "user", content });
137
137
  }
138
- return messages;
138
+ return this.mergeSystemMessages(messages);
139
+ }
140
+ mergeSystemMessages(messages) {
141
+ const [systemMessages, otherMessages] = partition(messages, (m) => m.role === "system");
142
+ const result = [];
143
+ if (systemMessages.length) {
144
+ result.push({
145
+ role: "system",
146
+ content: systemMessages
147
+ .map((i) => typeof i.content === "string"
148
+ ? i.content
149
+ : i.content
150
+ ?.map((c) => (c.type === "text" ? c.text : null))
151
+ .filter(isNonNullable)
152
+ .join("\n"))
153
+ .join("\n"),
154
+ });
155
+ }
156
+ return result.concat(otherMessages);
139
157
  }
140
158
  async convertMemoriesToMessages(memories, options) {
141
159
  const messages = [];
@@ -27,3 +27,4 @@ export declare function createAccessorArray<T>(array: T[], accessor: (array: T[]
27
27
  export declare function checkArguments<T extends ZodType>(prefix: string, schema: T, args: unknown): z.infer<T>;
28
28
  export declare function tryOrThrow<P extends PromiseOrValue<unknown>>(fn: () => P, error: string | Error | ((error: Error) => Error)): P;
29
29
  export declare function tryOrThrow<P extends PromiseOrValue<unknown>>(fn: () => P, error?: Nullish<string | Error | ((error: Error) => Nullish<Error>)>): P | undefined;
30
+ export declare function partition<T>(array: T[], predicate: (item: T) => boolean): [T[], T[]];
@@ -177,3 +177,16 @@ export function tryOrThrow(fn, error) {
177
177
  throw error;
178
178
  }
179
179
  }
180
+ export function partition(array, predicate) {
181
+ const pass = [];
182
+ const fail = [];
183
+ for (const item of array) {
184
+ if (predicate(item)) {
185
+ pass.push(item);
186
+ }
187
+ else {
188
+ fail.push(item);
189
+ }
190
+ }
191
+ return [pass, fail];
192
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aigne/core",
3
- "version": "1.63.0-beta.4",
3
+ "version": "1.63.0-beta.5",
4
4
  "description": "The functional core of agentic AI",
5
5
  "publishConfig": {
6
6
  "access": "public"