@aigne/core 1.34.0 → 1.37.0
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 +26 -0
- package/lib/cjs/agents/agent.d.ts +71 -10
- package/lib/cjs/agents/agent.js +73 -28
- package/lib/cjs/agents/ai-agent.js +6 -3
- package/lib/cjs/agents/team-agent.d.ts +93 -1
- package/lib/cjs/agents/team-agent.js +45 -17
- package/lib/cjs/aigne/context.d.ts +1 -0
- package/lib/cjs/aigne/context.js +25 -10
- package/lib/cjs/loader/agent-js.d.ts +2 -17
- package/lib/cjs/loader/agent-js.js +4 -16
- package/lib/cjs/loader/agent-yaml.d.ts +29 -8
- package/lib/cjs/loader/agent-yaml.js +44 -15
- package/lib/cjs/loader/index.d.ts +2 -2
- package/lib/cjs/loader/index.js +55 -16
- package/lib/cjs/loader/schema.d.ts +10 -0
- package/lib/cjs/loader/schema.js +17 -1
- package/lib/cjs/utils/type-utils.d.ts +1 -1
- package/lib/cjs/utils/type-utils.js +2 -4
- package/lib/dts/agents/agent.d.ts +71 -10
- package/lib/dts/agents/team-agent.d.ts +93 -1
- package/lib/dts/aigne/context.d.ts +1 -0
- package/lib/dts/loader/agent-js.d.ts +2 -17
- package/lib/dts/loader/agent-yaml.d.ts +29 -8
- package/lib/dts/loader/index.d.ts +2 -2
- package/lib/dts/loader/schema.d.ts +10 -0
- package/lib/dts/utils/type-utils.d.ts +1 -1
- package/lib/esm/agents/agent.d.ts +71 -10
- package/lib/esm/agents/agent.js +73 -28
- package/lib/esm/agents/ai-agent.js +6 -3
- package/lib/esm/agents/team-agent.d.ts +93 -1
- package/lib/esm/agents/team-agent.js +44 -16
- package/lib/esm/aigne/context.d.ts +1 -0
- package/lib/esm/aigne/context.js +25 -10
- package/lib/esm/loader/agent-js.d.ts +2 -17
- package/lib/esm/loader/agent-js.js +4 -13
- package/lib/esm/loader/agent-yaml.d.ts +29 -8
- package/lib/esm/loader/agent-yaml.js +44 -13
- package/lib/esm/loader/index.d.ts +2 -2
- package/lib/esm/loader/index.js +56 -17
- package/lib/esm/loader/schema.d.ts +10 -0
- package/lib/esm/loader/schema.js +12 -0
- package/lib/esm/utils/type-utils.d.ts +1 -1
- package/lib/esm/utils/type-utils.js +2 -4
- package/package.json +3 -3
|
@@ -102,10 +102,8 @@ function omitBy(obj, predicate) {
|
|
|
102
102
|
return !predicate(value, k);
|
|
103
103
|
}));
|
|
104
104
|
}
|
|
105
|
-
function flat(value) {
|
|
106
|
-
|
|
107
|
-
return [];
|
|
108
|
-
return Array.isArray(value) ? value : [value];
|
|
105
|
+
function flat(...value) {
|
|
106
|
+
return value.flat().filter(isNonNullable);
|
|
109
107
|
}
|
|
110
108
|
function createAccessorArray(array, accessor) {
|
|
111
109
|
return new Proxy(array, {
|
|
@@ -10,6 +10,7 @@ import { type Nullish, type PromiseOrValue, type XOr } from "../utils/type-utils
|
|
|
10
10
|
import type { GuideRailAgent, GuideRailAgentOutput } from "./guide-rail-agent.js";
|
|
11
11
|
import { type TransferAgentOutput } from "./types.js";
|
|
12
12
|
export * from "./types.js";
|
|
13
|
+
export declare const DEFAULT_INPUT_ACTION_GET = "$get";
|
|
13
14
|
/**
|
|
14
15
|
* Basic message type that can contain any key-value pairs
|
|
15
16
|
*/
|
|
@@ -72,6 +73,11 @@ export interface AgentOptions<I extends Message = Message, O extends Message = M
|
|
|
72
73
|
* Used to validate that input messages conform to the expected format
|
|
73
74
|
*/
|
|
74
75
|
inputSchema?: AgentInputOutputSchema<I>;
|
|
76
|
+
/**
|
|
77
|
+
* Default input message for the agent, it can be used to provide partial input
|
|
78
|
+
* or default values for the agent's input schema.
|
|
79
|
+
*/
|
|
80
|
+
defaultInput?: Agent<I, O>["defaultInput"];
|
|
75
81
|
/**
|
|
76
82
|
* Zod schema defining the output message structure
|
|
77
83
|
*
|
|
@@ -106,7 +112,7 @@ export interface AgentOptions<I extends Message = Message, O extends Message = M
|
|
|
106
112
|
* Maximum number of memory items to retrieve
|
|
107
113
|
*/
|
|
108
114
|
maxRetrieveMemoryCount?: number;
|
|
109
|
-
hooks?: AgentHooks<I, O
|
|
115
|
+
hooks?: AgentHooks<I, O> | AgentHooks<I, O>[];
|
|
110
116
|
}
|
|
111
117
|
export declare const agentOptionsSchema: ZodObject<{
|
|
112
118
|
[key in keyof AgentOptions]: ZodType<AgentOptions[key]>;
|
|
@@ -137,6 +143,10 @@ export interface AgentInvokeOptions<U extends UserContext = UserContext> {
|
|
|
137
143
|
* and returns the final JSON result
|
|
138
144
|
*/
|
|
139
145
|
streaming?: boolean;
|
|
146
|
+
/**
|
|
147
|
+
* Optional hooks for agent invocation
|
|
148
|
+
*/
|
|
149
|
+
hooks?: AgentHooks<any, any>;
|
|
140
150
|
}
|
|
141
151
|
/**
|
|
142
152
|
* Agent is the base class for all agents.
|
|
@@ -190,7 +200,7 @@ export declare abstract class Agent<I extends Message = any, O extends Message =
|
|
|
190
200
|
* Here's an example of using hooks:
|
|
191
201
|
* {@includeCode ../../test/agents/agent.test.ts#example-agent-hooks}
|
|
192
202
|
*/
|
|
193
|
-
readonly hooks: AgentHooks<I, O
|
|
203
|
+
readonly hooks: AgentHooks<I, O>[];
|
|
194
204
|
/**
|
|
195
205
|
* List of GuideRail agents applied to this agent
|
|
196
206
|
*
|
|
@@ -232,6 +242,11 @@ export declare abstract class Agent<I extends Message = any, O extends Message =
|
|
|
232
242
|
*/
|
|
233
243
|
readonly description?: string;
|
|
234
244
|
private readonly _inputSchema?;
|
|
245
|
+
defaultInput?: Partial<{
|
|
246
|
+
[key in keyof I]: {
|
|
247
|
+
[DEFAULT_INPUT_ACTION_GET]: string;
|
|
248
|
+
} | I[key];
|
|
249
|
+
}>;
|
|
235
250
|
private readonly _outputSchema?;
|
|
236
251
|
/**
|
|
237
252
|
* Get the input data schema for this agent
|
|
@@ -372,6 +387,8 @@ export declare abstract class Agent<I extends Message = any, O extends Message =
|
|
|
372
387
|
* @returns Agent response (streaming or regular)
|
|
373
388
|
*/
|
|
374
389
|
invoke(input: I & Message, options?: Partial<AgentInvokeOptions>): Promise<AgentResponse<O>>;
|
|
390
|
+
private callHooks;
|
|
391
|
+
private mergeDefaultInput;
|
|
375
392
|
protected invokeSkill<I extends Message, O extends Message>(skill: Agent<I, O>, input: I & Message, options: AgentInvokeOptions): Promise<O>;
|
|
376
393
|
/**
|
|
377
394
|
* Process agent output
|
|
@@ -517,11 +534,15 @@ export interface AgentHooks<I extends Message = Message, O extends Message = Mes
|
|
|
517
534
|
*
|
|
518
535
|
* @param event Object containing the input message
|
|
519
536
|
*/
|
|
520
|
-
onStart?: (event: {
|
|
537
|
+
onStart?: ((event: {
|
|
521
538
|
context: Context;
|
|
522
539
|
input: I;
|
|
523
540
|
}) => PromiseOrValue<void | {
|
|
524
541
|
input?: I;
|
|
542
|
+
}>) | Agent<{
|
|
543
|
+
input: I;
|
|
544
|
+
}, {
|
|
545
|
+
input?: I;
|
|
525
546
|
}>;
|
|
526
547
|
/**
|
|
527
548
|
* Called when agent processing completes or fails
|
|
@@ -532,13 +553,39 @@ export interface AgentHooks<I extends Message = Message, O extends Message = Mes
|
|
|
532
553
|
*
|
|
533
554
|
* @param event Object containing the input message and either output or error
|
|
534
555
|
*/
|
|
535
|
-
onEnd?: (event: XOr<{
|
|
556
|
+
onEnd?: ((event: XOr<{
|
|
536
557
|
context: Context;
|
|
537
558
|
input: I;
|
|
538
559
|
output: O;
|
|
539
560
|
error: Error;
|
|
540
561
|
}, "output", "error">) => PromiseOrValue<void | {
|
|
541
562
|
output?: O;
|
|
563
|
+
}>) | Agent<XOr<{
|
|
564
|
+
input: I;
|
|
565
|
+
output: O;
|
|
566
|
+
error: Error;
|
|
567
|
+
}, "output", "error">, {
|
|
568
|
+
output?: O;
|
|
569
|
+
}>;
|
|
570
|
+
onSuccess?: ((event: {
|
|
571
|
+
context: Context;
|
|
572
|
+
input: I;
|
|
573
|
+
output: O;
|
|
574
|
+
}) => PromiseOrValue<void | {
|
|
575
|
+
output?: O;
|
|
576
|
+
}>) | Agent<{
|
|
577
|
+
input: I;
|
|
578
|
+
output: O;
|
|
579
|
+
}, {
|
|
580
|
+
output?: O;
|
|
581
|
+
}>;
|
|
582
|
+
onError?: ((event: {
|
|
583
|
+
context: Context;
|
|
584
|
+
input: I;
|
|
585
|
+
error: Error;
|
|
586
|
+
}) => void) | Agent<{
|
|
587
|
+
input: I;
|
|
588
|
+
error: Error;
|
|
542
589
|
}>;
|
|
543
590
|
/**
|
|
544
591
|
* Called before a skill (sub-agent) is invoked
|
|
@@ -548,11 +595,14 @@ export interface AgentHooks<I extends Message = Message, O extends Message = Mes
|
|
|
548
595
|
*
|
|
549
596
|
* @param event Object containing the skill being used and input message
|
|
550
597
|
*/
|
|
551
|
-
onSkillStart?: (event: {
|
|
598
|
+
onSkillStart?: ((event: {
|
|
552
599
|
context: Context;
|
|
553
600
|
skill: Agent;
|
|
554
601
|
input: Message;
|
|
555
|
-
}) => PromiseOrValue<void
|
|
602
|
+
}) => PromiseOrValue<void>) | Agent<{
|
|
603
|
+
skill: Agent;
|
|
604
|
+
input: Message;
|
|
605
|
+
}>;
|
|
556
606
|
/**
|
|
557
607
|
* Called after a skill (sub-agent) completes or fails
|
|
558
608
|
*
|
|
@@ -562,13 +612,18 @@ export interface AgentHooks<I extends Message = Message, O extends Message = Mes
|
|
|
562
612
|
*
|
|
563
613
|
* @param event Object containing the skill used, input message, and either output or error
|
|
564
614
|
*/
|
|
565
|
-
onSkillEnd?: (event: XOr<{
|
|
615
|
+
onSkillEnd?: ((event: XOr<{
|
|
566
616
|
context: Context;
|
|
567
617
|
skill: Agent;
|
|
568
618
|
input: Message;
|
|
569
619
|
output: Message;
|
|
570
620
|
error: Error;
|
|
571
|
-
}, "output", "error">) => PromiseOrValue<void
|
|
621
|
+
}, "output", "error">) => PromiseOrValue<void>) | Agent<XOr<{
|
|
622
|
+
skill: Agent;
|
|
623
|
+
input: Message;
|
|
624
|
+
output: Message;
|
|
625
|
+
error: Error;
|
|
626
|
+
}, "output", "error">>;
|
|
572
627
|
/**
|
|
573
628
|
* Called when an agent hands off processing to another agent
|
|
574
629
|
*
|
|
@@ -578,13 +633,19 @@ export interface AgentHooks<I extends Message = Message, O extends Message = Mes
|
|
|
578
633
|
*
|
|
579
634
|
* @param event Object containing the source agent, target agent, and input message
|
|
580
635
|
*/
|
|
581
|
-
onHandoff?: (event: {
|
|
636
|
+
onHandoff?: ((event: {
|
|
582
637
|
context: Context;
|
|
583
638
|
source: Agent;
|
|
584
639
|
target: Agent;
|
|
585
640
|
input: I;
|
|
586
|
-
}) => PromiseOrValue<void
|
|
641
|
+
}) => PromiseOrValue<void>) | Agent<{
|
|
642
|
+
source: Agent;
|
|
643
|
+
target: Agent;
|
|
644
|
+
input: I;
|
|
645
|
+
}>;
|
|
587
646
|
}
|
|
647
|
+
export type AgentHookInput<H extends keyof AgentHooks, Hook extends AgentHooks[H] = AgentHooks[H]> = Hook extends (input: infer I) => any ? Omit<I, "context"> : never;
|
|
648
|
+
export type AgentHookOutput<H extends keyof AgentHooks, Hook extends AgentHooks[H] = AgentHooks[H]> = Hook extends (...args: any[]) => any ? Exclude<Awaited<ReturnType<Hook>>, void> | undefined : never;
|
|
588
649
|
/**
|
|
589
650
|
* Response type for an agent, can be:
|
|
590
651
|
* - Direct response object
|
|
@@ -22,6 +22,73 @@ export declare enum ProcessMode {
|
|
|
22
22
|
*/
|
|
23
23
|
parallel = "parallel"
|
|
24
24
|
}
|
|
25
|
+
export declare const DEFAULT_REFLECTION_MAX_ITERATIONS = 3;
|
|
26
|
+
/**
|
|
27
|
+
* Configuration for reflection mode processing in TeamAgent.
|
|
28
|
+
*
|
|
29
|
+
* Reflection mode enables iterative refinement of agent outputs through a review process.
|
|
30
|
+
* The team agent will repeatedly process the input and have a reviewer agent evaluate
|
|
31
|
+
* the output until it meets approval criteria or reaches the maximum iteration limit.
|
|
32
|
+
*
|
|
33
|
+
* This is particularly useful for:
|
|
34
|
+
* - Quality assurance workflows where outputs need validation
|
|
35
|
+
* - Iterative improvement processes where initial results can be refined
|
|
36
|
+
* - Self-correcting agent systems that learn from feedback
|
|
37
|
+
*/
|
|
38
|
+
export interface ReflectionMode {
|
|
39
|
+
/**
|
|
40
|
+
* The agent responsible for reviewing and providing feedback on the team's output.
|
|
41
|
+
*
|
|
42
|
+
* The reviewer agent receives the combined output from the team's processing
|
|
43
|
+
* and should provide feedback or evaluation that can be used to determine
|
|
44
|
+
* whether the output meets the required standards.
|
|
45
|
+
*/
|
|
46
|
+
reviewer: Agent;
|
|
47
|
+
/**
|
|
48
|
+
* Function that determines whether the reviewer's output indicates approval.
|
|
49
|
+
*
|
|
50
|
+
* This function receives the reviewer agent's output message and should return:
|
|
51
|
+
* - `true` or truthy value: The output is approved and processing should stop
|
|
52
|
+
* - `false` or falsy value: The output needs improvement and another iteration should run
|
|
53
|
+
*
|
|
54
|
+
* The function can be synchronous or asynchronous, allowing for complex approval logic
|
|
55
|
+
* including external validation, scoring systems, or human-in-the-loop approval.
|
|
56
|
+
*
|
|
57
|
+
* @param output - The message output from the reviewer agent
|
|
58
|
+
* @returns A boolean or truthy/falsy value indicating approval status
|
|
59
|
+
*/
|
|
60
|
+
isApproved: (output: Message) => PromiseOrValue<boolean | unknown>;
|
|
61
|
+
/**
|
|
62
|
+
* Maximum number of reflection iterations before giving up.
|
|
63
|
+
*
|
|
64
|
+
* This prevents infinite loops when the approval criteria cannot be met.
|
|
65
|
+
* If the maximum iterations are reached without approval, the process will
|
|
66
|
+
* throw an error indicating the reflection failed to converge.
|
|
67
|
+
*
|
|
68
|
+
* @default 3
|
|
69
|
+
*/
|
|
70
|
+
maxIterations?: number;
|
|
71
|
+
/**
|
|
72
|
+
* Controls the behavior when maximum iterations are reached without approval.
|
|
73
|
+
*
|
|
74
|
+
* When set to `true`, the TeamAgent will return the last generated output
|
|
75
|
+
* instead of throwing an error when the maximum number of reflection iterations
|
|
76
|
+
* is reached without the reviewer's approval.
|
|
77
|
+
*
|
|
78
|
+
* When set to `false` or undefined, the TeamAgent will throw an error
|
|
79
|
+
* indicating that the reflection process failed to converge within the
|
|
80
|
+
* maximum iteration limit.
|
|
81
|
+
*
|
|
82
|
+
* This option is useful for scenarios where:
|
|
83
|
+
* - You want to get the best available result even if it's not perfect
|
|
84
|
+
* - The approval criteria might be too strict for the given context
|
|
85
|
+
* - You prefer graceful degradation over complete failure
|
|
86
|
+
* - You want to implement custom error handling based on the returned result
|
|
87
|
+
*
|
|
88
|
+
* @default false
|
|
89
|
+
*/
|
|
90
|
+
returnLastOnMaxIterations?: boolean;
|
|
91
|
+
}
|
|
25
92
|
/**
|
|
26
93
|
* Configuration options for creating a TeamAgent.
|
|
27
94
|
*
|
|
@@ -33,6 +100,21 @@ export interface TeamAgentOptions<I extends Message, O extends Message> extends
|
|
|
33
100
|
* @default {ProcessMode.sequential}
|
|
34
101
|
*/
|
|
35
102
|
mode?: ProcessMode;
|
|
103
|
+
/**
|
|
104
|
+
* Configuration for reflection mode processing.
|
|
105
|
+
*
|
|
106
|
+
* When enabled, the TeamAgent will use an iterative refinement process where:
|
|
107
|
+
* 1. The team processes the input normally
|
|
108
|
+
* 2. A reviewer agent evaluates the output
|
|
109
|
+
* 3. If not approved, the process repeats with the previous output as context
|
|
110
|
+
* 4. This continues until approval or maximum iterations are reached
|
|
111
|
+
*
|
|
112
|
+
* This enables self-improving agent workflows that can iteratively refine
|
|
113
|
+
* their outputs based on feedback from a specialized reviewer agent.
|
|
114
|
+
*
|
|
115
|
+
* @see ReflectionMode for detailed configuration options
|
|
116
|
+
*/
|
|
117
|
+
reflection?: ReflectionMode;
|
|
36
118
|
/**
|
|
37
119
|
* Specifies which input field should be treated as an array for iterative processing.
|
|
38
120
|
*
|
|
@@ -116,6 +198,14 @@ export declare class TeamAgent<I extends Message, O extends Message> extends Age
|
|
|
116
198
|
* This can be either sequential (one after another) or parallel (all at once).
|
|
117
199
|
*/
|
|
118
200
|
mode: ProcessMode;
|
|
201
|
+
/**
|
|
202
|
+
* The reflection mode configuration with guaranteed maxIterations value.
|
|
203
|
+
*
|
|
204
|
+
* This is the internal representation after processing the user-provided
|
|
205
|
+
* reflection configuration, ensuring that maxIterations always has a value
|
|
206
|
+
* (defaulting to DEFAULT_REFLECTION_MAX_ITERATIONS if not specified).
|
|
207
|
+
*/
|
|
208
|
+
reflection?: ReflectionMode & Required<Pick<ReflectionMode, "maxIterations">>;
|
|
119
209
|
/**
|
|
120
210
|
* The input field key to iterate over when processing array inputs.
|
|
121
211
|
*
|
|
@@ -148,8 +238,10 @@ export declare class TeamAgent<I extends Message, O extends Message> extends Age
|
|
|
148
238
|
* @returns A stream of message chunks that collectively form the response
|
|
149
239
|
*/
|
|
150
240
|
process(input: I, options: AgentInvokeOptions): PromiseOrValue<AgentProcessResult<O>>;
|
|
241
|
+
private _processNonReflection;
|
|
242
|
+
private _processReflection;
|
|
151
243
|
private _processIterator;
|
|
152
|
-
private
|
|
244
|
+
private _processNonIterator;
|
|
153
245
|
/**
|
|
154
246
|
* Process input sequentially through each agent in the team.
|
|
155
247
|
*
|
|
@@ -180,6 +180,7 @@ declare class AIGNEContextShared {
|
|
|
180
180
|
span?: Span;
|
|
181
181
|
constructor(parent?: (Pick<Context, "model" | "skills" | "limits" | "observer"> & {
|
|
182
182
|
messageQueue?: MessageQueue;
|
|
183
|
+
events?: Emitter<any>;
|
|
183
184
|
}) | undefined);
|
|
184
185
|
readonly messageQueue: MessageQueue;
|
|
185
186
|
readonly events: Emitter<any>;
|
|
@@ -1,17 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export declare function loadAgentFromJsFile(path: string): Promise<Agent<any, any> | {
|
|
4
|
-
process: FunctionAgentFn;
|
|
5
|
-
name: string;
|
|
6
|
-
description?: string | undefined;
|
|
7
|
-
inputSchema?: ZodObject<Record<string, ZodType<any, z.ZodTypeDef, any>>, z.UnknownKeysParam, z.ZodTypeAny, {
|
|
8
|
-
[x: string]: any;
|
|
9
|
-
}, {
|
|
10
|
-
[x: string]: any;
|
|
11
|
-
}> | undefined;
|
|
12
|
-
outputSchema?: ZodObject<Record<string, ZodType<any, z.ZodTypeDef, any>>, z.UnknownKeysParam, z.ZodTypeAny, {
|
|
13
|
-
[x: string]: any;
|
|
14
|
-
}, {
|
|
15
|
-
[x: string]: any;
|
|
16
|
-
}> | undefined;
|
|
17
|
-
}>;
|
|
1
|
+
import { Agent } from "../agents/agent.js";
|
|
2
|
+
export declare function loadAgentFromJsFile(path: string): Promise<Agent<any, any> | import("./agent-yaml.js").AgentSchema>;
|
|
@@ -1,39 +1,60 @@
|
|
|
1
1
|
import { type ZodType } from "zod";
|
|
2
|
+
import type { FunctionAgentFn } from "../agents/agent.js";
|
|
2
3
|
import { AIAgentToolChoice } from "../agents/ai-agent.js";
|
|
3
4
|
import { ProcessMode } from "../agents/team-agent.js";
|
|
4
|
-
interface
|
|
5
|
+
export interface HooksSchema {
|
|
6
|
+
onStart?: NestAgentSchema;
|
|
7
|
+
onSuccess?: NestAgentSchema;
|
|
8
|
+
onError?: NestAgentSchema;
|
|
9
|
+
onEnd?: NestAgentSchema;
|
|
10
|
+
onSkillStart?: NestAgentSchema;
|
|
11
|
+
onSkillEnd?: NestAgentSchema;
|
|
12
|
+
onHandoff?: NestAgentSchema;
|
|
13
|
+
}
|
|
14
|
+
export type NestAgentSchema = string | {
|
|
15
|
+
url: string;
|
|
16
|
+
defaultInput?: Record<string, any>;
|
|
17
|
+
hooks?: HooksSchema | HooksSchema[];
|
|
18
|
+
} | AgentSchema;
|
|
19
|
+
export interface BaseAgentSchema {
|
|
5
20
|
name?: string;
|
|
6
21
|
description?: string;
|
|
7
22
|
inputSchema?: ZodType<Record<string, any>>;
|
|
23
|
+
defaultInput?: Record<string, any>;
|
|
8
24
|
outputSchema?: ZodType<Record<string, any>>;
|
|
9
|
-
skills?:
|
|
25
|
+
skills?: NestAgentSchema[];
|
|
26
|
+
hooks?: HooksSchema | HooksSchema[];
|
|
10
27
|
memory?: boolean | {
|
|
11
28
|
provider: string;
|
|
12
29
|
subscribeTopic?: string[];
|
|
13
30
|
};
|
|
14
31
|
}
|
|
15
|
-
interface AIAgentSchema extends BaseAgentSchema {
|
|
32
|
+
export interface AIAgentSchema extends BaseAgentSchema {
|
|
16
33
|
type: "ai";
|
|
17
34
|
instructions?: string;
|
|
18
35
|
inputKey?: string;
|
|
19
36
|
outputKey?: string;
|
|
20
37
|
toolChoice?: AIAgentToolChoice;
|
|
21
38
|
}
|
|
22
|
-
interface MCPAgentSchema {
|
|
39
|
+
export interface MCPAgentSchema extends BaseAgentSchema {
|
|
23
40
|
type: "mcp";
|
|
24
41
|
url?: string;
|
|
25
42
|
command?: string;
|
|
26
43
|
args?: string[];
|
|
27
44
|
}
|
|
28
|
-
interface TeamAgentSchema extends BaseAgentSchema {
|
|
45
|
+
export interface TeamAgentSchema extends BaseAgentSchema {
|
|
29
46
|
type: "team";
|
|
30
47
|
mode?: ProcessMode;
|
|
31
48
|
iterateOn?: string;
|
|
32
49
|
}
|
|
33
|
-
interface TransformAgentSchema extends BaseAgentSchema {
|
|
50
|
+
export interface TransformAgentSchema extends BaseAgentSchema {
|
|
34
51
|
type: "transform";
|
|
35
52
|
jsonata: string;
|
|
36
53
|
}
|
|
37
|
-
|
|
54
|
+
export interface FunctionAgentSchema extends BaseAgentSchema {
|
|
55
|
+
type: "function";
|
|
56
|
+
process: FunctionAgentFn;
|
|
57
|
+
}
|
|
58
|
+
export type AgentSchema = AIAgentSchema | MCPAgentSchema | TeamAgentSchema | TransformAgentSchema | FunctionAgentSchema;
|
|
59
|
+
export declare function parseAgentFile(path: string, data: object): Promise<AgentSchema>;
|
|
38
60
|
export declare function loadAgentFromYamlFile(path: string): Promise<AgentSchema>;
|
|
39
|
-
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Camelize } from "camelize-ts";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
-
import { Agent } from "../agents/agent.js";
|
|
3
|
+
import { Agent, type AgentOptions } from "../agents/agent.js";
|
|
4
4
|
import type { ChatModel, ChatModelOptions } from "../agents/chat-model.js";
|
|
5
5
|
import type { AIGNEOptions } from "../aigne/aigne.js";
|
|
6
6
|
import type { MemoryAgent, MemoryAgentOptions } from "../memory/memory.js";
|
|
@@ -25,7 +25,7 @@ export interface LoadOptions {
|
|
|
25
25
|
path: string;
|
|
26
26
|
}
|
|
27
27
|
export declare function load(options: LoadOptions): Promise<AIGNEOptions>;
|
|
28
|
-
export declare function loadAgent(path: string, options?: LoadOptions): Promise<Agent>;
|
|
28
|
+
export declare function loadAgent(path: string, options?: LoadOptions, agentOptions?: AgentOptions): Promise<Agent>;
|
|
29
29
|
export declare function loadModel(models: LoadableModel[], model?: Camelize<z.infer<typeof aigneFileSchema>["model"]>, modelOptions?: ChatModelOptions): Promise<ChatModel | undefined>;
|
|
30
30
|
declare const aigneFileSchema: z.ZodObject<{
|
|
31
31
|
name: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
|
|
@@ -22,4 +22,14 @@ export declare const inputOutputSchema: ({ path }: {
|
|
|
22
22
|
required?: string[] | undefined;
|
|
23
23
|
additionalProperties?: boolean | undefined;
|
|
24
24
|
}>]>;
|
|
25
|
+
export declare const defaultInputSchema: z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodObject<{
|
|
26
|
+
$get: z.ZodString;
|
|
27
|
+
}, "strip", z.ZodTypeAny, {
|
|
28
|
+
$get: string;
|
|
29
|
+
}, {
|
|
30
|
+
$get: string;
|
|
31
|
+
}>, z.ZodUnknown]>>;
|
|
25
32
|
export declare function optionalize<T>(schema: ZodType<T>): ZodType<T | undefined>;
|
|
33
|
+
export declare function camelizeSchema<T>(schema: ZodType<T>, { shallow }?: {
|
|
34
|
+
shallow?: boolean;
|
|
35
|
+
}): ZodType<T>;
|
|
@@ -19,7 +19,7 @@ export declare function pick<T extends object, K extends keyof T>(obj: T, ...key
|
|
|
19
19
|
export declare function omit<T extends object, K extends keyof T>(obj: T, ...keys: (K | K[])[]): Omit<T, K>;
|
|
20
20
|
export declare function omitDeep<T, K>(obj: T, ...keys: (K | K[])[]): unknown;
|
|
21
21
|
export declare function omitBy<T extends Record<string, unknown>, K extends keyof T>(obj: T, predicate: (value: T[K], key: K) => boolean): Partial<T>;
|
|
22
|
-
export declare function flat<T>(value
|
|
22
|
+
export declare function flat<T>(...value: (T | T[])[]): NonNullable<T>[];
|
|
23
23
|
export declare function createAccessorArray<T>(array: T[], accessor: (array: T[], name: string) => T | undefined): T[] & {
|
|
24
24
|
[key: string]: T;
|
|
25
25
|
};
|
|
@@ -10,6 +10,7 @@ import { type Nullish, type PromiseOrValue, type XOr } from "../utils/type-utils
|
|
|
10
10
|
import type { GuideRailAgent, GuideRailAgentOutput } from "./guide-rail-agent.js";
|
|
11
11
|
import { type TransferAgentOutput } from "./types.js";
|
|
12
12
|
export * from "./types.js";
|
|
13
|
+
export declare const DEFAULT_INPUT_ACTION_GET = "$get";
|
|
13
14
|
/**
|
|
14
15
|
* Basic message type that can contain any key-value pairs
|
|
15
16
|
*/
|
|
@@ -72,6 +73,11 @@ export interface AgentOptions<I extends Message = Message, O extends Message = M
|
|
|
72
73
|
* Used to validate that input messages conform to the expected format
|
|
73
74
|
*/
|
|
74
75
|
inputSchema?: AgentInputOutputSchema<I>;
|
|
76
|
+
/**
|
|
77
|
+
* Default input message for the agent, it can be used to provide partial input
|
|
78
|
+
* or default values for the agent's input schema.
|
|
79
|
+
*/
|
|
80
|
+
defaultInput?: Agent<I, O>["defaultInput"];
|
|
75
81
|
/**
|
|
76
82
|
* Zod schema defining the output message structure
|
|
77
83
|
*
|
|
@@ -106,7 +112,7 @@ export interface AgentOptions<I extends Message = Message, O extends Message = M
|
|
|
106
112
|
* Maximum number of memory items to retrieve
|
|
107
113
|
*/
|
|
108
114
|
maxRetrieveMemoryCount?: number;
|
|
109
|
-
hooks?: AgentHooks<I, O
|
|
115
|
+
hooks?: AgentHooks<I, O> | AgentHooks<I, O>[];
|
|
110
116
|
}
|
|
111
117
|
export declare const agentOptionsSchema: ZodObject<{
|
|
112
118
|
[key in keyof AgentOptions]: ZodType<AgentOptions[key]>;
|
|
@@ -137,6 +143,10 @@ export interface AgentInvokeOptions<U extends UserContext = UserContext> {
|
|
|
137
143
|
* and returns the final JSON result
|
|
138
144
|
*/
|
|
139
145
|
streaming?: boolean;
|
|
146
|
+
/**
|
|
147
|
+
* Optional hooks for agent invocation
|
|
148
|
+
*/
|
|
149
|
+
hooks?: AgentHooks<any, any>;
|
|
140
150
|
}
|
|
141
151
|
/**
|
|
142
152
|
* Agent is the base class for all agents.
|
|
@@ -190,7 +200,7 @@ export declare abstract class Agent<I extends Message = any, O extends Message =
|
|
|
190
200
|
* Here's an example of using hooks:
|
|
191
201
|
* {@includeCode ../../test/agents/agent.test.ts#example-agent-hooks}
|
|
192
202
|
*/
|
|
193
|
-
readonly hooks: AgentHooks<I, O
|
|
203
|
+
readonly hooks: AgentHooks<I, O>[];
|
|
194
204
|
/**
|
|
195
205
|
* List of GuideRail agents applied to this agent
|
|
196
206
|
*
|
|
@@ -232,6 +242,11 @@ export declare abstract class Agent<I extends Message = any, O extends Message =
|
|
|
232
242
|
*/
|
|
233
243
|
readonly description?: string;
|
|
234
244
|
private readonly _inputSchema?;
|
|
245
|
+
defaultInput?: Partial<{
|
|
246
|
+
[key in keyof I]: {
|
|
247
|
+
[DEFAULT_INPUT_ACTION_GET]: string;
|
|
248
|
+
} | I[key];
|
|
249
|
+
}>;
|
|
235
250
|
private readonly _outputSchema?;
|
|
236
251
|
/**
|
|
237
252
|
* Get the input data schema for this agent
|
|
@@ -372,6 +387,8 @@ export declare abstract class Agent<I extends Message = any, O extends Message =
|
|
|
372
387
|
* @returns Agent response (streaming or regular)
|
|
373
388
|
*/
|
|
374
389
|
invoke(input: I & Message, options?: Partial<AgentInvokeOptions>): Promise<AgentResponse<O>>;
|
|
390
|
+
private callHooks;
|
|
391
|
+
private mergeDefaultInput;
|
|
375
392
|
protected invokeSkill<I extends Message, O extends Message>(skill: Agent<I, O>, input: I & Message, options: AgentInvokeOptions): Promise<O>;
|
|
376
393
|
/**
|
|
377
394
|
* Process agent output
|
|
@@ -517,11 +534,15 @@ export interface AgentHooks<I extends Message = Message, O extends Message = Mes
|
|
|
517
534
|
*
|
|
518
535
|
* @param event Object containing the input message
|
|
519
536
|
*/
|
|
520
|
-
onStart?: (event: {
|
|
537
|
+
onStart?: ((event: {
|
|
521
538
|
context: Context;
|
|
522
539
|
input: I;
|
|
523
540
|
}) => PromiseOrValue<void | {
|
|
524
541
|
input?: I;
|
|
542
|
+
}>) | Agent<{
|
|
543
|
+
input: I;
|
|
544
|
+
}, {
|
|
545
|
+
input?: I;
|
|
525
546
|
}>;
|
|
526
547
|
/**
|
|
527
548
|
* Called when agent processing completes or fails
|
|
@@ -532,13 +553,39 @@ export interface AgentHooks<I extends Message = Message, O extends Message = Mes
|
|
|
532
553
|
*
|
|
533
554
|
* @param event Object containing the input message and either output or error
|
|
534
555
|
*/
|
|
535
|
-
onEnd?: (event: XOr<{
|
|
556
|
+
onEnd?: ((event: XOr<{
|
|
536
557
|
context: Context;
|
|
537
558
|
input: I;
|
|
538
559
|
output: O;
|
|
539
560
|
error: Error;
|
|
540
561
|
}, "output", "error">) => PromiseOrValue<void | {
|
|
541
562
|
output?: O;
|
|
563
|
+
}>) | Agent<XOr<{
|
|
564
|
+
input: I;
|
|
565
|
+
output: O;
|
|
566
|
+
error: Error;
|
|
567
|
+
}, "output", "error">, {
|
|
568
|
+
output?: O;
|
|
569
|
+
}>;
|
|
570
|
+
onSuccess?: ((event: {
|
|
571
|
+
context: Context;
|
|
572
|
+
input: I;
|
|
573
|
+
output: O;
|
|
574
|
+
}) => PromiseOrValue<void | {
|
|
575
|
+
output?: O;
|
|
576
|
+
}>) | Agent<{
|
|
577
|
+
input: I;
|
|
578
|
+
output: O;
|
|
579
|
+
}, {
|
|
580
|
+
output?: O;
|
|
581
|
+
}>;
|
|
582
|
+
onError?: ((event: {
|
|
583
|
+
context: Context;
|
|
584
|
+
input: I;
|
|
585
|
+
error: Error;
|
|
586
|
+
}) => void) | Agent<{
|
|
587
|
+
input: I;
|
|
588
|
+
error: Error;
|
|
542
589
|
}>;
|
|
543
590
|
/**
|
|
544
591
|
* Called before a skill (sub-agent) is invoked
|
|
@@ -548,11 +595,14 @@ export interface AgentHooks<I extends Message = Message, O extends Message = Mes
|
|
|
548
595
|
*
|
|
549
596
|
* @param event Object containing the skill being used and input message
|
|
550
597
|
*/
|
|
551
|
-
onSkillStart?: (event: {
|
|
598
|
+
onSkillStart?: ((event: {
|
|
552
599
|
context: Context;
|
|
553
600
|
skill: Agent;
|
|
554
601
|
input: Message;
|
|
555
|
-
}) => PromiseOrValue<void
|
|
602
|
+
}) => PromiseOrValue<void>) | Agent<{
|
|
603
|
+
skill: Agent;
|
|
604
|
+
input: Message;
|
|
605
|
+
}>;
|
|
556
606
|
/**
|
|
557
607
|
* Called after a skill (sub-agent) completes or fails
|
|
558
608
|
*
|
|
@@ -562,13 +612,18 @@ export interface AgentHooks<I extends Message = Message, O extends Message = Mes
|
|
|
562
612
|
*
|
|
563
613
|
* @param event Object containing the skill used, input message, and either output or error
|
|
564
614
|
*/
|
|
565
|
-
onSkillEnd?: (event: XOr<{
|
|
615
|
+
onSkillEnd?: ((event: XOr<{
|
|
566
616
|
context: Context;
|
|
567
617
|
skill: Agent;
|
|
568
618
|
input: Message;
|
|
569
619
|
output: Message;
|
|
570
620
|
error: Error;
|
|
571
|
-
}, "output", "error">) => PromiseOrValue<void
|
|
621
|
+
}, "output", "error">) => PromiseOrValue<void>) | Agent<XOr<{
|
|
622
|
+
skill: Agent;
|
|
623
|
+
input: Message;
|
|
624
|
+
output: Message;
|
|
625
|
+
error: Error;
|
|
626
|
+
}, "output", "error">>;
|
|
572
627
|
/**
|
|
573
628
|
* Called when an agent hands off processing to another agent
|
|
574
629
|
*
|
|
@@ -578,13 +633,19 @@ export interface AgentHooks<I extends Message = Message, O extends Message = Mes
|
|
|
578
633
|
*
|
|
579
634
|
* @param event Object containing the source agent, target agent, and input message
|
|
580
635
|
*/
|
|
581
|
-
onHandoff?: (event: {
|
|
636
|
+
onHandoff?: ((event: {
|
|
582
637
|
context: Context;
|
|
583
638
|
source: Agent;
|
|
584
639
|
target: Agent;
|
|
585
640
|
input: I;
|
|
586
|
-
}) => PromiseOrValue<void
|
|
641
|
+
}) => PromiseOrValue<void>) | Agent<{
|
|
642
|
+
source: Agent;
|
|
643
|
+
target: Agent;
|
|
644
|
+
input: I;
|
|
645
|
+
}>;
|
|
587
646
|
}
|
|
647
|
+
export type AgentHookInput<H extends keyof AgentHooks, Hook extends AgentHooks[H] = AgentHooks[H]> = Hook extends (input: infer I) => any ? Omit<I, "context"> : never;
|
|
648
|
+
export type AgentHookOutput<H extends keyof AgentHooks, Hook extends AgentHooks[H] = AgentHooks[H]> = Hook extends (...args: any[]) => any ? Exclude<Awaited<ReturnType<Hook>>, void> | undefined : never;
|
|
588
649
|
/**
|
|
589
650
|
* Response type for an agent, can be:
|
|
590
651
|
* - Direct response object
|