@aigne/core 1.11.0 → 1.12.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 +15 -0
- package/README.md +11 -10
- package/README.zh.md +7 -6
- package/lib/cjs/agents/agent.d.ts +20 -20
- package/lib/cjs/agents/agent.js +25 -26
- package/lib/cjs/agents/ai-agent.d.ts +17 -18
- package/lib/cjs/agents/ai-agent.js +6 -6
- package/lib/cjs/agents/mcp-agent.d.ts +10 -4
- package/lib/cjs/agents/mcp-agent.js +12 -6
- package/lib/cjs/agents/memory.d.ts +1 -1
- package/lib/cjs/agents/team-agent.d.ts +28 -0
- package/lib/cjs/agents/team-agent.js +93 -0
- package/lib/cjs/agents/user-agent.d.ts +9 -10
- package/lib/cjs/agents/user-agent.js +10 -13
- package/lib/{esm/execution-engine/execution-engine.d.ts → cjs/aigne/aigne.d.ts} +9 -12
- package/lib/cjs/{execution-engine/execution-engine.js → aigne/aigne.js} +19 -19
- package/lib/cjs/{execution-engine → aigne}/context.d.ts +31 -32
- package/lib/cjs/{execution-engine → aigne}/context.js +30 -40
- package/lib/cjs/aigne/index.d.ts +4 -0
- package/lib/cjs/{execution-engine → aigne}/index.js +2 -2
- package/lib/cjs/{execution-engine → aigne}/usage.d.ts +1 -1
- package/lib/cjs/client/client.d.ts +19 -0
- package/lib/cjs/client/client.js +49 -0
- package/lib/cjs/index.d.ts +2 -1
- package/lib/cjs/index.js +2 -1
- package/lib/cjs/loader/agent-yaml.d.ts +3 -3
- package/lib/cjs/loader/agent-yaml.js +10 -3
- package/lib/cjs/loader/index.d.ts +9 -9
- package/lib/cjs/loader/index.js +6 -6
- package/lib/cjs/models/chat-model.d.ts +1 -1
- package/lib/cjs/models/claude-chat-model.d.ts +3 -3
- package/lib/cjs/models/openai-chat-model.d.ts +3 -3
- package/lib/cjs/prompt/prompt-builder.d.ts +1 -1
- package/lib/cjs/prompt/prompt-builder.js +3 -3
- package/lib/cjs/server/error.d.ts +4 -0
- package/lib/cjs/server/error.js +11 -0
- package/lib/cjs/server/server.d.ts +54 -0
- package/lib/cjs/server/server.js +130 -0
- package/lib/cjs/utils/event-stream.d.ts +11 -0
- package/lib/cjs/utils/event-stream.js +91 -0
- package/lib/cjs/utils/mcp-utils.js +4 -1
- package/lib/cjs/utils/stream-utils.d.ts +7 -2
- package/lib/cjs/utils/stream-utils.js +43 -34
- package/lib/cjs/utils/type-utils.d.ts +4 -2
- package/lib/cjs/utils/type-utils.js +10 -2
- package/lib/dts/agents/agent.d.ts +20 -20
- package/lib/dts/agents/ai-agent.d.ts +17 -18
- package/lib/dts/agents/mcp-agent.d.ts +10 -4
- package/lib/dts/agents/memory.d.ts +1 -1
- package/lib/dts/agents/team-agent.d.ts +28 -0
- package/lib/dts/agents/user-agent.d.ts +9 -10
- package/lib/dts/{execution-engine/execution-engine.d.ts → aigne/aigne.d.ts} +9 -12
- package/lib/dts/{execution-engine → aigne}/context.d.ts +31 -32
- package/lib/dts/aigne/index.d.ts +4 -0
- package/lib/dts/{execution-engine → aigne}/usage.d.ts +1 -1
- package/lib/dts/client/client.d.ts +19 -0
- package/lib/dts/index.d.ts +2 -1
- package/lib/dts/loader/agent-yaml.d.ts +3 -3
- package/lib/dts/loader/index.d.ts +9 -9
- package/lib/dts/models/chat-model.d.ts +1 -1
- package/lib/dts/models/claude-chat-model.d.ts +3 -3
- package/lib/dts/models/openai-chat-model.d.ts +3 -3
- package/lib/dts/prompt/prompt-builder.d.ts +1 -1
- package/lib/dts/server/error.d.ts +4 -0
- package/lib/dts/server/server.d.ts +54 -0
- package/lib/dts/utils/event-stream.d.ts +11 -0
- package/lib/dts/utils/stream-utils.d.ts +7 -2
- package/lib/dts/utils/type-utils.d.ts +4 -2
- package/lib/esm/agents/agent.d.ts +20 -20
- package/lib/esm/agents/agent.js +25 -26
- package/lib/esm/agents/ai-agent.d.ts +17 -18
- package/lib/esm/agents/ai-agent.js +6 -6
- package/lib/esm/agents/mcp-agent.d.ts +10 -4
- package/lib/esm/agents/mcp-agent.js +12 -6
- package/lib/esm/agents/memory.d.ts +1 -1
- package/lib/esm/agents/team-agent.d.ts +28 -0
- package/lib/esm/agents/team-agent.js +89 -0
- package/lib/esm/agents/user-agent.d.ts +9 -10
- package/lib/esm/agents/user-agent.js +11 -14
- package/lib/{cjs/execution-engine/execution-engine.d.ts → esm/aigne/aigne.d.ts} +9 -12
- package/lib/esm/{execution-engine/execution-engine.js → aigne/aigne.js} +18 -18
- package/lib/esm/{execution-engine → aigne}/context.d.ts +31 -32
- package/lib/esm/{execution-engine → aigne}/context.js +28 -38
- package/lib/esm/aigne/index.d.ts +4 -0
- package/lib/esm/aigne/index.js +4 -0
- package/lib/esm/{execution-engine → aigne}/usage.d.ts +1 -1
- package/lib/esm/client/client.d.ts +19 -0
- package/lib/esm/client/client.js +45 -0
- package/lib/esm/index.d.ts +2 -1
- package/lib/esm/index.js +2 -1
- package/lib/esm/loader/agent-yaml.d.ts +3 -3
- package/lib/esm/loader/agent-yaml.js +10 -3
- package/lib/esm/loader/index.d.ts +9 -9
- package/lib/esm/loader/index.js +6 -6
- package/lib/esm/models/chat-model.d.ts +1 -1
- package/lib/esm/models/claude-chat-model.d.ts +3 -3
- package/lib/esm/models/openai-chat-model.d.ts +3 -3
- package/lib/esm/prompt/prompt-builder.d.ts +1 -1
- package/lib/esm/prompt/prompt-builder.js +3 -3
- package/lib/esm/server/error.d.ts +4 -0
- package/lib/esm/server/error.js +7 -0
- package/lib/esm/server/server.d.ts +54 -0
- package/lib/esm/server/server.js +123 -0
- package/lib/esm/utils/event-stream.d.ts +11 -0
- package/lib/esm/utils/event-stream.js +85 -0
- package/lib/esm/utils/mcp-utils.js +4 -1
- package/lib/esm/utils/stream-utils.d.ts +7 -2
- package/lib/esm/utils/stream-utils.js +42 -33
- package/lib/esm/utils/type-utils.d.ts +4 -2
- package/lib/esm/utils/type-utils.js +9 -2
- package/package.json +13 -4
- package/lib/cjs/execution-engine/index.d.ts +0 -4
- package/lib/cjs/execution-engine/utils.d.ts +0 -4
- package/lib/cjs/execution-engine/utils.js +0 -34
- package/lib/dts/execution-engine/index.d.ts +0 -4
- package/lib/dts/execution-engine/utils.d.ts +0 -4
- package/lib/esm/execution-engine/index.d.ts +0 -4
- package/lib/esm/execution-engine/index.js +0 -4
- package/lib/esm/execution-engine/utils.d.ts +0 -4
- package/lib/esm/execution-engine/utils.js +0 -30
- /package/lib/cjs/{execution-engine → aigne}/message-queue.d.ts +0 -0
- /package/lib/cjs/{execution-engine → aigne}/message-queue.js +0 -0
- /package/lib/cjs/{execution-engine → aigne}/usage.js +0 -0
- /package/lib/dts/{execution-engine → aigne}/message-queue.d.ts +0 -0
- /package/lib/esm/{execution-engine → aigne}/message-queue.d.ts +0 -0
- /package/lib/esm/{execution-engine → aigne}/message-queue.js +0 -0
- /package/lib/esm/{execution-engine → aigne}/usage.js +0 -0
|
@@ -11,7 +11,12 @@ export declare function onAgentResponseStreamEnd<T extends Message>(stream: Agen
|
|
|
11
11
|
}): ReadableStream<any>;
|
|
12
12
|
export declare function isAsyncGenerator<T extends AsyncGenerator>(value: AsyncGenerator | unknown): value is T;
|
|
13
13
|
export declare function arrayToAgentProcessAsyncGenerator<T extends Message>(chunks: (AgentResponseChunk<T> | Error)[], result?: Partial<T>): AgentProcessAsyncGenerator<T>;
|
|
14
|
-
export declare function
|
|
15
|
-
export declare function readableStreamToArray<T>(stream: ReadableStream<T
|
|
14
|
+
export declare function arrayToReadableStream<T>(chunks: (T | Error)[]): ReadableStream<T>;
|
|
15
|
+
export declare function readableStreamToArray<T>(stream: ReadableStream<T>, options: {
|
|
16
|
+
catchError: true;
|
|
17
|
+
}): Promise<(T | Error)[]>;
|
|
18
|
+
export declare function readableStreamToArray<T>(stream: ReadableStream<T>, options?: {
|
|
19
|
+
catchError?: false;
|
|
20
|
+
}): Promise<T[]>;
|
|
16
21
|
export declare function readableStreamToAsyncIterator<T>(stream: ReadableStream<T>): AsyncIterable<T>;
|
|
17
22
|
export declare function stringToAgentResponseStream(str: string, key?: "text" | typeof MESSAGE_KEY | string): AgentResponseStream<Message>;
|
|
@@ -10,7 +10,7 @@ exports.asyncGeneratorToReadableStream = asyncGeneratorToReadableStream;
|
|
|
10
10
|
exports.onAgentResponseStreamEnd = onAgentResponseStreamEnd;
|
|
11
11
|
exports.isAsyncGenerator = isAsyncGenerator;
|
|
12
12
|
exports.arrayToAgentProcessAsyncGenerator = arrayToAgentProcessAsyncGenerator;
|
|
13
|
-
exports.
|
|
13
|
+
exports.arrayToReadableStream = arrayToReadableStream;
|
|
14
14
|
exports.readableStreamToArray = readableStreamToArray;
|
|
15
15
|
exports.readableStreamToAsyncIterator = readableStreamToAsyncIterator;
|
|
16
16
|
exports.stringToAgentResponseStream = stringToAgentResponseStream;
|
|
@@ -19,7 +19,7 @@ const agent_js_1 = require("../agents/agent.js");
|
|
|
19
19
|
const type_utils_js_1 = require("./type-utils.js");
|
|
20
20
|
function objectToAgentResponseStream(json) {
|
|
21
21
|
return new ReadableStream({
|
|
22
|
-
|
|
22
|
+
pull(controller) {
|
|
23
23
|
controller.enqueue({ delta: { json } });
|
|
24
24
|
controller.close();
|
|
25
25
|
},
|
|
@@ -65,22 +65,20 @@ async function agentResponseStreamToObject(stream) {
|
|
|
65
65
|
}
|
|
66
66
|
function asyncGeneratorToReadableStream(generator) {
|
|
67
67
|
return new ReadableStream({
|
|
68
|
-
async
|
|
68
|
+
async pull(controller) {
|
|
69
69
|
try {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
if (chunk.
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
controller.enqueue(chunk.value);
|
|
78
|
-
}
|
|
70
|
+
const chunk = await generator.next();
|
|
71
|
+
if (chunk.value) {
|
|
72
|
+
if (chunk.done) {
|
|
73
|
+
controller.enqueue({ delta: { json: chunk.value } });
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
controller.enqueue(chunk.value);
|
|
79
77
|
}
|
|
80
|
-
if (chunk.done)
|
|
81
|
-
break;
|
|
82
78
|
}
|
|
83
|
-
|
|
79
|
+
if (chunk.done) {
|
|
80
|
+
controller.close();
|
|
81
|
+
}
|
|
84
82
|
}
|
|
85
83
|
catch (error) {
|
|
86
84
|
controller.error(error);
|
|
@@ -89,15 +87,18 @@ function asyncGeneratorToReadableStream(generator) {
|
|
|
89
87
|
});
|
|
90
88
|
}
|
|
91
89
|
function onAgentResponseStreamEnd(stream, callback, options) {
|
|
90
|
+
const json = {};
|
|
91
|
+
const reader = stream.getReader();
|
|
92
92
|
return new ReadableStream({
|
|
93
|
-
async
|
|
93
|
+
async pull(controller) {
|
|
94
94
|
try {
|
|
95
|
-
const
|
|
96
|
-
|
|
95
|
+
const { value, done } = await reader.read();
|
|
96
|
+
if (!done) {
|
|
97
97
|
const chunk = options?.processChunk ? options.processChunk(value) : value;
|
|
98
98
|
if (!(0, agent_js_1.isEmptyChunk)(chunk))
|
|
99
99
|
controller.enqueue(chunk);
|
|
100
100
|
mergeAgentResponseChunk(json, value);
|
|
101
|
+
return;
|
|
101
102
|
}
|
|
102
103
|
const result = await callback(json);
|
|
103
104
|
if (result && !(0, fast_deep_equal_1.default)(result, json)) {
|
|
@@ -106,13 +107,11 @@ function onAgentResponseStreamEnd(stream, callback, options) {
|
|
|
106
107
|
chunk = options.processChunk(chunk);
|
|
107
108
|
controller.enqueue(chunk);
|
|
108
109
|
}
|
|
110
|
+
controller.close();
|
|
109
111
|
}
|
|
110
112
|
catch (error) {
|
|
111
113
|
controller.error(options?.errorCallback?.(error) ?? error);
|
|
112
114
|
}
|
|
113
|
-
finally {
|
|
114
|
-
controller.close();
|
|
115
|
-
}
|
|
116
115
|
},
|
|
117
116
|
});
|
|
118
117
|
}
|
|
@@ -128,24 +127,34 @@ async function* arrayToAgentProcessAsyncGenerator(chunks, result) {
|
|
|
128
127
|
if (result !== undefined)
|
|
129
128
|
return result;
|
|
130
129
|
}
|
|
131
|
-
function
|
|
130
|
+
function arrayToReadableStream(chunks) {
|
|
131
|
+
const list = [...chunks];
|
|
132
132
|
return new ReadableStream({
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
}
|
|
139
|
-
controller.enqueue(chunk);
|
|
133
|
+
pull(controller) {
|
|
134
|
+
const item = list.shift();
|
|
135
|
+
if (!item) {
|
|
136
|
+
controller.close();
|
|
137
|
+
return;
|
|
140
138
|
}
|
|
141
|
-
|
|
139
|
+
if (item instanceof Error) {
|
|
140
|
+
controller.error(item);
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
controller.enqueue(item);
|
|
142
144
|
},
|
|
143
145
|
});
|
|
144
146
|
}
|
|
145
|
-
async function readableStreamToArray(stream) {
|
|
147
|
+
async function readableStreamToArray(stream, options) {
|
|
146
148
|
const result = [];
|
|
147
|
-
|
|
148
|
-
|
|
149
|
+
try {
|
|
150
|
+
for await (const value of readableStreamToAsyncIterator(stream)) {
|
|
151
|
+
result.push(value);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
catch (error) {
|
|
155
|
+
if (!options?.catchError)
|
|
156
|
+
throw error;
|
|
157
|
+
result.push(error);
|
|
149
158
|
}
|
|
150
159
|
return result;
|
|
151
160
|
}
|
|
@@ -161,5 +170,5 @@ async function* readableStreamToAsyncIterator(stream) {
|
|
|
161
170
|
function stringToAgentResponseStream(str, key = "text") {
|
|
162
171
|
const segmenter = new Intl.Segmenter(undefined, { granularity: "word" });
|
|
163
172
|
const segments = segmenter.segment(str);
|
|
164
|
-
return
|
|
173
|
+
return arrayToReadableStream(Array.from(segments).map((segment) => ({ delta: { text: { [key]: segment.segment } } })));
|
|
165
174
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { type ZodType } from "zod";
|
|
2
2
|
export type PromiseOrValue<T> = T | Promise<T>;
|
|
3
|
-
export type Nullish<T> = T | null | undefined;
|
|
3
|
+
export type Nullish<T> = T | null | undefined | void;
|
|
4
4
|
export type OmitPropertiesFromArrayFirstElement<T extends unknown[], K extends string | number | symbol> = T extends [infer U, ...infer Rest] ? [Omit<U, K>, ...Rest] : never;
|
|
5
5
|
export declare function isNil(value: unknown): value is null | undefined;
|
|
6
|
+
export declare function isRecord<T>(value: unknown): value is Record<string, T>;
|
|
6
7
|
export declare function isEmpty(obj: unknown): boolean;
|
|
7
8
|
export declare function isNonNullable<T>(value: T): value is NonNullable<T>;
|
|
8
9
|
export declare function isNotEmpty<T>(arr: T[]): arr is [T, ...T[]];
|
|
@@ -12,5 +13,6 @@ export declare function orArrayToArray<T>(value?: T | T[]): T[];
|
|
|
12
13
|
export declare function createAccessorArray<T>(array: T[], accessor: (array: T[], name: string) => T | undefined): T[] & {
|
|
13
14
|
[key: string]: T;
|
|
14
15
|
};
|
|
15
|
-
export declare function checkArguments<T>(prefix: string, schema: ZodType<T>, args: T): T;
|
|
16
|
+
export declare function checkArguments<T>(prefix: string, schema: ZodType<T>, args: T | unknown): T;
|
|
16
17
|
export declare function tryOrThrow<P extends PromiseOrValue<unknown>>(fn: () => P, error: string | Error | ((error: Error) => Error)): P;
|
|
18
|
+
export declare function tryOrThrow<P extends PromiseOrValue<unknown>>(fn: () => P, error?: Nullish<string | Error | ((error: Error) => Nullish<Error>)>): P | undefined;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isNil = isNil;
|
|
4
|
+
exports.isRecord = isRecord;
|
|
4
5
|
exports.isEmpty = isEmpty;
|
|
5
6
|
exports.isNonNullable = isNonNullable;
|
|
6
7
|
exports.isNotEmpty = isNotEmpty;
|
|
@@ -14,6 +15,9 @@ const zod_1 = require("zod");
|
|
|
14
15
|
function isNil(value) {
|
|
15
16
|
return value === null || value === undefined;
|
|
16
17
|
}
|
|
18
|
+
function isRecord(value) {
|
|
19
|
+
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
20
|
+
}
|
|
17
21
|
function isEmpty(obj) {
|
|
18
22
|
if (isNil(obj))
|
|
19
23
|
return true;
|
|
@@ -113,12 +117,16 @@ function tryOrThrow(fn, error) {
|
|
|
113
117
|
const result = fn();
|
|
114
118
|
if (result instanceof Promise) {
|
|
115
119
|
return result.catch((e) => {
|
|
116
|
-
|
|
120
|
+
const error = createError(e);
|
|
121
|
+
if (error)
|
|
122
|
+
throw error;
|
|
117
123
|
});
|
|
118
124
|
}
|
|
119
125
|
return result;
|
|
120
126
|
}
|
|
121
127
|
catch (e) {
|
|
122
|
-
|
|
128
|
+
const error = createError(e);
|
|
129
|
+
if (error)
|
|
130
|
+
throw error;
|
|
123
131
|
}
|
|
124
132
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { inspect } from "node:util";
|
|
2
2
|
import { type ZodType } from "zod";
|
|
3
|
-
import type { Context } from "../
|
|
3
|
+
import type { Context } from "../aigne/context.js";
|
|
4
4
|
import { type Nullish, type PromiseOrValue } from "../utils/type-utils.js";
|
|
5
5
|
import { AgentMemory, type AgentMemoryOptions } from "./memory.js";
|
|
6
6
|
import { type TransferAgentOutput } from "./types.js";
|
|
@@ -15,11 +15,11 @@ export interface AgentOptions<I extends Message = Message, O extends Message = M
|
|
|
15
15
|
inputSchema?: AgentInputOutputSchema<I>;
|
|
16
16
|
outputSchema?: AgentInputOutputSchema<O>;
|
|
17
17
|
includeInputInOutput?: boolean;
|
|
18
|
-
|
|
18
|
+
skills?: (Agent | FunctionAgentFn)[];
|
|
19
19
|
disableEvents?: boolean;
|
|
20
20
|
memory?: AgentMemory | AgentMemoryOptions | true;
|
|
21
21
|
}
|
|
22
|
-
export interface
|
|
22
|
+
export interface AgentInvokeOptions {
|
|
23
23
|
streaming?: boolean;
|
|
24
24
|
}
|
|
25
25
|
export declare abstract class Agent<I extends Message = Message, O extends Message = Message> {
|
|
@@ -38,38 +38,38 @@ export declare abstract class Agent<I extends Message = Message, O extends Messa
|
|
|
38
38
|
readonly includeInputInOutput?: boolean;
|
|
39
39
|
readonly subscribeTopic?: SubscribeTopic;
|
|
40
40
|
readonly publishTopic?: PublishTopic<Message>;
|
|
41
|
-
readonly
|
|
41
|
+
readonly skills: Agent<Message, Message>[] & {
|
|
42
42
|
[key: string]: Agent<Message, Message>;
|
|
43
43
|
};
|
|
44
44
|
private disableEvents?;
|
|
45
45
|
/**
|
|
46
46
|
* Attach agent to context:
|
|
47
|
-
* - subscribe to topic and
|
|
47
|
+
* - subscribe to topic and invoke process method when message received
|
|
48
48
|
* - subscribe to memory topic if memory is enabled
|
|
49
49
|
* @param context Context to attach
|
|
50
50
|
*/
|
|
51
51
|
attach(context: Pick<Context, "subscribe">): void;
|
|
52
|
-
|
|
53
|
-
get
|
|
52
|
+
addSkill(...skills: (Agent | FunctionAgentFn)[]): void;
|
|
53
|
+
get isInvokable(): boolean;
|
|
54
54
|
private checkContextStatus;
|
|
55
55
|
private newDefaultContext;
|
|
56
|
-
|
|
56
|
+
invoke(input: I | string, context: Context | undefined, options: AgentInvokeOptions & {
|
|
57
57
|
streaming: true;
|
|
58
58
|
}): Promise<AgentResponseStream<O>>;
|
|
59
|
-
|
|
59
|
+
invoke(input: I | string, context?: Context, options?: AgentInvokeOptions & {
|
|
60
60
|
streaming?: false;
|
|
61
61
|
}): Promise<O>;
|
|
62
|
-
|
|
62
|
+
invoke(input: I | string, context?: Context, options?: AgentInvokeOptions): Promise<AgentResponse<O>>;
|
|
63
63
|
private processAgentOutput;
|
|
64
64
|
private processAgentError;
|
|
65
|
-
protected
|
|
65
|
+
protected checkAgentInvokesUsage(context: Context): void;
|
|
66
66
|
protected preprocess(_: I, context: Context): void;
|
|
67
67
|
protected postprocess(input: I, output: O, context: Context): void;
|
|
68
|
-
abstract process(input: I, context: Context, options?:
|
|
68
|
+
abstract process(input: I, context: Context, options?: AgentInvokeOptions): PromiseOrValue<AgentProcessResult<O>>;
|
|
69
69
|
shutdown(): Promise<void>;
|
|
70
70
|
[inspect.custom](): string;
|
|
71
71
|
}
|
|
72
|
-
export type AgentResponse<T> = T | AgentResponseStream<T>;
|
|
72
|
+
export type AgentResponse<T> = T | TransferAgentOutput | AgentResponseStream<T>;
|
|
73
73
|
export type AgentResponseStream<T> = ReadableStream<AgentResponseChunk<T>>;
|
|
74
74
|
export type AgentResponseChunk<T> = AgentResponseDelta<T>;
|
|
75
75
|
export declare function isEmptyChunk<T>(chunk: AgentResponseChunk<T>): boolean;
|
|
@@ -77,14 +77,14 @@ export interface AgentResponseDelta<T> {
|
|
|
77
77
|
delta: {
|
|
78
78
|
text?: Partial<{
|
|
79
79
|
[key in keyof T as Extract<T[key], string> extends string ? key : never]: string;
|
|
80
|
-
}> | {
|
|
80
|
+
}> | Partial<{
|
|
81
81
|
[key: string]: string;
|
|
82
|
-
}
|
|
83
|
-
json?: Partial<T>;
|
|
82
|
+
}>;
|
|
83
|
+
json?: Partial<T | TransferAgentOutput>;
|
|
84
84
|
};
|
|
85
85
|
}
|
|
86
|
-
export type AgentProcessAsyncGenerator<O extends Message> = AsyncGenerator<AgentResponseChunk<O>, Partial<O> | undefined | void>;
|
|
87
|
-
export type AgentProcessResult<O extends Message> =
|
|
86
|
+
export type AgentProcessAsyncGenerator<O extends Message> = AsyncGenerator<AgentResponseChunk<O>, Partial<O | TransferAgentOutput> | undefined | void>;
|
|
87
|
+
export type AgentProcessResult<O extends Message> = AgentResponse<O> | AgentProcessAsyncGenerator<O> | Agent;
|
|
88
88
|
export type AgentInputOutputSchema<I extends Message = Message> = ZodType<I> | ((agent: Agent) => ZodType<I>);
|
|
89
89
|
export interface FunctionAgentOptions<I extends Message = Message, O extends Message = Message> extends AgentOptions<I, O> {
|
|
90
90
|
fn?: FunctionAgentFn<I, O>;
|
|
@@ -93,6 +93,6 @@ export declare class FunctionAgent<I extends Message = Message, O extends Messag
|
|
|
93
93
|
static from<I extends Message, O extends Message>(options: FunctionAgentOptions<I, O> | FunctionAgentFn<I, O>): FunctionAgent<I, O>;
|
|
94
94
|
constructor(options: FunctionAgentOptions<I, O>);
|
|
95
95
|
fn: FunctionAgentFn<I, O>;
|
|
96
|
-
process(input: I, context: Context
|
|
96
|
+
process(input: I, context: Context): PromiseOrValue<AgentProcessResult<O>>;
|
|
97
97
|
}
|
|
98
|
-
export type FunctionAgentFn<I extends Message =
|
|
98
|
+
export type FunctionAgentFn<I extends Message = any, O extends Message = any> = (input: I, context: Context) => PromiseOrValue<AgentProcessResult<O>>;
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import type { Context } from "../
|
|
2
|
+
import type { Context } from "../aigne/context.js";
|
|
3
3
|
import { ChatModel } from "../models/chat-model.js";
|
|
4
4
|
import type { ChatModelInput } from "../models/chat-model.js";
|
|
5
5
|
import { PromptBuilder } from "../prompt/prompt-builder.js";
|
|
6
6
|
import { Agent, type AgentOptions, type AgentProcessAsyncGenerator, type Message } from "./agent.js";
|
|
7
|
-
import { type TransferAgentOutput } from "./types.js";
|
|
8
7
|
export interface AIAgentOptions<I extends Message = Message, O extends Message = Message> extends AgentOptions<I, O> {
|
|
9
8
|
model?: ChatModel;
|
|
10
9
|
instructions?: string | PromptBuilder;
|
|
@@ -25,39 +24,39 @@ export declare const aiAgentOptionsSchema: z.ZodObject<{
|
|
|
25
24
|
publishTopic: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">, z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>]>>;
|
|
26
25
|
name: z.ZodOptional<z.ZodString>;
|
|
27
26
|
description: z.ZodOptional<z.ZodString>;
|
|
28
|
-
|
|
27
|
+
skills: z.ZodOptional<z.ZodArray<z.ZodUnion<[z.ZodType<Agent<Message, Message>, z.ZodTypeDef, Agent<Message, Message>>, z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>]>, "many">>;
|
|
29
28
|
disableLogging: z.ZodOptional<z.ZodBoolean>;
|
|
30
29
|
memory: z.ZodOptional<z.ZodUnion<[z.ZodBoolean, z.ZodAny, z.ZodAny]>>;
|
|
31
30
|
}, "strip", z.ZodTypeAny, {
|
|
32
|
-
tools?: (Agent<Message, Message> | ((...args: unknown[]) => unknown))[] | undefined;
|
|
33
|
-
toolChoice?: Agent<Message, Message> | "auto" | "none" | "required" | "router" | undefined;
|
|
34
|
-
name?: string | undefined;
|
|
35
31
|
description?: string | undefined;
|
|
32
|
+
memory?: any;
|
|
33
|
+
name?: string | undefined;
|
|
34
|
+
includeInputInOutput?: boolean | undefined;
|
|
35
|
+
subscribeTopic?: string | string[] | undefined;
|
|
36
|
+
publishTopic?: string | string[] | ((...args: unknown[]) => unknown) | undefined;
|
|
37
|
+
skills?: (Agent<Message, Message> | ((...args: unknown[]) => unknown))[] | undefined;
|
|
38
|
+
toolChoice?: Agent<Message, Message> | "auto" | "none" | "required" | "router" | undefined;
|
|
36
39
|
model?: ChatModel | undefined;
|
|
37
40
|
instructions?: string | PromptBuilder | undefined;
|
|
38
41
|
outputKey?: string | undefined;
|
|
39
42
|
enableHistory?: boolean | undefined;
|
|
40
43
|
maxHistoryMessages?: number | undefined;
|
|
44
|
+
disableLogging?: boolean | undefined;
|
|
45
|
+
}, {
|
|
46
|
+
description?: string | undefined;
|
|
47
|
+
memory?: any;
|
|
48
|
+
name?: string | undefined;
|
|
41
49
|
includeInputInOutput?: boolean | undefined;
|
|
42
50
|
subscribeTopic?: string | string[] | undefined;
|
|
43
51
|
publishTopic?: string | string[] | ((...args: unknown[]) => unknown) | undefined;
|
|
44
|
-
|
|
45
|
-
memory?: any;
|
|
46
|
-
}, {
|
|
47
|
-
tools?: (Agent<Message, Message> | ((...args: unknown[]) => unknown))[] | undefined;
|
|
52
|
+
skills?: (Agent<Message, Message> | ((...args: unknown[]) => unknown))[] | undefined;
|
|
48
53
|
toolChoice?: Agent<Message, Message> | "auto" | "none" | "required" | "router" | undefined;
|
|
49
|
-
name?: string | undefined;
|
|
50
|
-
description?: string | undefined;
|
|
51
54
|
model?: ChatModel | undefined;
|
|
52
55
|
instructions?: string | PromptBuilder | undefined;
|
|
53
56
|
outputKey?: string | undefined;
|
|
54
57
|
enableHistory?: boolean | undefined;
|
|
55
58
|
maxHistoryMessages?: number | undefined;
|
|
56
|
-
includeInputInOutput?: boolean | undefined;
|
|
57
|
-
subscribeTopic?: string | string[] | undefined;
|
|
58
|
-
publishTopic?: string | string[] | ((...args: unknown[]) => unknown) | undefined;
|
|
59
59
|
disableLogging?: boolean | undefined;
|
|
60
|
-
memory?: any;
|
|
61
60
|
}>;
|
|
62
61
|
export declare class AIAgent<I extends Message = Message, O extends Message = Message> extends Agent<I, O> {
|
|
63
62
|
static from<I extends Message, O extends Message>(options: AIAgentOptions<I, O>): AIAgent<I, O>;
|
|
@@ -66,6 +65,6 @@ export declare class AIAgent<I extends Message = Message, O extends Message = Me
|
|
|
66
65
|
instructions: PromptBuilder;
|
|
67
66
|
outputKey?: string;
|
|
68
67
|
toolChoice?: AIAgentToolChoice;
|
|
69
|
-
process(input: I, context: Context): AgentProcessAsyncGenerator<O
|
|
70
|
-
processRouter(input: I, model: ChatModel, modelInput: ChatModelInput, context: Context, toolsMap: Map<string, Agent>): AgentProcessAsyncGenerator<O
|
|
68
|
+
process(input: I, context: Context): AgentProcessAsyncGenerator<O>;
|
|
69
|
+
processRouter(input: I, model: ChatModel, modelInput: ChatModelInput, context: Context, toolsMap: Map<string, Agent>): AgentProcessAsyncGenerator<O>;
|
|
71
70
|
}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { Client, type ClientOptions } from "@modelcontextprotocol/sdk/client/index.js";
|
|
2
2
|
import { type SSEClientTransportOptions } from "@modelcontextprotocol/sdk/client/sse.js";
|
|
3
3
|
import { type StdioServerParameters } from "@modelcontextprotocol/sdk/client/stdio.js";
|
|
4
|
+
import { type StreamableHTTPClientTransportOptions } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
4
5
|
import type { RequestOptions } from "@modelcontextprotocol/sdk/shared/protocol.js";
|
|
5
6
|
import type { Transport } from "@modelcontextprotocol/sdk/shared/transport.js";
|
|
6
7
|
import type { CallToolResult, GetPromptResult, Implementation, ReadResourceResult, Request } from "@modelcontextprotocol/sdk/types.js";
|
|
7
8
|
import { type ZodType, z } from "zod";
|
|
8
|
-
import type { Context } from "../
|
|
9
|
+
import type { Context } from "../aigne/context.js";
|
|
9
10
|
import { type PromiseOrValue } from "../utils/type-utils.js";
|
|
10
11
|
import { Agent, type AgentOptions, type Message } from "./agent.js";
|
|
11
12
|
export interface MCPAgentOptions extends AgentOptions {
|
|
@@ -17,9 +18,14 @@ export type MCPServerOptions = SSEServerParameters | StdioServerParameters;
|
|
|
17
18
|
export type SSEServerParameters = {
|
|
18
19
|
url: string;
|
|
19
20
|
/**
|
|
20
|
-
*
|
|
21
|
+
* Whether to use the StreamableHTTPClientTransport instead of the SSEClientTransport.
|
|
22
|
+
* @default "sse"
|
|
21
23
|
*/
|
|
22
|
-
|
|
24
|
+
transport?: "sse" | "streamableHttp";
|
|
25
|
+
/**
|
|
26
|
+
* Additional options to pass to the SSEClientTransport or StreamableHTTPClientTransport.
|
|
27
|
+
*/
|
|
28
|
+
opts?: SSEClientTransportOptions | StreamableHTTPClientTransportOptions;
|
|
23
29
|
/**
|
|
24
30
|
* The timeout for requests to the server, in milliseconds.
|
|
25
31
|
* @default 60000
|
|
@@ -48,7 +54,7 @@ export declare class MCPAgent extends Agent {
|
|
|
48
54
|
readonly resources: MCPResource[] & {
|
|
49
55
|
[key: string]: MCPResource;
|
|
50
56
|
};
|
|
51
|
-
get
|
|
57
|
+
get isInvokable(): boolean;
|
|
52
58
|
process(_input: Message, _context?: Context): Promise<Message>;
|
|
53
59
|
shutdown(): Promise<void>;
|
|
54
60
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Context } from "../aigne/context.js";
|
|
2
|
+
import { type PromiseOrValue } from "../utils/type-utils.js";
|
|
3
|
+
import { Agent, type AgentOptions, type AgentProcessResult, type Message } from "./agent.js";
|
|
4
|
+
export declare enum ProcessMode {
|
|
5
|
+
/**
|
|
6
|
+
* Process the agents one by one, passing the output of each agent to the next.
|
|
7
|
+
*/
|
|
8
|
+
sequential = "sequential",
|
|
9
|
+
/**
|
|
10
|
+
* Process all agents in parallel, merging the output of all agents.
|
|
11
|
+
*/
|
|
12
|
+
parallel = "parallel"
|
|
13
|
+
}
|
|
14
|
+
export interface TeamAgentOptions<I extends Message, O extends Message> extends AgentOptions<I, O> {
|
|
15
|
+
/**
|
|
16
|
+
* The method to process the agents in the team.
|
|
17
|
+
* @default {ProcessMode.sequential}
|
|
18
|
+
*/
|
|
19
|
+
mode?: ProcessMode;
|
|
20
|
+
}
|
|
21
|
+
export declare class TeamAgent<I extends Message, O extends Message> extends Agent<I, O> {
|
|
22
|
+
static from<I extends Message, O extends Message>(options: TeamAgentOptions<I, O>): TeamAgent<I, O>;
|
|
23
|
+
constructor(options: TeamAgentOptions<I, O>);
|
|
24
|
+
mode: ProcessMode;
|
|
25
|
+
process(input: I, context: Context): PromiseOrValue<AgentProcessResult<O>>;
|
|
26
|
+
_processSequential(input: I, context: Context): PromiseOrValue<AgentProcessResult<O>>;
|
|
27
|
+
_processParallel(input: I, context: Context): PromiseOrValue<AgentProcessResult<O>>;
|
|
28
|
+
}
|
|
@@ -1,26 +1,25 @@
|
|
|
1
1
|
import { ReadableStream } from "node:stream/web";
|
|
2
|
-
import { type Context
|
|
3
|
-
import type { MessagePayload } from "../
|
|
4
|
-
import { type
|
|
5
|
-
import { Agent, type AgentOptions, type AgentProcessAsyncGenerator, type Message } from "./agent.js";
|
|
2
|
+
import { type Context } from "../aigne/context.js";
|
|
3
|
+
import type { MessagePayload } from "../aigne/message-queue.js";
|
|
4
|
+
import { type Agent, type AgentOptions, type AgentProcessResult, FunctionAgent, type FunctionAgentFn, type Message } from "./agent.js";
|
|
6
5
|
export interface UserAgentOptions<I extends Message = Message, O extends Message = Message> extends AgentOptions<I, O> {
|
|
7
6
|
context: Context;
|
|
8
|
-
process?:
|
|
9
|
-
activeAgent?:
|
|
7
|
+
process?: FunctionAgentFn<I, O>;
|
|
8
|
+
activeAgent?: Agent;
|
|
10
9
|
}
|
|
11
|
-
export declare class UserAgent<I extends Message = Message, O extends Message = Message> extends
|
|
10
|
+
export declare class UserAgent<I extends Message = Message, O extends Message = Message> extends FunctionAgent<I, O> {
|
|
12
11
|
static from<I extends Message, O extends Message>(options: UserAgentOptions<I, O>): UserAgent<I, O>;
|
|
13
12
|
constructor(options: UserAgentOptions<I, O>);
|
|
14
13
|
context: Context;
|
|
15
14
|
private _process?;
|
|
16
15
|
private activeAgent?;
|
|
17
|
-
|
|
18
|
-
process(input: I, context: Context):
|
|
16
|
+
invoke: Agent<I, O>["invoke"];
|
|
17
|
+
process(input: I, context: Context): Promise<AgentProcessResult<O>>;
|
|
19
18
|
publish: Context["publish"];
|
|
20
19
|
subscribe: Context["subscribe"];
|
|
21
20
|
unsubscribe: Context["unsubscribe"];
|
|
22
21
|
get stream(): ReadableStream<MessagePayload & {
|
|
23
22
|
topic: string;
|
|
24
23
|
}>;
|
|
25
|
-
protected
|
|
24
|
+
protected checkAgentInvokesUsage(_context: Context): void;
|
|
26
25
|
}
|
|
@@ -1,29 +1,26 @@
|
|
|
1
1
|
import { Agent } from "../agents/agent.js";
|
|
2
2
|
import { ChatModel } from "../models/chat-model.js";
|
|
3
|
-
import { type Context
|
|
3
|
+
import { AIGNEContext, type Context } from "./context.js";
|
|
4
4
|
import { MessageQueue } from "./message-queue.js";
|
|
5
5
|
import type { ContextLimits } from "./usage.js";
|
|
6
|
-
export interface
|
|
6
|
+
export interface AIGNEOptions {
|
|
7
7
|
name?: string;
|
|
8
8
|
description?: string;
|
|
9
9
|
model?: ChatModel;
|
|
10
|
-
|
|
10
|
+
skills?: Agent[];
|
|
11
11
|
agents?: Agent[];
|
|
12
12
|
limits?: ContextLimits;
|
|
13
13
|
}
|
|
14
|
-
export
|
|
15
|
-
returnActiveAgent?: boolean;
|
|
16
|
-
}
|
|
17
|
-
export declare class ExecutionEngine {
|
|
14
|
+
export declare class AIGNE {
|
|
18
15
|
static load({ path, ...options }: {
|
|
19
16
|
path: string;
|
|
20
|
-
} &
|
|
21
|
-
constructor(options?:
|
|
17
|
+
} & AIGNEOptions): Promise<AIGNE>;
|
|
18
|
+
constructor(options?: AIGNEOptions);
|
|
22
19
|
name?: string;
|
|
23
20
|
description?: string;
|
|
24
21
|
readonly messageQueue: MessageQueue;
|
|
25
22
|
model?: ChatModel;
|
|
26
|
-
readonly
|
|
23
|
+
readonly skills: Agent<import("../agents/agent.js").Message, import("../agents/agent.js").Message>[] & {
|
|
27
24
|
[key: string]: Agent<import("../agents/agent.js").Message, import("../agents/agent.js").Message>;
|
|
28
25
|
};
|
|
29
26
|
readonly agents: Agent<import("../agents/agent.js").Message, import("../agents/agent.js").Message>[] & {
|
|
@@ -31,9 +28,9 @@ export declare class ExecutionEngine {
|
|
|
31
28
|
};
|
|
32
29
|
limits?: ContextLimits;
|
|
33
30
|
addAgent(...agents: Agent[]): void;
|
|
34
|
-
newContext():
|
|
31
|
+
newContext(): AIGNEContext;
|
|
35
32
|
publish: Context["publish"];
|
|
36
|
-
|
|
33
|
+
invoke: Context["invoke"];
|
|
37
34
|
subscribe: Context["subscribe"];
|
|
38
35
|
unsubscribe: Context["unsubscribe"];
|
|
39
36
|
shutdown(): Promise<void>;
|