@aigne/core 1.10.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 +28 -0
- package/LICENSE +93 -0
- package/README.md +90 -0
- package/README.zh.md +90 -0
- package/lib/cjs/agents/agent.d.ts +21 -20
- package/lib/cjs/agents/agent.js +29 -26
- package/lib/cjs/agents/ai-agent.d.ts +9 -8
- package/lib/cjs/agents/ai-agent.js +20 -14
- 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-js.d.ts +2 -2
- package/lib/cjs/loader/agent-js.js +4 -5
- package/lib/cjs/loader/agent-yaml.d.ts +8 -5
- package/lib/cjs/loader/agent-yaml.js +21 -2
- package/lib/cjs/loader/index.d.ts +5 -5
- package/lib/cjs/loader/index.js +8 -19
- package/lib/cjs/models/chat-model.d.ts +1 -1
- package/lib/cjs/models/claude-chat-model.d.ts +3 -1
- package/lib/cjs/models/claude-chat-model.js +75 -60
- package/lib/cjs/models/openai-chat-model.d.ts +3 -3
- package/lib/cjs/models/openai-chat-model.js +1 -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/camelize.d.ts +13 -0
- package/lib/cjs/utils/camelize.js +16 -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 +10 -3
- package/lib/cjs/utils/stream-utils.js +51 -36
- 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 +21 -20
- package/lib/dts/agents/ai-agent.d.ts +9 -8
- 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-js.d.ts +2 -2
- package/lib/dts/loader/agent-yaml.d.ts +8 -5
- package/lib/dts/loader/index.d.ts +5 -5
- package/lib/dts/models/chat-model.d.ts +1 -1
- package/lib/dts/models/claude-chat-model.d.ts +3 -1
- 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/camelize.d.ts +13 -0
- package/lib/dts/utils/event-stream.d.ts +11 -0
- package/lib/dts/utils/stream-utils.d.ts +10 -3
- package/lib/dts/utils/type-utils.d.ts +4 -2
- package/lib/esm/agents/agent.d.ts +21 -20
- package/lib/esm/agents/agent.js +29 -27
- package/lib/esm/agents/ai-agent.d.ts +9 -8
- package/lib/esm/agents/ai-agent.js +20 -14
- 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-js.d.ts +2 -2
- package/lib/esm/loader/agent-js.js +4 -5
- package/lib/esm/loader/agent-yaml.d.ts +8 -5
- package/lib/esm/loader/agent-yaml.js +21 -2
- package/lib/esm/loader/index.d.ts +5 -5
- package/lib/esm/loader/index.js +8 -19
- package/lib/esm/models/chat-model.d.ts +1 -1
- package/lib/esm/models/claude-chat-model.d.ts +3 -1
- package/lib/esm/models/claude-chat-model.js +75 -60
- package/lib/esm/models/openai-chat-model.d.ts +3 -3
- package/lib/esm/models/openai-chat-model.js +1 -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/camelize.d.ts +13 -0
- package/lib/esm/utils/camelize.js +10 -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 +10 -3
- package/lib/esm/utils/stream-utils.js +49 -35
- package/lib/esm/utils/type-utils.d.ts +4 -2
- package/lib/esm/utils/type-utils.js +9 -2
- package/package.json +15 -5
- 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
|
@@ -10,14 +10,16 @@ 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
|
+
exports.stringToAgentResponseStream = stringToAgentResponseStream;
|
|
16
17
|
const fast_deep_equal_1 = __importDefault(require("fast-deep-equal"));
|
|
18
|
+
const agent_js_1 = require("../agents/agent.js");
|
|
17
19
|
const type_utils_js_1 = require("./type-utils.js");
|
|
18
20
|
function objectToAgentResponseStream(json) {
|
|
19
21
|
return new ReadableStream({
|
|
20
|
-
|
|
22
|
+
pull(controller) {
|
|
21
23
|
controller.enqueue({ delta: { json } });
|
|
22
24
|
controller.close();
|
|
23
25
|
},
|
|
@@ -63,40 +65,40 @@ async function agentResponseStreamToObject(stream) {
|
|
|
63
65
|
}
|
|
64
66
|
function asyncGeneratorToReadableStream(generator) {
|
|
65
67
|
return new ReadableStream({
|
|
66
|
-
async
|
|
68
|
+
async pull(controller) {
|
|
67
69
|
try {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
if (chunk.
|
|
71
|
-
|
|
72
|
-
controller.enqueue({ delta: { json: chunk.value } });
|
|
73
|
-
}
|
|
74
|
-
else {
|
|
75
|
-
controller.enqueue(chunk.value);
|
|
76
|
-
}
|
|
70
|
+
const chunk = await generator.next();
|
|
71
|
+
if (chunk.value) {
|
|
72
|
+
if (chunk.done) {
|
|
73
|
+
controller.enqueue({ delta: { json: chunk.value } });
|
|
77
74
|
}
|
|
78
|
-
|
|
79
|
-
|
|
75
|
+
else {
|
|
76
|
+
controller.enqueue(chunk.value);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (chunk.done) {
|
|
80
|
+
controller.close();
|
|
80
81
|
}
|
|
81
82
|
}
|
|
82
83
|
catch (error) {
|
|
83
84
|
controller.error(error);
|
|
84
85
|
}
|
|
85
|
-
finally {
|
|
86
|
-
controller.close();
|
|
87
|
-
}
|
|
88
86
|
},
|
|
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
|
+
controller.enqueue(chunk);
|
|
99
100
|
mergeAgentResponseChunk(json, value);
|
|
101
|
+
return;
|
|
100
102
|
}
|
|
101
103
|
const result = await callback(json);
|
|
102
104
|
if (result && !(0, fast_deep_equal_1.default)(result, json)) {
|
|
@@ -105,13 +107,11 @@ function onAgentResponseStreamEnd(stream, callback, options) {
|
|
|
105
107
|
chunk = options.processChunk(chunk);
|
|
106
108
|
controller.enqueue(chunk);
|
|
107
109
|
}
|
|
110
|
+
controller.close();
|
|
108
111
|
}
|
|
109
112
|
catch (error) {
|
|
110
113
|
controller.error(options?.errorCallback?.(error) ?? error);
|
|
111
114
|
}
|
|
112
|
-
finally {
|
|
113
|
-
controller.close();
|
|
114
|
-
}
|
|
115
115
|
},
|
|
116
116
|
});
|
|
117
117
|
}
|
|
@@ -127,24 +127,34 @@ async function* arrayToAgentProcessAsyncGenerator(chunks, result) {
|
|
|
127
127
|
if (result !== undefined)
|
|
128
128
|
return result;
|
|
129
129
|
}
|
|
130
|
-
function
|
|
130
|
+
function arrayToReadableStream(chunks) {
|
|
131
|
+
const list = [...chunks];
|
|
131
132
|
return new ReadableStream({
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
}
|
|
138
|
-
controller.enqueue(chunk);
|
|
133
|
+
pull(controller) {
|
|
134
|
+
const item = list.shift();
|
|
135
|
+
if (!item) {
|
|
136
|
+
controller.close();
|
|
137
|
+
return;
|
|
139
138
|
}
|
|
140
|
-
|
|
139
|
+
if (item instanceof Error) {
|
|
140
|
+
controller.error(item);
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
controller.enqueue(item);
|
|
141
144
|
},
|
|
142
145
|
});
|
|
143
146
|
}
|
|
144
|
-
async function readableStreamToArray(stream) {
|
|
147
|
+
async function readableStreamToArray(stream, options) {
|
|
145
148
|
const result = [];
|
|
146
|
-
|
|
147
|
-
|
|
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);
|
|
148
158
|
}
|
|
149
159
|
return result;
|
|
150
160
|
}
|
|
@@ -157,3 +167,8 @@ async function* readableStreamToAsyncIterator(stream) {
|
|
|
157
167
|
yield value;
|
|
158
168
|
}
|
|
159
169
|
}
|
|
170
|
+
function stringToAgentResponseStream(str, key = "text") {
|
|
171
|
+
const segmenter = new Intl.Segmenter(undefined, { granularity: "word" });
|
|
172
|
+
const segments = segmenter.segment(str);
|
|
173
|
+
return arrayToReadableStream(Array.from(segments).map((segment) => ({ delta: { text: { [key]: segment.segment } } })));
|
|
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,52 +38,53 @@ 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
|
+
export declare function isEmptyChunk<T>(chunk: AgentResponseChunk<T>): boolean;
|
|
75
76
|
export interface AgentResponseDelta<T> {
|
|
76
77
|
delta: {
|
|
77
78
|
text?: Partial<{
|
|
78
79
|
[key in keyof T as Extract<T[key], string> extends string ? key : never]: string;
|
|
79
|
-
}> | {
|
|
80
|
+
}> | Partial<{
|
|
80
81
|
[key: string]: string;
|
|
81
|
-
}
|
|
82
|
-
json?: Partial<T>;
|
|
82
|
+
}>;
|
|
83
|
+
json?: Partial<T | TransferAgentOutput>;
|
|
83
84
|
};
|
|
84
85
|
}
|
|
85
|
-
export type AgentProcessAsyncGenerator<O extends Message> = AsyncGenerator<AgentResponseChunk<O>, Partial<O> | undefined | void>;
|
|
86
|
-
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;
|
|
87
88
|
export type AgentInputOutputSchema<I extends Message = Message> = ZodType<I> | ((agent: Agent) => ZodType<I>);
|
|
88
89
|
export interface FunctionAgentOptions<I extends Message = Message, O extends Message = Message> extends AgentOptions<I, O> {
|
|
89
90
|
fn?: FunctionAgentFn<I, O>;
|
|
@@ -92,6 +93,6 @@ export declare class FunctionAgent<I extends Message = Message, O extends Messag
|
|
|
92
93
|
static from<I extends Message, O extends Message>(options: FunctionAgentOptions<I, O> | FunctionAgentFn<I, O>): FunctionAgent<I, O>;
|
|
93
94
|
constructor(options: FunctionAgentOptions<I, O>);
|
|
94
95
|
fn: FunctionAgentFn<I, O>;
|
|
95
|
-
process(input: I, context: Context
|
|
96
|
+
process(input: I, context: Context): PromiseOrValue<AgentProcessResult<O>>;
|
|
96
97
|
}
|
|
97
|
-
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,9 +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
|
+
import type { ChatModelInput } from "../models/chat-model.js";
|
|
4
5
|
import { PromptBuilder } from "../prompt/prompt-builder.js";
|
|
5
6
|
import { Agent, type AgentOptions, type AgentProcessAsyncGenerator, type Message } from "./agent.js";
|
|
6
|
-
import { type TransferAgentOutput } from "./types.js";
|
|
7
7
|
export interface AIAgentOptions<I extends Message = Message, O extends Message = Message> extends AgentOptions<I, O> {
|
|
8
8
|
model?: ChatModel;
|
|
9
9
|
instructions?: string | PromptBuilder;
|
|
@@ -24,18 +24,18 @@ export declare const aiAgentOptionsSchema: z.ZodObject<{
|
|
|
24
24
|
publishTopic: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">, z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>]>>;
|
|
25
25
|
name: z.ZodOptional<z.ZodString>;
|
|
26
26
|
description: z.ZodOptional<z.ZodString>;
|
|
27
|
-
|
|
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">>;
|
|
28
28
|
disableLogging: z.ZodOptional<z.ZodBoolean>;
|
|
29
29
|
memory: z.ZodOptional<z.ZodUnion<[z.ZodBoolean, z.ZodAny, z.ZodAny]>>;
|
|
30
30
|
}, "strip", z.ZodTypeAny, {
|
|
31
31
|
description?: string | undefined;
|
|
32
32
|
memory?: any;
|
|
33
|
+
name?: string | undefined;
|
|
33
34
|
includeInputInOutput?: boolean | undefined;
|
|
34
35
|
subscribeTopic?: string | string[] | undefined;
|
|
35
36
|
publishTopic?: string | string[] | ((...args: unknown[]) => unknown) | undefined;
|
|
36
|
-
|
|
37
|
+
skills?: (Agent<Message, Message> | ((...args: unknown[]) => unknown))[] | undefined;
|
|
37
38
|
toolChoice?: Agent<Message, Message> | "auto" | "none" | "required" | "router" | undefined;
|
|
38
|
-
name?: string | undefined;
|
|
39
39
|
model?: ChatModel | undefined;
|
|
40
40
|
instructions?: string | PromptBuilder | undefined;
|
|
41
41
|
outputKey?: string | undefined;
|
|
@@ -45,12 +45,12 @@ export declare const aiAgentOptionsSchema: z.ZodObject<{
|
|
|
45
45
|
}, {
|
|
46
46
|
description?: string | undefined;
|
|
47
47
|
memory?: any;
|
|
48
|
+
name?: string | undefined;
|
|
48
49
|
includeInputInOutput?: boolean | undefined;
|
|
49
50
|
subscribeTopic?: string | string[] | undefined;
|
|
50
51
|
publishTopic?: string | string[] | ((...args: unknown[]) => unknown) | undefined;
|
|
51
|
-
|
|
52
|
+
skills?: (Agent<Message, Message> | ((...args: unknown[]) => unknown))[] | undefined;
|
|
52
53
|
toolChoice?: Agent<Message, Message> | "auto" | "none" | "required" | "router" | undefined;
|
|
53
|
-
name?: string | undefined;
|
|
54
54
|
model?: ChatModel | undefined;
|
|
55
55
|
instructions?: string | PromptBuilder | undefined;
|
|
56
56
|
outputKey?: string | undefined;
|
|
@@ -65,5 +65,6 @@ export declare class AIAgent<I extends Message = Message, O extends Message = Me
|
|
|
65
65
|
instructions: PromptBuilder;
|
|
66
66
|
outputKey?: string;
|
|
67
67
|
toolChoice?: AIAgentToolChoice;
|
|
68
|
-
process(input: I, context: Context): 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>;
|
|
69
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>;
|