@aigne/core 1.54.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 +28 -0
- package/lib/cjs/agents/agent.js +0 -3
- package/lib/cjs/agents/team-agent.js +21 -12
- package/lib/cjs/aigne/context.d.ts +0 -4
- package/lib/cjs/aigne/context.js +5 -31
- package/lib/cjs/loader/agent-js.js +2 -34
- package/lib/dts/aigne/context.d.ts +0 -4
- package/lib/esm/agents/agent.js +0 -3
- package/lib/esm/agents/team-agent.js +21 -12
- package/lib/esm/aigne/context.d.ts +0 -4
- package/lib/esm/aigne/context.js +5 -31
- package/lib/esm/loader/agent-js.js +2 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,33 @@
|
|
|
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
|
+
|
|
17
|
+
## [1.55.0](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.54.0...core-v1.55.0) (2025-08-21)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Features
|
|
21
|
+
|
|
22
|
+
* **blocklet:** support agent runtime blocklet ([#396](https://github.com/AIGNE-io/aigne-framework/issues/396)) ([baaae69](https://github.com/AIGNE-io/aigne-framework/commit/baaae691d552b7c7d313c4964a135a1b245943f9))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Dependencies
|
|
26
|
+
|
|
27
|
+
* The following workspace dependencies were updated
|
|
28
|
+
* dependencies
|
|
29
|
+
* @aigne/observability-api bumped to 0.10.0
|
|
30
|
+
|
|
3
31
|
## [1.54.0](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.53.0...core-v1.54.0) (2025-08-21)
|
|
4
32
|
|
|
5
33
|
|
package/lib/cjs/agents/agent.js
CHANGED
|
@@ -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
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
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"];
|
package/lib/cjs/aigne/context.js
CHANGED
|
@@ -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
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
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 = [];
|
|
@@ -1,47 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
3
|
exports.loadAgentFromJsFile = loadAgentFromJsFile;
|
|
37
4
|
const ufo_1 = require("ufo");
|
|
38
5
|
const agent_js_1 = require("../agents/agent.js");
|
|
39
6
|
const type_utils_js_1 = require("../utils/type-utils.js");
|
|
40
7
|
const agent_yaml_js_1 = require("./agent-yaml.js");
|
|
8
|
+
const importFn = new Function("path", "return import(path)");
|
|
41
9
|
async function loadAgentFromJsFile(path, options) {
|
|
42
10
|
if (options?.key)
|
|
43
11
|
path = (0, ufo_1.withQuery)(path, { key: options?.key });
|
|
44
|
-
const { default: agent } = await (0, type_utils_js_1.tryOrThrow)(() =>
|
|
12
|
+
const { default: agent } = await (0, type_utils_js_1.tryOrThrow)(() => importFn(path), (error) => new Error(`Failed to load agent definition from ${path}: ${error.message}`));
|
|
45
13
|
if (agent instanceof agent_js_1.Agent)
|
|
46
14
|
return agent;
|
|
47
15
|
if (typeof agent !== "function") {
|
|
@@ -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"];
|
package/lib/esm/agents/agent.js
CHANGED
|
@@ -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
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
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"];
|
package/lib/esm/aigne/context.js
CHANGED
|
@@ -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
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
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 = [];
|
|
@@ -2,10 +2,11 @@ import { withQuery } from "ufo";
|
|
|
2
2
|
import { Agent } from "../agents/agent.js";
|
|
3
3
|
import { tryOrThrow } from "../utils/type-utils.js";
|
|
4
4
|
import { parseAgentFile } from "./agent-yaml.js";
|
|
5
|
+
const importFn = new Function("path", "return import(path)");
|
|
5
6
|
export async function loadAgentFromJsFile(path, options) {
|
|
6
7
|
if (options?.key)
|
|
7
8
|
path = withQuery(path, { key: options?.key });
|
|
8
|
-
const { default: agent } = await tryOrThrow(() =>
|
|
9
|
+
const { default: agent } = await tryOrThrow(() => importFn(path), (error) => new Error(`Failed to load agent definition from ${path}: ${error.message}`));
|
|
9
10
|
if (agent instanceof Agent)
|
|
10
11
|
return agent;
|
|
11
12
|
if (typeof agent !== "function") {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aigne/core",
|
|
3
|
-
"version": "1.
|
|
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.
|
|
92
|
+
"@aigne/observability-api": "^0.10.1",
|
|
93
93
|
"@aigne/platform-helpers": "^0.6.2"
|
|
94
94
|
},
|
|
95
95
|
"devDependencies": {
|