@aigne/core 1.63.0-beta.6 → 1.63.0-beta.7

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.7](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.63.0-beta.6...core-v1.63.0-beta.7) (2025-10-15)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * add options for system message reordering and merging ([#624](https://github.com/AIGNE-io/aigne-framework/issues/624)) ([8ca466d](https://github.com/AIGNE-io/aigne-framework/commit/8ca466d49d1e4ed08bc90922f39c0d3ed60c4fd5))
9
+
3
10
  ## [1.63.0-beta.6](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.63.0-beta.5...core-v1.63.0-beta.6) (2025-10-15)
4
11
 
5
12
 
@@ -23,6 +23,8 @@ export interface AIAgentOptions<I extends Message = Message, O extends Message =
23
23
  * more complex prompt templates
24
24
  */
25
25
  instructions?: string | PromptBuilder;
26
+ autoReorderSystemMessages?: boolean;
27
+ autoMergeSystemMessages?: boolean;
26
28
  /**
27
29
  * Pick a message from input to use as the user's message
28
30
  */
@@ -216,6 +218,8 @@ export declare class AIAgent<I extends Message = any, O extends Message = any> e
216
218
  * {@includeCode ../../test/agents/ai-agent.test.ts#example-ai-agent-prompt-builder}
217
219
  */
218
220
  instructions: PromptBuilder;
221
+ autoReorderSystemMessages?: boolean;
222
+ autoMergeSystemMessages?: boolean;
219
223
  /**
220
224
  * Pick a message from input to use as the user's message
221
225
  */
@@ -117,6 +117,8 @@ class AIAgent extends agent_js_1.Agent {
117
117
  typeof options.instructions === "string"
118
118
  ? prompt_builder_js_1.PromptBuilder.from(options.instructions)
119
119
  : (options.instructions ?? new prompt_builder_js_1.PromptBuilder());
120
+ this.autoReorderSystemMessages = options.autoReorderSystemMessages ?? false;
121
+ this.autoMergeSystemMessages = options.autoMergeSystemMessages ?? false;
120
122
  this.inputKey = options.inputKey;
121
123
  this.inputFileKey = options.inputFileKey;
122
124
  this.outputKey = options.outputKey || exports.DEFAULT_OUTPUT_KEY;
@@ -153,6 +155,8 @@ class AIAgent extends agent_js_1.Agent {
153
155
  * {@includeCode ../../test/agents/ai-agent.test.ts#example-ai-agent-prompt-builder}
154
156
  */
155
157
  instructions;
158
+ autoReorderSystemMessages;
159
+ autoMergeSystemMessages;
156
160
  /**
157
161
  * Pick a message from input to use as the user's message
158
162
  */
@@ -54,6 +54,8 @@ export type Instructions = {
54
54
  export interface AIAgentSchema extends BaseAgentSchema {
55
55
  type: "ai";
56
56
  instructions?: Instructions;
57
+ autoReorderSystemMessages?: boolean;
58
+ autoMergeSystemMessages?: boolean;
57
59
  inputKey?: string;
58
60
  inputFileKey?: string;
59
61
  outputKey?: string;
@@ -112,6 +112,8 @@ async function parseAgentFile(path, data) {
112
112
  .object({
113
113
  type: zod_1.z.literal("ai"),
114
114
  instructions: (0, schema_js_1.optionalize)(instructionsSchema),
115
+ autoReorderSystemMessages: (0, schema_js_1.optionalize)(zod_1.z.boolean()),
116
+ autoMergeSystemMessages: (0, schema_js_1.optionalize)(zod_1.z.boolean()),
115
117
  inputKey: (0, schema_js_1.optionalize)(zod_1.z.string()),
116
118
  outputKey: (0, schema_js_1.optionalize)(zod_1.z.string()),
117
119
  inputFileKey: (0, schema_js_1.optionalize)(zod_1.z.string()),
@@ -31,7 +31,7 @@ export declare class PromptBuilder {
31
31
  prompt: string;
32
32
  }>;
33
33
  private buildMessages;
34
- private mergeSystemMessages;
34
+ private refineMessages;
35
35
  private convertMemoriesToMessages;
36
36
  private buildResponseFormat;
37
37
  private buildTools;
@@ -138,10 +138,16 @@ class PromptBuilder {
138
138
  content.push(...files);
139
139
  messages.push({ role: "user", content });
140
140
  }
141
- return this.mergeSystemMessages(messages);
141
+ return this.refineMessages(options, messages);
142
142
  }
143
- mergeSystemMessages(messages) {
143
+ refineMessages(options, messages) {
144
+ const { autoReorderSystemMessages, autoMergeSystemMessages } = options.agent ?? {};
145
+ if (!autoReorderSystemMessages && !autoMergeSystemMessages)
146
+ return messages;
144
147
  const [systemMessages, otherMessages] = (0, type_utils_js_1.partition)(messages, (m) => m.role === "system");
148
+ if (!autoMergeSystemMessages) {
149
+ return systemMessages.concat(otherMessages);
150
+ }
145
151
  const result = [];
146
152
  if (systemMessages.length) {
147
153
  result.push({
@@ -23,6 +23,8 @@ export interface AIAgentOptions<I extends Message = Message, O extends Message =
23
23
  * more complex prompt templates
24
24
  */
25
25
  instructions?: string | PromptBuilder;
26
+ autoReorderSystemMessages?: boolean;
27
+ autoMergeSystemMessages?: boolean;
26
28
  /**
27
29
  * Pick a message from input to use as the user's message
28
30
  */
@@ -216,6 +218,8 @@ export declare class AIAgent<I extends Message = any, O extends Message = any> e
216
218
  * {@includeCode ../../test/agents/ai-agent.test.ts#example-ai-agent-prompt-builder}
217
219
  */
218
220
  instructions: PromptBuilder;
221
+ autoReorderSystemMessages?: boolean;
222
+ autoMergeSystemMessages?: boolean;
219
223
  /**
220
224
  * Pick a message from input to use as the user's message
221
225
  */
@@ -54,6 +54,8 @@ export type Instructions = {
54
54
  export interface AIAgentSchema extends BaseAgentSchema {
55
55
  type: "ai";
56
56
  instructions?: Instructions;
57
+ autoReorderSystemMessages?: boolean;
58
+ autoMergeSystemMessages?: boolean;
57
59
  inputKey?: string;
58
60
  inputFileKey?: string;
59
61
  outputKey?: string;
@@ -31,7 +31,7 @@ export declare class PromptBuilder {
31
31
  prompt: string;
32
32
  }>;
33
33
  private buildMessages;
34
- private mergeSystemMessages;
34
+ private refineMessages;
35
35
  private convertMemoriesToMessages;
36
36
  private buildResponseFormat;
37
37
  private buildTools;
@@ -23,6 +23,8 @@ export interface AIAgentOptions<I extends Message = Message, O extends Message =
23
23
  * more complex prompt templates
24
24
  */
25
25
  instructions?: string | PromptBuilder;
26
+ autoReorderSystemMessages?: boolean;
27
+ autoMergeSystemMessages?: boolean;
26
28
  /**
27
29
  * Pick a message from input to use as the user's message
28
30
  */
@@ -216,6 +218,8 @@ export declare class AIAgent<I extends Message = any, O extends Message = any> e
216
218
  * {@includeCode ../../test/agents/ai-agent.test.ts#example-ai-agent-prompt-builder}
217
219
  */
218
220
  instructions: PromptBuilder;
221
+ autoReorderSystemMessages?: boolean;
222
+ autoMergeSystemMessages?: boolean;
219
223
  /**
220
224
  * Pick a message from input to use as the user's message
221
225
  */
@@ -111,6 +111,8 @@ export class AIAgent extends Agent {
111
111
  typeof options.instructions === "string"
112
112
  ? PromptBuilder.from(options.instructions)
113
113
  : (options.instructions ?? new PromptBuilder());
114
+ this.autoReorderSystemMessages = options.autoReorderSystemMessages ?? false;
115
+ this.autoMergeSystemMessages = options.autoMergeSystemMessages ?? false;
114
116
  this.inputKey = options.inputKey;
115
117
  this.inputFileKey = options.inputFileKey;
116
118
  this.outputKey = options.outputKey || DEFAULT_OUTPUT_KEY;
@@ -147,6 +149,8 @@ export class AIAgent extends Agent {
147
149
  * {@includeCode ../../test/agents/ai-agent.test.ts#example-ai-agent-prompt-builder}
148
150
  */
149
151
  instructions;
152
+ autoReorderSystemMessages;
153
+ autoMergeSystemMessages;
150
154
  /**
151
155
  * Pick a message from input to use as the user's message
152
156
  */
@@ -54,6 +54,8 @@ export type Instructions = {
54
54
  export interface AIAgentSchema extends BaseAgentSchema {
55
55
  type: "ai";
56
56
  instructions?: Instructions;
57
+ autoReorderSystemMessages?: boolean;
58
+ autoMergeSystemMessages?: boolean;
57
59
  inputKey?: string;
58
60
  inputFileKey?: string;
59
61
  outputKey?: string;
@@ -108,6 +108,8 @@ export async function parseAgentFile(path, data) {
108
108
  .object({
109
109
  type: z.literal("ai"),
110
110
  instructions: optionalize(instructionsSchema),
111
+ autoReorderSystemMessages: optionalize(z.boolean()),
112
+ autoMergeSystemMessages: optionalize(z.boolean()),
111
113
  inputKey: optionalize(z.string()),
112
114
  outputKey: optionalize(z.string()),
113
115
  inputFileKey: optionalize(z.string()),
@@ -31,7 +31,7 @@ export declare class PromptBuilder {
31
31
  prompt: string;
32
32
  }>;
33
33
  private buildMessages;
34
- private mergeSystemMessages;
34
+ private refineMessages;
35
35
  private convertMemoriesToMessages;
36
36
  private buildResponseFormat;
37
37
  private buildTools;
@@ -135,10 +135,16 @@ export class PromptBuilder {
135
135
  content.push(...files);
136
136
  messages.push({ role: "user", content });
137
137
  }
138
- return this.mergeSystemMessages(messages);
138
+ return this.refineMessages(options, messages);
139
139
  }
140
- mergeSystemMessages(messages) {
140
+ refineMessages(options, messages) {
141
+ const { autoReorderSystemMessages, autoMergeSystemMessages } = options.agent ?? {};
142
+ if (!autoReorderSystemMessages && !autoMergeSystemMessages)
143
+ return messages;
141
144
  const [systemMessages, otherMessages] = partition(messages, (m) => m.role === "system");
145
+ if (!autoMergeSystemMessages) {
146
+ return systemMessages.concat(otherMessages);
147
+ }
142
148
  const result = [];
143
149
  if (systemMessages.length) {
144
150
  result.push({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aigne/core",
3
- "version": "1.63.0-beta.6",
3
+ "version": "1.63.0-beta.7",
4
4
  "description": "The functional core of agentic AI",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -92,8 +92,8 @@
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/afs": "^1.1.0-beta",
96
95
  "@aigne/observability-api": "^0.11.2-beta.2",
96
+ "@aigne/afs": "^1.1.0-beta",
97
97
  "@aigne/platform-helpers": "^0.6.3"
98
98
  },
99
99
  "devDependencies": {