@aigne/agent-library 1.3.0 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/lib/cjs/orchestrator/index.d.ts +8 -20
- package/lib/cjs/orchestrator/index.js +71 -52
- package/lib/cjs/orchestrator/orchestrator-prompts.d.ts +49 -49
- package/lib/cjs/orchestrator/orchestrator-prompts.js +103 -40
- package/lib/cjs/package.json +1 -0
- package/lib/dts/orchestrator/index.d.ts +8 -20
- package/lib/dts/orchestrator/orchestrator-prompts.d.ts +49 -49
- package/lib/esm/orchestrator/index.d.ts +8 -20
- package/lib/esm/orchestrator/index.js +69 -53
- package/lib/esm/orchestrator/orchestrator-prompts.d.ts +49 -49
- package/lib/esm/orchestrator/orchestrator-prompts.js +101 -39
- package/lib/esm/package.json +1 -0
- package/package.json +6 -3
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
- chore: release 1.2.0
|
|
4
4
|
|
|
5
|
+
## [1.3.1](https://github.com/AIGNE-io/aigne-framework/compare/agent-library-v1.3.0...agent-library-v1.3.1) (2025-03-26)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* **orchestrator:** refactor and enhance orchestrator with step synthesis ([#31](https://github.com/AIGNE-io/aigne-framework/issues/31)) ([ba9fca0](https://github.com/AIGNE-io/aigne-framework/commit/ba9fca04fad71d49c8f4f52172b56668a94ea714))
|
|
11
|
+
|
|
5
12
|
## [1.3.0](https://github.com/AIGNE-io/aigne-framework/compare/agent-library-v1.2.0...agent-library-v1.3.0) (2025-03-24)
|
|
6
13
|
|
|
7
14
|
|
|
@@ -1,29 +1,16 @@
|
|
|
1
1
|
import { Agent, type AgentOptions, type Context, type Message } from "@aigne/core";
|
|
2
|
-
import { type FullPlanOutput, type
|
|
2
|
+
import { type FullPlanOutput, type StepWithResult } from "./orchestrator-prompts.js";
|
|
3
3
|
export * from "./orchestrator-prompts.js";
|
|
4
|
-
export interface
|
|
5
|
-
step: Step;
|
|
6
|
-
task_results: Array<TaskWithResult>;
|
|
7
|
-
}
|
|
8
|
-
export interface TaskWithResult {
|
|
9
|
-
description: string;
|
|
10
|
-
agent: string;
|
|
11
|
-
result: string;
|
|
12
|
-
}
|
|
13
|
-
export interface PlanResult extends Message {
|
|
4
|
+
export interface FullPlanWithResult {
|
|
14
5
|
objective: string;
|
|
15
6
|
plan?: FullPlanOutput;
|
|
16
|
-
|
|
7
|
+
steps: StepWithResult[];
|
|
17
8
|
result?: string;
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
export interface FullPlanInput extends Message {
|
|
21
|
-
objective: string;
|
|
22
|
-
plan_result: string;
|
|
23
|
-
agents: string;
|
|
9
|
+
status?: boolean;
|
|
24
10
|
}
|
|
25
11
|
export interface OrchestratorAgentOptions<I extends Message = Message, O extends Message = Message> extends AgentOptions<I, O> {
|
|
26
12
|
maxIterations?: number;
|
|
13
|
+
tasksConcurrency?: number;
|
|
27
14
|
}
|
|
28
15
|
export declare class OrchestratorAgent<I extends Message = Message, O extends Message = Message> extends Agent<I, O> {
|
|
29
16
|
static from<I extends Message, O extends Message>(options: OrchestratorAgentOptions<I, O>): OrchestratorAgent<I, O>;
|
|
@@ -31,9 +18,10 @@ export declare class OrchestratorAgent<I extends Message = Message, O extends Me
|
|
|
31
18
|
private planner;
|
|
32
19
|
private completer;
|
|
33
20
|
maxIterations?: number;
|
|
21
|
+
tasksConcurrency?: number;
|
|
34
22
|
process(input: I, context?: Context): Promise<O>;
|
|
23
|
+
private getFullPlanInput;
|
|
35
24
|
private getFullPlan;
|
|
25
|
+
private synthesizePlanResult;
|
|
36
26
|
private executeStep;
|
|
37
|
-
private formatPlanResult;
|
|
38
|
-
private formatStepsResults;
|
|
39
27
|
}
|
|
@@ -13,11 +13,16 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
13
13
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
+
};
|
|
16
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
20
|
exports.OrchestratorAgent = void 0;
|
|
18
21
|
const core_1 = require("@aigne/core");
|
|
22
|
+
const fastq_1 = __importDefault(require("fastq"));
|
|
19
23
|
const orchestrator_prompts_js_1 = require("./orchestrator-prompts.js");
|
|
20
24
|
const DEFAULT_MAX_ITERATIONS = 30;
|
|
25
|
+
const DEFAULT_TASK_CONCURRENCY = 5;
|
|
21
26
|
__exportStar(require("./orchestrator-prompts.js"), exports);
|
|
22
27
|
class OrchestratorAgent extends core_1.Agent {
|
|
23
28
|
static from(options) {
|
|
@@ -26,20 +31,22 @@ class OrchestratorAgent extends core_1.Agent {
|
|
|
26
31
|
constructor(options) {
|
|
27
32
|
super({ ...options });
|
|
28
33
|
this.maxIterations = options.maxIterations;
|
|
34
|
+
this.tasksConcurrency = options.tasksConcurrency;
|
|
29
35
|
this.planner = new core_1.AIAgent({
|
|
30
36
|
name: "llm_orchestration_planner",
|
|
31
37
|
instructions: orchestrator_prompts_js_1.FULL_PLAN_PROMPT_TEMPLATE,
|
|
32
|
-
outputSchema: orchestrator_prompts_js_1.
|
|
38
|
+
outputSchema: () => (0, orchestrator_prompts_js_1.getFullPlanSchema)(this.tools),
|
|
33
39
|
});
|
|
34
40
|
this.completer = new core_1.AIAgent({
|
|
35
41
|
name: "llm_orchestration_completer",
|
|
36
|
-
instructions: orchestrator_prompts_js_1.
|
|
42
|
+
instructions: orchestrator_prompts_js_1.FULL_PLAN_PROMPT_TEMPLATE,
|
|
37
43
|
outputSchema: this.outputSchema,
|
|
38
44
|
});
|
|
39
45
|
}
|
|
40
46
|
planner;
|
|
41
47
|
completer;
|
|
42
48
|
maxIterations;
|
|
49
|
+
tasksConcurrency;
|
|
43
50
|
async process(input, context) {
|
|
44
51
|
const model = context?.model;
|
|
45
52
|
if (!model)
|
|
@@ -49,91 +56,103 @@ class OrchestratorAgent extends core_1.Agent {
|
|
|
49
56
|
throw new Error("Objective is required to run OrchestratorAgent");
|
|
50
57
|
const result = {
|
|
51
58
|
objective,
|
|
52
|
-
|
|
59
|
+
steps: [],
|
|
53
60
|
};
|
|
54
61
|
let iterations = 0;
|
|
55
62
|
const maxIterations = this.maxIterations ?? DEFAULT_MAX_ITERATIONS;
|
|
56
63
|
while (iterations++ < maxIterations) {
|
|
57
|
-
const plan = await this.getFullPlan(
|
|
64
|
+
const plan = await this.getFullPlan(result, context);
|
|
58
65
|
result.plan = plan;
|
|
59
|
-
if (plan.
|
|
60
|
-
return
|
|
66
|
+
if (plan.isComplete) {
|
|
67
|
+
return this.synthesizePlanResult(result, context);
|
|
61
68
|
}
|
|
62
69
|
for (const step of plan.steps) {
|
|
63
70
|
const stepResult = await this.executeStep(result, step, context);
|
|
64
|
-
result.
|
|
71
|
+
result.steps.push(stepResult);
|
|
65
72
|
}
|
|
66
73
|
}
|
|
67
74
|
throw new Error(`Max iterations reached: ${maxIterations}`);
|
|
68
75
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
76
|
+
getFullPlanInput(planResult) {
|
|
77
|
+
return {
|
|
78
|
+
objective: planResult.objective,
|
|
79
|
+
steps: planResult.steps,
|
|
80
|
+
plan: {
|
|
81
|
+
status: planResult.status ? "Complete" : "In Progress",
|
|
82
|
+
result: planResult.result || "No results yet",
|
|
83
|
+
},
|
|
84
|
+
agents: this.tools.map((i) => ({
|
|
85
|
+
name: i.name,
|
|
86
|
+
description: i.description,
|
|
87
|
+
tools: i.tools.map((i) => ({ name: i.name, description: i.description })),
|
|
88
|
+
})),
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
async getFullPlan(planResult, context) {
|
|
92
|
+
return context.call(this.planner, this.getFullPlanInput(planResult));
|
|
93
|
+
}
|
|
94
|
+
async synthesizePlanResult(planResult, context) {
|
|
95
|
+
return context.call(this.completer, {
|
|
96
|
+
...this.getFullPlanInput(planResult),
|
|
97
|
+
...(0, core_1.createMessage)(orchestrator_prompts_js_1.SYNTHESIZE_PLAN_USER_PROMPT_TEMPLATE),
|
|
79
98
|
});
|
|
80
99
|
}
|
|
81
|
-
async executeStep(
|
|
100
|
+
async executeStep(planResult, step, context) {
|
|
101
|
+
const concurrency = this.tasksConcurrency ?? DEFAULT_TASK_CONCURRENCY;
|
|
82
102
|
const model = context?.model;
|
|
83
103
|
if (!model)
|
|
84
104
|
throw new Error("model is required to run OrchestratorAgent");
|
|
85
|
-
const
|
|
86
|
-
for (const task of step.tasks) {
|
|
105
|
+
const queue = fastq_1.default.promise(async (task) => {
|
|
87
106
|
const agent = this.tools.find((agent) => agent.name === task.agent);
|
|
88
107
|
if (!agent)
|
|
89
108
|
throw new Error(`Agent ${task.agent} not found`);
|
|
90
109
|
const prompt = core_1.PromptTemplate.from(orchestrator_prompts_js_1.TASK_PROMPT_TEMPLATE).format({
|
|
91
|
-
objective:
|
|
92
|
-
|
|
93
|
-
|
|
110
|
+
objective: planResult.objective,
|
|
111
|
+
step,
|
|
112
|
+
task,
|
|
113
|
+
steps: planResult.steps,
|
|
94
114
|
});
|
|
95
115
|
let result;
|
|
96
116
|
if (agent.isCallable) {
|
|
97
|
-
result =
|
|
117
|
+
result = getMessageOrJsonString(await context.call(agent, prompt));
|
|
98
118
|
}
|
|
99
119
|
else {
|
|
100
120
|
const executor = core_1.AIAgent.from({
|
|
121
|
+
name: "llm_orchestration_task_executor",
|
|
101
122
|
instructions: prompt,
|
|
102
123
|
tools: agent.tools,
|
|
103
124
|
});
|
|
104
|
-
result =
|
|
125
|
+
result = getMessageOrJsonString(await context.call(executor, {}));
|
|
105
126
|
}
|
|
106
|
-
|
|
127
|
+
return { task, result };
|
|
128
|
+
}, concurrency);
|
|
129
|
+
let results;
|
|
130
|
+
try {
|
|
131
|
+
results = await Promise.all(step.tasks.map((task) => queue.push(task)));
|
|
107
132
|
}
|
|
133
|
+
catch (error) {
|
|
134
|
+
queue.kill();
|
|
135
|
+
throw error;
|
|
136
|
+
}
|
|
137
|
+
const result = getMessageOrJsonString(await context.call(core_1.AIAgent.from({
|
|
138
|
+
name: "llm_orchestration_step_synthesizer",
|
|
139
|
+
instructions: orchestrator_prompts_js_1.SYNTHESIZE_STEP_PROMPT_TEMPLATE,
|
|
140
|
+
}), { objective: planResult.objective, step, tasks: results }));
|
|
141
|
+
if (!result)
|
|
142
|
+
throw new Error("unexpected empty result from synthesize step's tasks results");
|
|
108
143
|
return {
|
|
109
144
|
step,
|
|
110
|
-
|
|
145
|
+
tasks: results,
|
|
146
|
+
result,
|
|
111
147
|
};
|
|
112
148
|
}
|
|
113
|
-
formatPlanResult(planResult) {
|
|
114
|
-
return core_1.PromptTemplate.from(orchestrator_prompts_js_1.PLAN_RESULT_TEMPLATE).format({
|
|
115
|
-
plan_objective: planResult.objective,
|
|
116
|
-
steps_str: this.formatStepsResults(planResult.step_results),
|
|
117
|
-
plan_status: planResult.is_complete ? "Complete" : "In Progress",
|
|
118
|
-
plan_result: planResult.result || "No results yet",
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
formatStepsResults(stepResults) {
|
|
122
|
-
if (!stepResults.length)
|
|
123
|
-
return "No steps executed yet";
|
|
124
|
-
return stepResults
|
|
125
|
-
.map((stepResult, index) => `${index + 1}:\n${stepResult.task_results.length
|
|
126
|
-
? core_1.PromptTemplate.from(orchestrator_prompts_js_1.STEP_RESULT_TEMPLATE).format({
|
|
127
|
-
step_description: stepResult.step.description,
|
|
128
|
-
tasks_str: stepResult.task_results
|
|
129
|
-
.map((task) => `- ${core_1.PromptTemplate.from(orchestrator_prompts_js_1.TASK_RESULT_TEMPLATE).format({
|
|
130
|
-
task_description: task.description,
|
|
131
|
-
task_result: task.result,
|
|
132
|
-
})}`)
|
|
133
|
-
.join("\n"),
|
|
134
|
-
})
|
|
135
|
-
: "No result"}`)
|
|
136
|
-
.join("\n\n");
|
|
137
|
-
}
|
|
138
149
|
}
|
|
139
150
|
exports.OrchestratorAgent = OrchestratorAgent;
|
|
151
|
+
function getMessageOrJsonString(output) {
|
|
152
|
+
const entries = Object.entries(output);
|
|
153
|
+
const firstValue = entries[0]?.[1];
|
|
154
|
+
if (entries.length === 1 && typeof firstValue === "string") {
|
|
155
|
+
return firstValue;
|
|
156
|
+
}
|
|
157
|
+
return JSON.stringify(output);
|
|
158
|
+
}
|
|
@@ -1,51 +1,12 @@
|
|
|
1
|
+
import { type Agent, type Message } from "@aigne/core";
|
|
1
2
|
import { z } from "zod";
|
|
2
|
-
export declare const
|
|
3
|
-
export declare
|
|
4
|
-
export declare const PLAN_RESULT_TEMPLATE = "Plan Objective: {{plan_objective}}\n\nProgress So Far (steps completed):\n{{steps_str}}\n\nPlan Current Status: {{plan_status}}\nPlan Current Result: {{plan_result}}";
|
|
5
|
-
export declare const FULL_PLAN_PROMPT_TEMPLATE = "You are tasked with orchestrating a plan to complete an objective.\nYou can analyze results from the previous steps already executed to decide if the objective is complete.\nYour plan must be structured in sequential steps, with each step containing independent parallel subtasks.\n\nObjective: {{objective}}\n\n{{plan_result}}\n\nIf the previous results achieve the objective, return is_complete=true.\nOtherwise, generate remaining steps needed.\n\nYou have access to the following Agents(which are collections of tools/functions):\n\nAgents:\n{{agents}}\n\nGenerate a plan with all remaining steps needed.\nSteps are sequential, but each Step can have parallel subtasks.\nFor each Step, specify a description of the step and independent subtasks that can run in parallel.\nFor each subtask specify:\n 1. Clear description of the task that an LLM can execute\n 2. Name of 1 Agent to use for the task";
|
|
6
|
-
export declare const TASK_PROMPT_TEMPLATE = "You are part of a larger workflow to achieve the objective: {{objective}}.\nYour job is to accomplish only the following task: {{task}}.\n\nResults so far that may provide helpful context:\n{{context}}";
|
|
7
|
-
export declare const SYNTHESIZE_PLAN_PROMPT_TEMPLATE = "Synthesize the results of executing all steps in the plan into a cohesive result:\n{{plan_result}}";
|
|
8
|
-
export declare const TaskSchema: z.ZodObject<{
|
|
9
|
-
description: z.ZodString;
|
|
10
|
-
agent: z.ZodString;
|
|
11
|
-
}, "strip", z.ZodTypeAny, {
|
|
12
|
-
description: string;
|
|
13
|
-
agent: string;
|
|
14
|
-
}, {
|
|
15
|
-
description: string;
|
|
16
|
-
agent: string;
|
|
17
|
-
}>;
|
|
18
|
-
export declare const StepSchema: z.ZodObject<{
|
|
19
|
-
description: z.ZodString;
|
|
20
|
-
tasks: z.ZodArray<z.ZodObject<{
|
|
21
|
-
description: z.ZodString;
|
|
22
|
-
agent: z.ZodString;
|
|
23
|
-
}, "strip", z.ZodTypeAny, {
|
|
24
|
-
description: string;
|
|
25
|
-
agent: string;
|
|
26
|
-
}, {
|
|
27
|
-
description: string;
|
|
28
|
-
agent: string;
|
|
29
|
-
}>, "many">;
|
|
30
|
-
}, "strip", z.ZodTypeAny, {
|
|
31
|
-
description: string;
|
|
32
|
-
tasks: {
|
|
33
|
-
description: string;
|
|
34
|
-
agent: string;
|
|
35
|
-
}[];
|
|
36
|
-
}, {
|
|
37
|
-
description: string;
|
|
38
|
-
tasks: {
|
|
39
|
-
description: string;
|
|
40
|
-
agent: string;
|
|
41
|
-
}[];
|
|
42
|
-
}>;
|
|
43
|
-
export declare const FullPlanSchema: z.ZodObject<{
|
|
3
|
+
export declare const SYNTHESIZE_PLAN_USER_PROMPT_TEMPLATE = "Synthesize the results of executing all steps in the plan into a cohesive result\n";
|
|
4
|
+
export declare function getFullPlanSchema(agents: Agent[]): z.ZodObject<{
|
|
44
5
|
steps: z.ZodArray<z.ZodObject<{
|
|
45
6
|
description: z.ZodString;
|
|
46
7
|
tasks: z.ZodArray<z.ZodObject<{
|
|
47
8
|
description: z.ZodString;
|
|
48
|
-
agent: z.
|
|
9
|
+
agent: z.ZodUnion<[z.ZodLiteral<string>, z.ZodLiteral<string>, ...z.ZodLiteral<string>[]]>;
|
|
49
10
|
}, "strip", z.ZodTypeAny, {
|
|
50
11
|
description: string;
|
|
51
12
|
agent: string;
|
|
@@ -66,7 +27,7 @@ export declare const FullPlanSchema: z.ZodObject<{
|
|
|
66
27
|
agent: string;
|
|
67
28
|
}[];
|
|
68
29
|
}>, "many">;
|
|
69
|
-
|
|
30
|
+
isComplete: z.ZodBoolean;
|
|
70
31
|
}, "strip", z.ZodTypeAny, {
|
|
71
32
|
steps: {
|
|
72
33
|
description: string;
|
|
@@ -75,7 +36,7 @@ export declare const FullPlanSchema: z.ZodObject<{
|
|
|
75
36
|
agent: string;
|
|
76
37
|
}[];
|
|
77
38
|
}[];
|
|
78
|
-
|
|
39
|
+
isComplete: boolean;
|
|
79
40
|
}, {
|
|
80
41
|
steps: {
|
|
81
42
|
description: string;
|
|
@@ -84,8 +45,47 @@ export declare const FullPlanSchema: z.ZodObject<{
|
|
|
84
45
|
agent: string;
|
|
85
46
|
}[];
|
|
86
47
|
}[];
|
|
87
|
-
|
|
48
|
+
isComplete: boolean;
|
|
88
49
|
}>;
|
|
89
|
-
export type
|
|
90
|
-
export type Step =
|
|
91
|
-
export type
|
|
50
|
+
export type FullPlanOutput = z.infer<ReturnType<typeof getFullPlanSchema>>;
|
|
51
|
+
export type Step = FullPlanOutput["steps"][number];
|
|
52
|
+
export type Task = Step["tasks"][number];
|
|
53
|
+
export interface StepWithResult {
|
|
54
|
+
step: Step;
|
|
55
|
+
tasks: Array<TaskWithResult>;
|
|
56
|
+
result: string;
|
|
57
|
+
}
|
|
58
|
+
export interface TaskWithResult {
|
|
59
|
+
task: Task;
|
|
60
|
+
result: string;
|
|
61
|
+
}
|
|
62
|
+
export interface FullPlanInput extends Message {
|
|
63
|
+
objective: string;
|
|
64
|
+
steps: StepWithResult[];
|
|
65
|
+
plan: {
|
|
66
|
+
status: string;
|
|
67
|
+
result: string;
|
|
68
|
+
};
|
|
69
|
+
agents: {
|
|
70
|
+
name: string;
|
|
71
|
+
description?: string;
|
|
72
|
+
tools: {
|
|
73
|
+
name: string;
|
|
74
|
+
description?: string;
|
|
75
|
+
}[];
|
|
76
|
+
}[];
|
|
77
|
+
}
|
|
78
|
+
export declare const FULL_PLAN_PROMPT_TEMPLATE = "You are tasked with orchestrating a plan to complete an objective.\nYou can analyze results from the previous steps already executed to decide if the objective is complete.\nYour plan must be structured in sequential steps, with each step containing independent parallel subtasks.\n\n<objective>\n{{objective}}\n</objective>\n\n<steps_completed>\n{{#steps}}\n- Step: {{step.description}}\n Result: {{result}}\n{{/steps}}\n</steps_completed>\n\n<previous_plan_status>\n{{plan.status}}\n</previous_plan_status>\n\n<previous_plan_result>\n{{plan.result}}\n</previous_plan_result>\n\nYou have access to the following Agents(which are collections of tools/functions):\n\n<agents>\n{{#agents}}\n- Agent: {{name}}\n Description: {{description}}\n Functions:\n {{#tools}}\n - Tool: {{name}}\n Description: {{description}}\n {{/tools}}\n{{/agents}}\n</agents>\n\n- If the previous plan results achieve the objective, return isComplete=true.\n- Otherwise, generate remaining steps needed.\n- Generate a plan with all remaining steps needed.\n- Steps are sequential, but each Step can have parallel subtasks.\n- For each Step, specify a description of the step and independent subtasks that can run in parallel.\n- For each subtask specify:\n 1. Clear description of the task that an LLM can execute\n 2. Name of 1 Agent to use for the task";
|
|
79
|
+
export interface TaskPromptInput extends Message {
|
|
80
|
+
objective: string;
|
|
81
|
+
step: Step;
|
|
82
|
+
task: Task;
|
|
83
|
+
steps: StepWithResult[];
|
|
84
|
+
}
|
|
85
|
+
export declare const TASK_PROMPT_TEMPLATE = "You are part of a larger workflow to achieve the step then the objective:\n\n<objective>\n{{objective}}\n</objective>\n\n<step>\n{{step.description}}\n</step>\n\nYour job is to accomplish only the following task:\n\n<task>\n{{task.description}}\n</task>\n\nResults so far that may provide helpful context:\n\n<steps_completed>\n{{#steps}}\n- Step: {{step.description}}\n Result: {{result}}\n{{/steps}}\n</steps_completed>\n";
|
|
86
|
+
export interface SynthesizeStepPromptInput extends Message {
|
|
87
|
+
objective: string;
|
|
88
|
+
step: Step;
|
|
89
|
+
tasks: TaskWithResult[];
|
|
90
|
+
}
|
|
91
|
+
export declare const SYNTHESIZE_STEP_PROMPT_TEMPLATE = "Synthesize the results of these parallel tasks into a cohesive result\n\n<objective>\n{{objective}}\n</objective>\n\n<step>\n{{step.description}}\n</step>\n\n<tasks>\n{{#tasks}}\n- Task: {{task.description}}\n Result: {{result}}\n{{/tasks}}\n</tasks>\n";
|
|
@@ -1,57 +1,120 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.SYNTHESIZE_STEP_PROMPT_TEMPLATE = exports.TASK_PROMPT_TEMPLATE = exports.FULL_PLAN_PROMPT_TEMPLATE = exports.SYNTHESIZE_PLAN_USER_PROMPT_TEMPLATE = void 0;
|
|
4
|
+
exports.getFullPlanSchema = getFullPlanSchema;
|
|
5
|
+
const core_1 = require("@aigne/core");
|
|
6
|
+
const lodash_es_1 = require("lodash-es");
|
|
4
7
|
const zod_1 = require("zod");
|
|
5
|
-
exports.
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
8
|
+
exports.SYNTHESIZE_PLAN_USER_PROMPT_TEMPLATE = `\
|
|
9
|
+
Synthesize the results of executing all steps in the plan into a cohesive result
|
|
10
|
+
`;
|
|
11
|
+
function getFullPlanSchema(agents) {
|
|
12
|
+
const agentNames = agents.map((i) => i.name);
|
|
13
|
+
if (new Set(agentNames).size !== agentNames.length) {
|
|
14
|
+
const duplicates = (0, lodash_es_1.pickBy)((0, lodash_es_1.groupBy)(agentNames), (x) => x.length > 1);
|
|
15
|
+
throw new Error(`Tools name must be unique for orchestrator: ${Object.keys(duplicates).join(",")}`);
|
|
16
|
+
}
|
|
17
|
+
const TaskSchema = zod_1.z.object({
|
|
18
|
+
description: zod_1.z.string().describe("Detailed description of the task"),
|
|
19
|
+
agent: zod_1.z
|
|
20
|
+
.union((0, core_1.ensureZodUnionArray)(agents.map((i) => zod_1.z.literal(i.name))))
|
|
21
|
+
.describe("Name of the agent to execute the task"),
|
|
22
|
+
});
|
|
23
|
+
const StepSchema = zod_1.z.object({
|
|
24
|
+
description: zod_1.z.string().describe("Detailed description of the step"),
|
|
25
|
+
tasks: zod_1.z.array(TaskSchema).describe("Tasks that can run in parallel in this step"),
|
|
26
|
+
});
|
|
27
|
+
return zod_1.z.object({
|
|
28
|
+
steps: zod_1.z.array(StepSchema).describe("All sequential steps in the plan"),
|
|
29
|
+
isComplete: zod_1.z.boolean().describe("Whether the previous plan results achieve the objective"),
|
|
30
|
+
});
|
|
31
|
+
}
|
|
17
32
|
exports.FULL_PLAN_PROMPT_TEMPLATE = `You are tasked with orchestrating a plan to complete an objective.
|
|
18
33
|
You can analyze results from the previous steps already executed to decide if the objective is complete.
|
|
19
34
|
Your plan must be structured in sequential steps, with each step containing independent parallel subtasks.
|
|
20
35
|
|
|
21
|
-
|
|
36
|
+
<objective>
|
|
37
|
+
{{objective}}
|
|
38
|
+
</objective>
|
|
22
39
|
|
|
23
|
-
|
|
40
|
+
<steps_completed>
|
|
41
|
+
{{#steps}}
|
|
42
|
+
- Step: {{step.description}}
|
|
43
|
+
Result: {{result}}
|
|
44
|
+
{{/steps}}
|
|
45
|
+
</steps_completed>
|
|
24
46
|
|
|
25
|
-
|
|
26
|
-
|
|
47
|
+
<previous_plan_status>
|
|
48
|
+
{{plan.status}}
|
|
49
|
+
</previous_plan_status>
|
|
50
|
+
|
|
51
|
+
<previous_plan_result>
|
|
52
|
+
{{plan.result}}
|
|
53
|
+
</previous_plan_result>
|
|
27
54
|
|
|
28
55
|
You have access to the following Agents(which are collections of tools/functions):
|
|
29
56
|
|
|
30
|
-
|
|
31
|
-
{{agents}}
|
|
57
|
+
<agents>
|
|
58
|
+
{{#agents}}
|
|
59
|
+
- Agent: {{name}}
|
|
60
|
+
Description: {{description}}
|
|
61
|
+
Functions:
|
|
62
|
+
{{#tools}}
|
|
63
|
+
- Tool: {{name}}
|
|
64
|
+
Description: {{description}}
|
|
65
|
+
{{/tools}}
|
|
66
|
+
{{/agents}}
|
|
67
|
+
</agents>
|
|
32
68
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
69
|
+
- If the previous plan results achieve the objective, return isComplete=true.
|
|
70
|
+
- Otherwise, generate remaining steps needed.
|
|
71
|
+
- Generate a plan with all remaining steps needed.
|
|
72
|
+
- Steps are sequential, but each Step can have parallel subtasks.
|
|
73
|
+
- For each Step, specify a description of the step and independent subtasks that can run in parallel.
|
|
74
|
+
- For each subtask specify:
|
|
37
75
|
1. Clear description of the task that an LLM can execute
|
|
38
76
|
2. Name of 1 Agent to use for the task`;
|
|
39
|
-
exports.TASK_PROMPT_TEMPLATE =
|
|
40
|
-
|
|
77
|
+
exports.TASK_PROMPT_TEMPLATE = `\
|
|
78
|
+
You are part of a larger workflow to achieve the step then the objective:
|
|
79
|
+
|
|
80
|
+
<objective>
|
|
81
|
+
{{objective}}
|
|
82
|
+
</objective>
|
|
83
|
+
|
|
84
|
+
<step>
|
|
85
|
+
{{step.description}}
|
|
86
|
+
</step>
|
|
87
|
+
|
|
88
|
+
Your job is to accomplish only the following task:
|
|
89
|
+
|
|
90
|
+
<task>
|
|
91
|
+
{{task.description}}
|
|
92
|
+
</task>
|
|
41
93
|
|
|
42
94
|
Results so far that may provide helpful context:
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
{{
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
95
|
+
|
|
96
|
+
<steps_completed>
|
|
97
|
+
{{#steps}}
|
|
98
|
+
- Step: {{step.description}}
|
|
99
|
+
Result: {{result}}
|
|
100
|
+
{{/steps}}
|
|
101
|
+
</steps_completed>
|
|
102
|
+
`;
|
|
103
|
+
exports.SYNTHESIZE_STEP_PROMPT_TEMPLATE = `\
|
|
104
|
+
Synthesize the results of these parallel tasks into a cohesive result
|
|
105
|
+
|
|
106
|
+
<objective>
|
|
107
|
+
{{objective}}
|
|
108
|
+
</objective>
|
|
109
|
+
|
|
110
|
+
<step>
|
|
111
|
+
{{step.description}}
|
|
112
|
+
</step>
|
|
113
|
+
|
|
114
|
+
<tasks>
|
|
115
|
+
{{#tasks}}
|
|
116
|
+
- Task: {{task.description}}
|
|
117
|
+
Result: {{result}}
|
|
118
|
+
{{/tasks}}
|
|
119
|
+
</tasks>
|
|
120
|
+
`;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type": "commonjs"}
|
|
@@ -1,29 +1,16 @@
|
|
|
1
1
|
import { Agent, type AgentOptions, type Context, type Message } from "@aigne/core";
|
|
2
|
-
import { type FullPlanOutput, type
|
|
2
|
+
import { type FullPlanOutput, type StepWithResult } from "./orchestrator-prompts.js";
|
|
3
3
|
export * from "./orchestrator-prompts.js";
|
|
4
|
-
export interface
|
|
5
|
-
step: Step;
|
|
6
|
-
task_results: Array<TaskWithResult>;
|
|
7
|
-
}
|
|
8
|
-
export interface TaskWithResult {
|
|
9
|
-
description: string;
|
|
10
|
-
agent: string;
|
|
11
|
-
result: string;
|
|
12
|
-
}
|
|
13
|
-
export interface PlanResult extends Message {
|
|
4
|
+
export interface FullPlanWithResult {
|
|
14
5
|
objective: string;
|
|
15
6
|
plan?: FullPlanOutput;
|
|
16
|
-
|
|
7
|
+
steps: StepWithResult[];
|
|
17
8
|
result?: string;
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
export interface FullPlanInput extends Message {
|
|
21
|
-
objective: string;
|
|
22
|
-
plan_result: string;
|
|
23
|
-
agents: string;
|
|
9
|
+
status?: boolean;
|
|
24
10
|
}
|
|
25
11
|
export interface OrchestratorAgentOptions<I extends Message = Message, O extends Message = Message> extends AgentOptions<I, O> {
|
|
26
12
|
maxIterations?: number;
|
|
13
|
+
tasksConcurrency?: number;
|
|
27
14
|
}
|
|
28
15
|
export declare class OrchestratorAgent<I extends Message = Message, O extends Message = Message> extends Agent<I, O> {
|
|
29
16
|
static from<I extends Message, O extends Message>(options: OrchestratorAgentOptions<I, O>): OrchestratorAgent<I, O>;
|
|
@@ -31,9 +18,10 @@ export declare class OrchestratorAgent<I extends Message = Message, O extends Me
|
|
|
31
18
|
private planner;
|
|
32
19
|
private completer;
|
|
33
20
|
maxIterations?: number;
|
|
21
|
+
tasksConcurrency?: number;
|
|
34
22
|
process(input: I, context?: Context): Promise<O>;
|
|
23
|
+
private getFullPlanInput;
|
|
35
24
|
private getFullPlan;
|
|
25
|
+
private synthesizePlanResult;
|
|
36
26
|
private executeStep;
|
|
37
|
-
private formatPlanResult;
|
|
38
|
-
private formatStepsResults;
|
|
39
27
|
}
|
|
@@ -1,51 +1,12 @@
|
|
|
1
|
+
import { type Agent, type Message } from "@aigne/core";
|
|
1
2
|
import { z } from "zod";
|
|
2
|
-
export declare const
|
|
3
|
-
export declare
|
|
4
|
-
export declare const PLAN_RESULT_TEMPLATE = "Plan Objective: {{plan_objective}}\n\nProgress So Far (steps completed):\n{{steps_str}}\n\nPlan Current Status: {{plan_status}}\nPlan Current Result: {{plan_result}}";
|
|
5
|
-
export declare const FULL_PLAN_PROMPT_TEMPLATE = "You are tasked with orchestrating a plan to complete an objective.\nYou can analyze results from the previous steps already executed to decide if the objective is complete.\nYour plan must be structured in sequential steps, with each step containing independent parallel subtasks.\n\nObjective: {{objective}}\n\n{{plan_result}}\n\nIf the previous results achieve the objective, return is_complete=true.\nOtherwise, generate remaining steps needed.\n\nYou have access to the following Agents(which are collections of tools/functions):\n\nAgents:\n{{agents}}\n\nGenerate a plan with all remaining steps needed.\nSteps are sequential, but each Step can have parallel subtasks.\nFor each Step, specify a description of the step and independent subtasks that can run in parallel.\nFor each subtask specify:\n 1. Clear description of the task that an LLM can execute\n 2. Name of 1 Agent to use for the task";
|
|
6
|
-
export declare const TASK_PROMPT_TEMPLATE = "You are part of a larger workflow to achieve the objective: {{objective}}.\nYour job is to accomplish only the following task: {{task}}.\n\nResults so far that may provide helpful context:\n{{context}}";
|
|
7
|
-
export declare const SYNTHESIZE_PLAN_PROMPT_TEMPLATE = "Synthesize the results of executing all steps in the plan into a cohesive result:\n{{plan_result}}";
|
|
8
|
-
export declare const TaskSchema: z.ZodObject<{
|
|
9
|
-
description: z.ZodString;
|
|
10
|
-
agent: z.ZodString;
|
|
11
|
-
}, "strip", z.ZodTypeAny, {
|
|
12
|
-
description: string;
|
|
13
|
-
agent: string;
|
|
14
|
-
}, {
|
|
15
|
-
description: string;
|
|
16
|
-
agent: string;
|
|
17
|
-
}>;
|
|
18
|
-
export declare const StepSchema: z.ZodObject<{
|
|
19
|
-
description: z.ZodString;
|
|
20
|
-
tasks: z.ZodArray<z.ZodObject<{
|
|
21
|
-
description: z.ZodString;
|
|
22
|
-
agent: z.ZodString;
|
|
23
|
-
}, "strip", z.ZodTypeAny, {
|
|
24
|
-
description: string;
|
|
25
|
-
agent: string;
|
|
26
|
-
}, {
|
|
27
|
-
description: string;
|
|
28
|
-
agent: string;
|
|
29
|
-
}>, "many">;
|
|
30
|
-
}, "strip", z.ZodTypeAny, {
|
|
31
|
-
description: string;
|
|
32
|
-
tasks: {
|
|
33
|
-
description: string;
|
|
34
|
-
agent: string;
|
|
35
|
-
}[];
|
|
36
|
-
}, {
|
|
37
|
-
description: string;
|
|
38
|
-
tasks: {
|
|
39
|
-
description: string;
|
|
40
|
-
agent: string;
|
|
41
|
-
}[];
|
|
42
|
-
}>;
|
|
43
|
-
export declare const FullPlanSchema: z.ZodObject<{
|
|
3
|
+
export declare const SYNTHESIZE_PLAN_USER_PROMPT_TEMPLATE = "Synthesize the results of executing all steps in the plan into a cohesive result\n";
|
|
4
|
+
export declare function getFullPlanSchema(agents: Agent[]): z.ZodObject<{
|
|
44
5
|
steps: z.ZodArray<z.ZodObject<{
|
|
45
6
|
description: z.ZodString;
|
|
46
7
|
tasks: z.ZodArray<z.ZodObject<{
|
|
47
8
|
description: z.ZodString;
|
|
48
|
-
agent: z.
|
|
9
|
+
agent: z.ZodUnion<[z.ZodLiteral<string>, z.ZodLiteral<string>, ...z.ZodLiteral<string>[]]>;
|
|
49
10
|
}, "strip", z.ZodTypeAny, {
|
|
50
11
|
description: string;
|
|
51
12
|
agent: string;
|
|
@@ -66,7 +27,7 @@ export declare const FullPlanSchema: z.ZodObject<{
|
|
|
66
27
|
agent: string;
|
|
67
28
|
}[];
|
|
68
29
|
}>, "many">;
|
|
69
|
-
|
|
30
|
+
isComplete: z.ZodBoolean;
|
|
70
31
|
}, "strip", z.ZodTypeAny, {
|
|
71
32
|
steps: {
|
|
72
33
|
description: string;
|
|
@@ -75,7 +36,7 @@ export declare const FullPlanSchema: z.ZodObject<{
|
|
|
75
36
|
agent: string;
|
|
76
37
|
}[];
|
|
77
38
|
}[];
|
|
78
|
-
|
|
39
|
+
isComplete: boolean;
|
|
79
40
|
}, {
|
|
80
41
|
steps: {
|
|
81
42
|
description: string;
|
|
@@ -84,8 +45,47 @@ export declare const FullPlanSchema: z.ZodObject<{
|
|
|
84
45
|
agent: string;
|
|
85
46
|
}[];
|
|
86
47
|
}[];
|
|
87
|
-
|
|
48
|
+
isComplete: boolean;
|
|
88
49
|
}>;
|
|
89
|
-
export type
|
|
90
|
-
export type Step =
|
|
91
|
-
export type
|
|
50
|
+
export type FullPlanOutput = z.infer<ReturnType<typeof getFullPlanSchema>>;
|
|
51
|
+
export type Step = FullPlanOutput["steps"][number];
|
|
52
|
+
export type Task = Step["tasks"][number];
|
|
53
|
+
export interface StepWithResult {
|
|
54
|
+
step: Step;
|
|
55
|
+
tasks: Array<TaskWithResult>;
|
|
56
|
+
result: string;
|
|
57
|
+
}
|
|
58
|
+
export interface TaskWithResult {
|
|
59
|
+
task: Task;
|
|
60
|
+
result: string;
|
|
61
|
+
}
|
|
62
|
+
export interface FullPlanInput extends Message {
|
|
63
|
+
objective: string;
|
|
64
|
+
steps: StepWithResult[];
|
|
65
|
+
plan: {
|
|
66
|
+
status: string;
|
|
67
|
+
result: string;
|
|
68
|
+
};
|
|
69
|
+
agents: {
|
|
70
|
+
name: string;
|
|
71
|
+
description?: string;
|
|
72
|
+
tools: {
|
|
73
|
+
name: string;
|
|
74
|
+
description?: string;
|
|
75
|
+
}[];
|
|
76
|
+
}[];
|
|
77
|
+
}
|
|
78
|
+
export declare const FULL_PLAN_PROMPT_TEMPLATE = "You are tasked with orchestrating a plan to complete an objective.\nYou can analyze results from the previous steps already executed to decide if the objective is complete.\nYour plan must be structured in sequential steps, with each step containing independent parallel subtasks.\n\n<objective>\n{{objective}}\n</objective>\n\n<steps_completed>\n{{#steps}}\n- Step: {{step.description}}\n Result: {{result}}\n{{/steps}}\n</steps_completed>\n\n<previous_plan_status>\n{{plan.status}}\n</previous_plan_status>\n\n<previous_plan_result>\n{{plan.result}}\n</previous_plan_result>\n\nYou have access to the following Agents(which are collections of tools/functions):\n\n<agents>\n{{#agents}}\n- Agent: {{name}}\n Description: {{description}}\n Functions:\n {{#tools}}\n - Tool: {{name}}\n Description: {{description}}\n {{/tools}}\n{{/agents}}\n</agents>\n\n- If the previous plan results achieve the objective, return isComplete=true.\n- Otherwise, generate remaining steps needed.\n- Generate a plan with all remaining steps needed.\n- Steps are sequential, but each Step can have parallel subtasks.\n- For each Step, specify a description of the step and independent subtasks that can run in parallel.\n- For each subtask specify:\n 1. Clear description of the task that an LLM can execute\n 2. Name of 1 Agent to use for the task";
|
|
79
|
+
export interface TaskPromptInput extends Message {
|
|
80
|
+
objective: string;
|
|
81
|
+
step: Step;
|
|
82
|
+
task: Task;
|
|
83
|
+
steps: StepWithResult[];
|
|
84
|
+
}
|
|
85
|
+
export declare const TASK_PROMPT_TEMPLATE = "You are part of a larger workflow to achieve the step then the objective:\n\n<objective>\n{{objective}}\n</objective>\n\n<step>\n{{step.description}}\n</step>\n\nYour job is to accomplish only the following task:\n\n<task>\n{{task.description}}\n</task>\n\nResults so far that may provide helpful context:\n\n<steps_completed>\n{{#steps}}\n- Step: {{step.description}}\n Result: {{result}}\n{{/steps}}\n</steps_completed>\n";
|
|
86
|
+
export interface SynthesizeStepPromptInput extends Message {
|
|
87
|
+
objective: string;
|
|
88
|
+
step: Step;
|
|
89
|
+
tasks: TaskWithResult[];
|
|
90
|
+
}
|
|
91
|
+
export declare const SYNTHESIZE_STEP_PROMPT_TEMPLATE = "Synthesize the results of these parallel tasks into a cohesive result\n\n<objective>\n{{objective}}\n</objective>\n\n<step>\n{{step.description}}\n</step>\n\n<tasks>\n{{#tasks}}\n- Task: {{task.description}}\n Result: {{result}}\n{{/tasks}}\n</tasks>\n";
|
|
@@ -1,29 +1,16 @@
|
|
|
1
1
|
import { Agent, type AgentOptions, type Context, type Message } from "@aigne/core";
|
|
2
|
-
import { type FullPlanOutput, type
|
|
2
|
+
import { type FullPlanOutput, type StepWithResult } from "./orchestrator-prompts.js";
|
|
3
3
|
export * from "./orchestrator-prompts.js";
|
|
4
|
-
export interface
|
|
5
|
-
step: Step;
|
|
6
|
-
task_results: Array<TaskWithResult>;
|
|
7
|
-
}
|
|
8
|
-
export interface TaskWithResult {
|
|
9
|
-
description: string;
|
|
10
|
-
agent: string;
|
|
11
|
-
result: string;
|
|
12
|
-
}
|
|
13
|
-
export interface PlanResult extends Message {
|
|
4
|
+
export interface FullPlanWithResult {
|
|
14
5
|
objective: string;
|
|
15
6
|
plan?: FullPlanOutput;
|
|
16
|
-
|
|
7
|
+
steps: StepWithResult[];
|
|
17
8
|
result?: string;
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
export interface FullPlanInput extends Message {
|
|
21
|
-
objective: string;
|
|
22
|
-
plan_result: string;
|
|
23
|
-
agents: string;
|
|
9
|
+
status?: boolean;
|
|
24
10
|
}
|
|
25
11
|
export interface OrchestratorAgentOptions<I extends Message = Message, O extends Message = Message> extends AgentOptions<I, O> {
|
|
26
12
|
maxIterations?: number;
|
|
13
|
+
tasksConcurrency?: number;
|
|
27
14
|
}
|
|
28
15
|
export declare class OrchestratorAgent<I extends Message = Message, O extends Message = Message> extends Agent<I, O> {
|
|
29
16
|
static from<I extends Message, O extends Message>(options: OrchestratorAgentOptions<I, O>): OrchestratorAgent<I, O>;
|
|
@@ -31,9 +18,10 @@ export declare class OrchestratorAgent<I extends Message = Message, O extends Me
|
|
|
31
18
|
private planner;
|
|
32
19
|
private completer;
|
|
33
20
|
maxIterations?: number;
|
|
21
|
+
tasksConcurrency?: number;
|
|
34
22
|
process(input: I, context?: Context): Promise<O>;
|
|
23
|
+
private getFullPlanInput;
|
|
35
24
|
private getFullPlan;
|
|
25
|
+
private synthesizePlanResult;
|
|
36
26
|
private executeStep;
|
|
37
|
-
private formatPlanResult;
|
|
38
|
-
private formatStepsResults;
|
|
39
27
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { AIAgent, Agent, PromptTemplate, getMessage, } from "@aigne/core";
|
|
2
|
-
import
|
|
1
|
+
import { AIAgent, Agent, PromptTemplate, createMessage, getMessage, } from "@aigne/core";
|
|
2
|
+
import fastq from "fastq";
|
|
3
|
+
import { FULL_PLAN_PROMPT_TEMPLATE, SYNTHESIZE_PLAN_USER_PROMPT_TEMPLATE, SYNTHESIZE_STEP_PROMPT_TEMPLATE, TASK_PROMPT_TEMPLATE, getFullPlanSchema, } from "./orchestrator-prompts.js";
|
|
3
4
|
const DEFAULT_MAX_ITERATIONS = 30;
|
|
5
|
+
const DEFAULT_TASK_CONCURRENCY = 5;
|
|
4
6
|
export * from "./orchestrator-prompts.js";
|
|
5
7
|
export class OrchestratorAgent extends Agent {
|
|
6
8
|
static from(options) {
|
|
@@ -9,20 +11,22 @@ export class OrchestratorAgent extends Agent {
|
|
|
9
11
|
constructor(options) {
|
|
10
12
|
super({ ...options });
|
|
11
13
|
this.maxIterations = options.maxIterations;
|
|
14
|
+
this.tasksConcurrency = options.tasksConcurrency;
|
|
12
15
|
this.planner = new AIAgent({
|
|
13
16
|
name: "llm_orchestration_planner",
|
|
14
17
|
instructions: FULL_PLAN_PROMPT_TEMPLATE,
|
|
15
|
-
outputSchema:
|
|
18
|
+
outputSchema: () => getFullPlanSchema(this.tools),
|
|
16
19
|
});
|
|
17
20
|
this.completer = new AIAgent({
|
|
18
21
|
name: "llm_orchestration_completer",
|
|
19
|
-
instructions:
|
|
22
|
+
instructions: FULL_PLAN_PROMPT_TEMPLATE,
|
|
20
23
|
outputSchema: this.outputSchema,
|
|
21
24
|
});
|
|
22
25
|
}
|
|
23
26
|
planner;
|
|
24
27
|
completer;
|
|
25
28
|
maxIterations;
|
|
29
|
+
tasksConcurrency;
|
|
26
30
|
async process(input, context) {
|
|
27
31
|
const model = context?.model;
|
|
28
32
|
if (!model)
|
|
@@ -32,90 +36,102 @@ export class OrchestratorAgent extends Agent {
|
|
|
32
36
|
throw new Error("Objective is required to run OrchestratorAgent");
|
|
33
37
|
const result = {
|
|
34
38
|
objective,
|
|
35
|
-
|
|
39
|
+
steps: [],
|
|
36
40
|
};
|
|
37
41
|
let iterations = 0;
|
|
38
42
|
const maxIterations = this.maxIterations ?? DEFAULT_MAX_ITERATIONS;
|
|
39
43
|
while (iterations++ < maxIterations) {
|
|
40
|
-
const plan = await this.getFullPlan(
|
|
44
|
+
const plan = await this.getFullPlan(result, context);
|
|
41
45
|
result.plan = plan;
|
|
42
|
-
if (plan.
|
|
43
|
-
return
|
|
46
|
+
if (plan.isComplete) {
|
|
47
|
+
return this.synthesizePlanResult(result, context);
|
|
44
48
|
}
|
|
45
49
|
for (const step of plan.steps) {
|
|
46
50
|
const stepResult = await this.executeStep(result, step, context);
|
|
47
|
-
result.
|
|
51
|
+
result.steps.push(stepResult);
|
|
48
52
|
}
|
|
49
53
|
}
|
|
50
54
|
throw new Error(`Max iterations reached: ${maxIterations}`);
|
|
51
55
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
56
|
+
getFullPlanInput(planResult) {
|
|
57
|
+
return {
|
|
58
|
+
objective: planResult.objective,
|
|
59
|
+
steps: planResult.steps,
|
|
60
|
+
plan: {
|
|
61
|
+
status: planResult.status ? "Complete" : "In Progress",
|
|
62
|
+
result: planResult.result || "No results yet",
|
|
63
|
+
},
|
|
64
|
+
agents: this.tools.map((i) => ({
|
|
65
|
+
name: i.name,
|
|
66
|
+
description: i.description,
|
|
67
|
+
tools: i.tools.map((i) => ({ name: i.name, description: i.description })),
|
|
68
|
+
})),
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
async getFullPlan(planResult, context) {
|
|
72
|
+
return context.call(this.planner, this.getFullPlanInput(planResult));
|
|
73
|
+
}
|
|
74
|
+
async synthesizePlanResult(planResult, context) {
|
|
75
|
+
return context.call(this.completer, {
|
|
76
|
+
...this.getFullPlanInput(planResult),
|
|
77
|
+
...createMessage(SYNTHESIZE_PLAN_USER_PROMPT_TEMPLATE),
|
|
62
78
|
});
|
|
63
79
|
}
|
|
64
|
-
async executeStep(
|
|
80
|
+
async executeStep(planResult, step, context) {
|
|
81
|
+
const concurrency = this.tasksConcurrency ?? DEFAULT_TASK_CONCURRENCY;
|
|
65
82
|
const model = context?.model;
|
|
66
83
|
if (!model)
|
|
67
84
|
throw new Error("model is required to run OrchestratorAgent");
|
|
68
|
-
const
|
|
69
|
-
for (const task of step.tasks) {
|
|
85
|
+
const queue = fastq.promise(async (task) => {
|
|
70
86
|
const agent = this.tools.find((agent) => agent.name === task.agent);
|
|
71
87
|
if (!agent)
|
|
72
88
|
throw new Error(`Agent ${task.agent} not found`);
|
|
73
89
|
const prompt = PromptTemplate.from(TASK_PROMPT_TEMPLATE).format({
|
|
74
|
-
objective:
|
|
75
|
-
|
|
76
|
-
|
|
90
|
+
objective: planResult.objective,
|
|
91
|
+
step,
|
|
92
|
+
task,
|
|
93
|
+
steps: planResult.steps,
|
|
77
94
|
});
|
|
78
95
|
let result;
|
|
79
96
|
if (agent.isCallable) {
|
|
80
|
-
result =
|
|
97
|
+
result = getMessageOrJsonString(await context.call(agent, prompt));
|
|
81
98
|
}
|
|
82
99
|
else {
|
|
83
100
|
const executor = AIAgent.from({
|
|
101
|
+
name: "llm_orchestration_task_executor",
|
|
84
102
|
instructions: prompt,
|
|
85
103
|
tools: agent.tools,
|
|
86
104
|
});
|
|
87
|
-
result =
|
|
105
|
+
result = getMessageOrJsonString(await context.call(executor, {}));
|
|
88
106
|
}
|
|
89
|
-
|
|
107
|
+
return { task, result };
|
|
108
|
+
}, concurrency);
|
|
109
|
+
let results;
|
|
110
|
+
try {
|
|
111
|
+
results = await Promise.all(step.tasks.map((task) => queue.push(task)));
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
queue.kill();
|
|
115
|
+
throw error;
|
|
90
116
|
}
|
|
117
|
+
const result = getMessageOrJsonString(await context.call(AIAgent.from({
|
|
118
|
+
name: "llm_orchestration_step_synthesizer",
|
|
119
|
+
instructions: SYNTHESIZE_STEP_PROMPT_TEMPLATE,
|
|
120
|
+
}), { objective: planResult.objective, step, tasks: results }));
|
|
121
|
+
if (!result)
|
|
122
|
+
throw new Error("unexpected empty result from synthesize step's tasks results");
|
|
91
123
|
return {
|
|
92
124
|
step,
|
|
93
|
-
|
|
125
|
+
tasks: results,
|
|
126
|
+
result,
|
|
94
127
|
};
|
|
95
128
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
formatStepsResults(stepResults) {
|
|
105
|
-
if (!stepResults.length)
|
|
106
|
-
return "No steps executed yet";
|
|
107
|
-
return stepResults
|
|
108
|
-
.map((stepResult, index) => `${index + 1}:\n${stepResult.task_results.length
|
|
109
|
-
? PromptTemplate.from(STEP_RESULT_TEMPLATE).format({
|
|
110
|
-
step_description: stepResult.step.description,
|
|
111
|
-
tasks_str: stepResult.task_results
|
|
112
|
-
.map((task) => `- ${PromptTemplate.from(TASK_RESULT_TEMPLATE).format({
|
|
113
|
-
task_description: task.description,
|
|
114
|
-
task_result: task.result,
|
|
115
|
-
})}`)
|
|
116
|
-
.join("\n"),
|
|
117
|
-
})
|
|
118
|
-
: "No result"}`)
|
|
119
|
-
.join("\n\n");
|
|
129
|
+
}
|
|
130
|
+
function getMessageOrJsonString(output) {
|
|
131
|
+
const entries = Object.entries(output);
|
|
132
|
+
const firstValue = entries[0]?.[1];
|
|
133
|
+
if (entries.length === 1 && typeof firstValue === "string") {
|
|
134
|
+
return firstValue;
|
|
120
135
|
}
|
|
136
|
+
return JSON.stringify(output);
|
|
121
137
|
}
|
|
@@ -1,51 +1,12 @@
|
|
|
1
|
+
import { type Agent, type Message } from "@aigne/core";
|
|
1
2
|
import { z } from "zod";
|
|
2
|
-
export declare const
|
|
3
|
-
export declare
|
|
4
|
-
export declare const PLAN_RESULT_TEMPLATE = "Plan Objective: {{plan_objective}}\n\nProgress So Far (steps completed):\n{{steps_str}}\n\nPlan Current Status: {{plan_status}}\nPlan Current Result: {{plan_result}}";
|
|
5
|
-
export declare const FULL_PLAN_PROMPT_TEMPLATE = "You are tasked with orchestrating a plan to complete an objective.\nYou can analyze results from the previous steps already executed to decide if the objective is complete.\nYour plan must be structured in sequential steps, with each step containing independent parallel subtasks.\n\nObjective: {{objective}}\n\n{{plan_result}}\n\nIf the previous results achieve the objective, return is_complete=true.\nOtherwise, generate remaining steps needed.\n\nYou have access to the following Agents(which are collections of tools/functions):\n\nAgents:\n{{agents}}\n\nGenerate a plan with all remaining steps needed.\nSteps are sequential, but each Step can have parallel subtasks.\nFor each Step, specify a description of the step and independent subtasks that can run in parallel.\nFor each subtask specify:\n 1. Clear description of the task that an LLM can execute\n 2. Name of 1 Agent to use for the task";
|
|
6
|
-
export declare const TASK_PROMPT_TEMPLATE = "You are part of a larger workflow to achieve the objective: {{objective}}.\nYour job is to accomplish only the following task: {{task}}.\n\nResults so far that may provide helpful context:\n{{context}}";
|
|
7
|
-
export declare const SYNTHESIZE_PLAN_PROMPT_TEMPLATE = "Synthesize the results of executing all steps in the plan into a cohesive result:\n{{plan_result}}";
|
|
8
|
-
export declare const TaskSchema: z.ZodObject<{
|
|
9
|
-
description: z.ZodString;
|
|
10
|
-
agent: z.ZodString;
|
|
11
|
-
}, "strip", z.ZodTypeAny, {
|
|
12
|
-
description: string;
|
|
13
|
-
agent: string;
|
|
14
|
-
}, {
|
|
15
|
-
description: string;
|
|
16
|
-
agent: string;
|
|
17
|
-
}>;
|
|
18
|
-
export declare const StepSchema: z.ZodObject<{
|
|
19
|
-
description: z.ZodString;
|
|
20
|
-
tasks: z.ZodArray<z.ZodObject<{
|
|
21
|
-
description: z.ZodString;
|
|
22
|
-
agent: z.ZodString;
|
|
23
|
-
}, "strip", z.ZodTypeAny, {
|
|
24
|
-
description: string;
|
|
25
|
-
agent: string;
|
|
26
|
-
}, {
|
|
27
|
-
description: string;
|
|
28
|
-
agent: string;
|
|
29
|
-
}>, "many">;
|
|
30
|
-
}, "strip", z.ZodTypeAny, {
|
|
31
|
-
description: string;
|
|
32
|
-
tasks: {
|
|
33
|
-
description: string;
|
|
34
|
-
agent: string;
|
|
35
|
-
}[];
|
|
36
|
-
}, {
|
|
37
|
-
description: string;
|
|
38
|
-
tasks: {
|
|
39
|
-
description: string;
|
|
40
|
-
agent: string;
|
|
41
|
-
}[];
|
|
42
|
-
}>;
|
|
43
|
-
export declare const FullPlanSchema: z.ZodObject<{
|
|
3
|
+
export declare const SYNTHESIZE_PLAN_USER_PROMPT_TEMPLATE = "Synthesize the results of executing all steps in the plan into a cohesive result\n";
|
|
4
|
+
export declare function getFullPlanSchema(agents: Agent[]): z.ZodObject<{
|
|
44
5
|
steps: z.ZodArray<z.ZodObject<{
|
|
45
6
|
description: z.ZodString;
|
|
46
7
|
tasks: z.ZodArray<z.ZodObject<{
|
|
47
8
|
description: z.ZodString;
|
|
48
|
-
agent: z.
|
|
9
|
+
agent: z.ZodUnion<[z.ZodLiteral<string>, z.ZodLiteral<string>, ...z.ZodLiteral<string>[]]>;
|
|
49
10
|
}, "strip", z.ZodTypeAny, {
|
|
50
11
|
description: string;
|
|
51
12
|
agent: string;
|
|
@@ -66,7 +27,7 @@ export declare const FullPlanSchema: z.ZodObject<{
|
|
|
66
27
|
agent: string;
|
|
67
28
|
}[];
|
|
68
29
|
}>, "many">;
|
|
69
|
-
|
|
30
|
+
isComplete: z.ZodBoolean;
|
|
70
31
|
}, "strip", z.ZodTypeAny, {
|
|
71
32
|
steps: {
|
|
72
33
|
description: string;
|
|
@@ -75,7 +36,7 @@ export declare const FullPlanSchema: z.ZodObject<{
|
|
|
75
36
|
agent: string;
|
|
76
37
|
}[];
|
|
77
38
|
}[];
|
|
78
|
-
|
|
39
|
+
isComplete: boolean;
|
|
79
40
|
}, {
|
|
80
41
|
steps: {
|
|
81
42
|
description: string;
|
|
@@ -84,8 +45,47 @@ export declare const FullPlanSchema: z.ZodObject<{
|
|
|
84
45
|
agent: string;
|
|
85
46
|
}[];
|
|
86
47
|
}[];
|
|
87
|
-
|
|
48
|
+
isComplete: boolean;
|
|
88
49
|
}>;
|
|
89
|
-
export type
|
|
90
|
-
export type Step =
|
|
91
|
-
export type
|
|
50
|
+
export type FullPlanOutput = z.infer<ReturnType<typeof getFullPlanSchema>>;
|
|
51
|
+
export type Step = FullPlanOutput["steps"][number];
|
|
52
|
+
export type Task = Step["tasks"][number];
|
|
53
|
+
export interface StepWithResult {
|
|
54
|
+
step: Step;
|
|
55
|
+
tasks: Array<TaskWithResult>;
|
|
56
|
+
result: string;
|
|
57
|
+
}
|
|
58
|
+
export interface TaskWithResult {
|
|
59
|
+
task: Task;
|
|
60
|
+
result: string;
|
|
61
|
+
}
|
|
62
|
+
export interface FullPlanInput extends Message {
|
|
63
|
+
objective: string;
|
|
64
|
+
steps: StepWithResult[];
|
|
65
|
+
plan: {
|
|
66
|
+
status: string;
|
|
67
|
+
result: string;
|
|
68
|
+
};
|
|
69
|
+
agents: {
|
|
70
|
+
name: string;
|
|
71
|
+
description?: string;
|
|
72
|
+
tools: {
|
|
73
|
+
name: string;
|
|
74
|
+
description?: string;
|
|
75
|
+
}[];
|
|
76
|
+
}[];
|
|
77
|
+
}
|
|
78
|
+
export declare const FULL_PLAN_PROMPT_TEMPLATE = "You are tasked with orchestrating a plan to complete an objective.\nYou can analyze results from the previous steps already executed to decide if the objective is complete.\nYour plan must be structured in sequential steps, with each step containing independent parallel subtasks.\n\n<objective>\n{{objective}}\n</objective>\n\n<steps_completed>\n{{#steps}}\n- Step: {{step.description}}\n Result: {{result}}\n{{/steps}}\n</steps_completed>\n\n<previous_plan_status>\n{{plan.status}}\n</previous_plan_status>\n\n<previous_plan_result>\n{{plan.result}}\n</previous_plan_result>\n\nYou have access to the following Agents(which are collections of tools/functions):\n\n<agents>\n{{#agents}}\n- Agent: {{name}}\n Description: {{description}}\n Functions:\n {{#tools}}\n - Tool: {{name}}\n Description: {{description}}\n {{/tools}}\n{{/agents}}\n</agents>\n\n- If the previous plan results achieve the objective, return isComplete=true.\n- Otherwise, generate remaining steps needed.\n- Generate a plan with all remaining steps needed.\n- Steps are sequential, but each Step can have parallel subtasks.\n- For each Step, specify a description of the step and independent subtasks that can run in parallel.\n- For each subtask specify:\n 1. Clear description of the task that an LLM can execute\n 2. Name of 1 Agent to use for the task";
|
|
79
|
+
export interface TaskPromptInput extends Message {
|
|
80
|
+
objective: string;
|
|
81
|
+
step: Step;
|
|
82
|
+
task: Task;
|
|
83
|
+
steps: StepWithResult[];
|
|
84
|
+
}
|
|
85
|
+
export declare const TASK_PROMPT_TEMPLATE = "You are part of a larger workflow to achieve the step then the objective:\n\n<objective>\n{{objective}}\n</objective>\n\n<step>\n{{step.description}}\n</step>\n\nYour job is to accomplish only the following task:\n\n<task>\n{{task.description}}\n</task>\n\nResults so far that may provide helpful context:\n\n<steps_completed>\n{{#steps}}\n- Step: {{step.description}}\n Result: {{result}}\n{{/steps}}\n</steps_completed>\n";
|
|
86
|
+
export interface SynthesizeStepPromptInput extends Message {
|
|
87
|
+
objective: string;
|
|
88
|
+
step: Step;
|
|
89
|
+
tasks: TaskWithResult[];
|
|
90
|
+
}
|
|
91
|
+
export declare const SYNTHESIZE_STEP_PROMPT_TEMPLATE = "Synthesize the results of these parallel tasks into a cohesive result\n\n<objective>\n{{objective}}\n</objective>\n\n<step>\n{{step.description}}\n</step>\n\n<tasks>\n{{#tasks}}\n- Task: {{task.description}}\n Result: {{result}}\n{{/tasks}}\n</tasks>\n";
|
|
@@ -1,54 +1,116 @@
|
|
|
1
|
+
import { ensureZodUnionArray } from "@aigne/core";
|
|
2
|
+
import { groupBy, pickBy } from "lodash-es";
|
|
1
3
|
import { z } from "zod";
|
|
2
|
-
export const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
4
|
+
export const SYNTHESIZE_PLAN_USER_PROMPT_TEMPLATE = `\
|
|
5
|
+
Synthesize the results of executing all steps in the plan into a cohesive result
|
|
6
|
+
`;
|
|
7
|
+
export function getFullPlanSchema(agents) {
|
|
8
|
+
const agentNames = agents.map((i) => i.name);
|
|
9
|
+
if (new Set(agentNames).size !== agentNames.length) {
|
|
10
|
+
const duplicates = pickBy(groupBy(agentNames), (x) => x.length > 1);
|
|
11
|
+
throw new Error(`Tools name must be unique for orchestrator: ${Object.keys(duplicates).join(",")}`);
|
|
12
|
+
}
|
|
13
|
+
const TaskSchema = z.object({
|
|
14
|
+
description: z.string().describe("Detailed description of the task"),
|
|
15
|
+
agent: z
|
|
16
|
+
.union(ensureZodUnionArray(agents.map((i) => z.literal(i.name))))
|
|
17
|
+
.describe("Name of the agent to execute the task"),
|
|
18
|
+
});
|
|
19
|
+
const StepSchema = z.object({
|
|
20
|
+
description: z.string().describe("Detailed description of the step"),
|
|
21
|
+
tasks: z.array(TaskSchema).describe("Tasks that can run in parallel in this step"),
|
|
22
|
+
});
|
|
23
|
+
return z.object({
|
|
24
|
+
steps: z.array(StepSchema).describe("All sequential steps in the plan"),
|
|
25
|
+
isComplete: z.boolean().describe("Whether the previous plan results achieve the objective"),
|
|
26
|
+
});
|
|
27
|
+
}
|
|
14
28
|
export const FULL_PLAN_PROMPT_TEMPLATE = `You are tasked with orchestrating a plan to complete an objective.
|
|
15
29
|
You can analyze results from the previous steps already executed to decide if the objective is complete.
|
|
16
30
|
Your plan must be structured in sequential steps, with each step containing independent parallel subtasks.
|
|
17
31
|
|
|
18
|
-
|
|
32
|
+
<objective>
|
|
33
|
+
{{objective}}
|
|
34
|
+
</objective>
|
|
19
35
|
|
|
20
|
-
|
|
36
|
+
<steps_completed>
|
|
37
|
+
{{#steps}}
|
|
38
|
+
- Step: {{step.description}}
|
|
39
|
+
Result: {{result}}
|
|
40
|
+
{{/steps}}
|
|
41
|
+
</steps_completed>
|
|
21
42
|
|
|
22
|
-
|
|
23
|
-
|
|
43
|
+
<previous_plan_status>
|
|
44
|
+
{{plan.status}}
|
|
45
|
+
</previous_plan_status>
|
|
46
|
+
|
|
47
|
+
<previous_plan_result>
|
|
48
|
+
{{plan.result}}
|
|
49
|
+
</previous_plan_result>
|
|
24
50
|
|
|
25
51
|
You have access to the following Agents(which are collections of tools/functions):
|
|
26
52
|
|
|
27
|
-
|
|
28
|
-
{{agents}}
|
|
53
|
+
<agents>
|
|
54
|
+
{{#agents}}
|
|
55
|
+
- Agent: {{name}}
|
|
56
|
+
Description: {{description}}
|
|
57
|
+
Functions:
|
|
58
|
+
{{#tools}}
|
|
59
|
+
- Tool: {{name}}
|
|
60
|
+
Description: {{description}}
|
|
61
|
+
{{/tools}}
|
|
62
|
+
{{/agents}}
|
|
63
|
+
</agents>
|
|
29
64
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
65
|
+
- If the previous plan results achieve the objective, return isComplete=true.
|
|
66
|
+
- Otherwise, generate remaining steps needed.
|
|
67
|
+
- Generate a plan with all remaining steps needed.
|
|
68
|
+
- Steps are sequential, but each Step can have parallel subtasks.
|
|
69
|
+
- For each Step, specify a description of the step and independent subtasks that can run in parallel.
|
|
70
|
+
- For each subtask specify:
|
|
34
71
|
1. Clear description of the task that an LLM can execute
|
|
35
72
|
2. Name of 1 Agent to use for the task`;
|
|
36
|
-
export const TASK_PROMPT_TEMPLATE =
|
|
37
|
-
|
|
73
|
+
export const TASK_PROMPT_TEMPLATE = `\
|
|
74
|
+
You are part of a larger workflow to achieve the step then the objective:
|
|
75
|
+
|
|
76
|
+
<objective>
|
|
77
|
+
{{objective}}
|
|
78
|
+
</objective>
|
|
79
|
+
|
|
80
|
+
<step>
|
|
81
|
+
{{step.description}}
|
|
82
|
+
</step>
|
|
83
|
+
|
|
84
|
+
Your job is to accomplish only the following task:
|
|
85
|
+
|
|
86
|
+
<task>
|
|
87
|
+
{{task.description}}
|
|
88
|
+
</task>
|
|
38
89
|
|
|
39
90
|
Results so far that may provide helpful context:
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
{{
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
91
|
+
|
|
92
|
+
<steps_completed>
|
|
93
|
+
{{#steps}}
|
|
94
|
+
- Step: {{step.description}}
|
|
95
|
+
Result: {{result}}
|
|
96
|
+
{{/steps}}
|
|
97
|
+
</steps_completed>
|
|
98
|
+
`;
|
|
99
|
+
export const SYNTHESIZE_STEP_PROMPT_TEMPLATE = `\
|
|
100
|
+
Synthesize the results of these parallel tasks into a cohesive result
|
|
101
|
+
|
|
102
|
+
<objective>
|
|
103
|
+
{{objective}}
|
|
104
|
+
</objective>
|
|
105
|
+
|
|
106
|
+
<step>
|
|
107
|
+
{{step.description}}
|
|
108
|
+
</step>
|
|
109
|
+
|
|
110
|
+
<tasks>
|
|
111
|
+
{{#tasks}}
|
|
112
|
+
- Task: {{task.description}}
|
|
113
|
+
Result: {{result}}
|
|
114
|
+
{{/tasks}}
|
|
115
|
+
</tasks>
|
|
116
|
+
`;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type": "module"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aigne/agent-library",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"description": "Collection of agent libraries for AIGNE framework",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -32,8 +32,10 @@
|
|
|
32
32
|
}
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
+
"fastq": "^1.19.1",
|
|
36
|
+
"lodash-es": "^4.17.21",
|
|
35
37
|
"zod": "^3.24.2",
|
|
36
|
-
"@aigne/core": "^1.
|
|
38
|
+
"@aigne/core": "^1.4.0"
|
|
37
39
|
},
|
|
38
40
|
"devDependencies": {
|
|
39
41
|
"@types/bun": "^1.2.5",
|
|
@@ -46,6 +48,7 @@
|
|
|
46
48
|
"build": "tsc --build scripts/tsconfig.build.json",
|
|
47
49
|
"clean": "rimraf lib coverage",
|
|
48
50
|
"test": "bun test",
|
|
49
|
-
"test:coverage": "bun test --coverage --coverage-reporter=lcov --coverage-reporter=text"
|
|
51
|
+
"test:coverage": "bun test --coverage --coverage-reporter=lcov --coverage-reporter=text",
|
|
52
|
+
"postbuild": "echo '{\"type\": \"module\"}' > lib/esm/package.json && echo '{\"type\": \"commonjs\"}' > lib/cjs/package.json"
|
|
50
53
|
}
|
|
51
54
|
}
|