@aigne/core 1.20.1 → 1.22.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 +21 -0
- package/lib/cjs/agents/agent.d.ts +6 -4
- package/lib/cjs/agents/agent.js +2 -0
- package/lib/cjs/agents/ai-agent.d.ts +8 -10
- package/lib/cjs/agents/ai-agent.js +6 -5
- package/lib/cjs/agents/chat-model.d.ts +1 -0
- package/lib/cjs/agents/chat-model.js +1 -0
- package/lib/cjs/agents/mcp-agent.d.ts +5 -0
- package/lib/cjs/agents/mcp-agent.js +5 -0
- package/lib/cjs/agents/team-agent.d.ts +1 -0
- package/lib/cjs/agents/team-agent.js +1 -0
- package/lib/cjs/agents/user-agent.d.ts +1 -0
- package/lib/cjs/agents/user-agent.js +6 -3
- package/lib/cjs/aigne/aigne.d.ts +15 -6
- package/lib/cjs/aigne/aigne.js +19 -2
- package/lib/cjs/aigne/context.d.ts +31 -10
- package/lib/cjs/aigne/context.js +86 -14
- 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/memory/memory.d.ts +1 -0
- package/lib/cjs/memory/memory.js +1 -0
- package/lib/cjs/memory/recorder.d.ts +1 -0
- package/lib/cjs/memory/recorder.js +1 -0
- package/lib/cjs/memory/retriever.d.ts +1 -0
- package/lib/cjs/memory/retriever.js +1 -0
- package/lib/cjs/prompt/prompt-builder.d.ts +1 -1
- package/lib/dts/agents/agent.d.ts +6 -4
- package/lib/dts/agents/ai-agent.d.ts +8 -10
- package/lib/dts/agents/chat-model.d.ts +1 -0
- package/lib/dts/agents/mcp-agent.d.ts +5 -0
- package/lib/dts/agents/team-agent.d.ts +1 -0
- package/lib/dts/agents/user-agent.d.ts +1 -0
- package/lib/dts/aigne/aigne.d.ts +15 -6
- package/lib/dts/aigne/context.d.ts +31 -10
- 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/memory/memory.d.ts +1 -0
- package/lib/dts/memory/recorder.d.ts +1 -0
- package/lib/dts/memory/retriever.d.ts +1 -0
- package/lib/dts/prompt/prompt-builder.d.ts +1 -1
- package/lib/esm/agents/agent.d.ts +6 -4
- package/lib/esm/agents/agent.js +2 -0
- package/lib/esm/agents/ai-agent.d.ts +8 -10
- package/lib/esm/agents/ai-agent.js +3 -2
- package/lib/esm/agents/chat-model.d.ts +1 -0
- package/lib/esm/agents/chat-model.js +1 -0
- package/lib/esm/agents/mcp-agent.d.ts +5 -0
- package/lib/esm/agents/mcp-agent.js +5 -0
- package/lib/esm/agents/team-agent.d.ts +1 -0
- package/lib/esm/agents/team-agent.js +1 -0
- package/lib/esm/agents/user-agent.d.ts +1 -0
- package/lib/esm/agents/user-agent.js +6 -3
- package/lib/esm/aigne/aigne.d.ts +15 -6
- package/lib/esm/aigne/aigne.js +19 -2
- package/lib/esm/aigne/context.d.ts +31 -10
- package/lib/esm/aigne/context.js +86 -14
- 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/memory/memory.d.ts +1 -0
- package/lib/esm/memory/memory.js +1 -0
- package/lib/esm/memory/recorder.d.ts +1 -0
- package/lib/esm/memory/recorder.js +1 -0
- package/lib/esm/memory/retriever.d.ts +1 -0
- package/lib/esm/memory/retriever.js +1 -0
- package/lib/esm/prompt/prompt-builder.d.ts +1 -1
- package/package.json +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,27 @@
|
|
|
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.22.0](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.21.0...core-v1.22.0) (2025-06-24)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* support observability for cli and blocklet ([#155](https://github.com/AIGNE-io/aigne-framework/issues/155)) ([5baa705](https://github.com/AIGNE-io/aigne-framework/commit/5baa705a33cfdba1efc5ccbe18674c27513ca97d))
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### Dependencies
|
|
17
|
+
|
|
18
|
+
* The following workspace dependencies were updated
|
|
19
|
+
* dependencies
|
|
20
|
+
* @aigne/observability bumped to 0.1.0
|
|
21
|
+
|
|
22
|
+
## [1.21.0](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.20.1...core-v1.21.0) (2025-06-20)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Features
|
|
26
|
+
|
|
27
|
+
* **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))
|
|
28
|
+
|
|
8
29
|
## [1.20.1](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.20.0...core-v1.20.1) (2025-06-19)
|
|
9
30
|
|
|
10
31
|
|
|
@@ -176,6 +176,7 @@ export declare abstract class Agent<I extends Message = Message, O extends Messa
|
|
|
176
176
|
* List of memories this agent can use
|
|
177
177
|
*/
|
|
178
178
|
readonly memories: MemoryAgent[];
|
|
179
|
+
tag?: string;
|
|
179
180
|
/**
|
|
180
181
|
* Maximum number of memory items to retrieve
|
|
181
182
|
*/
|
|
@@ -341,7 +342,7 @@ export declare abstract class Agent<I extends Message = Message, O extends Messa
|
|
|
341
342
|
* Here's an example of invoking an agent with regular mode:
|
|
342
343
|
* {@includeCode ../../test/agents/agent.test.ts#example-invoke}
|
|
343
344
|
*/
|
|
344
|
-
invoke(input: I, options?: Partial<AgentInvokeOptions> & {
|
|
345
|
+
invoke(input: I & Message, options?: Partial<AgentInvokeOptions> & {
|
|
345
346
|
streaming?: false;
|
|
346
347
|
}): Promise<O>;
|
|
347
348
|
/**
|
|
@@ -359,7 +360,7 @@ export declare abstract class Agent<I extends Message = Message, O extends Messa
|
|
|
359
360
|
* Here's an example of invoking an agent with streaming response:
|
|
360
361
|
* {@includeCode ../../test/agents/agent.test.ts#example-invoke-streaming}
|
|
361
362
|
*/
|
|
362
|
-
invoke(input: I, options: Partial<AgentInvokeOptions> & {
|
|
363
|
+
invoke(input: I & Message, options: Partial<AgentInvokeOptions> & {
|
|
363
364
|
streaming: true;
|
|
364
365
|
}): Promise<AgentResponseStream<O>>;
|
|
365
366
|
/**
|
|
@@ -371,8 +372,8 @@ export declare abstract class Agent<I extends Message = Message, O extends Messa
|
|
|
371
372
|
* @param options Invocation options
|
|
372
373
|
* @returns Agent response (streaming or regular)
|
|
373
374
|
*/
|
|
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>;
|
|
375
|
+
invoke(input: I & Message, options?: Partial<AgentInvokeOptions>): Promise<AgentResponse<O>>;
|
|
376
|
+
protected invokeSkill<I extends Message, O extends Message>(skill: Agent<I, O>, input: I & Message, options: AgentInvokeOptions): Promise<O>;
|
|
376
377
|
/**
|
|
377
378
|
* Process agent output
|
|
378
379
|
*
|
|
@@ -723,6 +724,7 @@ export interface FunctionAgentOptions<I extends Message = Message, O extends Mes
|
|
|
723
724
|
* {@includeCode ../../test/agents/agent.test.ts#example-function-agent}
|
|
724
725
|
*/
|
|
725
726
|
export declare class FunctionAgent<I extends Message = Message, O extends Message = Message> extends Agent<I, O> {
|
|
727
|
+
tag: string;
|
|
726
728
|
/**
|
|
727
729
|
* Create a function agent from a function or options
|
|
728
730
|
*
|
package/lib/cjs/agents/agent.js
CHANGED
|
@@ -127,6 +127,7 @@ class Agent {
|
|
|
127
127
|
* List of memories this agent can use
|
|
128
128
|
*/
|
|
129
129
|
memories = [];
|
|
130
|
+
tag;
|
|
130
131
|
/**
|
|
131
132
|
* Maximum number of memory items to retrieve
|
|
132
133
|
*/
|
|
@@ -641,6 +642,7 @@ function checkAgentInputOutputSchema(schema) {
|
|
|
641
642
|
* {@includeCode ../../test/agents/agent.test.ts#example-function-agent}
|
|
642
643
|
*/
|
|
643
644
|
class FunctionAgent extends Agent {
|
|
645
|
+
tag = "FunctionAgent";
|
|
644
646
|
/**
|
|
645
647
|
* Create a function agent from a function or options
|
|
646
648
|
*
|
|
@@ -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,8 @@ 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> {
|
|
135
|
+
tag: string;
|
|
137
136
|
/**
|
|
138
137
|
* Create an AIAgent with the specified options
|
|
139
138
|
*
|
|
@@ -146,13 +145,13 @@ export declare class AIAgent<InputKey extends string = string, I extends Message
|
|
|
146
145
|
* AI agent with custom instructions:
|
|
147
146
|
* {@includeCode ../../test/agents/ai-agent.test.ts#example-ai-agent-instructions}
|
|
148
147
|
*/
|
|
149
|
-
static from<
|
|
148
|
+
static from<I extends Message, O extends Message>(options: AIAgentOptions<I, O>): AIAgent<I, O>;
|
|
150
149
|
/**
|
|
151
150
|
* Create an AIAgent instance
|
|
152
151
|
*
|
|
153
152
|
* @param options Configuration options for the AI agent
|
|
154
153
|
*/
|
|
155
|
-
constructor(options: AIAgentOptions<
|
|
154
|
+
constructor(options: AIAgentOptions<I, O>);
|
|
156
155
|
/**
|
|
157
156
|
* The language model used by this agent
|
|
158
157
|
*
|
|
@@ -173,7 +172,7 @@ export declare class AIAgent<InputKey extends string = string, I extends Message
|
|
|
173
172
|
/**
|
|
174
173
|
* Pick a message from input to use as the user's message
|
|
175
174
|
*/
|
|
176
|
-
inputKey?:
|
|
175
|
+
inputKey?: string;
|
|
177
176
|
/**
|
|
178
177
|
* Custom key to use for text output in the response
|
|
179
178
|
*
|
|
@@ -235,4 +234,3 @@ export declare class AIAgent<InputKey extends string = string, I extends Message
|
|
|
235
234
|
*/
|
|
236
235
|
_processRouter(input: I, model: ChatModel, modelInput: ChatModelInput, options: AgentInvokeOptions, toolsMap: Map<string, Agent>): AgentProcessAsyncGenerator<O>;
|
|
237
236
|
}
|
|
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
|
*
|
|
@@ -80,6 +80,7 @@ exports.aiAgentOptionsSchema = agent_js_1.agentOptionsSchema.extend({
|
|
|
80
80
|
* {@includeCode ../../test/agents/ai-agent.test.ts#example-ai-agent-basic}
|
|
81
81
|
*/
|
|
82
82
|
class AIAgent extends agent_js_1.Agent {
|
|
83
|
+
tag = "AIAgent";
|
|
83
84
|
/**
|
|
84
85
|
* Create an AIAgent with the specified options
|
|
85
86
|
*
|
|
@@ -101,7 +102,7 @@ class AIAgent extends agent_js_1.Agent {
|
|
|
101
102
|
* @param options Configuration options for the AI agent
|
|
102
103
|
*/
|
|
103
104
|
constructor(options) {
|
|
104
|
-
super(
|
|
105
|
+
super(options);
|
|
105
106
|
(0, type_utils_js_1.checkArguments)("AIAgent", exports.aiAgentOptionsSchema, options);
|
|
106
107
|
this.model = options.model;
|
|
107
108
|
this.instructions =
|
|
@@ -109,7 +110,7 @@ class AIAgent extends agent_js_1.Agent {
|
|
|
109
110
|
? prompt_builder_js_1.PromptBuilder.from(options.instructions)
|
|
110
111
|
: (options.instructions ?? new prompt_builder_js_1.PromptBuilder());
|
|
111
112
|
this.inputKey = options.inputKey;
|
|
112
|
-
this.outputKey = options.outputKey || DEFAULT_OUTPUT_KEY;
|
|
113
|
+
this.outputKey = options.outputKey || exports.DEFAULT_OUTPUT_KEY;
|
|
113
114
|
this.toolChoice = options.toolChoice;
|
|
114
115
|
this.memoryAgentsAsTools = options.memoryAgentsAsTools;
|
|
115
116
|
this.memoryPromptTemplate = options.memoryPromptTemplate;
|
|
@@ -264,7 +265,7 @@ class AIAgent extends agent_js_1.Agent {
|
|
|
264
265
|
}
|
|
265
266
|
}
|
|
266
267
|
async onGuideRailError(error) {
|
|
267
|
-
const outputKey = this.outputKey || DEFAULT_OUTPUT_KEY;
|
|
268
|
+
const outputKey = this.outputKey || exports.DEFAULT_OUTPUT_KEY;
|
|
268
269
|
return {
|
|
269
270
|
[outputKey]: error.reason,
|
|
270
271
|
};
|
|
@@ -24,6 +24,7 @@ import { Agent, type AgentInvokeOptions, type AgentProcessResult, type Message }
|
|
|
24
24
|
* {@includeCode ../../test/agents/chat-model.test.ts#example-chat-model-tools}
|
|
25
25
|
*/
|
|
26
26
|
export declare abstract class ChatModel extends Agent<ChatModelInput, ChatModelOutput> {
|
|
27
|
+
tag: string;
|
|
27
28
|
constructor();
|
|
28
29
|
/**
|
|
29
30
|
* Indicates whether the model supports parallel tool calls
|
|
@@ -27,6 +27,7 @@ const agent_js_1 = require("./agent.js");
|
|
|
27
27
|
* {@includeCode ../../test/agents/chat-model.test.ts#example-chat-model-tools}
|
|
28
28
|
*/
|
|
29
29
|
class ChatModel extends agent_js_1.Agent {
|
|
30
|
+
tag = "ChatModelAgent";
|
|
30
31
|
constructor() {
|
|
31
32
|
super({
|
|
32
33
|
inputSchema: chatModelInputSchema,
|
|
@@ -57,6 +57,7 @@ export type SSEServerParameters = {
|
|
|
57
57
|
* {@includeCode ../../test/agents/mcp-agent.test.ts#example-mcp-agent-from-sse}
|
|
58
58
|
*/
|
|
59
59
|
export declare class MCPAgent extends Agent {
|
|
60
|
+
tag: string;
|
|
60
61
|
/**
|
|
61
62
|
* Create an MCPAgent from a connection to an SSE server.
|
|
62
63
|
*
|
|
@@ -186,22 +187,26 @@ export interface MCPBaseOptions<I extends Message = Message, O extends Message =
|
|
|
186
187
|
client: ClientWithReconnect;
|
|
187
188
|
}
|
|
188
189
|
export declare abstract class MCPBase<I extends Message, O extends Message> extends Agent<I, O> {
|
|
190
|
+
tag: string;
|
|
189
191
|
constructor(options: MCPBaseOptions<I, O>);
|
|
190
192
|
protected client: ClientWithReconnect;
|
|
191
193
|
}
|
|
192
194
|
export declare class MCPTool extends MCPBase<Message, CallToolResult> {
|
|
195
|
+
tag: string;
|
|
193
196
|
process(input: Message): Promise<CallToolResult>;
|
|
194
197
|
}
|
|
195
198
|
export interface MCPPromptInput extends Record<string, unknown> {
|
|
196
199
|
[key: string]: string;
|
|
197
200
|
}
|
|
198
201
|
export declare class MCPPrompt extends MCPBase<MCPPromptInput, GetPromptResult> {
|
|
202
|
+
tag: string;
|
|
199
203
|
process(input: MCPPromptInput): Promise<GetPromptResult>;
|
|
200
204
|
}
|
|
201
205
|
export interface MCPResourceOptions extends MCPBaseOptions<MCPPromptInput, ReadResourceResult> {
|
|
202
206
|
uri: string;
|
|
203
207
|
}
|
|
204
208
|
export declare class MCPResource extends MCPBase<MCPPromptInput, ReadResourceResult> {
|
|
209
|
+
tag: string;
|
|
205
210
|
constructor(options: MCPResourceOptions);
|
|
206
211
|
uri: string;
|
|
207
212
|
process(input: MCPPromptInput): Promise<ReadResourceResult>;
|
|
@@ -55,6 +55,7 @@ function getMCPServerString(options) {
|
|
|
55
55
|
* {@includeCode ../../test/agents/mcp-agent.test.ts#example-mcp-agent-from-sse}
|
|
56
56
|
*/
|
|
57
57
|
class MCPAgent extends agent_js_1.Agent {
|
|
58
|
+
tag = "MCPAgent";
|
|
58
59
|
static from(options) {
|
|
59
60
|
(0, type_utils_js_1.checkArguments)("MCPAgent.from", mcpAgentOptionsSchema, options);
|
|
60
61
|
if (isSSEServerParameters(options)) {
|
|
@@ -251,6 +252,7 @@ class ClientWithReconnect extends index_js_2.Client {
|
|
|
251
252
|
}
|
|
252
253
|
}
|
|
253
254
|
class MCPBase extends agent_js_1.Agent {
|
|
255
|
+
tag = "MCPBase";
|
|
254
256
|
constructor(options) {
|
|
255
257
|
super(options);
|
|
256
258
|
this.client = options.client;
|
|
@@ -259,6 +261,7 @@ class MCPBase extends agent_js_1.Agent {
|
|
|
259
261
|
}
|
|
260
262
|
exports.MCPBase = MCPBase;
|
|
261
263
|
class MCPTool extends MCPBase {
|
|
264
|
+
tag = "MCPTool";
|
|
262
265
|
async process(input) {
|
|
263
266
|
const result = await this.client.callTool({ name: this.name, arguments: input });
|
|
264
267
|
return result;
|
|
@@ -266,6 +269,7 @@ class MCPTool extends MCPBase {
|
|
|
266
269
|
}
|
|
267
270
|
exports.MCPTool = MCPTool;
|
|
268
271
|
class MCPPrompt extends MCPBase {
|
|
272
|
+
tag = "MCPPrompt";
|
|
269
273
|
async process(input) {
|
|
270
274
|
const result = await this.client.getPrompt({ name: this.name, arguments: input });
|
|
271
275
|
return result;
|
|
@@ -273,6 +277,7 @@ class MCPPrompt extends MCPBase {
|
|
|
273
277
|
}
|
|
274
278
|
exports.MCPPrompt = MCPPrompt;
|
|
275
279
|
class MCPResource extends MCPBase {
|
|
280
|
+
tag = "MCPResource";
|
|
276
281
|
constructor(options) {
|
|
277
282
|
super(options);
|
|
278
283
|
this.uri = options.uri;
|
|
@@ -52,6 +52,7 @@ export interface TeamAgentOptions<I extends Message, O extends Message> extends
|
|
|
52
52
|
* {@includeCode ../../test/agents/team-agent.test.ts#example-team-agent-sequential}
|
|
53
53
|
*/
|
|
54
54
|
export declare class TeamAgent<I extends Message, O extends Message> extends Agent<I, O> {
|
|
55
|
+
tag: string;
|
|
55
56
|
/**
|
|
56
57
|
* Create a TeamAgent from the provided options.
|
|
57
58
|
*
|
|
@@ -7,6 +7,7 @@ export interface UserAgentOptions<I extends Message = Message, O extends Message
|
|
|
7
7
|
activeAgent?: Agent;
|
|
8
8
|
}
|
|
9
9
|
export declare class UserAgent<I extends Message = Message, O extends Message = Message> extends Agent<I, O> {
|
|
10
|
+
tag: string;
|
|
10
11
|
static from<I extends Message, O extends Message>(options: UserAgentOptions<I, O>): UserAgent<I, O>;
|
|
11
12
|
constructor(options: UserAgentOptions<I, O>);
|
|
12
13
|
context: Context;
|
|
@@ -5,6 +5,7 @@ const message_queue_js_1 = require("../aigne/message-queue.js");
|
|
|
5
5
|
const type_utils_js_1 = require("../utils/type-utils.js");
|
|
6
6
|
const agent_js_1 = require("./agent.js");
|
|
7
7
|
class UserAgent extends agent_js_1.Agent {
|
|
8
|
+
tag = "UserAgent";
|
|
8
9
|
static from(options) {
|
|
9
10
|
return new UserAgent(options);
|
|
10
11
|
}
|
|
@@ -26,9 +27,8 @@ class UserAgent extends agent_js_1.Agent {
|
|
|
26
27
|
super.publishToTopics(output, options);
|
|
27
28
|
}
|
|
28
29
|
invoke = ((input, options = {}) => {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return super.invoke(input, { ...options, context: this.context });
|
|
30
|
+
options.context ??= this.context.newContext({ reset: true });
|
|
31
|
+
return super.invoke(input, options);
|
|
32
32
|
});
|
|
33
33
|
async process(input, options) {
|
|
34
34
|
if (this._process) {
|
|
@@ -38,6 +38,9 @@ class UserAgent extends agent_js_1.Agent {
|
|
|
38
38
|
const [output, agent] = await options.context.invoke(this.activeAgent, input, {
|
|
39
39
|
returnActiveAgent: true,
|
|
40
40
|
streaming: true,
|
|
41
|
+
// Do not create a new context for the nested agent invocation,
|
|
42
|
+
// We are resetting the context in the override invoke method
|
|
43
|
+
newContext: false,
|
|
41
44
|
});
|
|
42
45
|
agent.then((agent) => {
|
|
43
46
|
this.activeAgent = agent;
|
package/lib/cjs/aigne/aigne.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { AIGNEObserver } from "@aigne/observability";
|
|
1
2
|
import { Agent, type AgentResponse, type AgentResponseStream, type Message } from "../agents/agent.js";
|
|
2
3
|
import { ChatModel } from "../agents/chat-model.js";
|
|
3
4
|
import type { UserAgent } from "../agents/user-agent.js";
|
|
@@ -33,6 +34,10 @@ export interface AIGNEOptions {
|
|
|
33
34
|
* Limits for the AIGNE instance, such as timeout, max tokens, max invocations, etc.
|
|
34
35
|
*/
|
|
35
36
|
limits?: ContextLimits;
|
|
37
|
+
/**
|
|
38
|
+
* Observer for the AIGNE instance.
|
|
39
|
+
*/
|
|
40
|
+
observer?: AIGNEObserver;
|
|
36
41
|
}
|
|
37
42
|
/**
|
|
38
43
|
* AIGNE is a class that orchestrates multiple agents to build complex AI applications.
|
|
@@ -98,6 +103,10 @@ export declare class AIGNE<U extends UserContext = UserContext> {
|
|
|
98
103
|
readonly agents: Agent<Message, Message>[] & {
|
|
99
104
|
[key: string]: Agent<Message, Message>;
|
|
100
105
|
};
|
|
106
|
+
/**
|
|
107
|
+
* Observer for the AIGNE instance.
|
|
108
|
+
*/
|
|
109
|
+
readonly observer?: AIGNEObserver;
|
|
101
110
|
/**
|
|
102
111
|
* Adds one or more agents to this AIGNE instance.
|
|
103
112
|
* Each agent is attached to this AIGNE instance, allowing it to access the AIGNE's resources.
|
|
@@ -111,7 +120,7 @@ export declare class AIGNE<U extends UserContext = UserContext> {
|
|
|
111
120
|
*
|
|
112
121
|
* @returns A new AIGNEContext instance bound to this AIGNE.
|
|
113
122
|
*/
|
|
114
|
-
newContext(options?: Partial<Context
|
|
123
|
+
newContext(options?: Partial<Pick<Context, "userContext" | "memories">>): AIGNEContext;
|
|
115
124
|
/**
|
|
116
125
|
* Creates a user agent for consistent interactions with a specified agent.
|
|
117
126
|
* This method allows you to create a wrapper around an agent for repeated invocations.
|
|
@@ -134,7 +143,7 @@ export declare class AIGNE<U extends UserContext = UserContext> {
|
|
|
134
143
|
* @param options.streaming - Must be false to return a response stream
|
|
135
144
|
* @returns A promise resolving to a tuple containing the agent's response and the final active agent
|
|
136
145
|
*/
|
|
137
|
-
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I, options: InvokeOptions<U> & {
|
|
146
|
+
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I & Message, options: InvokeOptions<U> & {
|
|
138
147
|
returnActiveAgent: true;
|
|
139
148
|
streaming?: false;
|
|
140
149
|
}): Promise<[O, Agent]>;
|
|
@@ -148,7 +157,7 @@ export declare class AIGNE<U extends UserContext = UserContext> {
|
|
|
148
157
|
* @param options.streaming - Must be true to return a response stream
|
|
149
158
|
* @returns A promise resolving to a tuple containing the agent's response stream and a promise for the final agent
|
|
150
159
|
*/
|
|
151
|
-
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I, options: InvokeOptions<U> & {
|
|
160
|
+
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I & Message, options: InvokeOptions<U> & {
|
|
152
161
|
returnActiveAgent: true;
|
|
153
162
|
streaming: true;
|
|
154
163
|
}): Promise<[AgentResponseStream<O>, Promise<Agent>]>;
|
|
@@ -165,7 +174,7 @@ export declare class AIGNE<U extends UserContext = UserContext> {
|
|
|
165
174
|
* Here's a simple example of how to invoke an agent:
|
|
166
175
|
* {@includeCode ../../test/aigne/aigne.test.ts#example-simple}
|
|
167
176
|
*/
|
|
168
|
-
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I, options?: InvokeOptions<U> & {
|
|
177
|
+
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I & Message, options?: InvokeOptions<U> & {
|
|
169
178
|
returnActiveAgent?: false;
|
|
170
179
|
streaming?: false;
|
|
171
180
|
}): Promise<O>;
|
|
@@ -182,7 +191,7 @@ export declare class AIGNE<U extends UserContext = UserContext> {
|
|
|
182
191
|
* Here's an example of how to invoke an agent with streaming response:
|
|
183
192
|
* {@includeCode ../../test/aigne/aigne.test.ts#example-streaming}
|
|
184
193
|
*/
|
|
185
|
-
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I, options: InvokeOptions<U> & {
|
|
194
|
+
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I & Message, options: InvokeOptions<U> & {
|
|
186
195
|
returnActiveAgent?: false;
|
|
187
196
|
streaming: true;
|
|
188
197
|
}): Promise<AgentResponseStream<O>>;
|
|
@@ -196,7 +205,7 @@ export declare class AIGNE<U extends UserContext = UserContext> {
|
|
|
196
205
|
* @returns Either a UserAgent (when no message provided) or a promise resolving to the agent's response
|
|
197
206
|
* with optional active agent information based on the provided options
|
|
198
207
|
*/
|
|
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]>;
|
|
208
|
+
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
209
|
/**
|
|
201
210
|
* Publishes a message to the message queue for inter-agent communication.
|
|
202
211
|
* This method broadcasts a message to all subscribers of the specified topic(s).
|
package/lib/cjs/aigne/aigne.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AIGNE = void 0;
|
|
4
|
+
const observability_1 = require("@aigne/observability");
|
|
4
5
|
const zod_1 = require("zod");
|
|
5
6
|
const agent_js_1 = require("../agents/agent.js");
|
|
6
7
|
const chat_model_js_1 = require("../agents/chat-model.js");
|
|
@@ -52,10 +53,15 @@ class AIGNE {
|
|
|
52
53
|
this.description = options?.description;
|
|
53
54
|
this.model = options?.model;
|
|
54
55
|
this.limits = options?.limits;
|
|
56
|
+
this.observer =
|
|
57
|
+
process.env.AIGNE_OBSERVABILITY_DISABLED === "true"
|
|
58
|
+
? undefined
|
|
59
|
+
: (options?.observer ?? new observability_1.AIGNEObserver());
|
|
55
60
|
if (options?.skills?.length)
|
|
56
61
|
this.skills.push(...options.skills);
|
|
57
62
|
if (options?.agents?.length)
|
|
58
63
|
this.addAgent(...options.agents);
|
|
64
|
+
this.observer?.serve();
|
|
59
65
|
this.initProcessExitHandler();
|
|
60
66
|
}
|
|
61
67
|
/**
|
|
@@ -90,6 +96,10 @@ class AIGNE {
|
|
|
90
96
|
* Provides indexed access by agent name.
|
|
91
97
|
*/
|
|
92
98
|
agents = (0, type_utils_js_1.createAccessorArray)([], (arr, name) => arr.find((i) => i.name === name));
|
|
99
|
+
/**
|
|
100
|
+
* Observer for the AIGNE instance.
|
|
101
|
+
*/
|
|
102
|
+
observer;
|
|
93
103
|
/**
|
|
94
104
|
* Adds one or more agents to this AIGNE instance.
|
|
95
105
|
* Each agent is attached to this AIGNE instance, allowing it to access the AIGNE's resources.
|
|
@@ -110,10 +120,16 @@ class AIGNE {
|
|
|
110
120
|
* @returns A new AIGNEContext instance bound to this AIGNE.
|
|
111
121
|
*/
|
|
112
122
|
newContext(options) {
|
|
113
|
-
|
|
123
|
+
const context = new context_js_1.AIGNEContext(this);
|
|
124
|
+
if (options?.userContext)
|
|
125
|
+
context.userContext = options.userContext;
|
|
126
|
+
if (options?.memories)
|
|
127
|
+
context.memories = options.memories;
|
|
128
|
+
return context;
|
|
114
129
|
}
|
|
115
130
|
invoke(agent, message, options) {
|
|
116
|
-
|
|
131
|
+
const context = new context_js_1.AIGNEContext(this);
|
|
132
|
+
return context.invoke(agent, message, { ...options, newContext: false });
|
|
117
133
|
}
|
|
118
134
|
/**
|
|
119
135
|
* Publishes a message to the message queue for inter-agent communication.
|
|
@@ -192,5 +208,6 @@ const aigneOptionsSchema = zod_1.z.object({
|
|
|
192
208
|
model: zod_1.z.instanceof(chat_model_js_1.ChatModel).optional(),
|
|
193
209
|
skills: zod_1.z.array(zod_1.z.instanceof(agent_js_1.Agent)).optional(),
|
|
194
210
|
agents: zod_1.z.array(zod_1.z.instanceof(agent_js_1.Agent)).optional(),
|
|
211
|
+
observer: zod_1.z.instanceof(observability_1.AIGNEObserver).optional(),
|
|
195
212
|
});
|
|
196
213
|
const aigneAddAgentArgsSchema = zod_1.z.array(zod_1.z.instanceof(agent_js_1.Agent));
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { AIGNEObserver } from "@aigne/observability";
|
|
2
|
+
import type { Span } from "@opentelemetry/api";
|
|
1
3
|
import { Emitter } from "strict-event-emitter";
|
|
2
4
|
import { Agent, type AgentInvokeOptions, type AgentProcessAsyncGenerator, type AgentResponse, type AgentResponseStream, type Message } from "../agents/agent.js";
|
|
3
5
|
import type { ChatModel } from "../agents/chat-model.js";
|
|
@@ -45,6 +47,13 @@ export interface InvokeOptions<U extends UserContext = UserContext> extends Part
|
|
|
45
47
|
returnMetadata?: boolean;
|
|
46
48
|
disableTransfer?: boolean;
|
|
47
49
|
sourceAgent?: Agent;
|
|
50
|
+
/**
|
|
51
|
+
* Whether to create a new context for this invocation.
|
|
52
|
+
* If false, the invocation will use the current context.
|
|
53
|
+
*
|
|
54
|
+
* @default true
|
|
55
|
+
*/
|
|
56
|
+
newContext?: boolean;
|
|
48
57
|
}
|
|
49
58
|
/**
|
|
50
59
|
* @hidden
|
|
@@ -57,8 +66,11 @@ export interface UserContext extends Record<string, unknown> {
|
|
|
57
66
|
export interface Context<U extends UserContext = UserContext> extends TypedEventEmitter<ContextEventMap, ContextEmitEventMap> {
|
|
58
67
|
id: string;
|
|
59
68
|
parentId?: string;
|
|
69
|
+
rootId: string;
|
|
60
70
|
model?: ChatModel;
|
|
61
71
|
skills?: Agent[];
|
|
72
|
+
observer?: AIGNEObserver;
|
|
73
|
+
span?: Span;
|
|
62
74
|
usage: ContextUsage;
|
|
63
75
|
limits?: ContextLimits;
|
|
64
76
|
status?: "normal" | "timeout";
|
|
@@ -78,11 +90,11 @@ export interface Context<U extends UserContext = UserContext> extends TypedEvent
|
|
|
78
90
|
* @param options.streaming return a stream of the output
|
|
79
91
|
* @returns the output of the agent and the final active agent
|
|
80
92
|
*/
|
|
81
|
-
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I, options: InvokeOptions & {
|
|
93
|
+
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I & Message, options: InvokeOptions & {
|
|
82
94
|
returnActiveAgent: true;
|
|
83
95
|
streaming?: false;
|
|
84
96
|
}): Promise<[O, Agent]>;
|
|
85
|
-
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I, options: InvokeOptions & {
|
|
97
|
+
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I & Message, options: InvokeOptions & {
|
|
86
98
|
returnActiveAgent: true;
|
|
87
99
|
streaming: true;
|
|
88
100
|
}): Promise<[AgentResponseStream<O>, Promise<Agent>]>;
|
|
@@ -92,13 +104,13 @@ export interface Context<U extends UserContext = UserContext> extends TypedEvent
|
|
|
92
104
|
* @param message Message to pass to the agent
|
|
93
105
|
* @returns the output of the agent
|
|
94
106
|
*/
|
|
95
|
-
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I, options?: InvokeOptions & {
|
|
107
|
+
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I & Message, options?: InvokeOptions & {
|
|
96
108
|
streaming?: false;
|
|
97
109
|
}): Promise<O>;
|
|
98
|
-
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I, options: InvokeOptions & {
|
|
110
|
+
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I & Message, options: InvokeOptions & {
|
|
99
111
|
streaming: true;
|
|
100
112
|
}): 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]>;
|
|
113
|
+
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
114
|
/**
|
|
103
115
|
* Publish a message to a topic, the aigne will invoke the listeners of the topic
|
|
104
116
|
* @param topic topic name, or an array of topic names
|
|
@@ -126,12 +138,18 @@ export interface Context<U extends UserContext = UserContext> extends TypedEvent
|
|
|
126
138
|
* @hidden
|
|
127
139
|
*/
|
|
128
140
|
export declare class AIGNEContext implements Context {
|
|
129
|
-
constructor(
|
|
130
|
-
|
|
141
|
+
constructor(parent?: ConstructorParameters<typeof AIGNEContextShared>[0], { reset }?: {
|
|
142
|
+
reset?: boolean;
|
|
143
|
+
});
|
|
131
144
|
id: string;
|
|
145
|
+
parentId?: string;
|
|
146
|
+
rootId: string;
|
|
147
|
+
span?: Span;
|
|
132
148
|
readonly internal: AIGNEContextShared;
|
|
149
|
+
get messageQueue(): MessageQueue;
|
|
133
150
|
get model(): ChatModel | undefined;
|
|
134
151
|
get skills(): Agent<Message, Message>[] | undefined;
|
|
152
|
+
get observer(): AIGNEObserver | undefined;
|
|
135
153
|
get limits(): ContextLimits | undefined;
|
|
136
154
|
get status(): "normal" | "timeout";
|
|
137
155
|
get usage(): ContextUsage;
|
|
@@ -148,19 +166,22 @@ export declare class AIGNEContext implements Context {
|
|
|
148
166
|
subscribe: Context["subscribe"];
|
|
149
167
|
unsubscribe: Context["unsubscribe"];
|
|
150
168
|
emit<K extends keyof ContextEmitEventMap>(eventName: K, ...args: Args<K, ContextEmitEventMap>): boolean;
|
|
169
|
+
private trace;
|
|
151
170
|
on<K extends keyof ContextEventMap>(eventName: K, listener: Listener<K, ContextEventMap>): this;
|
|
152
171
|
once<K extends keyof ContextEventMap>(eventName: K, listener: Listener<K, ContextEventMap>): this;
|
|
153
172
|
off<K extends keyof ContextEventMap>(eventName: K, listener: Listener<K, ContextEventMap>): this;
|
|
154
173
|
}
|
|
155
174
|
declare class AIGNEContextShared {
|
|
156
175
|
private readonly parent?;
|
|
157
|
-
|
|
176
|
+
span?: Span;
|
|
177
|
+
constructor(parent?: (Pick<Context, "model" | "skills" | "limits" | "observer"> & {
|
|
158
178
|
messageQueue?: MessageQueue;
|
|
159
|
-
}) | undefined
|
|
179
|
+
}) | undefined);
|
|
160
180
|
readonly messageQueue: MessageQueue;
|
|
161
181
|
readonly events: Emitter<any>;
|
|
162
182
|
get model(): ChatModel | undefined;
|
|
163
183
|
get skills(): Agent<Message, Message>[] | undefined;
|
|
184
|
+
get observer(): AIGNEObserver | undefined;
|
|
164
185
|
get limits(): ContextLimits | undefined;
|
|
165
186
|
usage: ContextUsage;
|
|
166
187
|
userContext: Context["userContext"];
|
|
@@ -169,7 +190,7 @@ declare class AIGNEContextShared {
|
|
|
169
190
|
private timer?;
|
|
170
191
|
private initTimeout;
|
|
171
192
|
get status(): "normal" | "timeout";
|
|
172
|
-
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, input: I, context: Context, options?: InvokeOptions): AgentProcessAsyncGenerator<O & {
|
|
193
|
+
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, input: I & Message, context: Context, options?: InvokeOptions): AgentProcessAsyncGenerator<O & {
|
|
173
194
|
__activeAgent__: Agent;
|
|
174
195
|
}>;
|
|
175
196
|
private invokeAgent;
|