@blocklet/pages-kit-agents 0.5.56 → 0.6.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.
@@ -1,131 +0,0 @@
1
- import { ensureZodUnionArray } from '@aigne/core/utils/json-schema.js';
2
- import { duplicates } from '@aigne/core/utils/type-utils.js';
3
- import { z } from 'zod';
4
- /**
5
- * @hidden
6
- */
7
- export const SYNTHESIZE_PLAN_USER_PROMPT_TEMPLATE = `\
8
- Synthesize the results of executing all steps in the plan into a cohesive result
9
- `;
10
- /**
11
- * @hidden
12
- */
13
- export function getFullPlanSchema(agents) {
14
- const agentNames = agents.map((i) => i.name);
15
- if (new Set(agentNames).size !== agentNames.length) {
16
- const dup = duplicates(agentNames);
17
- throw new Error(`Duplicate agent names found in orchestrator: ${dup.join(',')}`);
18
- }
19
- const TaskSchema = z.object({
20
- description: z.string().describe('Detailed description of the task'),
21
- agent: z
22
- .union(ensureZodUnionArray(agents.map((i) => z.literal(i.name))))
23
- .describe('Name of the agent to execute the task'),
24
- });
25
- const StepSchema = z.object({
26
- description: z.string().describe('Detailed description of the step'),
27
- tasks: z.array(TaskSchema).describe('Tasks that can run in parallel in this step'),
28
- });
29
- return z.object({
30
- steps: z.array(StepSchema).describe('All sequential steps in the plan'),
31
- isComplete: z.boolean().describe('Whether the previous plan results achieve the objective'),
32
- });
33
- }
34
- /**
35
- * @hidden
36
- */
37
- export const FULL_PLAN_PROMPT_TEMPLATE = `You are tasked with orchestrating a plan to complete an objective.
38
- You can analyze results from the previous steps already executed to decide if the objective is complete.
39
- Your plan must be structured in sequential steps, with each step containing independent parallel subtasks.
40
-
41
- <objective>
42
- {{objective}}
43
- </objective>
44
-
45
- <steps_completed>
46
- {{#steps}}
47
- - Step: {{step.description}}
48
- Result: {{result}}
49
- {{/steps}}
50
- </steps_completed>
51
-
52
- <previous_plan_status>
53
- {{plan.status}}
54
- </previous_plan_status>
55
-
56
- <previous_plan_result>
57
- {{plan.result}}
58
- </previous_plan_result>
59
-
60
- You have access to the following Agents(which are collections of tools/functions):
61
-
62
- <agents>
63
- {{#agents}}
64
- - Agent: {{name}}
65
- Description: {{description}}
66
- Functions:
67
- {{#tools}}
68
- - Tool: {{name}}
69
- Description: {{description}}
70
- {{/tools}}
71
- {{/agents}}
72
- </agents>
73
-
74
- - If the previous plan results achieve the objective, return isComplete=true.
75
- - Otherwise, generate remaining steps needed.
76
- - Generate a plan with all remaining steps needed.
77
- - Steps are sequential, but each Step can have parallel subtasks.
78
- - For each Step, specify a description of the step and independent subtasks that can run in parallel.
79
- - For each subtask specify:
80
- 1. Clear description of the task that an LLM can execute
81
- 2. Name of 1 Agent to use for the task`;
82
- /**
83
- * @hidden
84
- */
85
- export const TASK_PROMPT_TEMPLATE = `\
86
- You are part of a larger workflow to achieve the step then the objective:
87
-
88
- <objective>
89
- {{objective}}
90
- </objective>
91
-
92
- <step>
93
- {{step.description}}
94
- </step>
95
-
96
- Your job is to accomplish only the following task:
97
-
98
- <task>
99
- {{task.description}}
100
- </task>
101
-
102
- Results so far that may provide helpful context:
103
-
104
- <steps_completed>
105
- {{#steps}}
106
- - Step: {{step.description}}
107
- Result: {{result}}
108
- {{/steps}}
109
- </steps_completed>
110
- `;
111
- /**
112
- * @hidden
113
- */
114
- export const SYNTHESIZE_STEP_PROMPT_TEMPLATE = `\
115
- Synthesize the results of these parallel tasks into a cohesive result
116
-
117
- <objective>
118
- {{objective}}
119
- </objective>
120
-
121
- <step>
122
- {{step.description}}
123
- </step>
124
-
125
- <tasks>
126
- {{#tasks}}
127
- - Task: {{task.description}}
128
- Result: {{result}}
129
- {{/tasks}}
130
- </tasks>
131
- `;
@@ -1,115 +0,0 @@
1
- import { Agent, type AgentInvokeOptions, type AgentOptions, type Message } from '@aigne/core';
2
- import { type FullPlanOutput, type StepWithResult } from './orchestrator-prompts.js';
3
- /**
4
- * Re-export orchestrator prompt templates and related types
5
- */
6
- export * from './orchestrator-prompts.js';
7
- /**
8
- * Represents a complete plan with execution results
9
- * @hidden
10
- */
11
- export interface FullPlanWithResult {
12
- /**
13
- * The overall objective
14
- */
15
- objective: string;
16
- /**
17
- * The generated complete plan
18
- */
19
- plan?: FullPlanOutput;
20
- /**
21
- * List of executed steps with their results
22
- */
23
- steps: StepWithResult[];
24
- /**
25
- * Final result
26
- */
27
- result?: string;
28
- /**
29
- * Plan completion status
30
- */
31
- status?: boolean;
32
- }
33
- /**
34
- * Configuration options for the Orchestrator Agent
35
- */
36
- export interface OrchestratorAgentOptions<I extends Message = Message, O extends Message = Message> extends AgentOptions<I, O> {
37
- /**
38
- * Maximum number of iterations to prevent infinite loops
39
- * Default: 30
40
- */
41
- maxIterations?: number;
42
- /**
43
- * Number of concurrent tasks
44
- * Default: 5
45
- */
46
- tasksConcurrency?: number;
47
- /**
48
- * Chain step results as input to the next step
49
- * Default: false
50
- */
51
- chainStepResults?: boolean;
52
- }
53
- /**
54
- * Orchestrator Agent Class
55
- *
56
- * This Agent is responsible for:
57
- * 1. Generating an execution plan based on the objective
58
- * 2. Breaking down the plan into steps and tasks
59
- * 3. Coordinating the execution of steps and tasks
60
- * 4. Synthesizing the final result
61
- *
62
- * Workflow:
63
- * - Receives input objective
64
- * - Uses planner to create execution plan
65
- * - Executes tasks and steps according to the plan
66
- * - Synthesizes final result through completer
67
- */
68
- export declare class OrchestratorAgent<I extends Message = Message, O extends Message = Message> extends Agent<I, O> {
69
- /**
70
- * Factory method to create an OrchestratorAgent instance
71
- * @param options - Configuration options for the Orchestrator Agent
72
- * @returns A new OrchestratorAgent instance
73
- */
74
- static from<I extends Message, O extends Message>(options: OrchestratorAgentOptions<I, O>): OrchestratorAgent<I, O>;
75
- /**
76
- * Creates an OrchestratorAgent instance
77
- * @param options - Configuration options for the Orchestrator Agent
78
- */
79
- constructor(options: OrchestratorAgentOptions<I, O>);
80
- private planner;
81
- private completer;
82
- /**
83
- * Maximum number of iterations
84
- * Prevents infinite execution loops
85
- */
86
- maxIterations?: number;
87
- /**
88
- * Number of concurrent tasks
89
- * Controls how many tasks can be executed simultaneously
90
- */
91
- tasksConcurrency?: number;
92
- /**
93
- * Whether to chain step results as input to next step
94
- */
95
- chainStepResults?: boolean;
96
- /**
97
- * Process input and execute the orchestrator workflow
98
- *
99
- * Workflow:
100
- * 1. Extract the objective
101
- * 2. Loop until plan completion or maximum iterations:
102
- * a. Generate/update execution plan
103
- * b. If plan is complete, synthesize result
104
- * c. Otherwise, execute steps in the plan
105
- *
106
- * @param input - Input message containing the objective
107
- * @param options - Agent invocation options
108
- * @returns Processing result
109
- */
110
- process(input: I, options: AgentInvokeOptions): Promise<O>;
111
- private getFullPlanInput;
112
- private getFullPlan;
113
- private synthesizePlanResult;
114
- private executeStep;
115
- }
@@ -1,130 +0,0 @@
1
- import type { Agent, Message } from '@aigne/core';
2
- import { z } from 'zod';
3
- /**
4
- * @hidden
5
- */
6
- export declare const SYNTHESIZE_PLAN_USER_PROMPT_TEMPLATE = "Synthesize the results of executing all steps in the plan into a cohesive result\n";
7
- /**
8
- * @hidden
9
- */
10
- export declare function getFullPlanSchema(agents: Agent[]): z.ZodObject<{
11
- steps: z.ZodArray<z.ZodObject<{
12
- description: z.ZodString;
13
- tasks: z.ZodArray<z.ZodObject<{
14
- description: z.ZodString;
15
- agent: z.ZodUnion<[z.ZodLiteral<string>, z.ZodLiteral<string>, ...z.ZodLiteral<string>[]]>;
16
- }, "strip", z.ZodTypeAny, {
17
- description: string;
18
- agent: string;
19
- }, {
20
- description: string;
21
- agent: string;
22
- }>, "many">;
23
- }, "strip", z.ZodTypeAny, {
24
- description: string;
25
- tasks: {
26
- description: string;
27
- agent: string;
28
- }[];
29
- }, {
30
- description: string;
31
- tasks: {
32
- description: string;
33
- agent: string;
34
- }[];
35
- }>, "many">;
36
- isComplete: z.ZodBoolean;
37
- }, "strip", z.ZodTypeAny, {
38
- steps: {
39
- description: string;
40
- tasks: {
41
- description: string;
42
- agent: string;
43
- }[];
44
- }[];
45
- isComplete: boolean;
46
- }, {
47
- steps: {
48
- description: string;
49
- tasks: {
50
- description: string;
51
- agent: string;
52
- }[];
53
- }[];
54
- isComplete: boolean;
55
- }>;
56
- /**
57
- * @hidden
58
- */
59
- export type FullPlanOutput = z.infer<ReturnType<typeof getFullPlanSchema>>;
60
- /**
61
- * @hidden
62
- */
63
- export type Step = FullPlanOutput['steps'][number];
64
- /**
65
- * @hidden
66
- */
67
- export type Task = Step['tasks'][number];
68
- /**
69
- * @hidden
70
- */
71
- export interface StepWithResult {
72
- step: Step;
73
- tasks: Array<TaskWithResult>;
74
- result: string;
75
- }
76
- /**
77
- * @hidden
78
- */
79
- export interface TaskWithResult {
80
- task: Task;
81
- result: string;
82
- }
83
- /**
84
- * @hidden
85
- */
86
- export interface FullPlanInput extends Message {
87
- objective: string;
88
- steps: StepWithResult[];
89
- plan: {
90
- status: string;
91
- result: string;
92
- };
93
- agents: {
94
- name: string;
95
- description?: string;
96
- tools: {
97
- name: string;
98
- description?: string;
99
- }[];
100
- }[];
101
- }
102
- /**
103
- * @hidden
104
- */
105
- 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";
106
- /**
107
- * @hidden
108
- */
109
- export interface TaskPromptInput extends Message {
110
- objective: string;
111
- step: Step;
112
- task: Task;
113
- steps: StepWithResult[];
114
- }
115
- /**
116
- * @hidden
117
- */
118
- 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";
119
- /**
120
- * @hidden
121
- */
122
- export interface SynthesizeStepPromptInput extends Message {
123
- objective: string;
124
- step: Step;
125
- tasks: TaskWithResult[];
126
- }
127
- /**
128
- * @hidden
129
- */
130
- 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";