@aigne/core 1.62.0-beta.4 → 1.62.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,17 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.62.0-beta.5](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.62.0-beta.4...core-v1.62.0-beta.5) (2025-10-02)
4
+
5
+
6
+ ### Features
7
+
8
+ * **core:** add `keepTextInToolUses` option for AI Agent ([#585](https://github.com/AIGNE-io/aigne-framework/issues/585)) ([6c6be9e](https://github.com/AIGNE-io/aigne-framework/commit/6c6be9eee8e96294921b676a1982a18c93b2f66d))
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * **core:** agent should not emit error event if retried ([#583](https://github.com/AIGNE-io/aigne-framework/issues/583)) ([04edcbf](https://github.com/AIGNE-io/aigne-framework/commit/04edcbfd71aa2746dad98140e20e0b718701fa0a))
14
+
3
15
  ## [1.62.0-beta.4](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.62.0-beta.3...core-v1.62.0-beta.4) (2025-10-01)
4
16
 
5
17
 
@@ -551,9 +551,11 @@ class Agent {
551
551
  */
552
552
  async processAgentError(input, error, options) {
553
553
  logger_js_1.logger.error("Invoke agent %s failed with error: %O", this.name, error);
554
- if (!this.disableEvents)
555
- options.context.emit("agentFailed", { agent: this, error });
556
554
  const res = (await this.callHooks(["onError", "onEnd"], { input, error }, options)) ?? {};
555
+ if (!res.retry) {
556
+ if (!this.disableEvents)
557
+ options.context.emit("agentFailed", { agent: this, error });
558
+ }
557
559
  return { ...res };
558
560
  }
559
561
  /**
@@ -42,6 +42,10 @@ export interface AIAgentOptions<I extends Message = Message, O extends Message =
42
42
  * @default AIAgentToolChoice.auto
43
43
  */
44
44
  toolChoice?: AIAgentToolChoice | Agent;
45
+ /**
46
+ * Whether to preserve text generated during tool usage in the final output
47
+ */
48
+ keepTextInToolUses?: boolean;
45
49
  /**
46
50
  * Whether to catch errors from tool execution and continue processing.
47
51
  * If set to false, the agent will throw an error if a tool fails.
@@ -233,6 +237,10 @@ export declare class AIAgent<I extends Message = any, O extends Message = any> e
233
237
  * {@includeCode ../../test/agents/ai-agent.test.ts#example-ai-agent-router}
234
238
  */
235
239
  toolChoice?: AIAgentToolChoice | Agent;
240
+ /**
241
+ * Whether to preserve text generated during tool usage in the final output
242
+ */
243
+ keepTextInToolUses?: boolean;
236
244
  /**
237
245
  * Whether to include memory agents as tools for the AI model
238
246
  *
@@ -58,6 +58,7 @@ exports.aiAgentOptionsSchema = agent_js_1.agentOptionsSchema.extend({
58
58
  inputKey: zod_1.z.string().optional(),
59
59
  outputKey: zod_1.z.string().optional(),
60
60
  toolChoice: exports.aiAgentToolChoiceSchema.optional(),
61
+ keepTextInToolUses: zod_1.z.boolean().optional(),
61
62
  memoryAgentsAsTools: zod_1.z.boolean().optional(),
62
63
  memoryPromptTemplate: zod_1.z.string().optional(),
63
64
  });
@@ -116,6 +117,7 @@ class AIAgent extends agent_js_1.Agent {
116
117
  this.outputFileKey = options.outputFileKey || exports.DEFAULT_OUTPUT_FILE_KEY;
117
118
  this.outputFileType = options.outputFileType;
118
119
  this.toolChoice = options.toolChoice;
120
+ this.keepTextInToolUses = options.keepTextInToolUses;
119
121
  this.memoryAgentsAsTools = options.memoryAgentsAsTools;
120
122
  this.memoryPromptTemplate = options.memoryPromptTemplate;
121
123
  this.useMemoriesFromContext = options.useMemoriesFromContext;
@@ -171,6 +173,10 @@ class AIAgent extends agent_js_1.Agent {
171
173
  * {@includeCode ../../test/agents/ai-agent.test.ts#example-ai-agent-router}
172
174
  */
173
175
  toolChoice;
176
+ /**
177
+ * Whether to preserve text generated during tool usage in the final output
178
+ */
179
+ keepTextInToolUses;
174
180
  /**
175
181
  * Whether to include memory agents as tools for the AI model
176
182
  *
@@ -271,6 +277,12 @@ class AIAgent extends agent_js_1.Agent {
271
277
  }
272
278
  const { toolCalls, json, text, files } = modelOutput;
273
279
  if (toolCalls?.length) {
280
+ if (!this.keepTextInToolUses) {
281
+ yield { delta: { json: { [outputKey]: "" } } };
282
+ }
283
+ else {
284
+ yield { delta: { text: { [outputKey]: "\n" } } };
285
+ }
274
286
  const executedToolCalls = [];
275
287
  // Execute tools
276
288
  for (const call of toolCalls) {
@@ -48,6 +48,7 @@ export interface AIAgentSchema extends BaseAgentSchema {
48
48
  inputKey?: string;
49
49
  outputKey?: string;
50
50
  toolChoice?: AIAgentToolChoice;
51
+ keepTextInToolUses?: boolean;
51
52
  }
52
53
  export interface ImageAgentSchema extends BaseAgentSchema {
53
54
  type: "image";
@@ -96,6 +96,7 @@ async function parseAgentFile(path, data) {
96
96
  inputKey: (0, schema_js_1.optionalize)(zod_1.z.string()),
97
97
  outputKey: (0, schema_js_1.optionalize)(zod_1.z.string()),
98
98
  toolChoice: (0, schema_js_1.optionalize)(zod_1.z.nativeEnum(ai_agent_js_1.AIAgentToolChoice)),
99
+ keepTextInToolUses: (0, schema_js_1.optionalize)(zod_1.z.boolean()),
99
100
  structuredStreamMode: (0, schema_js_1.optionalize)(zod_1.z.boolean()),
100
101
  })
101
102
  .extend(baseAgentSchema.shape),
@@ -42,6 +42,10 @@ export interface AIAgentOptions<I extends Message = Message, O extends Message =
42
42
  * @default AIAgentToolChoice.auto
43
43
  */
44
44
  toolChoice?: AIAgentToolChoice | Agent;
45
+ /**
46
+ * Whether to preserve text generated during tool usage in the final output
47
+ */
48
+ keepTextInToolUses?: boolean;
45
49
  /**
46
50
  * Whether to catch errors from tool execution and continue processing.
47
51
  * If set to false, the agent will throw an error if a tool fails.
@@ -233,6 +237,10 @@ export declare class AIAgent<I extends Message = any, O extends Message = any> e
233
237
  * {@includeCode ../../test/agents/ai-agent.test.ts#example-ai-agent-router}
234
238
  */
235
239
  toolChoice?: AIAgentToolChoice | Agent;
240
+ /**
241
+ * Whether to preserve text generated during tool usage in the final output
242
+ */
243
+ keepTextInToolUses?: boolean;
236
244
  /**
237
245
  * Whether to include memory agents as tools for the AI model
238
246
  *
@@ -48,6 +48,7 @@ export interface AIAgentSchema extends BaseAgentSchema {
48
48
  inputKey?: string;
49
49
  outputKey?: string;
50
50
  toolChoice?: AIAgentToolChoice;
51
+ keepTextInToolUses?: boolean;
51
52
  }
52
53
  export interface ImageAgentSchema extends BaseAgentSchema {
53
54
  type: "image";
@@ -503,9 +503,11 @@ export class Agent {
503
503
  */
504
504
  async processAgentError(input, error, options) {
505
505
  logger.error("Invoke agent %s failed with error: %O", this.name, error);
506
- if (!this.disableEvents)
507
- options.context.emit("agentFailed", { agent: this, error });
508
506
  const res = (await this.callHooks(["onError", "onEnd"], { input, error }, options)) ?? {};
507
+ if (!res.retry) {
508
+ if (!this.disableEvents)
509
+ options.context.emit("agentFailed", { agent: this, error });
510
+ }
509
511
  return { ...res };
510
512
  }
511
513
  /**
@@ -42,6 +42,10 @@ export interface AIAgentOptions<I extends Message = Message, O extends Message =
42
42
  * @default AIAgentToolChoice.auto
43
43
  */
44
44
  toolChoice?: AIAgentToolChoice | Agent;
45
+ /**
46
+ * Whether to preserve text generated during tool usage in the final output
47
+ */
48
+ keepTextInToolUses?: boolean;
45
49
  /**
46
50
  * Whether to catch errors from tool execution and continue processing.
47
51
  * If set to false, the agent will throw an error if a tool fails.
@@ -233,6 +237,10 @@ export declare class AIAgent<I extends Message = any, O extends Message = any> e
233
237
  * {@includeCode ../../test/agents/ai-agent.test.ts#example-ai-agent-router}
234
238
  */
235
239
  toolChoice?: AIAgentToolChoice | Agent;
240
+ /**
241
+ * Whether to preserve text generated during tool usage in the final output
242
+ */
243
+ keepTextInToolUses?: boolean;
236
244
  /**
237
245
  * Whether to include memory agents as tools for the AI model
238
246
  *
@@ -55,6 +55,7 @@ export const aiAgentOptionsSchema = agentOptionsSchema.extend({
55
55
  inputKey: z.string().optional(),
56
56
  outputKey: z.string().optional(),
57
57
  toolChoice: aiAgentToolChoiceSchema.optional(),
58
+ keepTextInToolUses: z.boolean().optional(),
58
59
  memoryAgentsAsTools: z.boolean().optional(),
59
60
  memoryPromptTemplate: z.string().optional(),
60
61
  });
@@ -113,6 +114,7 @@ export class AIAgent extends Agent {
113
114
  this.outputFileKey = options.outputFileKey || DEFAULT_OUTPUT_FILE_KEY;
114
115
  this.outputFileType = options.outputFileType;
115
116
  this.toolChoice = options.toolChoice;
117
+ this.keepTextInToolUses = options.keepTextInToolUses;
116
118
  this.memoryAgentsAsTools = options.memoryAgentsAsTools;
117
119
  this.memoryPromptTemplate = options.memoryPromptTemplate;
118
120
  this.useMemoriesFromContext = options.useMemoriesFromContext;
@@ -168,6 +170,10 @@ export class AIAgent extends Agent {
168
170
  * {@includeCode ../../test/agents/ai-agent.test.ts#example-ai-agent-router}
169
171
  */
170
172
  toolChoice;
173
+ /**
174
+ * Whether to preserve text generated during tool usage in the final output
175
+ */
176
+ keepTextInToolUses;
171
177
  /**
172
178
  * Whether to include memory agents as tools for the AI model
173
179
  *
@@ -268,6 +274,12 @@ export class AIAgent extends Agent {
268
274
  }
269
275
  const { toolCalls, json, text, files } = modelOutput;
270
276
  if (toolCalls?.length) {
277
+ if (!this.keepTextInToolUses) {
278
+ yield { delta: { json: { [outputKey]: "" } } };
279
+ }
280
+ else {
281
+ yield { delta: { text: { [outputKey]: "\n" } } };
282
+ }
271
283
  const executedToolCalls = [];
272
284
  // Execute tools
273
285
  for (const call of toolCalls) {
@@ -48,6 +48,7 @@ export interface AIAgentSchema extends BaseAgentSchema {
48
48
  inputKey?: string;
49
49
  outputKey?: string;
50
50
  toolChoice?: AIAgentToolChoice;
51
+ keepTextInToolUses?: boolean;
51
52
  }
52
53
  export interface ImageAgentSchema extends BaseAgentSchema {
53
54
  type: "image";
@@ -92,6 +92,7 @@ export async function parseAgentFile(path, data) {
92
92
  inputKey: optionalize(z.string()),
93
93
  outputKey: optionalize(z.string()),
94
94
  toolChoice: optionalize(z.nativeEnum(AIAgentToolChoice)),
95
+ keepTextInToolUses: optionalize(z.boolean()),
95
96
  structuredStreamMode: optionalize(z.boolean()),
96
97
  })
97
98
  .extend(baseAgentSchema.shape),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aigne/core",
3
- "version": "1.62.0-beta.4",
3
+ "version": "1.62.0-beta.5",
4
4
  "description": "The functional core of agentic AI",
5
5
  "publishConfig": {
6
6
  "access": "public"