@aigne/agent-library 1.24.0-beta.4 → 1.24.0-beta.6
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 +22 -0
- package/lib/cjs/ask-user-question/index.d.ts +27 -0
- package/lib/cjs/ask-user-question/index.js +100 -0
- package/lib/dts/ask-user-question/index.d.ts +27 -0
- package/lib/esm/ask-user-question/index.d.ts +27 -0
- package/lib/esm/ask-user-question/index.js +97 -0
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,28 @@
|
|
|
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.6](https://github.com/AIGNE-io/aigne-framework/compare/agent-library-v1.24.0-beta.5...agent-library-v1.24.0-beta.6) (2025-12-25)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Bug Fixes
|
|
14
|
+
|
|
15
|
+
* **agent-library:** add header field and use object-based answers in AskUserQuestion ([#851](https://github.com/AIGNE-io/aigne-framework/issues/851)) ([095db95](https://github.com/AIGNE-io/aigne-framework/commit/095db95e43b5d39b35c638d90d6f0b99565e0dc4))
|
|
16
|
+
|
|
17
|
+
## [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)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Features
|
|
21
|
+
|
|
22
|
+
* **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))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Dependencies
|
|
26
|
+
|
|
27
|
+
* The following workspace dependencies were updated
|
|
28
|
+
* dependencies
|
|
29
|
+
* @aigne/core bumped to 1.72.0-beta.5
|
|
30
|
+
* @aigne/openai bumped to 0.16.16-beta.5
|
|
31
|
+
|
|
10
32
|
## [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)
|
|
11
33
|
|
|
12
34
|
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
header: string;
|
|
10
|
+
question: string;
|
|
11
|
+
options?: AskUserQuestionAgentOption[];
|
|
12
|
+
multipleSelect?: boolean;
|
|
13
|
+
}[];
|
|
14
|
+
allowCustomAnswer?: boolean;
|
|
15
|
+
}
|
|
16
|
+
export interface AskUserQuestionAgentOutput extends Message {
|
|
17
|
+
answers: Record<string, string>;
|
|
18
|
+
}
|
|
19
|
+
export default class AskUserQuestionAgent extends Agent<AskUserQuestionAgentInput, AskUserQuestionAgentOutput> {
|
|
20
|
+
tag: string;
|
|
21
|
+
static schema(): z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>;
|
|
22
|
+
static load<I extends Message = any, O extends Message = any>(options: {
|
|
23
|
+
filepath: string;
|
|
24
|
+
parsed: object;
|
|
25
|
+
}): Promise<Agent<I, O>>;
|
|
26
|
+
process(input: AskUserQuestionAgentInput, options: AgentInvokeOptions): Promise<AgentProcessResult<AskUserQuestionAgentOutput>>;
|
|
27
|
+
}
|
|
@@ -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
|
+
header: zod_1.z
|
|
14
|
+
.string()
|
|
15
|
+
.describe("Very short label (max 12 chars) used as key in answers. Examples: 'Auth method', 'Library', 'Approach'"),
|
|
16
|
+
question: zod_1.z.string().describe("The question to ask the user"),
|
|
17
|
+
options: (0, schema_js_1.optionalize)(zod_1.z.array(askUserQuestionAgentOptionSchema)).describe("List of options to present to the user"),
|
|
18
|
+
multipleSelect: (0, schema_js_1.optionalize)(zod_1.z.boolean()).describe("Whether to allow multiple selections"),
|
|
19
|
+
}))
|
|
20
|
+
.describe("List of questions to ask the user"),
|
|
21
|
+
allowCustomAnswer: (0, schema_js_1.optionalize)(zod_1.z.boolean()).describe("Whether to allow the user to provide custom answers"),
|
|
22
|
+
});
|
|
23
|
+
class AskUserQuestionAgent extends core_1.Agent {
|
|
24
|
+
tag = "AskUserQuestion";
|
|
25
|
+
static schema() {
|
|
26
|
+
return zod_1.z.object({});
|
|
27
|
+
}
|
|
28
|
+
static async load(options) {
|
|
29
|
+
return new AskUserQuestionAgent({
|
|
30
|
+
name: defaultName,
|
|
31
|
+
description: defaultDescription,
|
|
32
|
+
...options.parsed,
|
|
33
|
+
inputSchema: askUserQuestionAgentInputSchema,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
async process(input, options) {
|
|
37
|
+
const { prompts } = options;
|
|
38
|
+
if (!prompts)
|
|
39
|
+
throw new Error("Prompts is not available in AskUserQuestionAgent");
|
|
40
|
+
const { questions, allowCustomAnswer } = input;
|
|
41
|
+
const answers = {};
|
|
42
|
+
for (const q of questions) {
|
|
43
|
+
let answer;
|
|
44
|
+
if (q.options?.length) {
|
|
45
|
+
const choices = q.options.map((opt) => ({
|
|
46
|
+
value: opt.label,
|
|
47
|
+
name: opt.label,
|
|
48
|
+
description: opt.description ?? opt.label,
|
|
49
|
+
}));
|
|
50
|
+
if (allowCustomAnswer) {
|
|
51
|
+
choices.push({
|
|
52
|
+
name: "None of the above / Enter my own response",
|
|
53
|
+
value: "OTHER_OPTION",
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
if (!q.multipleSelect) {
|
|
57
|
+
answer = await prompts.select({
|
|
58
|
+
message: q.question,
|
|
59
|
+
choices,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
answer = await prompts.checkbox({
|
|
64
|
+
message: q.question,
|
|
65
|
+
choices,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
if (answer === "OTHER_OPTION" ||
|
|
69
|
+
(Array.isArray(answer) && answer.includes("OTHER_OPTION"))) {
|
|
70
|
+
answer = await prompts.input({
|
|
71
|
+
message: `Please provide your response for: ${q.question}`,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
answer = await prompts.input({
|
|
77
|
+
message: q.question,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
answers[q.header] = Array.isArray(answer) ? answer.join(", ") : answer;
|
|
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
|
+
`;
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
header: string;
|
|
10
|
+
question: string;
|
|
11
|
+
options?: AskUserQuestionAgentOption[];
|
|
12
|
+
multipleSelect?: boolean;
|
|
13
|
+
}[];
|
|
14
|
+
allowCustomAnswer?: boolean;
|
|
15
|
+
}
|
|
16
|
+
export interface AskUserQuestionAgentOutput extends Message {
|
|
17
|
+
answers: Record<string, string>;
|
|
18
|
+
}
|
|
19
|
+
export default class AskUserQuestionAgent extends Agent<AskUserQuestionAgentInput, AskUserQuestionAgentOutput> {
|
|
20
|
+
tag: string;
|
|
21
|
+
static schema(): z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>;
|
|
22
|
+
static load<I extends Message = any, O extends Message = any>(options: {
|
|
23
|
+
filepath: string;
|
|
24
|
+
parsed: object;
|
|
25
|
+
}): Promise<Agent<I, O>>;
|
|
26
|
+
process(input: AskUserQuestionAgentInput, options: AgentInvokeOptions): Promise<AgentProcessResult<AskUserQuestionAgentOutput>>;
|
|
27
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
header: string;
|
|
10
|
+
question: string;
|
|
11
|
+
options?: AskUserQuestionAgentOption[];
|
|
12
|
+
multipleSelect?: boolean;
|
|
13
|
+
}[];
|
|
14
|
+
allowCustomAnswer?: boolean;
|
|
15
|
+
}
|
|
16
|
+
export interface AskUserQuestionAgentOutput extends Message {
|
|
17
|
+
answers: Record<string, string>;
|
|
18
|
+
}
|
|
19
|
+
export default class AskUserQuestionAgent extends Agent<AskUserQuestionAgentInput, AskUserQuestionAgentOutput> {
|
|
20
|
+
tag: string;
|
|
21
|
+
static schema(): z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>;
|
|
22
|
+
static load<I extends Message = any, O extends Message = any>(options: {
|
|
23
|
+
filepath: string;
|
|
24
|
+
parsed: object;
|
|
25
|
+
}): Promise<Agent<I, O>>;
|
|
26
|
+
process(input: AskUserQuestionAgentInput, options: AgentInvokeOptions): Promise<AgentProcessResult<AskUserQuestionAgentOutput>>;
|
|
27
|
+
}
|
|
@@ -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
|
+
header: z
|
|
12
|
+
.string()
|
|
13
|
+
.describe("Very short label (max 12 chars) used as key in answers. Examples: 'Auth method', 'Library', 'Approach'"),
|
|
14
|
+
question: z.string().describe("The question to ask the user"),
|
|
15
|
+
options: optionalize(z.array(askUserQuestionAgentOptionSchema)).describe("List of options to present to the user"),
|
|
16
|
+
multipleSelect: optionalize(z.boolean()).describe("Whether to allow multiple selections"),
|
|
17
|
+
}))
|
|
18
|
+
.describe("List of questions to ask the user"),
|
|
19
|
+
allowCustomAnswer: optionalize(z.boolean()).describe("Whether to allow the user to provide custom answers"),
|
|
20
|
+
});
|
|
21
|
+
export default class AskUserQuestionAgent extends Agent {
|
|
22
|
+
tag = "AskUserQuestion";
|
|
23
|
+
static schema() {
|
|
24
|
+
return z.object({});
|
|
25
|
+
}
|
|
26
|
+
static async load(options) {
|
|
27
|
+
return new AskUserQuestionAgent({
|
|
28
|
+
name: defaultName,
|
|
29
|
+
description: defaultDescription,
|
|
30
|
+
...options.parsed,
|
|
31
|
+
inputSchema: askUserQuestionAgentInputSchema,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
async process(input, options) {
|
|
35
|
+
const { prompts } = options;
|
|
36
|
+
if (!prompts)
|
|
37
|
+
throw new Error("Prompts is not available in AskUserQuestionAgent");
|
|
38
|
+
const { questions, allowCustomAnswer } = input;
|
|
39
|
+
const answers = {};
|
|
40
|
+
for (const q of questions) {
|
|
41
|
+
let answer;
|
|
42
|
+
if (q.options?.length) {
|
|
43
|
+
const choices = q.options.map((opt) => ({
|
|
44
|
+
value: opt.label,
|
|
45
|
+
name: opt.label,
|
|
46
|
+
description: opt.description ?? opt.label,
|
|
47
|
+
}));
|
|
48
|
+
if (allowCustomAnswer) {
|
|
49
|
+
choices.push({
|
|
50
|
+
name: "None of the above / Enter my own response",
|
|
51
|
+
value: "OTHER_OPTION",
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
if (!q.multipleSelect) {
|
|
55
|
+
answer = await prompts.select({
|
|
56
|
+
message: q.question,
|
|
57
|
+
choices,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
answer = await prompts.checkbox({
|
|
62
|
+
message: q.question,
|
|
63
|
+
choices,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
if (answer === "OTHER_OPTION" ||
|
|
67
|
+
(Array.isArray(answer) && answer.includes("OTHER_OPTION"))) {
|
|
68
|
+
answer = await prompts.input({
|
|
69
|
+
message: `Please provide your response for: ${q.question}`,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
answer = await prompts.input({
|
|
75
|
+
message: q.question,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
answers[q.header] = Array.isArray(answer) ? answer.join(", ") : answer;
|
|
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
|
+
`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aigne/agent-library",
|
|
3
|
-
"version": "1.24.0-beta.
|
|
3
|
+
"version": "1.24.0-beta.6",
|
|
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/
|
|
61
|
-
"@aigne/
|
|
62
|
-
"@aigne/
|
|
60
|
+
"@aigne/openai": "^0.16.16-beta.5",
|
|
61
|
+
"@aigne/core": "^1.72.0-beta.5",
|
|
62
|
+
"@aigne/sqlite": "^0.4.9-beta"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
65
|
"@types/bun": "^1.2.22",
|