@aigne/agent-library 1.22.4-beta → 1.23.0-beta
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 +25 -0
- package/README.md +6 -94
- package/lib/cjs/orchestrator/index.d.ts +39 -71
- package/lib/cjs/orchestrator/index.js +174 -169
- package/lib/cjs/orchestrator/prompt.d.ts +3 -0
- package/lib/cjs/orchestrator/prompt.js +82 -0
- package/lib/cjs/orchestrator/type.d.ts +505 -0
- package/lib/cjs/orchestrator/type.js +83 -0
- package/lib/dts/orchestrator/index.d.ts +39 -71
- package/lib/dts/orchestrator/prompt.d.ts +3 -0
- package/lib/dts/orchestrator/type.d.ts +505 -0
- package/lib/esm/orchestrator/index.d.ts +39 -71
- package/lib/esm/orchestrator/index.js +176 -154
- package/lib/esm/orchestrator/prompt.d.ts +3 -0
- package/lib/esm/orchestrator/prompt.js +79 -0
- package/lib/esm/orchestrator/type.d.ts +505 -0
- package/lib/esm/orchestrator/type.js +77 -0
- package/package.json +12 -6
- package/lib/cjs/orchestrator/orchestrator-prompts.d.ts +0 -130
- package/lib/cjs/orchestrator/orchestrator-prompts.js +0 -135
- package/lib/dts/orchestrator/orchestrator-prompts.d.ts +0 -130
- package/lib/esm/orchestrator/orchestrator-prompts.d.ts +0 -130
- package/lib/esm/orchestrator/orchestrator-prompts.js +0 -131
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare const ORCHESTRATOR_COMPLETE_PROMPT = "You are an intelligent assistant that synthesizes and presents the results of completed tasks.\n\n## User Objective\n{{ objective }}\n\n## Execution Results\n{{ executionState | yaml.stringify }}\n\n## Your Task\nBased on the execution results above, provide a comprehensive and helpful response to the user's objective.\n";
|
|
2
|
+
export declare const TODO_PLANNER_PROMPT_TEMPLATE = "You are an intelligent task planner that determines what needs to be done next to achieve the user's objective.\n\n## Your Role\nContinuously evaluate progress and decide the next task to execute. You work iteratively - planning one task at a time based on the current state and previous results.\n\n## Available Skills\n{{ skills | yaml.stringify }}\n\n## User Objective\n{{ objective }}\n\n## Current State\n{{ executionState | yaml.stringify }}\n\n## Understanding Task Status\nEach task in the execution state has a status:\n- **completed**: Task finished successfully, result is available\n- **failed**: Task encountered an error, check error field for details\n- **pending**: Task has not been executed yet\n\n## Your Task\nBased on the objective, current state, and any previous results, determine what should happen next:\n\n1. **If the objective is achieved or all work is complete:** Set finished: true and leave nextTask empty\n2. **If a previous task failed:** Decide whether to retry, skip, or use an alternative approach\n3. **If more work is needed:** Provide a clear, actionable nextTask description\n\n### Guidelines:\n- Focus on the immediate next step, not the entire plan\n- Review task history to avoid repeating work and build on previous results\n- Pay attention to task status - handle failures appropriately\n- Write self-contained task descriptions that the worker can execute independently\n- Set finished: true when the objective is satisfied\n- Consider retrying failed tasks with different approaches if appropriate\n";
|
|
3
|
+
export declare const TODO_WORKER_PROMPT_TEMPLATE = "You are a task execution agent. Your job is to execute the specific task assigned to you - nothing more, nothing less.\n\n## Overall Objective (For Context Only)\n{{ objective }}\n\n**CRITICAL CONSTRAINT**: The objective above is provided ONLY for context. You must NOT attempt to:\n- Solve the entire objective\n- Plan additional steps beyond your current task\n- Make decisions about what should happen next\n- Execute any tasks other than the one explicitly assigned to you below\n\nYour SOLE responsibility is to execute the specific task described below and return the result.\n\n## Current Execution State\n{{ executionState | yaml.stringify }}\n\n## Your Current Task\n{{ task }}\n\n## Important Instructions\n- Focus EXCLUSIVELY on completing the current task described above\n- The task is self-contained - execute it completely and accurately\n- Do NOT perform additional tasks beyond what is specified\n- Do NOT try to determine what should happen after this task\n- Use the available tools and skills to accomplish this specific task\n- Return a clear result that the planner can use to decide the next step\n\n## Output Format\nReturn your task execution result as a structured response. The output schema will guide you on the required fields.\n";
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TODO_WORKER_PROMPT_TEMPLATE = exports.TODO_PLANNER_PROMPT_TEMPLATE = exports.ORCHESTRATOR_COMPLETE_PROMPT = void 0;
|
|
4
|
+
exports.ORCHESTRATOR_COMPLETE_PROMPT = `\
|
|
5
|
+
You are an intelligent assistant that synthesizes and presents the results of completed tasks.
|
|
6
|
+
|
|
7
|
+
## User Objective
|
|
8
|
+
{{ objective }}
|
|
9
|
+
|
|
10
|
+
## Execution Results
|
|
11
|
+
{{ executionState | yaml.stringify }}
|
|
12
|
+
|
|
13
|
+
## Your Task
|
|
14
|
+
Based on the execution results above, provide a comprehensive and helpful response to the user's objective.
|
|
15
|
+
`;
|
|
16
|
+
exports.TODO_PLANNER_PROMPT_TEMPLATE = `\
|
|
17
|
+
You are an intelligent task planner that determines what needs to be done next to achieve the user's objective.
|
|
18
|
+
|
|
19
|
+
## Your Role
|
|
20
|
+
Continuously evaluate progress and decide the next task to execute. You work iteratively - planning one task at a time based on the current state and previous results.
|
|
21
|
+
|
|
22
|
+
## Available Skills
|
|
23
|
+
{{ skills | yaml.stringify }}
|
|
24
|
+
|
|
25
|
+
## User Objective
|
|
26
|
+
{{ objective }}
|
|
27
|
+
|
|
28
|
+
## Current State
|
|
29
|
+
{{ executionState | yaml.stringify }}
|
|
30
|
+
|
|
31
|
+
## Understanding Task Status
|
|
32
|
+
Each task in the execution state has a status:
|
|
33
|
+
- **completed**: Task finished successfully, result is available
|
|
34
|
+
- **failed**: Task encountered an error, check error field for details
|
|
35
|
+
- **pending**: Task has not been executed yet
|
|
36
|
+
|
|
37
|
+
## Your Task
|
|
38
|
+
Based on the objective, current state, and any previous results, determine what should happen next:
|
|
39
|
+
|
|
40
|
+
1. **If the objective is achieved or all work is complete:** Set finished: true and leave nextTask empty
|
|
41
|
+
2. **If a previous task failed:** Decide whether to retry, skip, or use an alternative approach
|
|
42
|
+
3. **If more work is needed:** Provide a clear, actionable nextTask description
|
|
43
|
+
|
|
44
|
+
### Guidelines:
|
|
45
|
+
- Focus on the immediate next step, not the entire plan
|
|
46
|
+
- Review task history to avoid repeating work and build on previous results
|
|
47
|
+
- Pay attention to task status - handle failures appropriately
|
|
48
|
+
- Write self-contained task descriptions that the worker can execute independently
|
|
49
|
+
- Set finished: true when the objective is satisfied
|
|
50
|
+
- Consider retrying failed tasks with different approaches if appropriate
|
|
51
|
+
`;
|
|
52
|
+
exports.TODO_WORKER_PROMPT_TEMPLATE = `\
|
|
53
|
+
You are a task execution agent. Your job is to execute the specific task assigned to you - nothing more, nothing less.
|
|
54
|
+
|
|
55
|
+
## Overall Objective (For Context Only)
|
|
56
|
+
{{ objective }}
|
|
57
|
+
|
|
58
|
+
**CRITICAL CONSTRAINT**: The objective above is provided ONLY for context. You must NOT attempt to:
|
|
59
|
+
- Solve the entire objective
|
|
60
|
+
- Plan additional steps beyond your current task
|
|
61
|
+
- Make decisions about what should happen next
|
|
62
|
+
- Execute any tasks other than the one explicitly assigned to you below
|
|
63
|
+
|
|
64
|
+
Your SOLE responsibility is to execute the specific task described below and return the result.
|
|
65
|
+
|
|
66
|
+
## Current Execution State
|
|
67
|
+
{{ executionState | yaml.stringify }}
|
|
68
|
+
|
|
69
|
+
## Your Current Task
|
|
70
|
+
{{ task }}
|
|
71
|
+
|
|
72
|
+
## Important Instructions
|
|
73
|
+
- Focus EXCLUSIVELY on completing the current task described above
|
|
74
|
+
- The task is self-contained - execute it completely and accurately
|
|
75
|
+
- Do NOT perform additional tasks beyond what is specified
|
|
76
|
+
- Do NOT try to determine what should happen after this task
|
|
77
|
+
- Use the available tools and skills to accomplish this specific task
|
|
78
|
+
- Return a clear result that the planner can use to decide the next step
|
|
79
|
+
|
|
80
|
+
## Output Format
|
|
81
|
+
Return your task execution result as a structured response. The output schema will guide you on the required fields.
|
|
82
|
+
`;
|
|
@@ -0,0 +1,505 @@
|
|
|
1
|
+
import type { Message } from "@aigne/core";
|
|
2
|
+
import z from "zod";
|
|
3
|
+
/**
|
|
4
|
+
* Task execution status
|
|
5
|
+
*/
|
|
6
|
+
export type TaskStatus = "pending" | "completed" | "failed";
|
|
7
|
+
/**
|
|
8
|
+
* Individual task execution record
|
|
9
|
+
*/
|
|
10
|
+
export interface TaskRecord {
|
|
11
|
+
/** Task description */
|
|
12
|
+
task: string;
|
|
13
|
+
/** Task execution status */
|
|
14
|
+
status: TaskStatus;
|
|
15
|
+
/** Task execution result (can be any type) */
|
|
16
|
+
result?: unknown;
|
|
17
|
+
/** Error information if task failed */
|
|
18
|
+
error?: {
|
|
19
|
+
message: string;
|
|
20
|
+
};
|
|
21
|
+
/** Timestamp when task was created */
|
|
22
|
+
createdAt?: number;
|
|
23
|
+
/** Timestamp when task was completed or failed */
|
|
24
|
+
completedAt?: number;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Execution state tracking all tasks
|
|
28
|
+
*/
|
|
29
|
+
export interface ExecutionState {
|
|
30
|
+
tasks: TaskRecord[];
|
|
31
|
+
}
|
|
32
|
+
export declare const taskRecordSchema: z.ZodObject<{
|
|
33
|
+
task: z.ZodString;
|
|
34
|
+
status: z.ZodEnum<["pending", "completed", "failed"]>;
|
|
35
|
+
result: z.ZodOptional<z.ZodUnknown>;
|
|
36
|
+
error: z.ZodOptional<z.ZodObject<{
|
|
37
|
+
message: z.ZodString;
|
|
38
|
+
}, "strip", z.ZodTypeAny, {
|
|
39
|
+
message: string;
|
|
40
|
+
}, {
|
|
41
|
+
message: string;
|
|
42
|
+
}>>;
|
|
43
|
+
createdAt: z.ZodOptional<z.ZodNumber>;
|
|
44
|
+
completedAt: z.ZodOptional<z.ZodNumber>;
|
|
45
|
+
}, "strip", z.ZodTypeAny, {
|
|
46
|
+
status: "pending" | "completed" | "failed";
|
|
47
|
+
task: string;
|
|
48
|
+
error?: {
|
|
49
|
+
message: string;
|
|
50
|
+
} | undefined;
|
|
51
|
+
result?: unknown;
|
|
52
|
+
createdAt?: number | undefined;
|
|
53
|
+
completedAt?: number | undefined;
|
|
54
|
+
}, {
|
|
55
|
+
status: "pending" | "completed" | "failed";
|
|
56
|
+
task: string;
|
|
57
|
+
error?: {
|
|
58
|
+
message: string;
|
|
59
|
+
} | undefined;
|
|
60
|
+
result?: unknown;
|
|
61
|
+
createdAt?: number | undefined;
|
|
62
|
+
completedAt?: number | undefined;
|
|
63
|
+
}>;
|
|
64
|
+
export declare const executionStateSchema: z.ZodObject<{
|
|
65
|
+
tasks: z.ZodArray<z.ZodObject<{
|
|
66
|
+
task: z.ZodString;
|
|
67
|
+
status: z.ZodEnum<["pending", "completed", "failed"]>;
|
|
68
|
+
result: z.ZodOptional<z.ZodUnknown>;
|
|
69
|
+
error: z.ZodOptional<z.ZodObject<{
|
|
70
|
+
message: z.ZodString;
|
|
71
|
+
}, "strip", z.ZodTypeAny, {
|
|
72
|
+
message: string;
|
|
73
|
+
}, {
|
|
74
|
+
message: string;
|
|
75
|
+
}>>;
|
|
76
|
+
createdAt: z.ZodOptional<z.ZodNumber>;
|
|
77
|
+
completedAt: z.ZodOptional<z.ZodNumber>;
|
|
78
|
+
}, "strip", z.ZodTypeAny, {
|
|
79
|
+
status: "pending" | "completed" | "failed";
|
|
80
|
+
task: string;
|
|
81
|
+
error?: {
|
|
82
|
+
message: string;
|
|
83
|
+
} | undefined;
|
|
84
|
+
result?: unknown;
|
|
85
|
+
createdAt?: number | undefined;
|
|
86
|
+
completedAt?: number | undefined;
|
|
87
|
+
}, {
|
|
88
|
+
status: "pending" | "completed" | "failed";
|
|
89
|
+
task: string;
|
|
90
|
+
error?: {
|
|
91
|
+
message: string;
|
|
92
|
+
} | undefined;
|
|
93
|
+
result?: unknown;
|
|
94
|
+
createdAt?: number | undefined;
|
|
95
|
+
completedAt?: number | undefined;
|
|
96
|
+
}>, "many">;
|
|
97
|
+
}, "strip", z.ZodTypeAny, {
|
|
98
|
+
tasks: {
|
|
99
|
+
status: "pending" | "completed" | "failed";
|
|
100
|
+
task: string;
|
|
101
|
+
error?: {
|
|
102
|
+
message: string;
|
|
103
|
+
} | undefined;
|
|
104
|
+
result?: unknown;
|
|
105
|
+
createdAt?: number | undefined;
|
|
106
|
+
completedAt?: number | undefined;
|
|
107
|
+
}[];
|
|
108
|
+
}, {
|
|
109
|
+
tasks: {
|
|
110
|
+
status: "pending" | "completed" | "failed";
|
|
111
|
+
task: string;
|
|
112
|
+
error?: {
|
|
113
|
+
message: string;
|
|
114
|
+
} | undefined;
|
|
115
|
+
result?: unknown;
|
|
116
|
+
createdAt?: number | undefined;
|
|
117
|
+
completedAt?: number | undefined;
|
|
118
|
+
}[];
|
|
119
|
+
}>;
|
|
120
|
+
export interface PlannerInput extends Message {
|
|
121
|
+
objective: string;
|
|
122
|
+
skills: {
|
|
123
|
+
name: string;
|
|
124
|
+
description?: string;
|
|
125
|
+
}[];
|
|
126
|
+
executionState: ExecutionState;
|
|
127
|
+
}
|
|
128
|
+
export declare const plannerInputSchema: z.ZodObject<{
|
|
129
|
+
objective: z.ZodString;
|
|
130
|
+
skills: z.ZodArray<z.ZodObject<{
|
|
131
|
+
name: z.ZodString;
|
|
132
|
+
description: z.ZodOptional<z.ZodString>;
|
|
133
|
+
}, "strip", z.ZodTypeAny, {
|
|
134
|
+
name: string;
|
|
135
|
+
description?: string | undefined;
|
|
136
|
+
}, {
|
|
137
|
+
name: string;
|
|
138
|
+
description?: string | undefined;
|
|
139
|
+
}>, "many">;
|
|
140
|
+
executionState: z.ZodObject<{
|
|
141
|
+
tasks: z.ZodArray<z.ZodObject<{
|
|
142
|
+
task: z.ZodString;
|
|
143
|
+
status: z.ZodEnum<["pending", "completed", "failed"]>;
|
|
144
|
+
result: z.ZodOptional<z.ZodUnknown>;
|
|
145
|
+
error: z.ZodOptional<z.ZodObject<{
|
|
146
|
+
message: z.ZodString;
|
|
147
|
+
}, "strip", z.ZodTypeAny, {
|
|
148
|
+
message: string;
|
|
149
|
+
}, {
|
|
150
|
+
message: string;
|
|
151
|
+
}>>;
|
|
152
|
+
createdAt: z.ZodOptional<z.ZodNumber>;
|
|
153
|
+
completedAt: z.ZodOptional<z.ZodNumber>;
|
|
154
|
+
}, "strip", z.ZodTypeAny, {
|
|
155
|
+
status: "pending" | "completed" | "failed";
|
|
156
|
+
task: string;
|
|
157
|
+
error?: {
|
|
158
|
+
message: string;
|
|
159
|
+
} | undefined;
|
|
160
|
+
result?: unknown;
|
|
161
|
+
createdAt?: number | undefined;
|
|
162
|
+
completedAt?: number | undefined;
|
|
163
|
+
}, {
|
|
164
|
+
status: "pending" | "completed" | "failed";
|
|
165
|
+
task: string;
|
|
166
|
+
error?: {
|
|
167
|
+
message: string;
|
|
168
|
+
} | undefined;
|
|
169
|
+
result?: unknown;
|
|
170
|
+
createdAt?: number | undefined;
|
|
171
|
+
completedAt?: number | undefined;
|
|
172
|
+
}>, "many">;
|
|
173
|
+
}, "strip", z.ZodTypeAny, {
|
|
174
|
+
tasks: {
|
|
175
|
+
status: "pending" | "completed" | "failed";
|
|
176
|
+
task: string;
|
|
177
|
+
error?: {
|
|
178
|
+
message: string;
|
|
179
|
+
} | undefined;
|
|
180
|
+
result?: unknown;
|
|
181
|
+
createdAt?: number | undefined;
|
|
182
|
+
completedAt?: number | undefined;
|
|
183
|
+
}[];
|
|
184
|
+
}, {
|
|
185
|
+
tasks: {
|
|
186
|
+
status: "pending" | "completed" | "failed";
|
|
187
|
+
task: string;
|
|
188
|
+
error?: {
|
|
189
|
+
message: string;
|
|
190
|
+
} | undefined;
|
|
191
|
+
result?: unknown;
|
|
192
|
+
createdAt?: number | undefined;
|
|
193
|
+
completedAt?: number | undefined;
|
|
194
|
+
}[];
|
|
195
|
+
}>;
|
|
196
|
+
}, "strip", z.ZodTypeAny, {
|
|
197
|
+
skills: {
|
|
198
|
+
name: string;
|
|
199
|
+
description?: string | undefined;
|
|
200
|
+
}[];
|
|
201
|
+
objective: string;
|
|
202
|
+
executionState: {
|
|
203
|
+
tasks: {
|
|
204
|
+
status: "pending" | "completed" | "failed";
|
|
205
|
+
task: string;
|
|
206
|
+
error?: {
|
|
207
|
+
message: string;
|
|
208
|
+
} | undefined;
|
|
209
|
+
result?: unknown;
|
|
210
|
+
createdAt?: number | undefined;
|
|
211
|
+
completedAt?: number | undefined;
|
|
212
|
+
}[];
|
|
213
|
+
};
|
|
214
|
+
}, {
|
|
215
|
+
skills: {
|
|
216
|
+
name: string;
|
|
217
|
+
description?: string | undefined;
|
|
218
|
+
}[];
|
|
219
|
+
objective: string;
|
|
220
|
+
executionState: {
|
|
221
|
+
tasks: {
|
|
222
|
+
status: "pending" | "completed" | "failed";
|
|
223
|
+
task: string;
|
|
224
|
+
error?: {
|
|
225
|
+
message: string;
|
|
226
|
+
} | undefined;
|
|
227
|
+
result?: unknown;
|
|
228
|
+
createdAt?: number | undefined;
|
|
229
|
+
completedAt?: number | undefined;
|
|
230
|
+
}[];
|
|
231
|
+
};
|
|
232
|
+
}>;
|
|
233
|
+
export interface PlannerOutput extends Message {
|
|
234
|
+
nextTask?: string;
|
|
235
|
+
finished?: boolean;
|
|
236
|
+
}
|
|
237
|
+
export declare const plannerOutputSchema: z.ZodObject<{
|
|
238
|
+
nextTask: z.ZodOptional<z.ZodString>;
|
|
239
|
+
finished: z.ZodOptional<z.ZodBoolean>;
|
|
240
|
+
}, "strip", z.ZodTypeAny, {
|
|
241
|
+
nextTask?: string | undefined;
|
|
242
|
+
finished?: boolean | undefined;
|
|
243
|
+
}, {
|
|
244
|
+
nextTask?: string | undefined;
|
|
245
|
+
finished?: boolean | undefined;
|
|
246
|
+
}>;
|
|
247
|
+
export interface WorkerInput extends Message {
|
|
248
|
+
objective: string;
|
|
249
|
+
executionState: ExecutionState;
|
|
250
|
+
task: string;
|
|
251
|
+
}
|
|
252
|
+
export declare const workerInputSchema: z.ZodObject<{
|
|
253
|
+
objective: z.ZodString;
|
|
254
|
+
task: z.ZodString;
|
|
255
|
+
executionState: z.ZodObject<{
|
|
256
|
+
tasks: z.ZodArray<z.ZodObject<{
|
|
257
|
+
task: z.ZodString;
|
|
258
|
+
status: z.ZodEnum<["pending", "completed", "failed"]>;
|
|
259
|
+
result: z.ZodOptional<z.ZodUnknown>;
|
|
260
|
+
error: z.ZodOptional<z.ZodObject<{
|
|
261
|
+
message: z.ZodString;
|
|
262
|
+
}, "strip", z.ZodTypeAny, {
|
|
263
|
+
message: string;
|
|
264
|
+
}, {
|
|
265
|
+
message: string;
|
|
266
|
+
}>>;
|
|
267
|
+
createdAt: z.ZodOptional<z.ZodNumber>;
|
|
268
|
+
completedAt: z.ZodOptional<z.ZodNumber>;
|
|
269
|
+
}, "strip", z.ZodTypeAny, {
|
|
270
|
+
status: "pending" | "completed" | "failed";
|
|
271
|
+
task: string;
|
|
272
|
+
error?: {
|
|
273
|
+
message: string;
|
|
274
|
+
} | undefined;
|
|
275
|
+
result?: unknown;
|
|
276
|
+
createdAt?: number | undefined;
|
|
277
|
+
completedAt?: number | undefined;
|
|
278
|
+
}, {
|
|
279
|
+
status: "pending" | "completed" | "failed";
|
|
280
|
+
task: string;
|
|
281
|
+
error?: {
|
|
282
|
+
message: string;
|
|
283
|
+
} | undefined;
|
|
284
|
+
result?: unknown;
|
|
285
|
+
createdAt?: number | undefined;
|
|
286
|
+
completedAt?: number | undefined;
|
|
287
|
+
}>, "many">;
|
|
288
|
+
}, "strip", z.ZodTypeAny, {
|
|
289
|
+
tasks: {
|
|
290
|
+
status: "pending" | "completed" | "failed";
|
|
291
|
+
task: string;
|
|
292
|
+
error?: {
|
|
293
|
+
message: string;
|
|
294
|
+
} | undefined;
|
|
295
|
+
result?: unknown;
|
|
296
|
+
createdAt?: number | undefined;
|
|
297
|
+
completedAt?: number | undefined;
|
|
298
|
+
}[];
|
|
299
|
+
}, {
|
|
300
|
+
tasks: {
|
|
301
|
+
status: "pending" | "completed" | "failed";
|
|
302
|
+
task: string;
|
|
303
|
+
error?: {
|
|
304
|
+
message: string;
|
|
305
|
+
} | undefined;
|
|
306
|
+
result?: unknown;
|
|
307
|
+
createdAt?: number | undefined;
|
|
308
|
+
completedAt?: number | undefined;
|
|
309
|
+
}[];
|
|
310
|
+
}>;
|
|
311
|
+
}, "strip", z.ZodTypeAny, {
|
|
312
|
+
task: string;
|
|
313
|
+
objective: string;
|
|
314
|
+
executionState: {
|
|
315
|
+
tasks: {
|
|
316
|
+
status: "pending" | "completed" | "failed";
|
|
317
|
+
task: string;
|
|
318
|
+
error?: {
|
|
319
|
+
message: string;
|
|
320
|
+
} | undefined;
|
|
321
|
+
result?: unknown;
|
|
322
|
+
createdAt?: number | undefined;
|
|
323
|
+
completedAt?: number | undefined;
|
|
324
|
+
}[];
|
|
325
|
+
};
|
|
326
|
+
}, {
|
|
327
|
+
task: string;
|
|
328
|
+
objective: string;
|
|
329
|
+
executionState: {
|
|
330
|
+
tasks: {
|
|
331
|
+
status: "pending" | "completed" | "failed";
|
|
332
|
+
task: string;
|
|
333
|
+
error?: {
|
|
334
|
+
message: string;
|
|
335
|
+
} | undefined;
|
|
336
|
+
result?: unknown;
|
|
337
|
+
createdAt?: number | undefined;
|
|
338
|
+
completedAt?: number | undefined;
|
|
339
|
+
}[];
|
|
340
|
+
};
|
|
341
|
+
}>;
|
|
342
|
+
/**
|
|
343
|
+
* Worker output structure
|
|
344
|
+
*/
|
|
345
|
+
export interface WorkerOutput extends Message {
|
|
346
|
+
/** Task execution result */
|
|
347
|
+
result?: string;
|
|
348
|
+
/** Whether the task was completed successfully */
|
|
349
|
+
success: boolean;
|
|
350
|
+
/** Error information if task failed */
|
|
351
|
+
error?: {
|
|
352
|
+
message: string;
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
export declare const workerOutputSchema: z.ZodObject<{
|
|
356
|
+
result: z.ZodOptional<z.ZodString>;
|
|
357
|
+
success: z.ZodBoolean;
|
|
358
|
+
error: z.ZodOptional<z.ZodObject<{
|
|
359
|
+
message: z.ZodString;
|
|
360
|
+
}, "strip", z.ZodTypeAny, {
|
|
361
|
+
message: string;
|
|
362
|
+
}, {
|
|
363
|
+
message: string;
|
|
364
|
+
}>>;
|
|
365
|
+
}, "strip", z.ZodTypeAny, {
|
|
366
|
+
success: boolean;
|
|
367
|
+
error?: {
|
|
368
|
+
message: string;
|
|
369
|
+
} | undefined;
|
|
370
|
+
result?: string | undefined;
|
|
371
|
+
}, {
|
|
372
|
+
success: boolean;
|
|
373
|
+
error?: {
|
|
374
|
+
message: string;
|
|
375
|
+
} | undefined;
|
|
376
|
+
result?: string | undefined;
|
|
377
|
+
}>;
|
|
378
|
+
export interface CompleterInput extends Message {
|
|
379
|
+
objective: string;
|
|
380
|
+
executionState: ExecutionState;
|
|
381
|
+
}
|
|
382
|
+
export declare const completerInputSchema: z.ZodObject<{
|
|
383
|
+
objective: z.ZodString;
|
|
384
|
+
executionState: z.ZodObject<{
|
|
385
|
+
tasks: z.ZodArray<z.ZodObject<{
|
|
386
|
+
task: z.ZodString;
|
|
387
|
+
status: z.ZodEnum<["pending", "completed", "failed"]>;
|
|
388
|
+
result: z.ZodOptional<z.ZodUnknown>;
|
|
389
|
+
error: z.ZodOptional<z.ZodObject<{
|
|
390
|
+
message: z.ZodString;
|
|
391
|
+
}, "strip", z.ZodTypeAny, {
|
|
392
|
+
message: string;
|
|
393
|
+
}, {
|
|
394
|
+
message: string;
|
|
395
|
+
}>>;
|
|
396
|
+
createdAt: z.ZodOptional<z.ZodNumber>;
|
|
397
|
+
completedAt: z.ZodOptional<z.ZodNumber>;
|
|
398
|
+
}, "strip", z.ZodTypeAny, {
|
|
399
|
+
status: "pending" | "completed" | "failed";
|
|
400
|
+
task: string;
|
|
401
|
+
error?: {
|
|
402
|
+
message: string;
|
|
403
|
+
} | undefined;
|
|
404
|
+
result?: unknown;
|
|
405
|
+
createdAt?: number | undefined;
|
|
406
|
+
completedAt?: number | undefined;
|
|
407
|
+
}, {
|
|
408
|
+
status: "pending" | "completed" | "failed";
|
|
409
|
+
task: string;
|
|
410
|
+
error?: {
|
|
411
|
+
message: string;
|
|
412
|
+
} | undefined;
|
|
413
|
+
result?: unknown;
|
|
414
|
+
createdAt?: number | undefined;
|
|
415
|
+
completedAt?: number | undefined;
|
|
416
|
+
}>, "many">;
|
|
417
|
+
}, "strip", z.ZodTypeAny, {
|
|
418
|
+
tasks: {
|
|
419
|
+
status: "pending" | "completed" | "failed";
|
|
420
|
+
task: string;
|
|
421
|
+
error?: {
|
|
422
|
+
message: string;
|
|
423
|
+
} | undefined;
|
|
424
|
+
result?: unknown;
|
|
425
|
+
createdAt?: number | undefined;
|
|
426
|
+
completedAt?: number | undefined;
|
|
427
|
+
}[];
|
|
428
|
+
}, {
|
|
429
|
+
tasks: {
|
|
430
|
+
status: "pending" | "completed" | "failed";
|
|
431
|
+
task: string;
|
|
432
|
+
error?: {
|
|
433
|
+
message: string;
|
|
434
|
+
} | undefined;
|
|
435
|
+
result?: unknown;
|
|
436
|
+
createdAt?: number | undefined;
|
|
437
|
+
completedAt?: number | undefined;
|
|
438
|
+
}[];
|
|
439
|
+
}>;
|
|
440
|
+
}, "strip", z.ZodTypeAny, {
|
|
441
|
+
objective: string;
|
|
442
|
+
executionState: {
|
|
443
|
+
tasks: {
|
|
444
|
+
status: "pending" | "completed" | "failed";
|
|
445
|
+
task: string;
|
|
446
|
+
error?: {
|
|
447
|
+
message: string;
|
|
448
|
+
} | undefined;
|
|
449
|
+
result?: unknown;
|
|
450
|
+
createdAt?: number | undefined;
|
|
451
|
+
completedAt?: number | undefined;
|
|
452
|
+
}[];
|
|
453
|
+
};
|
|
454
|
+
}, {
|
|
455
|
+
objective: string;
|
|
456
|
+
executionState: {
|
|
457
|
+
tasks: {
|
|
458
|
+
status: "pending" | "completed" | "failed";
|
|
459
|
+
task: string;
|
|
460
|
+
error?: {
|
|
461
|
+
message: string;
|
|
462
|
+
} | undefined;
|
|
463
|
+
result?: unknown;
|
|
464
|
+
createdAt?: number | undefined;
|
|
465
|
+
completedAt?: number | undefined;
|
|
466
|
+
}[];
|
|
467
|
+
};
|
|
468
|
+
}>;
|
|
469
|
+
/**
|
|
470
|
+
* Default maximum number of task execution iterations
|
|
471
|
+
*/
|
|
472
|
+
export declare const DEFAULT_MAX_ITERATIONS = 20;
|
|
473
|
+
/**
|
|
474
|
+
* Options for managing execution state to prevent context overflow
|
|
475
|
+
*/
|
|
476
|
+
export interface StateManagementOptions {
|
|
477
|
+
/**
|
|
478
|
+
* Maximum tokens allowed for execution state
|
|
479
|
+
* When exceeded, triggers compression
|
|
480
|
+
*/
|
|
481
|
+
maxTokens?: number;
|
|
482
|
+
/**
|
|
483
|
+
* Number of recent tasks to keep when compression is triggered
|
|
484
|
+
*/
|
|
485
|
+
keepRecent?: number;
|
|
486
|
+
/**
|
|
487
|
+
* Maximum number of task execution iterations
|
|
488
|
+
* When reached, orchestrator will stop and synthesize final result
|
|
489
|
+
* @default 20
|
|
490
|
+
*/
|
|
491
|
+
maxIterations?: number;
|
|
492
|
+
}
|
|
493
|
+
export declare const stateManagementOptionsSchema: z.ZodObject<{
|
|
494
|
+
maxTokens: z.ZodType<number | undefined, z.ZodTypeDef, number | undefined>;
|
|
495
|
+
keepRecent: z.ZodType<number | undefined, z.ZodTypeDef, number | undefined>;
|
|
496
|
+
maxIterations: z.ZodType<number | undefined, z.ZodTypeDef, number | undefined>;
|
|
497
|
+
}, "strip", z.ZodTypeAny, {
|
|
498
|
+
maxTokens?: number | undefined;
|
|
499
|
+
keepRecent?: number | undefined;
|
|
500
|
+
maxIterations?: number | undefined;
|
|
501
|
+
}, {
|
|
502
|
+
maxTokens?: number | undefined;
|
|
503
|
+
keepRecent?: number | undefined;
|
|
504
|
+
maxIterations?: number | undefined;
|
|
505
|
+
}>;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.stateManagementOptionsSchema = exports.DEFAULT_MAX_ITERATIONS = exports.completerInputSchema = exports.workerOutputSchema = exports.workerInputSchema = exports.plannerOutputSchema = exports.plannerInputSchema = exports.executionStateSchema = exports.taskRecordSchema = void 0;
|
|
7
|
+
const schema_js_1 = require("@aigne/core/loader/schema.js");
|
|
8
|
+
const zod_1 = __importDefault(require("zod"));
|
|
9
|
+
exports.taskRecordSchema = zod_1.default.object({
|
|
10
|
+
task: zod_1.default.string().describe("The description of the executed task."),
|
|
11
|
+
status: zod_1.default
|
|
12
|
+
.enum(["pending", "completed", "failed"])
|
|
13
|
+
.describe("The execution status of the task: pending, completed, or failed."),
|
|
14
|
+
result: zod_1.default.unknown().optional().describe("The result produced by executing the task."),
|
|
15
|
+
error: zod_1.default
|
|
16
|
+
.object({
|
|
17
|
+
message: zod_1.default.string().describe("Error message if the task failed."),
|
|
18
|
+
})
|
|
19
|
+
.optional()
|
|
20
|
+
.describe("Error information if the task failed."),
|
|
21
|
+
createdAt: zod_1.default.number().optional().describe("Timestamp when the task was created."),
|
|
22
|
+
completedAt: zod_1.default.number().optional().describe("Timestamp when the task completed or failed."),
|
|
23
|
+
});
|
|
24
|
+
exports.executionStateSchema = zod_1.default.object({
|
|
25
|
+
tasks: zod_1.default
|
|
26
|
+
.array(exports.taskRecordSchema)
|
|
27
|
+
.describe("The list of tasks that have been executed along with their results."),
|
|
28
|
+
});
|
|
29
|
+
exports.plannerInputSchema = zod_1.default.object({
|
|
30
|
+
objective: zod_1.default.string().describe("The user's overall objective."),
|
|
31
|
+
skills: zod_1.default
|
|
32
|
+
.array(zod_1.default.object({
|
|
33
|
+
name: zod_1.default.string().describe("The name of the skill."),
|
|
34
|
+
description: zod_1.default.string().optional().describe("A brief description of the skill."),
|
|
35
|
+
}))
|
|
36
|
+
.describe("The list of available skills the agent can use."),
|
|
37
|
+
executionState: exports.executionStateSchema,
|
|
38
|
+
});
|
|
39
|
+
exports.plannerOutputSchema = zod_1.default.object({
|
|
40
|
+
nextTask: zod_1.default
|
|
41
|
+
.string()
|
|
42
|
+
.optional()
|
|
43
|
+
.describe("The next task to be executed by the worker. Should contain a clear, actionable description of what needs to be done."),
|
|
44
|
+
finished: zod_1.default
|
|
45
|
+
.boolean()
|
|
46
|
+
.optional()
|
|
47
|
+
.describe("Indicates if all tasks are completed and the objective has been achieved. Set to true when no more work is needed."),
|
|
48
|
+
});
|
|
49
|
+
exports.workerInputSchema = zod_1.default.object({
|
|
50
|
+
objective: zod_1.default.string().describe("The user's overall objective."),
|
|
51
|
+
task: zod_1.default.string().describe("The specific task assigned to the worker for execution."),
|
|
52
|
+
executionState: exports.executionStateSchema,
|
|
53
|
+
});
|
|
54
|
+
exports.workerOutputSchema = zod_1.default.object({
|
|
55
|
+
result: zod_1.default
|
|
56
|
+
.string()
|
|
57
|
+
.optional()
|
|
58
|
+
.describe("The text result or output produced by executing the task. Include key findings, data retrieved, or actions taken. Can be omitted if the task failed with no partial results."),
|
|
59
|
+
success: zod_1.default
|
|
60
|
+
.boolean()
|
|
61
|
+
.describe("Whether the task completed successfully. Set to true if the task achieved its goal, false if it encountered errors or could not be completed."),
|
|
62
|
+
error: zod_1.default
|
|
63
|
+
.object({
|
|
64
|
+
message: zod_1.default
|
|
65
|
+
.string()
|
|
66
|
+
.describe("A clear description of what went wrong, including error type and relevant context to help with debugging or retry strategies."),
|
|
67
|
+
})
|
|
68
|
+
.optional()
|
|
69
|
+
.describe("Error details if the task failed. Only include when success is false."),
|
|
70
|
+
});
|
|
71
|
+
exports.completerInputSchema = zod_1.default.object({
|
|
72
|
+
objective: zod_1.default.string().describe("The user's overall objective."),
|
|
73
|
+
executionState: exports.executionStateSchema,
|
|
74
|
+
});
|
|
75
|
+
/**
|
|
76
|
+
* Default maximum number of task execution iterations
|
|
77
|
+
*/
|
|
78
|
+
exports.DEFAULT_MAX_ITERATIONS = 20;
|
|
79
|
+
exports.stateManagementOptionsSchema = zod_1.default.object({
|
|
80
|
+
maxTokens: (0, schema_js_1.optionalize)(zod_1.default.number().int().positive()),
|
|
81
|
+
keepRecent: (0, schema_js_1.optionalize)(zod_1.default.number().int().positive()),
|
|
82
|
+
maxIterations: (0, schema_js_1.optionalize)(zod_1.default.number().int().positive()),
|
|
83
|
+
});
|