@aigne/core 1.55.0 → 1.55.1

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,19 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.55.1](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.55.0...core-v1.55.1) (2025-08-26)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * **cli:** reduce memory usage of AIGNE CLI ([#411](https://github.com/AIGNE-io/aigne-framework/issues/411)) ([9c36969](https://github.com/AIGNE-io/aigne-framework/commit/9c369699d966d37abf2d6a1624eac3d2fda4123b))
9
+
10
+
11
+ ### Dependencies
12
+
13
+ * The following workspace dependencies were updated
14
+ * dependencies
15
+ * @aigne/observability-api bumped to 0.10.1
16
+
3
17
  ## [1.55.0](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.54.0...core-v1.55.0) (2025-08-21)
4
18
 
5
19
 
@@ -506,9 +506,6 @@ class Agent {
506
506
  * @param options Invocation options
507
507
  */
508
508
  async processAgentError(input, error, options) {
509
- if ("$error_has_been_processed" in error && error.$error_has_been_processed)
510
- return {};
511
- Object.defineProperty(error, "$error_has_been_processed", { value: true, enumerable: false });
512
509
  logger_js_1.logger.error("Invoke agent %s failed with error: %O", this.name, error);
513
510
  if (!this.disableEvents)
514
511
  options.context.emit("agentFailed", { agent: this, error });
@@ -196,25 +196,34 @@ class TeamAgent extends agent_js_1.Agent {
196
196
  let arr = input[this.iterateOn];
197
197
  arr = Array.isArray(arr) ? [...arr] : (0, type_utils_js_1.isNil)(arr) ? [arr] : [];
198
198
  const results = new Array(arr.length);
199
+ let error;
199
200
  const queue = fastq_1.default.promise(async ({ item, index }) => {
200
- if (!(0, type_utils_js_1.isRecord)(item))
201
- throw new TypeError(`Expected ${String(key)} to be an object, got ${typeof item}`);
202
- const o = await (0, agent_js_1.agentProcessResultToObject)(await this._processNonIterator({ ...input, [key]: arr, ...item }, { ...options, streaming: false }));
203
- const res = (0, type_utils_js_1.omit)(o, key);
204
- // Merge the item result with the original item used for next iteration
205
- if (this.iterateWithPreviousOutput) {
206
- arr = (0, immer_1.produce)(arr, (draft) => {
207
- const item = draft[index];
208
- (0, node_assert_1.default)(item);
209
- Object.assign(item, res);
210
- });
201
+ try {
202
+ if (!(0, type_utils_js_1.isRecord)(item))
203
+ throw new TypeError(`Expected ${String(key)} to be an object, got ${typeof item}`);
204
+ const o = await (0, agent_js_1.agentProcessResultToObject)(await this._processNonIterator({ ...input, [key]: arr, ...item }, { ...options, streaming: false }));
205
+ const res = (0, type_utils_js_1.omit)(o, key);
206
+ // Merge the item result with the original item used for next iteration
207
+ if (this.iterateWithPreviousOutput) {
208
+ arr = (0, immer_1.produce)(arr, (draft) => {
209
+ const item = draft[index];
210
+ (0, node_assert_1.default)(item);
211
+ Object.assign(item, res);
212
+ });
213
+ }
214
+ results[index] = res;
215
+ }
216
+ catch (e) {
217
+ error = e;
218
+ queue.killAndDrain();
211
219
  }
212
- results[index] = res;
213
220
  }, this.concurrency);
214
221
  for (let index = 0; index < arr.length; index++) {
215
222
  queue.push({ index, item: arr[index] });
216
223
  }
217
224
  await queue.drained();
225
+ if (error)
226
+ throw error;
218
227
  yield { delta: { json: { [key]: results } } };
219
228
  }
220
229
  _processNonIterator(input, options) {
@@ -163,7 +163,6 @@ export declare class AIGNEContext implements Context {
163
163
  get observer(): AIGNEObserver | undefined;
164
164
  get limits(): ContextLimits | undefined;
165
165
  get status(): "normal" | "timeout";
166
- get spans(): Span[];
167
166
  get usage(): ContextUsage;
168
167
  get userContext(): Context["userContext"];
169
168
  set userContext(userContext: Context["userContext"]);
@@ -181,7 +180,6 @@ export declare class AIGNEContext implements Context {
181
180
  subscribe: Context["subscribe"];
182
181
  unsubscribe: Context["unsubscribe"];
183
182
  emit<K extends keyof ContextEmitEventMap>(eventName: K, ...args: Args<K, ContextEmitEventMap>): boolean;
184
- private endAllSpans;
185
183
  private trace;
186
184
  on<K extends keyof ContextEventMap>(eventName: K, listener: Listener<K, ContextEventMap>): this;
187
185
  once<K extends keyof ContextEventMap>(eventName: K, listener: Listener<K, ContextEventMap>): this;
@@ -189,7 +187,6 @@ export declare class AIGNEContext implements Context {
189
187
  }
190
188
  declare class AIGNEContextShared {
191
189
  private readonly parent?;
192
- spans: Span[];
193
190
  constructor(parent?: (Pick<Context, "model" | "imageModel" | "agents" | "skills" | "limits" | "observer"> & {
194
191
  messageQueue?: MessageQueue;
195
192
  events?: Emitter<any>;
@@ -202,7 +199,6 @@ declare class AIGNEContextShared {
202
199
  get agents(): Agent<any, any>[];
203
200
  get observer(): AIGNEObserver | undefined;
204
201
  get limits(): ContextLimits | undefined;
205
- addSpan(span: Span): void;
206
202
  usage: ContextUsage;
207
203
  userContext: Context["userContext"];
208
204
  memories: Context["memories"];
@@ -45,9 +45,6 @@ class AIGNEContext {
45
45
  // 修改了 rootId 是否会之前的有影响?,之前为 this.id
46
46
  this.rootId = this.span?.spanContext?.().traceId ?? (0, uuid_1.v7)();
47
47
  }
48
- if (this.span) {
49
- this.internal.addSpan(this.span);
50
- }
51
48
  this.id = this.span?.spanContext()?.spanId ?? (0, uuid_1.v7)();
52
49
  }
53
50
  id;
@@ -79,9 +76,6 @@ class AIGNEContext {
79
76
  get status() {
80
77
  return this.internal.status;
81
78
  }
82
- get spans() {
83
- return this.internal.spans;
84
- }
85
79
  get usage() {
86
80
  return this.internal.usage;
87
81
  }
@@ -122,18 +116,12 @@ class AIGNEContext {
122
116
  const newContext = options?.newContext === false ? this : this.newContext();
123
117
  return Promise.resolve(newContext.internal.invoke(agent, message, newContext, options)).then(async (response) => {
124
118
  if (!options?.streaming) {
125
- try {
126
- let { __activeAgent__: activeAgent, ...output } = await (0, stream_utils_js_1.agentResponseStreamToObject)(response);
127
- output = await this.onInvocationResult(output, options);
128
- if (options?.returnActiveAgent) {
129
- return [output, activeAgent];
130
- }
131
- return output;
132
- }
133
- catch (error) {
134
- this.endAllSpans(error);
135
- throw error;
119
+ let { __activeAgent__: activeAgent, ...output } = await (0, stream_utils_js_1.agentResponseStreamToObject)(response);
120
+ output = await this.onInvocationResult(output, options);
121
+ if (options?.returnActiveAgent) {
122
+ return [output, activeAgent];
136
123
  }
124
+ return output;
137
125
  }
138
126
  const activeAgentPromise = (0, promise_js_1.promiseWithResolvers)();
139
127
  const stream = (0, stream_utils_js_1.onAgentResponseStreamEnd)((0, stream_utils_js_1.asyncGeneratorToReadableStream)(response), {
@@ -152,10 +140,6 @@ class AIGNEContext {
152
140
  activeAgentPromise.resolve(output.__activeAgent__);
153
141
  return await this.onInvocationResult(output, options);
154
142
  },
155
- onError: (error) => {
156
- this.endAllSpans(error);
157
- return error;
158
- },
159
143
  });
160
144
  const finalStream = !options.returnProgressChunks
161
145
  ? stream
@@ -217,12 +201,6 @@ class AIGNEContext {
217
201
  this.trace(eventName, args, b);
218
202
  return this.internal.events.emit(eventName, ...newArgs);
219
203
  }
220
- async endAllSpans(error) {
221
- this.spans.forEach((span) => {
222
- span.setStatus({ code: api_1.SpanStatusCode.ERROR, message: error?.message });
223
- span.end();
224
- });
225
- }
226
204
  async trace(eventName, args, b) {
227
205
  const span = this.span;
228
206
  if (!span)
@@ -298,7 +276,6 @@ class AIGNEContext {
298
276
  exports.AIGNEContext = AIGNEContext;
299
277
  class AIGNEContextShared {
300
278
  parent;
301
- spans = [];
302
279
  constructor(parent) {
303
280
  this.parent = parent;
304
281
  this.messageQueue = this.parent?.messageQueue ?? new message_queue_js_1.MessageQueue();
@@ -324,9 +301,6 @@ class AIGNEContextShared {
324
301
  get limits() {
325
302
  return this.parent?.limits;
326
303
  }
327
- addSpan(span) {
328
- this.spans.push(span);
329
- }
330
304
  usage = (0, usage_js_1.newEmptyContextUsage)();
331
305
  userContext = {};
332
306
  memories = [];
@@ -163,7 +163,6 @@ export declare class AIGNEContext implements Context {
163
163
  get observer(): AIGNEObserver | undefined;
164
164
  get limits(): ContextLimits | undefined;
165
165
  get status(): "normal" | "timeout";
166
- get spans(): Span[];
167
166
  get usage(): ContextUsage;
168
167
  get userContext(): Context["userContext"];
169
168
  set userContext(userContext: Context["userContext"]);
@@ -181,7 +180,6 @@ export declare class AIGNEContext implements Context {
181
180
  subscribe: Context["subscribe"];
182
181
  unsubscribe: Context["unsubscribe"];
183
182
  emit<K extends keyof ContextEmitEventMap>(eventName: K, ...args: Args<K, ContextEmitEventMap>): boolean;
184
- private endAllSpans;
185
183
  private trace;
186
184
  on<K extends keyof ContextEventMap>(eventName: K, listener: Listener<K, ContextEventMap>): this;
187
185
  once<K extends keyof ContextEventMap>(eventName: K, listener: Listener<K, ContextEventMap>): this;
@@ -189,7 +187,6 @@ export declare class AIGNEContext implements Context {
189
187
  }
190
188
  declare class AIGNEContextShared {
191
189
  private readonly parent?;
192
- spans: Span[];
193
190
  constructor(parent?: (Pick<Context, "model" | "imageModel" | "agents" | "skills" | "limits" | "observer"> & {
194
191
  messageQueue?: MessageQueue;
195
192
  events?: Emitter<any>;
@@ -202,7 +199,6 @@ declare class AIGNEContextShared {
202
199
  get agents(): Agent<any, any>[];
203
200
  get observer(): AIGNEObserver | undefined;
204
201
  get limits(): ContextLimits | undefined;
205
- addSpan(span: Span): void;
206
202
  usage: ContextUsage;
207
203
  userContext: Context["userContext"];
208
204
  memories: Context["memories"];
@@ -458,9 +458,6 @@ export class Agent {
458
458
  * @param options Invocation options
459
459
  */
460
460
  async processAgentError(input, error, options) {
461
- if ("$error_has_been_processed" in error && error.$error_has_been_processed)
462
- return {};
463
- Object.defineProperty(error, "$error_has_been_processed", { value: true, enumerable: false });
464
461
  logger.error("Invoke agent %s failed with error: %O", this.name, error);
465
462
  if (!this.disableEvents)
466
463
  options.context.emit("agentFailed", { agent: this, error });
@@ -190,25 +190,34 @@ export class TeamAgent extends Agent {
190
190
  let arr = input[this.iterateOn];
191
191
  arr = Array.isArray(arr) ? [...arr] : isNil(arr) ? [arr] : [];
192
192
  const results = new Array(arr.length);
193
+ let error;
193
194
  const queue = fastq.promise(async ({ item, index }) => {
194
- if (!isRecord(item))
195
- throw new TypeError(`Expected ${String(key)} to be an object, got ${typeof item}`);
196
- const o = await agentProcessResultToObject(await this._processNonIterator({ ...input, [key]: arr, ...item }, { ...options, streaming: false }));
197
- const res = omit(o, key);
198
- // Merge the item result with the original item used for next iteration
199
- if (this.iterateWithPreviousOutput) {
200
- arr = produce(arr, (draft) => {
201
- const item = draft[index];
202
- assert(item);
203
- Object.assign(item, res);
204
- });
195
+ try {
196
+ if (!isRecord(item))
197
+ throw new TypeError(`Expected ${String(key)} to be an object, got ${typeof item}`);
198
+ const o = await agentProcessResultToObject(await this._processNonIterator({ ...input, [key]: arr, ...item }, { ...options, streaming: false }));
199
+ const res = omit(o, key);
200
+ // Merge the item result with the original item used for next iteration
201
+ if (this.iterateWithPreviousOutput) {
202
+ arr = produce(arr, (draft) => {
203
+ const item = draft[index];
204
+ assert(item);
205
+ Object.assign(item, res);
206
+ });
207
+ }
208
+ results[index] = res;
209
+ }
210
+ catch (e) {
211
+ error = e;
212
+ queue.killAndDrain();
205
213
  }
206
- results[index] = res;
207
214
  }, this.concurrency);
208
215
  for (let index = 0; index < arr.length; index++) {
209
216
  queue.push({ index, item: arr[index] });
210
217
  }
211
218
  await queue.drained();
219
+ if (error)
220
+ throw error;
212
221
  yield { delta: { json: { [key]: results } } };
213
222
  }
214
223
  _processNonIterator(input, options) {
@@ -163,7 +163,6 @@ export declare class AIGNEContext implements Context {
163
163
  get observer(): AIGNEObserver | undefined;
164
164
  get limits(): ContextLimits | undefined;
165
165
  get status(): "normal" | "timeout";
166
- get spans(): Span[];
167
166
  get usage(): ContextUsage;
168
167
  get userContext(): Context["userContext"];
169
168
  set userContext(userContext: Context["userContext"]);
@@ -181,7 +180,6 @@ export declare class AIGNEContext implements Context {
181
180
  subscribe: Context["subscribe"];
182
181
  unsubscribe: Context["unsubscribe"];
183
182
  emit<K extends keyof ContextEmitEventMap>(eventName: K, ...args: Args<K, ContextEmitEventMap>): boolean;
184
- private endAllSpans;
185
183
  private trace;
186
184
  on<K extends keyof ContextEventMap>(eventName: K, listener: Listener<K, ContextEventMap>): this;
187
185
  once<K extends keyof ContextEventMap>(eventName: K, listener: Listener<K, ContextEventMap>): this;
@@ -189,7 +187,6 @@ export declare class AIGNEContext implements Context {
189
187
  }
190
188
  declare class AIGNEContextShared {
191
189
  private readonly parent?;
192
- spans: Span[];
193
190
  constructor(parent?: (Pick<Context, "model" | "imageModel" | "agents" | "skills" | "limits" | "observer"> & {
194
191
  messageQueue?: MessageQueue;
195
192
  events?: Emitter<any>;
@@ -202,7 +199,6 @@ declare class AIGNEContextShared {
202
199
  get agents(): Agent<any, any>[];
203
200
  get observer(): AIGNEObserver | undefined;
204
201
  get limits(): ContextLimits | undefined;
205
- addSpan(span: Span): void;
206
202
  usage: ContextUsage;
207
203
  userContext: Context["userContext"];
208
204
  memories: Context["memories"];
@@ -39,9 +39,6 @@ export class AIGNEContext {
39
39
  // 修改了 rootId 是否会之前的有影响?,之前为 this.id
40
40
  this.rootId = this.span?.spanContext?.().traceId ?? v7();
41
41
  }
42
- if (this.span) {
43
- this.internal.addSpan(this.span);
44
- }
45
42
  this.id = this.span?.spanContext()?.spanId ?? v7();
46
43
  }
47
44
  id;
@@ -73,9 +70,6 @@ export class AIGNEContext {
73
70
  get status() {
74
71
  return this.internal.status;
75
72
  }
76
- get spans() {
77
- return this.internal.spans;
78
- }
79
73
  get usage() {
80
74
  return this.internal.usage;
81
75
  }
@@ -116,18 +110,12 @@ export class AIGNEContext {
116
110
  const newContext = options?.newContext === false ? this : this.newContext();
117
111
  return Promise.resolve(newContext.internal.invoke(agent, message, newContext, options)).then(async (response) => {
118
112
  if (!options?.streaming) {
119
- try {
120
- let { __activeAgent__: activeAgent, ...output } = await agentResponseStreamToObject(response);
121
- output = await this.onInvocationResult(output, options);
122
- if (options?.returnActiveAgent) {
123
- return [output, activeAgent];
124
- }
125
- return output;
126
- }
127
- catch (error) {
128
- this.endAllSpans(error);
129
- throw error;
113
+ let { __activeAgent__: activeAgent, ...output } = await agentResponseStreamToObject(response);
114
+ output = await this.onInvocationResult(output, options);
115
+ if (options?.returnActiveAgent) {
116
+ return [output, activeAgent];
130
117
  }
118
+ return output;
131
119
  }
132
120
  const activeAgentPromise = promiseWithResolvers();
133
121
  const stream = onAgentResponseStreamEnd(asyncGeneratorToReadableStream(response), {
@@ -146,10 +134,6 @@ export class AIGNEContext {
146
134
  activeAgentPromise.resolve(output.__activeAgent__);
147
135
  return await this.onInvocationResult(output, options);
148
136
  },
149
- onError: (error) => {
150
- this.endAllSpans(error);
151
- return error;
152
- },
153
137
  });
154
138
  const finalStream = !options.returnProgressChunks
155
139
  ? stream
@@ -211,12 +195,6 @@ export class AIGNEContext {
211
195
  this.trace(eventName, args, b);
212
196
  return this.internal.events.emit(eventName, ...newArgs);
213
197
  }
214
- async endAllSpans(error) {
215
- this.spans.forEach((span) => {
216
- span.setStatus({ code: SpanStatusCode.ERROR, message: error?.message });
217
- span.end();
218
- });
219
- }
220
198
  async trace(eventName, args, b) {
221
199
  const span = this.span;
222
200
  if (!span)
@@ -291,7 +269,6 @@ export class AIGNEContext {
291
269
  }
292
270
  class AIGNEContextShared {
293
271
  parent;
294
- spans = [];
295
272
  constructor(parent) {
296
273
  this.parent = parent;
297
274
  this.messageQueue = this.parent?.messageQueue ?? new MessageQueue();
@@ -317,9 +294,6 @@ class AIGNEContextShared {
317
294
  get limits() {
318
295
  return this.parent?.limits;
319
296
  }
320
- addSpan(span) {
321
- this.spans.push(span);
322
- }
323
297
  usage = newEmptyContextUsage();
324
298
  userContext = {};
325
299
  memories = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aigne/core",
3
- "version": "1.55.0",
3
+ "version": "1.55.1",
4
4
  "description": "The functional core of agentic AI",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -89,7 +89,7 @@
89
89
  "yaml": "^2.8.0",
90
90
  "zod": "^3.25.67",
91
91
  "zod-to-json-schema": "^3.24.6",
92
- "@aigne/observability-api": "^0.10.0",
92
+ "@aigne/observability-api": "^0.10.1",
93
93
  "@aigne/platform-helpers": "^0.6.2"
94
94
  },
95
95
  "devDependencies": {