@aigne/core 1.20.1 → 1.21.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 +7 -0
- package/lib/cjs/agents/agent.d.ts +4 -4
- package/lib/cjs/agents/ai-agent.d.ts +7 -10
- package/lib/cjs/agents/ai-agent.js +5 -5
- package/lib/cjs/aigne/aigne.d.ts +5 -5
- package/lib/cjs/aigne/context.d.ts +6 -6
- package/lib/cjs/loader/agent-js.d.ts +2 -2
- package/lib/cjs/loader/agent-js.js +3 -0
- package/lib/cjs/loader/agent-yaml.d.ts +23 -6
- package/lib/cjs/loader/agent-yaml.js +38 -2
- package/lib/cjs/loader/index.d.ts +1 -1
- package/lib/cjs/loader/index.js +16 -4
- package/lib/cjs/prompt/prompt-builder.d.ts +1 -1
- package/lib/dts/agents/agent.d.ts +4 -4
- package/lib/dts/agents/ai-agent.d.ts +7 -10
- package/lib/dts/aigne/aigne.d.ts +5 -5
- package/lib/dts/aigne/context.d.ts +6 -6
- package/lib/dts/loader/agent-js.d.ts +2 -2
- package/lib/dts/loader/agent-yaml.d.ts +23 -6
- package/lib/dts/loader/index.d.ts +1 -1
- package/lib/dts/prompt/prompt-builder.d.ts +1 -1
- package/lib/esm/agents/agent.d.ts +4 -4
- package/lib/esm/agents/ai-agent.d.ts +7 -10
- package/lib/esm/agents/ai-agent.js +2 -2
- package/lib/esm/aigne/aigne.d.ts +5 -5
- package/lib/esm/aigne/context.d.ts +6 -6
- package/lib/esm/loader/agent-js.d.ts +2 -2
- package/lib/esm/loader/agent-js.js +3 -0
- package/lib/esm/loader/agent-yaml.d.ts +23 -6
- package/lib/esm/loader/agent-yaml.js +38 -2
- package/lib/esm/loader/index.d.ts +1 -1
- package/lib/esm/loader/index.js +17 -5
- package/lib/esm/prompt/prompt-builder.d.ts +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,13 @@
|
|
|
5
5
|
|
|
6
6
|
* add user context support ([#131](https://github.com/AIGNE-io/aigne-framework/issues/131)) ([4dd9d20](https://github.com/AIGNE-io/aigne-framework/commit/4dd9d20953f6ac33933723db56efd9b44bafeb02))
|
|
7
7
|
|
|
8
|
+
## [1.21.0](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.20.1...core-v1.21.0) (2025-06-20)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* **cli:** support pass named input to agent by --input-xxx ([#167](https://github.com/AIGNE-io/aigne-framework/issues/167)) ([cda5bb6](https://github.com/AIGNE-io/aigne-framework/commit/cda5bb6baab680787de1a042664fe34c17a84bb1))
|
|
14
|
+
|
|
8
15
|
## [1.20.1](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.20.0...core-v1.20.1) (2025-06-19)
|
|
9
16
|
|
|
10
17
|
|
|
@@ -341,7 +341,7 @@ export declare abstract class Agent<I extends Message = Message, O extends Messa
|
|
|
341
341
|
* Here's an example of invoking an agent with regular mode:
|
|
342
342
|
* {@includeCode ../../test/agents/agent.test.ts#example-invoke}
|
|
343
343
|
*/
|
|
344
|
-
invoke(input: I, options?: Partial<AgentInvokeOptions> & {
|
|
344
|
+
invoke(input: I & Message, options?: Partial<AgentInvokeOptions> & {
|
|
345
345
|
streaming?: false;
|
|
346
346
|
}): Promise<O>;
|
|
347
347
|
/**
|
|
@@ -359,7 +359,7 @@ export declare abstract class Agent<I extends Message = Message, O extends Messa
|
|
|
359
359
|
* Here's an example of invoking an agent with streaming response:
|
|
360
360
|
* {@includeCode ../../test/agents/agent.test.ts#example-invoke-streaming}
|
|
361
361
|
*/
|
|
362
|
-
invoke(input: I, options: Partial<AgentInvokeOptions> & {
|
|
362
|
+
invoke(input: I & Message, options: Partial<AgentInvokeOptions> & {
|
|
363
363
|
streaming: true;
|
|
364
364
|
}): Promise<AgentResponseStream<O>>;
|
|
365
365
|
/**
|
|
@@ -371,8 +371,8 @@ export declare abstract class Agent<I extends Message = Message, O extends Messa
|
|
|
371
371
|
* @param options Invocation options
|
|
372
372
|
* @returns Agent response (streaming or regular)
|
|
373
373
|
*/
|
|
374
|
-
invoke(input: I, options?: Partial<AgentInvokeOptions>): Promise<AgentResponse<O>>;
|
|
375
|
-
protected invokeSkill<I extends Message, O extends Message>(skill: Agent<I, O>, input: I, options: AgentInvokeOptions): Promise<O>;
|
|
374
|
+
invoke(input: I & Message, options?: Partial<AgentInvokeOptions>): Promise<AgentResponse<O>>;
|
|
375
|
+
protected invokeSkill<I extends Message, O extends Message>(skill: Agent<I, O>, input: I & Message, options: AgentInvokeOptions): Promise<O>;
|
|
376
376
|
/**
|
|
377
377
|
* Process agent output
|
|
378
378
|
*
|
|
@@ -3,6 +3,7 @@ import { PromptBuilder } from "../prompt/prompt-builder.js";
|
|
|
3
3
|
import { Agent, type AgentInvokeOptions, type AgentOptions, type AgentProcessAsyncGenerator, type Message } from "./agent.js";
|
|
4
4
|
import { ChatModel, type ChatModelInput } from "./chat-model.js";
|
|
5
5
|
import type { GuideRailAgentOutput } from "./guide-rail-agent.js";
|
|
6
|
+
export declare const DEFAULT_OUTPUT_KEY = "message";
|
|
6
7
|
/**
|
|
7
8
|
* Configuration options for an AI Agent
|
|
8
9
|
*
|
|
@@ -12,7 +13,7 @@ import type { GuideRailAgentOutput } from "./guide-rail-agent.js";
|
|
|
12
13
|
* @template I The input message type the agent accepts
|
|
13
14
|
* @template O The output message type the agent returns
|
|
14
15
|
*/
|
|
15
|
-
export interface AIAgentOptions<
|
|
16
|
+
export interface AIAgentOptions<I extends Message = Message, O extends Message = Message> extends AgentOptions<I, O> {
|
|
16
17
|
/**
|
|
17
18
|
* The language model to use for this agent
|
|
18
19
|
*
|
|
@@ -29,7 +30,7 @@ export interface AIAgentOptions<InputKey extends string = string, I extends Mess
|
|
|
29
30
|
/**
|
|
30
31
|
* Pick a message from input to use as the user's message
|
|
31
32
|
*/
|
|
32
|
-
inputKey?:
|
|
33
|
+
inputKey?: string;
|
|
33
34
|
/**
|
|
34
35
|
* Custom key to use for text output in the response
|
|
35
36
|
*
|
|
@@ -110,9 +111,6 @@ export declare const aiAgentToolChoiceSchema: z.ZodUnion<[z.ZodNativeEnum<typeof
|
|
|
110
111
|
export declare const aiAgentOptionsSchema: ZodObject<{
|
|
111
112
|
[key in keyof AIAgentOptions]: ZodType<AIAgentOptions[key]>;
|
|
112
113
|
}>;
|
|
113
|
-
type InputMessage<K> = K extends string ? {
|
|
114
|
-
[key in K]: string;
|
|
115
|
-
} : Message;
|
|
116
114
|
/**
|
|
117
115
|
* AI-powered agent that leverages language models
|
|
118
116
|
*
|
|
@@ -133,7 +131,7 @@ type InputMessage<K> = K extends string ? {
|
|
|
133
131
|
* Basic AIAgent creation:
|
|
134
132
|
* {@includeCode ../../test/agents/ai-agent.test.ts#example-ai-agent-basic}
|
|
135
133
|
*/
|
|
136
|
-
export declare class AIAgent<
|
|
134
|
+
export declare class AIAgent<I extends Message = Message, O extends Message = Message> extends Agent<I, O> {
|
|
137
135
|
/**
|
|
138
136
|
* Create an AIAgent with the specified options
|
|
139
137
|
*
|
|
@@ -146,13 +144,13 @@ export declare class AIAgent<InputKey extends string = string, I extends Message
|
|
|
146
144
|
* AI agent with custom instructions:
|
|
147
145
|
* {@includeCode ../../test/agents/ai-agent.test.ts#example-ai-agent-instructions}
|
|
148
146
|
*/
|
|
149
|
-
static from<
|
|
147
|
+
static from<I extends Message, O extends Message>(options: AIAgentOptions<I, O>): AIAgent<I, O>;
|
|
150
148
|
/**
|
|
151
149
|
* Create an AIAgent instance
|
|
152
150
|
*
|
|
153
151
|
* @param options Configuration options for the AI agent
|
|
154
152
|
*/
|
|
155
|
-
constructor(options: AIAgentOptions<
|
|
153
|
+
constructor(options: AIAgentOptions<I, O>);
|
|
156
154
|
/**
|
|
157
155
|
* The language model used by this agent
|
|
158
156
|
*
|
|
@@ -173,7 +171,7 @@ export declare class AIAgent<InputKey extends string = string, I extends Message
|
|
|
173
171
|
/**
|
|
174
172
|
* Pick a message from input to use as the user's message
|
|
175
173
|
*/
|
|
176
|
-
inputKey?:
|
|
174
|
+
inputKey?: string;
|
|
177
175
|
/**
|
|
178
176
|
* Custom key to use for text output in the response
|
|
179
177
|
*
|
|
@@ -235,4 +233,3 @@ export declare class AIAgent<InputKey extends string = string, I extends Message
|
|
|
235
233
|
*/
|
|
236
234
|
_processRouter(input: I, model: ChatModel, modelInput: ChatModelInput, options: AgentInvokeOptions, toolsMap: Map<string, Agent>): AgentProcessAsyncGenerator<O>;
|
|
237
235
|
}
|
|
238
|
-
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AIAgent = exports.aiAgentOptionsSchema = exports.aiAgentToolChoiceSchema = exports.AIAgentToolChoice = void 0;
|
|
3
|
+
exports.AIAgent = exports.aiAgentOptionsSchema = exports.aiAgentToolChoiceSchema = exports.AIAgentToolChoice = exports.DEFAULT_OUTPUT_KEY = void 0;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
5
|
const prompt_builder_js_1 = require("../prompt/prompt-builder.js");
|
|
6
6
|
const template_js_1 = require("../prompt/template.js");
|
|
@@ -8,7 +8,7 @@ const type_utils_js_1 = require("../utils/type-utils.js");
|
|
|
8
8
|
const agent_js_1 = require("./agent.js");
|
|
9
9
|
const chat_model_js_1 = require("./chat-model.js");
|
|
10
10
|
const types_js_1 = require("./types.js");
|
|
11
|
-
|
|
11
|
+
exports.DEFAULT_OUTPUT_KEY = "message";
|
|
12
12
|
/**
|
|
13
13
|
* Tool choice options for AI agents
|
|
14
14
|
*
|
|
@@ -101,7 +101,7 @@ class AIAgent extends agent_js_1.Agent {
|
|
|
101
101
|
* @param options Configuration options for the AI agent
|
|
102
102
|
*/
|
|
103
103
|
constructor(options) {
|
|
104
|
-
super(
|
|
104
|
+
super(options);
|
|
105
105
|
(0, type_utils_js_1.checkArguments)("AIAgent", exports.aiAgentOptionsSchema, options);
|
|
106
106
|
this.model = options.model;
|
|
107
107
|
this.instructions =
|
|
@@ -109,7 +109,7 @@ class AIAgent extends agent_js_1.Agent {
|
|
|
109
109
|
? prompt_builder_js_1.PromptBuilder.from(options.instructions)
|
|
110
110
|
: (options.instructions ?? new prompt_builder_js_1.PromptBuilder());
|
|
111
111
|
this.inputKey = options.inputKey;
|
|
112
|
-
this.outputKey = options.outputKey || DEFAULT_OUTPUT_KEY;
|
|
112
|
+
this.outputKey = options.outputKey || exports.DEFAULT_OUTPUT_KEY;
|
|
113
113
|
this.toolChoice = options.toolChoice;
|
|
114
114
|
this.memoryAgentsAsTools = options.memoryAgentsAsTools;
|
|
115
115
|
this.memoryPromptTemplate = options.memoryPromptTemplate;
|
|
@@ -264,7 +264,7 @@ class AIAgent extends agent_js_1.Agent {
|
|
|
264
264
|
}
|
|
265
265
|
}
|
|
266
266
|
async onGuideRailError(error) {
|
|
267
|
-
const outputKey = this.outputKey || DEFAULT_OUTPUT_KEY;
|
|
267
|
+
const outputKey = this.outputKey || exports.DEFAULT_OUTPUT_KEY;
|
|
268
268
|
return {
|
|
269
269
|
[outputKey]: error.reason,
|
|
270
270
|
};
|
package/lib/cjs/aigne/aigne.d.ts
CHANGED
|
@@ -134,7 +134,7 @@ export declare class AIGNE<U extends UserContext = UserContext> {
|
|
|
134
134
|
* @param options.streaming - Must be false to return a response stream
|
|
135
135
|
* @returns A promise resolving to a tuple containing the agent's response and the final active agent
|
|
136
136
|
*/
|
|
137
|
-
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I, options: InvokeOptions<U> & {
|
|
137
|
+
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I & Message, options: InvokeOptions<U> & {
|
|
138
138
|
returnActiveAgent: true;
|
|
139
139
|
streaming?: false;
|
|
140
140
|
}): Promise<[O, Agent]>;
|
|
@@ -148,7 +148,7 @@ export declare class AIGNE<U extends UserContext = UserContext> {
|
|
|
148
148
|
* @param options.streaming - Must be true to return a response stream
|
|
149
149
|
* @returns A promise resolving to a tuple containing the agent's response stream and a promise for the final agent
|
|
150
150
|
*/
|
|
151
|
-
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I, options: InvokeOptions<U> & {
|
|
151
|
+
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I & Message, options: InvokeOptions<U> & {
|
|
152
152
|
returnActiveAgent: true;
|
|
153
153
|
streaming: true;
|
|
154
154
|
}): Promise<[AgentResponseStream<O>, Promise<Agent>]>;
|
|
@@ -165,7 +165,7 @@ export declare class AIGNE<U extends UserContext = UserContext> {
|
|
|
165
165
|
* Here's a simple example of how to invoke an agent:
|
|
166
166
|
* {@includeCode ../../test/aigne/aigne.test.ts#example-simple}
|
|
167
167
|
*/
|
|
168
|
-
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I, options?: InvokeOptions<U> & {
|
|
168
|
+
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I & Message, options?: InvokeOptions<U> & {
|
|
169
169
|
returnActiveAgent?: false;
|
|
170
170
|
streaming?: false;
|
|
171
171
|
}): Promise<O>;
|
|
@@ -182,7 +182,7 @@ export declare class AIGNE<U extends UserContext = UserContext> {
|
|
|
182
182
|
* Here's an example of how to invoke an agent with streaming response:
|
|
183
183
|
* {@includeCode ../../test/aigne/aigne.test.ts#example-streaming}
|
|
184
184
|
*/
|
|
185
|
-
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I, options: InvokeOptions<U> & {
|
|
185
|
+
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I & Message, options: InvokeOptions<U> & {
|
|
186
186
|
returnActiveAgent?: false;
|
|
187
187
|
streaming: true;
|
|
188
188
|
}): Promise<AgentResponseStream<O>>;
|
|
@@ -196,7 +196,7 @@ export declare class AIGNE<U extends UserContext = UserContext> {
|
|
|
196
196
|
* @returns Either a UserAgent (when no message provided) or a promise resolving to the agent's response
|
|
197
197
|
* with optional active agent information based on the provided options
|
|
198
198
|
*/
|
|
199
|
-
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message?: I, options?: InvokeOptions<U>): UserAgent<I, O> | Promise<AgentResponse<O> | [AgentResponse<O>, Agent]>;
|
|
199
|
+
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message?: I & Message, options?: InvokeOptions<U>): UserAgent<I, O> | Promise<AgentResponse<O> | [AgentResponse<O>, Agent]>;
|
|
200
200
|
/**
|
|
201
201
|
* Publishes a message to the message queue for inter-agent communication.
|
|
202
202
|
* This method broadcasts a message to all subscribers of the specified topic(s).
|
|
@@ -78,11 +78,11 @@ export interface Context<U extends UserContext = UserContext> extends TypedEvent
|
|
|
78
78
|
* @param options.streaming return a stream of the output
|
|
79
79
|
* @returns the output of the agent and the final active agent
|
|
80
80
|
*/
|
|
81
|
-
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I, options: InvokeOptions & {
|
|
81
|
+
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I & Message, options: InvokeOptions & {
|
|
82
82
|
returnActiveAgent: true;
|
|
83
83
|
streaming?: false;
|
|
84
84
|
}): Promise<[O, Agent]>;
|
|
85
|
-
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I, options: InvokeOptions & {
|
|
85
|
+
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I & Message, options: InvokeOptions & {
|
|
86
86
|
returnActiveAgent: true;
|
|
87
87
|
streaming: true;
|
|
88
88
|
}): Promise<[AgentResponseStream<O>, Promise<Agent>]>;
|
|
@@ -92,13 +92,13 @@ export interface Context<U extends UserContext = UserContext> extends TypedEvent
|
|
|
92
92
|
* @param message Message to pass to the agent
|
|
93
93
|
* @returns the output of the agent
|
|
94
94
|
*/
|
|
95
|
-
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I, options?: InvokeOptions & {
|
|
95
|
+
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I & Message, options?: InvokeOptions & {
|
|
96
96
|
streaming?: false;
|
|
97
97
|
}): Promise<O>;
|
|
98
|
-
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I, options: InvokeOptions & {
|
|
98
|
+
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I & Message, options: InvokeOptions & {
|
|
99
99
|
streaming: true;
|
|
100
100
|
}): Promise<AgentResponseStream<O>>;
|
|
101
|
-
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message?: I, options?: InvokeOptions): UserAgent<I, O> | Promise<AgentResponse<O> | [AgentResponse<O>, Agent]>;
|
|
101
|
+
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message?: I & Message, options?: InvokeOptions): UserAgent<I, O> | Promise<AgentResponse<O> | [AgentResponse<O>, Agent]>;
|
|
102
102
|
/**
|
|
103
103
|
* Publish a message to a topic, the aigne will invoke the listeners of the topic
|
|
104
104
|
* @param topic topic name, or an array of topic names
|
|
@@ -169,7 +169,7 @@ declare class AIGNEContextShared {
|
|
|
169
169
|
private timer?;
|
|
170
170
|
private initTimeout;
|
|
171
171
|
get status(): "normal" | "timeout";
|
|
172
|
-
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, input: I, context: Context, options?: InvokeOptions): AgentProcessAsyncGenerator<O & {
|
|
172
|
+
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, input: I & Message, context: Context, options?: InvokeOptions): AgentProcessAsyncGenerator<O & {
|
|
173
173
|
__activeAgent__: Agent;
|
|
174
174
|
}>;
|
|
175
175
|
private invokeAgent;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type ZodObject, type ZodType, z } from "zod";
|
|
2
|
-
import type
|
|
3
|
-
export declare function loadAgentFromJsFile(path: string): Promise<{
|
|
2
|
+
import { Agent, type Message } from "../agents/agent.js";
|
|
3
|
+
export declare function loadAgentFromJsFile(path: string): Promise<Agent<any, any> | {
|
|
4
4
|
process: (args_0: Message) => Message;
|
|
5
5
|
name: string;
|
|
6
6
|
description?: string | undefined;
|
|
@@ -36,6 +36,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
36
36
|
exports.loadAgentFromJsFile = loadAgentFromJsFile;
|
|
37
37
|
const json_schema_to_zod_1 = require("@aigne/json-schema-to-zod");
|
|
38
38
|
const zod_1 = require("zod");
|
|
39
|
+
const agent_js_1 = require("../agents/agent.js");
|
|
39
40
|
const camelize_js_1 = require("../utils/camelize.js");
|
|
40
41
|
const type_utils_js_1 = require("../utils/type-utils.js");
|
|
41
42
|
const schema_js_1 = require("./schema.js");
|
|
@@ -55,6 +56,8 @@ const agentJsFileSchema = zod_1.z.object({
|
|
|
55
56
|
});
|
|
56
57
|
async function loadAgentFromJsFile(path) {
|
|
57
58
|
const { default: agent } = await (0, type_utils_js_1.tryOrThrow)(() => Promise.resolve(`${path}`).then(s => __importStar(require(s))), (error) => new Error(`Failed to load agent definition from ${path}: ${error.message}`));
|
|
59
|
+
if (agent instanceof agent_js_1.Agent)
|
|
60
|
+
return agent;
|
|
58
61
|
if (typeof agent !== "function") {
|
|
59
62
|
throw new Error(`Agent file ${path} must export a default function, but got ${typeof agent}`);
|
|
60
63
|
}
|
|
@@ -1,6 +1,29 @@
|
|
|
1
1
|
import { type ZodObject, type ZodType, z } from "zod";
|
|
2
2
|
import { AIAgentToolChoice } from "../agents/ai-agent.js";
|
|
3
|
+
import { ProcessMode } from "../agents/team-agent.js";
|
|
3
4
|
export declare function loadAgentFromYamlFile(path: string): Promise<{
|
|
5
|
+
type: "mcp";
|
|
6
|
+
url?: string | undefined;
|
|
7
|
+
args?: string[] | undefined;
|
|
8
|
+
command?: string | undefined;
|
|
9
|
+
} | {
|
|
10
|
+
type: "team";
|
|
11
|
+
name: string;
|
|
12
|
+
description?: string | undefined;
|
|
13
|
+
skills?: string[] | undefined;
|
|
14
|
+
mode?: ProcessMode | undefined;
|
|
15
|
+
inputSchema?: ZodObject<Record<string, ZodType<any, z.ZodTypeDef, any>>, z.UnknownKeysParam, z.ZodTypeAny, {
|
|
16
|
+
[x: string]: any;
|
|
17
|
+
}, {
|
|
18
|
+
[x: string]: any;
|
|
19
|
+
}> | undefined;
|
|
20
|
+
outputSchema?: ZodObject<Record<string, ZodType<any, z.ZodTypeDef, any>>, z.UnknownKeysParam, z.ZodTypeAny, {
|
|
21
|
+
[x: string]: any;
|
|
22
|
+
}, {
|
|
23
|
+
[x: string]: any;
|
|
24
|
+
}> | undefined;
|
|
25
|
+
} | {
|
|
26
|
+
instructions: string | undefined;
|
|
4
27
|
type: "ai";
|
|
5
28
|
name: string;
|
|
6
29
|
description?: string | undefined;
|
|
@@ -9,7 +32,6 @@ export declare function loadAgentFromYamlFile(path: string): Promise<{
|
|
|
9
32
|
provider: string;
|
|
10
33
|
subscribeTopic?: string[] | undefined;
|
|
11
34
|
} | undefined;
|
|
12
|
-
instructions?: string | undefined;
|
|
13
35
|
inputSchema?: ZodObject<Record<string, ZodType<any, z.ZodTypeDef, any>>, z.UnknownKeysParam, z.ZodTypeAny, {
|
|
14
36
|
[x: string]: any;
|
|
15
37
|
}, {
|
|
@@ -23,9 +45,4 @@ export declare function loadAgentFromYamlFile(path: string): Promise<{
|
|
|
23
45
|
inputKey?: string | undefined;
|
|
24
46
|
outputKey?: string | undefined;
|
|
25
47
|
toolChoice?: AIAgentToolChoice | undefined;
|
|
26
|
-
} | {
|
|
27
|
-
type: "mcp";
|
|
28
|
-
url?: string | undefined;
|
|
29
|
-
args?: string[] | undefined;
|
|
30
|
-
command?: string | undefined;
|
|
31
48
|
}>;
|
|
@@ -6,6 +6,7 @@ const index_js_1 = require("@aigne/platform-helpers/nodejs/index.js");
|
|
|
6
6
|
const yaml_1 = require("yaml");
|
|
7
7
|
const zod_1 = require("zod");
|
|
8
8
|
const ai_agent_js_1 = require("../agents/ai-agent.js");
|
|
9
|
+
const team_agent_js_1 = require("../agents/team-agent.js");
|
|
9
10
|
const camelize_js_1 = require("../utils/camelize.js");
|
|
10
11
|
const type_utils_js_1 = require("../utils/type-utils.js");
|
|
11
12
|
const schema_js_1 = require("./schema.js");
|
|
@@ -18,7 +19,12 @@ const agentFileSchema = zod_1.z.discriminatedUnion("type", [
|
|
|
18
19
|
.nullish()
|
|
19
20
|
.transform((v) => v ?? undefined),
|
|
20
21
|
instructions: zod_1.z
|
|
21
|
-
.
|
|
22
|
+
.union([
|
|
23
|
+
zod_1.z.string(),
|
|
24
|
+
zod_1.z.object({
|
|
25
|
+
url: zod_1.z.string(),
|
|
26
|
+
}),
|
|
27
|
+
])
|
|
22
28
|
.nullish()
|
|
23
29
|
.transform((v) => v ?? undefined),
|
|
24
30
|
input_key: zod_1.z
|
|
@@ -72,16 +78,46 @@ const agentFileSchema = zod_1.z.discriminatedUnion("type", [
|
|
|
72
78
|
.nullish()
|
|
73
79
|
.transform((v) => v ?? undefined),
|
|
74
80
|
}),
|
|
81
|
+
zod_1.z.object({
|
|
82
|
+
type: zod_1.z.literal("team"),
|
|
83
|
+
name: zod_1.z.string(),
|
|
84
|
+
description: zod_1.z
|
|
85
|
+
.string()
|
|
86
|
+
.nullish()
|
|
87
|
+
.transform((v) => v ?? undefined),
|
|
88
|
+
input_schema: schema_js_1.inputOutputSchema
|
|
89
|
+
.nullish()
|
|
90
|
+
.transform((v) => (v ? (0, json_schema_to_zod_1.jsonSchemaToZod)(v) : undefined)),
|
|
91
|
+
output_schema: schema_js_1.inputOutputSchema
|
|
92
|
+
.nullish()
|
|
93
|
+
.transform((v) => (v ? (0, json_schema_to_zod_1.jsonSchemaToZod)(v) : undefined)),
|
|
94
|
+
skills: zod_1.z
|
|
95
|
+
.array(zod_1.z.string())
|
|
96
|
+
.nullish()
|
|
97
|
+
.transform((v) => v ?? undefined),
|
|
98
|
+
mode: zod_1.z
|
|
99
|
+
.nativeEnum(team_agent_js_1.ProcessMode)
|
|
100
|
+
.nullish()
|
|
101
|
+
.transform((v) => v ?? undefined),
|
|
102
|
+
}),
|
|
75
103
|
]);
|
|
76
104
|
async function loadAgentFromYamlFile(path) {
|
|
77
105
|
const raw = await (0, type_utils_js_1.tryOrThrow)(() => index_js_1.nodejs.fs.readFile(path, "utf8"), (error) => new Error(`Failed to load agent definition from ${path}: ${error.message}`));
|
|
78
106
|
const json = await (0, type_utils_js_1.tryOrThrow)(() => (0, yaml_1.parse)(raw), (error) => new Error(`Failed to parse agent definition from ${path}: ${error.message}`));
|
|
79
|
-
const agent = (0, type_utils_js_1.tryOrThrow)(() => (0, camelize_js_1.customCamelize)(agentFileSchema.
|
|
107
|
+
const agent = await (0, type_utils_js_1.tryOrThrow)(async () => (0, camelize_js_1.customCamelize)(await agentFileSchema.parseAsync({
|
|
80
108
|
...json,
|
|
81
109
|
type: json.type ?? "ai",
|
|
82
110
|
skills: json.skills ?? json.tools,
|
|
83
111
|
}), {
|
|
84
112
|
shallowKeys: ["input_schema", "output_schema"],
|
|
85
113
|
}), (error) => new Error(`Failed to validate agent definition from ${path}: ${error.message}`));
|
|
114
|
+
if (agent.type === "ai") {
|
|
115
|
+
return {
|
|
116
|
+
...agent,
|
|
117
|
+
instructions: typeof agent.instructions === "object" && "url" in agent.instructions
|
|
118
|
+
? await index_js_1.nodejs.fs.readFile(index_js_1.nodejs.path.join(index_js_1.nodejs.path.dirname(path), agent.instructions.url), "utf8")
|
|
119
|
+
: agent.instructions,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
86
122
|
return agent;
|
|
87
123
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Camelize } from "camelize-ts";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
-
import {
|
|
3
|
+
import { Agent } from "../agents/agent.js";
|
|
4
4
|
import type { ChatModel, ChatModelOptions } from "../agents/chat-model.js";
|
|
5
5
|
import type { MemoryAgent, MemoryAgentOptions } from "../memory/memory.js";
|
|
6
6
|
export interface LoadOptions {
|
package/lib/cjs/loader/index.js
CHANGED
|
@@ -10,6 +10,7 @@ const zod_1 = require("zod");
|
|
|
10
10
|
const agent_js_1 = require("../agents/agent.js");
|
|
11
11
|
const ai_agent_js_1 = require("../agents/ai-agent.js");
|
|
12
12
|
const mcp_agent_js_1 = require("../agents/mcp-agent.js");
|
|
13
|
+
const team_agent_js_1 = require("../agents/team-agent.js");
|
|
13
14
|
const type_utils_js_1 = require("../utils/type-utils.js");
|
|
14
15
|
const agent_js_js_1 = require("./agent-js.js");
|
|
15
16
|
const agent_yaml_js_1 = require("./agent-yaml.js");
|
|
@@ -28,20 +29,25 @@ async function load(options) {
|
|
|
28
29
|
};
|
|
29
30
|
}
|
|
30
31
|
async function loadAgent(path, options) {
|
|
31
|
-
if (index_js_1.nodejs.path.extname(path)
|
|
32
|
+
if ([".js", ".mjs", ".ts", ".mts"].includes(index_js_1.nodejs.path.extname(path))) {
|
|
32
33
|
const agent = await (0, agent_js_js_1.loadAgentFromJsFile)(path);
|
|
34
|
+
if (agent instanceof agent_js_1.Agent)
|
|
35
|
+
return agent;
|
|
33
36
|
return agent_js_1.FunctionAgent.from(agent);
|
|
34
37
|
}
|
|
35
|
-
if (
|
|
38
|
+
if ([".yml", ".yaml"].includes(index_js_1.nodejs.path.extname(path))) {
|
|
36
39
|
const agent = await (0, agent_yaml_js_1.loadAgentFromYamlFile)(path);
|
|
40
|
+
const skills = "skills" in agent
|
|
41
|
+
? agent.skills &&
|
|
42
|
+
(await Promise.all(agent.skills.map((filename) => loadAgent(index_js_1.nodejs.path.join(index_js_1.nodejs.path.dirname(path), filename), options))))
|
|
43
|
+
: undefined;
|
|
37
44
|
if (agent.type === "ai") {
|
|
38
45
|
return ai_agent_js_1.AIAgent.from({
|
|
39
46
|
...agent,
|
|
40
47
|
memory: !options?.memories?.length || !agent.memory
|
|
41
48
|
? undefined
|
|
42
49
|
: await loadMemory(options.memories, typeof agent.memory === "object" ? agent.memory.provider : undefined, typeof agent.memory === "object" ? agent.memory : {}),
|
|
43
|
-
skills
|
|
44
|
-
(await Promise.all(agent.skills.map((filename) => loadAgent(index_js_1.nodejs.path.join(index_js_1.nodejs.path.dirname(path), filename), options)))),
|
|
50
|
+
skills,
|
|
45
51
|
});
|
|
46
52
|
}
|
|
47
53
|
if (agent.type === "mcp") {
|
|
@@ -58,6 +64,12 @@ async function loadAgent(path, options) {
|
|
|
58
64
|
}
|
|
59
65
|
throw new Error(`Missing url or command in mcp agent: ${path}`);
|
|
60
66
|
}
|
|
67
|
+
if (agent.type === "team") {
|
|
68
|
+
return team_agent_js_1.TeamAgent.from({
|
|
69
|
+
...agent,
|
|
70
|
+
skills,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
61
73
|
}
|
|
62
74
|
throw new Error(`Unsupported agent file type: ${path}`);
|
|
63
75
|
}
|
|
@@ -7,7 +7,7 @@ export interface PromptBuilderOptions {
|
|
|
7
7
|
instructions?: string | ChatMessagesTemplate;
|
|
8
8
|
}
|
|
9
9
|
export interface PromptBuildOptions extends Pick<AgentInvokeOptions, "context"> {
|
|
10
|
-
agent?: AIAgent
|
|
10
|
+
agent?: AIAgent;
|
|
11
11
|
input?: Message;
|
|
12
12
|
model?: ChatModel;
|
|
13
13
|
outputSchema?: Agent["outputSchema"];
|
|
@@ -341,7 +341,7 @@ export declare abstract class Agent<I extends Message = Message, O extends Messa
|
|
|
341
341
|
* Here's an example of invoking an agent with regular mode:
|
|
342
342
|
* {@includeCode ../../test/agents/agent.test.ts#example-invoke}
|
|
343
343
|
*/
|
|
344
|
-
invoke(input: I, options?: Partial<AgentInvokeOptions> & {
|
|
344
|
+
invoke(input: I & Message, options?: Partial<AgentInvokeOptions> & {
|
|
345
345
|
streaming?: false;
|
|
346
346
|
}): Promise<O>;
|
|
347
347
|
/**
|
|
@@ -359,7 +359,7 @@ export declare abstract class Agent<I extends Message = Message, O extends Messa
|
|
|
359
359
|
* Here's an example of invoking an agent with streaming response:
|
|
360
360
|
* {@includeCode ../../test/agents/agent.test.ts#example-invoke-streaming}
|
|
361
361
|
*/
|
|
362
|
-
invoke(input: I, options: Partial<AgentInvokeOptions> & {
|
|
362
|
+
invoke(input: I & Message, options: Partial<AgentInvokeOptions> & {
|
|
363
363
|
streaming: true;
|
|
364
364
|
}): Promise<AgentResponseStream<O>>;
|
|
365
365
|
/**
|
|
@@ -371,8 +371,8 @@ export declare abstract class Agent<I extends Message = Message, O extends Messa
|
|
|
371
371
|
* @param options Invocation options
|
|
372
372
|
* @returns Agent response (streaming or regular)
|
|
373
373
|
*/
|
|
374
|
-
invoke(input: I, options?: Partial<AgentInvokeOptions>): Promise<AgentResponse<O>>;
|
|
375
|
-
protected invokeSkill<I extends Message, O extends Message>(skill: Agent<I, O>, input: I, options: AgentInvokeOptions): Promise<O>;
|
|
374
|
+
invoke(input: I & Message, options?: Partial<AgentInvokeOptions>): Promise<AgentResponse<O>>;
|
|
375
|
+
protected invokeSkill<I extends Message, O extends Message>(skill: Agent<I, O>, input: I & Message, options: AgentInvokeOptions): Promise<O>;
|
|
376
376
|
/**
|
|
377
377
|
* Process agent output
|
|
378
378
|
*
|
|
@@ -3,6 +3,7 @@ import { PromptBuilder } from "../prompt/prompt-builder.js";
|
|
|
3
3
|
import { Agent, type AgentInvokeOptions, type AgentOptions, type AgentProcessAsyncGenerator, type Message } from "./agent.js";
|
|
4
4
|
import { ChatModel, type ChatModelInput } from "./chat-model.js";
|
|
5
5
|
import type { GuideRailAgentOutput } from "./guide-rail-agent.js";
|
|
6
|
+
export declare const DEFAULT_OUTPUT_KEY = "message";
|
|
6
7
|
/**
|
|
7
8
|
* Configuration options for an AI Agent
|
|
8
9
|
*
|
|
@@ -12,7 +13,7 @@ import type { GuideRailAgentOutput } from "./guide-rail-agent.js";
|
|
|
12
13
|
* @template I The input message type the agent accepts
|
|
13
14
|
* @template O The output message type the agent returns
|
|
14
15
|
*/
|
|
15
|
-
export interface AIAgentOptions<
|
|
16
|
+
export interface AIAgentOptions<I extends Message = Message, O extends Message = Message> extends AgentOptions<I, O> {
|
|
16
17
|
/**
|
|
17
18
|
* The language model to use for this agent
|
|
18
19
|
*
|
|
@@ -29,7 +30,7 @@ export interface AIAgentOptions<InputKey extends string = string, I extends Mess
|
|
|
29
30
|
/**
|
|
30
31
|
* Pick a message from input to use as the user's message
|
|
31
32
|
*/
|
|
32
|
-
inputKey?:
|
|
33
|
+
inputKey?: string;
|
|
33
34
|
/**
|
|
34
35
|
* Custom key to use for text output in the response
|
|
35
36
|
*
|
|
@@ -110,9 +111,6 @@ export declare const aiAgentToolChoiceSchema: z.ZodUnion<[z.ZodNativeEnum<typeof
|
|
|
110
111
|
export declare const aiAgentOptionsSchema: ZodObject<{
|
|
111
112
|
[key in keyof AIAgentOptions]: ZodType<AIAgentOptions[key]>;
|
|
112
113
|
}>;
|
|
113
|
-
type InputMessage<K> = K extends string ? {
|
|
114
|
-
[key in K]: string;
|
|
115
|
-
} : Message;
|
|
116
114
|
/**
|
|
117
115
|
* AI-powered agent that leverages language models
|
|
118
116
|
*
|
|
@@ -133,7 +131,7 @@ type InputMessage<K> = K extends string ? {
|
|
|
133
131
|
* Basic AIAgent creation:
|
|
134
132
|
* {@includeCode ../../test/agents/ai-agent.test.ts#example-ai-agent-basic}
|
|
135
133
|
*/
|
|
136
|
-
export declare class AIAgent<
|
|
134
|
+
export declare class AIAgent<I extends Message = Message, O extends Message = Message> extends Agent<I, O> {
|
|
137
135
|
/**
|
|
138
136
|
* Create an AIAgent with the specified options
|
|
139
137
|
*
|
|
@@ -146,13 +144,13 @@ export declare class AIAgent<InputKey extends string = string, I extends Message
|
|
|
146
144
|
* AI agent with custom instructions:
|
|
147
145
|
* {@includeCode ../../test/agents/ai-agent.test.ts#example-ai-agent-instructions}
|
|
148
146
|
*/
|
|
149
|
-
static from<
|
|
147
|
+
static from<I extends Message, O extends Message>(options: AIAgentOptions<I, O>): AIAgent<I, O>;
|
|
150
148
|
/**
|
|
151
149
|
* Create an AIAgent instance
|
|
152
150
|
*
|
|
153
151
|
* @param options Configuration options for the AI agent
|
|
154
152
|
*/
|
|
155
|
-
constructor(options: AIAgentOptions<
|
|
153
|
+
constructor(options: AIAgentOptions<I, O>);
|
|
156
154
|
/**
|
|
157
155
|
* The language model used by this agent
|
|
158
156
|
*
|
|
@@ -173,7 +171,7 @@ export declare class AIAgent<InputKey extends string = string, I extends Message
|
|
|
173
171
|
/**
|
|
174
172
|
* Pick a message from input to use as the user's message
|
|
175
173
|
*/
|
|
176
|
-
inputKey?:
|
|
174
|
+
inputKey?: string;
|
|
177
175
|
/**
|
|
178
176
|
* Custom key to use for text output in the response
|
|
179
177
|
*
|
|
@@ -235,4 +233,3 @@ export declare class AIAgent<InputKey extends string = string, I extends Message
|
|
|
235
233
|
*/
|
|
236
234
|
_processRouter(input: I, model: ChatModel, modelInput: ChatModelInput, options: AgentInvokeOptions, toolsMap: Map<string, Agent>): AgentProcessAsyncGenerator<O>;
|
|
237
235
|
}
|
|
238
|
-
export {};
|
package/lib/dts/aigne/aigne.d.ts
CHANGED
|
@@ -134,7 +134,7 @@ export declare class AIGNE<U extends UserContext = UserContext> {
|
|
|
134
134
|
* @param options.streaming - Must be false to return a response stream
|
|
135
135
|
* @returns A promise resolving to a tuple containing the agent's response and the final active agent
|
|
136
136
|
*/
|
|
137
|
-
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I, options: InvokeOptions<U> & {
|
|
137
|
+
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I & Message, options: InvokeOptions<U> & {
|
|
138
138
|
returnActiveAgent: true;
|
|
139
139
|
streaming?: false;
|
|
140
140
|
}): Promise<[O, Agent]>;
|
|
@@ -148,7 +148,7 @@ export declare class AIGNE<U extends UserContext = UserContext> {
|
|
|
148
148
|
* @param options.streaming - Must be true to return a response stream
|
|
149
149
|
* @returns A promise resolving to a tuple containing the agent's response stream and a promise for the final agent
|
|
150
150
|
*/
|
|
151
|
-
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I, options: InvokeOptions<U> & {
|
|
151
|
+
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I & Message, options: InvokeOptions<U> & {
|
|
152
152
|
returnActiveAgent: true;
|
|
153
153
|
streaming: true;
|
|
154
154
|
}): Promise<[AgentResponseStream<O>, Promise<Agent>]>;
|
|
@@ -165,7 +165,7 @@ export declare class AIGNE<U extends UserContext = UserContext> {
|
|
|
165
165
|
* Here's a simple example of how to invoke an agent:
|
|
166
166
|
* {@includeCode ../../test/aigne/aigne.test.ts#example-simple}
|
|
167
167
|
*/
|
|
168
|
-
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I, options?: InvokeOptions<U> & {
|
|
168
|
+
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I & Message, options?: InvokeOptions<U> & {
|
|
169
169
|
returnActiveAgent?: false;
|
|
170
170
|
streaming?: false;
|
|
171
171
|
}): Promise<O>;
|
|
@@ -182,7 +182,7 @@ export declare class AIGNE<U extends UserContext = UserContext> {
|
|
|
182
182
|
* Here's an example of how to invoke an agent with streaming response:
|
|
183
183
|
* {@includeCode ../../test/aigne/aigne.test.ts#example-streaming}
|
|
184
184
|
*/
|
|
185
|
-
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I, options: InvokeOptions<U> & {
|
|
185
|
+
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I & Message, options: InvokeOptions<U> & {
|
|
186
186
|
returnActiveAgent?: false;
|
|
187
187
|
streaming: true;
|
|
188
188
|
}): Promise<AgentResponseStream<O>>;
|
|
@@ -196,7 +196,7 @@ export declare class AIGNE<U extends UserContext = UserContext> {
|
|
|
196
196
|
* @returns Either a UserAgent (when no message provided) or a promise resolving to the agent's response
|
|
197
197
|
* with optional active agent information based on the provided options
|
|
198
198
|
*/
|
|
199
|
-
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message?: I, options?: InvokeOptions<U>): UserAgent<I, O> | Promise<AgentResponse<O> | [AgentResponse<O>, Agent]>;
|
|
199
|
+
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message?: I & Message, options?: InvokeOptions<U>): UserAgent<I, O> | Promise<AgentResponse<O> | [AgentResponse<O>, Agent]>;
|
|
200
200
|
/**
|
|
201
201
|
* Publishes a message to the message queue for inter-agent communication.
|
|
202
202
|
* This method broadcasts a message to all subscribers of the specified topic(s).
|
|
@@ -78,11 +78,11 @@ export interface Context<U extends UserContext = UserContext> extends TypedEvent
|
|
|
78
78
|
* @param options.streaming return a stream of the output
|
|
79
79
|
* @returns the output of the agent and the final active agent
|
|
80
80
|
*/
|
|
81
|
-
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I, options: InvokeOptions & {
|
|
81
|
+
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I & Message, options: InvokeOptions & {
|
|
82
82
|
returnActiveAgent: true;
|
|
83
83
|
streaming?: false;
|
|
84
84
|
}): Promise<[O, Agent]>;
|
|
85
|
-
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I, options: InvokeOptions & {
|
|
85
|
+
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I & Message, options: InvokeOptions & {
|
|
86
86
|
returnActiveAgent: true;
|
|
87
87
|
streaming: true;
|
|
88
88
|
}): Promise<[AgentResponseStream<O>, Promise<Agent>]>;
|
|
@@ -92,13 +92,13 @@ export interface Context<U extends UserContext = UserContext> extends TypedEvent
|
|
|
92
92
|
* @param message Message to pass to the agent
|
|
93
93
|
* @returns the output of the agent
|
|
94
94
|
*/
|
|
95
|
-
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I, options?: InvokeOptions & {
|
|
95
|
+
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I & Message, options?: InvokeOptions & {
|
|
96
96
|
streaming?: false;
|
|
97
97
|
}): Promise<O>;
|
|
98
|
-
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I, options: InvokeOptions & {
|
|
98
|
+
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I & Message, options: InvokeOptions & {
|
|
99
99
|
streaming: true;
|
|
100
100
|
}): Promise<AgentResponseStream<O>>;
|
|
101
|
-
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message?: I, options?: InvokeOptions): UserAgent<I, O> | Promise<AgentResponse<O> | [AgentResponse<O>, Agent]>;
|
|
101
|
+
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message?: I & Message, options?: InvokeOptions): UserAgent<I, O> | Promise<AgentResponse<O> | [AgentResponse<O>, Agent]>;
|
|
102
102
|
/**
|
|
103
103
|
* Publish a message to a topic, the aigne will invoke the listeners of the topic
|
|
104
104
|
* @param topic topic name, or an array of topic names
|
|
@@ -169,7 +169,7 @@ declare class AIGNEContextShared {
|
|
|
169
169
|
private timer?;
|
|
170
170
|
private initTimeout;
|
|
171
171
|
get status(): "normal" | "timeout";
|
|
172
|
-
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, input: I, context: Context, options?: InvokeOptions): AgentProcessAsyncGenerator<O & {
|
|
172
|
+
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, input: I & Message, context: Context, options?: InvokeOptions): AgentProcessAsyncGenerator<O & {
|
|
173
173
|
__activeAgent__: Agent;
|
|
174
174
|
}>;
|
|
175
175
|
private invokeAgent;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type ZodObject, type ZodType, z } from "zod";
|
|
2
|
-
import type
|
|
3
|
-
export declare function loadAgentFromJsFile(path: string): Promise<{
|
|
2
|
+
import { Agent, type Message } from "../agents/agent.js";
|
|
3
|
+
export declare function loadAgentFromJsFile(path: string): Promise<Agent<any, any> | {
|
|
4
4
|
process: (args_0: Message) => Message;
|
|
5
5
|
name: string;
|
|
6
6
|
description?: string | undefined;
|
|
@@ -1,6 +1,29 @@
|
|
|
1
1
|
import { type ZodObject, type ZodType, z } from "zod";
|
|
2
2
|
import { AIAgentToolChoice } from "../agents/ai-agent.js";
|
|
3
|
+
import { ProcessMode } from "../agents/team-agent.js";
|
|
3
4
|
export declare function loadAgentFromYamlFile(path: string): Promise<{
|
|
5
|
+
type: "mcp";
|
|
6
|
+
url?: string | undefined;
|
|
7
|
+
args?: string[] | undefined;
|
|
8
|
+
command?: string | undefined;
|
|
9
|
+
} | {
|
|
10
|
+
type: "team";
|
|
11
|
+
name: string;
|
|
12
|
+
description?: string | undefined;
|
|
13
|
+
skills?: string[] | undefined;
|
|
14
|
+
mode?: ProcessMode | undefined;
|
|
15
|
+
inputSchema?: ZodObject<Record<string, ZodType<any, z.ZodTypeDef, any>>, z.UnknownKeysParam, z.ZodTypeAny, {
|
|
16
|
+
[x: string]: any;
|
|
17
|
+
}, {
|
|
18
|
+
[x: string]: any;
|
|
19
|
+
}> | undefined;
|
|
20
|
+
outputSchema?: ZodObject<Record<string, ZodType<any, z.ZodTypeDef, any>>, z.UnknownKeysParam, z.ZodTypeAny, {
|
|
21
|
+
[x: string]: any;
|
|
22
|
+
}, {
|
|
23
|
+
[x: string]: any;
|
|
24
|
+
}> | undefined;
|
|
25
|
+
} | {
|
|
26
|
+
instructions: string | undefined;
|
|
4
27
|
type: "ai";
|
|
5
28
|
name: string;
|
|
6
29
|
description?: string | undefined;
|
|
@@ -9,7 +32,6 @@ export declare function loadAgentFromYamlFile(path: string): Promise<{
|
|
|
9
32
|
provider: string;
|
|
10
33
|
subscribeTopic?: string[] | undefined;
|
|
11
34
|
} | undefined;
|
|
12
|
-
instructions?: string | undefined;
|
|
13
35
|
inputSchema?: ZodObject<Record<string, ZodType<any, z.ZodTypeDef, any>>, z.UnknownKeysParam, z.ZodTypeAny, {
|
|
14
36
|
[x: string]: any;
|
|
15
37
|
}, {
|
|
@@ -23,9 +45,4 @@ export declare function loadAgentFromYamlFile(path: string): Promise<{
|
|
|
23
45
|
inputKey?: string | undefined;
|
|
24
46
|
outputKey?: string | undefined;
|
|
25
47
|
toolChoice?: AIAgentToolChoice | undefined;
|
|
26
|
-
} | {
|
|
27
|
-
type: "mcp";
|
|
28
|
-
url?: string | undefined;
|
|
29
|
-
args?: string[] | undefined;
|
|
30
|
-
command?: string | undefined;
|
|
31
48
|
}>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Camelize } from "camelize-ts";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
-
import {
|
|
3
|
+
import { Agent } from "../agents/agent.js";
|
|
4
4
|
import type { ChatModel, ChatModelOptions } from "../agents/chat-model.js";
|
|
5
5
|
import type { MemoryAgent, MemoryAgentOptions } from "../memory/memory.js";
|
|
6
6
|
export interface LoadOptions {
|
|
@@ -7,7 +7,7 @@ export interface PromptBuilderOptions {
|
|
|
7
7
|
instructions?: string | ChatMessagesTemplate;
|
|
8
8
|
}
|
|
9
9
|
export interface PromptBuildOptions extends Pick<AgentInvokeOptions, "context"> {
|
|
10
|
-
agent?: AIAgent
|
|
10
|
+
agent?: AIAgent;
|
|
11
11
|
input?: Message;
|
|
12
12
|
model?: ChatModel;
|
|
13
13
|
outputSchema?: Agent["outputSchema"];
|
|
@@ -341,7 +341,7 @@ export declare abstract class Agent<I extends Message = Message, O extends Messa
|
|
|
341
341
|
* Here's an example of invoking an agent with regular mode:
|
|
342
342
|
* {@includeCode ../../test/agents/agent.test.ts#example-invoke}
|
|
343
343
|
*/
|
|
344
|
-
invoke(input: I, options?: Partial<AgentInvokeOptions> & {
|
|
344
|
+
invoke(input: I & Message, options?: Partial<AgentInvokeOptions> & {
|
|
345
345
|
streaming?: false;
|
|
346
346
|
}): Promise<O>;
|
|
347
347
|
/**
|
|
@@ -359,7 +359,7 @@ export declare abstract class Agent<I extends Message = Message, O extends Messa
|
|
|
359
359
|
* Here's an example of invoking an agent with streaming response:
|
|
360
360
|
* {@includeCode ../../test/agents/agent.test.ts#example-invoke-streaming}
|
|
361
361
|
*/
|
|
362
|
-
invoke(input: I, options: Partial<AgentInvokeOptions> & {
|
|
362
|
+
invoke(input: I & Message, options: Partial<AgentInvokeOptions> & {
|
|
363
363
|
streaming: true;
|
|
364
364
|
}): Promise<AgentResponseStream<O>>;
|
|
365
365
|
/**
|
|
@@ -371,8 +371,8 @@ export declare abstract class Agent<I extends Message = Message, O extends Messa
|
|
|
371
371
|
* @param options Invocation options
|
|
372
372
|
* @returns Agent response (streaming or regular)
|
|
373
373
|
*/
|
|
374
|
-
invoke(input: I, options?: Partial<AgentInvokeOptions>): Promise<AgentResponse<O>>;
|
|
375
|
-
protected invokeSkill<I extends Message, O extends Message>(skill: Agent<I, O>, input: I, options: AgentInvokeOptions): Promise<O>;
|
|
374
|
+
invoke(input: I & Message, options?: Partial<AgentInvokeOptions>): Promise<AgentResponse<O>>;
|
|
375
|
+
protected invokeSkill<I extends Message, O extends Message>(skill: Agent<I, O>, input: I & Message, options: AgentInvokeOptions): Promise<O>;
|
|
376
376
|
/**
|
|
377
377
|
* Process agent output
|
|
378
378
|
*
|
|
@@ -3,6 +3,7 @@ import { PromptBuilder } from "../prompt/prompt-builder.js";
|
|
|
3
3
|
import { Agent, type AgentInvokeOptions, type AgentOptions, type AgentProcessAsyncGenerator, type Message } from "./agent.js";
|
|
4
4
|
import { ChatModel, type ChatModelInput } from "./chat-model.js";
|
|
5
5
|
import type { GuideRailAgentOutput } from "./guide-rail-agent.js";
|
|
6
|
+
export declare const DEFAULT_OUTPUT_KEY = "message";
|
|
6
7
|
/**
|
|
7
8
|
* Configuration options for an AI Agent
|
|
8
9
|
*
|
|
@@ -12,7 +13,7 @@ import type { GuideRailAgentOutput } from "./guide-rail-agent.js";
|
|
|
12
13
|
* @template I The input message type the agent accepts
|
|
13
14
|
* @template O The output message type the agent returns
|
|
14
15
|
*/
|
|
15
|
-
export interface AIAgentOptions<
|
|
16
|
+
export interface AIAgentOptions<I extends Message = Message, O extends Message = Message> extends AgentOptions<I, O> {
|
|
16
17
|
/**
|
|
17
18
|
* The language model to use for this agent
|
|
18
19
|
*
|
|
@@ -29,7 +30,7 @@ export interface AIAgentOptions<InputKey extends string = string, I extends Mess
|
|
|
29
30
|
/**
|
|
30
31
|
* Pick a message from input to use as the user's message
|
|
31
32
|
*/
|
|
32
|
-
inputKey?:
|
|
33
|
+
inputKey?: string;
|
|
33
34
|
/**
|
|
34
35
|
* Custom key to use for text output in the response
|
|
35
36
|
*
|
|
@@ -110,9 +111,6 @@ export declare const aiAgentToolChoiceSchema: z.ZodUnion<[z.ZodNativeEnum<typeof
|
|
|
110
111
|
export declare const aiAgentOptionsSchema: ZodObject<{
|
|
111
112
|
[key in keyof AIAgentOptions]: ZodType<AIAgentOptions[key]>;
|
|
112
113
|
}>;
|
|
113
|
-
type InputMessage<K> = K extends string ? {
|
|
114
|
-
[key in K]: string;
|
|
115
|
-
} : Message;
|
|
116
114
|
/**
|
|
117
115
|
* AI-powered agent that leverages language models
|
|
118
116
|
*
|
|
@@ -133,7 +131,7 @@ type InputMessage<K> = K extends string ? {
|
|
|
133
131
|
* Basic AIAgent creation:
|
|
134
132
|
* {@includeCode ../../test/agents/ai-agent.test.ts#example-ai-agent-basic}
|
|
135
133
|
*/
|
|
136
|
-
export declare class AIAgent<
|
|
134
|
+
export declare class AIAgent<I extends Message = Message, O extends Message = Message> extends Agent<I, O> {
|
|
137
135
|
/**
|
|
138
136
|
* Create an AIAgent with the specified options
|
|
139
137
|
*
|
|
@@ -146,13 +144,13 @@ export declare class AIAgent<InputKey extends string = string, I extends Message
|
|
|
146
144
|
* AI agent with custom instructions:
|
|
147
145
|
* {@includeCode ../../test/agents/ai-agent.test.ts#example-ai-agent-instructions}
|
|
148
146
|
*/
|
|
149
|
-
static from<
|
|
147
|
+
static from<I extends Message, O extends Message>(options: AIAgentOptions<I, O>): AIAgent<I, O>;
|
|
150
148
|
/**
|
|
151
149
|
* Create an AIAgent instance
|
|
152
150
|
*
|
|
153
151
|
* @param options Configuration options for the AI agent
|
|
154
152
|
*/
|
|
155
|
-
constructor(options: AIAgentOptions<
|
|
153
|
+
constructor(options: AIAgentOptions<I, O>);
|
|
156
154
|
/**
|
|
157
155
|
* The language model used by this agent
|
|
158
156
|
*
|
|
@@ -173,7 +171,7 @@ export declare class AIAgent<InputKey extends string = string, I extends Message
|
|
|
173
171
|
/**
|
|
174
172
|
* Pick a message from input to use as the user's message
|
|
175
173
|
*/
|
|
176
|
-
inputKey?:
|
|
174
|
+
inputKey?: string;
|
|
177
175
|
/**
|
|
178
176
|
* Custom key to use for text output in the response
|
|
179
177
|
*
|
|
@@ -235,4 +233,3 @@ export declare class AIAgent<InputKey extends string = string, I extends Message
|
|
|
235
233
|
*/
|
|
236
234
|
_processRouter(input: I, model: ChatModel, modelInput: ChatModelInput, options: AgentInvokeOptions, toolsMap: Map<string, Agent>): AgentProcessAsyncGenerator<O>;
|
|
237
235
|
}
|
|
238
|
-
export {};
|
|
@@ -5,7 +5,7 @@ import { checkArguments, isEmpty } from "../utils/type-utils.js";
|
|
|
5
5
|
import { Agent, agentOptionsSchema, isAgentResponseDelta, } from "./agent.js";
|
|
6
6
|
import { ChatModel, } from "./chat-model.js";
|
|
7
7
|
import { isTransferAgentOutput } from "./types.js";
|
|
8
|
-
const DEFAULT_OUTPUT_KEY = "message";
|
|
8
|
+
export const DEFAULT_OUTPUT_KEY = "message";
|
|
9
9
|
/**
|
|
10
10
|
* Tool choice options for AI agents
|
|
11
11
|
*
|
|
@@ -98,7 +98,7 @@ export class AIAgent extends Agent {
|
|
|
98
98
|
* @param options Configuration options for the AI agent
|
|
99
99
|
*/
|
|
100
100
|
constructor(options) {
|
|
101
|
-
super(
|
|
101
|
+
super(options);
|
|
102
102
|
checkArguments("AIAgent", aiAgentOptionsSchema, options);
|
|
103
103
|
this.model = options.model;
|
|
104
104
|
this.instructions =
|
package/lib/esm/aigne/aigne.d.ts
CHANGED
|
@@ -134,7 +134,7 @@ export declare class AIGNE<U extends UserContext = UserContext> {
|
|
|
134
134
|
* @param options.streaming - Must be false to return a response stream
|
|
135
135
|
* @returns A promise resolving to a tuple containing the agent's response and the final active agent
|
|
136
136
|
*/
|
|
137
|
-
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I, options: InvokeOptions<U> & {
|
|
137
|
+
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I & Message, options: InvokeOptions<U> & {
|
|
138
138
|
returnActiveAgent: true;
|
|
139
139
|
streaming?: false;
|
|
140
140
|
}): Promise<[O, Agent]>;
|
|
@@ -148,7 +148,7 @@ export declare class AIGNE<U extends UserContext = UserContext> {
|
|
|
148
148
|
* @param options.streaming - Must be true to return a response stream
|
|
149
149
|
* @returns A promise resolving to a tuple containing the agent's response stream and a promise for the final agent
|
|
150
150
|
*/
|
|
151
|
-
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I, options: InvokeOptions<U> & {
|
|
151
|
+
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I & Message, options: InvokeOptions<U> & {
|
|
152
152
|
returnActiveAgent: true;
|
|
153
153
|
streaming: true;
|
|
154
154
|
}): Promise<[AgentResponseStream<O>, Promise<Agent>]>;
|
|
@@ -165,7 +165,7 @@ export declare class AIGNE<U extends UserContext = UserContext> {
|
|
|
165
165
|
* Here's a simple example of how to invoke an agent:
|
|
166
166
|
* {@includeCode ../../test/aigne/aigne.test.ts#example-simple}
|
|
167
167
|
*/
|
|
168
|
-
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I, options?: InvokeOptions<U> & {
|
|
168
|
+
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I & Message, options?: InvokeOptions<U> & {
|
|
169
169
|
returnActiveAgent?: false;
|
|
170
170
|
streaming?: false;
|
|
171
171
|
}): Promise<O>;
|
|
@@ -182,7 +182,7 @@ export declare class AIGNE<U extends UserContext = UserContext> {
|
|
|
182
182
|
* Here's an example of how to invoke an agent with streaming response:
|
|
183
183
|
* {@includeCode ../../test/aigne/aigne.test.ts#example-streaming}
|
|
184
184
|
*/
|
|
185
|
-
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I, options: InvokeOptions<U> & {
|
|
185
|
+
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I & Message, options: InvokeOptions<U> & {
|
|
186
186
|
returnActiveAgent?: false;
|
|
187
187
|
streaming: true;
|
|
188
188
|
}): Promise<AgentResponseStream<O>>;
|
|
@@ -196,7 +196,7 @@ export declare class AIGNE<U extends UserContext = UserContext> {
|
|
|
196
196
|
* @returns Either a UserAgent (when no message provided) or a promise resolving to the agent's response
|
|
197
197
|
* with optional active agent information based on the provided options
|
|
198
198
|
*/
|
|
199
|
-
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message?: I, options?: InvokeOptions<U>): UserAgent<I, O> | Promise<AgentResponse<O> | [AgentResponse<O>, Agent]>;
|
|
199
|
+
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message?: I & Message, options?: InvokeOptions<U>): UserAgent<I, O> | Promise<AgentResponse<O> | [AgentResponse<O>, Agent]>;
|
|
200
200
|
/**
|
|
201
201
|
* Publishes a message to the message queue for inter-agent communication.
|
|
202
202
|
* This method broadcasts a message to all subscribers of the specified topic(s).
|
|
@@ -78,11 +78,11 @@ export interface Context<U extends UserContext = UserContext> extends TypedEvent
|
|
|
78
78
|
* @param options.streaming return a stream of the output
|
|
79
79
|
* @returns the output of the agent and the final active agent
|
|
80
80
|
*/
|
|
81
|
-
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I, options: InvokeOptions & {
|
|
81
|
+
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I & Message, options: InvokeOptions & {
|
|
82
82
|
returnActiveAgent: true;
|
|
83
83
|
streaming?: false;
|
|
84
84
|
}): Promise<[O, Agent]>;
|
|
85
|
-
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I, options: InvokeOptions & {
|
|
85
|
+
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I & Message, options: InvokeOptions & {
|
|
86
86
|
returnActiveAgent: true;
|
|
87
87
|
streaming: true;
|
|
88
88
|
}): Promise<[AgentResponseStream<O>, Promise<Agent>]>;
|
|
@@ -92,13 +92,13 @@ export interface Context<U extends UserContext = UserContext> extends TypedEvent
|
|
|
92
92
|
* @param message Message to pass to the agent
|
|
93
93
|
* @returns the output of the agent
|
|
94
94
|
*/
|
|
95
|
-
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I, options?: InvokeOptions & {
|
|
95
|
+
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I & Message, options?: InvokeOptions & {
|
|
96
96
|
streaming?: false;
|
|
97
97
|
}): Promise<O>;
|
|
98
|
-
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I, options: InvokeOptions & {
|
|
98
|
+
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I & Message, options: InvokeOptions & {
|
|
99
99
|
streaming: true;
|
|
100
100
|
}): Promise<AgentResponseStream<O>>;
|
|
101
|
-
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message?: I, options?: InvokeOptions): UserAgent<I, O> | Promise<AgentResponse<O> | [AgentResponse<O>, Agent]>;
|
|
101
|
+
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message?: I & Message, options?: InvokeOptions): UserAgent<I, O> | Promise<AgentResponse<O> | [AgentResponse<O>, Agent]>;
|
|
102
102
|
/**
|
|
103
103
|
* Publish a message to a topic, the aigne will invoke the listeners of the topic
|
|
104
104
|
* @param topic topic name, or an array of topic names
|
|
@@ -169,7 +169,7 @@ declare class AIGNEContextShared {
|
|
|
169
169
|
private timer?;
|
|
170
170
|
private initTimeout;
|
|
171
171
|
get status(): "normal" | "timeout";
|
|
172
|
-
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, input: I, context: Context, options?: InvokeOptions): AgentProcessAsyncGenerator<O & {
|
|
172
|
+
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, input: I & Message, context: Context, options?: InvokeOptions): AgentProcessAsyncGenerator<O & {
|
|
173
173
|
__activeAgent__: Agent;
|
|
174
174
|
}>;
|
|
175
175
|
private invokeAgent;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type ZodObject, type ZodType, z } from "zod";
|
|
2
|
-
import type
|
|
3
|
-
export declare function loadAgentFromJsFile(path: string): Promise<{
|
|
2
|
+
import { Agent, type Message } from "../agents/agent.js";
|
|
3
|
+
export declare function loadAgentFromJsFile(path: string): Promise<Agent<any, any> | {
|
|
4
4
|
process: (args_0: Message) => Message;
|
|
5
5
|
name: string;
|
|
6
6
|
description?: string | undefined;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { jsonSchemaToZod } from "@aigne/json-schema-to-zod";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
+
import { Agent } from "../agents/agent.js";
|
|
3
4
|
import { customCamelize } from "../utils/camelize.js";
|
|
4
5
|
import { tryOrThrow } from "../utils/type-utils.js";
|
|
5
6
|
import { inputOutputSchema } from "./schema.js";
|
|
@@ -19,6 +20,8 @@ const agentJsFileSchema = z.object({
|
|
|
19
20
|
});
|
|
20
21
|
export async function loadAgentFromJsFile(path) {
|
|
21
22
|
const { default: agent } = await tryOrThrow(() => import(path), (error) => new Error(`Failed to load agent definition from ${path}: ${error.message}`));
|
|
23
|
+
if (agent instanceof Agent)
|
|
24
|
+
return agent;
|
|
22
25
|
if (typeof agent !== "function") {
|
|
23
26
|
throw new Error(`Agent file ${path} must export a default function, but got ${typeof agent}`);
|
|
24
27
|
}
|
|
@@ -1,6 +1,29 @@
|
|
|
1
1
|
import { type ZodObject, type ZodType, z } from "zod";
|
|
2
2
|
import { AIAgentToolChoice } from "../agents/ai-agent.js";
|
|
3
|
+
import { ProcessMode } from "../agents/team-agent.js";
|
|
3
4
|
export declare function loadAgentFromYamlFile(path: string): Promise<{
|
|
5
|
+
type: "mcp";
|
|
6
|
+
url?: string | undefined;
|
|
7
|
+
args?: string[] | undefined;
|
|
8
|
+
command?: string | undefined;
|
|
9
|
+
} | {
|
|
10
|
+
type: "team";
|
|
11
|
+
name: string;
|
|
12
|
+
description?: string | undefined;
|
|
13
|
+
skills?: string[] | undefined;
|
|
14
|
+
mode?: ProcessMode | undefined;
|
|
15
|
+
inputSchema?: ZodObject<Record<string, ZodType<any, z.ZodTypeDef, any>>, z.UnknownKeysParam, z.ZodTypeAny, {
|
|
16
|
+
[x: string]: any;
|
|
17
|
+
}, {
|
|
18
|
+
[x: string]: any;
|
|
19
|
+
}> | undefined;
|
|
20
|
+
outputSchema?: ZodObject<Record<string, ZodType<any, z.ZodTypeDef, any>>, z.UnknownKeysParam, z.ZodTypeAny, {
|
|
21
|
+
[x: string]: any;
|
|
22
|
+
}, {
|
|
23
|
+
[x: string]: any;
|
|
24
|
+
}> | undefined;
|
|
25
|
+
} | {
|
|
26
|
+
instructions: string | undefined;
|
|
4
27
|
type: "ai";
|
|
5
28
|
name: string;
|
|
6
29
|
description?: string | undefined;
|
|
@@ -9,7 +32,6 @@ export declare function loadAgentFromYamlFile(path: string): Promise<{
|
|
|
9
32
|
provider: string;
|
|
10
33
|
subscribeTopic?: string[] | undefined;
|
|
11
34
|
} | undefined;
|
|
12
|
-
instructions?: string | undefined;
|
|
13
35
|
inputSchema?: ZodObject<Record<string, ZodType<any, z.ZodTypeDef, any>>, z.UnknownKeysParam, z.ZodTypeAny, {
|
|
14
36
|
[x: string]: any;
|
|
15
37
|
}, {
|
|
@@ -23,9 +45,4 @@ export declare function loadAgentFromYamlFile(path: string): Promise<{
|
|
|
23
45
|
inputKey?: string | undefined;
|
|
24
46
|
outputKey?: string | undefined;
|
|
25
47
|
toolChoice?: AIAgentToolChoice | undefined;
|
|
26
|
-
} | {
|
|
27
|
-
type: "mcp";
|
|
28
|
-
url?: string | undefined;
|
|
29
|
-
args?: string[] | undefined;
|
|
30
|
-
command?: string | undefined;
|
|
31
48
|
}>;
|
|
@@ -3,6 +3,7 @@ import { nodejs } from "@aigne/platform-helpers/nodejs/index.js";
|
|
|
3
3
|
import { parse } from "yaml";
|
|
4
4
|
import { z } from "zod";
|
|
5
5
|
import { AIAgentToolChoice } from "../agents/ai-agent.js";
|
|
6
|
+
import { ProcessMode } from "../agents/team-agent.js";
|
|
6
7
|
import { customCamelize } from "../utils/camelize.js";
|
|
7
8
|
import { tryOrThrow } from "../utils/type-utils.js";
|
|
8
9
|
import { inputOutputSchema } from "./schema.js";
|
|
@@ -15,7 +16,12 @@ const agentFileSchema = z.discriminatedUnion("type", [
|
|
|
15
16
|
.nullish()
|
|
16
17
|
.transform((v) => v ?? undefined),
|
|
17
18
|
instructions: z
|
|
18
|
-
.
|
|
19
|
+
.union([
|
|
20
|
+
z.string(),
|
|
21
|
+
z.object({
|
|
22
|
+
url: z.string(),
|
|
23
|
+
}),
|
|
24
|
+
])
|
|
19
25
|
.nullish()
|
|
20
26
|
.transform((v) => v ?? undefined),
|
|
21
27
|
input_key: z
|
|
@@ -69,16 +75,46 @@ const agentFileSchema = z.discriminatedUnion("type", [
|
|
|
69
75
|
.nullish()
|
|
70
76
|
.transform((v) => v ?? undefined),
|
|
71
77
|
}),
|
|
78
|
+
z.object({
|
|
79
|
+
type: z.literal("team"),
|
|
80
|
+
name: z.string(),
|
|
81
|
+
description: z
|
|
82
|
+
.string()
|
|
83
|
+
.nullish()
|
|
84
|
+
.transform((v) => v ?? undefined),
|
|
85
|
+
input_schema: inputOutputSchema
|
|
86
|
+
.nullish()
|
|
87
|
+
.transform((v) => (v ? jsonSchemaToZod(v) : undefined)),
|
|
88
|
+
output_schema: inputOutputSchema
|
|
89
|
+
.nullish()
|
|
90
|
+
.transform((v) => (v ? jsonSchemaToZod(v) : undefined)),
|
|
91
|
+
skills: z
|
|
92
|
+
.array(z.string())
|
|
93
|
+
.nullish()
|
|
94
|
+
.transform((v) => v ?? undefined),
|
|
95
|
+
mode: z
|
|
96
|
+
.nativeEnum(ProcessMode)
|
|
97
|
+
.nullish()
|
|
98
|
+
.transform((v) => v ?? undefined),
|
|
99
|
+
}),
|
|
72
100
|
]);
|
|
73
101
|
export async function loadAgentFromYamlFile(path) {
|
|
74
102
|
const raw = await tryOrThrow(() => nodejs.fs.readFile(path, "utf8"), (error) => new Error(`Failed to load agent definition from ${path}: ${error.message}`));
|
|
75
103
|
const json = await tryOrThrow(() => parse(raw), (error) => new Error(`Failed to parse agent definition from ${path}: ${error.message}`));
|
|
76
|
-
const agent = tryOrThrow(() => customCamelize(agentFileSchema.
|
|
104
|
+
const agent = await tryOrThrow(async () => customCamelize(await agentFileSchema.parseAsync({
|
|
77
105
|
...json,
|
|
78
106
|
type: json.type ?? "ai",
|
|
79
107
|
skills: json.skills ?? json.tools,
|
|
80
108
|
}), {
|
|
81
109
|
shallowKeys: ["input_schema", "output_schema"],
|
|
82
110
|
}), (error) => new Error(`Failed to validate agent definition from ${path}: ${error.message}`));
|
|
111
|
+
if (agent.type === "ai") {
|
|
112
|
+
return {
|
|
113
|
+
...agent,
|
|
114
|
+
instructions: typeof agent.instructions === "object" && "url" in agent.instructions
|
|
115
|
+
? await nodejs.fs.readFile(nodejs.path.join(nodejs.path.dirname(path), agent.instructions.url), "utf8")
|
|
116
|
+
: agent.instructions,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
83
119
|
return agent;
|
|
84
120
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Camelize } from "camelize-ts";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
-
import {
|
|
3
|
+
import { Agent } from "../agents/agent.js";
|
|
4
4
|
import type { ChatModel, ChatModelOptions } from "../agents/chat-model.js";
|
|
5
5
|
import type { MemoryAgent, MemoryAgentOptions } from "../memory/memory.js";
|
|
6
6
|
export interface LoadOptions {
|
package/lib/esm/loader/index.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { nodejs } from "@aigne/platform-helpers/nodejs/index.js";
|
|
2
2
|
import { parse } from "yaml";
|
|
3
3
|
import { z } from "zod";
|
|
4
|
-
import { FunctionAgent } from "../agents/agent.js";
|
|
4
|
+
import { Agent, FunctionAgent } from "../agents/agent.js";
|
|
5
5
|
import { AIAgent } from "../agents/ai-agent.js";
|
|
6
6
|
import { MCPAgent } from "../agents/mcp-agent.js";
|
|
7
|
+
import { TeamAgent } from "../agents/team-agent.js";
|
|
7
8
|
import { tryOrThrow } from "../utils/type-utils.js";
|
|
8
9
|
import { loadAgentFromJsFile } from "./agent-js.js";
|
|
9
10
|
import { loadAgentFromYamlFile } from "./agent-yaml.js";
|
|
@@ -22,20 +23,25 @@ export async function load(options) {
|
|
|
22
23
|
};
|
|
23
24
|
}
|
|
24
25
|
export async function loadAgent(path, options) {
|
|
25
|
-
if (nodejs.path.extname(path)
|
|
26
|
+
if ([".js", ".mjs", ".ts", ".mts"].includes(nodejs.path.extname(path))) {
|
|
26
27
|
const agent = await loadAgentFromJsFile(path);
|
|
28
|
+
if (agent instanceof Agent)
|
|
29
|
+
return agent;
|
|
27
30
|
return FunctionAgent.from(agent);
|
|
28
31
|
}
|
|
29
|
-
if (
|
|
32
|
+
if ([".yml", ".yaml"].includes(nodejs.path.extname(path))) {
|
|
30
33
|
const agent = await loadAgentFromYamlFile(path);
|
|
34
|
+
const skills = "skills" in agent
|
|
35
|
+
? agent.skills &&
|
|
36
|
+
(await Promise.all(agent.skills.map((filename) => loadAgent(nodejs.path.join(nodejs.path.dirname(path), filename), options))))
|
|
37
|
+
: undefined;
|
|
31
38
|
if (agent.type === "ai") {
|
|
32
39
|
return AIAgent.from({
|
|
33
40
|
...agent,
|
|
34
41
|
memory: !options?.memories?.length || !agent.memory
|
|
35
42
|
? undefined
|
|
36
43
|
: await loadMemory(options.memories, typeof agent.memory === "object" ? agent.memory.provider : undefined, typeof agent.memory === "object" ? agent.memory : {}),
|
|
37
|
-
skills
|
|
38
|
-
(await Promise.all(agent.skills.map((filename) => loadAgent(nodejs.path.join(nodejs.path.dirname(path), filename), options)))),
|
|
44
|
+
skills,
|
|
39
45
|
});
|
|
40
46
|
}
|
|
41
47
|
if (agent.type === "mcp") {
|
|
@@ -52,6 +58,12 @@ export async function loadAgent(path, options) {
|
|
|
52
58
|
}
|
|
53
59
|
throw new Error(`Missing url or command in mcp agent: ${path}`);
|
|
54
60
|
}
|
|
61
|
+
if (agent.type === "team") {
|
|
62
|
+
return TeamAgent.from({
|
|
63
|
+
...agent,
|
|
64
|
+
skills,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
55
67
|
}
|
|
56
68
|
throw new Error(`Unsupported agent file type: ${path}`);
|
|
57
69
|
}
|
|
@@ -7,7 +7,7 @@ export interface PromptBuilderOptions {
|
|
|
7
7
|
instructions?: string | ChatMessagesTemplate;
|
|
8
8
|
}
|
|
9
9
|
export interface PromptBuildOptions extends Pick<AgentInvokeOptions, "context"> {
|
|
10
|
-
agent?: AIAgent
|
|
10
|
+
agent?: AIAgent;
|
|
11
11
|
input?: Message;
|
|
12
12
|
model?: ChatModel;
|
|
13
13
|
outputSchema?: Agent["outputSchema"];
|