@aigne/core 1.72.0-beta.3 → 1.72.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 +27 -0
- package/lib/cjs/agents/agent.d.ts +31 -1
- package/lib/cjs/agents/agent.js +13 -0
- package/lib/cjs/agents/ai-agent.d.ts +7 -0
- package/lib/cjs/agents/ai-agent.js +85 -3
- package/lib/cjs/agents/image-agent.d.ts +17 -1
- package/lib/cjs/agents/image-agent.js +16 -0
- package/lib/cjs/agents/image-model.d.ts +4 -4
- package/lib/cjs/agents/mcp-agent.d.ts +17 -0
- package/lib/cjs/agents/mcp-agent.js +18 -0
- package/lib/cjs/agents/team-agent.d.ts +55 -0
- package/lib/cjs/agents/team-agent.js +31 -0
- package/lib/cjs/agents/transform-agent.d.ts +12 -0
- package/lib/cjs/agents/transform-agent.js +13 -0
- package/lib/cjs/agents/video-model.d.ts +4 -4
- package/lib/cjs/loader/agent-yaml.d.ts +5 -67
- package/lib/cjs/loader/agent-yaml.js +4 -139
- package/lib/cjs/loader/agents.d.ts +4 -0
- package/lib/cjs/loader/agents.js +17 -0
- package/lib/cjs/loader/index.d.ts +18 -14
- package/lib/cjs/loader/index.js +20 -81
- package/lib/cjs/loader/schema.d.ts +21 -6
- package/lib/cjs/loader/schema.js +60 -1
- package/lib/cjs/prompt/prompt-builder.js +0 -1
- package/lib/cjs/prompt/skills/afs/agent-skill/agent-skill.d.ts +17 -0
- package/lib/cjs/prompt/skills/afs/agent-skill/agent-skill.js +63 -0
- package/lib/cjs/prompt/skills/afs/agent-skill/skill-loader.d.ts +13 -0
- package/lib/cjs/prompt/skills/afs/agent-skill/skill-loader.js +61 -0
- package/lib/cjs/prompt/skills/afs/delete.js +15 -3
- package/lib/cjs/prompt/skills/afs/edit.d.ts +6 -9
- package/lib/cjs/prompt/skills/afs/edit.js +85 -59
- package/lib/cjs/prompt/skills/afs/exec.js +17 -6
- package/lib/cjs/prompt/skills/afs/index.js +4 -1
- package/lib/cjs/prompt/skills/afs/list.js +26 -10
- package/lib/cjs/prompt/skills/afs/read.d.ts +6 -2
- package/lib/cjs/prompt/skills/afs/read.js +62 -15
- package/lib/cjs/prompt/skills/afs/rename.js +18 -4
- package/lib/cjs/prompt/skills/afs/search.js +21 -5
- package/lib/cjs/prompt/skills/afs/write.js +20 -6
- package/lib/cjs/prompt/template.d.ts +23 -23
- package/lib/dts/agents/agent.d.ts +31 -1
- package/lib/dts/agents/ai-agent.d.ts +7 -0
- package/lib/dts/agents/image-agent.d.ts +17 -1
- package/lib/dts/agents/image-model.d.ts +4 -4
- package/lib/dts/agents/mcp-agent.d.ts +17 -0
- package/lib/dts/agents/team-agent.d.ts +55 -0
- package/lib/dts/agents/transform-agent.d.ts +12 -0
- package/lib/dts/agents/video-model.d.ts +4 -4
- package/lib/dts/aigne/context.d.ts +2 -2
- package/lib/dts/loader/agent-yaml.d.ts +5 -67
- package/lib/dts/loader/agents.d.ts +4 -0
- package/lib/dts/loader/index.d.ts +18 -14
- package/lib/dts/loader/schema.d.ts +21 -6
- package/lib/dts/prompt/skills/afs/agent-skill/agent-skill.d.ts +17 -0
- package/lib/dts/prompt/skills/afs/agent-skill/skill-loader.d.ts +13 -0
- package/lib/dts/prompt/skills/afs/edit.d.ts +6 -9
- package/lib/dts/prompt/skills/afs/read.d.ts +6 -2
- package/lib/dts/prompt/template.d.ts +25 -25
- package/lib/esm/agents/agent.d.ts +31 -1
- package/lib/esm/agents/agent.js +13 -0
- package/lib/esm/agents/ai-agent.d.ts +7 -0
- package/lib/esm/agents/ai-agent.js +85 -3
- package/lib/esm/agents/image-agent.d.ts +17 -1
- package/lib/esm/agents/image-agent.js +16 -0
- package/lib/esm/agents/image-model.d.ts +4 -4
- package/lib/esm/agents/mcp-agent.d.ts +17 -0
- package/lib/esm/agents/mcp-agent.js +18 -0
- package/lib/esm/agents/team-agent.d.ts +55 -0
- package/lib/esm/agents/team-agent.js +31 -0
- package/lib/esm/agents/transform-agent.d.ts +12 -0
- package/lib/esm/agents/transform-agent.js +13 -0
- package/lib/esm/agents/video-model.d.ts +4 -4
- package/lib/esm/aigne/context.d.ts +2 -2
- package/lib/esm/loader/agent-yaml.d.ts +5 -67
- package/lib/esm/loader/agent-yaml.js +4 -138
- package/lib/esm/loader/agents.d.ts +4 -0
- package/lib/esm/loader/agents.js +14 -0
- package/lib/esm/loader/index.d.ts +18 -14
- package/lib/esm/loader/index.js +21 -81
- package/lib/esm/loader/schema.d.ts +21 -6
- package/lib/esm/loader/schema.js +57 -0
- package/lib/esm/prompt/prompt-builder.js +1 -2
- package/lib/esm/prompt/skills/afs/agent-skill/agent-skill.d.ts +17 -0
- package/lib/esm/prompt/skills/afs/agent-skill/agent-skill.js +59 -0
- package/lib/esm/prompt/skills/afs/agent-skill/skill-loader.d.ts +13 -0
- package/lib/esm/prompt/skills/afs/agent-skill/skill-loader.js +53 -0
- package/lib/esm/prompt/skills/afs/delete.js +15 -3
- package/lib/esm/prompt/skills/afs/edit.d.ts +6 -9
- package/lib/esm/prompt/skills/afs/edit.js +85 -59
- package/lib/esm/prompt/skills/afs/exec.js +17 -6
- package/lib/esm/prompt/skills/afs/index.js +4 -1
- package/lib/esm/prompt/skills/afs/list.js +26 -10
- package/lib/esm/prompt/skills/afs/read.d.ts +6 -2
- package/lib/esm/prompt/skills/afs/read.js +62 -15
- package/lib/esm/prompt/skills/afs/rename.js +18 -4
- package/lib/esm/prompt/skills/afs/search.js +21 -5
- package/lib/esm/prompt/skills/afs/write.js +20 -6
- package/lib/esm/prompt/template.d.ts +25 -25
- package/package.json +5 -4
|
@@ -188,6 +188,13 @@ export declare const aiAgentOptionsSchema: ZodObject<{
|
|
|
188
188
|
*/
|
|
189
189
|
export declare class AIAgent<I extends Message = any, O extends Message = any> extends Agent<I, O> {
|
|
190
190
|
tag: string;
|
|
191
|
+
static schema<T>({ filepath }: {
|
|
192
|
+
filepath: string;
|
|
193
|
+
}): ZodType<T>;
|
|
194
|
+
static load<I extends Message = any, O extends Message = any>(options: {
|
|
195
|
+
filepath: string;
|
|
196
|
+
parsed: object;
|
|
197
|
+
}): Promise<Agent<I, O>>;
|
|
191
198
|
/**
|
|
192
199
|
* Create an AIAgent with the specified options
|
|
193
200
|
*
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
import { camelizeSchema, getInstructionsSchema, instructionsToPromptBuilder, optionalize, } from "../loader/schema.js";
|
|
2
3
|
import { PromptBuilder } from "../prompt/prompt-builder.js";
|
|
3
4
|
import { STRUCTURED_STREAM_INSTRUCTIONS } from "../prompt/prompts/structured-stream-instructions.js";
|
|
4
5
|
import { AgentMessageTemplate, ToolMessageTemplate } from "../prompt/template.js";
|
|
5
6
|
import * as fastq from "../utils/queue.js";
|
|
7
|
+
import { mergeAgentResponseChunk } from "../utils/stream-utils.js";
|
|
6
8
|
import { ExtractMetadataTransform } from "../utils/structured-stream-extractor.js";
|
|
7
9
|
import { checkArguments, isEmpty } from "../utils/type-utils.js";
|
|
8
10
|
import { Agent, agentOptionsSchema, isAgentResponseDelta, } from "./agent.js";
|
|
@@ -84,6 +86,32 @@ export const aiAgentOptionsSchema = agentOptionsSchema.extend({
|
|
|
84
86
|
*/
|
|
85
87
|
export class AIAgent extends Agent {
|
|
86
88
|
tag = "AIAgent";
|
|
89
|
+
static schema({ filepath }) {
|
|
90
|
+
const instructionsSchema = getInstructionsSchema({ filepath });
|
|
91
|
+
return camelizeSchema(z.object({
|
|
92
|
+
instructions: optionalize(instructionsSchema),
|
|
93
|
+
autoReorderSystemMessages: optionalize(z.boolean()),
|
|
94
|
+
autoMergeSystemMessages: optionalize(z.boolean()),
|
|
95
|
+
inputKey: optionalize(z.string()),
|
|
96
|
+
outputKey: optionalize(z.string()),
|
|
97
|
+
inputFileKey: optionalize(z.string()),
|
|
98
|
+
outputFileKey: optionalize(z.string()),
|
|
99
|
+
toolChoice: optionalize(z.nativeEnum(AIAgentToolChoice)),
|
|
100
|
+
toolCallsConcurrency: optionalize(z.number().int().min(0)),
|
|
101
|
+
keepTextInToolUses: optionalize(z.boolean()),
|
|
102
|
+
catchToolsError: optionalize(z.boolean()),
|
|
103
|
+
structuredStreamMode: optionalize(z.boolean()),
|
|
104
|
+
}));
|
|
105
|
+
}
|
|
106
|
+
static async load(options) {
|
|
107
|
+
const schema = AIAgent.schema(options);
|
|
108
|
+
const valid = await schema.parseAsync(options.parsed);
|
|
109
|
+
return new AIAgent({
|
|
110
|
+
...options.parsed,
|
|
111
|
+
...valid,
|
|
112
|
+
instructions: valid.instructions && instructionsToPromptBuilder(valid.instructions),
|
|
113
|
+
});
|
|
114
|
+
}
|
|
87
115
|
/**
|
|
88
116
|
* Create an AIAgent with the specified options
|
|
89
117
|
*
|
|
@@ -280,6 +308,16 @@ export class AIAgent extends Agent {
|
|
|
280
308
|
}
|
|
281
309
|
const toolCallMessages = [];
|
|
282
310
|
const outputKey = this.outputKey;
|
|
311
|
+
const inputMessage = this.inputKey ? input[this.inputKey] : undefined;
|
|
312
|
+
if (inputMessage) {
|
|
313
|
+
yield {
|
|
314
|
+
progress: {
|
|
315
|
+
event: "message",
|
|
316
|
+
role: "user",
|
|
317
|
+
message: [{ type: "text", content: inputMessage }],
|
|
318
|
+
},
|
|
319
|
+
};
|
|
320
|
+
}
|
|
283
321
|
for (;;) {
|
|
284
322
|
const modelOutput = {};
|
|
285
323
|
let stream = await this.invokeChildAgent(model, { ...modelInput, messages: modelInput.messages.concat(toolCallMessages) }, { ...options, streaming: true });
|
|
@@ -289,12 +327,12 @@ export class AIAgent extends Agent {
|
|
|
289
327
|
}
|
|
290
328
|
let isTextIgnored = false;
|
|
291
329
|
for await (const value of stream) {
|
|
330
|
+
mergeAgentResponseChunk(modelOutput, value);
|
|
292
331
|
if (isAgentResponseDelta(value)) {
|
|
293
332
|
if (!isTextIgnored && value.delta.text?.text) {
|
|
294
333
|
yield { delta: { text: { [outputKey]: value.delta.text.text } } };
|
|
295
334
|
}
|
|
296
335
|
if (value.delta.json) {
|
|
297
|
-
Object.assign(modelOutput, value.delta.json);
|
|
298
336
|
if (this.structuredStreamMode) {
|
|
299
337
|
yield { delta: { json: value.delta.json.json } };
|
|
300
338
|
if (!isTextIgnored && modelOutput.json && this.ignoreTextOfStructuredStreamMode) {
|
|
@@ -304,13 +342,23 @@ export class AIAgent extends Agent {
|
|
|
304
342
|
}
|
|
305
343
|
}
|
|
306
344
|
}
|
|
307
|
-
const { toolCalls, json, text, files } = modelOutput;
|
|
345
|
+
const { toolCalls, json, text, thoughts, files } = modelOutput;
|
|
346
|
+
if (text) {
|
|
347
|
+
yield {
|
|
348
|
+
progress: { event: "message", role: "agent", message: [{ type: "text", content: text }] },
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
if (thoughts) {
|
|
352
|
+
yield {
|
|
353
|
+
progress: { event: "message", role: "agent", message: [{ type: "thinking", thoughts }] },
|
|
354
|
+
};
|
|
355
|
+
}
|
|
308
356
|
if (toolCalls?.length) {
|
|
309
357
|
if (this.keepTextInToolUses !== true) {
|
|
310
358
|
yield { delta: { json: { [outputKey]: "" } } };
|
|
311
359
|
}
|
|
312
360
|
else {
|
|
313
|
-
yield { delta: { text: { [outputKey]: "\n" } } };
|
|
361
|
+
yield { delta: { text: { [outputKey]: "\n\n" } } };
|
|
314
362
|
}
|
|
315
363
|
const executedToolCalls = [];
|
|
316
364
|
let error;
|
|
@@ -340,6 +388,20 @@ export class AIAgent extends Agent {
|
|
|
340
388
|
const tool = toolsMap.get(call.function.name);
|
|
341
389
|
if (!tool)
|
|
342
390
|
throw new Error(`Tool not found: ${call.function.name}`);
|
|
391
|
+
yield {
|
|
392
|
+
progress: {
|
|
393
|
+
event: "message",
|
|
394
|
+
role: "agent",
|
|
395
|
+
message: [
|
|
396
|
+
{
|
|
397
|
+
type: "tool_use",
|
|
398
|
+
name: call.function.name,
|
|
399
|
+
input: call.function.arguments,
|
|
400
|
+
toolUseId: call.id,
|
|
401
|
+
},
|
|
402
|
+
],
|
|
403
|
+
},
|
|
404
|
+
};
|
|
343
405
|
queue.push({ tool, call });
|
|
344
406
|
}
|
|
345
407
|
await queue.drained();
|
|
@@ -347,6 +409,21 @@ export class AIAgent extends Agent {
|
|
|
347
409
|
throw error;
|
|
348
410
|
// Continue LLM function calling loop if any tools were executed
|
|
349
411
|
if (executedToolCalls.length) {
|
|
412
|
+
for (const { call, output } of executedToolCalls) {
|
|
413
|
+
yield {
|
|
414
|
+
progress: {
|
|
415
|
+
event: "message",
|
|
416
|
+
role: "agent",
|
|
417
|
+
message: [
|
|
418
|
+
{
|
|
419
|
+
type: "tool_result",
|
|
420
|
+
toolUseId: call.id,
|
|
421
|
+
content: output,
|
|
422
|
+
},
|
|
423
|
+
],
|
|
424
|
+
},
|
|
425
|
+
};
|
|
426
|
+
}
|
|
350
427
|
const transferOutput = executedToolCalls.find((i) => isTransferAgentOutput(i.output))?.output;
|
|
351
428
|
if (transferOutput)
|
|
352
429
|
return transferOutput;
|
|
@@ -367,6 +444,11 @@ export class AIAgent extends Agent {
|
|
|
367
444
|
if (!isEmpty(result)) {
|
|
368
445
|
yield { delta: { json: result } };
|
|
369
446
|
}
|
|
447
|
+
if (text) {
|
|
448
|
+
yield {
|
|
449
|
+
progress: { event: "message", role: "agent", message: [{ type: "text", content: text }] },
|
|
450
|
+
};
|
|
451
|
+
}
|
|
370
452
|
return;
|
|
371
453
|
}
|
|
372
454
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type ZodObject, type ZodType } from "zod";
|
|
1
|
+
import z, { type ZodObject, type ZodType } from "zod";
|
|
2
2
|
import { PromptBuilder } from "../prompt/prompt-builder.js";
|
|
3
3
|
import { Agent, type AgentInvokeOptions, type AgentOptions, type Message } from "./agent.js";
|
|
4
4
|
import { type ImageModelOutput } from "./image-model.js";
|
|
@@ -13,6 +13,22 @@ export declare const imageAgentOptionsSchema: ZodObject<{
|
|
|
13
13
|
}>;
|
|
14
14
|
export declare class ImageAgent<I extends Message = any, O extends ImageModelOutput = any> extends Agent<I, O> {
|
|
15
15
|
tag: string;
|
|
16
|
+
static schema({ filepath }: {
|
|
17
|
+
filepath: string;
|
|
18
|
+
}): z.ZodObject<{
|
|
19
|
+
instructions: z.ZodType<import("../loader/schema.js").Instructions, z.ZodTypeDef, import("../loader/schema.js").Instructions>;
|
|
20
|
+
inputFileKey: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
|
|
21
|
+
}, "strip", z.ZodTypeAny, {
|
|
22
|
+
instructions: import("../loader/schema.js").Instructions;
|
|
23
|
+
inputFileKey?: string | undefined;
|
|
24
|
+
}, {
|
|
25
|
+
instructions: import("../loader/schema.js").Instructions;
|
|
26
|
+
inputFileKey?: string | undefined;
|
|
27
|
+
}>;
|
|
28
|
+
static load<I extends Message = any, O extends Message = any>(options: {
|
|
29
|
+
filepath: string;
|
|
30
|
+
parsed: object;
|
|
31
|
+
}): Promise<Agent<I, O>>;
|
|
16
32
|
static from<I extends Message = any, O extends ImageModelOutput = any>(options: ImageAgentOptions<I, O>): ImageAgent<I, O>;
|
|
17
33
|
constructor(options: ImageAgentOptions<I, O>);
|
|
18
34
|
instructions: PromptBuilder;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import z from "zod";
|
|
2
|
+
import { camelizeSchema, getInstructionsSchema, instructionsToPromptBuilder, optionalize, } from "../loader/schema.js";
|
|
2
3
|
import { PromptBuilder } from "../prompt/prompt-builder.js";
|
|
3
4
|
import { checkArguments } from "../utils/type-utils.js";
|
|
4
5
|
import { Agent, agentOptionsSchema, } from "./agent.js";
|
|
@@ -10,6 +11,21 @@ export const imageAgentOptionsSchema = agentOptionsSchema.extend({
|
|
|
10
11
|
});
|
|
11
12
|
export class ImageAgent extends Agent {
|
|
12
13
|
tag = "ImageAgent";
|
|
14
|
+
static schema({ filepath }) {
|
|
15
|
+
const instructionsSchema = getInstructionsSchema({ filepath });
|
|
16
|
+
return camelizeSchema(z.object({
|
|
17
|
+
instructions: instructionsSchema,
|
|
18
|
+
inputFileKey: optionalize(z.string()),
|
|
19
|
+
}));
|
|
20
|
+
}
|
|
21
|
+
static async load(options) {
|
|
22
|
+
const valid = await ImageAgent.schema({ filepath: options.filepath }).parseAsync(options.parsed);
|
|
23
|
+
return new ImageAgent({
|
|
24
|
+
...options.parsed,
|
|
25
|
+
...valid,
|
|
26
|
+
instructions: instructionsToPromptBuilder(valid.instructions),
|
|
27
|
+
});
|
|
28
|
+
}
|
|
13
29
|
static from(options) {
|
|
14
30
|
return new ImageAgent(options);
|
|
15
31
|
}
|
|
@@ -91,6 +91,7 @@ export declare const imageModelInputSchema: z.ZodObject<{
|
|
|
91
91
|
}, "strip", z.ZodTypeAny, {
|
|
92
92
|
prompt: string;
|
|
93
93
|
modelOptions?: Record<string, unknown> | undefined;
|
|
94
|
+
outputFileType?: "local" | "url" | "file" | undefined;
|
|
94
95
|
image?: ({
|
|
95
96
|
type: "url";
|
|
96
97
|
url: string;
|
|
@@ -107,11 +108,11 @@ export declare const imageModelInputSchema: z.ZodObject<{
|
|
|
107
108
|
filename?: string | undefined;
|
|
108
109
|
mimeType?: string | undefined;
|
|
109
110
|
})[] | undefined;
|
|
110
|
-
outputFileType?: "local" | "file" | "url" | undefined;
|
|
111
111
|
n?: number | undefined;
|
|
112
112
|
}, {
|
|
113
113
|
prompt: string;
|
|
114
114
|
modelOptions?: Record<string, unknown> | undefined;
|
|
115
|
+
outputFileType?: "local" | "url" | "file" | undefined;
|
|
115
116
|
image?: ({
|
|
116
117
|
type: "url";
|
|
117
118
|
url: string;
|
|
@@ -128,7 +129,6 @@ export declare const imageModelInputSchema: z.ZodObject<{
|
|
|
128
129
|
filename?: string | undefined;
|
|
129
130
|
mimeType?: string | undefined;
|
|
130
131
|
})[] | undefined;
|
|
131
|
-
outputFileType?: "local" | "file" | "url" | undefined;
|
|
132
132
|
n?: number | undefined;
|
|
133
133
|
}>;
|
|
134
134
|
export interface ImageModelOutput extends Message {
|
|
@@ -232,7 +232,6 @@ export declare const imageModelOutputSchema: z.ZodObject<{
|
|
|
232
232
|
filename?: string | undefined;
|
|
233
233
|
mimeType?: string | undefined;
|
|
234
234
|
})[];
|
|
235
|
-
model?: string | undefined;
|
|
236
235
|
usage?: {
|
|
237
236
|
inputTokens: number;
|
|
238
237
|
outputTokens: number;
|
|
@@ -241,6 +240,7 @@ export declare const imageModelOutputSchema: z.ZodObject<{
|
|
|
241
240
|
cacheReadInputTokens?: number | undefined;
|
|
242
241
|
creditPrefix?: "$" | "€" | "¥" | undefined;
|
|
243
242
|
} | undefined;
|
|
243
|
+
model?: string | undefined;
|
|
244
244
|
}, {
|
|
245
245
|
images: ({
|
|
246
246
|
type: "url";
|
|
@@ -258,7 +258,6 @@ export declare const imageModelOutputSchema: z.ZodObject<{
|
|
|
258
258
|
filename?: string | undefined;
|
|
259
259
|
mimeType?: string | undefined;
|
|
260
260
|
})[];
|
|
261
|
-
model?: string | undefined;
|
|
262
261
|
usage?: {
|
|
263
262
|
inputTokens: number;
|
|
264
263
|
outputTokens: number;
|
|
@@ -267,4 +266,5 @@ export declare const imageModelOutputSchema: z.ZodObject<{
|
|
|
267
266
|
cacheReadInputTokens?: number | undefined;
|
|
268
267
|
creditPrefix?: "$" | "€" | "¥" | undefined;
|
|
269
268
|
} | undefined;
|
|
269
|
+
model?: string | undefined;
|
|
270
270
|
}>;
|
|
@@ -58,6 +58,23 @@ export type SSEServerParameters = {
|
|
|
58
58
|
*/
|
|
59
59
|
export declare class MCPAgent extends Agent {
|
|
60
60
|
tag: string;
|
|
61
|
+
static schema(): z.ZodObject<{
|
|
62
|
+
url: ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
|
|
63
|
+
command: ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
|
|
64
|
+
args: ZodType<string[] | undefined, z.ZodTypeDef, string[] | undefined>;
|
|
65
|
+
}, "strip", z.ZodTypeAny, {
|
|
66
|
+
url?: string | undefined;
|
|
67
|
+
args?: string[] | undefined;
|
|
68
|
+
command?: string | undefined;
|
|
69
|
+
}, {
|
|
70
|
+
url?: string | undefined;
|
|
71
|
+
args?: string[] | undefined;
|
|
72
|
+
command?: string | undefined;
|
|
73
|
+
}>;
|
|
74
|
+
static load<I extends Message = any, O extends Message = any>(options: {
|
|
75
|
+
filepath: string;
|
|
76
|
+
parsed: object;
|
|
77
|
+
}): Promise<Agent<I, O>>;
|
|
61
78
|
/**
|
|
62
79
|
* Create an MCPAgent from a connection to an SSE server.
|
|
63
80
|
*
|
|
@@ -5,6 +5,7 @@ import { SSEClientTransport, } from "@modelcontextprotocol/sdk/client/sse.js";
|
|
|
5
5
|
import { StreamableHTTPClientTransport, } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
6
6
|
import { UriTemplate } from "@modelcontextprotocol/sdk/shared/uriTemplate.js";
|
|
7
7
|
import { z } from "zod";
|
|
8
|
+
import { optionalize } from "../loader/schema.js";
|
|
8
9
|
import { logger } from "../utils/logger.js";
|
|
9
10
|
import { promptFromMCPPrompt, resourceFromMCPResource, toolFromMCPTool, } from "../utils/mcp-utils.js";
|
|
10
11
|
import { checkArguments, createAccessorArray } from "../utils/type-utils.js";
|
|
@@ -49,6 +50,23 @@ function getMCPServerString(options) {
|
|
|
49
50
|
*/
|
|
50
51
|
export class MCPAgent extends Agent {
|
|
51
52
|
tag = "MCPAgent";
|
|
53
|
+
static schema() {
|
|
54
|
+
return z.object({
|
|
55
|
+
url: optionalize(z.string()),
|
|
56
|
+
command: optionalize(z.string()),
|
|
57
|
+
args: optionalize(z.array(z.string())),
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
static async load(options) {
|
|
61
|
+
const valid = await MCPAgent.schema().parseAsync(options.parsed);
|
|
62
|
+
if (!valid.url && !valid.command) {
|
|
63
|
+
throw new Error(`Missing url or command in mcp agent: ${options.filepath}`);
|
|
64
|
+
}
|
|
65
|
+
return MCPAgent.from({
|
|
66
|
+
...options.parsed,
|
|
67
|
+
...valid,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
52
70
|
static from(options) {
|
|
53
71
|
checkArguments("MCPAgent.from", mcpAgentOptionsSchema, options);
|
|
54
72
|
if (isSSEServerParameters(options)) {
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { AgentLoadOptions } from "../loader/index.js";
|
|
1
3
|
import { type PromiseOrValue } from "../utils/type-utils.js";
|
|
2
4
|
import { Agent, type AgentInvokeOptions, type AgentOptions, type AgentProcessResult, type Message } from "./agent.js";
|
|
3
5
|
/**
|
|
@@ -200,6 +202,59 @@ export interface TeamAgentOptions<I extends Message, O extends Message> extends
|
|
|
200
202
|
*/
|
|
201
203
|
export declare class TeamAgent<I extends Message, O extends Message> extends Agent<I, O> {
|
|
202
204
|
tag: string;
|
|
205
|
+
static schema({ filepath }: {
|
|
206
|
+
filepath: string;
|
|
207
|
+
}): z.ZodObject<{
|
|
208
|
+
mode: z.ZodType<ProcessMode | undefined, z.ZodTypeDef, ProcessMode | undefined>;
|
|
209
|
+
iterateOn: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
|
|
210
|
+
concurrency: z.ZodType<number | undefined, z.ZodTypeDef, number | undefined>;
|
|
211
|
+
iterateWithPreviousOutput: z.ZodType<boolean | undefined, z.ZodTypeDef, boolean | undefined>;
|
|
212
|
+
includeAllStepsOutput: z.ZodType<boolean | undefined, z.ZodTypeDef, boolean | undefined>;
|
|
213
|
+
reflection: z.ZodType<{
|
|
214
|
+
reviewer: import("../loader/agent-yaml.js").NestAgentSchema;
|
|
215
|
+
isApproved: string;
|
|
216
|
+
maxIterations?: number | undefined;
|
|
217
|
+
returnLastOnMaxIterations?: boolean | undefined;
|
|
218
|
+
customErrorMessage?: string | undefined;
|
|
219
|
+
} | undefined, z.ZodTypeDef, {
|
|
220
|
+
reviewer: import("../loader/agent-yaml.js").NestAgentSchema;
|
|
221
|
+
isApproved: string;
|
|
222
|
+
maxIterations?: number | undefined;
|
|
223
|
+
returnLastOnMaxIterations?: boolean | undefined;
|
|
224
|
+
customErrorMessage?: string | undefined;
|
|
225
|
+
} | undefined>;
|
|
226
|
+
}, "strip", z.ZodTypeAny, {
|
|
227
|
+
mode?: ProcessMode | undefined;
|
|
228
|
+
reflection?: {
|
|
229
|
+
reviewer: import("../loader/agent-yaml.js").NestAgentSchema;
|
|
230
|
+
isApproved: string;
|
|
231
|
+
maxIterations?: number | undefined;
|
|
232
|
+
returnLastOnMaxIterations?: boolean | undefined;
|
|
233
|
+
customErrorMessage?: string | undefined;
|
|
234
|
+
} | undefined;
|
|
235
|
+
iterateOn?: string | undefined;
|
|
236
|
+
concurrency?: number | undefined;
|
|
237
|
+
iterateWithPreviousOutput?: boolean | undefined;
|
|
238
|
+
includeAllStepsOutput?: boolean | undefined;
|
|
239
|
+
}, {
|
|
240
|
+
mode?: ProcessMode | undefined;
|
|
241
|
+
reflection?: {
|
|
242
|
+
reviewer: import("../loader/agent-yaml.js").NestAgentSchema;
|
|
243
|
+
isApproved: string;
|
|
244
|
+
maxIterations?: number | undefined;
|
|
245
|
+
returnLastOnMaxIterations?: boolean | undefined;
|
|
246
|
+
customErrorMessage?: string | undefined;
|
|
247
|
+
} | undefined;
|
|
248
|
+
iterateOn?: string | undefined;
|
|
249
|
+
concurrency?: number | undefined;
|
|
250
|
+
iterateWithPreviousOutput?: boolean | undefined;
|
|
251
|
+
includeAllStepsOutput?: boolean | undefined;
|
|
252
|
+
}>;
|
|
253
|
+
static load<I extends Message = any, O extends Message = any>(options: {
|
|
254
|
+
filepath: string;
|
|
255
|
+
parsed: object;
|
|
256
|
+
options: AgentLoadOptions;
|
|
257
|
+
}): Promise<Agent<I, O>>;
|
|
203
258
|
/**
|
|
204
259
|
* Create a TeamAgent from the provided options.
|
|
205
260
|
*
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import assert from "node:assert";
|
|
2
2
|
import { produce } from "immer";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { getNestAgentSchema } from "../loader/agent-yaml.js";
|
|
5
|
+
import { camelizeSchema, optionalize } from "../loader/schema.js";
|
|
3
6
|
import * as fastq from "../utils/queue.js";
|
|
4
7
|
import { mergeAgentResponseChunk } from "../utils/stream-utils.js";
|
|
5
8
|
import { isEmpty, isNil, isRecord, omit } from "../utils/type-utils.js";
|
|
@@ -47,6 +50,34 @@ export const DEFAULT_REFLECTION_MAX_ITERATIONS = 3;
|
|
|
47
50
|
*/
|
|
48
51
|
export class TeamAgent extends Agent {
|
|
49
52
|
tag = "TeamAgent";
|
|
53
|
+
static schema({ filepath }) {
|
|
54
|
+
const nestAgentSchema = getNestAgentSchema({ filepath });
|
|
55
|
+
return z.object({
|
|
56
|
+
mode: optionalize(z.nativeEnum(ProcessMode)),
|
|
57
|
+
iterateOn: optionalize(z.string()),
|
|
58
|
+
concurrency: optionalize(z.number().int().min(1)),
|
|
59
|
+
iterateWithPreviousOutput: optionalize(z.boolean()),
|
|
60
|
+
includeAllStepsOutput: optionalize(z.boolean()),
|
|
61
|
+
reflection: camelizeSchema(optionalize(z.object({
|
|
62
|
+
reviewer: nestAgentSchema,
|
|
63
|
+
isApproved: z.string(),
|
|
64
|
+
maxIterations: optionalize(z.number().int().min(1)),
|
|
65
|
+
returnLastOnMaxIterations: optionalize(z.boolean()),
|
|
66
|
+
customErrorMessage: optionalize(z.string()),
|
|
67
|
+
}))),
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
static async load(options) {
|
|
71
|
+
const valid = await TeamAgent.schema({ filepath: options.filepath }).parseAsync(options.parsed);
|
|
72
|
+
return TeamAgent.from({
|
|
73
|
+
...options.parsed,
|
|
74
|
+
...valid,
|
|
75
|
+
reflection: valid.reflection && {
|
|
76
|
+
...valid.reflection,
|
|
77
|
+
reviewer: await options.options.loadNestAgent(options.filepath, valid.reflection.reviewer, options.options),
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
}
|
|
50
81
|
/**
|
|
51
82
|
* Create a TeamAgent from the provided options.
|
|
52
83
|
*
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
1
2
|
import { Agent, type AgentOptions, type Message } from "./agent.js";
|
|
2
3
|
/**
|
|
3
4
|
* Configuration options for TransformAgent
|
|
@@ -47,6 +48,17 @@ export interface TransformAgentOptions<I extends Message, O extends Message> ext
|
|
|
47
48
|
*/
|
|
48
49
|
export declare class TransformAgent<I extends Message = Message, O extends Message = Message> extends Agent<I, O> {
|
|
49
50
|
static type: string;
|
|
51
|
+
static schema(): z.ZodObject<{
|
|
52
|
+
jsonata: z.ZodString;
|
|
53
|
+
}, "strip", z.ZodTypeAny, {
|
|
54
|
+
jsonata: string;
|
|
55
|
+
}, {
|
|
56
|
+
jsonata: string;
|
|
57
|
+
}>;
|
|
58
|
+
static load<I extends Message = any, O extends Message = any>(options: {
|
|
59
|
+
filepath: string;
|
|
60
|
+
parsed: object;
|
|
61
|
+
}): Promise<Agent<I, O>>;
|
|
50
62
|
/**
|
|
51
63
|
* Factory method to create a new TransformAgent instance
|
|
52
64
|
*
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import jsonata from "jsonata";
|
|
2
|
+
import { z } from "zod";
|
|
2
3
|
import { Agent } from "./agent.js";
|
|
3
4
|
/**
|
|
4
5
|
* TransformAgent - A specialized agent for data transformation using JSONata expressions
|
|
@@ -17,6 +18,18 @@ import { Agent } from "./agent.js";
|
|
|
17
18
|
*/
|
|
18
19
|
export class TransformAgent extends Agent {
|
|
19
20
|
static type = "TransformAgent";
|
|
21
|
+
static schema() {
|
|
22
|
+
return z.object({
|
|
23
|
+
jsonata: z.string(),
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
static async load(options) {
|
|
27
|
+
const parsed = await TransformAgent.schema().parseAsync(options.parsed);
|
|
28
|
+
return TransformAgent.from({
|
|
29
|
+
...options.parsed,
|
|
30
|
+
...parsed,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
20
33
|
/**
|
|
21
34
|
* Factory method to create a new TransformAgent instance
|
|
22
35
|
*
|
|
@@ -94,6 +94,7 @@ export declare const videoModelInputSchema: z.ZodObject<{
|
|
|
94
94
|
prompt: string;
|
|
95
95
|
model?: string | undefined;
|
|
96
96
|
modelOptions?: Record<string, unknown> | undefined;
|
|
97
|
+
outputFileType?: "local" | "url" | "file" | undefined;
|
|
97
98
|
image?: {
|
|
98
99
|
type: "url";
|
|
99
100
|
url: string;
|
|
@@ -110,13 +111,13 @@ export declare const videoModelInputSchema: z.ZodObject<{
|
|
|
110
111
|
filename?: string | undefined;
|
|
111
112
|
mimeType?: string | undefined;
|
|
112
113
|
} | undefined;
|
|
113
|
-
outputFileType?: "local" | "file" | "url" | undefined;
|
|
114
114
|
size?: string | undefined;
|
|
115
115
|
seconds?: string | undefined;
|
|
116
116
|
}, {
|
|
117
117
|
prompt: string;
|
|
118
118
|
model?: string | undefined;
|
|
119
119
|
modelOptions?: Record<string, unknown> | undefined;
|
|
120
|
+
outputFileType?: "local" | "url" | "file" | undefined;
|
|
120
121
|
image?: {
|
|
121
122
|
type: "url";
|
|
122
123
|
url: string;
|
|
@@ -133,7 +134,6 @@ export declare const videoModelInputSchema: z.ZodObject<{
|
|
|
133
134
|
filename?: string | undefined;
|
|
134
135
|
mimeType?: string | undefined;
|
|
135
136
|
} | undefined;
|
|
136
|
-
outputFileType?: "local" | "file" | "url" | undefined;
|
|
137
137
|
size?: string | undefined;
|
|
138
138
|
seconds?: string | undefined;
|
|
139
139
|
}>;
|
|
@@ -240,7 +240,6 @@ export declare const videoModelOutputSchema: z.ZodObject<{
|
|
|
240
240
|
filename?: string | undefined;
|
|
241
241
|
mimeType?: string | undefined;
|
|
242
242
|
})[];
|
|
243
|
-
model?: string | undefined;
|
|
244
243
|
usage?: {
|
|
245
244
|
inputTokens: number;
|
|
246
245
|
outputTokens: number;
|
|
@@ -249,6 +248,7 @@ export declare const videoModelOutputSchema: z.ZodObject<{
|
|
|
249
248
|
cacheReadInputTokens?: number | undefined;
|
|
250
249
|
creditPrefix?: "$" | "€" | "¥" | undefined;
|
|
251
250
|
} | undefined;
|
|
251
|
+
model?: string | undefined;
|
|
252
252
|
seconds?: number | undefined;
|
|
253
253
|
}, {
|
|
254
254
|
videos: ({
|
|
@@ -267,7 +267,6 @@ export declare const videoModelOutputSchema: z.ZodObject<{
|
|
|
267
267
|
filename?: string | undefined;
|
|
268
268
|
mimeType?: string | undefined;
|
|
269
269
|
})[];
|
|
270
|
-
model?: string | undefined;
|
|
271
270
|
usage?: {
|
|
272
271
|
inputTokens: number;
|
|
273
272
|
outputTokens: number;
|
|
@@ -276,5 +275,6 @@ export declare const videoModelOutputSchema: z.ZodObject<{
|
|
|
276
275
|
cacheReadInputTokens?: number | undefined;
|
|
277
276
|
creditPrefix?: "$" | "€" | "¥" | undefined;
|
|
278
277
|
} | undefined;
|
|
278
|
+
model?: string | undefined;
|
|
279
279
|
seconds?: number | undefined;
|
|
280
280
|
}>;
|
|
@@ -159,7 +159,7 @@ export declare class AIGNEContext implements Context {
|
|
|
159
159
|
readonly internal: AIGNEContextShared;
|
|
160
160
|
get messageQueue(): MessageQueue;
|
|
161
161
|
get model(): ChatModel | undefined;
|
|
162
|
-
get imageModel(): ImageModel<import("../
|
|
162
|
+
get imageModel(): ImageModel<import("../index.js").ImageModelInput, import("../index.js").ImageModelOutput> | undefined;
|
|
163
163
|
get skills(): Agent<any, any>[] | undefined;
|
|
164
164
|
get agents(): Agent<any, any>[];
|
|
165
165
|
get observer(): AIGNEObserver | undefined;
|
|
@@ -197,7 +197,7 @@ declare class AIGNEContextShared {
|
|
|
197
197
|
readonly messageQueue: MessageQueue;
|
|
198
198
|
readonly events: Emitter<any>;
|
|
199
199
|
get model(): ChatModel | undefined;
|
|
200
|
-
get imageModel(): ImageModel<import("../
|
|
200
|
+
get imageModel(): ImageModel<import("../index.js").ImageModelInput, import("../index.js").ImageModelOutput> | undefined;
|
|
201
201
|
get skills(): Agent<any, any>[] | undefined;
|
|
202
202
|
get agents(): Agent<any, any>[];
|
|
203
203
|
get observer(): AIGNEObserver | undefined;
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import type { AFSOptions } from "@aigne/afs";
|
|
2
2
|
import { type ZodType, z } from "zod";
|
|
3
|
-
import type {
|
|
4
|
-
import { AIAgentToolChoice } from "../agents/ai-agent.js";
|
|
5
|
-
import { type Role } from "../agents/chat-model.js";
|
|
6
|
-
import { ProcessMode, type ReflectionMode } from "../agents/team-agent.js";
|
|
3
|
+
import type { AgentHooks, TaskRenderMode } from "../agents/agent.js";
|
|
7
4
|
import type { LoadOptions } from "./index.js";
|
|
8
5
|
import { chatModelSchema, imageModelSchema } from "./schema.js";
|
|
9
6
|
export interface HooksSchema {
|
|
@@ -45,7 +42,8 @@ export interface AFSContextSchema {
|
|
|
45
42
|
presets?: Record<string, AFSContextPresetSchema>;
|
|
46
43
|
};
|
|
47
44
|
}
|
|
48
|
-
export interface
|
|
45
|
+
export interface AgentSchema {
|
|
46
|
+
type: string;
|
|
49
47
|
name?: string;
|
|
50
48
|
description?: string;
|
|
51
49
|
model?: z.infer<typeof chatModelSchema>;
|
|
@@ -67,71 +65,11 @@ export interface BaseAgentSchema {
|
|
|
67
65
|
context?: AFSContextSchema;
|
|
68
66
|
});
|
|
69
67
|
shareAFS?: boolean;
|
|
68
|
+
[key: string]: unknown;
|
|
70
69
|
}
|
|
71
|
-
export type Instructions = {
|
|
72
|
-
role: Exclude<Role, "tool">;
|
|
73
|
-
content: string;
|
|
74
|
-
path: string;
|
|
75
|
-
cacheControl?: {
|
|
76
|
-
type: "ephemeral";
|
|
77
|
-
ttl?: "5m" | "1h";
|
|
78
|
-
};
|
|
79
|
-
}[];
|
|
80
|
-
export interface AIAgentSchema extends BaseAgentSchema {
|
|
81
|
-
type: "ai";
|
|
82
|
-
instructions?: Instructions;
|
|
83
|
-
autoReorderSystemMessages?: boolean;
|
|
84
|
-
autoMergeSystemMessages?: boolean;
|
|
85
|
-
inputKey?: string;
|
|
86
|
-
inputFileKey?: string;
|
|
87
|
-
outputKey?: string;
|
|
88
|
-
outputFileKey?: string;
|
|
89
|
-
toolChoice?: AIAgentToolChoice;
|
|
90
|
-
toolCallsConcurrency?: number;
|
|
91
|
-
keepTextInToolUses?: boolean;
|
|
92
|
-
}
|
|
93
|
-
export interface ImageAgentSchema extends BaseAgentSchema {
|
|
94
|
-
type: "image";
|
|
95
|
-
instructions: Instructions;
|
|
96
|
-
inputFileKey?: string;
|
|
97
|
-
}
|
|
98
|
-
export interface MCPAgentSchema extends BaseAgentSchema {
|
|
99
|
-
type: "mcp";
|
|
100
|
-
url?: string;
|
|
101
|
-
command?: string;
|
|
102
|
-
args?: string[];
|
|
103
|
-
}
|
|
104
|
-
export interface TeamAgentSchema extends BaseAgentSchema {
|
|
105
|
-
type: "team";
|
|
106
|
-
mode?: ProcessMode;
|
|
107
|
-
iterateOn?: string;
|
|
108
|
-
concurrency?: number;
|
|
109
|
-
iterateWithPreviousOutput?: boolean;
|
|
110
|
-
includeAllStepsOutput?: boolean;
|
|
111
|
-
reflection?: Omit<ReflectionMode, "reviewer"> & {
|
|
112
|
-
reviewer: NestAgentSchema;
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
export interface TransformAgentSchema extends BaseAgentSchema {
|
|
116
|
-
type: "transform";
|
|
117
|
-
jsonata: string;
|
|
118
|
-
}
|
|
119
|
-
export interface FunctionAgentSchema extends BaseAgentSchema {
|
|
120
|
-
type: "function";
|
|
121
|
-
process: FunctionAgentFn;
|
|
122
|
-
}
|
|
123
|
-
export interface ThirdAgentSchema extends BaseAgentSchema {
|
|
124
|
-
agentClass?: AgentClass;
|
|
125
|
-
type: "";
|
|
126
|
-
[key: string]: any;
|
|
127
|
-
}
|
|
128
|
-
export type AgentSchema = AIAgentSchema | ImageAgentSchema | MCPAgentSchema | TeamAgentSchema | TransformAgentSchema | FunctionAgentSchema | ThirdAgentSchema;
|
|
129
70
|
export declare function parseAgentFile(path: string, data: any, options: LoadOptions): Promise<AgentSchema>;
|
|
130
71
|
export declare function loadAgentFromYamlFile(path: string, options: LoadOptions): Promise<AgentSchema>;
|
|
131
|
-
export declare const
|
|
132
|
-
filepath: string;
|
|
133
|
-
}) => ZodType<Instructions>;
|
|
134
|
-
export declare const getAgentSchema: ({ filepath, options, }: {
|
|
72
|
+
export declare const getAgentSchema: ({ filepath }: {
|
|
135
73
|
filepath: string;
|
|
136
74
|
options?: LoadOptions;
|
|
137
75
|
}) => ZodType<AgentSchema, z.ZodTypeDef, AgentSchema>;
|