@aigne/agent-library 1.23.0-beta.6 → 1.23.0-beta.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/lib/cjs/orchestrator/index.d.ts +3 -3
- package/lib/cjs/orchestrator/index.js +20 -7
- package/lib/cjs/orchestrator/type.d.ts +40 -139
- package/lib/cjs/orchestrator/type.js +7 -7
- package/lib/dts/orchestrator/index.d.ts +3 -3
- package/lib/dts/orchestrator/type.d.ts +40 -139
- package/lib/esm/orchestrator/index.d.ts +3 -3
- package/lib/esm/orchestrator/index.js +21 -8
- package/lib/esm/orchestrator/type.d.ts +40 -139
- package/lib/esm/orchestrator/type.js +7 -7
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,21 @@
|
|
|
7
7
|
* @aigne/core bumped to 1.22.0
|
|
8
8
|
* @aigne/openai bumped to 0.3.4
|
|
9
9
|
|
|
10
|
+
## [1.23.0-beta.7](https://github.com/AIGNE-io/aigne-framework/compare/agent-library-v1.23.0-beta.6...agent-library-v1.23.0-beta.7) (2025-12-11)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Bug Fixes
|
|
14
|
+
|
|
15
|
+
* **orchestrator:** support custom input schema for planner/worker/completer ([#823](https://github.com/AIGNE-io/aigne-framework/issues/823)) ([3d26f8b](https://github.com/AIGNE-io/aigne-framework/commit/3d26f8bac8b679010f25d9e4eb59fc6e80afda4c))
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Dependencies
|
|
19
|
+
|
|
20
|
+
* The following workspace dependencies were updated
|
|
21
|
+
* dependencies
|
|
22
|
+
* @aigne/core bumped to 1.71.0-beta.6
|
|
23
|
+
* @aigne/openai bumped to 0.16.15-beta.6
|
|
24
|
+
|
|
10
25
|
## [1.23.0-beta.6](https://github.com/AIGNE-io/aigne-framework/compare/agent-library-v1.23.0-beta.5...agent-library-v1.23.0-beta.6) (2025-12-11)
|
|
11
26
|
|
|
12
27
|
|
|
@@ -6,7 +6,7 @@ import { type StateManagementOptions } from "./type.js";
|
|
|
6
6
|
* Configuration options for the Orchestrator Agent
|
|
7
7
|
*/
|
|
8
8
|
export interface OrchestratorAgentOptions<I extends Message = Message, O extends Message = Message> extends Omit<AIAgentOptions<I, O>, "instructions"> {
|
|
9
|
-
objective
|
|
9
|
+
objective?: PromptBuilder;
|
|
10
10
|
planner?: OrchestratorAgent<I, O>["planner"];
|
|
11
11
|
worker?: OrchestratorAgent<I, O>["worker"];
|
|
12
12
|
completer?: OrchestratorAgent<I, O>["completer"];
|
|
@@ -17,7 +17,7 @@ export interface OrchestratorAgentOptions<I extends Message = Message, O extends
|
|
|
17
17
|
stateManagement?: StateManagementOptions;
|
|
18
18
|
}
|
|
19
19
|
export interface LoadOrchestratorAgentOptions<I extends Message = Message, O extends Message = Message> extends Omit<AIAgentOptions<I, O>, "instructions"> {
|
|
20
|
-
objective
|
|
20
|
+
objective?: string | PromptBuilder | Instructions;
|
|
21
21
|
planner?: NestAgentSchema | {
|
|
22
22
|
instructions?: string | PromptBuilder | Instructions;
|
|
23
23
|
};
|
|
@@ -62,7 +62,7 @@ export declare class OrchestratorAgent<I extends Message = Message, O extends Me
|
|
|
62
62
|
* @param options - Configuration options for the Orchestrator Agent
|
|
63
63
|
*/
|
|
64
64
|
constructor(options: OrchestratorAgentOptions<I, O>);
|
|
65
|
-
private objective
|
|
65
|
+
private objective?;
|
|
66
66
|
private planner;
|
|
67
67
|
private worker;
|
|
68
68
|
private completer;
|
|
@@ -60,7 +60,7 @@ class OrchestratorAgent extends core_1.AIAgent {
|
|
|
60
60
|
const valid = await schema.parseAsync(parsed);
|
|
61
61
|
return new OrchestratorAgent({
|
|
62
62
|
...parsed,
|
|
63
|
-
objective: (0, index_js_1.instructionsToPromptBuilder)(valid.objective),
|
|
63
|
+
objective: valid.objective && (0, index_js_1.instructionsToPromptBuilder)(valid.objective),
|
|
64
64
|
planner: valid.planner
|
|
65
65
|
? (await (0, index_js_1.loadNestAgent)(filepath, valid.planner, options, {
|
|
66
66
|
...defaultPlannerOptions,
|
|
@@ -170,10 +170,10 @@ class OrchestratorAgent extends core_1.AIAgent {
|
|
|
170
170
|
const model = this.model || options.model || options.context.model;
|
|
171
171
|
if (!model)
|
|
172
172
|
throw new Error("model is required to run OrchestratorAgent");
|
|
173
|
-
const
|
|
173
|
+
const objective = (await this.objective?.buildPrompt({
|
|
174
174
|
input,
|
|
175
175
|
context: options.context,
|
|
176
|
-
});
|
|
176
|
+
}))?.prompt;
|
|
177
177
|
const executionState = { tasks: [] };
|
|
178
178
|
let iterationCount = 0;
|
|
179
179
|
const maxIterations = this.stateManagement?.maxIterations ?? type_js_1.DEFAULT_MAX_ITERATIONS;
|
|
@@ -193,13 +193,22 @@ class OrchestratorAgent extends core_1.AIAgent {
|
|
|
193
193
|
iterationCount++;
|
|
194
194
|
// Compress state for planner input if needed
|
|
195
195
|
const compressedState = this.compressState(executionState);
|
|
196
|
-
const plan = await this.invokeChildAgent(this.planner, {
|
|
196
|
+
const plan = await this.invokeChildAgent(this.planner, {
|
|
197
|
+
objective,
|
|
198
|
+
executionState: compressedState,
|
|
199
|
+
...(0, type_utils_js_1.pick)(input, this.planner.inputKeys),
|
|
200
|
+
}, { ...options, model, streaming: false });
|
|
197
201
|
if (plan.finished || !plan.nextTask) {
|
|
198
202
|
break;
|
|
199
203
|
}
|
|
200
204
|
const task = plan.nextTask;
|
|
201
205
|
const createdAt = Date.now();
|
|
202
|
-
const taskResult = await this.invokeChildAgent(this.worker, {
|
|
206
|
+
const taskResult = await this.invokeChildAgent(this.worker, {
|
|
207
|
+
objective,
|
|
208
|
+
executionState: compressedState,
|
|
209
|
+
task,
|
|
210
|
+
...(0, type_utils_js_1.pick)(input, this.worker.inputKeys),
|
|
211
|
+
}, { ...options, model, streaming: false })
|
|
203
212
|
.then((res) => {
|
|
204
213
|
if (res.error || res.success === false) {
|
|
205
214
|
return { status: "failed", result: res.result, error: res.error };
|
|
@@ -219,7 +228,11 @@ class OrchestratorAgent extends core_1.AIAgent {
|
|
|
219
228
|
}
|
|
220
229
|
// Compress state for completer input if needed
|
|
221
230
|
const compressedState = this.compressState(executionState);
|
|
222
|
-
yield* await this.invokeChildAgent(this.completer, {
|
|
231
|
+
yield* await this.invokeChildAgent(this.completer, {
|
|
232
|
+
objective,
|
|
233
|
+
executionState: compressedState,
|
|
234
|
+
...(0, type_utils_js_1.pick)(input, this.completer.inputKeys),
|
|
235
|
+
}, { ...options, model, streaming: true });
|
|
223
236
|
}
|
|
224
237
|
}
|
|
225
238
|
exports.OrchestratorAgent = OrchestratorAgent;
|
|
@@ -228,7 +241,7 @@ function getOrchestratorAgentSchema({ filepath }) {
|
|
|
228
241
|
const nestAgentSchema = (0, agent_yaml_js_1.getNestAgentSchema)({ filepath });
|
|
229
242
|
const instructionsSchema = (0, agent_yaml_js_1.getInstructionsSchema)({ filepath });
|
|
230
243
|
return (0, schema_js_1.camelizeSchema)(zod_1.z.object({
|
|
231
|
-
objective: instructionsSchema,
|
|
244
|
+
objective: (0, schema_js_1.optionalize)(instructionsSchema),
|
|
232
245
|
planner: (0, schema_js_1.optionalize)(nestAgentSchema),
|
|
233
246
|
worker: (0, schema_js_1.optionalize)(nestAgentSchema),
|
|
234
247
|
completer: (0, schema_js_1.optionalize)(nestAgentSchema),
|
|
@@ -118,45 +118,12 @@ export declare const executionStateSchema: z.ZodObject<{
|
|
|
118
118
|
}[];
|
|
119
119
|
}>;
|
|
120
120
|
export interface PlannerInput extends Message {
|
|
121
|
-
objective
|
|
122
|
-
executionState
|
|
121
|
+
objective?: string;
|
|
122
|
+
executionState?: ExecutionState;
|
|
123
123
|
}
|
|
124
124
|
export declare const plannerInputSchema: z.ZodObject<{
|
|
125
|
-
objective: z.
|
|
126
|
-
executionState: z.
|
|
127
|
-
tasks: z.ZodArray<z.ZodObject<{
|
|
128
|
-
task: z.ZodString;
|
|
129
|
-
status: z.ZodEnum<["pending", "completed", "failed"]>;
|
|
130
|
-
result: z.ZodOptional<z.ZodUnknown>;
|
|
131
|
-
error: z.ZodOptional<z.ZodObject<{
|
|
132
|
-
message: z.ZodString;
|
|
133
|
-
}, "strip", z.ZodTypeAny, {
|
|
134
|
-
message: string;
|
|
135
|
-
}, {
|
|
136
|
-
message: string;
|
|
137
|
-
}>>;
|
|
138
|
-
createdAt: z.ZodOptional<z.ZodNumber>;
|
|
139
|
-
completedAt: z.ZodOptional<z.ZodNumber>;
|
|
140
|
-
}, "strip", z.ZodTypeAny, {
|
|
141
|
-
status: "pending" | "completed" | "failed";
|
|
142
|
-
task: string;
|
|
143
|
-
error?: {
|
|
144
|
-
message: string;
|
|
145
|
-
} | undefined;
|
|
146
|
-
result?: unknown;
|
|
147
|
-
createdAt?: number | undefined;
|
|
148
|
-
completedAt?: number | undefined;
|
|
149
|
-
}, {
|
|
150
|
-
status: "pending" | "completed" | "failed";
|
|
151
|
-
task: string;
|
|
152
|
-
error?: {
|
|
153
|
-
message: string;
|
|
154
|
-
} | undefined;
|
|
155
|
-
result?: unknown;
|
|
156
|
-
createdAt?: number | undefined;
|
|
157
|
-
completedAt?: number | undefined;
|
|
158
|
-
}>, "many">;
|
|
159
|
-
}, "strip", z.ZodTypeAny, {
|
|
125
|
+
objective: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
|
|
126
|
+
executionState: z.ZodType<{
|
|
160
127
|
tasks: {
|
|
161
128
|
status: "pending" | "completed" | "failed";
|
|
162
129
|
task: string;
|
|
@@ -167,7 +134,7 @@ export declare const plannerInputSchema: z.ZodObject<{
|
|
|
167
134
|
createdAt?: number | undefined;
|
|
168
135
|
completedAt?: number | undefined;
|
|
169
136
|
}[];
|
|
170
|
-
}, {
|
|
137
|
+
} | undefined, z.ZodTypeDef, {
|
|
171
138
|
tasks: {
|
|
172
139
|
status: "pending" | "completed" | "failed";
|
|
173
140
|
task: string;
|
|
@@ -178,10 +145,10 @@ export declare const plannerInputSchema: z.ZodObject<{
|
|
|
178
145
|
createdAt?: number | undefined;
|
|
179
146
|
completedAt?: number | undefined;
|
|
180
147
|
}[];
|
|
181
|
-
}>;
|
|
148
|
+
} | undefined>;
|
|
182
149
|
}, "strip", z.ZodTypeAny, {
|
|
183
|
-
objective
|
|
184
|
-
executionState
|
|
150
|
+
objective?: string | undefined;
|
|
151
|
+
executionState?: {
|
|
185
152
|
tasks: {
|
|
186
153
|
status: "pending" | "completed" | "failed";
|
|
187
154
|
task: string;
|
|
@@ -192,10 +159,10 @@ export declare const plannerInputSchema: z.ZodObject<{
|
|
|
192
159
|
createdAt?: number | undefined;
|
|
193
160
|
completedAt?: number | undefined;
|
|
194
161
|
}[];
|
|
195
|
-
};
|
|
162
|
+
} | undefined;
|
|
196
163
|
}, {
|
|
197
|
-
objective
|
|
198
|
-
executionState
|
|
164
|
+
objective?: string | undefined;
|
|
165
|
+
executionState?: {
|
|
199
166
|
tasks: {
|
|
200
167
|
status: "pending" | "completed" | "failed";
|
|
201
168
|
task: string;
|
|
@@ -206,7 +173,7 @@ export declare const plannerInputSchema: z.ZodObject<{
|
|
|
206
173
|
createdAt?: number | undefined;
|
|
207
174
|
completedAt?: number | undefined;
|
|
208
175
|
}[];
|
|
209
|
-
};
|
|
176
|
+
} | undefined;
|
|
210
177
|
}>;
|
|
211
178
|
export interface PlannerOutput extends Message {
|
|
212
179
|
nextTask?: string;
|
|
@@ -223,47 +190,14 @@ export declare const plannerOutputSchema: z.ZodObject<{
|
|
|
223
190
|
finished?: boolean | undefined;
|
|
224
191
|
}>;
|
|
225
192
|
export interface WorkerInput extends Message {
|
|
226
|
-
objective
|
|
227
|
-
executionState
|
|
228
|
-
task
|
|
193
|
+
objective?: string;
|
|
194
|
+
executionState?: ExecutionState;
|
|
195
|
+
task?: string;
|
|
229
196
|
}
|
|
230
197
|
export declare const workerInputSchema: z.ZodObject<{
|
|
231
|
-
objective: z.
|
|
232
|
-
task: z.
|
|
233
|
-
executionState: z.
|
|
234
|
-
tasks: z.ZodArray<z.ZodObject<{
|
|
235
|
-
task: z.ZodString;
|
|
236
|
-
status: z.ZodEnum<["pending", "completed", "failed"]>;
|
|
237
|
-
result: z.ZodOptional<z.ZodUnknown>;
|
|
238
|
-
error: z.ZodOptional<z.ZodObject<{
|
|
239
|
-
message: z.ZodString;
|
|
240
|
-
}, "strip", z.ZodTypeAny, {
|
|
241
|
-
message: string;
|
|
242
|
-
}, {
|
|
243
|
-
message: string;
|
|
244
|
-
}>>;
|
|
245
|
-
createdAt: z.ZodOptional<z.ZodNumber>;
|
|
246
|
-
completedAt: z.ZodOptional<z.ZodNumber>;
|
|
247
|
-
}, "strip", z.ZodTypeAny, {
|
|
248
|
-
status: "pending" | "completed" | "failed";
|
|
249
|
-
task: string;
|
|
250
|
-
error?: {
|
|
251
|
-
message: string;
|
|
252
|
-
} | undefined;
|
|
253
|
-
result?: unknown;
|
|
254
|
-
createdAt?: number | undefined;
|
|
255
|
-
completedAt?: number | undefined;
|
|
256
|
-
}, {
|
|
257
|
-
status: "pending" | "completed" | "failed";
|
|
258
|
-
task: string;
|
|
259
|
-
error?: {
|
|
260
|
-
message: string;
|
|
261
|
-
} | undefined;
|
|
262
|
-
result?: unknown;
|
|
263
|
-
createdAt?: number | undefined;
|
|
264
|
-
completedAt?: number | undefined;
|
|
265
|
-
}>, "many">;
|
|
266
|
-
}, "strip", z.ZodTypeAny, {
|
|
198
|
+
objective: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
|
|
199
|
+
task: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
|
|
200
|
+
executionState: z.ZodType<{
|
|
267
201
|
tasks: {
|
|
268
202
|
status: "pending" | "completed" | "failed";
|
|
269
203
|
task: string;
|
|
@@ -274,7 +208,7 @@ export declare const workerInputSchema: z.ZodObject<{
|
|
|
274
208
|
createdAt?: number | undefined;
|
|
275
209
|
completedAt?: number | undefined;
|
|
276
210
|
}[];
|
|
277
|
-
}, {
|
|
211
|
+
} | undefined, z.ZodTypeDef, {
|
|
278
212
|
tasks: {
|
|
279
213
|
status: "pending" | "completed" | "failed";
|
|
280
214
|
task: string;
|
|
@@ -285,11 +219,11 @@ export declare const workerInputSchema: z.ZodObject<{
|
|
|
285
219
|
createdAt?: number | undefined;
|
|
286
220
|
completedAt?: number | undefined;
|
|
287
221
|
}[];
|
|
288
|
-
}>;
|
|
222
|
+
} | undefined>;
|
|
289
223
|
}, "strip", z.ZodTypeAny, {
|
|
290
|
-
task
|
|
291
|
-
objective
|
|
292
|
-
executionState
|
|
224
|
+
task?: string | undefined;
|
|
225
|
+
objective?: string | undefined;
|
|
226
|
+
executionState?: {
|
|
293
227
|
tasks: {
|
|
294
228
|
status: "pending" | "completed" | "failed";
|
|
295
229
|
task: string;
|
|
@@ -300,11 +234,11 @@ export declare const workerInputSchema: z.ZodObject<{
|
|
|
300
234
|
createdAt?: number | undefined;
|
|
301
235
|
completedAt?: number | undefined;
|
|
302
236
|
}[];
|
|
303
|
-
};
|
|
237
|
+
} | undefined;
|
|
304
238
|
}, {
|
|
305
|
-
task
|
|
306
|
-
objective
|
|
307
|
-
executionState
|
|
239
|
+
task?: string | undefined;
|
|
240
|
+
objective?: string | undefined;
|
|
241
|
+
executionState?: {
|
|
308
242
|
tasks: {
|
|
309
243
|
status: "pending" | "completed" | "failed";
|
|
310
244
|
task: string;
|
|
@@ -315,7 +249,7 @@ export declare const workerInputSchema: z.ZodObject<{
|
|
|
315
249
|
createdAt?: number | undefined;
|
|
316
250
|
completedAt?: number | undefined;
|
|
317
251
|
}[];
|
|
318
|
-
};
|
|
252
|
+
} | undefined;
|
|
319
253
|
}>;
|
|
320
254
|
/**
|
|
321
255
|
* Worker output structure
|
|
@@ -354,45 +288,12 @@ export declare const workerOutputSchema: z.ZodObject<{
|
|
|
354
288
|
result?: string | undefined;
|
|
355
289
|
}>;
|
|
356
290
|
export interface CompleterInput extends Message {
|
|
357
|
-
objective
|
|
358
|
-
executionState
|
|
291
|
+
objective?: string;
|
|
292
|
+
executionState?: ExecutionState;
|
|
359
293
|
}
|
|
360
294
|
export declare const completerInputSchema: z.ZodObject<{
|
|
361
|
-
objective: z.
|
|
362
|
-
executionState: z.
|
|
363
|
-
tasks: z.ZodArray<z.ZodObject<{
|
|
364
|
-
task: z.ZodString;
|
|
365
|
-
status: z.ZodEnum<["pending", "completed", "failed"]>;
|
|
366
|
-
result: z.ZodOptional<z.ZodUnknown>;
|
|
367
|
-
error: z.ZodOptional<z.ZodObject<{
|
|
368
|
-
message: z.ZodString;
|
|
369
|
-
}, "strip", z.ZodTypeAny, {
|
|
370
|
-
message: string;
|
|
371
|
-
}, {
|
|
372
|
-
message: string;
|
|
373
|
-
}>>;
|
|
374
|
-
createdAt: z.ZodOptional<z.ZodNumber>;
|
|
375
|
-
completedAt: z.ZodOptional<z.ZodNumber>;
|
|
376
|
-
}, "strip", z.ZodTypeAny, {
|
|
377
|
-
status: "pending" | "completed" | "failed";
|
|
378
|
-
task: string;
|
|
379
|
-
error?: {
|
|
380
|
-
message: string;
|
|
381
|
-
} | undefined;
|
|
382
|
-
result?: unknown;
|
|
383
|
-
createdAt?: number | undefined;
|
|
384
|
-
completedAt?: number | undefined;
|
|
385
|
-
}, {
|
|
386
|
-
status: "pending" | "completed" | "failed";
|
|
387
|
-
task: string;
|
|
388
|
-
error?: {
|
|
389
|
-
message: string;
|
|
390
|
-
} | undefined;
|
|
391
|
-
result?: unknown;
|
|
392
|
-
createdAt?: number | undefined;
|
|
393
|
-
completedAt?: number | undefined;
|
|
394
|
-
}>, "many">;
|
|
395
|
-
}, "strip", z.ZodTypeAny, {
|
|
295
|
+
objective: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
|
|
296
|
+
executionState: z.ZodType<{
|
|
396
297
|
tasks: {
|
|
397
298
|
status: "pending" | "completed" | "failed";
|
|
398
299
|
task: string;
|
|
@@ -403,7 +304,7 @@ export declare const completerInputSchema: z.ZodObject<{
|
|
|
403
304
|
createdAt?: number | undefined;
|
|
404
305
|
completedAt?: number | undefined;
|
|
405
306
|
}[];
|
|
406
|
-
}, {
|
|
307
|
+
} | undefined, z.ZodTypeDef, {
|
|
407
308
|
tasks: {
|
|
408
309
|
status: "pending" | "completed" | "failed";
|
|
409
310
|
task: string;
|
|
@@ -414,10 +315,10 @@ export declare const completerInputSchema: z.ZodObject<{
|
|
|
414
315
|
createdAt?: number | undefined;
|
|
415
316
|
completedAt?: number | undefined;
|
|
416
317
|
}[];
|
|
417
|
-
}>;
|
|
318
|
+
} | undefined>;
|
|
418
319
|
}, "strip", z.ZodTypeAny, {
|
|
419
|
-
objective
|
|
420
|
-
executionState
|
|
320
|
+
objective?: string | undefined;
|
|
321
|
+
executionState?: {
|
|
421
322
|
tasks: {
|
|
422
323
|
status: "pending" | "completed" | "failed";
|
|
423
324
|
task: string;
|
|
@@ -428,10 +329,10 @@ export declare const completerInputSchema: z.ZodObject<{
|
|
|
428
329
|
createdAt?: number | undefined;
|
|
429
330
|
completedAt?: number | undefined;
|
|
430
331
|
}[];
|
|
431
|
-
};
|
|
332
|
+
} | undefined;
|
|
432
333
|
}, {
|
|
433
|
-
objective
|
|
434
|
-
executionState
|
|
334
|
+
objective?: string | undefined;
|
|
335
|
+
executionState?: {
|
|
435
336
|
tasks: {
|
|
436
337
|
status: "pending" | "completed" | "failed";
|
|
437
338
|
task: string;
|
|
@@ -442,7 +343,7 @@ export declare const completerInputSchema: z.ZodObject<{
|
|
|
442
343
|
createdAt?: number | undefined;
|
|
443
344
|
completedAt?: number | undefined;
|
|
444
345
|
}[];
|
|
445
|
-
};
|
|
346
|
+
} | undefined;
|
|
446
347
|
}>;
|
|
447
348
|
/**
|
|
448
349
|
* Default maximum number of task execution iterations
|
|
@@ -27,8 +27,8 @@ exports.executionStateSchema = zod_1.default.object({
|
|
|
27
27
|
.describe("The list of tasks that have been executed along with their results."),
|
|
28
28
|
});
|
|
29
29
|
exports.plannerInputSchema = zod_1.default.object({
|
|
30
|
-
objective: zod_1.default.string().describe("The user's overall objective."),
|
|
31
|
-
executionState: exports.executionStateSchema,
|
|
30
|
+
objective: (0, schema_js_1.optionalize)(zod_1.default.string().describe("The user's overall objective.")),
|
|
31
|
+
executionState: (0, schema_js_1.optionalize)(exports.executionStateSchema),
|
|
32
32
|
});
|
|
33
33
|
exports.plannerOutputSchema = zod_1.default.object({
|
|
34
34
|
nextTask: zod_1.default
|
|
@@ -50,9 +50,9 @@ When finished is true, nextTask should be omitted.
|
|
|
50
50
|
`),
|
|
51
51
|
});
|
|
52
52
|
exports.workerInputSchema = zod_1.default.object({
|
|
53
|
-
objective: zod_1.default.string().describe("The user's overall objective."),
|
|
54
|
-
task: zod_1.default.string().describe("The specific task assigned to the worker for execution."),
|
|
55
|
-
executionState: exports.executionStateSchema,
|
|
53
|
+
objective: (0, schema_js_1.optionalize)(zod_1.default.string().describe("The user's overall objective.")),
|
|
54
|
+
task: (0, schema_js_1.optionalize)(zod_1.default.string().describe("The specific task assigned to the worker for execution.")),
|
|
55
|
+
executionState: (0, schema_js_1.optionalize)(exports.executionStateSchema),
|
|
56
56
|
});
|
|
57
57
|
exports.workerOutputSchema = zod_1.default.object({
|
|
58
58
|
result: zod_1.default
|
|
@@ -72,8 +72,8 @@ exports.workerOutputSchema = zod_1.default.object({
|
|
|
72
72
|
.describe("Error details if the task failed. Only include when success is false."),
|
|
73
73
|
});
|
|
74
74
|
exports.completerInputSchema = zod_1.default.object({
|
|
75
|
-
objective: zod_1.default.string().describe("The user's overall objective."),
|
|
76
|
-
executionState: exports.executionStateSchema,
|
|
75
|
+
objective: (0, schema_js_1.optionalize)(zod_1.default.string().describe("The user's overall objective.")),
|
|
76
|
+
executionState: (0, schema_js_1.optionalize)(exports.executionStateSchema),
|
|
77
77
|
});
|
|
78
78
|
/**
|
|
79
79
|
* Default maximum number of task execution iterations
|
|
@@ -6,7 +6,7 @@ import { type StateManagementOptions } from "./type.js";
|
|
|
6
6
|
* Configuration options for the Orchestrator Agent
|
|
7
7
|
*/
|
|
8
8
|
export interface OrchestratorAgentOptions<I extends Message = Message, O extends Message = Message> extends Omit<AIAgentOptions<I, O>, "instructions"> {
|
|
9
|
-
objective
|
|
9
|
+
objective?: PromptBuilder;
|
|
10
10
|
planner?: OrchestratorAgent<I, O>["planner"];
|
|
11
11
|
worker?: OrchestratorAgent<I, O>["worker"];
|
|
12
12
|
completer?: OrchestratorAgent<I, O>["completer"];
|
|
@@ -17,7 +17,7 @@ export interface OrchestratorAgentOptions<I extends Message = Message, O extends
|
|
|
17
17
|
stateManagement?: StateManagementOptions;
|
|
18
18
|
}
|
|
19
19
|
export interface LoadOrchestratorAgentOptions<I extends Message = Message, O extends Message = Message> extends Omit<AIAgentOptions<I, O>, "instructions"> {
|
|
20
|
-
objective
|
|
20
|
+
objective?: string | PromptBuilder | Instructions;
|
|
21
21
|
planner?: NestAgentSchema | {
|
|
22
22
|
instructions?: string | PromptBuilder | Instructions;
|
|
23
23
|
};
|
|
@@ -62,7 +62,7 @@ export declare class OrchestratorAgent<I extends Message = Message, O extends Me
|
|
|
62
62
|
* @param options - Configuration options for the Orchestrator Agent
|
|
63
63
|
*/
|
|
64
64
|
constructor(options: OrchestratorAgentOptions<I, O>);
|
|
65
|
-
private objective
|
|
65
|
+
private objective?;
|
|
66
66
|
private planner;
|
|
67
67
|
private worker;
|
|
68
68
|
private completer;
|
|
@@ -118,45 +118,12 @@ export declare const executionStateSchema: z.ZodObject<{
|
|
|
118
118
|
}[];
|
|
119
119
|
}>;
|
|
120
120
|
export interface PlannerInput extends Message {
|
|
121
|
-
objective
|
|
122
|
-
executionState
|
|
121
|
+
objective?: string;
|
|
122
|
+
executionState?: ExecutionState;
|
|
123
123
|
}
|
|
124
124
|
export declare const plannerInputSchema: z.ZodObject<{
|
|
125
|
-
objective: z.
|
|
126
|
-
executionState: z.
|
|
127
|
-
tasks: z.ZodArray<z.ZodObject<{
|
|
128
|
-
task: z.ZodString;
|
|
129
|
-
status: z.ZodEnum<["pending", "completed", "failed"]>;
|
|
130
|
-
result: z.ZodOptional<z.ZodUnknown>;
|
|
131
|
-
error: z.ZodOptional<z.ZodObject<{
|
|
132
|
-
message: z.ZodString;
|
|
133
|
-
}, "strip", z.ZodTypeAny, {
|
|
134
|
-
message: string;
|
|
135
|
-
}, {
|
|
136
|
-
message: string;
|
|
137
|
-
}>>;
|
|
138
|
-
createdAt: z.ZodOptional<z.ZodNumber>;
|
|
139
|
-
completedAt: z.ZodOptional<z.ZodNumber>;
|
|
140
|
-
}, "strip", z.ZodTypeAny, {
|
|
141
|
-
status: "pending" | "completed" | "failed";
|
|
142
|
-
task: string;
|
|
143
|
-
error?: {
|
|
144
|
-
message: string;
|
|
145
|
-
} | undefined;
|
|
146
|
-
result?: unknown;
|
|
147
|
-
createdAt?: number | undefined;
|
|
148
|
-
completedAt?: number | undefined;
|
|
149
|
-
}, {
|
|
150
|
-
status: "pending" | "completed" | "failed";
|
|
151
|
-
task: string;
|
|
152
|
-
error?: {
|
|
153
|
-
message: string;
|
|
154
|
-
} | undefined;
|
|
155
|
-
result?: unknown;
|
|
156
|
-
createdAt?: number | undefined;
|
|
157
|
-
completedAt?: number | undefined;
|
|
158
|
-
}>, "many">;
|
|
159
|
-
}, "strip", z.ZodTypeAny, {
|
|
125
|
+
objective: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
|
|
126
|
+
executionState: z.ZodType<{
|
|
160
127
|
tasks: {
|
|
161
128
|
status: "pending" | "completed" | "failed";
|
|
162
129
|
task: string;
|
|
@@ -167,7 +134,7 @@ export declare const plannerInputSchema: z.ZodObject<{
|
|
|
167
134
|
createdAt?: number | undefined;
|
|
168
135
|
completedAt?: number | undefined;
|
|
169
136
|
}[];
|
|
170
|
-
}, {
|
|
137
|
+
} | undefined, z.ZodTypeDef, {
|
|
171
138
|
tasks: {
|
|
172
139
|
status: "pending" | "completed" | "failed";
|
|
173
140
|
task: string;
|
|
@@ -178,10 +145,10 @@ export declare const plannerInputSchema: z.ZodObject<{
|
|
|
178
145
|
createdAt?: number | undefined;
|
|
179
146
|
completedAt?: number | undefined;
|
|
180
147
|
}[];
|
|
181
|
-
}>;
|
|
148
|
+
} | undefined>;
|
|
182
149
|
}, "strip", z.ZodTypeAny, {
|
|
183
|
-
objective
|
|
184
|
-
executionState
|
|
150
|
+
objective?: string | undefined;
|
|
151
|
+
executionState?: {
|
|
185
152
|
tasks: {
|
|
186
153
|
status: "pending" | "completed" | "failed";
|
|
187
154
|
task: string;
|
|
@@ -192,10 +159,10 @@ export declare const plannerInputSchema: z.ZodObject<{
|
|
|
192
159
|
createdAt?: number | undefined;
|
|
193
160
|
completedAt?: number | undefined;
|
|
194
161
|
}[];
|
|
195
|
-
};
|
|
162
|
+
} | undefined;
|
|
196
163
|
}, {
|
|
197
|
-
objective
|
|
198
|
-
executionState
|
|
164
|
+
objective?: string | undefined;
|
|
165
|
+
executionState?: {
|
|
199
166
|
tasks: {
|
|
200
167
|
status: "pending" | "completed" | "failed";
|
|
201
168
|
task: string;
|
|
@@ -206,7 +173,7 @@ export declare const plannerInputSchema: z.ZodObject<{
|
|
|
206
173
|
createdAt?: number | undefined;
|
|
207
174
|
completedAt?: number | undefined;
|
|
208
175
|
}[];
|
|
209
|
-
};
|
|
176
|
+
} | undefined;
|
|
210
177
|
}>;
|
|
211
178
|
export interface PlannerOutput extends Message {
|
|
212
179
|
nextTask?: string;
|
|
@@ -223,47 +190,14 @@ export declare const plannerOutputSchema: z.ZodObject<{
|
|
|
223
190
|
finished?: boolean | undefined;
|
|
224
191
|
}>;
|
|
225
192
|
export interface WorkerInput extends Message {
|
|
226
|
-
objective
|
|
227
|
-
executionState
|
|
228
|
-
task
|
|
193
|
+
objective?: string;
|
|
194
|
+
executionState?: ExecutionState;
|
|
195
|
+
task?: string;
|
|
229
196
|
}
|
|
230
197
|
export declare const workerInputSchema: z.ZodObject<{
|
|
231
|
-
objective: z.
|
|
232
|
-
task: z.
|
|
233
|
-
executionState: z.
|
|
234
|
-
tasks: z.ZodArray<z.ZodObject<{
|
|
235
|
-
task: z.ZodString;
|
|
236
|
-
status: z.ZodEnum<["pending", "completed", "failed"]>;
|
|
237
|
-
result: z.ZodOptional<z.ZodUnknown>;
|
|
238
|
-
error: z.ZodOptional<z.ZodObject<{
|
|
239
|
-
message: z.ZodString;
|
|
240
|
-
}, "strip", z.ZodTypeAny, {
|
|
241
|
-
message: string;
|
|
242
|
-
}, {
|
|
243
|
-
message: string;
|
|
244
|
-
}>>;
|
|
245
|
-
createdAt: z.ZodOptional<z.ZodNumber>;
|
|
246
|
-
completedAt: z.ZodOptional<z.ZodNumber>;
|
|
247
|
-
}, "strip", z.ZodTypeAny, {
|
|
248
|
-
status: "pending" | "completed" | "failed";
|
|
249
|
-
task: string;
|
|
250
|
-
error?: {
|
|
251
|
-
message: string;
|
|
252
|
-
} | undefined;
|
|
253
|
-
result?: unknown;
|
|
254
|
-
createdAt?: number | undefined;
|
|
255
|
-
completedAt?: number | undefined;
|
|
256
|
-
}, {
|
|
257
|
-
status: "pending" | "completed" | "failed";
|
|
258
|
-
task: string;
|
|
259
|
-
error?: {
|
|
260
|
-
message: string;
|
|
261
|
-
} | undefined;
|
|
262
|
-
result?: unknown;
|
|
263
|
-
createdAt?: number | undefined;
|
|
264
|
-
completedAt?: number | undefined;
|
|
265
|
-
}>, "many">;
|
|
266
|
-
}, "strip", z.ZodTypeAny, {
|
|
198
|
+
objective: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
|
|
199
|
+
task: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
|
|
200
|
+
executionState: z.ZodType<{
|
|
267
201
|
tasks: {
|
|
268
202
|
status: "pending" | "completed" | "failed";
|
|
269
203
|
task: string;
|
|
@@ -274,7 +208,7 @@ export declare const workerInputSchema: z.ZodObject<{
|
|
|
274
208
|
createdAt?: number | undefined;
|
|
275
209
|
completedAt?: number | undefined;
|
|
276
210
|
}[];
|
|
277
|
-
}, {
|
|
211
|
+
} | undefined, z.ZodTypeDef, {
|
|
278
212
|
tasks: {
|
|
279
213
|
status: "pending" | "completed" | "failed";
|
|
280
214
|
task: string;
|
|
@@ -285,11 +219,11 @@ export declare const workerInputSchema: z.ZodObject<{
|
|
|
285
219
|
createdAt?: number | undefined;
|
|
286
220
|
completedAt?: number | undefined;
|
|
287
221
|
}[];
|
|
288
|
-
}>;
|
|
222
|
+
} | undefined>;
|
|
289
223
|
}, "strip", z.ZodTypeAny, {
|
|
290
|
-
task
|
|
291
|
-
objective
|
|
292
|
-
executionState
|
|
224
|
+
task?: string | undefined;
|
|
225
|
+
objective?: string | undefined;
|
|
226
|
+
executionState?: {
|
|
293
227
|
tasks: {
|
|
294
228
|
status: "pending" | "completed" | "failed";
|
|
295
229
|
task: string;
|
|
@@ -300,11 +234,11 @@ export declare const workerInputSchema: z.ZodObject<{
|
|
|
300
234
|
createdAt?: number | undefined;
|
|
301
235
|
completedAt?: number | undefined;
|
|
302
236
|
}[];
|
|
303
|
-
};
|
|
237
|
+
} | undefined;
|
|
304
238
|
}, {
|
|
305
|
-
task
|
|
306
|
-
objective
|
|
307
|
-
executionState
|
|
239
|
+
task?: string | undefined;
|
|
240
|
+
objective?: string | undefined;
|
|
241
|
+
executionState?: {
|
|
308
242
|
tasks: {
|
|
309
243
|
status: "pending" | "completed" | "failed";
|
|
310
244
|
task: string;
|
|
@@ -315,7 +249,7 @@ export declare const workerInputSchema: z.ZodObject<{
|
|
|
315
249
|
createdAt?: number | undefined;
|
|
316
250
|
completedAt?: number | undefined;
|
|
317
251
|
}[];
|
|
318
|
-
};
|
|
252
|
+
} | undefined;
|
|
319
253
|
}>;
|
|
320
254
|
/**
|
|
321
255
|
* Worker output structure
|
|
@@ -354,45 +288,12 @@ export declare const workerOutputSchema: z.ZodObject<{
|
|
|
354
288
|
result?: string | undefined;
|
|
355
289
|
}>;
|
|
356
290
|
export interface CompleterInput extends Message {
|
|
357
|
-
objective
|
|
358
|
-
executionState
|
|
291
|
+
objective?: string;
|
|
292
|
+
executionState?: ExecutionState;
|
|
359
293
|
}
|
|
360
294
|
export declare const completerInputSchema: z.ZodObject<{
|
|
361
|
-
objective: z.
|
|
362
|
-
executionState: z.
|
|
363
|
-
tasks: z.ZodArray<z.ZodObject<{
|
|
364
|
-
task: z.ZodString;
|
|
365
|
-
status: z.ZodEnum<["pending", "completed", "failed"]>;
|
|
366
|
-
result: z.ZodOptional<z.ZodUnknown>;
|
|
367
|
-
error: z.ZodOptional<z.ZodObject<{
|
|
368
|
-
message: z.ZodString;
|
|
369
|
-
}, "strip", z.ZodTypeAny, {
|
|
370
|
-
message: string;
|
|
371
|
-
}, {
|
|
372
|
-
message: string;
|
|
373
|
-
}>>;
|
|
374
|
-
createdAt: z.ZodOptional<z.ZodNumber>;
|
|
375
|
-
completedAt: z.ZodOptional<z.ZodNumber>;
|
|
376
|
-
}, "strip", z.ZodTypeAny, {
|
|
377
|
-
status: "pending" | "completed" | "failed";
|
|
378
|
-
task: string;
|
|
379
|
-
error?: {
|
|
380
|
-
message: string;
|
|
381
|
-
} | undefined;
|
|
382
|
-
result?: unknown;
|
|
383
|
-
createdAt?: number | undefined;
|
|
384
|
-
completedAt?: number | undefined;
|
|
385
|
-
}, {
|
|
386
|
-
status: "pending" | "completed" | "failed";
|
|
387
|
-
task: string;
|
|
388
|
-
error?: {
|
|
389
|
-
message: string;
|
|
390
|
-
} | undefined;
|
|
391
|
-
result?: unknown;
|
|
392
|
-
createdAt?: number | undefined;
|
|
393
|
-
completedAt?: number | undefined;
|
|
394
|
-
}>, "many">;
|
|
395
|
-
}, "strip", z.ZodTypeAny, {
|
|
295
|
+
objective: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
|
|
296
|
+
executionState: z.ZodType<{
|
|
396
297
|
tasks: {
|
|
397
298
|
status: "pending" | "completed" | "failed";
|
|
398
299
|
task: string;
|
|
@@ -403,7 +304,7 @@ export declare const completerInputSchema: z.ZodObject<{
|
|
|
403
304
|
createdAt?: number | undefined;
|
|
404
305
|
completedAt?: number | undefined;
|
|
405
306
|
}[];
|
|
406
|
-
}, {
|
|
307
|
+
} | undefined, z.ZodTypeDef, {
|
|
407
308
|
tasks: {
|
|
408
309
|
status: "pending" | "completed" | "failed";
|
|
409
310
|
task: string;
|
|
@@ -414,10 +315,10 @@ export declare const completerInputSchema: z.ZodObject<{
|
|
|
414
315
|
createdAt?: number | undefined;
|
|
415
316
|
completedAt?: number | undefined;
|
|
416
317
|
}[];
|
|
417
|
-
}>;
|
|
318
|
+
} | undefined>;
|
|
418
319
|
}, "strip", z.ZodTypeAny, {
|
|
419
|
-
objective
|
|
420
|
-
executionState
|
|
320
|
+
objective?: string | undefined;
|
|
321
|
+
executionState?: {
|
|
421
322
|
tasks: {
|
|
422
323
|
status: "pending" | "completed" | "failed";
|
|
423
324
|
task: string;
|
|
@@ -428,10 +329,10 @@ export declare const completerInputSchema: z.ZodObject<{
|
|
|
428
329
|
createdAt?: number | undefined;
|
|
429
330
|
completedAt?: number | undefined;
|
|
430
331
|
}[];
|
|
431
|
-
};
|
|
332
|
+
} | undefined;
|
|
432
333
|
}, {
|
|
433
|
-
objective
|
|
434
|
-
executionState
|
|
334
|
+
objective?: string | undefined;
|
|
335
|
+
executionState?: {
|
|
435
336
|
tasks: {
|
|
436
337
|
status: "pending" | "completed" | "failed";
|
|
437
338
|
task: string;
|
|
@@ -442,7 +343,7 @@ export declare const completerInputSchema: z.ZodObject<{
|
|
|
442
343
|
createdAt?: number | undefined;
|
|
443
344
|
completedAt?: number | undefined;
|
|
444
345
|
}[];
|
|
445
|
-
};
|
|
346
|
+
} | undefined;
|
|
446
347
|
}>;
|
|
447
348
|
/**
|
|
448
349
|
* Default maximum number of task execution iterations
|
|
@@ -6,7 +6,7 @@ import { type StateManagementOptions } from "./type.js";
|
|
|
6
6
|
* Configuration options for the Orchestrator Agent
|
|
7
7
|
*/
|
|
8
8
|
export interface OrchestratorAgentOptions<I extends Message = Message, O extends Message = Message> extends Omit<AIAgentOptions<I, O>, "instructions"> {
|
|
9
|
-
objective
|
|
9
|
+
objective?: PromptBuilder;
|
|
10
10
|
planner?: OrchestratorAgent<I, O>["planner"];
|
|
11
11
|
worker?: OrchestratorAgent<I, O>["worker"];
|
|
12
12
|
completer?: OrchestratorAgent<I, O>["completer"];
|
|
@@ -17,7 +17,7 @@ export interface OrchestratorAgentOptions<I extends Message = Message, O extends
|
|
|
17
17
|
stateManagement?: StateManagementOptions;
|
|
18
18
|
}
|
|
19
19
|
export interface LoadOrchestratorAgentOptions<I extends Message = Message, O extends Message = Message> extends Omit<AIAgentOptions<I, O>, "instructions"> {
|
|
20
|
-
objective
|
|
20
|
+
objective?: string | PromptBuilder | Instructions;
|
|
21
21
|
planner?: NestAgentSchema | {
|
|
22
22
|
instructions?: string | PromptBuilder | Instructions;
|
|
23
23
|
};
|
|
@@ -62,7 +62,7 @@ export declare class OrchestratorAgent<I extends Message = Message, O extends Me
|
|
|
62
62
|
* @param options - Configuration options for the Orchestrator Agent
|
|
63
63
|
*/
|
|
64
64
|
constructor(options: OrchestratorAgentOptions<I, O>);
|
|
65
|
-
private objective
|
|
65
|
+
private objective?;
|
|
66
66
|
private planner;
|
|
67
67
|
private worker;
|
|
68
68
|
private completer;
|
|
@@ -4,7 +4,7 @@ import { instructionsToPromptBuilder, loadNestAgent, } from "@aigne/core/loader/
|
|
|
4
4
|
import { camelizeSchema, optionalize } from "@aigne/core/loader/schema.js";
|
|
5
5
|
import { isAgent } from "@aigne/core/utils/agent-utils.js";
|
|
6
6
|
import { estimateTokens } from "@aigne/core/utils/token-estimator.js";
|
|
7
|
-
import { omit } from "@aigne/core/utils/type-utils.js";
|
|
7
|
+
import { omit, pick } from "@aigne/core/utils/type-utils.js";
|
|
8
8
|
import { z } from "zod";
|
|
9
9
|
import { ORCHESTRATOR_COMPLETE_PROMPT, TODO_PLANNER_PROMPT_TEMPLATE, TODO_WORKER_PROMPT_TEMPLATE, } from "./prompt.js";
|
|
10
10
|
import { completerInputSchema, DEFAULT_MAX_ITERATIONS, plannerInputSchema, plannerOutputSchema, stateManagementOptionsSchema, workerInputSchema, workerOutputSchema, } from "./type.js";
|
|
@@ -57,7 +57,7 @@ export class OrchestratorAgent extends AIAgent {
|
|
|
57
57
|
const valid = await schema.parseAsync(parsed);
|
|
58
58
|
return new OrchestratorAgent({
|
|
59
59
|
...parsed,
|
|
60
|
-
objective: instructionsToPromptBuilder(valid.objective),
|
|
60
|
+
objective: valid.objective && instructionsToPromptBuilder(valid.objective),
|
|
61
61
|
planner: valid.planner
|
|
62
62
|
? (await loadNestAgent(filepath, valid.planner, options, {
|
|
63
63
|
...defaultPlannerOptions,
|
|
@@ -167,10 +167,10 @@ export class OrchestratorAgent extends AIAgent {
|
|
|
167
167
|
const model = this.model || options.model || options.context.model;
|
|
168
168
|
if (!model)
|
|
169
169
|
throw new Error("model is required to run OrchestratorAgent");
|
|
170
|
-
const
|
|
170
|
+
const objective = (await this.objective?.buildPrompt({
|
|
171
171
|
input,
|
|
172
172
|
context: options.context,
|
|
173
|
-
});
|
|
173
|
+
}))?.prompt;
|
|
174
174
|
const executionState = { tasks: [] };
|
|
175
175
|
let iterationCount = 0;
|
|
176
176
|
const maxIterations = this.stateManagement?.maxIterations ?? DEFAULT_MAX_ITERATIONS;
|
|
@@ -190,13 +190,22 @@ export class OrchestratorAgent extends AIAgent {
|
|
|
190
190
|
iterationCount++;
|
|
191
191
|
// Compress state for planner input if needed
|
|
192
192
|
const compressedState = this.compressState(executionState);
|
|
193
|
-
const plan = await this.invokeChildAgent(this.planner, {
|
|
193
|
+
const plan = await this.invokeChildAgent(this.planner, {
|
|
194
|
+
objective,
|
|
195
|
+
executionState: compressedState,
|
|
196
|
+
...pick(input, this.planner.inputKeys),
|
|
197
|
+
}, { ...options, model, streaming: false });
|
|
194
198
|
if (plan.finished || !plan.nextTask) {
|
|
195
199
|
break;
|
|
196
200
|
}
|
|
197
201
|
const task = plan.nextTask;
|
|
198
202
|
const createdAt = Date.now();
|
|
199
|
-
const taskResult = await this.invokeChildAgent(this.worker, {
|
|
203
|
+
const taskResult = await this.invokeChildAgent(this.worker, {
|
|
204
|
+
objective,
|
|
205
|
+
executionState: compressedState,
|
|
206
|
+
task,
|
|
207
|
+
...pick(input, this.worker.inputKeys),
|
|
208
|
+
}, { ...options, model, streaming: false })
|
|
200
209
|
.then((res) => {
|
|
201
210
|
if (res.error || res.success === false) {
|
|
202
211
|
return { status: "failed", result: res.result, error: res.error };
|
|
@@ -216,7 +225,11 @@ export class OrchestratorAgent extends AIAgent {
|
|
|
216
225
|
}
|
|
217
226
|
// Compress state for completer input if needed
|
|
218
227
|
const compressedState = this.compressState(executionState);
|
|
219
|
-
yield* await this.invokeChildAgent(this.completer, {
|
|
228
|
+
yield* await this.invokeChildAgent(this.completer, {
|
|
229
|
+
objective,
|
|
230
|
+
executionState: compressedState,
|
|
231
|
+
...pick(input, this.completer.inputKeys),
|
|
232
|
+
}, { ...options, model, streaming: true });
|
|
220
233
|
}
|
|
221
234
|
}
|
|
222
235
|
export default OrchestratorAgent;
|
|
@@ -224,7 +237,7 @@ function getOrchestratorAgentSchema({ filepath }) {
|
|
|
224
237
|
const nestAgentSchema = getNestAgentSchema({ filepath });
|
|
225
238
|
const instructionsSchema = getInstructionsSchema({ filepath });
|
|
226
239
|
return camelizeSchema(z.object({
|
|
227
|
-
objective: instructionsSchema,
|
|
240
|
+
objective: optionalize(instructionsSchema),
|
|
228
241
|
planner: optionalize(nestAgentSchema),
|
|
229
242
|
worker: optionalize(nestAgentSchema),
|
|
230
243
|
completer: optionalize(nestAgentSchema),
|
|
@@ -118,45 +118,12 @@ export declare const executionStateSchema: z.ZodObject<{
|
|
|
118
118
|
}[];
|
|
119
119
|
}>;
|
|
120
120
|
export interface PlannerInput extends Message {
|
|
121
|
-
objective
|
|
122
|
-
executionState
|
|
121
|
+
objective?: string;
|
|
122
|
+
executionState?: ExecutionState;
|
|
123
123
|
}
|
|
124
124
|
export declare const plannerInputSchema: z.ZodObject<{
|
|
125
|
-
objective: z.
|
|
126
|
-
executionState: z.
|
|
127
|
-
tasks: z.ZodArray<z.ZodObject<{
|
|
128
|
-
task: z.ZodString;
|
|
129
|
-
status: z.ZodEnum<["pending", "completed", "failed"]>;
|
|
130
|
-
result: z.ZodOptional<z.ZodUnknown>;
|
|
131
|
-
error: z.ZodOptional<z.ZodObject<{
|
|
132
|
-
message: z.ZodString;
|
|
133
|
-
}, "strip", z.ZodTypeAny, {
|
|
134
|
-
message: string;
|
|
135
|
-
}, {
|
|
136
|
-
message: string;
|
|
137
|
-
}>>;
|
|
138
|
-
createdAt: z.ZodOptional<z.ZodNumber>;
|
|
139
|
-
completedAt: z.ZodOptional<z.ZodNumber>;
|
|
140
|
-
}, "strip", z.ZodTypeAny, {
|
|
141
|
-
status: "pending" | "completed" | "failed";
|
|
142
|
-
task: string;
|
|
143
|
-
error?: {
|
|
144
|
-
message: string;
|
|
145
|
-
} | undefined;
|
|
146
|
-
result?: unknown;
|
|
147
|
-
createdAt?: number | undefined;
|
|
148
|
-
completedAt?: number | undefined;
|
|
149
|
-
}, {
|
|
150
|
-
status: "pending" | "completed" | "failed";
|
|
151
|
-
task: string;
|
|
152
|
-
error?: {
|
|
153
|
-
message: string;
|
|
154
|
-
} | undefined;
|
|
155
|
-
result?: unknown;
|
|
156
|
-
createdAt?: number | undefined;
|
|
157
|
-
completedAt?: number | undefined;
|
|
158
|
-
}>, "many">;
|
|
159
|
-
}, "strip", z.ZodTypeAny, {
|
|
125
|
+
objective: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
|
|
126
|
+
executionState: z.ZodType<{
|
|
160
127
|
tasks: {
|
|
161
128
|
status: "pending" | "completed" | "failed";
|
|
162
129
|
task: string;
|
|
@@ -167,7 +134,7 @@ export declare const plannerInputSchema: z.ZodObject<{
|
|
|
167
134
|
createdAt?: number | undefined;
|
|
168
135
|
completedAt?: number | undefined;
|
|
169
136
|
}[];
|
|
170
|
-
}, {
|
|
137
|
+
} | undefined, z.ZodTypeDef, {
|
|
171
138
|
tasks: {
|
|
172
139
|
status: "pending" | "completed" | "failed";
|
|
173
140
|
task: string;
|
|
@@ -178,10 +145,10 @@ export declare const plannerInputSchema: z.ZodObject<{
|
|
|
178
145
|
createdAt?: number | undefined;
|
|
179
146
|
completedAt?: number | undefined;
|
|
180
147
|
}[];
|
|
181
|
-
}>;
|
|
148
|
+
} | undefined>;
|
|
182
149
|
}, "strip", z.ZodTypeAny, {
|
|
183
|
-
objective
|
|
184
|
-
executionState
|
|
150
|
+
objective?: string | undefined;
|
|
151
|
+
executionState?: {
|
|
185
152
|
tasks: {
|
|
186
153
|
status: "pending" | "completed" | "failed";
|
|
187
154
|
task: string;
|
|
@@ -192,10 +159,10 @@ export declare const plannerInputSchema: z.ZodObject<{
|
|
|
192
159
|
createdAt?: number | undefined;
|
|
193
160
|
completedAt?: number | undefined;
|
|
194
161
|
}[];
|
|
195
|
-
};
|
|
162
|
+
} | undefined;
|
|
196
163
|
}, {
|
|
197
|
-
objective
|
|
198
|
-
executionState
|
|
164
|
+
objective?: string | undefined;
|
|
165
|
+
executionState?: {
|
|
199
166
|
tasks: {
|
|
200
167
|
status: "pending" | "completed" | "failed";
|
|
201
168
|
task: string;
|
|
@@ -206,7 +173,7 @@ export declare const plannerInputSchema: z.ZodObject<{
|
|
|
206
173
|
createdAt?: number | undefined;
|
|
207
174
|
completedAt?: number | undefined;
|
|
208
175
|
}[];
|
|
209
|
-
};
|
|
176
|
+
} | undefined;
|
|
210
177
|
}>;
|
|
211
178
|
export interface PlannerOutput extends Message {
|
|
212
179
|
nextTask?: string;
|
|
@@ -223,47 +190,14 @@ export declare const plannerOutputSchema: z.ZodObject<{
|
|
|
223
190
|
finished?: boolean | undefined;
|
|
224
191
|
}>;
|
|
225
192
|
export interface WorkerInput extends Message {
|
|
226
|
-
objective
|
|
227
|
-
executionState
|
|
228
|
-
task
|
|
193
|
+
objective?: string;
|
|
194
|
+
executionState?: ExecutionState;
|
|
195
|
+
task?: string;
|
|
229
196
|
}
|
|
230
197
|
export declare const workerInputSchema: z.ZodObject<{
|
|
231
|
-
objective: z.
|
|
232
|
-
task: z.
|
|
233
|
-
executionState: z.
|
|
234
|
-
tasks: z.ZodArray<z.ZodObject<{
|
|
235
|
-
task: z.ZodString;
|
|
236
|
-
status: z.ZodEnum<["pending", "completed", "failed"]>;
|
|
237
|
-
result: z.ZodOptional<z.ZodUnknown>;
|
|
238
|
-
error: z.ZodOptional<z.ZodObject<{
|
|
239
|
-
message: z.ZodString;
|
|
240
|
-
}, "strip", z.ZodTypeAny, {
|
|
241
|
-
message: string;
|
|
242
|
-
}, {
|
|
243
|
-
message: string;
|
|
244
|
-
}>>;
|
|
245
|
-
createdAt: z.ZodOptional<z.ZodNumber>;
|
|
246
|
-
completedAt: z.ZodOptional<z.ZodNumber>;
|
|
247
|
-
}, "strip", z.ZodTypeAny, {
|
|
248
|
-
status: "pending" | "completed" | "failed";
|
|
249
|
-
task: string;
|
|
250
|
-
error?: {
|
|
251
|
-
message: string;
|
|
252
|
-
} | undefined;
|
|
253
|
-
result?: unknown;
|
|
254
|
-
createdAt?: number | undefined;
|
|
255
|
-
completedAt?: number | undefined;
|
|
256
|
-
}, {
|
|
257
|
-
status: "pending" | "completed" | "failed";
|
|
258
|
-
task: string;
|
|
259
|
-
error?: {
|
|
260
|
-
message: string;
|
|
261
|
-
} | undefined;
|
|
262
|
-
result?: unknown;
|
|
263
|
-
createdAt?: number | undefined;
|
|
264
|
-
completedAt?: number | undefined;
|
|
265
|
-
}>, "many">;
|
|
266
|
-
}, "strip", z.ZodTypeAny, {
|
|
198
|
+
objective: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
|
|
199
|
+
task: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
|
|
200
|
+
executionState: z.ZodType<{
|
|
267
201
|
tasks: {
|
|
268
202
|
status: "pending" | "completed" | "failed";
|
|
269
203
|
task: string;
|
|
@@ -274,7 +208,7 @@ export declare const workerInputSchema: z.ZodObject<{
|
|
|
274
208
|
createdAt?: number | undefined;
|
|
275
209
|
completedAt?: number | undefined;
|
|
276
210
|
}[];
|
|
277
|
-
}, {
|
|
211
|
+
} | undefined, z.ZodTypeDef, {
|
|
278
212
|
tasks: {
|
|
279
213
|
status: "pending" | "completed" | "failed";
|
|
280
214
|
task: string;
|
|
@@ -285,11 +219,11 @@ export declare const workerInputSchema: z.ZodObject<{
|
|
|
285
219
|
createdAt?: number | undefined;
|
|
286
220
|
completedAt?: number | undefined;
|
|
287
221
|
}[];
|
|
288
|
-
}>;
|
|
222
|
+
} | undefined>;
|
|
289
223
|
}, "strip", z.ZodTypeAny, {
|
|
290
|
-
task
|
|
291
|
-
objective
|
|
292
|
-
executionState
|
|
224
|
+
task?: string | undefined;
|
|
225
|
+
objective?: string | undefined;
|
|
226
|
+
executionState?: {
|
|
293
227
|
tasks: {
|
|
294
228
|
status: "pending" | "completed" | "failed";
|
|
295
229
|
task: string;
|
|
@@ -300,11 +234,11 @@ export declare const workerInputSchema: z.ZodObject<{
|
|
|
300
234
|
createdAt?: number | undefined;
|
|
301
235
|
completedAt?: number | undefined;
|
|
302
236
|
}[];
|
|
303
|
-
};
|
|
237
|
+
} | undefined;
|
|
304
238
|
}, {
|
|
305
|
-
task
|
|
306
|
-
objective
|
|
307
|
-
executionState
|
|
239
|
+
task?: string | undefined;
|
|
240
|
+
objective?: string | undefined;
|
|
241
|
+
executionState?: {
|
|
308
242
|
tasks: {
|
|
309
243
|
status: "pending" | "completed" | "failed";
|
|
310
244
|
task: string;
|
|
@@ -315,7 +249,7 @@ export declare const workerInputSchema: z.ZodObject<{
|
|
|
315
249
|
createdAt?: number | undefined;
|
|
316
250
|
completedAt?: number | undefined;
|
|
317
251
|
}[];
|
|
318
|
-
};
|
|
252
|
+
} | undefined;
|
|
319
253
|
}>;
|
|
320
254
|
/**
|
|
321
255
|
* Worker output structure
|
|
@@ -354,45 +288,12 @@ export declare const workerOutputSchema: z.ZodObject<{
|
|
|
354
288
|
result?: string | undefined;
|
|
355
289
|
}>;
|
|
356
290
|
export interface CompleterInput extends Message {
|
|
357
|
-
objective
|
|
358
|
-
executionState
|
|
291
|
+
objective?: string;
|
|
292
|
+
executionState?: ExecutionState;
|
|
359
293
|
}
|
|
360
294
|
export declare const completerInputSchema: z.ZodObject<{
|
|
361
|
-
objective: z.
|
|
362
|
-
executionState: z.
|
|
363
|
-
tasks: z.ZodArray<z.ZodObject<{
|
|
364
|
-
task: z.ZodString;
|
|
365
|
-
status: z.ZodEnum<["pending", "completed", "failed"]>;
|
|
366
|
-
result: z.ZodOptional<z.ZodUnknown>;
|
|
367
|
-
error: z.ZodOptional<z.ZodObject<{
|
|
368
|
-
message: z.ZodString;
|
|
369
|
-
}, "strip", z.ZodTypeAny, {
|
|
370
|
-
message: string;
|
|
371
|
-
}, {
|
|
372
|
-
message: string;
|
|
373
|
-
}>>;
|
|
374
|
-
createdAt: z.ZodOptional<z.ZodNumber>;
|
|
375
|
-
completedAt: z.ZodOptional<z.ZodNumber>;
|
|
376
|
-
}, "strip", z.ZodTypeAny, {
|
|
377
|
-
status: "pending" | "completed" | "failed";
|
|
378
|
-
task: string;
|
|
379
|
-
error?: {
|
|
380
|
-
message: string;
|
|
381
|
-
} | undefined;
|
|
382
|
-
result?: unknown;
|
|
383
|
-
createdAt?: number | undefined;
|
|
384
|
-
completedAt?: number | undefined;
|
|
385
|
-
}, {
|
|
386
|
-
status: "pending" | "completed" | "failed";
|
|
387
|
-
task: string;
|
|
388
|
-
error?: {
|
|
389
|
-
message: string;
|
|
390
|
-
} | undefined;
|
|
391
|
-
result?: unknown;
|
|
392
|
-
createdAt?: number | undefined;
|
|
393
|
-
completedAt?: number | undefined;
|
|
394
|
-
}>, "many">;
|
|
395
|
-
}, "strip", z.ZodTypeAny, {
|
|
295
|
+
objective: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
|
|
296
|
+
executionState: z.ZodType<{
|
|
396
297
|
tasks: {
|
|
397
298
|
status: "pending" | "completed" | "failed";
|
|
398
299
|
task: string;
|
|
@@ -403,7 +304,7 @@ export declare const completerInputSchema: z.ZodObject<{
|
|
|
403
304
|
createdAt?: number | undefined;
|
|
404
305
|
completedAt?: number | undefined;
|
|
405
306
|
}[];
|
|
406
|
-
}, {
|
|
307
|
+
} | undefined, z.ZodTypeDef, {
|
|
407
308
|
tasks: {
|
|
408
309
|
status: "pending" | "completed" | "failed";
|
|
409
310
|
task: string;
|
|
@@ -414,10 +315,10 @@ export declare const completerInputSchema: z.ZodObject<{
|
|
|
414
315
|
createdAt?: number | undefined;
|
|
415
316
|
completedAt?: number | undefined;
|
|
416
317
|
}[];
|
|
417
|
-
}>;
|
|
318
|
+
} | undefined>;
|
|
418
319
|
}, "strip", z.ZodTypeAny, {
|
|
419
|
-
objective
|
|
420
|
-
executionState
|
|
320
|
+
objective?: string | undefined;
|
|
321
|
+
executionState?: {
|
|
421
322
|
tasks: {
|
|
422
323
|
status: "pending" | "completed" | "failed";
|
|
423
324
|
task: string;
|
|
@@ -428,10 +329,10 @@ export declare const completerInputSchema: z.ZodObject<{
|
|
|
428
329
|
createdAt?: number | undefined;
|
|
429
330
|
completedAt?: number | undefined;
|
|
430
331
|
}[];
|
|
431
|
-
};
|
|
332
|
+
} | undefined;
|
|
432
333
|
}, {
|
|
433
|
-
objective
|
|
434
|
-
executionState
|
|
334
|
+
objective?: string | undefined;
|
|
335
|
+
executionState?: {
|
|
435
336
|
tasks: {
|
|
436
337
|
status: "pending" | "completed" | "failed";
|
|
437
338
|
task: string;
|
|
@@ -442,7 +343,7 @@ export declare const completerInputSchema: z.ZodObject<{
|
|
|
442
343
|
createdAt?: number | undefined;
|
|
443
344
|
completedAt?: number | undefined;
|
|
444
345
|
}[];
|
|
445
|
-
};
|
|
346
|
+
} | undefined;
|
|
446
347
|
}>;
|
|
447
348
|
/**
|
|
448
349
|
* Default maximum number of task execution iterations
|
|
@@ -21,8 +21,8 @@ export const executionStateSchema = z.object({
|
|
|
21
21
|
.describe("The list of tasks that have been executed along with their results."),
|
|
22
22
|
});
|
|
23
23
|
export const plannerInputSchema = z.object({
|
|
24
|
-
objective: z.string().describe("The user's overall objective."),
|
|
25
|
-
executionState: executionStateSchema,
|
|
24
|
+
objective: optionalize(z.string().describe("The user's overall objective.")),
|
|
25
|
+
executionState: optionalize(executionStateSchema),
|
|
26
26
|
});
|
|
27
27
|
export const plannerOutputSchema = z.object({
|
|
28
28
|
nextTask: z
|
|
@@ -44,9 +44,9 @@ When finished is true, nextTask should be omitted.
|
|
|
44
44
|
`),
|
|
45
45
|
});
|
|
46
46
|
export const workerInputSchema = z.object({
|
|
47
|
-
objective: z.string().describe("The user's overall objective."),
|
|
48
|
-
task: z.string().describe("The specific task assigned to the worker for execution."),
|
|
49
|
-
executionState: executionStateSchema,
|
|
47
|
+
objective: optionalize(z.string().describe("The user's overall objective.")),
|
|
48
|
+
task: optionalize(z.string().describe("The specific task assigned to the worker for execution.")),
|
|
49
|
+
executionState: optionalize(executionStateSchema),
|
|
50
50
|
});
|
|
51
51
|
export const workerOutputSchema = z.object({
|
|
52
52
|
result: z
|
|
@@ -66,8 +66,8 @@ export const workerOutputSchema = z.object({
|
|
|
66
66
|
.describe("Error details if the task failed. Only include when success is false."),
|
|
67
67
|
});
|
|
68
68
|
export const completerInputSchema = z.object({
|
|
69
|
-
objective: z.string().describe("The user's overall objective."),
|
|
70
|
-
executionState: executionStateSchema,
|
|
69
|
+
objective: optionalize(z.string().describe("The user's overall objective.")),
|
|
70
|
+
executionState: optionalize(executionStateSchema),
|
|
71
71
|
});
|
|
72
72
|
/**
|
|
73
73
|
* Default maximum number of task execution iterations
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aigne/agent-library",
|
|
3
|
-
"version": "1.23.0-beta.
|
|
3
|
+
"version": "1.23.0-beta.7",
|
|
4
4
|
"description": "Collection of agent libraries for AIGNE framework",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -55,8 +55,8 @@
|
|
|
55
55
|
"yaml": "^2.8.1",
|
|
56
56
|
"zod": "^3.25.67",
|
|
57
57
|
"zod-to-json-schema": "^3.24.6",
|
|
58
|
-
"@aigne/
|
|
59
|
-
"@aigne/
|
|
58
|
+
"@aigne/core": "^1.71.0-beta.6",
|
|
59
|
+
"@aigne/openai": "^0.16.15-beta.6",
|
|
60
60
|
"@aigne/sqlite": "^0.4.8-beta"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|