@aigne/core 1.6.0 → 1.8.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 +27 -0
- package/lib/cjs/agents/agent.d.ts +5 -2
- package/lib/cjs/agents/agent.js +42 -24
- package/lib/cjs/agents/ai-agent.d.ts +8 -8
- package/lib/cjs/agents/ai-agent.js +5 -2
- package/lib/cjs/agents/mcp-agent.d.ts +12 -2
- package/lib/cjs/agents/mcp-agent.js +45 -27
- package/lib/cjs/agents/user-agent.d.ts +9 -9
- package/lib/cjs/agents/user-agent.js +26 -16
- package/lib/cjs/execution-engine/context.d.ts +84 -46
- package/lib/cjs/execution-engine/context.js +136 -98
- package/lib/cjs/execution-engine/execution-engine.d.ts +16 -47
- package/lib/cjs/execution-engine/execution-engine.js +14 -41
- package/lib/cjs/execution-engine/message-queue.d.ts +3 -3
- package/lib/cjs/execution-engine/message-queue.js +32 -2
- package/lib/cjs/execution-engine/usage.d.ts +11 -0
- package/lib/cjs/execution-engine/usage.js +10 -0
- package/lib/cjs/loader/agent-js.js +1 -1
- package/lib/cjs/loader/agent-yaml.d.ts +1 -0
- package/lib/cjs/loader/agent-yaml.js +4 -0
- package/lib/cjs/loader/index.d.ts +72 -1
- package/lib/cjs/loader/index.js +13 -13
- package/lib/cjs/models/chat-model.d.ts +3 -2
- package/lib/cjs/models/chat-model.js +6 -5
- package/lib/cjs/models/claude-chat-model.js +11 -8
- package/lib/cjs/models/openai-chat-model.js +5 -2
- package/lib/cjs/prompt/prompt-builder.d.ts +1 -1
- package/lib/cjs/prompt/prompt-builder.js +3 -1
- package/lib/cjs/utils/json-schema.js +2 -2
- package/lib/cjs/utils/logger.d.ts +3 -15
- package/lib/cjs/utils/logger.js +3 -77
- package/lib/cjs/utils/mcp-utils.js +1 -5
- package/lib/cjs/utils/model-utils.js +2 -2
- package/lib/cjs/utils/type-utils.d.ts +1 -0
- package/lib/cjs/utils/typed-event-emtter.d.ts +10 -0
- package/lib/cjs/utils/typed-event-emtter.js +2 -0
- package/lib/dts/agents/agent.d.ts +5 -2
- package/lib/dts/agents/ai-agent.d.ts +8 -8
- package/lib/dts/agents/mcp-agent.d.ts +12 -2
- package/lib/dts/agents/user-agent.d.ts +9 -9
- package/lib/dts/execution-engine/context.d.ts +84 -46
- package/lib/dts/execution-engine/execution-engine.d.ts +16 -47
- package/lib/dts/execution-engine/message-queue.d.ts +3 -3
- package/lib/dts/execution-engine/usage.d.ts +11 -0
- package/lib/dts/loader/agent-yaml.d.ts +1 -0
- package/lib/dts/loader/index.d.ts +72 -1
- package/lib/dts/models/chat-model.d.ts +3 -2
- package/lib/dts/prompt/prompt-builder.d.ts +1 -1
- package/lib/dts/utils/logger.d.ts +3 -15
- package/lib/dts/utils/type-utils.d.ts +1 -0
- package/lib/dts/utils/typed-event-emtter.d.ts +10 -0
- package/lib/esm/agents/agent.d.ts +5 -2
- package/lib/esm/agents/agent.js +42 -24
- package/lib/esm/agents/ai-agent.d.ts +8 -8
- package/lib/esm/agents/ai-agent.js +5 -2
- package/lib/esm/agents/mcp-agent.d.ts +12 -2
- package/lib/esm/agents/mcp-agent.js +46 -28
- package/lib/esm/agents/user-agent.d.ts +9 -9
- package/lib/esm/agents/user-agent.js +26 -16
- package/lib/esm/execution-engine/context.d.ts +84 -46
- package/lib/esm/execution-engine/context.js +135 -98
- package/lib/esm/execution-engine/execution-engine.d.ts +16 -47
- package/lib/esm/execution-engine/execution-engine.js +15 -39
- package/lib/esm/execution-engine/message-queue.d.ts +3 -3
- package/lib/esm/execution-engine/message-queue.js +33 -3
- package/lib/esm/execution-engine/usage.d.ts +11 -0
- package/lib/esm/execution-engine/usage.js +7 -0
- package/lib/esm/loader/agent-js.js +1 -1
- package/lib/esm/loader/agent-yaml.d.ts +1 -0
- package/lib/esm/loader/agent-yaml.js +4 -0
- package/lib/esm/loader/index.d.ts +72 -1
- package/lib/esm/loader/index.js +13 -14
- package/lib/esm/models/chat-model.d.ts +3 -2
- package/lib/esm/models/chat-model.js +6 -5
- package/lib/esm/models/claude-chat-model.js +11 -8
- package/lib/esm/models/openai-chat-model.js +5 -2
- package/lib/esm/prompt/prompt-builder.d.ts +1 -1
- package/lib/esm/prompt/prompt-builder.js +3 -1
- package/lib/esm/utils/json-schema.js +2 -2
- package/lib/esm/utils/logger.d.ts +3 -15
- package/lib/esm/utils/logger.js +3 -77
- package/lib/esm/utils/mcp-utils.js +1 -5
- package/lib/esm/utils/model-utils.js +2 -2
- package/lib/esm/utils/type-utils.d.ts +1 -0
- package/lib/esm/utils/typed-event-emtter.d.ts +10 -0
- package/lib/esm/utils/typed-event-emtter.js +1 -0
- package/package.json +11 -9
- package/lib/cjs/utils/run-chat-loop.d.ts +0 -11
- package/lib/cjs/utils/run-chat-loop.js +0 -82
- package/lib/dts/utils/run-chat-loop.d.ts +0 -11
- package/lib/esm/utils/run-chat-loop.d.ts +0 -11
- package/lib/esm/utils/run-chat-loop.js +0 -76
|
@@ -28,6 +28,10 @@ export declare const aiAgentOptionsSchema: z.ZodObject<{
|
|
|
28
28
|
memory: z.ZodOptional<z.ZodUnion<[z.ZodBoolean, z.ZodAny, z.ZodAny]>>;
|
|
29
29
|
}, "strip", z.ZodTypeAny, {
|
|
30
30
|
description?: string | undefined;
|
|
31
|
+
memory?: any;
|
|
32
|
+
includeInputInOutput?: boolean | undefined;
|
|
33
|
+
subscribeTopic?: string | string[] | undefined;
|
|
34
|
+
publishTopic?: string | string[] | ((...args: unknown[]) => unknown) | undefined;
|
|
31
35
|
tools?: (Agent<Message, Message> | ((...args: unknown[]) => unknown))[] | undefined;
|
|
32
36
|
toolChoice?: Agent<Message, Message> | "auto" | "none" | "required" | "router" | undefined;
|
|
33
37
|
name?: string | undefined;
|
|
@@ -36,13 +40,13 @@ export declare const aiAgentOptionsSchema: z.ZodObject<{
|
|
|
36
40
|
outputKey?: string | undefined;
|
|
37
41
|
enableHistory?: boolean | undefined;
|
|
38
42
|
maxHistoryMessages?: number | undefined;
|
|
39
|
-
includeInputInOutput?: boolean | undefined;
|
|
40
|
-
subscribeTopic?: string | string[] | undefined;
|
|
41
|
-
publishTopic?: string | string[] | ((...args: unknown[]) => unknown) | undefined;
|
|
42
43
|
disableLogging?: boolean | undefined;
|
|
43
|
-
memory?: any;
|
|
44
44
|
}, {
|
|
45
45
|
description?: string | undefined;
|
|
46
|
+
memory?: any;
|
|
47
|
+
includeInputInOutput?: boolean | undefined;
|
|
48
|
+
subscribeTopic?: string | string[] | undefined;
|
|
49
|
+
publishTopic?: string | string[] | ((...args: unknown[]) => unknown) | undefined;
|
|
46
50
|
tools?: (Agent<Message, Message> | ((...args: unknown[]) => unknown))[] | undefined;
|
|
47
51
|
toolChoice?: Agent<Message, Message> | "auto" | "none" | "required" | "router" | undefined;
|
|
48
52
|
name?: string | undefined;
|
|
@@ -51,11 +55,7 @@ export declare const aiAgentOptionsSchema: z.ZodObject<{
|
|
|
51
55
|
outputKey?: string | undefined;
|
|
52
56
|
enableHistory?: boolean | undefined;
|
|
53
57
|
maxHistoryMessages?: number | undefined;
|
|
54
|
-
includeInputInOutput?: boolean | undefined;
|
|
55
|
-
subscribeTopic?: string | string[] | undefined;
|
|
56
|
-
publishTopic?: string | string[] | ((...args: unknown[]) => unknown) | undefined;
|
|
57
58
|
disableLogging?: boolean | undefined;
|
|
58
|
-
memory?: any;
|
|
59
59
|
}>;
|
|
60
60
|
export declare class AIAgent<I extends Message = Message, O extends Message = Message> extends Agent<I, O> {
|
|
61
61
|
static from<I extends Message, O extends Message>(options: AIAgentOptions<I, O>): AIAgent<I, O>;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Client, type ClientOptions } from "@modelcontextprotocol/sdk/client/index.js";
|
|
2
|
+
import { type SSEClientTransportOptions } from "@modelcontextprotocol/sdk/client/sse.js";
|
|
2
3
|
import { type StdioServerParameters } from "@modelcontextprotocol/sdk/client/stdio.js";
|
|
3
4
|
import type { RequestOptions } from "@modelcontextprotocol/sdk/shared/protocol.js";
|
|
4
5
|
import type { Transport } from "@modelcontextprotocol/sdk/shared/transport.js";
|
|
@@ -15,6 +16,15 @@ export interface MCPAgentOptions extends AgentOptions {
|
|
|
15
16
|
export type MCPServerOptions = SSEServerParameters | StdioServerParameters;
|
|
16
17
|
export type SSEServerParameters = {
|
|
17
18
|
url: string;
|
|
19
|
+
/**
|
|
20
|
+
* Additional options to pass to the SSEClientTransport.
|
|
21
|
+
*/
|
|
22
|
+
opts?: SSEClientTransportOptions;
|
|
23
|
+
/**
|
|
24
|
+
* The timeout for requests to the server, in milliseconds.
|
|
25
|
+
* @default 60000
|
|
26
|
+
*/
|
|
27
|
+
timeout?: number;
|
|
18
28
|
/**
|
|
19
29
|
* Whether to automatically reconnect to the server if the connection is lost.
|
|
20
30
|
* @default 10 set to 0 to disable automatic reconnection
|
|
@@ -31,7 +41,7 @@ export declare class MCPAgent extends Agent {
|
|
|
31
41
|
static from(options: MCPAgentOptions): MCPAgent;
|
|
32
42
|
private static fromTransport;
|
|
33
43
|
constructor(options: MCPAgentOptions);
|
|
34
|
-
|
|
44
|
+
client: Client;
|
|
35
45
|
readonly prompts: MCPPrompt[] & {
|
|
36
46
|
[key: string]: MCPPrompt;
|
|
37
47
|
};
|
|
@@ -44,6 +54,7 @@ export declare class MCPAgent extends Agent {
|
|
|
44
54
|
}
|
|
45
55
|
export interface ClientWithReconnectOptions {
|
|
46
56
|
transportCreator?: () => PromiseOrValue<Transport>;
|
|
57
|
+
timeout?: number;
|
|
47
58
|
maxReconnects?: number;
|
|
48
59
|
shouldReconnect?: (error: Error) => boolean;
|
|
49
60
|
}
|
|
@@ -60,7 +71,6 @@ export interface MCPBaseOptions<I extends Message = Message, O extends Message =
|
|
|
60
71
|
export declare abstract class MCPBase<I extends Message, O extends Message> extends Agent<I, O> {
|
|
61
72
|
constructor(options: MCPBaseOptions<I, O>);
|
|
62
73
|
protected client: ClientWithReconnect;
|
|
63
|
-
protected get mcpServer(): string | undefined;
|
|
64
74
|
}
|
|
65
75
|
export declare class MCPTool extends MCPBase<Message, CallToolResult> {
|
|
66
76
|
process(input: Message): Promise<CallToolResult>;
|
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
import { ReadableStream } from "node:stream/web";
|
|
2
|
-
import type
|
|
3
|
-
import type { MessagePayload
|
|
2
|
+
import { type Context, type Runnable } from "../execution-engine/context.js";
|
|
3
|
+
import type { MessagePayload } from "../execution-engine/message-queue.js";
|
|
4
4
|
import { type PromiseOrValue } from "../utils/type-utils.js";
|
|
5
5
|
import { Agent, type AgentOptions, type Message } from "./agent.js";
|
|
6
6
|
export interface UserAgentOptions<I extends Message = Message, O extends Message = Message> extends AgentOptions<I, O> {
|
|
7
7
|
context: Context;
|
|
8
8
|
process?: (input: I, context: Context) => PromiseOrValue<O>;
|
|
9
|
+
activeAgent?: Runnable;
|
|
9
10
|
}
|
|
10
11
|
export declare class UserAgent<I extends Message = Message, O extends Message = Message> extends Agent<I, O> {
|
|
11
12
|
static from<I extends Message, O extends Message>(options: UserAgentOptions<I, O>): UserAgent<I, O>;
|
|
12
13
|
constructor(options: UserAgentOptions<I, O>);
|
|
13
|
-
|
|
14
|
-
private get ctx();
|
|
14
|
+
context: Context;
|
|
15
15
|
private _process?;
|
|
16
|
+
private activeAgent?;
|
|
16
17
|
call(input: string | I, context?: Context): Promise<O>;
|
|
17
18
|
process(input: I, context: Context): Promise<O>;
|
|
18
|
-
publish
|
|
19
|
-
subscribe
|
|
20
|
-
|
|
21
|
-
subscribe(topic: string, listener?: MessageQueueListener): Unsubscribe | Promise<MessagePayload>;
|
|
22
|
-
unsubscribe(topic: string, listener: MessageQueueListener): void;
|
|
19
|
+
publish: Context["publish"];
|
|
20
|
+
subscribe: Context["subscribe"];
|
|
21
|
+
unsubscribe: Context["unsubscribe"];
|
|
23
22
|
get stream(): ReadableStream<MessagePayload & {
|
|
24
23
|
topic: string;
|
|
25
24
|
}>;
|
|
25
|
+
protected checkUsageAgentCalls(_context: Context): void;
|
|
26
26
|
}
|
|
@@ -2,19 +2,36 @@ import EventEmitter from "node:events";
|
|
|
2
2
|
import { Agent, type FunctionAgentFn, type Message } from "../agents/agent.js";
|
|
3
3
|
import { UserAgent } from "../agents/user-agent.js";
|
|
4
4
|
import type { ChatModel } from "../models/chat-model.js";
|
|
5
|
+
import { type OmitPropertiesFromArrayFirstElement } from "../utils/type-utils.js";
|
|
6
|
+
import type { Args, Listener, TypedEventEmitter } from "../utils/typed-event-emtter.js";
|
|
5
7
|
import { type MessagePayload, MessageQueue, type MessageQueueListener, type Unsubscribe } from "./message-queue.js";
|
|
8
|
+
import { type ContextLimits, type ContextUsage } from "./usage.js";
|
|
6
9
|
export type Runnable<I extends Message = Message, O extends Message = Message> = Agent<I, O> | FunctionAgentFn;
|
|
7
|
-
export interface
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
export interface AgentEvent {
|
|
11
|
+
parentContextId?: string;
|
|
12
|
+
contextId: string;
|
|
13
|
+
timestamp: number;
|
|
14
|
+
agent: Agent;
|
|
11
15
|
}
|
|
12
|
-
export interface
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
+
export interface ContextEventMap {
|
|
17
|
+
agentStarted: [AgentEvent & {
|
|
18
|
+
input: Message;
|
|
19
|
+
}];
|
|
20
|
+
agentSucceed: [AgentEvent & {
|
|
21
|
+
output: Message;
|
|
22
|
+
}];
|
|
23
|
+
agentFailed: [AgentEvent & {
|
|
24
|
+
error: Error;
|
|
25
|
+
}];
|
|
16
26
|
}
|
|
17
|
-
export
|
|
27
|
+
export type ContextEmitEventMap = {
|
|
28
|
+
[K in keyof ContextEventMap]: OmitPropertiesFromArrayFirstElement<ContextEventMap[K], "contextId" | "parentContextId" | "timestamp">;
|
|
29
|
+
};
|
|
30
|
+
export interface CallOptions {
|
|
31
|
+
returnActiveAgent?: boolean;
|
|
32
|
+
disableTransfer?: boolean;
|
|
33
|
+
}
|
|
34
|
+
export interface Context extends TypedEventEmitter<ContextEventMap, ContextEmitEventMap> {
|
|
18
35
|
model?: ChatModel;
|
|
19
36
|
tools?: Agent[];
|
|
20
37
|
usage: ContextUsage;
|
|
@@ -26,13 +43,6 @@ export interface Context extends EventEmitter {
|
|
|
26
43
|
* @returns User agent
|
|
27
44
|
*/
|
|
28
45
|
call<I extends Message, O extends Message>(agent: Runnable<I, O>): UserAgent<I, O>;
|
|
29
|
-
/**
|
|
30
|
-
* Call an agent with a message
|
|
31
|
-
* @param agent Agent to call
|
|
32
|
-
* @param message Message to pass to the agent
|
|
33
|
-
* @returns the output of the agent
|
|
34
|
-
*/
|
|
35
|
-
call<I extends Message, O extends Message>(agent: Runnable<I, O>, message: I | string): Promise<O>;
|
|
36
46
|
/**
|
|
37
47
|
* Call an agent with a message and return the output and the active agent
|
|
38
48
|
* @param agent Agent to call
|
|
@@ -40,54 +50,82 @@ export interface Context extends EventEmitter {
|
|
|
40
50
|
* @param options.returnActiveAgent return the active agent
|
|
41
51
|
* @returns the output of the agent and the final active agent
|
|
42
52
|
*/
|
|
43
|
-
call<I extends Message, O extends Message>(agent: Runnable<I, O>, message: I | string, options: {
|
|
53
|
+
call<I extends Message, O extends Message>(agent: Runnable<I, O>, message: I | string, options: CallOptions & {
|
|
44
54
|
returnActiveAgent: true;
|
|
45
55
|
}): Promise<[O, Runnable]>;
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
56
|
+
/**
|
|
57
|
+
* Call an agent with a message
|
|
58
|
+
* @param agent Agent to call
|
|
59
|
+
* @param message Message to pass to the agent
|
|
60
|
+
* @returns the output of the agent
|
|
61
|
+
*/
|
|
62
|
+
call<I extends Message, O extends Message>(agent: Runnable<I, O>, message: I | string, options?: CallOptions): Promise<O>;
|
|
63
|
+
call<I extends Message, O extends Message>(agent: Runnable<I, O>, message?: I | string, options?: CallOptions): UserAgent<I, O> | Promise<O | [O, Runnable]>;
|
|
49
64
|
/**
|
|
50
65
|
* Publish a message to a topic, the engine will call the listeners of the topic
|
|
51
66
|
* @param topic topic name, or an array of topic names
|
|
52
|
-
* @param
|
|
53
|
-
* @param from the agent who publish the message, if not provided, it will be treated as a user message
|
|
67
|
+
* @param payload message to publish
|
|
54
68
|
*/
|
|
55
|
-
publish(topic: string | string[],
|
|
69
|
+
publish(topic: string | string[], payload: Omit<MessagePayload, "context">): void;
|
|
56
70
|
subscribe(topic: string, listener?: undefined): Promise<MessagePayload>;
|
|
57
71
|
subscribe(topic: string, listener: MessageQueueListener): Unsubscribe;
|
|
58
72
|
subscribe(topic: string, listener?: MessageQueueListener): Unsubscribe | Promise<MessagePayload>;
|
|
73
|
+
subscribe(topic: string, listener?: MessageQueueListener): Unsubscribe | Promise<MessagePayload>;
|
|
59
74
|
unsubscribe(topic: string, listener: MessageQueueListener): void;
|
|
75
|
+
/**
|
|
76
|
+
* Create a child context with the same configuration as the parent context.
|
|
77
|
+
* If `reset` is true, the child context will have a new state (such as: usage).
|
|
78
|
+
*
|
|
79
|
+
* @param options
|
|
80
|
+
* @param options.reset create a new context with initial state (such as: usage)
|
|
81
|
+
* @returns new context
|
|
82
|
+
*/
|
|
83
|
+
newContext(options?: {
|
|
84
|
+
reset?: boolean;
|
|
85
|
+
}): Context;
|
|
86
|
+
}
|
|
87
|
+
export declare function createPublishMessage(message: string | Message, from?: Agent): Omit<MessagePayload, "context">;
|
|
88
|
+
export declare class ExecutionContext implements Context {
|
|
89
|
+
constructor(parent?: ConstructorParameters<typeof ExecutionContextInternal>[0]);
|
|
90
|
+
parentId?: string;
|
|
91
|
+
id: string;
|
|
92
|
+
readonly internal: ExecutionContextInternal;
|
|
93
|
+
get model(): ChatModel | undefined;
|
|
94
|
+
get tools(): Agent<Message, Message>[] | undefined;
|
|
95
|
+
get limits(): ContextLimits | undefined;
|
|
96
|
+
get status(): "normal" | "timeout";
|
|
97
|
+
get usage(): ContextUsage;
|
|
98
|
+
newContext({ reset }?: {
|
|
99
|
+
reset?: boolean;
|
|
100
|
+
}): ExecutionContext;
|
|
101
|
+
call: Context["call"];
|
|
102
|
+
publish: Context["publish"];
|
|
103
|
+
subscribe: Context["subscribe"];
|
|
104
|
+
unsubscribe: Context["unsubscribe"];
|
|
105
|
+
emit<K extends keyof ContextEmitEventMap>(eventName: K, ...args: Args<K, ContextEmitEventMap>): boolean;
|
|
106
|
+
on<K extends keyof ContextEventMap>(eventName: K, listener: Listener<K, ContextEventMap>): this;
|
|
107
|
+
once<K extends keyof ContextEventMap>(eventName: K, listener: Listener<K, ContextEventMap>): this;
|
|
108
|
+
off<K extends keyof ContextEventMap>(eventName: K, listener: Listener<K, ContextEventMap>): this;
|
|
60
109
|
}
|
|
61
|
-
|
|
62
|
-
private readonly
|
|
63
|
-
constructor(
|
|
64
|
-
model?: ChatModel;
|
|
65
|
-
tools?: Agent[];
|
|
66
|
-
limits?: ContextLimits;
|
|
110
|
+
declare class ExecutionContextInternal {
|
|
111
|
+
private readonly parent?;
|
|
112
|
+
constructor(parent?: (Pick<Context, "model" | "tools" | "limits"> & {
|
|
67
113
|
messageQueue?: MessageQueue;
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
114
|
+
}) | undefined);
|
|
115
|
+
readonly messageQueue: MessageQueue;
|
|
116
|
+
readonly events: EventEmitter<ContextEventMap>;
|
|
71
117
|
get model(): ChatModel | undefined;
|
|
72
118
|
get tools(): Agent<Message, Message>[] | undefined;
|
|
119
|
+
get limits(): ContextLimits | undefined;
|
|
73
120
|
usage: ContextUsage;
|
|
74
|
-
limits?: ContextLimits | undefined;
|
|
75
121
|
private abortController;
|
|
76
122
|
private timer?;
|
|
77
123
|
private initTimeout;
|
|
78
124
|
get status(): "normal" | "timeout";
|
|
79
|
-
call<I extends Message, O extends Message>(agent: Runnable<I, O
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}): Promise<[O, Runnable]>;
|
|
84
|
-
call<I extends Message, O extends Message>(agent: Runnable<I, O>, message?: I | string, options?: {
|
|
85
|
-
returnActiveAgent?: boolean;
|
|
86
|
-
}): UserAgent<I, O> | Promise<O | [O, Runnable]>;
|
|
87
|
-
publish(topic: string | string[], message: Message | string, from?: Agent): void;
|
|
88
|
-
subscribe(topic: string, listener?: undefined): Promise<MessagePayload>;
|
|
89
|
-
subscribe(topic: string, listener: MessageQueueListener): Unsubscribe;
|
|
90
|
-
unsubscribe(topic: string, listener: MessageQueueListener): void;
|
|
91
|
-
emit(eventName: string | symbol, ...args: unknown[]): boolean;
|
|
125
|
+
call<I extends Message, O extends Message>(agent: Runnable<I, O>, input: I, context: Context, options?: CallOptions): Promise<{
|
|
126
|
+
agent: Runnable;
|
|
127
|
+
output: O;
|
|
128
|
+
}>;
|
|
92
129
|
private callAgent;
|
|
93
130
|
}
|
|
131
|
+
export {};
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { Agent, type Message } from "../agents/agent.js";
|
|
3
|
-
import type { UserAgent } from "../agents/user-agent.js";
|
|
1
|
+
import { Agent } from "../agents/agent.js";
|
|
4
2
|
import { ChatModel } from "../models/chat-model.js";
|
|
5
|
-
import { type
|
|
6
|
-
import {
|
|
3
|
+
import { type Context, ExecutionContext } from "./context.js";
|
|
4
|
+
import { MessageQueue } from "./message-queue.js";
|
|
5
|
+
import type { ContextLimits } from "./usage.js";
|
|
7
6
|
export interface ExecutionEngineOptions {
|
|
8
7
|
name?: string;
|
|
9
8
|
description?: string;
|
|
@@ -12,7 +11,10 @@ export interface ExecutionEngineOptions {
|
|
|
12
11
|
agents?: Agent[];
|
|
13
12
|
limits?: ContextLimits;
|
|
14
13
|
}
|
|
15
|
-
export
|
|
14
|
+
export interface ExecutionEngineRunOptions {
|
|
15
|
+
returnActiveAgent?: boolean;
|
|
16
|
+
}
|
|
17
|
+
export declare class ExecutionEngine {
|
|
16
18
|
static load({ path, ...options }: {
|
|
17
19
|
path: string;
|
|
18
20
|
} & ExecutionEngineOptions): Promise<ExecutionEngine>;
|
|
@@ -21,52 +23,19 @@ export declare class ExecutionEngine extends EventEmitter {
|
|
|
21
23
|
description?: string;
|
|
22
24
|
readonly messageQueue: MessageQueue;
|
|
23
25
|
model?: ChatModel;
|
|
24
|
-
readonly tools: Agent<Message, Message>[] & {
|
|
25
|
-
[key: string]: Agent<Message, Message>;
|
|
26
|
+
readonly tools: Agent<import("../agents/agent.js").Message, import("../agents/agent.js").Message>[] & {
|
|
27
|
+
[key: string]: Agent<import("../agents/agent.js").Message, import("../agents/agent.js").Message>;
|
|
26
28
|
};
|
|
27
|
-
readonly agents: Agent<Message, Message>[] & {
|
|
28
|
-
[key: string]: Agent<Message, Message>;
|
|
29
|
+
readonly agents: Agent<import("../agents/agent.js").Message, import("../agents/agent.js").Message>[] & {
|
|
30
|
+
[key: string]: Agent<import("../agents/agent.js").Message, import("../agents/agent.js").Message>;
|
|
29
31
|
};
|
|
30
32
|
limits?: ContextLimits;
|
|
31
33
|
addAgent(...agents: Agent[]): void;
|
|
32
34
|
newContext(): ExecutionContext;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
* @param from the agent who publish the message, if not provided, it will be treated as a user message
|
|
38
|
-
*/
|
|
39
|
-
publish(topic: string | string[], message: Message | string, from?: Agent): void;
|
|
40
|
-
/**
|
|
41
|
-
* Create a user agent to consistently call an agent
|
|
42
|
-
* @param agent Agent to call
|
|
43
|
-
* @returns User agent
|
|
44
|
-
*/
|
|
45
|
-
call<I extends Message, O extends Message>(agent: Runnable<I, O>): UserAgent<I, O>;
|
|
46
|
-
/**
|
|
47
|
-
* Call an agent with a message
|
|
48
|
-
* @param agent Agent to call
|
|
49
|
-
* @param message Message to pass to the agent
|
|
50
|
-
* @returns the output of the agent
|
|
51
|
-
*/
|
|
52
|
-
call<I extends Message, O extends Message>(agent: Runnable<I, O>, message: I | string): Promise<O>;
|
|
53
|
-
/**
|
|
54
|
-
* Call an agent with a message and return the output and the active agent
|
|
55
|
-
* @param agent Agent to call
|
|
56
|
-
* @param message Message to pass to the agent
|
|
57
|
-
* @param options.returnActiveAgent return the active agent
|
|
58
|
-
* @returns the output of the agent and the final active agent
|
|
59
|
-
*/
|
|
60
|
-
call<I extends Message, O extends Message>(agent: Runnable<I, O>, message: I | string, options: {
|
|
61
|
-
returnActiveAgent: true;
|
|
62
|
-
}): Promise<[O, Runnable]>;
|
|
63
|
-
call<I extends Message, O extends Message>(agent: Runnable<I, O>, message?: I | string, options?: {
|
|
64
|
-
returnActiveAgent?: boolean;
|
|
65
|
-
}): UserAgent<I, O> | Promise<O | [O, Runnable]>;
|
|
66
|
-
subscribe(topic: string, listener?: undefined): Promise<MessagePayload>;
|
|
67
|
-
subscribe(topic: string, listener: MessageQueueListener): Unsubscribe;
|
|
68
|
-
subscribe(topic: string, listener?: MessageQueueListener): Unsubscribe | Promise<MessagePayload>;
|
|
69
|
-
unsubscribe(topic: string, listener: MessageQueueListener): void;
|
|
35
|
+
publish: Context["publish"];
|
|
36
|
+
call: Context["call"];
|
|
37
|
+
subscribe: Context["subscribe"];
|
|
38
|
+
unsubscribe: Context["unsubscribe"];
|
|
70
39
|
shutdown(): Promise<void>;
|
|
71
40
|
private initProcessExitHandler;
|
|
72
41
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { EventEmitter } from "node:events";
|
|
1
2
|
import type { Message } from "../agents/agent.js";
|
|
2
3
|
import type { Context } from "./context.js";
|
|
3
4
|
export declare const UserInputTopic = "UserInputTopic";
|
|
@@ -9,11 +10,10 @@ export interface MessagePayload {
|
|
|
9
10
|
context: Context;
|
|
10
11
|
}
|
|
11
12
|
export type MessageQueueListener = (message: MessagePayload) => void;
|
|
12
|
-
export type MessageRequest = MessagePayload;
|
|
13
13
|
export type Unsubscribe = () => void;
|
|
14
14
|
export declare class MessageQueue {
|
|
15
|
-
|
|
16
|
-
publish(topic: string | string[],
|
|
15
|
+
events: EventEmitter<[never]>;
|
|
16
|
+
publish(topic: string | string[], payload: MessagePayload): void;
|
|
17
17
|
error(error: Error): void;
|
|
18
18
|
subscribe(topic: string, listener?: undefined): Promise<MessagePayload>;
|
|
19
19
|
subscribe(topic: string, listener: MessageQueueListener): Unsubscribe;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface ContextUsage {
|
|
2
|
+
inputTokens: number;
|
|
3
|
+
outputTokens: number;
|
|
4
|
+
agentCalls: number;
|
|
5
|
+
}
|
|
6
|
+
export declare function newEmptyContextUsage(): ContextUsage;
|
|
7
|
+
export interface ContextLimits {
|
|
8
|
+
maxTokens?: number;
|
|
9
|
+
maxAgentCalls?: number;
|
|
10
|
+
timeout?: number;
|
|
11
|
+
}
|
|
@@ -10,6 +10,7 @@ export declare function loadAgentFromYamlFile(path: string): Promise<{
|
|
|
10
10
|
}, {
|
|
11
11
|
[x: string]: any;
|
|
12
12
|
}> | undefined;
|
|
13
|
+
tool_choice?: "auto" | "none" | "required" | "router" | undefined;
|
|
13
14
|
output_schema?: ZodObject<Record<string, ZodType<any, z.ZodTypeDef, any>>, z.UnknownKeysParam, z.ZodTypeAny, {
|
|
14
15
|
[x: string]: any;
|
|
15
16
|
}, {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
1
2
|
import { type Agent } from "../agents/agent.js";
|
|
2
|
-
import type { ChatModel } from "../models/chat-model.js";
|
|
3
|
+
import type { ChatModel, ChatModelOptions } from "../models/chat-model.js";
|
|
3
4
|
export interface LoadOptions {
|
|
4
5
|
path: string;
|
|
5
6
|
}
|
|
@@ -19,6 +20,75 @@ export declare function load(options: LoadOptions): Promise<{
|
|
|
19
20
|
} | null | undefined;
|
|
20
21
|
}>;
|
|
21
22
|
export declare function loadAgent(path: string): Promise<Agent>;
|
|
23
|
+
export declare function loadModel(model?: z.infer<typeof aigneFileSchema>["chat_model"], modelOptions?: ChatModelOptions): Promise<ChatModel | undefined>;
|
|
24
|
+
declare const aigneFileSchema: z.ZodObject<{
|
|
25
|
+
name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
26
|
+
description: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
27
|
+
chat_model: z.ZodEffects<z.ZodOptional<z.ZodNullable<z.ZodUnion<[z.ZodString, z.ZodObject<{
|
|
28
|
+
provider: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
29
|
+
name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
30
|
+
temperature: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
31
|
+
top_p: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
32
|
+
frequent_penalty: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
33
|
+
presence_penalty: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
34
|
+
}, "strip", z.ZodTypeAny, {
|
|
35
|
+
name?: string | null | undefined;
|
|
36
|
+
temperature?: number | null | undefined;
|
|
37
|
+
provider?: string | null | undefined;
|
|
38
|
+
top_p?: number | null | undefined;
|
|
39
|
+
frequent_penalty?: number | null | undefined;
|
|
40
|
+
presence_penalty?: number | null | undefined;
|
|
41
|
+
}, {
|
|
42
|
+
name?: string | null | undefined;
|
|
43
|
+
temperature?: number | null | undefined;
|
|
44
|
+
provider?: string | null | undefined;
|
|
45
|
+
top_p?: number | null | undefined;
|
|
46
|
+
frequent_penalty?: number | null | undefined;
|
|
47
|
+
presence_penalty?: number | null | undefined;
|
|
48
|
+
}>]>>>, {
|
|
49
|
+
name?: string | null | undefined;
|
|
50
|
+
temperature?: number | null | undefined;
|
|
51
|
+
provider?: string | null | undefined;
|
|
52
|
+
top_p?: number | null | undefined;
|
|
53
|
+
frequent_penalty?: number | null | undefined;
|
|
54
|
+
presence_penalty?: number | null | undefined;
|
|
55
|
+
} | null | undefined, string | {
|
|
56
|
+
name?: string | null | undefined;
|
|
57
|
+
temperature?: number | null | undefined;
|
|
58
|
+
provider?: string | null | undefined;
|
|
59
|
+
top_p?: number | null | undefined;
|
|
60
|
+
frequent_penalty?: number | null | undefined;
|
|
61
|
+
presence_penalty?: number | null | undefined;
|
|
62
|
+
} | null | undefined>;
|
|
63
|
+
agents: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString, "many">>>;
|
|
64
|
+
tools: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString, "many">>>;
|
|
65
|
+
}, "strip", z.ZodTypeAny, {
|
|
66
|
+
description?: string | null | undefined;
|
|
67
|
+
tools?: string[] | null | undefined;
|
|
68
|
+
name?: string | null | undefined;
|
|
69
|
+
chat_model?: {
|
|
70
|
+
name?: string | null | undefined;
|
|
71
|
+
temperature?: number | null | undefined;
|
|
72
|
+
provider?: string | null | undefined;
|
|
73
|
+
top_p?: number | null | undefined;
|
|
74
|
+
frequent_penalty?: number | null | undefined;
|
|
75
|
+
presence_penalty?: number | null | undefined;
|
|
76
|
+
} | null | undefined;
|
|
77
|
+
agents?: string[] | null | undefined;
|
|
78
|
+
}, {
|
|
79
|
+
description?: string | null | undefined;
|
|
80
|
+
tools?: string[] | null | undefined;
|
|
81
|
+
name?: string | null | undefined;
|
|
82
|
+
chat_model?: string | {
|
|
83
|
+
name?: string | null | undefined;
|
|
84
|
+
temperature?: number | null | undefined;
|
|
85
|
+
provider?: string | null | undefined;
|
|
86
|
+
top_p?: number | null | undefined;
|
|
87
|
+
frequent_penalty?: number | null | undefined;
|
|
88
|
+
presence_penalty?: number | null | undefined;
|
|
89
|
+
} | null | undefined;
|
|
90
|
+
agents?: string[] | null | undefined;
|
|
91
|
+
}>;
|
|
22
92
|
export declare function loadAIGNEFile(path: string): Promise<{
|
|
23
93
|
description?: string | null | undefined;
|
|
24
94
|
tools?: string[] | null | undefined;
|
|
@@ -33,3 +103,4 @@ export declare function loadAIGNEFile(path: string): Promise<{
|
|
|
33
103
|
} | null | undefined;
|
|
34
104
|
agents?: string[] | null | undefined;
|
|
35
105
|
}>;
|
|
106
|
+
export {};
|
|
@@ -75,6 +75,7 @@ export interface ChatModelOutput extends Message {
|
|
|
75
75
|
json?: object;
|
|
76
76
|
toolCalls?: ChatModelOutputToolCall[];
|
|
77
77
|
usage?: ChatModelOutputUsage;
|
|
78
|
+
model?: string;
|
|
78
79
|
}
|
|
79
80
|
export interface ChatModelOutputToolCall {
|
|
80
81
|
id: string;
|
|
@@ -85,6 +86,6 @@ export interface ChatModelOutputToolCall {
|
|
|
85
86
|
};
|
|
86
87
|
}
|
|
87
88
|
export interface ChatModelOutputUsage {
|
|
88
|
-
|
|
89
|
-
|
|
89
|
+
inputTokens: number;
|
|
90
|
+
outputTokens: number;
|
|
90
91
|
}
|
|
@@ -7,7 +7,7 @@ import type { ChatModel, ChatModelInput } from "../models/chat-model.js";
|
|
|
7
7
|
import { ChatMessagesTemplate } from "./template.js";
|
|
8
8
|
export declare const MESSAGE_KEY = "$message";
|
|
9
9
|
export declare const DEFAULT_MAX_HISTORY_MESSAGES = 10;
|
|
10
|
-
export declare function createMessage(message: string |
|
|
10
|
+
export declare function createMessage<I extends Message>(message: string | I): I;
|
|
11
11
|
export declare function getMessage(input: Message): string | undefined;
|
|
12
12
|
export interface PromptBuilderOptions {
|
|
13
13
|
instructions?: string | ChatMessagesTemplate;
|
|
@@ -1,20 +1,8 @@
|
|
|
1
|
-
import debug
|
|
2
|
-
import type { Ora } from "ora";
|
|
3
|
-
interface DebugWithSpinner extends Debugger {
|
|
4
|
-
spinner<T>(promise: Promise<T>, message?: string, callback?: (result: T) => void, options?: {
|
|
5
|
-
disabled?: boolean;
|
|
6
|
-
}): Promise<T>;
|
|
7
|
-
extend: (namespace: string) => DebugWithSpinner;
|
|
8
|
-
}
|
|
9
|
-
declare function spinner<T>(promise: Promise<T>, message?: string, callback?: (result: T) => void): Promise<T>;
|
|
1
|
+
import debug from "debug";
|
|
10
2
|
export declare const logger: debug.Debug & {
|
|
11
3
|
debug: debug.Debug;
|
|
12
4
|
default: debug.Debug;
|
|
13
5
|
} & {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
debug: DebugWithSpinner;
|
|
17
|
-
spinner: typeof spinner;
|
|
18
|
-
setSpinner: (spinner: Ora) => void;
|
|
6
|
+
core: debug.Debugger;
|
|
7
|
+
mcp: debug.Debugger;
|
|
19
8
|
};
|
|
20
|
-
export {};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type ZodType } from "zod";
|
|
2
2
|
export type PromiseOrValue<T> = T | Promise<T>;
|
|
3
3
|
export type Nullish<T> = T | null | undefined;
|
|
4
|
+
export type OmitPropertiesFromArrayFirstElement<T extends unknown[], K extends string | number | symbol> = T extends [infer U, ...infer Rest] ? [Omit<U, K>, ...Rest] : never;
|
|
4
5
|
export declare function isNil(value: unknown): value is null | undefined;
|
|
5
6
|
export declare function isEmpty(obj: unknown): boolean;
|
|
6
7
|
export declare function isNonNullable<T>(value: T): value is NonNullable<T>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
type EventMap<T> = Record<keyof T, unknown[]>;
|
|
2
|
+
export type Args<K, T> = K extends keyof T ? T[K] : never;
|
|
3
|
+
export type Listener<K, T> = K extends keyof T ? T[K] extends unknown[] ? (...args: T[K]) => void : never : never;
|
|
4
|
+
export interface TypedEventEmitter<T extends EventMap<T>, E extends EventMap<E> = T> {
|
|
5
|
+
emit<K extends keyof E>(eventName: K, ...args: Args<K, E>): boolean;
|
|
6
|
+
on<K extends keyof T>(eventName: K, listener: Listener<K, T>): this;
|
|
7
|
+
once<K extends keyof T>(eventName: K, listener: Listener<K, T>): this;
|
|
8
|
+
off<K extends keyof T>(eventName: K, listener: Listener<K, T>): this;
|
|
9
|
+
}
|
|
10
|
+
export {};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { inspect } from "node:util";
|
|
1
2
|
import { type ZodType } from "zod";
|
|
2
3
|
import type { Context } from "../execution-engine/context.js";
|
|
3
4
|
import { type Nullish, type PromiseOrValue } from "../utils/type-utils.js";
|
|
@@ -15,7 +16,7 @@ export interface AgentOptions<I extends Message = Message, O extends Message = M
|
|
|
15
16
|
outputSchema?: AgentInputOutputSchema<O>;
|
|
16
17
|
includeInputInOutput?: boolean;
|
|
17
18
|
tools?: (Agent | FunctionAgentFn)[];
|
|
18
|
-
|
|
19
|
+
disableEvents?: boolean;
|
|
19
20
|
memory?: AgentMemory | AgentMemoryOptions | true;
|
|
20
21
|
}
|
|
21
22
|
export declare abstract class Agent<I extends Message = Message, O extends Message = Message> {
|
|
@@ -37,7 +38,7 @@ export declare abstract class Agent<I extends Message = Message, O extends Messa
|
|
|
37
38
|
readonly tools: Agent<Message, Message>[] & {
|
|
38
39
|
[key: string]: Agent<Message, Message>;
|
|
39
40
|
};
|
|
40
|
-
private
|
|
41
|
+
private disableEvents?;
|
|
41
42
|
/**
|
|
42
43
|
* Attach agent to context:
|
|
43
44
|
* - subscribe to topic and call process method when message received
|
|
@@ -50,10 +51,12 @@ export declare abstract class Agent<I extends Message = Message, O extends Messa
|
|
|
50
51
|
private checkContextStatus;
|
|
51
52
|
private newDefaultContext;
|
|
52
53
|
call(input: I | string, context?: Context): Promise<O>;
|
|
54
|
+
protected checkUsageAgentCalls(context: Context): void;
|
|
53
55
|
protected preprocess(_: I, context: Context): void;
|
|
54
56
|
protected postprocess(input: I, output: O, context: Context): void;
|
|
55
57
|
abstract process(input: I, context: Context): Promise<O | TransferAgentOutput>;
|
|
56
58
|
shutdown(): Promise<void>;
|
|
59
|
+
[inspect.custom](): string;
|
|
57
60
|
}
|
|
58
61
|
export type AgentInputOutputSchema<I extends Message = Message> = ZodType<I> | ((agent: Agent) => ZodType<I>);
|
|
59
62
|
export interface FunctionAgentOptions<I extends Message = Message, O extends Message = Message> extends AgentOptions<I, O> {
|