@aigne/core 1.44.0 → 1.46.0
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 +39 -0
- package/lib/cjs/agents/agent.d.ts +2 -0
- package/lib/cjs/agents/agent.js +3 -1
- package/lib/cjs/agents/mcp-agent.js +35 -5
- package/lib/cjs/agents/team-agent.d.ts +26 -0
- package/lib/cjs/agents/team-agent.js +26 -7
- package/lib/cjs/aigne/context.d.ts +6 -1
- package/lib/cjs/aigne/context.js +16 -9
- package/lib/cjs/loader/agent-yaml.d.ts +4 -0
- package/lib/cjs/loader/agent-yaml.js +4 -0
- package/lib/cjs/loader/schema.js +2 -5
- package/lib/cjs/utils/camelize.d.ts +1 -0
- package/lib/cjs/utils/camelize.js +21 -0
- package/lib/dts/agents/agent.d.ts +2 -0
- package/lib/dts/agents/team-agent.d.ts +26 -0
- package/lib/dts/aigne/context.d.ts +6 -1
- package/lib/dts/loader/agent-yaml.d.ts +4 -0
- package/lib/dts/utils/camelize.d.ts +1 -0
- package/lib/esm/agents/agent.d.ts +2 -0
- package/lib/esm/agents/agent.js +3 -1
- package/lib/esm/agents/mcp-agent.js +2 -2
- package/lib/esm/agents/team-agent.d.ts +26 -0
- package/lib/esm/agents/team-agent.js +26 -7
- package/lib/esm/aigne/context.d.ts +6 -1
- package/lib/esm/aigne/context.js +16 -9
- package/lib/esm/loader/agent-yaml.d.ts +4 -0
- package/lib/esm/loader/agent-yaml.js +4 -0
- package/lib/esm/loader/schema.js +1 -1
- package/lib/esm/utils/camelize.d.ts +1 -0
- package/lib/esm/utils/camelize.js +18 -0
- package/package.json +3 -5
package/CHANGELOG.md
CHANGED
|
@@ -12,6 +12,45 @@
|
|
|
12
12
|
* dependencies
|
|
13
13
|
* @aigne/observability bumped to 0.1.0
|
|
14
14
|
|
|
15
|
+
## [1.46.0](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.45.0...core-v1.46.0) (2025-08-06)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Features
|
|
19
|
+
|
|
20
|
+
* **cli:** support custom task title of agent in cli ([#328](https://github.com/AIGNE-io/aigne-framework/issues/328)) ([128d75f](https://github.com/AIGNE-io/aigne-framework/commit/128d75fb42ca470b47a2793d79c92d7bb64cfedb))
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
### Bug Fixes
|
|
24
|
+
|
|
25
|
+
* **core:** improve hook handling in agent and context ([#325](https://github.com/AIGNE-io/aigne-framework/issues/325)) ([c858fec](https://github.com/AIGNE-io/aigne-framework/commit/c858fecb08453c2daca9708f4b8a9c135fac40b0))
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
### Dependencies
|
|
29
|
+
|
|
30
|
+
* The following workspace dependencies were updated
|
|
31
|
+
* dependencies
|
|
32
|
+
* @aigne/platform-helpers bumped to 0.6.0
|
|
33
|
+
|
|
34
|
+
## [1.45.0](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.44.0...core-v1.45.0) (2025-08-06)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
### Features
|
|
38
|
+
|
|
39
|
+
* **core:** add concurrency support for team agent ([#323](https://github.com/AIGNE-io/aigne-framework/issues/323)) ([5743260](https://github.com/AIGNE-io/aigne-framework/commit/57432603a45208ad3503b9fc4c64f07c8151f9ee))
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
### Bug Fixes
|
|
43
|
+
|
|
44
|
+
* **core:** remove lodash dependency ensure core support both esm and cjs ([#324](https://github.com/AIGNE-io/aigne-framework/issues/324)) ([d6c2452](https://github.com/AIGNE-io/aigne-framework/commit/d6c2452b660a163c73f2c628ffdc2a12949360b0))
|
|
45
|
+
* **models:** aigne-hub adapter not working in node.js v21 ([#320](https://github.com/AIGNE-io/aigne-framework/issues/320)) ([2884d00](https://github.com/AIGNE-io/aigne-framework/commit/2884d00b83e153ae7465ef1369fcd22d7c6d43e0))
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
### Dependencies
|
|
49
|
+
|
|
50
|
+
* The following workspace dependencies were updated
|
|
51
|
+
* dependencies
|
|
52
|
+
* @aigne/platform-helpers bumped to 0.5.1
|
|
53
|
+
|
|
15
54
|
## [1.44.0](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.43.1...core-v1.44.0) (2025-08-05)
|
|
16
55
|
|
|
17
56
|
|
|
@@ -72,6 +72,7 @@ export interface AgentOptions<I extends Message = Message, O extends Message = M
|
|
|
72
72
|
* for documentation and debugging
|
|
73
73
|
*/
|
|
74
74
|
description?: string;
|
|
75
|
+
taskTitle?: string;
|
|
75
76
|
/**
|
|
76
77
|
* Zod schema defining the input message structure
|
|
77
78
|
*
|
|
@@ -256,6 +257,7 @@ export declare abstract class Agent<I extends Message = any, O extends Message =
|
|
|
256
257
|
* each other's roles in a multi-agent system
|
|
257
258
|
*/
|
|
258
259
|
readonly description?: string;
|
|
260
|
+
taskTitle?: string;
|
|
259
261
|
private readonly _inputSchema?;
|
|
260
262
|
defaultInput?: Partial<{
|
|
261
263
|
[key in keyof I]: {
|
package/lib/cjs/agents/agent.js
CHANGED
|
@@ -104,6 +104,7 @@ class Agent {
|
|
|
104
104
|
this.name = options.name || this.constructor.name;
|
|
105
105
|
this.alias = options.alias;
|
|
106
106
|
this.description = options.description;
|
|
107
|
+
this.taskTitle = options.taskTitle;
|
|
107
108
|
if (inputSchema)
|
|
108
109
|
checkAgentInputOutputSchema(inputSchema);
|
|
109
110
|
if (outputSchema)
|
|
@@ -193,6 +194,7 @@ class Agent {
|
|
|
193
194
|
* each other's roles in a multi-agent system
|
|
194
195
|
*/
|
|
195
196
|
description;
|
|
197
|
+
taskTitle;
|
|
196
198
|
_inputSchema;
|
|
197
199
|
defaultInput;
|
|
198
200
|
_outputSchema;
|
|
@@ -388,7 +390,7 @@ class Agent {
|
|
|
388
390
|
async callHooks(hook, input, options) {
|
|
389
391
|
const { context } = options;
|
|
390
392
|
const result = {};
|
|
391
|
-
for (const hooks of (0, type_utils_js_1.flat)(options.hooks, this.hooks)) {
|
|
393
|
+
for (const hooks of (0, type_utils_js_1.flat)(options.hooks, options.context.hooks, this.hooks)) {
|
|
392
394
|
const h = hooks[hook];
|
|
393
395
|
if (!h)
|
|
394
396
|
continue;
|
|
@@ -1,7 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
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
|
+
})();
|
|
5
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
36
|
exports.MCPResource = exports.MCPPrompt = exports.MCPTool = exports.MCPBase = exports.MCPAgent = void 0;
|
|
7
37
|
const stdio_client_transport_js_1 = require("@aigne/platform-helpers/mcp/stdio-client-transport.js");
|
|
@@ -10,7 +40,6 @@ const index_js_2 = require("@modelcontextprotocol/sdk/client/index.js");
|
|
|
10
40
|
const sse_js_1 = require("@modelcontextprotocol/sdk/client/sse.js");
|
|
11
41
|
const streamableHttp_js_1 = require("@modelcontextprotocol/sdk/client/streamableHttp.js");
|
|
12
42
|
const uriTemplate_js_1 = require("@modelcontextprotocol/sdk/shared/uriTemplate.js");
|
|
13
|
-
const p_retry_1 = __importDefault(require("p-retry"));
|
|
14
43
|
const zod_1 = require("zod");
|
|
15
44
|
const logger_js_1 = require("../utils/logger.js");
|
|
16
45
|
const mcp_utils_js_1 = require("../utils/mcp-utils.js");
|
|
@@ -222,7 +251,8 @@ class ClientWithReconnect extends index_js_2.Client {
|
|
|
222
251
|
const transportCreator = this.reconnectOptions?.transportCreator;
|
|
223
252
|
if (!transportCreator)
|
|
224
253
|
throw new Error("reconnect requires a transportCreator");
|
|
225
|
-
await (
|
|
254
|
+
const retry = await Promise.resolve().then(() => __importStar(require("p-retry")));
|
|
255
|
+
await retry.default(async () => {
|
|
226
256
|
await this.close();
|
|
227
257
|
await this.connect(await transportCreator(), {
|
|
228
258
|
timeout: this.reconnectOptions?.timeout ?? DEFAULT_TIMEOUT(),
|
|
@@ -137,6 +137,22 @@ export interface TeamAgentOptions<I extends Message, O extends Message> extends
|
|
|
137
137
|
* - The processing results are streamed incrementally as each iteration completes
|
|
138
138
|
*/
|
|
139
139
|
iterateOn?: keyof I;
|
|
140
|
+
/**
|
|
141
|
+
* The maximum number of concurrent operations when processing array items with `iterateOn`.
|
|
142
|
+
*
|
|
143
|
+
* This property controls how many array elements are processed simultaneously when
|
|
144
|
+
* iterating over an array field. A higher concurrency value allows for faster
|
|
145
|
+
* parallel processing but may consume more resources.
|
|
146
|
+
*
|
|
147
|
+
* @remarks
|
|
148
|
+
* - Only applies when `iterateOn` is specified
|
|
149
|
+
* - Cannot be used together with `iterateWithPreviousOutput` (concurrency > 1)
|
|
150
|
+
* - Uses a queue-based approach to limit concurrent operations
|
|
151
|
+
* - Each concurrent operation processes one array element through the entire agent workflow
|
|
152
|
+
*
|
|
153
|
+
* @default 1
|
|
154
|
+
*/
|
|
155
|
+
concurrency?: number;
|
|
140
156
|
/**
|
|
141
157
|
* Controls whether to merge the output from each iteration back into the array items
|
|
142
158
|
* for subsequent iterations when using `iterateOn`.
|
|
@@ -228,6 +244,16 @@ export declare class TeamAgent<I extends Message, O extends Message> extends Age
|
|
|
228
244
|
* @see TeamAgentOptions.iterateOn for detailed documentation
|
|
229
245
|
*/
|
|
230
246
|
iterateOn?: keyof I;
|
|
247
|
+
/**
|
|
248
|
+
* The maximum number of concurrent operations when processing array items.
|
|
249
|
+
*
|
|
250
|
+
* This property controls the concurrency level for iterative processing when `iterateOn`
|
|
251
|
+
* is used. It determines how many array elements are processed simultaneously.
|
|
252
|
+
*
|
|
253
|
+
* @see TeamAgentOptions.concurrency for detailed documentation
|
|
254
|
+
* @default 1
|
|
255
|
+
*/
|
|
256
|
+
concurrency: number;
|
|
231
257
|
/**
|
|
232
258
|
* Controls whether to merge the output from each iteration back into the array items
|
|
233
259
|
* for subsequent iterations when using `iterateOn`.
|
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.TeamAgent = exports.DEFAULT_REFLECTION_MAX_ITERATIONS = exports.ProcessMode = void 0;
|
|
7
7
|
const node_assert_1 = __importDefault(require("node:assert"));
|
|
8
|
+
const fastq_1 = __importDefault(require("fastq"));
|
|
8
9
|
const immer_1 = require("immer");
|
|
9
10
|
const stream_utils_js_1 = require("../utils/stream-utils.js");
|
|
10
11
|
const type_utils_js_1 = require("../utils/type-utils.js");
|
|
@@ -82,8 +83,12 @@ class TeamAgent extends agent_js_1.Agent {
|
|
|
82
83
|
maxIterations: options.reflection.maxIterations ?? exports.DEFAULT_REFLECTION_MAX_ITERATIONS,
|
|
83
84
|
};
|
|
84
85
|
this.iterateOn = options.iterateOn;
|
|
86
|
+
this.concurrency = options.concurrency ?? 1;
|
|
85
87
|
this.iterateWithPreviousOutput = options.iterateWithPreviousOutput;
|
|
86
88
|
this.includeAllStepsOutput = options.includeAllStepsOutput;
|
|
89
|
+
if (this.concurrency !== 1 && this.iterateWithPreviousOutput) {
|
|
90
|
+
throw new Error(`iterateWithPreviousOutput cannot be used with concurrency > 1, concurrency: ${this.concurrency}`);
|
|
91
|
+
}
|
|
87
92
|
}
|
|
88
93
|
/**
|
|
89
94
|
* The processing mode that determines how agents in the team are executed.
|
|
@@ -109,6 +114,16 @@ class TeamAgent extends agent_js_1.Agent {
|
|
|
109
114
|
* @see TeamAgentOptions.iterateOn for detailed documentation
|
|
110
115
|
*/
|
|
111
116
|
iterateOn;
|
|
117
|
+
/**
|
|
118
|
+
* The maximum number of concurrent operations when processing array items.
|
|
119
|
+
*
|
|
120
|
+
* This property controls the concurrency level for iterative processing when `iterateOn`
|
|
121
|
+
* is used. It determines how many array elements are processed simultaneously.
|
|
122
|
+
*
|
|
123
|
+
* @see TeamAgentOptions.concurrency for detailed documentation
|
|
124
|
+
* @default 1
|
|
125
|
+
*/
|
|
126
|
+
concurrency;
|
|
112
127
|
/**
|
|
113
128
|
* Controls whether to merge the output from each iteration back into the array items
|
|
114
129
|
* for subsequent iterations when using `iterateOn`.
|
|
@@ -180,23 +195,27 @@ class TeamAgent extends agent_js_1.Agent {
|
|
|
180
195
|
(0, node_assert_1.default)(this.iterateOn, "iterateInputKey must be defined for iterator processing");
|
|
181
196
|
let arr = input[this.iterateOn];
|
|
182
197
|
arr = Array.isArray(arr) ? [...arr] : (0, type_utils_js_1.isNil)(arr) ? [arr] : [];
|
|
183
|
-
const
|
|
184
|
-
|
|
185
|
-
const item = arr[i];
|
|
198
|
+
const results = new Array(arr.length);
|
|
199
|
+
const queue = fastq_1.default.promise(async ({ item, index }) => {
|
|
186
200
|
if (!(0, type_utils_js_1.isRecord)(item))
|
|
187
201
|
throw new TypeError(`Expected ${String(key)} to be an object, got ${typeof item}`);
|
|
188
|
-
const
|
|
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);
|
|
189
204
|
// Merge the item result with the original item used for next iteration
|
|
190
205
|
if (this.iterateWithPreviousOutput) {
|
|
191
206
|
arr = (0, immer_1.produce)(arr, (draft) => {
|
|
192
|
-
const item = draft[
|
|
207
|
+
const item = draft[index];
|
|
193
208
|
(0, node_assert_1.default)(item);
|
|
194
209
|
Object.assign(item, res);
|
|
195
210
|
});
|
|
196
211
|
}
|
|
197
|
-
|
|
198
|
-
|
|
212
|
+
results[index] = res;
|
|
213
|
+
}, this.concurrency);
|
|
214
|
+
for (let index = 0; index < arr.length; index++) {
|
|
215
|
+
queue.push({ index, item: arr[index] });
|
|
199
216
|
}
|
|
217
|
+
await queue.drained();
|
|
218
|
+
yield { delta: { json: { [key]: results } } };
|
|
200
219
|
}
|
|
201
220
|
_processNonIterator(input, options) {
|
|
202
221
|
switch (this.mode) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { AIGNEObserver } from "@aigne/observability-api";
|
|
2
2
|
import type { Span } from "@opentelemetry/api";
|
|
3
3
|
import { Emitter } from "strict-event-emitter";
|
|
4
|
-
import { type Agent, type AgentInvokeOptions, type AgentProcessAsyncGenerator, type AgentResponse, type AgentResponseStream, type Message } from "../agents/agent.js";
|
|
4
|
+
import { type Agent, type AgentHooks, type AgentInvokeOptions, type AgentProcessAsyncGenerator, type AgentResponse, type AgentResponseStream, type Message } from "../agents/agent.js";
|
|
5
5
|
import type { ChatModel } from "../agents/chat-model.js";
|
|
6
6
|
import { UserAgent } from "../agents/user-agent.js";
|
|
7
7
|
import type { Memory } from "../memory/memory.js";
|
|
@@ -80,6 +80,7 @@ export interface Context<U extends UserContext = UserContext> extends TypedEvent
|
|
|
80
80
|
limits?: ContextLimits;
|
|
81
81
|
status?: "normal" | "timeout";
|
|
82
82
|
userContext: U;
|
|
83
|
+
hooks?: AgentHooks[];
|
|
83
84
|
memories: Pick<Memory, "content">[];
|
|
84
85
|
/**
|
|
85
86
|
* Create a user agent to consistently invoke an agent
|
|
@@ -164,11 +165,14 @@ export declare class AIGNEContext implements Context {
|
|
|
164
165
|
set userContext(userContext: Context["userContext"]);
|
|
165
166
|
get memories(): Context["memories"];
|
|
166
167
|
set memories(memories: Context["memories"]);
|
|
168
|
+
get hooks(): AgentHooks[];
|
|
169
|
+
set hooks(hooks: AgentHooks[]);
|
|
167
170
|
newContext({ reset }?: {
|
|
168
171
|
reset?: boolean;
|
|
169
172
|
}): AIGNEContext;
|
|
170
173
|
invoke: Context["invoke"];
|
|
171
174
|
private onInvocationResult;
|
|
175
|
+
private processOptions;
|
|
172
176
|
publish: Context["publish"];
|
|
173
177
|
subscribe: Context["subscribe"];
|
|
174
178
|
unsubscribe: Context["unsubscribe"];
|
|
@@ -197,6 +201,7 @@ declare class AIGNEContextShared {
|
|
|
197
201
|
usage: ContextUsage;
|
|
198
202
|
userContext: Context["userContext"];
|
|
199
203
|
memories: Context["memories"];
|
|
204
|
+
hooks: AgentHooks[];
|
|
200
205
|
private abortController;
|
|
201
206
|
private timer?;
|
|
202
207
|
private initTimeout;
|
package/lib/cjs/aigne/context.js
CHANGED
|
@@ -94,6 +94,12 @@ class AIGNEContext {
|
|
|
94
94
|
set memories(memories) {
|
|
95
95
|
this.internal.memories = memories;
|
|
96
96
|
}
|
|
97
|
+
get hooks() {
|
|
98
|
+
return this.internal.hooks;
|
|
99
|
+
}
|
|
100
|
+
set hooks(hooks) {
|
|
101
|
+
this.internal.hooks = hooks;
|
|
102
|
+
}
|
|
97
103
|
newContext({ reset } = {}) {
|
|
98
104
|
return new AIGNEContext(this, { reset });
|
|
99
105
|
}
|
|
@@ -103,14 +109,7 @@ class AIGNEContext {
|
|
|
103
109
|
message,
|
|
104
110
|
options,
|
|
105
111
|
});
|
|
106
|
-
|
|
107
|
-
Object.assign(this.userContext, options.userContext);
|
|
108
|
-
options.userContext = undefined;
|
|
109
|
-
}
|
|
110
|
-
if (options?.memories?.length) {
|
|
111
|
-
this.memories.push(...options.memories);
|
|
112
|
-
options.memories = undefined;
|
|
113
|
-
}
|
|
112
|
+
this.processOptions(options);
|
|
114
113
|
if ((0, type_utils_js_1.isNil)(message)) {
|
|
115
114
|
return user_agent_js_1.UserAgent.from({
|
|
116
115
|
context: this,
|
|
@@ -176,7 +175,7 @@ class AIGNEContext {
|
|
|
176
175
|
},
|
|
177
176
|
};
|
|
178
177
|
}
|
|
179
|
-
|
|
178
|
+
processOptions(options) {
|
|
180
179
|
if (options?.userContext) {
|
|
181
180
|
Object.assign(this.userContext, options.userContext);
|
|
182
181
|
options.userContext = undefined;
|
|
@@ -185,6 +184,13 @@ class AIGNEContext {
|
|
|
185
184
|
this.memories.push(...options.memories);
|
|
186
185
|
options.memories = undefined;
|
|
187
186
|
}
|
|
187
|
+
if (options?.hooks) {
|
|
188
|
+
this.hooks.push(...(0, type_utils_js_1.flat)(options.hooks));
|
|
189
|
+
options.hooks = undefined;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
publish = ((topic, payload, options) => {
|
|
193
|
+
this.processOptions(options);
|
|
188
194
|
const newContext = options?.newContext === false ? this : this.newContext();
|
|
189
195
|
return this.internal.messageQueue.publish(topic, {
|
|
190
196
|
...(0, message_queue_js_1.toMessagePayload)(payload),
|
|
@@ -318,6 +324,7 @@ class AIGNEContextShared {
|
|
|
318
324
|
usage = (0, usage_js_1.newEmptyContextUsage)();
|
|
319
325
|
userContext = {};
|
|
320
326
|
memories = [];
|
|
327
|
+
hooks = [];
|
|
321
328
|
abortController = new AbortController();
|
|
322
329
|
timer;
|
|
323
330
|
initTimeout() {
|
|
@@ -19,6 +19,7 @@ export type NestAgentSchema = string | {
|
|
|
19
19
|
export interface BaseAgentSchema {
|
|
20
20
|
name?: string;
|
|
21
21
|
description?: string;
|
|
22
|
+
taskTitle?: string;
|
|
22
23
|
inputSchema?: ZodType<Record<string, any>>;
|
|
23
24
|
defaultInput?: Record<string, any>;
|
|
24
25
|
outputSchema?: ZodType<Record<string, any>>;
|
|
@@ -46,6 +47,9 @@ export interface TeamAgentSchema extends BaseAgentSchema {
|
|
|
46
47
|
type: "team";
|
|
47
48
|
mode?: ProcessMode;
|
|
48
49
|
iterateOn?: string;
|
|
50
|
+
concurrency?: number;
|
|
51
|
+
iterateWithPreviousOutput?: boolean;
|
|
52
|
+
includeAllStepsOutput?: boolean;
|
|
49
53
|
reflection?: Omit<ReflectionMode, "reviewer"> & {
|
|
50
54
|
reviewer: NestAgentSchema;
|
|
51
55
|
};
|
|
@@ -34,6 +34,7 @@ async function parseAgentFile(path, data) {
|
|
|
34
34
|
name: (0, schema_js_1.optionalize)(zod_1.z.string()),
|
|
35
35
|
alias: (0, schema_js_1.optionalize)(zod_1.z.array(zod_1.z.string())),
|
|
36
36
|
description: (0, schema_js_1.optionalize)(zod_1.z.string()),
|
|
37
|
+
taskTitle: (0, schema_js_1.optionalize)(zod_1.z.string()),
|
|
37
38
|
inputSchema: (0, schema_js_1.optionalize)((0, schema_js_1.inputOutputSchema)({ path })).transform((v) => v ? (0, json_schema_to_zod_1.jsonSchemaToZod)(v) : undefined),
|
|
38
39
|
defaultInput: (0, schema_js_1.optionalize)(schema_js_1.defaultInputSchema),
|
|
39
40
|
outputSchema: (0, schema_js_1.optionalize)((0, schema_js_1.inputOutputSchema)({ path })).transform((v) => v ? (0, json_schema_to_zod_1.jsonSchemaToZod)(v) : undefined),
|
|
@@ -78,6 +79,9 @@ async function parseAgentFile(path, data) {
|
|
|
78
79
|
type: zod_1.z.literal("team"),
|
|
79
80
|
mode: (0, schema_js_1.optionalize)(zod_1.z.nativeEnum(team_agent_js_1.ProcessMode)),
|
|
80
81
|
iterateOn: (0, schema_js_1.optionalize)(zod_1.z.string()),
|
|
82
|
+
concurrency: (0, schema_js_1.optionalize)(zod_1.z.number().int().min(1)),
|
|
83
|
+
iterateWithPreviousOutput: (0, schema_js_1.optionalize)(zod_1.z.boolean()),
|
|
84
|
+
includeAllStepsOutput: (0, schema_js_1.optionalize)(zod_1.z.boolean()),
|
|
81
85
|
reflection: (0, schema_js_1.camelizeSchema)((0, schema_js_1.optionalize)(zod_1.z.object({
|
|
82
86
|
reviewer: nestAgentSchema,
|
|
83
87
|
isApproved: zod_1.z.string(),
|
package/lib/cjs/loader/schema.js
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.defaultInputSchema = exports.inputOutputSchema = void 0;
|
|
7
4
|
exports.optionalize = optionalize;
|
|
8
5
|
exports.camelizeSchema = camelizeSchema;
|
|
9
6
|
const index_js_1 = require("@aigne/platform-helpers/nodejs/index.js");
|
|
10
|
-
const camelize_ts_1 = __importDefault(require("camelize-ts"));
|
|
11
7
|
const yaml_1 = require("yaml");
|
|
12
8
|
const zod_1 = require("zod");
|
|
13
9
|
const agent_js_1 = require("../agents/agent.js");
|
|
10
|
+
const camelize_js_1 = require("../utils/camelize.js");
|
|
14
11
|
const type_utils_js_1 = require("../utils/type-utils.js");
|
|
15
12
|
const inputOutputSchema = ({ path }) => {
|
|
16
13
|
const includeExternalSchema = async (schema) => {
|
|
@@ -67,5 +64,5 @@ function optionalize(schema) {
|
|
|
67
64
|
return schema.nullish().transform((v) => v ?? undefined);
|
|
68
65
|
}
|
|
69
66
|
function camelizeSchema(schema, { shallow = true } = {}) {
|
|
70
|
-
return zod_1.z.preprocess((v) => ((0, type_utils_js_1.isRecord)(v) ? (0,
|
|
67
|
+
return zod_1.z.preprocess((v) => ((0, type_utils_js_1.isRecord)(v) ? (0, camelize_js_1.camelize)(v, shallow) : v), schema);
|
|
71
68
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function camelize<T>(obj: T, shallow?: boolean): any;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.camelize = camelize;
|
|
4
|
+
const type_utils_js_1 = require("./type-utils.js");
|
|
5
|
+
function camelize(obj, shallow = false) {
|
|
6
|
+
if (Array.isArray(obj)) {
|
|
7
|
+
return shallow ? obj : obj.map((item) => camelize(item, false));
|
|
8
|
+
}
|
|
9
|
+
if ((0, type_utils_js_1.isRecord)(obj)) {
|
|
10
|
+
return Object.fromEntries(Object.entries(obj).map(([key, value]) => [
|
|
11
|
+
camelCase(key),
|
|
12
|
+
shallow ? value : camelize(value, false),
|
|
13
|
+
]));
|
|
14
|
+
}
|
|
15
|
+
return obj;
|
|
16
|
+
}
|
|
17
|
+
function camelCase(key) {
|
|
18
|
+
key = key.replace(/[-_#@$\s]+(.)?/g, (_, char) => char.toUpperCase());
|
|
19
|
+
key = key.charAt(0).toLowerCase() + key.slice(1);
|
|
20
|
+
return key;
|
|
21
|
+
}
|
|
@@ -72,6 +72,7 @@ export interface AgentOptions<I extends Message = Message, O extends Message = M
|
|
|
72
72
|
* for documentation and debugging
|
|
73
73
|
*/
|
|
74
74
|
description?: string;
|
|
75
|
+
taskTitle?: string;
|
|
75
76
|
/**
|
|
76
77
|
* Zod schema defining the input message structure
|
|
77
78
|
*
|
|
@@ -256,6 +257,7 @@ export declare abstract class Agent<I extends Message = any, O extends Message =
|
|
|
256
257
|
* each other's roles in a multi-agent system
|
|
257
258
|
*/
|
|
258
259
|
readonly description?: string;
|
|
260
|
+
taskTitle?: string;
|
|
259
261
|
private readonly _inputSchema?;
|
|
260
262
|
defaultInput?: Partial<{
|
|
261
263
|
[key in keyof I]: {
|
|
@@ -137,6 +137,22 @@ export interface TeamAgentOptions<I extends Message, O extends Message> extends
|
|
|
137
137
|
* - The processing results are streamed incrementally as each iteration completes
|
|
138
138
|
*/
|
|
139
139
|
iterateOn?: keyof I;
|
|
140
|
+
/**
|
|
141
|
+
* The maximum number of concurrent operations when processing array items with `iterateOn`.
|
|
142
|
+
*
|
|
143
|
+
* This property controls how many array elements are processed simultaneously when
|
|
144
|
+
* iterating over an array field. A higher concurrency value allows for faster
|
|
145
|
+
* parallel processing but may consume more resources.
|
|
146
|
+
*
|
|
147
|
+
* @remarks
|
|
148
|
+
* - Only applies when `iterateOn` is specified
|
|
149
|
+
* - Cannot be used together with `iterateWithPreviousOutput` (concurrency > 1)
|
|
150
|
+
* - Uses a queue-based approach to limit concurrent operations
|
|
151
|
+
* - Each concurrent operation processes one array element through the entire agent workflow
|
|
152
|
+
*
|
|
153
|
+
* @default 1
|
|
154
|
+
*/
|
|
155
|
+
concurrency?: number;
|
|
140
156
|
/**
|
|
141
157
|
* Controls whether to merge the output from each iteration back into the array items
|
|
142
158
|
* for subsequent iterations when using `iterateOn`.
|
|
@@ -228,6 +244,16 @@ export declare class TeamAgent<I extends Message, O extends Message> extends Age
|
|
|
228
244
|
* @see TeamAgentOptions.iterateOn for detailed documentation
|
|
229
245
|
*/
|
|
230
246
|
iterateOn?: keyof I;
|
|
247
|
+
/**
|
|
248
|
+
* The maximum number of concurrent operations when processing array items.
|
|
249
|
+
*
|
|
250
|
+
* This property controls the concurrency level for iterative processing when `iterateOn`
|
|
251
|
+
* is used. It determines how many array elements are processed simultaneously.
|
|
252
|
+
*
|
|
253
|
+
* @see TeamAgentOptions.concurrency for detailed documentation
|
|
254
|
+
* @default 1
|
|
255
|
+
*/
|
|
256
|
+
concurrency: number;
|
|
231
257
|
/**
|
|
232
258
|
* Controls whether to merge the output from each iteration back into the array items
|
|
233
259
|
* for subsequent iterations when using `iterateOn`.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { AIGNEObserver } from "@aigne/observability-api";
|
|
2
2
|
import type { Span } from "@opentelemetry/api";
|
|
3
3
|
import { Emitter } from "strict-event-emitter";
|
|
4
|
-
import { type Agent, type AgentInvokeOptions, type AgentProcessAsyncGenerator, type AgentResponse, type AgentResponseStream, type Message } from "../agents/agent.js";
|
|
4
|
+
import { type Agent, type AgentHooks, type AgentInvokeOptions, type AgentProcessAsyncGenerator, type AgentResponse, type AgentResponseStream, type Message } from "../agents/agent.js";
|
|
5
5
|
import type { ChatModel } from "../agents/chat-model.js";
|
|
6
6
|
import { UserAgent } from "../agents/user-agent.js";
|
|
7
7
|
import type { Memory } from "../memory/memory.js";
|
|
@@ -80,6 +80,7 @@ export interface Context<U extends UserContext = UserContext> extends TypedEvent
|
|
|
80
80
|
limits?: ContextLimits;
|
|
81
81
|
status?: "normal" | "timeout";
|
|
82
82
|
userContext: U;
|
|
83
|
+
hooks?: AgentHooks[];
|
|
83
84
|
memories: Pick<Memory, "content">[];
|
|
84
85
|
/**
|
|
85
86
|
* Create a user agent to consistently invoke an agent
|
|
@@ -164,11 +165,14 @@ export declare class AIGNEContext implements Context {
|
|
|
164
165
|
set userContext(userContext: Context["userContext"]);
|
|
165
166
|
get memories(): Context["memories"];
|
|
166
167
|
set memories(memories: Context["memories"]);
|
|
168
|
+
get hooks(): AgentHooks[];
|
|
169
|
+
set hooks(hooks: AgentHooks[]);
|
|
167
170
|
newContext({ reset }?: {
|
|
168
171
|
reset?: boolean;
|
|
169
172
|
}): AIGNEContext;
|
|
170
173
|
invoke: Context["invoke"];
|
|
171
174
|
private onInvocationResult;
|
|
175
|
+
private processOptions;
|
|
172
176
|
publish: Context["publish"];
|
|
173
177
|
subscribe: Context["subscribe"];
|
|
174
178
|
unsubscribe: Context["unsubscribe"];
|
|
@@ -197,6 +201,7 @@ declare class AIGNEContextShared {
|
|
|
197
201
|
usage: ContextUsage;
|
|
198
202
|
userContext: Context["userContext"];
|
|
199
203
|
memories: Context["memories"];
|
|
204
|
+
hooks: AgentHooks[];
|
|
200
205
|
private abortController;
|
|
201
206
|
private timer?;
|
|
202
207
|
private initTimeout;
|
|
@@ -19,6 +19,7 @@ export type NestAgentSchema = string | {
|
|
|
19
19
|
export interface BaseAgentSchema {
|
|
20
20
|
name?: string;
|
|
21
21
|
description?: string;
|
|
22
|
+
taskTitle?: string;
|
|
22
23
|
inputSchema?: ZodType<Record<string, any>>;
|
|
23
24
|
defaultInput?: Record<string, any>;
|
|
24
25
|
outputSchema?: ZodType<Record<string, any>>;
|
|
@@ -46,6 +47,9 @@ export interface TeamAgentSchema extends BaseAgentSchema {
|
|
|
46
47
|
type: "team";
|
|
47
48
|
mode?: ProcessMode;
|
|
48
49
|
iterateOn?: string;
|
|
50
|
+
concurrency?: number;
|
|
51
|
+
iterateWithPreviousOutput?: boolean;
|
|
52
|
+
includeAllStepsOutput?: boolean;
|
|
49
53
|
reflection?: Omit<ReflectionMode, "reviewer"> & {
|
|
50
54
|
reviewer: NestAgentSchema;
|
|
51
55
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function camelize<T>(obj: T, shallow?: boolean): any;
|
|
@@ -72,6 +72,7 @@ export interface AgentOptions<I extends Message = Message, O extends Message = M
|
|
|
72
72
|
* for documentation and debugging
|
|
73
73
|
*/
|
|
74
74
|
description?: string;
|
|
75
|
+
taskTitle?: string;
|
|
75
76
|
/**
|
|
76
77
|
* Zod schema defining the input message structure
|
|
77
78
|
*
|
|
@@ -256,6 +257,7 @@ export declare abstract class Agent<I extends Message = any, O extends Message =
|
|
|
256
257
|
* each other's roles in a multi-agent system
|
|
257
258
|
*/
|
|
258
259
|
readonly description?: string;
|
|
260
|
+
taskTitle?: string;
|
|
259
261
|
private readonly _inputSchema?;
|
|
260
262
|
defaultInput?: Partial<{
|
|
261
263
|
[key in keyof I]: {
|
package/lib/esm/agents/agent.js
CHANGED
|
@@ -59,6 +59,7 @@ export class Agent {
|
|
|
59
59
|
this.name = options.name || this.constructor.name;
|
|
60
60
|
this.alias = options.alias;
|
|
61
61
|
this.description = options.description;
|
|
62
|
+
this.taskTitle = options.taskTitle;
|
|
62
63
|
if (inputSchema)
|
|
63
64
|
checkAgentInputOutputSchema(inputSchema);
|
|
64
65
|
if (outputSchema)
|
|
@@ -148,6 +149,7 @@ export class Agent {
|
|
|
148
149
|
* each other's roles in a multi-agent system
|
|
149
150
|
*/
|
|
150
151
|
description;
|
|
152
|
+
taskTitle;
|
|
151
153
|
_inputSchema;
|
|
152
154
|
defaultInput;
|
|
153
155
|
_outputSchema;
|
|
@@ -343,7 +345,7 @@ export class Agent {
|
|
|
343
345
|
async callHooks(hook, input, options) {
|
|
344
346
|
const { context } = options;
|
|
345
347
|
const result = {};
|
|
346
|
-
for (const hooks of flat(options.hooks, this.hooks)) {
|
|
348
|
+
for (const hooks of flat(options.hooks, options.context.hooks, this.hooks)) {
|
|
347
349
|
const h = hooks[hook];
|
|
348
350
|
if (!h)
|
|
349
351
|
continue;
|
|
@@ -4,7 +4,6 @@ import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
|
4
4
|
import { SSEClientTransport, } from "@modelcontextprotocol/sdk/client/sse.js";
|
|
5
5
|
import { StreamableHTTPClientTransport, } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
6
6
|
import { UriTemplate } from "@modelcontextprotocol/sdk/shared/uriTemplate.js";
|
|
7
|
-
import pRetry from "p-retry";
|
|
8
7
|
import { z } from "zod";
|
|
9
8
|
import { logger } from "../utils/logger.js";
|
|
10
9
|
import { promptFromMCPPrompt, resourceFromMCPResource, toolFromMCPTool, } from "../utils/mcp-utils.js";
|
|
@@ -215,7 +214,8 @@ class ClientWithReconnect extends Client {
|
|
|
215
214
|
const transportCreator = this.reconnectOptions?.transportCreator;
|
|
216
215
|
if (!transportCreator)
|
|
217
216
|
throw new Error("reconnect requires a transportCreator");
|
|
218
|
-
await
|
|
217
|
+
const retry = await import("p-retry");
|
|
218
|
+
await retry.default(async () => {
|
|
219
219
|
await this.close();
|
|
220
220
|
await this.connect(await transportCreator(), {
|
|
221
221
|
timeout: this.reconnectOptions?.timeout ?? DEFAULT_TIMEOUT(),
|
|
@@ -137,6 +137,22 @@ export interface TeamAgentOptions<I extends Message, O extends Message> extends
|
|
|
137
137
|
* - The processing results are streamed incrementally as each iteration completes
|
|
138
138
|
*/
|
|
139
139
|
iterateOn?: keyof I;
|
|
140
|
+
/**
|
|
141
|
+
* The maximum number of concurrent operations when processing array items with `iterateOn`.
|
|
142
|
+
*
|
|
143
|
+
* This property controls how many array elements are processed simultaneously when
|
|
144
|
+
* iterating over an array field. A higher concurrency value allows for faster
|
|
145
|
+
* parallel processing but may consume more resources.
|
|
146
|
+
*
|
|
147
|
+
* @remarks
|
|
148
|
+
* - Only applies when `iterateOn` is specified
|
|
149
|
+
* - Cannot be used together with `iterateWithPreviousOutput` (concurrency > 1)
|
|
150
|
+
* - Uses a queue-based approach to limit concurrent operations
|
|
151
|
+
* - Each concurrent operation processes one array element through the entire agent workflow
|
|
152
|
+
*
|
|
153
|
+
* @default 1
|
|
154
|
+
*/
|
|
155
|
+
concurrency?: number;
|
|
140
156
|
/**
|
|
141
157
|
* Controls whether to merge the output from each iteration back into the array items
|
|
142
158
|
* for subsequent iterations when using `iterateOn`.
|
|
@@ -228,6 +244,16 @@ export declare class TeamAgent<I extends Message, O extends Message> extends Age
|
|
|
228
244
|
* @see TeamAgentOptions.iterateOn for detailed documentation
|
|
229
245
|
*/
|
|
230
246
|
iterateOn?: keyof I;
|
|
247
|
+
/**
|
|
248
|
+
* The maximum number of concurrent operations when processing array items.
|
|
249
|
+
*
|
|
250
|
+
* This property controls the concurrency level for iterative processing when `iterateOn`
|
|
251
|
+
* is used. It determines how many array elements are processed simultaneously.
|
|
252
|
+
*
|
|
253
|
+
* @see TeamAgentOptions.concurrency for detailed documentation
|
|
254
|
+
* @default 1
|
|
255
|
+
*/
|
|
256
|
+
concurrency: number;
|
|
231
257
|
/**
|
|
232
258
|
* Controls whether to merge the output from each iteration back into the array items
|
|
233
259
|
* for subsequent iterations when using `iterateOn`.
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import assert from "node:assert";
|
|
2
|
+
import fastq from "fastq";
|
|
2
3
|
import { produce } from "immer";
|
|
3
4
|
import { mergeAgentResponseChunk } from "../utils/stream-utils.js";
|
|
4
5
|
import { isEmpty, isNil, isRecord, omit } from "../utils/type-utils.js";
|
|
@@ -76,8 +77,12 @@ export class TeamAgent extends Agent {
|
|
|
76
77
|
maxIterations: options.reflection.maxIterations ?? DEFAULT_REFLECTION_MAX_ITERATIONS,
|
|
77
78
|
};
|
|
78
79
|
this.iterateOn = options.iterateOn;
|
|
80
|
+
this.concurrency = options.concurrency ?? 1;
|
|
79
81
|
this.iterateWithPreviousOutput = options.iterateWithPreviousOutput;
|
|
80
82
|
this.includeAllStepsOutput = options.includeAllStepsOutput;
|
|
83
|
+
if (this.concurrency !== 1 && this.iterateWithPreviousOutput) {
|
|
84
|
+
throw new Error(`iterateWithPreviousOutput cannot be used with concurrency > 1, concurrency: ${this.concurrency}`);
|
|
85
|
+
}
|
|
81
86
|
}
|
|
82
87
|
/**
|
|
83
88
|
* The processing mode that determines how agents in the team are executed.
|
|
@@ -103,6 +108,16 @@ export class TeamAgent extends Agent {
|
|
|
103
108
|
* @see TeamAgentOptions.iterateOn for detailed documentation
|
|
104
109
|
*/
|
|
105
110
|
iterateOn;
|
|
111
|
+
/**
|
|
112
|
+
* The maximum number of concurrent operations when processing array items.
|
|
113
|
+
*
|
|
114
|
+
* This property controls the concurrency level for iterative processing when `iterateOn`
|
|
115
|
+
* is used. It determines how many array elements are processed simultaneously.
|
|
116
|
+
*
|
|
117
|
+
* @see TeamAgentOptions.concurrency for detailed documentation
|
|
118
|
+
* @default 1
|
|
119
|
+
*/
|
|
120
|
+
concurrency;
|
|
106
121
|
/**
|
|
107
122
|
* Controls whether to merge the output from each iteration back into the array items
|
|
108
123
|
* for subsequent iterations when using `iterateOn`.
|
|
@@ -174,23 +189,27 @@ export class TeamAgent extends Agent {
|
|
|
174
189
|
assert(this.iterateOn, "iterateInputKey must be defined for iterator processing");
|
|
175
190
|
let arr = input[this.iterateOn];
|
|
176
191
|
arr = Array.isArray(arr) ? [...arr] : isNil(arr) ? [arr] : [];
|
|
177
|
-
const
|
|
178
|
-
|
|
179
|
-
const item = arr[i];
|
|
192
|
+
const results = new Array(arr.length);
|
|
193
|
+
const queue = fastq.promise(async ({ item, index }) => {
|
|
180
194
|
if (!isRecord(item))
|
|
181
195
|
throw new TypeError(`Expected ${String(key)} to be an object, got ${typeof item}`);
|
|
182
|
-
const
|
|
196
|
+
const o = await agentProcessResultToObject(await this._processNonIterator({ ...input, [key]: arr, ...item }, { ...options, streaming: false }));
|
|
197
|
+
const res = omit(o, key);
|
|
183
198
|
// Merge the item result with the original item used for next iteration
|
|
184
199
|
if (this.iterateWithPreviousOutput) {
|
|
185
200
|
arr = produce(arr, (draft) => {
|
|
186
|
-
const item = draft[
|
|
201
|
+
const item = draft[index];
|
|
187
202
|
assert(item);
|
|
188
203
|
Object.assign(item, res);
|
|
189
204
|
});
|
|
190
205
|
}
|
|
191
|
-
|
|
192
|
-
|
|
206
|
+
results[index] = res;
|
|
207
|
+
}, this.concurrency);
|
|
208
|
+
for (let index = 0; index < arr.length; index++) {
|
|
209
|
+
queue.push({ index, item: arr[index] });
|
|
193
210
|
}
|
|
211
|
+
await queue.drained();
|
|
212
|
+
yield { delta: { json: { [key]: results } } };
|
|
194
213
|
}
|
|
195
214
|
_processNonIterator(input, options) {
|
|
196
215
|
switch (this.mode) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { AIGNEObserver } from "@aigne/observability-api";
|
|
2
2
|
import type { Span } from "@opentelemetry/api";
|
|
3
3
|
import { Emitter } from "strict-event-emitter";
|
|
4
|
-
import { type Agent, type AgentInvokeOptions, type AgentProcessAsyncGenerator, type AgentResponse, type AgentResponseStream, type Message } from "../agents/agent.js";
|
|
4
|
+
import { type Agent, type AgentHooks, type AgentInvokeOptions, type AgentProcessAsyncGenerator, type AgentResponse, type AgentResponseStream, type Message } from "../agents/agent.js";
|
|
5
5
|
import type { ChatModel } from "../agents/chat-model.js";
|
|
6
6
|
import { UserAgent } from "../agents/user-agent.js";
|
|
7
7
|
import type { Memory } from "../memory/memory.js";
|
|
@@ -80,6 +80,7 @@ export interface Context<U extends UserContext = UserContext> extends TypedEvent
|
|
|
80
80
|
limits?: ContextLimits;
|
|
81
81
|
status?: "normal" | "timeout";
|
|
82
82
|
userContext: U;
|
|
83
|
+
hooks?: AgentHooks[];
|
|
83
84
|
memories: Pick<Memory, "content">[];
|
|
84
85
|
/**
|
|
85
86
|
* Create a user agent to consistently invoke an agent
|
|
@@ -164,11 +165,14 @@ export declare class AIGNEContext implements Context {
|
|
|
164
165
|
set userContext(userContext: Context["userContext"]);
|
|
165
166
|
get memories(): Context["memories"];
|
|
166
167
|
set memories(memories: Context["memories"]);
|
|
168
|
+
get hooks(): AgentHooks[];
|
|
169
|
+
set hooks(hooks: AgentHooks[]);
|
|
167
170
|
newContext({ reset }?: {
|
|
168
171
|
reset?: boolean;
|
|
169
172
|
}): AIGNEContext;
|
|
170
173
|
invoke: Context["invoke"];
|
|
171
174
|
private onInvocationResult;
|
|
175
|
+
private processOptions;
|
|
172
176
|
publish: Context["publish"];
|
|
173
177
|
subscribe: Context["subscribe"];
|
|
174
178
|
unsubscribe: Context["unsubscribe"];
|
|
@@ -197,6 +201,7 @@ declare class AIGNEContextShared {
|
|
|
197
201
|
usage: ContextUsage;
|
|
198
202
|
userContext: Context["userContext"];
|
|
199
203
|
memories: Context["memories"];
|
|
204
|
+
hooks: AgentHooks[];
|
|
200
205
|
private abortController;
|
|
201
206
|
private timer?;
|
|
202
207
|
private initTimeout;
|
package/lib/esm/aigne/context.js
CHANGED
|
@@ -88,6 +88,12 @@ export class AIGNEContext {
|
|
|
88
88
|
set memories(memories) {
|
|
89
89
|
this.internal.memories = memories;
|
|
90
90
|
}
|
|
91
|
+
get hooks() {
|
|
92
|
+
return this.internal.hooks;
|
|
93
|
+
}
|
|
94
|
+
set hooks(hooks) {
|
|
95
|
+
this.internal.hooks = hooks;
|
|
96
|
+
}
|
|
91
97
|
newContext({ reset } = {}) {
|
|
92
98
|
return new AIGNEContext(this, { reset });
|
|
93
99
|
}
|
|
@@ -97,14 +103,7 @@ export class AIGNEContext {
|
|
|
97
103
|
message,
|
|
98
104
|
options,
|
|
99
105
|
});
|
|
100
|
-
|
|
101
|
-
Object.assign(this.userContext, options.userContext);
|
|
102
|
-
options.userContext = undefined;
|
|
103
|
-
}
|
|
104
|
-
if (options?.memories?.length) {
|
|
105
|
-
this.memories.push(...options.memories);
|
|
106
|
-
options.memories = undefined;
|
|
107
|
-
}
|
|
106
|
+
this.processOptions(options);
|
|
108
107
|
if (isNil(message)) {
|
|
109
108
|
return UserAgent.from({
|
|
110
109
|
context: this,
|
|
@@ -170,7 +169,7 @@ export class AIGNEContext {
|
|
|
170
169
|
},
|
|
171
170
|
};
|
|
172
171
|
}
|
|
173
|
-
|
|
172
|
+
processOptions(options) {
|
|
174
173
|
if (options?.userContext) {
|
|
175
174
|
Object.assign(this.userContext, options.userContext);
|
|
176
175
|
options.userContext = undefined;
|
|
@@ -179,6 +178,13 @@ export class AIGNEContext {
|
|
|
179
178
|
this.memories.push(...options.memories);
|
|
180
179
|
options.memories = undefined;
|
|
181
180
|
}
|
|
181
|
+
if (options?.hooks) {
|
|
182
|
+
this.hooks.push(...flat(options.hooks));
|
|
183
|
+
options.hooks = undefined;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
publish = ((topic, payload, options) => {
|
|
187
|
+
this.processOptions(options);
|
|
182
188
|
const newContext = options?.newContext === false ? this : this.newContext();
|
|
183
189
|
return this.internal.messageQueue.publish(topic, {
|
|
184
190
|
...toMessagePayload(payload),
|
|
@@ -311,6 +317,7 @@ class AIGNEContextShared {
|
|
|
311
317
|
usage = newEmptyContextUsage();
|
|
312
318
|
userContext = {};
|
|
313
319
|
memories = [];
|
|
320
|
+
hooks = [];
|
|
314
321
|
abortController = new AbortController();
|
|
315
322
|
timer;
|
|
316
323
|
initTimeout() {
|
|
@@ -19,6 +19,7 @@ export type NestAgentSchema = string | {
|
|
|
19
19
|
export interface BaseAgentSchema {
|
|
20
20
|
name?: string;
|
|
21
21
|
description?: string;
|
|
22
|
+
taskTitle?: string;
|
|
22
23
|
inputSchema?: ZodType<Record<string, any>>;
|
|
23
24
|
defaultInput?: Record<string, any>;
|
|
24
25
|
outputSchema?: ZodType<Record<string, any>>;
|
|
@@ -46,6 +47,9 @@ export interface TeamAgentSchema extends BaseAgentSchema {
|
|
|
46
47
|
type: "team";
|
|
47
48
|
mode?: ProcessMode;
|
|
48
49
|
iterateOn?: string;
|
|
50
|
+
concurrency?: number;
|
|
51
|
+
iterateWithPreviousOutput?: boolean;
|
|
52
|
+
includeAllStepsOutput?: boolean;
|
|
49
53
|
reflection?: Omit<ReflectionMode, "reviewer"> & {
|
|
50
54
|
reviewer: NestAgentSchema;
|
|
51
55
|
};
|
|
@@ -30,6 +30,7 @@ export async function parseAgentFile(path, data) {
|
|
|
30
30
|
name: optionalize(z.string()),
|
|
31
31
|
alias: optionalize(z.array(z.string())),
|
|
32
32
|
description: optionalize(z.string()),
|
|
33
|
+
taskTitle: optionalize(z.string()),
|
|
33
34
|
inputSchema: optionalize(inputOutputSchema({ path })).transform((v) => v ? jsonSchemaToZod(v) : undefined),
|
|
34
35
|
defaultInput: optionalize(defaultInputSchema),
|
|
35
36
|
outputSchema: optionalize(inputOutputSchema({ path })).transform((v) => v ? jsonSchemaToZod(v) : undefined),
|
|
@@ -74,6 +75,9 @@ export async function parseAgentFile(path, data) {
|
|
|
74
75
|
type: z.literal("team"),
|
|
75
76
|
mode: optionalize(z.nativeEnum(ProcessMode)),
|
|
76
77
|
iterateOn: optionalize(z.string()),
|
|
78
|
+
concurrency: optionalize(z.number().int().min(1)),
|
|
79
|
+
iterateWithPreviousOutput: optionalize(z.boolean()),
|
|
80
|
+
includeAllStepsOutput: optionalize(z.boolean()),
|
|
77
81
|
reflection: camelizeSchema(optionalize(z.object({
|
|
78
82
|
reviewer: nestAgentSchema,
|
|
79
83
|
isApproved: z.string(),
|
package/lib/esm/loader/schema.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { nodejs } from "@aigne/platform-helpers/nodejs/index.js";
|
|
2
|
-
import camelize from "camelize-ts";
|
|
3
2
|
import { parse } from "yaml";
|
|
4
3
|
import { z } from "zod";
|
|
5
4
|
import { DEFAULT_INPUT_ACTION_GET } from "../agents/agent.js";
|
|
5
|
+
import { camelize } from "../utils/camelize.js";
|
|
6
6
|
import { isRecord } from "../utils/type-utils.js";
|
|
7
7
|
export const inputOutputSchema = ({ path }) => {
|
|
8
8
|
const includeExternalSchema = async (schema) => {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function camelize<T>(obj: T, shallow?: boolean): any;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { isRecord } from "./type-utils.js";
|
|
2
|
+
export function camelize(obj, shallow = false) {
|
|
3
|
+
if (Array.isArray(obj)) {
|
|
4
|
+
return shallow ? obj : obj.map((item) => camelize(item, false));
|
|
5
|
+
}
|
|
6
|
+
if (isRecord(obj)) {
|
|
7
|
+
return Object.fromEntries(Object.entries(obj).map(([key, value]) => [
|
|
8
|
+
camelCase(key),
|
|
9
|
+
shallow ? value : camelize(value, false),
|
|
10
|
+
]));
|
|
11
|
+
}
|
|
12
|
+
return obj;
|
|
13
|
+
}
|
|
14
|
+
function camelCase(key) {
|
|
15
|
+
key = key.replace(/[-_#@$\s]+(.)?/g, (_, char) => char.toUpperCase());
|
|
16
|
+
key = key.charAt(0).toLowerCase() + key.slice(1);
|
|
17
|
+
return key;
|
|
18
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aigne/core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.46.0",
|
|
4
4
|
"description": "AIGNE core library for building AI-powered applications",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -76,11 +76,10 @@
|
|
|
76
76
|
"debug": "^4.4.1",
|
|
77
77
|
"eventsource-parser": "^3.0.3",
|
|
78
78
|
"fast-deep-equal": "^3.1.3",
|
|
79
|
+
"fastq": "^1.19.1",
|
|
79
80
|
"immer": "^10.1.1",
|
|
80
81
|
"jaison": "^2.0.2",
|
|
81
82
|
"jsonata": "^2.0.6",
|
|
82
|
-
"mustache": "^4.2.0",
|
|
83
|
-
"nanoid": "^5.1.5",
|
|
84
83
|
"nunjucks": "^3.2.4",
|
|
85
84
|
"p-retry": "^6.2.1",
|
|
86
85
|
"raw-body": "^3.0.0",
|
|
@@ -91,14 +90,13 @@
|
|
|
91
90
|
"zod": "^3.25.67",
|
|
92
91
|
"zod-to-json-schema": "^3.24.6",
|
|
93
92
|
"@aigne/observability-api": "^0.9.0",
|
|
94
|
-
"@aigne/platform-helpers": "^0.
|
|
93
|
+
"@aigne/platform-helpers": "^0.6.0"
|
|
95
94
|
},
|
|
96
95
|
"devDependencies": {
|
|
97
96
|
"@types/bun": "^1.2.18",
|
|
98
97
|
"@types/compression": "^1.8.1",
|
|
99
98
|
"@types/content-type": "^1.1.9",
|
|
100
99
|
"@types/express": "^5.0.3",
|
|
101
|
-
"@types/mustache": "^4.2.6",
|
|
102
100
|
"@types/node": "^24.0.12",
|
|
103
101
|
"@types/nunjucks": "^3.2.6",
|
|
104
102
|
"compression": "^1.8.0",
|