@aigne/agent-library 1.24.0-beta.3 → 1.24.0-beta.5

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 CHANGED
@@ -7,6 +7,36 @@
7
7
  * @aigne/core bumped to 1.22.0
8
8
  * @aigne/openai bumped to 0.3.4
9
9
 
10
+ ## [1.24.0-beta.5](https://github.com/AIGNE-io/aigne-framework/compare/agent-library-v1.24.0-beta.4...agent-library-v1.24.0-beta.5) (2025-12-25)
11
+
12
+
13
+ ### Features
14
+
15
+ * **agent-library:** add askUserQuestion agent ([#848](https://github.com/AIGNE-io/aigne-framework/issues/848)) ([60fa69b](https://github.com/AIGNE-io/aigne-framework/commit/60fa69b40ec122295e57ad175075875ed4840345))
16
+
17
+
18
+ ### Dependencies
19
+
20
+ * The following workspace dependencies were updated
21
+ * dependencies
22
+ * @aigne/core bumped to 1.72.0-beta.5
23
+ * @aigne/openai bumped to 0.16.16-beta.5
24
+
25
+ ## [1.24.0-beta.4](https://github.com/AIGNE-io/aigne-framework/compare/agent-library-v1.24.0-beta.3...agent-library-v1.24.0-beta.4) (2025-12-24)
26
+
27
+
28
+ ### Features
29
+
30
+ * add Agent Skill support ([#787](https://github.com/AIGNE-io/aigne-framework/issues/787)) ([f04fbe7](https://github.com/AIGNE-io/aigne-framework/commit/f04fbe76ec24cf3c59c74adf92d87b0c3784a8f7))
31
+
32
+
33
+ ### Dependencies
34
+
35
+ * The following workspace dependencies were updated
36
+ * dependencies
37
+ * @aigne/core bumped to 1.72.0-beta.4
38
+ * @aigne/openai bumped to 0.16.16-beta.4
39
+
10
40
  ## [1.24.0-beta.3](https://github.com/AIGNE-io/aigne-framework/compare/agent-library-v1.24.0-beta.2...agent-library-v1.24.0-beta.3) (2025-12-19)
11
41
 
12
42
 
@@ -0,0 +1,29 @@
1
+ import { Agent, type AgentInvokeOptions, type AgentProcessResult, type Message } from "@aigne/core";
2
+ import { z } from "zod";
3
+ export interface AskUserQuestionAgentOption {
4
+ label: string;
5
+ description?: string;
6
+ }
7
+ export interface AskUserQuestionAgentInput extends Message {
8
+ questions: {
9
+ question: string;
10
+ options?: AskUserQuestionAgentOption[];
11
+ multipleSelect?: boolean;
12
+ }[];
13
+ allowCustomAnswer?: boolean;
14
+ }
15
+ export interface AskUserQuestionAgentOutput extends Message {
16
+ answers: {
17
+ question: string;
18
+ answer: string | string[];
19
+ }[];
20
+ }
21
+ export default class AskUserQuestionAgent extends Agent<AskUserQuestionAgentInput, AskUserQuestionAgentOutput> {
22
+ tag: string;
23
+ static schema(): z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>;
24
+ static load<I extends Message = any, O extends Message = any>(options: {
25
+ filepath: string;
26
+ parsed: object;
27
+ }): Promise<Agent<I, O>>;
28
+ process(input: AskUserQuestionAgentInput, options: AgentInvokeOptions): Promise<AgentProcessResult<AskUserQuestionAgentOutput>>;
29
+ }
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const core_1 = require("@aigne/core");
4
+ const schema_js_1 = require("@aigne/core/loader/schema.js");
5
+ const zod_1 = require("zod");
6
+ const askUserQuestionAgentOptionSchema = zod_1.z.object({
7
+ label: zod_1.z.string().describe("The display text for this option (1-5 words)"),
8
+ description: (0, schema_js_1.optionalize)(zod_1.z.string()).describe("Explanation of what this option means"),
9
+ });
10
+ const askUserQuestionAgentInputSchema = zod_1.z.object({
11
+ questions: zod_1.z
12
+ .array(zod_1.z.object({
13
+ question: zod_1.z.string().describe("The question to ask the user"),
14
+ options: (0, schema_js_1.optionalize)(zod_1.z.array(askUserQuestionAgentOptionSchema)).describe("List of options to present to the user"),
15
+ multipleSelect: (0, schema_js_1.optionalize)(zod_1.z.boolean()).describe("Whether to allow multiple selections"),
16
+ }))
17
+ .describe("List of questions to ask the user"),
18
+ allowCustomAnswer: (0, schema_js_1.optionalize)(zod_1.z.boolean()).describe("Whether to allow the user to provide custom answers"),
19
+ });
20
+ class AskUserQuestionAgent extends core_1.Agent {
21
+ tag = "AskUserQuestion";
22
+ static schema() {
23
+ return zod_1.z.object({});
24
+ }
25
+ static async load(options) {
26
+ return new AskUserQuestionAgent({
27
+ name: defaultName,
28
+ description: defaultDescription,
29
+ ...options.parsed,
30
+ inputSchema: askUserQuestionAgentInputSchema,
31
+ });
32
+ }
33
+ async process(input, options) {
34
+ const { prompts } = options;
35
+ if (!prompts)
36
+ throw new Error("Prompts is not available in AskUserQuestionAgent");
37
+ const { questions, allowCustomAnswer } = input;
38
+ const answers = [];
39
+ for (const q of questions) {
40
+ let answer;
41
+ if (q.options?.length) {
42
+ const choices = q.options.map((opt) => ({
43
+ value: opt.label,
44
+ name: opt.label,
45
+ description: opt.description ?? opt.label,
46
+ }));
47
+ if (allowCustomAnswer) {
48
+ choices.push({
49
+ name: "None of the above / Enter my own response",
50
+ value: "OTHER_OPTION",
51
+ });
52
+ }
53
+ if (!q.multipleSelect) {
54
+ answer = await prompts.select({
55
+ message: q.question,
56
+ choices,
57
+ });
58
+ }
59
+ else {
60
+ answer = await prompts.checkbox({
61
+ message: q.question,
62
+ choices,
63
+ });
64
+ }
65
+ if (answer === "OTHER_OPTION" ||
66
+ (Array.isArray(answer) && answer.includes("OTHER_OPTION"))) {
67
+ answer = await prompts.input({
68
+ message: `Please provide your response for: ${q.question}`,
69
+ });
70
+ }
71
+ }
72
+ else {
73
+ answer = await prompts.input({
74
+ message: q.question,
75
+ });
76
+ }
77
+ answers.push({
78
+ question: q.question,
79
+ answer,
80
+ });
81
+ }
82
+ return {
83
+ answers,
84
+ };
85
+ }
86
+ }
87
+ exports.default = AskUserQuestionAgent;
88
+ const defaultName = "askUserQuestion";
89
+ const defaultDescription = `\
90
+ Use this tool when you need to ask the user questions during execution. This allows you to:
91
+ 1. Gather user preferences or requirements
92
+ 2. Clarify ambiguous instructions
93
+ 3. Get decisions on implementation choices as you work
94
+ 4. Offer choices to the user about what direction to take.
95
+
96
+ Usage notes:
97
+ - Users will always be able to select "Other" to provide custom text input
98
+ - Use multiSelect: true to allow multiple answers to be selected for a question
99
+ - If you recommend a specific option, make that the first option in the list and add "(Recommended)" at the end of the label
100
+ `;
@@ -3,6 +3,7 @@ import { Agent, type AgentInvokeOptions, type AgentOptions, type AgentResponseSt
3
3
  import { type NestAgentSchema } from "@aigne/core/loader/agent-yaml.js";
4
4
  import { type LoadOptions } from "@aigne/core/loader/index.js";
5
5
  import { type SandboxRuntimeConfig } from "@anthropic-ai/sandbox-runtime";
6
+ import z from "zod";
6
7
  export interface BashAgentOptions extends AgentOptions<BashAgentInput, BashAgentOutput> {
7
8
  sandbox?: Partial<{
8
9
  [K in keyof SandboxRuntimeConfig]: Partial<SandboxRuntimeConfig[K]>;
@@ -59,6 +60,53 @@ export interface BashAgentOutput extends Message {
59
60
  }
60
61
  export declare class BashAgent extends Agent<BashAgentInput, BashAgentOutput> {
61
62
  options: BashAgentOptions;
63
+ tag: string;
64
+ static schema({ filepath }: {
65
+ filepath: string;
66
+ }): z.ZodObject<{
67
+ sandbox: z.ZodType<boolean | {
68
+ [x: string]: z.ZodTypeAny | undefined;
69
+ } | undefined, z.ZodTypeDef, boolean | {
70
+ [x: string]: z.ZodTypeAny | undefined;
71
+ } | undefined>;
72
+ inputKey: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
73
+ timeout: z.ZodType<number | undefined, z.ZodTypeDef, number | undefined>;
74
+ permissions: z.ZodType<{
75
+ allow?: string[] | undefined;
76
+ deny?: string[] | undefined;
77
+ guard?: NestAgentSchema | undefined;
78
+ defaultMode?: "allow" | "ask" | "deny" | undefined;
79
+ } | undefined, z.ZodTypeDef, {
80
+ allow?: string[] | undefined;
81
+ deny?: string[] | undefined;
82
+ guard?: NestAgentSchema | undefined;
83
+ defaultMode?: "allow" | "ask" | "deny" | undefined;
84
+ } | undefined>;
85
+ }, "strip", z.ZodTypeAny, {
86
+ sandbox?: boolean | {
87
+ [x: string]: z.ZodTypeAny | undefined;
88
+ } | undefined;
89
+ inputKey?: string | undefined;
90
+ timeout?: number | undefined;
91
+ permissions?: {
92
+ allow?: string[] | undefined;
93
+ deny?: string[] | undefined;
94
+ guard?: NestAgentSchema | undefined;
95
+ defaultMode?: "allow" | "ask" | "deny" | undefined;
96
+ } | undefined;
97
+ }, {
98
+ sandbox?: boolean | {
99
+ [x: string]: z.ZodTypeAny | undefined;
100
+ } | undefined;
101
+ inputKey?: string | undefined;
102
+ timeout?: number | undefined;
103
+ permissions?: {
104
+ allow?: string[] | undefined;
105
+ deny?: string[] | undefined;
106
+ guard?: NestAgentSchema | undefined;
107
+ defaultMode?: "allow" | "ask" | "deny" | undefined;
108
+ } | undefined;
109
+ }>;
62
110
  static load(options: {
63
111
  filepath: string;
64
112
  parsed: LoadBashAgentOptions;
@@ -48,15 +48,30 @@ let sandboxInitialization;
48
48
  const mutex = new mutex_js_1.Mutex();
49
49
  class BashAgent extends core_1.Agent {
50
50
  options;
51
+ tag = "Bash";
52
+ static schema({ filepath }) {
53
+ const nestAgentSchema = (0, agent_yaml_js_1.getNestAgentSchema)({ filepath });
54
+ return (0, schema_js_1.camelizeSchema)(zod_1.default.object({
55
+ sandbox: (0, schema_js_1.optionalize)(zod_1.default.union([makeShapePropertiesOptions(sandbox_runtime_1.SandboxRuntimeConfigSchema, 2), zod_1.default.boolean()])),
56
+ inputKey: (0, schema_js_1.optionalize)(zod_1.default.string().describe("The input key for the bash script.")),
57
+ timeout: (0, schema_js_1.optionalize)(zod_1.default.number().describe("Timeout for script execution in milliseconds.")),
58
+ permissions: (0, schema_js_1.optionalize)((0, schema_js_1.camelizeSchema)(zod_1.default.object({
59
+ allow: (0, schema_js_1.optionalize)(zod_1.default.array(zod_1.default.string())),
60
+ deny: (0, schema_js_1.optionalize)(zod_1.default.array(zod_1.default.string())),
61
+ defaultMode: (0, schema_js_1.optionalize)(zod_1.default.enum(["allow", "ask", "deny"])),
62
+ guard: (0, schema_js_1.optionalize)(nestAgentSchema),
63
+ }))),
64
+ }));
65
+ }
51
66
  static async load(options) {
52
- const schema = getBashAgentSchema({ filepath: options.filepath });
53
- const parsed = await schema.parseAsync(options.parsed);
67
+ const valid = await BashAgent.schema(options).parseAsync(options.parsed);
54
68
  return new BashAgent({
55
- ...parsed,
69
+ ...options.parsed,
70
+ ...valid,
56
71
  permissions: {
57
- ...parsed.permissions,
58
- guard: parsed.permissions?.guard
59
- ? await (0, index_js_1.loadNestAgent)(options.filepath, parsed.permissions.guard, options.options ?? {}, {
72
+ ...valid.permissions,
73
+ guard: valid.permissions?.guard
74
+ ? await (0, index_js_1.loadNestAgent)(options.filepath, valid.permissions.guard, options.options ?? {}, {
60
75
  outputSchema: zod_1.default.object({
61
76
  approved: zod_1.default.boolean().describe("Whether the command is approved by the user."),
62
77
  reason: zod_1.default.string().describe("Optional reason for rejection.").optional(),
@@ -334,20 +349,6 @@ When to use:
334
349
  }
335
350
  exports.BashAgent = BashAgent;
336
351
  exports.default = BashAgent;
337
- function getBashAgentSchema({ filepath }) {
338
- const nestAgentSchema = (0, agent_yaml_js_1.getNestAgentSchema)({ filepath });
339
- return (0, schema_js_1.camelizeSchema)(zod_1.default.object({
340
- sandbox: (0, schema_js_1.optionalize)(zod_1.default.union([makeShapePropertiesOptions(sandbox_runtime_1.SandboxRuntimeConfigSchema, 2), zod_1.default.boolean()])),
341
- inputKey: (0, schema_js_1.optionalize)(zod_1.default.string().describe("The input key for the bash script.")),
342
- timeout: (0, schema_js_1.optionalize)(zod_1.default.number().describe("Timeout for script execution in milliseconds.")),
343
- permissions: (0, schema_js_1.optionalize)((0, schema_js_1.camelizeSchema)(zod_1.default.object({
344
- allow: (0, schema_js_1.optionalize)(zod_1.default.array(zod_1.default.string())),
345
- deny: (0, schema_js_1.optionalize)(zod_1.default.array(zod_1.default.string())),
346
- defaultMode: (0, schema_js_1.optionalize)(zod_1.default.enum(["allow", "ask", "deny"])),
347
- guard: (0, schema_js_1.optionalize)(nestAgentSchema),
348
- }))),
349
- }));
350
- }
351
352
  function makeShapePropertiesOptions(schema, depth = 1) {
352
353
  return zod_1.default.object(Object.fromEntries(Object.entries(schema.shape).map(([key, value]) => {
353
354
  const isObject = value instanceof zod_1.ZodObject;
@@ -1,6 +1,8 @@
1
1
  import { type AgentInvokeOptions, type AgentOptions, AIAgent, type AIAgentOptions, type Message, type PromptBuilder } from "@aigne/core";
2
- import { type Instructions, type NestAgentSchema } from "@aigne/core/loader/agent-yaml.js";
3
- import { type LoadOptions } from "@aigne/core/loader/index.js";
2
+ import { type NestAgentSchema } from "@aigne/core/loader/agent-yaml.js";
3
+ import type { AgentLoadOptions } from "@aigne/core/loader/index.js";
4
+ import { type Instructions } from "@aigne/core/loader/schema.js";
5
+ import { type ZodType } from "zod";
4
6
  import { type StateManagementOptions } from "./type.js";
5
7
  /**
6
8
  * Configuration options for the Orchestrator Agent
@@ -17,17 +19,11 @@ export interface OrchestratorAgentOptions<I extends Message = Message, O extends
17
19
  stateManagement?: StateManagementOptions;
18
20
  concurrency?: number;
19
21
  }
20
- export interface LoadOrchestratorAgentOptions<I extends Message = Message, O extends Message = Message> extends Omit<AIAgentOptions<I, O>, "instructions"> {
21
- objective?: string | PromptBuilder | Instructions;
22
- planner?: NestAgentSchema | {
23
- instructions?: string | PromptBuilder | Instructions;
24
- };
25
- worker?: NestAgentSchema | {
26
- instructions?: string | PromptBuilder | Instructions;
27
- };
28
- completer?: NestAgentSchema | {
29
- instructions?: string | PromptBuilder | Instructions;
30
- };
22
+ export interface LoadOrchestratorAgentOptions {
23
+ objective?: string | Instructions;
24
+ planner?: NestAgentSchema;
25
+ worker?: NestAgentSchema;
26
+ completer?: NestAgentSchema;
31
27
  stateManagement?: StateManagementOptions;
32
28
  }
33
29
  /**
@@ -47,10 +43,13 @@ export interface LoadOrchestratorAgentOptions<I extends Message = Message, O ext
47
43
  */
48
44
  export declare class OrchestratorAgent<I extends Message = Message, O extends Message = Message> extends AIAgent<I, O> {
49
45
  tag: string;
46
+ static schema<T>({ filepath }: {
47
+ filepath: string;
48
+ }): ZodType<T>;
50
49
  static load<I extends Message = Message, O extends Message = Message>({ filepath, parsed, options, }: {
51
50
  filepath: string;
52
- parsed: AgentOptions<I, O> & LoadOrchestratorAgentOptions<I, O>;
53
- options?: LoadOptions;
51
+ parsed: LoadOrchestratorAgentOptions & AgentOptions<I, O>;
52
+ options?: AgentLoadOptions;
54
53
  }): Promise<OrchestratorAgent<I, O>>;
55
54
  /**
56
55
  * Factory method to create an OrchestratorAgent instance
@@ -36,7 +36,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.OrchestratorAgent = void 0;
37
37
  const core_1 = require("@aigne/core");
38
38
  const agent_yaml_js_1 = require("@aigne/core/loader/agent-yaml.js");
39
- const index_js_1 = require("@aigne/core/loader/index.js");
40
39
  const schema_js_1 = require("@aigne/core/loader/schema.js");
41
40
  const agent_utils_js_1 = require("@aigne/core/utils/agent-utils.js");
42
41
  const fastq = __importStar(require("@aigne/core/utils/queue.js"));
@@ -90,28 +89,41 @@ const DEFAULT_CONCURRENCY = 5;
90
89
  */
91
90
  class OrchestratorAgent extends core_1.AIAgent {
92
91
  tag = "OrchestratorAgent";
93
- static async load({ filepath, parsed, options = {}, }) {
94
- const schema = getOrchestratorAgentSchema({ filepath });
95
- const valid = await schema.parseAsync(parsed);
92
+ static schema({ filepath }) {
93
+ const nestAgentSchema = (0, agent_yaml_js_1.getNestAgentSchema)({ filepath });
94
+ const instructionsSchema = (0, schema_js_1.getInstructionsSchema)({ filepath });
95
+ return (0, schema_js_1.camelizeSchema)(zod_1.z.object({
96
+ objective: (0, schema_js_1.optionalize)(instructionsSchema),
97
+ planner: (0, schema_js_1.optionalize)(nestAgentSchema),
98
+ worker: (0, schema_js_1.optionalize)(nestAgentSchema),
99
+ completer: (0, schema_js_1.optionalize)(nestAgentSchema),
100
+ stateManagement: (0, schema_js_1.optionalize)((0, schema_js_1.camelizeSchema)(type_js_1.stateManagementOptionsSchema)),
101
+ concurrency: (0, schema_js_1.optionalize)(zod_1.z.number().int().min(1).default(DEFAULT_CONCURRENCY)),
102
+ }));
103
+ }
104
+ static async load({ filepath, parsed, options, }) {
105
+ const valid = await OrchestratorAgent.schema({
106
+ filepath,
107
+ }).parseAsync(parsed);
96
108
  return new OrchestratorAgent({
97
109
  ...parsed,
98
- objective: valid.objective && (0, index_js_1.instructionsToPromptBuilder)(valid.objective),
110
+ objective: valid.objective ? (0, schema_js_1.instructionsToPromptBuilder)(valid.objective) : undefined,
99
111
  planner: valid.planner
100
- ? (await (0, index_js_1.loadNestAgent)(filepath, valid.planner, options, {
112
+ ? (await options?.loadNestAgent(filepath, valid.planner, options, {
101
113
  ...defaultPlannerOptions,
102
114
  afs: parsed.afs,
103
115
  skills: parsed.skills,
104
116
  }))
105
117
  : undefined,
106
118
  worker: valid.worker
107
- ? (await (0, index_js_1.loadNestAgent)(filepath, valid.worker, options, {
119
+ ? (await options?.loadNestAgent(filepath, valid.worker, options, {
108
120
  ...defaultWorkerOptions,
109
121
  afs: parsed.afs,
110
122
  skills: parsed.skills,
111
123
  }))
112
124
  : undefined,
113
125
  completer: valid.completer
114
- ? (await (0, index_js_1.loadNestAgent)(filepath, valid.completer, options, {
126
+ ? (await options?.loadNestAgent(filepath, valid.completer, options, {
115
127
  ...defaultCompleterOptions,
116
128
  outputSchema: parsed.outputSchema,
117
129
  afs: parsed.afs,
@@ -272,15 +284,3 @@ class OrchestratorAgent extends core_1.AIAgent {
272
284
  }
273
285
  exports.OrchestratorAgent = OrchestratorAgent;
274
286
  exports.default = OrchestratorAgent;
275
- function getOrchestratorAgentSchema({ filepath }) {
276
- const nestAgentSchema = (0, agent_yaml_js_1.getNestAgentSchema)({ filepath });
277
- const instructionsSchema = (0, agent_yaml_js_1.getInstructionsSchema)({ filepath });
278
- return (0, schema_js_1.camelizeSchema)(zod_1.z.object({
279
- objective: (0, schema_js_1.optionalize)(instructionsSchema),
280
- planner: (0, schema_js_1.optionalize)(nestAgentSchema),
281
- worker: (0, schema_js_1.optionalize)(nestAgentSchema),
282
- completer: (0, schema_js_1.optionalize)(nestAgentSchema),
283
- stateManagement: (0, schema_js_1.optionalize)((0, schema_js_1.camelizeSchema)(type_js_1.stateManagementOptionsSchema)),
284
- concurrency: (0, schema_js_1.optionalize)(zod_1.z.number().int().min(1).default(DEFAULT_CONCURRENCY)),
285
- }));
286
- }
@@ -0,0 +1,29 @@
1
+ import { Agent, type AgentInvokeOptions, type AgentProcessResult, type Message } from "@aigne/core";
2
+ import { z } from "zod";
3
+ export interface AskUserQuestionAgentOption {
4
+ label: string;
5
+ description?: string;
6
+ }
7
+ export interface AskUserQuestionAgentInput extends Message {
8
+ questions: {
9
+ question: string;
10
+ options?: AskUserQuestionAgentOption[];
11
+ multipleSelect?: boolean;
12
+ }[];
13
+ allowCustomAnswer?: boolean;
14
+ }
15
+ export interface AskUserQuestionAgentOutput extends Message {
16
+ answers: {
17
+ question: string;
18
+ answer: string | string[];
19
+ }[];
20
+ }
21
+ export default class AskUserQuestionAgent extends Agent<AskUserQuestionAgentInput, AskUserQuestionAgentOutput> {
22
+ tag: string;
23
+ static schema(): z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>;
24
+ static load<I extends Message = any, O extends Message = any>(options: {
25
+ filepath: string;
26
+ parsed: object;
27
+ }): Promise<Agent<I, O>>;
28
+ process(input: AskUserQuestionAgentInput, options: AgentInvokeOptions): Promise<AgentProcessResult<AskUserQuestionAgentOutput>>;
29
+ }
@@ -3,6 +3,7 @@ import { Agent, type AgentInvokeOptions, type AgentOptions, type AgentResponseSt
3
3
  import { type NestAgentSchema } from "@aigne/core/loader/agent-yaml.js";
4
4
  import { type LoadOptions } from "@aigne/core/loader/index.js";
5
5
  import { type SandboxRuntimeConfig } from "@anthropic-ai/sandbox-runtime";
6
+ import z from "zod";
6
7
  export interface BashAgentOptions extends AgentOptions<BashAgentInput, BashAgentOutput> {
7
8
  sandbox?: Partial<{
8
9
  [K in keyof SandboxRuntimeConfig]: Partial<SandboxRuntimeConfig[K]>;
@@ -59,6 +60,53 @@ export interface BashAgentOutput extends Message {
59
60
  }
60
61
  export declare class BashAgent extends Agent<BashAgentInput, BashAgentOutput> {
61
62
  options: BashAgentOptions;
63
+ tag: string;
64
+ static schema({ filepath }: {
65
+ filepath: string;
66
+ }): z.ZodObject<{
67
+ sandbox: z.ZodType<boolean | {
68
+ [x: string]: z.ZodTypeAny | undefined;
69
+ } | undefined, z.ZodTypeDef, boolean | {
70
+ [x: string]: z.ZodTypeAny | undefined;
71
+ } | undefined>;
72
+ inputKey: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
73
+ timeout: z.ZodType<number | undefined, z.ZodTypeDef, number | undefined>;
74
+ permissions: z.ZodType<{
75
+ allow?: string[] | undefined;
76
+ deny?: string[] | undefined;
77
+ guard?: NestAgentSchema | undefined;
78
+ defaultMode?: "allow" | "ask" | "deny" | undefined;
79
+ } | undefined, z.ZodTypeDef, {
80
+ allow?: string[] | undefined;
81
+ deny?: string[] | undefined;
82
+ guard?: NestAgentSchema | undefined;
83
+ defaultMode?: "allow" | "ask" | "deny" | undefined;
84
+ } | undefined>;
85
+ }, "strip", z.ZodTypeAny, {
86
+ sandbox?: boolean | {
87
+ [x: string]: z.ZodTypeAny | undefined;
88
+ } | undefined;
89
+ inputKey?: string | undefined;
90
+ timeout?: number | undefined;
91
+ permissions?: {
92
+ allow?: string[] | undefined;
93
+ deny?: string[] | undefined;
94
+ guard?: NestAgentSchema | undefined;
95
+ defaultMode?: "allow" | "ask" | "deny" | undefined;
96
+ } | undefined;
97
+ }, {
98
+ sandbox?: boolean | {
99
+ [x: string]: z.ZodTypeAny | undefined;
100
+ } | undefined;
101
+ inputKey?: string | undefined;
102
+ timeout?: number | undefined;
103
+ permissions?: {
104
+ allow?: string[] | undefined;
105
+ deny?: string[] | undefined;
106
+ guard?: NestAgentSchema | undefined;
107
+ defaultMode?: "allow" | "ask" | "deny" | undefined;
108
+ } | undefined;
109
+ }>;
62
110
  static load(options: {
63
111
  filepath: string;
64
112
  parsed: LoadBashAgentOptions;
@@ -1,6 +1,8 @@
1
1
  import { type AgentInvokeOptions, type AgentOptions, AIAgent, type AIAgentOptions, type Message, type PromptBuilder } from "@aigne/core";
2
- import { type Instructions, type NestAgentSchema } from "@aigne/core/loader/agent-yaml.js";
3
- import { type LoadOptions } from "@aigne/core/loader/index.js";
2
+ import { type NestAgentSchema } from "@aigne/core/loader/agent-yaml.js";
3
+ import type { AgentLoadOptions } from "@aigne/core/loader/index.js";
4
+ import { type Instructions } from "@aigne/core/loader/schema.js";
5
+ import { type ZodType } from "zod";
4
6
  import { type StateManagementOptions } from "./type.js";
5
7
  /**
6
8
  * Configuration options for the Orchestrator Agent
@@ -17,17 +19,11 @@ export interface OrchestratorAgentOptions<I extends Message = Message, O extends
17
19
  stateManagement?: StateManagementOptions;
18
20
  concurrency?: number;
19
21
  }
20
- export interface LoadOrchestratorAgentOptions<I extends Message = Message, O extends Message = Message> extends Omit<AIAgentOptions<I, O>, "instructions"> {
21
- objective?: string | PromptBuilder | Instructions;
22
- planner?: NestAgentSchema | {
23
- instructions?: string | PromptBuilder | Instructions;
24
- };
25
- worker?: NestAgentSchema | {
26
- instructions?: string | PromptBuilder | Instructions;
27
- };
28
- completer?: NestAgentSchema | {
29
- instructions?: string | PromptBuilder | Instructions;
30
- };
22
+ export interface LoadOrchestratorAgentOptions {
23
+ objective?: string | Instructions;
24
+ planner?: NestAgentSchema;
25
+ worker?: NestAgentSchema;
26
+ completer?: NestAgentSchema;
31
27
  stateManagement?: StateManagementOptions;
32
28
  }
33
29
  /**
@@ -47,10 +43,13 @@ export interface LoadOrchestratorAgentOptions<I extends Message = Message, O ext
47
43
  */
48
44
  export declare class OrchestratorAgent<I extends Message = Message, O extends Message = Message> extends AIAgent<I, O> {
49
45
  tag: string;
46
+ static schema<T>({ filepath }: {
47
+ filepath: string;
48
+ }): ZodType<T>;
50
49
  static load<I extends Message = Message, O extends Message = Message>({ filepath, parsed, options, }: {
51
50
  filepath: string;
52
- parsed: AgentOptions<I, O> & LoadOrchestratorAgentOptions<I, O>;
53
- options?: LoadOptions;
51
+ parsed: LoadOrchestratorAgentOptions & AgentOptions<I, O>;
52
+ options?: AgentLoadOptions;
54
53
  }): Promise<OrchestratorAgent<I, O>>;
55
54
  /**
56
55
  * Factory method to create an OrchestratorAgent instance
@@ -0,0 +1,29 @@
1
+ import { Agent, type AgentInvokeOptions, type AgentProcessResult, type Message } from "@aigne/core";
2
+ import { z } from "zod";
3
+ export interface AskUserQuestionAgentOption {
4
+ label: string;
5
+ description?: string;
6
+ }
7
+ export interface AskUserQuestionAgentInput extends Message {
8
+ questions: {
9
+ question: string;
10
+ options?: AskUserQuestionAgentOption[];
11
+ multipleSelect?: boolean;
12
+ }[];
13
+ allowCustomAnswer?: boolean;
14
+ }
15
+ export interface AskUserQuestionAgentOutput extends Message {
16
+ answers: {
17
+ question: string;
18
+ answer: string | string[];
19
+ }[];
20
+ }
21
+ export default class AskUserQuestionAgent extends Agent<AskUserQuestionAgentInput, AskUserQuestionAgentOutput> {
22
+ tag: string;
23
+ static schema(): z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>;
24
+ static load<I extends Message = any, O extends Message = any>(options: {
25
+ filepath: string;
26
+ parsed: object;
27
+ }): Promise<Agent<I, O>>;
28
+ process(input: AskUserQuestionAgentInput, options: AgentInvokeOptions): Promise<AgentProcessResult<AskUserQuestionAgentOutput>>;
29
+ }
@@ -0,0 +1,97 @@
1
+ import { Agent } from "@aigne/core";
2
+ import { optionalize } from "@aigne/core/loader/schema.js";
3
+ import { z } from "zod";
4
+ const askUserQuestionAgentOptionSchema = z.object({
5
+ label: z.string().describe("The display text for this option (1-5 words)"),
6
+ description: optionalize(z.string()).describe("Explanation of what this option means"),
7
+ });
8
+ const askUserQuestionAgentInputSchema = z.object({
9
+ questions: z
10
+ .array(z.object({
11
+ question: z.string().describe("The question to ask the user"),
12
+ options: optionalize(z.array(askUserQuestionAgentOptionSchema)).describe("List of options to present to the user"),
13
+ multipleSelect: optionalize(z.boolean()).describe("Whether to allow multiple selections"),
14
+ }))
15
+ .describe("List of questions to ask the user"),
16
+ allowCustomAnswer: optionalize(z.boolean()).describe("Whether to allow the user to provide custom answers"),
17
+ });
18
+ export default class AskUserQuestionAgent extends Agent {
19
+ tag = "AskUserQuestion";
20
+ static schema() {
21
+ return z.object({});
22
+ }
23
+ static async load(options) {
24
+ return new AskUserQuestionAgent({
25
+ name: defaultName,
26
+ description: defaultDescription,
27
+ ...options.parsed,
28
+ inputSchema: askUserQuestionAgentInputSchema,
29
+ });
30
+ }
31
+ async process(input, options) {
32
+ const { prompts } = options;
33
+ if (!prompts)
34
+ throw new Error("Prompts is not available in AskUserQuestionAgent");
35
+ const { questions, allowCustomAnswer } = input;
36
+ const answers = [];
37
+ for (const q of questions) {
38
+ let answer;
39
+ if (q.options?.length) {
40
+ const choices = q.options.map((opt) => ({
41
+ value: opt.label,
42
+ name: opt.label,
43
+ description: opt.description ?? opt.label,
44
+ }));
45
+ if (allowCustomAnswer) {
46
+ choices.push({
47
+ name: "None of the above / Enter my own response",
48
+ value: "OTHER_OPTION",
49
+ });
50
+ }
51
+ if (!q.multipleSelect) {
52
+ answer = await prompts.select({
53
+ message: q.question,
54
+ choices,
55
+ });
56
+ }
57
+ else {
58
+ answer = await prompts.checkbox({
59
+ message: q.question,
60
+ choices,
61
+ });
62
+ }
63
+ if (answer === "OTHER_OPTION" ||
64
+ (Array.isArray(answer) && answer.includes("OTHER_OPTION"))) {
65
+ answer = await prompts.input({
66
+ message: `Please provide your response for: ${q.question}`,
67
+ });
68
+ }
69
+ }
70
+ else {
71
+ answer = await prompts.input({
72
+ message: q.question,
73
+ });
74
+ }
75
+ answers.push({
76
+ question: q.question,
77
+ answer,
78
+ });
79
+ }
80
+ return {
81
+ answers,
82
+ };
83
+ }
84
+ }
85
+ const defaultName = "askUserQuestion";
86
+ const defaultDescription = `\
87
+ Use this tool when you need to ask the user questions during execution. This allows you to:
88
+ 1. Gather user preferences or requirements
89
+ 2. Clarify ambiguous instructions
90
+ 3. Get decisions on implementation choices as you work
91
+ 4. Offer choices to the user about what direction to take.
92
+
93
+ Usage notes:
94
+ - Users will always be able to select "Other" to provide custom text input
95
+ - Use multiSelect: true to allow multiple answers to be selected for a question
96
+ - If you recommend a specific option, make that the first option in the list and add "(Recommended)" at the end of the label
97
+ `;
@@ -3,6 +3,7 @@ import { Agent, type AgentInvokeOptions, type AgentOptions, type AgentResponseSt
3
3
  import { type NestAgentSchema } from "@aigne/core/loader/agent-yaml.js";
4
4
  import { type LoadOptions } from "@aigne/core/loader/index.js";
5
5
  import { type SandboxRuntimeConfig } from "@anthropic-ai/sandbox-runtime";
6
+ import z from "zod";
6
7
  export interface BashAgentOptions extends AgentOptions<BashAgentInput, BashAgentOutput> {
7
8
  sandbox?: Partial<{
8
9
  [K in keyof SandboxRuntimeConfig]: Partial<SandboxRuntimeConfig[K]>;
@@ -59,6 +60,53 @@ export interface BashAgentOutput extends Message {
59
60
  }
60
61
  export declare class BashAgent extends Agent<BashAgentInput, BashAgentOutput> {
61
62
  options: BashAgentOptions;
63
+ tag: string;
64
+ static schema({ filepath }: {
65
+ filepath: string;
66
+ }): z.ZodObject<{
67
+ sandbox: z.ZodType<boolean | {
68
+ [x: string]: z.ZodTypeAny | undefined;
69
+ } | undefined, z.ZodTypeDef, boolean | {
70
+ [x: string]: z.ZodTypeAny | undefined;
71
+ } | undefined>;
72
+ inputKey: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
73
+ timeout: z.ZodType<number | undefined, z.ZodTypeDef, number | undefined>;
74
+ permissions: z.ZodType<{
75
+ allow?: string[] | undefined;
76
+ deny?: string[] | undefined;
77
+ guard?: NestAgentSchema | undefined;
78
+ defaultMode?: "allow" | "ask" | "deny" | undefined;
79
+ } | undefined, z.ZodTypeDef, {
80
+ allow?: string[] | undefined;
81
+ deny?: string[] | undefined;
82
+ guard?: NestAgentSchema | undefined;
83
+ defaultMode?: "allow" | "ask" | "deny" | undefined;
84
+ } | undefined>;
85
+ }, "strip", z.ZodTypeAny, {
86
+ sandbox?: boolean | {
87
+ [x: string]: z.ZodTypeAny | undefined;
88
+ } | undefined;
89
+ inputKey?: string | undefined;
90
+ timeout?: number | undefined;
91
+ permissions?: {
92
+ allow?: string[] | undefined;
93
+ deny?: string[] | undefined;
94
+ guard?: NestAgentSchema | undefined;
95
+ defaultMode?: "allow" | "ask" | "deny" | undefined;
96
+ } | undefined;
97
+ }, {
98
+ sandbox?: boolean | {
99
+ [x: string]: z.ZodTypeAny | undefined;
100
+ } | undefined;
101
+ inputKey?: string | undefined;
102
+ timeout?: number | undefined;
103
+ permissions?: {
104
+ allow?: string[] | undefined;
105
+ deny?: string[] | undefined;
106
+ guard?: NestAgentSchema | undefined;
107
+ defaultMode?: "allow" | "ask" | "deny" | undefined;
108
+ } | undefined;
109
+ }>;
62
110
  static load(options: {
63
111
  filepath: string;
64
112
  parsed: LoadBashAgentOptions;
@@ -12,15 +12,30 @@ let sandboxInitialization;
12
12
  const mutex = new Mutex();
13
13
  export class BashAgent extends Agent {
14
14
  options;
15
+ tag = "Bash";
16
+ static schema({ filepath }) {
17
+ const nestAgentSchema = getNestAgentSchema({ filepath });
18
+ return camelizeSchema(z.object({
19
+ sandbox: optionalize(z.union([makeShapePropertiesOptions(SandboxRuntimeConfigSchema, 2), z.boolean()])),
20
+ inputKey: optionalize(z.string().describe("The input key for the bash script.")),
21
+ timeout: optionalize(z.number().describe("Timeout for script execution in milliseconds.")),
22
+ permissions: optionalize(camelizeSchema(z.object({
23
+ allow: optionalize(z.array(z.string())),
24
+ deny: optionalize(z.array(z.string())),
25
+ defaultMode: optionalize(z.enum(["allow", "ask", "deny"])),
26
+ guard: optionalize(nestAgentSchema),
27
+ }))),
28
+ }));
29
+ }
15
30
  static async load(options) {
16
- const schema = getBashAgentSchema({ filepath: options.filepath });
17
- const parsed = await schema.parseAsync(options.parsed);
31
+ const valid = await BashAgent.schema(options).parseAsync(options.parsed);
18
32
  return new BashAgent({
19
- ...parsed,
33
+ ...options.parsed,
34
+ ...valid,
20
35
  permissions: {
21
- ...parsed.permissions,
22
- guard: parsed.permissions?.guard
23
- ? await loadNestAgent(options.filepath, parsed.permissions.guard, options.options ?? {}, {
36
+ ...valid.permissions,
37
+ guard: valid.permissions?.guard
38
+ ? await loadNestAgent(options.filepath, valid.permissions.guard, options.options ?? {}, {
24
39
  outputSchema: z.object({
25
40
  approved: z.boolean().describe("Whether the command is approved by the user."),
26
41
  reason: z.string().describe("Optional reason for rejection.").optional(),
@@ -297,20 +312,6 @@ When to use:
297
312
  }
298
313
  }
299
314
  export default BashAgent;
300
- function getBashAgentSchema({ filepath }) {
301
- const nestAgentSchema = getNestAgentSchema({ filepath });
302
- return camelizeSchema(z.object({
303
- sandbox: optionalize(z.union([makeShapePropertiesOptions(SandboxRuntimeConfigSchema, 2), z.boolean()])),
304
- inputKey: optionalize(z.string().describe("The input key for the bash script.")),
305
- timeout: optionalize(z.number().describe("Timeout for script execution in milliseconds.")),
306
- permissions: optionalize(camelizeSchema(z.object({
307
- allow: optionalize(z.array(z.string())),
308
- deny: optionalize(z.array(z.string())),
309
- defaultMode: optionalize(z.enum(["allow", "ask", "deny"])),
310
- guard: optionalize(nestAgentSchema),
311
- }))),
312
- }));
313
- }
314
315
  function makeShapePropertiesOptions(schema, depth = 1) {
315
316
  return z.object(Object.fromEntries(Object.entries(schema.shape).map(([key, value]) => {
316
317
  const isObject = value instanceof ZodObject;
@@ -1,6 +1,8 @@
1
1
  import { type AgentInvokeOptions, type AgentOptions, AIAgent, type AIAgentOptions, type Message, type PromptBuilder } from "@aigne/core";
2
- import { type Instructions, type NestAgentSchema } from "@aigne/core/loader/agent-yaml.js";
3
- import { type LoadOptions } from "@aigne/core/loader/index.js";
2
+ import { type NestAgentSchema } from "@aigne/core/loader/agent-yaml.js";
3
+ import type { AgentLoadOptions } from "@aigne/core/loader/index.js";
4
+ import { type Instructions } from "@aigne/core/loader/schema.js";
5
+ import { type ZodType } from "zod";
4
6
  import { type StateManagementOptions } from "./type.js";
5
7
  /**
6
8
  * Configuration options for the Orchestrator Agent
@@ -17,17 +19,11 @@ export interface OrchestratorAgentOptions<I extends Message = Message, O extends
17
19
  stateManagement?: StateManagementOptions;
18
20
  concurrency?: number;
19
21
  }
20
- export interface LoadOrchestratorAgentOptions<I extends Message = Message, O extends Message = Message> extends Omit<AIAgentOptions<I, O>, "instructions"> {
21
- objective?: string | PromptBuilder | Instructions;
22
- planner?: NestAgentSchema | {
23
- instructions?: string | PromptBuilder | Instructions;
24
- };
25
- worker?: NestAgentSchema | {
26
- instructions?: string | PromptBuilder | Instructions;
27
- };
28
- completer?: NestAgentSchema | {
29
- instructions?: string | PromptBuilder | Instructions;
30
- };
22
+ export interface LoadOrchestratorAgentOptions {
23
+ objective?: string | Instructions;
24
+ planner?: NestAgentSchema;
25
+ worker?: NestAgentSchema;
26
+ completer?: NestAgentSchema;
31
27
  stateManagement?: StateManagementOptions;
32
28
  }
33
29
  /**
@@ -47,10 +43,13 @@ export interface LoadOrchestratorAgentOptions<I extends Message = Message, O ext
47
43
  */
48
44
  export declare class OrchestratorAgent<I extends Message = Message, O extends Message = Message> extends AIAgent<I, O> {
49
45
  tag: string;
46
+ static schema<T>({ filepath }: {
47
+ filepath: string;
48
+ }): ZodType<T>;
50
49
  static load<I extends Message = Message, O extends Message = Message>({ filepath, parsed, options, }: {
51
50
  filepath: string;
52
- parsed: AgentOptions<I, O> & LoadOrchestratorAgentOptions<I, O>;
53
- options?: LoadOptions;
51
+ parsed: LoadOrchestratorAgentOptions & AgentOptions<I, O>;
52
+ options?: AgentLoadOptions;
54
53
  }): Promise<OrchestratorAgent<I, O>>;
55
54
  /**
56
55
  * Factory method to create an OrchestratorAgent instance
@@ -1,7 +1,6 @@
1
1
  import { AIAgent, } from "@aigne/core";
2
- import { getInstructionsSchema, getNestAgentSchema, } from "@aigne/core/loader/agent-yaml.js";
3
- import { instructionsToPromptBuilder, loadNestAgent, } from "@aigne/core/loader/index.js";
4
- import { camelizeSchema, optionalize } from "@aigne/core/loader/schema.js";
2
+ import { getNestAgentSchema } from "@aigne/core/loader/agent-yaml.js";
3
+ import { camelizeSchema, getInstructionsSchema, instructionsToPromptBuilder, optionalize, } from "@aigne/core/loader/schema.js";
5
4
  import { isAgent } from "@aigne/core/utils/agent-utils.js";
6
5
  import * as fastq from "@aigne/core/utils/queue.js";
7
6
  import { estimateTokens } from "@aigne/core/utils/token-estimator.js";
@@ -54,28 +53,41 @@ const DEFAULT_CONCURRENCY = 5;
54
53
  */
55
54
  export class OrchestratorAgent extends AIAgent {
56
55
  tag = "OrchestratorAgent";
57
- static async load({ filepath, parsed, options = {}, }) {
58
- const schema = getOrchestratorAgentSchema({ filepath });
59
- const valid = await schema.parseAsync(parsed);
56
+ static schema({ filepath }) {
57
+ const nestAgentSchema = getNestAgentSchema({ filepath });
58
+ const instructionsSchema = getInstructionsSchema({ filepath });
59
+ return camelizeSchema(z.object({
60
+ objective: optionalize(instructionsSchema),
61
+ planner: optionalize(nestAgentSchema),
62
+ worker: optionalize(nestAgentSchema),
63
+ completer: optionalize(nestAgentSchema),
64
+ stateManagement: optionalize(camelizeSchema(stateManagementOptionsSchema)),
65
+ concurrency: optionalize(z.number().int().min(1).default(DEFAULT_CONCURRENCY)),
66
+ }));
67
+ }
68
+ static async load({ filepath, parsed, options, }) {
69
+ const valid = await OrchestratorAgent.schema({
70
+ filepath,
71
+ }).parseAsync(parsed);
60
72
  return new OrchestratorAgent({
61
73
  ...parsed,
62
- objective: valid.objective && instructionsToPromptBuilder(valid.objective),
74
+ objective: valid.objective ? instructionsToPromptBuilder(valid.objective) : undefined,
63
75
  planner: valid.planner
64
- ? (await loadNestAgent(filepath, valid.planner, options, {
76
+ ? (await options?.loadNestAgent(filepath, valid.planner, options, {
65
77
  ...defaultPlannerOptions,
66
78
  afs: parsed.afs,
67
79
  skills: parsed.skills,
68
80
  }))
69
81
  : undefined,
70
82
  worker: valid.worker
71
- ? (await loadNestAgent(filepath, valid.worker, options, {
83
+ ? (await options?.loadNestAgent(filepath, valid.worker, options, {
72
84
  ...defaultWorkerOptions,
73
85
  afs: parsed.afs,
74
86
  skills: parsed.skills,
75
87
  }))
76
88
  : undefined,
77
89
  completer: valid.completer
78
- ? (await loadNestAgent(filepath, valid.completer, options, {
90
+ ? (await options?.loadNestAgent(filepath, valid.completer, options, {
79
91
  ...defaultCompleterOptions,
80
92
  outputSchema: parsed.outputSchema,
81
93
  afs: parsed.afs,
@@ -235,15 +247,3 @@ export class OrchestratorAgent extends AIAgent {
235
247
  }
236
248
  }
237
249
  export default OrchestratorAgent;
238
- function getOrchestratorAgentSchema({ filepath }) {
239
- const nestAgentSchema = getNestAgentSchema({ filepath });
240
- const instructionsSchema = getInstructionsSchema({ filepath });
241
- return camelizeSchema(z.object({
242
- objective: optionalize(instructionsSchema),
243
- planner: optionalize(nestAgentSchema),
244
- worker: optionalize(nestAgentSchema),
245
- completer: optionalize(nestAgentSchema),
246
- stateManagement: optionalize(camelizeSchema(stateManagementOptionsSchema)),
247
- concurrency: optionalize(z.number().int().min(1).default(DEFAULT_CONCURRENCY)),
248
- }));
249
- }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aigne/agent-library",
3
- "version": "1.24.0-beta.3",
3
+ "version": "1.24.0-beta.5",
4
4
  "description": "Collection of agent libraries for AIGNE framework",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -57,9 +57,9 @@
57
57
  "yaml": "^2.8.1",
58
58
  "zod": "^3.25.67",
59
59
  "zod-to-json-schema": "^3.24.6",
60
- "@aigne/core": "^1.72.0-beta.3",
61
- "@aigne/sqlite": "^0.4.9-beta",
62
- "@aigne/openai": "^0.16.16-beta.3"
60
+ "@aigne/core": "^1.72.0-beta.5",
61
+ "@aigne/openai": "^0.16.16-beta.5",
62
+ "@aigne/sqlite": "^0.4.9-beta"
63
63
  },
64
64
  "devDependencies": {
65
65
  "@types/bun": "^1.2.22",