@aigne/core 1.16.0 → 1.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/lib/cjs/agents/agent.d.ts +42 -26
- package/lib/cjs/agents/agent.js +59 -55
- package/lib/cjs/agents/ai-agent.d.ts +4 -5
- package/lib/cjs/agents/ai-agent.js +11 -11
- package/lib/cjs/agents/chat-model.d.ts +7 -8
- package/lib/cjs/agents/chat-model.js +9 -9
- package/lib/cjs/agents/mcp-agent.d.ts +3 -4
- package/lib/cjs/agents/mcp-agent.js +2 -2
- package/lib/cjs/agents/team-agent.d.ts +7 -8
- package/lib/cjs/agents/team-agent.js +10 -10
- package/lib/cjs/agents/user-agent.d.ts +4 -4
- package/lib/cjs/agents/user-agent.js +10 -10
- package/lib/cjs/aigne/aigne.d.ts +10 -9
- package/lib/cjs/aigne/aigne.js +5 -4
- package/lib/cjs/aigne/context.d.ts +17 -7
- package/lib/cjs/aigne/context.js +20 -7
- package/lib/cjs/index.d.ts +2 -1
- package/lib/cjs/index.js +2 -1
- package/lib/cjs/loader/agent-yaml.d.ts +1 -1
- package/lib/cjs/memory/default-memory/default-memory-storage/index.d.ts +30 -0
- package/lib/cjs/memory/default-memory/default-memory-storage/index.js +69 -0
- package/lib/cjs/memory/default-memory/default-memory-storage/migrate.d.ts +7 -0
- package/lib/cjs/memory/default-memory/default-memory-storage/migrate.js +53 -0
- package/lib/cjs/memory/default-memory/default-memory-storage/migrations/20250523165801-init.d.ts +7 -0
- package/lib/cjs/memory/default-memory/default-memory-storage/migrations/20250523165801-init.js +33 -0
- package/lib/cjs/memory/default-memory/default-memory-storage/models/memory.d.ts +10 -0
- package/lib/cjs/memory/default-memory/default-memory-storage/models/memory.js +32 -0
- package/lib/cjs/memory/default-memory/index.d.ts +10 -0
- package/lib/cjs/memory/{default-memory.js → default-memory/index.js} +16 -25
- package/lib/cjs/memory/default-memory/storage.d.ts +13 -0
- package/lib/cjs/memory/default-memory/storage.js +6 -0
- package/lib/cjs/memory/memory.d.ts +3 -2
- package/lib/cjs/memory/memory.js +1 -1
- package/lib/cjs/prompt/prompt-builder.d.ts +7 -1
- package/lib/cjs/prompt/prompt-builder.js +4 -4
- package/lib/cjs/utils/type-utils.d.ts +2 -2
- package/lib/dts/agents/agent.d.ts +42 -26
- package/lib/dts/agents/ai-agent.d.ts +4 -5
- package/lib/dts/agents/chat-model.d.ts +7 -8
- package/lib/dts/agents/mcp-agent.d.ts +3 -4
- package/lib/dts/agents/team-agent.d.ts +7 -8
- package/lib/dts/agents/user-agent.d.ts +4 -4
- package/lib/dts/aigne/aigne.d.ts +10 -9
- package/lib/dts/aigne/context.d.ts +17 -7
- package/lib/dts/index.d.ts +2 -1
- package/lib/dts/loader/agent-yaml.d.ts +1 -1
- package/lib/dts/memory/default-memory/default-memory-storage/index.d.ts +30 -0
- package/lib/dts/memory/default-memory/default-memory-storage/migrate.d.ts +7 -0
- package/lib/dts/memory/default-memory/default-memory-storage/migrations/20250523165801-init.d.ts +7 -0
- package/lib/dts/memory/default-memory/default-memory-storage/models/memory.d.ts +10 -0
- package/lib/dts/memory/default-memory/index.d.ts +10 -0
- package/lib/dts/memory/default-memory/storage.d.ts +13 -0
- package/lib/dts/memory/memory.d.ts +3 -2
- package/lib/dts/prompt/prompt-builder.d.ts +7 -1
- package/lib/dts/utils/type-utils.d.ts +2 -2
- package/lib/esm/agents/agent.d.ts +42 -26
- package/lib/esm/agents/agent.js +59 -55
- package/lib/esm/agents/ai-agent.d.ts +4 -5
- package/lib/esm/agents/ai-agent.js +10 -10
- package/lib/esm/agents/chat-model.d.ts +7 -8
- package/lib/esm/agents/chat-model.js +9 -9
- package/lib/esm/agents/mcp-agent.d.ts +3 -4
- package/lib/esm/agents/mcp-agent.js +2 -2
- package/lib/esm/agents/team-agent.d.ts +7 -8
- package/lib/esm/agents/team-agent.js +10 -10
- package/lib/esm/agents/user-agent.d.ts +4 -4
- package/lib/esm/agents/user-agent.js +10 -10
- package/lib/esm/aigne/aigne.d.ts +10 -9
- package/lib/esm/aigne/aigne.js +5 -4
- package/lib/esm/aigne/context.d.ts +17 -7
- package/lib/esm/aigne/context.js +21 -8
- package/lib/esm/index.d.ts +2 -1
- package/lib/esm/index.js +2 -1
- package/lib/esm/loader/agent-yaml.d.ts +1 -1
- package/lib/esm/memory/default-memory/default-memory-storage/index.d.ts +30 -0
- package/lib/esm/memory/default-memory/default-memory-storage/index.js +64 -0
- package/lib/esm/memory/default-memory/default-memory-storage/migrate.d.ts +7 -0
- package/lib/esm/memory/default-memory/default-memory-storage/migrate.js +16 -0
- package/lib/esm/memory/default-memory/default-memory-storage/migrations/20250523165801-init.d.ts +7 -0
- package/lib/esm/memory/default-memory/default-memory-storage/migrations/20250523165801-init.js +28 -0
- package/lib/esm/memory/default-memory/default-memory-storage/models/memory.d.ts +10 -0
- package/lib/esm/memory/default-memory/default-memory-storage/models/memory.js +29 -0
- package/lib/esm/memory/default-memory/index.d.ts +10 -0
- package/lib/esm/memory/{default-memory.js → default-memory/index.js} +15 -24
- package/lib/esm/memory/default-memory/storage.d.ts +13 -0
- package/lib/esm/memory/default-memory/storage.js +2 -0
- package/lib/esm/memory/memory.d.ts +3 -2
- package/lib/esm/memory/memory.js +2 -2
- package/lib/esm/prompt/prompt-builder.d.ts +7 -1
- package/lib/esm/prompt/prompt-builder.js +4 -4
- package/lib/esm/utils/type-utils.d.ts +2 -2
- package/package.json +4 -1
- package/lib/cjs/memory/default-memory.d.ts +0 -16
- package/lib/dts/memory/default-memory.d.ts +0 -16
- package/lib/esm/memory/default-memory.d.ts +0 -16
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { type ZodObject, type ZodType, z } from "zod";
|
|
2
|
-
import type
|
|
3
|
-
import { type DefaultMemoryOptions } from "../memory/default-memory.js";
|
|
2
|
+
import { type DefaultMemoryOptions } from "../memory/default-memory/index.js";
|
|
4
3
|
import { PromptBuilder } from "../prompt/prompt-builder.js";
|
|
5
|
-
import { Agent, type AgentOptions, type AgentProcessAsyncGenerator, type Message } from "./agent.js";
|
|
4
|
+
import { Agent, type AgentInvokeOptions, type AgentOptions, type AgentProcessAsyncGenerator, type Message } from "./agent.js";
|
|
6
5
|
import { ChatModel, type ChatModelInput } from "./chat-model.js";
|
|
7
6
|
import type { GuideRailAgentOutput } from "./guide-rail-agent.js";
|
|
8
7
|
/**
|
|
@@ -215,7 +214,7 @@ export declare class AIAgent<I extends Message = Message, O extends Message = Me
|
|
|
215
214
|
*
|
|
216
215
|
* @protected
|
|
217
216
|
*/
|
|
218
|
-
process(input: I,
|
|
217
|
+
process(input: I, options: AgentInvokeOptions): AgentProcessAsyncGenerator<O>;
|
|
219
218
|
protected onGuideRailError(error: GuideRailAgentOutput): Promise<O | GuideRailAgentOutput>;
|
|
220
219
|
/**
|
|
221
220
|
* Process router mode requests
|
|
@@ -225,5 +224,5 @@ export declare class AIAgent<I extends Message = Message, O extends Message = Me
|
|
|
225
224
|
*
|
|
226
225
|
* @protected
|
|
227
226
|
*/
|
|
228
|
-
_processRouter(input: I, model: ChatModel, modelInput: ChatModelInput,
|
|
227
|
+
_processRouter(input: I, model: ChatModel, modelInput: ChatModelInput, options: AgentInvokeOptions, toolsMap: Map<string, Agent>): AgentProcessAsyncGenerator<O>;
|
|
229
228
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import type { Context } from "../aigne/context.js";
|
|
2
1
|
import type { PromiseOrValue } from "../utils/type-utils.js";
|
|
3
|
-
import { Agent, type AgentProcessResult, type Message } from "./agent.js";
|
|
2
|
+
import { Agent, type AgentInvokeOptions, type AgentProcessResult, type Message } from "./agent.js";
|
|
4
3
|
/**
|
|
5
4
|
* ChatModel is an abstract base class for interacting with Large Language Models (LLMs).
|
|
6
5
|
*
|
|
@@ -61,10 +60,10 @@ export declare abstract class ChatModel extends Agent<ChatModelInput, ChatModelO
|
|
|
61
60
|
* Primarily checks if token usage exceeds limits, throwing an exception if limits are exceeded
|
|
62
61
|
*
|
|
63
62
|
* @param input Input message
|
|
64
|
-
* @param
|
|
63
|
+
* @param options Options for invoking the agent
|
|
65
64
|
* @throws Error if token usage exceeds maximum limit
|
|
66
65
|
*/
|
|
67
|
-
protected preprocess(input: ChatModelInput,
|
|
66
|
+
protected preprocess(input: ChatModelInput, options: AgentInvokeOptions): Promise<void>;
|
|
68
67
|
/**
|
|
69
68
|
* Performs postprocessing operations after handling output
|
|
70
69
|
*
|
|
@@ -72,9 +71,9 @@ export declare abstract class ChatModel extends Agent<ChatModelInput, ChatModelO
|
|
|
72
71
|
*
|
|
73
72
|
* @param input Input message
|
|
74
73
|
* @param output Output message
|
|
75
|
-
* @param
|
|
74
|
+
* @param options Options for invoking the agent
|
|
76
75
|
*/
|
|
77
|
-
protected postprocess(input: ChatModelInput, output: ChatModelOutput,
|
|
76
|
+
protected postprocess(input: ChatModelInput, output: ChatModelOutput, options: AgentInvokeOptions): Promise<void>;
|
|
78
77
|
/**
|
|
79
78
|
* Processes input messages and generates model responses
|
|
80
79
|
*
|
|
@@ -92,10 +91,10 @@ export declare abstract class ChatModel extends Agent<ChatModelInput, ChatModelO
|
|
|
92
91
|
* - Tool call processing if applicable
|
|
93
92
|
*
|
|
94
93
|
* @param input - The standardized input containing messages and model options
|
|
95
|
-
* @param
|
|
94
|
+
* @param options - The options for invoking the agent, including context and limits
|
|
96
95
|
* @returns A promise or direct value containing the model's response
|
|
97
96
|
*/
|
|
98
|
-
abstract process(input: ChatModelInput,
|
|
97
|
+
abstract process(input: ChatModelInput, options: AgentInvokeOptions): PromiseOrValue<AgentProcessResult<ChatModelOutput>>;
|
|
99
98
|
}
|
|
100
99
|
/**
|
|
101
100
|
* Input message format for ChatModel
|
|
@@ -6,9 +6,8 @@ import type { RequestOptions } from "@modelcontextprotocol/sdk/shared/protocol.j
|
|
|
6
6
|
import type { Transport } from "@modelcontextprotocol/sdk/shared/transport.js";
|
|
7
7
|
import type { CallToolResult, GetPromptResult, Implementation, ReadResourceResult, Request } from "@modelcontextprotocol/sdk/types.js";
|
|
8
8
|
import { type ZodType, z } from "zod";
|
|
9
|
-
import type { Context } from "../aigne/context.js";
|
|
10
9
|
import { type PromiseOrValue } from "../utils/type-utils.js";
|
|
11
|
-
import { Agent, type AgentOptions, type Message } from "./agent.js";
|
|
10
|
+
import { Agent, type AgentInvokeOptions, type AgentOptions, type Message } from "./agent.js";
|
|
12
11
|
export interface MCPAgentOptions extends AgentOptions {
|
|
13
12
|
client: Client;
|
|
14
13
|
prompts?: MCPPrompt[];
|
|
@@ -150,10 +149,10 @@ export declare class MCPAgent extends Agent {
|
|
|
150
149
|
* throws an error if called.
|
|
151
150
|
*
|
|
152
151
|
* @param _input Input message (unused)
|
|
153
|
-
* @param
|
|
152
|
+
* @param _options AgentInvokeOptions (unused)
|
|
154
153
|
* @throws Error This method always throws an error since MCPAgent is not directly invokable
|
|
155
154
|
*/
|
|
156
|
-
process(_input: Message,
|
|
155
|
+
process(_input: Message, _options: AgentInvokeOptions): Promise<Message>;
|
|
157
156
|
/**
|
|
158
157
|
* Shut down the agent and close the MCP connection.
|
|
159
158
|
*
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import type { Context } from "../aigne/context.js";
|
|
2
1
|
import { type PromiseOrValue } from "../utils/type-utils.js";
|
|
3
|
-
import { Agent, type AgentOptions, type AgentProcessResult, type Message } from "./agent.js";
|
|
2
|
+
import { Agent, type AgentInvokeOptions, type AgentOptions, type AgentProcessResult, type Message } from "./agent.js";
|
|
4
3
|
/**
|
|
5
4
|
* Defines the processing modes available for a TeamAgent.
|
|
6
5
|
*
|
|
@@ -89,10 +88,10 @@ export declare class TeamAgent<I extends Message, O extends Message> extends Age
|
|
|
89
88
|
* - In parallel mode: Process input through all agents simultaneously and combine their outputs
|
|
90
89
|
*
|
|
91
90
|
* @param input The message to process
|
|
92
|
-
* @param
|
|
91
|
+
* @param options The invocation options
|
|
93
92
|
* @returns A stream of message chunks that collectively form the response
|
|
94
93
|
*/
|
|
95
|
-
process(input: I,
|
|
94
|
+
process(input: I, options: AgentInvokeOptions): PromiseOrValue<AgentProcessResult<O>>;
|
|
96
95
|
/**
|
|
97
96
|
* Process input sequentially through each agent in the team.
|
|
98
97
|
*
|
|
@@ -103,12 +102,12 @@ export declare class TeamAgent<I extends Message, O extends Message> extends Age
|
|
|
103
102
|
* 4. Updates the team's agent list with any changes that occurred during processing
|
|
104
103
|
*
|
|
105
104
|
* @param input The message to process
|
|
106
|
-
* @param
|
|
105
|
+
* @param options The invocation options
|
|
107
106
|
* @returns A stream of message chunks from all agents
|
|
108
107
|
*
|
|
109
108
|
* @private
|
|
110
109
|
*/
|
|
111
|
-
_processSequential(input: I,
|
|
110
|
+
_processSequential(input: I, options: AgentInvokeOptions): PromiseOrValue<AgentProcessResult<O>>;
|
|
112
111
|
/**
|
|
113
112
|
* Process input in parallel through all agents in the team.
|
|
114
113
|
*
|
|
@@ -118,10 +117,10 @@ export declare class TeamAgent<I extends Message, O extends Message> extends Age
|
|
|
118
117
|
* 3. Updates the team's agent list with any changes that occurred during processing
|
|
119
118
|
*
|
|
120
119
|
* @param input The message to process
|
|
121
|
-
* @param
|
|
120
|
+
* @param options The invocation options
|
|
122
121
|
* @returns A stream of combined message chunks from all agents
|
|
123
122
|
*
|
|
124
123
|
* @private
|
|
125
124
|
*/
|
|
126
|
-
_processParallel(input: I,
|
|
125
|
+
_processParallel(input: I, options: AgentInvokeOptions): PromiseOrValue<AgentProcessResult<O>>;
|
|
127
126
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ReadableStream } from "node:stream/web";
|
|
2
2
|
import type { Context } from "../aigne/context.js";
|
|
3
3
|
import { type MessagePayload } from "../aigne/message-queue.js";
|
|
4
|
-
import { Agent, type AgentOptions, type AgentProcessResult, type FunctionAgentFn, type Message } from "./agent.js";
|
|
4
|
+
import { Agent, type AgentInvokeOptions, type AgentOptions, type AgentProcessResult, type FunctionAgentFn, type Message } from "./agent.js";
|
|
5
5
|
export interface UserAgentOptions<I extends Message = Message, O extends Message = Message> extends AgentOptions<I, O> {
|
|
6
6
|
context: Context;
|
|
7
7
|
process?: FunctionAgentFn<I, O>;
|
|
@@ -14,14 +14,14 @@ export declare class UserAgent<I extends Message = Message, O extends Message =
|
|
|
14
14
|
private _process?;
|
|
15
15
|
private activeAgent?;
|
|
16
16
|
protected subscribeToTopics(context: Pick<Context, "subscribe">): void;
|
|
17
|
-
protected publishToTopics(output: O,
|
|
17
|
+
protected publishToTopics(output: O, options: AgentInvokeOptions): Promise<void>;
|
|
18
18
|
invoke: Agent<I, O>["invoke"];
|
|
19
|
-
process(input: I,
|
|
19
|
+
process(input: I, options: AgentInvokeOptions): Promise<AgentProcessResult<O>>;
|
|
20
20
|
publish: Context["publish"];
|
|
21
21
|
subscribe: Context["subscribe"];
|
|
22
22
|
unsubscribe: Context["unsubscribe"];
|
|
23
23
|
get stream(): ReadableStream<MessagePayload & {
|
|
24
24
|
topic: string;
|
|
25
25
|
}>;
|
|
26
|
-
protected checkAgentInvokesUsage(
|
|
26
|
+
protected checkAgentInvokesUsage(_options: AgentInvokeOptions): void;
|
|
27
27
|
}
|
package/lib/dts/aigne/aigne.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { Agent, type AgentResponse, type AgentResponseStream, type Message } fro
|
|
|
2
2
|
import { ChatModel } from "../agents/chat-model.js";
|
|
3
3
|
import type { UserAgent } from "../agents/user-agent.js";
|
|
4
4
|
import { type LoadOptions } from "../loader/index.js";
|
|
5
|
-
import { AIGNEContext, type InvokeOptions } from "./context.js";
|
|
5
|
+
import { AIGNEContext, type Context, type InvokeOptions, type UserContext } from "./context.js";
|
|
6
6
|
import { type MessagePayload, MessageQueue, type MessageQueueListener, type Unsubscribe } from "./message-queue.js";
|
|
7
7
|
import type { ContextLimits } from "./usage.js";
|
|
8
8
|
/**
|
|
@@ -46,7 +46,7 @@ export interface AIGNEOptions {
|
|
|
46
46
|
* Here's an example of how to use AIGNE with streaming response:
|
|
47
47
|
* {@includeCode ../../test/aigne/aigne.test.ts#example-streaming}
|
|
48
48
|
*/
|
|
49
|
-
export declare class AIGNE {
|
|
49
|
+
export declare class AIGNE<U extends UserContext = UserContext> {
|
|
50
50
|
/**
|
|
51
51
|
* Loads an AIGNE instance from a directory containing an aigne.yaml file and agent definitions.
|
|
52
52
|
* This static method provides a convenient way to initialize an AIGNE system from configuration files.
|
|
@@ -111,7 +111,7 @@ export declare class AIGNE {
|
|
|
111
111
|
*
|
|
112
112
|
* @returns A new AIGNEContext instance bound to this AIGNE.
|
|
113
113
|
*/
|
|
114
|
-
newContext(): AIGNEContext;
|
|
114
|
+
newContext(options?: Partial<Context>): AIGNEContext;
|
|
115
115
|
/**
|
|
116
116
|
* Creates a user agent for consistent interactions with a specified agent.
|
|
117
117
|
* This method allows you to create a wrapper around an agent for repeated invocations.
|
|
@@ -134,7 +134,7 @@ export declare class AIGNE {
|
|
|
134
134
|
* @param options.streaming - Must be false to return a response stream
|
|
135
135
|
* @returns A promise resolving to a tuple containing the agent's response and the final active agent
|
|
136
136
|
*/
|
|
137
|
-
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I | string, options: InvokeOptions & {
|
|
137
|
+
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I | string, options: InvokeOptions<U> & {
|
|
138
138
|
returnActiveAgent: true;
|
|
139
139
|
streaming?: false;
|
|
140
140
|
}): Promise<[O, Agent]>;
|
|
@@ -148,7 +148,7 @@ export declare class AIGNE {
|
|
|
148
148
|
* @param options.streaming - Must be true to return a response stream
|
|
149
149
|
* @returns A promise resolving to a tuple containing the agent's response stream and a promise for the final agent
|
|
150
150
|
*/
|
|
151
|
-
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I | string, options: InvokeOptions & {
|
|
151
|
+
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I | string, options: InvokeOptions<U> & {
|
|
152
152
|
returnActiveAgent: true;
|
|
153
153
|
streaming: true;
|
|
154
154
|
}): Promise<[AgentResponseStream<O>, Promise<Agent>]>;
|
|
@@ -165,7 +165,7 @@ export declare class AIGNE {
|
|
|
165
165
|
* Here's a simple example of how to invoke an agent:
|
|
166
166
|
* {@includeCode ../../test/aigne/aigne.test.ts#example-simple}
|
|
167
167
|
*/
|
|
168
|
-
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I | string, options?: InvokeOptions & {
|
|
168
|
+
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I | string, options?: InvokeOptions<U> & {
|
|
169
169
|
returnActiveAgent?: false;
|
|
170
170
|
streaming?: false;
|
|
171
171
|
}): Promise<O>;
|
|
@@ -182,7 +182,7 @@ export declare class AIGNE {
|
|
|
182
182
|
* Here's an example of how to invoke an agent with streaming response:
|
|
183
183
|
* {@includeCode ../../test/aigne/aigne.test.ts#example-streaming}
|
|
184
184
|
*/
|
|
185
|
-
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I | string, options: InvokeOptions & {
|
|
185
|
+
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I | string, options: InvokeOptions<U> & {
|
|
186
186
|
returnActiveAgent?: false;
|
|
187
187
|
streaming: true;
|
|
188
188
|
}): Promise<AgentResponseStream<O>>;
|
|
@@ -196,7 +196,7 @@ export declare class AIGNE {
|
|
|
196
196
|
* @returns Either a UserAgent (when no message provided) or a promise resolving to the agent's response
|
|
197
197
|
* with optional active agent information based on the provided options
|
|
198
198
|
*/
|
|
199
|
-
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message?: I | string, options?: InvokeOptions): UserAgent<I, O> | Promise<AgentResponse<O> | [AgentResponse<O>, Agent]>;
|
|
199
|
+
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message?: I | string, options?: InvokeOptions<U>): UserAgent<I, O> | Promise<AgentResponse<O> | [AgentResponse<O>, Agent]>;
|
|
200
200
|
/**
|
|
201
201
|
* Publishes a message to the message queue for inter-agent communication.
|
|
202
202
|
* This method broadcasts a message to all subscribers of the specified topic(s).
|
|
@@ -204,12 +204,13 @@ export declare class AIGNE {
|
|
|
204
204
|
*
|
|
205
205
|
* @param topic - The topic or array of topics to publish the message to
|
|
206
206
|
* @param payload - The message payload to be delivered to subscribers
|
|
207
|
+
* @param options - Optional configuration parameters for the publish operation
|
|
207
208
|
*
|
|
208
209
|
* @example
|
|
209
210
|
* Here's an example of how to publish a message:
|
|
210
211
|
* {@includeCode ../../test/aigne/aigne.test.ts#example-publish-message}
|
|
211
212
|
*/
|
|
212
|
-
publish(topic: string | string[], payload: Omit<MessagePayload, "context"> | Message | string): void;
|
|
213
|
+
publish(topic: string | string[], payload: Omit<MessagePayload, "context"> | Message | string, options?: InvokeOptions<U>): void;
|
|
213
214
|
/**
|
|
214
215
|
* Subscribes to receive the next message on a specific topic.
|
|
215
216
|
* This overload returns a Promise that resolves with the next message published to the topic.
|
|
@@ -38,20 +38,27 @@ export type ContextEmitEventMap = {
|
|
|
38
38
|
/**
|
|
39
39
|
* @hidden
|
|
40
40
|
*/
|
|
41
|
-
export interface InvokeOptions extends AgentInvokeOptions {
|
|
41
|
+
export interface InvokeOptions<U extends UserContext = UserContext> extends Partial<Omit<AgentInvokeOptions<U>, "context">> {
|
|
42
42
|
returnActiveAgent?: boolean;
|
|
43
43
|
disableTransfer?: boolean;
|
|
44
44
|
sourceAgent?: Agent;
|
|
45
|
+
userContext?: U;
|
|
45
46
|
}
|
|
46
47
|
/**
|
|
47
48
|
* @hidden
|
|
48
49
|
*/
|
|
49
|
-
export interface
|
|
50
|
+
export interface UserContext extends Record<string, unknown> {
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* @hidden
|
|
54
|
+
*/
|
|
55
|
+
export interface Context<U extends UserContext = UserContext> extends TypedEventEmitter<ContextEventMap, ContextEmitEventMap> {
|
|
50
56
|
model?: ChatModel;
|
|
51
57
|
skills?: Agent[];
|
|
52
58
|
usage: ContextUsage;
|
|
53
59
|
limits?: ContextLimits;
|
|
54
60
|
status?: "normal" | "timeout";
|
|
61
|
+
userContext: U;
|
|
55
62
|
/**
|
|
56
63
|
* Create a user agent to consistently invoke an agent
|
|
57
64
|
* @param agent Agent to invoke
|
|
@@ -92,7 +99,7 @@ export interface Context extends TypedEventEmitter<ContextEventMap, ContextEmitE
|
|
|
92
99
|
* @param topic topic name, or an array of topic names
|
|
93
100
|
* @param payload message to publish
|
|
94
101
|
*/
|
|
95
|
-
publish(topic: string | string[], payload: Omit<MessagePayload, "context"> | Message | string): void;
|
|
102
|
+
publish(topic: string | string[], payload: Omit<MessagePayload, "context"> | Message | string, options?: InvokeOptions): void;
|
|
96
103
|
subscribe(topic: string | string[], listener?: undefined): Promise<MessagePayload>;
|
|
97
104
|
subscribe(topic: string | string[], listener: MessageQueueListener): Unsubscribe;
|
|
98
105
|
subscribe(topic: string | string[], listener?: MessageQueueListener): Unsubscribe | Promise<MessagePayload>;
|
|
@@ -114,15 +121,17 @@ export interface Context extends TypedEventEmitter<ContextEventMap, ContextEmitE
|
|
|
114
121
|
* @hidden
|
|
115
122
|
*/
|
|
116
123
|
export declare class AIGNEContext implements Context {
|
|
117
|
-
constructor(parent
|
|
124
|
+
constructor(...[parent, ...args]: ConstructorParameters<typeof AIGNEContextShared>);
|
|
118
125
|
parentId?: string;
|
|
119
126
|
id: string;
|
|
120
|
-
readonly internal:
|
|
127
|
+
readonly internal: AIGNEContextShared;
|
|
121
128
|
get model(): ChatModel | undefined;
|
|
122
129
|
get skills(): Agent<Message, Message>[] | undefined;
|
|
123
130
|
get limits(): ContextLimits | undefined;
|
|
124
131
|
get status(): "normal" | "timeout";
|
|
125
132
|
get usage(): ContextUsage;
|
|
133
|
+
get userContext(): Context["userContext"];
|
|
134
|
+
set userContext(userContext: Context["userContext"]);
|
|
126
135
|
newContext({ reset }?: {
|
|
127
136
|
reset?: boolean;
|
|
128
137
|
}): AIGNEContext;
|
|
@@ -135,17 +144,18 @@ export declare class AIGNEContext implements Context {
|
|
|
135
144
|
once<K extends keyof ContextEventMap>(eventName: K, listener: Listener<K, ContextEventMap>): this;
|
|
136
145
|
off<K extends keyof ContextEventMap>(eventName: K, listener: Listener<K, ContextEventMap>): this;
|
|
137
146
|
}
|
|
138
|
-
declare class
|
|
147
|
+
declare class AIGNEContextShared {
|
|
139
148
|
private readonly parent?;
|
|
140
149
|
constructor(parent?: (Pick<Context, "model" | "skills" | "limits"> & {
|
|
141
150
|
messageQueue?: MessageQueue;
|
|
142
|
-
}) | undefined);
|
|
151
|
+
}) | undefined, overrides?: Partial<Context>);
|
|
143
152
|
readonly messageQueue: MessageQueue;
|
|
144
153
|
readonly events: EventEmitter<ContextEventMap>;
|
|
145
154
|
get model(): ChatModel | undefined;
|
|
146
155
|
get skills(): Agent<Message, Message>[] | undefined;
|
|
147
156
|
get limits(): ContextLimits | undefined;
|
|
148
157
|
usage: ContextUsage;
|
|
158
|
+
userContext: Context["userContext"];
|
|
149
159
|
private abortController;
|
|
150
160
|
private timer?;
|
|
151
161
|
private initTimeout;
|
package/lib/dts/index.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
export * from "./agents/agent.js";
|
|
2
2
|
export * from "./agents/ai-agent.js";
|
|
3
|
+
export * from "./agents/chat-model.js";
|
|
4
|
+
export * from "./agents/guide-rail-agent.js";
|
|
3
5
|
export * from "./agents/mcp-agent.js";
|
|
4
6
|
export * from "./agents/team-agent.js";
|
|
5
7
|
export * from "./agents/types.js";
|
|
6
8
|
export * from "./agents/user-agent.js";
|
|
7
9
|
export * from "./aigne/index.js";
|
|
8
|
-
export * from "./agents/chat-model.js";
|
|
9
10
|
export * from "./prompt/prompt-builder.js";
|
|
10
11
|
export * from "./prompt/template.js";
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { AgentInvokeOptions } from "../../../agents/agent.js";
|
|
2
|
+
import "sqlite3";
|
|
3
|
+
import { Sequelize } from "sequelize";
|
|
4
|
+
import type { Context } from "../../../aigne/context.js";
|
|
5
|
+
import type { PromiseOrValue } from "../../../utils/type-utils.js";
|
|
6
|
+
import type { Memory } from "../../memory.js";
|
|
7
|
+
import { MemoryStorage } from "../storage.js";
|
|
8
|
+
export interface DefaultMemoryStorageOptions {
|
|
9
|
+
path?: string;
|
|
10
|
+
getSessionId?: (context: Context) => PromiseOrValue<string>;
|
|
11
|
+
}
|
|
12
|
+
export declare class DefaultMemoryStorage extends MemoryStorage {
|
|
13
|
+
options?: DefaultMemoryStorageOptions | undefined;
|
|
14
|
+
memories: {
|
|
15
|
+
[groupId: string]: Memory[];
|
|
16
|
+
};
|
|
17
|
+
constructor(options?: DefaultMemoryStorageOptions | undefined);
|
|
18
|
+
private _models?;
|
|
19
|
+
private get models();
|
|
20
|
+
private convertMemory;
|
|
21
|
+
search(query: {
|
|
22
|
+
limit?: number;
|
|
23
|
+
}, { context }: AgentInvokeOptions): Promise<{
|
|
24
|
+
result: Memory[];
|
|
25
|
+
}>;
|
|
26
|
+
create(memory: Pick<Memory, "content">, { context }: AgentInvokeOptions): Promise<{
|
|
27
|
+
result: Memory;
|
|
28
|
+
}>;
|
|
29
|
+
}
|
|
30
|
+
export declare function initSequelize(path?: string): Sequelize;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Sequelize } from "sequelize";
|
|
2
|
+
import { type MigrateDownOptions, type MigrateUpOptions } from "umzug";
|
|
3
|
+
export declare const migrate: (sequelize: Sequelize, { type, upOptions, downOptions, }?: {
|
|
4
|
+
type?: "up" | "down";
|
|
5
|
+
upOptions?: MigrateUpOptions;
|
|
6
|
+
downOptions?: MigrateDownOptions;
|
|
7
|
+
}) => Promise<void>;
|
package/lib/dts/memory/default-memory/default-memory-storage/migrations/20250523165801-init.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type QueryInterface } from "sequelize";
|
|
2
|
+
export declare const up: ({ context: queryInterface }: {
|
|
3
|
+
context: QueryInterface;
|
|
4
|
+
}) => Promise<void>;
|
|
5
|
+
export declare const down: ({ context: queryInterface }: {
|
|
6
|
+
context: QueryInterface;
|
|
7
|
+
}) => Promise<void>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type CreationOptional, type InferAttributes, type InferCreationAttributes, Model } from "sequelize";
|
|
2
|
+
import type { ModelStatic, Sequelize } from "sequelize";
|
|
3
|
+
export interface Memory extends Model<InferAttributes<Memory>, InferCreationAttributes<Memory>> {
|
|
4
|
+
id: CreationOptional<string>;
|
|
5
|
+
createdAt: CreationOptional<Date>;
|
|
6
|
+
updatedAt: CreationOptional<Date>;
|
|
7
|
+
sessionId?: string | null;
|
|
8
|
+
content: unknown;
|
|
9
|
+
}
|
|
10
|
+
export declare function initMemoryModel(sequelize: Sequelize): ModelStatic<Memory>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { MemoryAgent, type MemoryAgentOptions } from "../memory.js";
|
|
2
|
+
import { type DefaultMemoryStorageOptions } from "./default-memory-storage/index.js";
|
|
3
|
+
import { MemoryStorage } from "./storage.js";
|
|
4
|
+
export interface DefaultMemoryOptions extends Partial<MemoryAgentOptions> {
|
|
5
|
+
storage?: MemoryStorage | DefaultMemoryStorageOptions;
|
|
6
|
+
}
|
|
7
|
+
export declare class DefaultMemory extends MemoryAgent {
|
|
8
|
+
constructor(options?: DefaultMemoryOptions);
|
|
9
|
+
storage: MemoryStorage;
|
|
10
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { AgentInvokeOptions } from "../../agents/agent.js";
|
|
2
|
+
import type { Memory } from "../memory.js";
|
|
3
|
+
export declare abstract class MemoryStorage {
|
|
4
|
+
abstract create(memory: Pick<Memory, "content">, options: AgentInvokeOptions): Promise<{
|
|
5
|
+
result: Memory;
|
|
6
|
+
}>;
|
|
7
|
+
abstract search(query: {
|
|
8
|
+
search?: string;
|
|
9
|
+
limit?: number;
|
|
10
|
+
}, options: AgentInvokeOptions): Promise<{
|
|
11
|
+
result: Memory[];
|
|
12
|
+
}>;
|
|
13
|
+
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { Agent, type AgentOptions, type Message } from "../agents/agent.js";
|
|
1
|
+
import { Agent, type AgentInvokeOptions, type AgentOptions, type Message } from "../agents/agent.js";
|
|
2
2
|
import type { Context } from "../aigne/context.js";
|
|
3
3
|
import type { MessagePayload } from "../aigne/message-queue.js";
|
|
4
4
|
import type { MemoryRecorder, MemoryRecorderInput, MemoryRecorderOutput } from "./recorder.js";
|
|
5
5
|
import type { MemoryRetriever, MemoryRetrieverInput, MemoryRetrieverOutput } from "./retriever.js";
|
|
6
6
|
export interface Memory {
|
|
7
7
|
id: string;
|
|
8
|
+
sessionId?: string | null;
|
|
8
9
|
content: unknown;
|
|
9
10
|
createdAt: string;
|
|
10
11
|
}
|
|
@@ -62,7 +63,7 @@ export declare class MemoryAgent extends Agent {
|
|
|
62
63
|
* MemoryAgent doesn't directly process messages like other agents, so this method
|
|
63
64
|
* throws an error when called. Use the specialized retrieve() and record() methods instead.
|
|
64
65
|
*/
|
|
65
|
-
process(_input: Message,
|
|
66
|
+
process(_input: Message, _options: AgentInvokeOptions): Promise<Message>;
|
|
66
67
|
/**
|
|
67
68
|
* Retrieves memories based on the provided input criteria.
|
|
68
69
|
*
|
|
@@ -6,7 +6,13 @@ import type { Context } from "../aigne/context.js";
|
|
|
6
6
|
import type { MemoryAgent } from "../memory/memory.js";
|
|
7
7
|
import { ChatMessagesTemplate } from "./template.js";
|
|
8
8
|
export declare const MESSAGE_KEY = "$message";
|
|
9
|
-
export declare function createMessage<
|
|
9
|
+
export declare function createMessage<V extends Message>(message: string, variables?: V): {
|
|
10
|
+
[MESSAGE_KEY]: string;
|
|
11
|
+
} & typeof variables;
|
|
12
|
+
export declare function createMessage<I extends Message, V extends Message>(message: I, variables?: V): I & typeof variables;
|
|
13
|
+
export declare function createMessage<I extends Message, V extends Message>(message: string | I, variables?: V): ({
|
|
14
|
+
[MESSAGE_KEY]: string;
|
|
15
|
+
} | I) & typeof variables;
|
|
10
16
|
export declare function getMessage(input: Message): string | undefined;
|
|
11
17
|
export interface PromptBuilderOptions {
|
|
12
18
|
instructions?: string | ChatMessagesTemplate;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type ZodType } from "zod";
|
|
1
|
+
import { type ZodType, z } from "zod";
|
|
2
2
|
export type PromiseOrValue<T> = T | Promise<T>;
|
|
3
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;
|
|
@@ -20,6 +20,6 @@ export declare function orArrayToArray<T>(value?: T | T[]): T[];
|
|
|
20
20
|
export declare function createAccessorArray<T>(array: T[], accessor: (array: T[], name: string) => T | undefined): T[] & {
|
|
21
21
|
[key: string]: T;
|
|
22
22
|
};
|
|
23
|
-
export declare function checkArguments<T>(prefix: string, schema:
|
|
23
|
+
export declare function checkArguments<T extends ZodType>(prefix: string, schema: T, args: unknown): z.infer<T>;
|
|
24
24
|
export declare function tryOrThrow<P extends PromiseOrValue<unknown>>(fn: () => P, error: string | Error | ((error: Error) => Error)): P;
|
|
25
25
|
export declare function tryOrThrow<P extends PromiseOrValue<unknown>>(fn: () => P, error?: Nullish<string | Error | ((error: Error) => Nullish<Error>)>): P | undefined;
|