@aigne/core 1.15.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.
Files changed (194) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/README.md +9 -7
  3. package/README.zh.md +9 -7
  4. package/lib/cjs/agents/agent.d.ts +168 -29
  5. package/lib/cjs/agents/agent.js +152 -56
  6. package/lib/cjs/agents/ai-agent.d.ts +7 -7
  7. package/lib/cjs/agents/ai-agent.js +19 -15
  8. package/lib/{esm/models → cjs/agents}/chat-model.d.ts +29 -19
  9. package/lib/cjs/{models → agents}/chat-model.js +56 -15
  10. package/lib/cjs/agents/guide-rail-agent.d.ts +62 -0
  11. package/lib/cjs/agents/guide-rail-agent.js +14 -0
  12. package/lib/cjs/agents/mcp-agent.d.ts +3 -4
  13. package/lib/cjs/agents/mcp-agent.js +11 -11
  14. package/lib/cjs/agents/team-agent.d.ts +7 -8
  15. package/lib/cjs/agents/team-agent.js +10 -10
  16. package/lib/cjs/agents/user-agent.d.ts +4 -4
  17. package/lib/cjs/agents/user-agent.js +10 -10
  18. package/lib/cjs/aigne/aigne.d.ts +13 -11
  19. package/lib/cjs/aigne/aigne.js +7 -6
  20. package/lib/cjs/aigne/context.d.ts +19 -8
  21. package/lib/cjs/aigne/context.js +27 -7
  22. package/lib/cjs/index.d.ts +2 -1
  23. package/lib/cjs/index.js +2 -1
  24. package/lib/cjs/loader/agent-yaml.d.ts +2 -2
  25. package/lib/cjs/loader/index.d.ts +18 -11
  26. package/lib/cjs/loader/index.js +8 -27
  27. package/lib/cjs/memory/default-memory/default-memory-storage/index.d.ts +30 -0
  28. package/lib/cjs/memory/default-memory/default-memory-storage/index.js +69 -0
  29. package/lib/cjs/memory/default-memory/default-memory-storage/migrate.d.ts +7 -0
  30. package/lib/cjs/memory/default-memory/default-memory-storage/migrate.js +53 -0
  31. package/lib/cjs/memory/default-memory/default-memory-storage/migrations/20250523165801-init.d.ts +7 -0
  32. package/lib/cjs/memory/default-memory/default-memory-storage/migrations/20250523165801-init.js +33 -0
  33. package/lib/cjs/memory/default-memory/default-memory-storage/models/memory.d.ts +10 -0
  34. package/lib/cjs/memory/default-memory/default-memory-storage/models/memory.js +32 -0
  35. package/lib/cjs/memory/default-memory/index.d.ts +10 -0
  36. package/lib/cjs/memory/{default-memory.js → default-memory/index.js} +16 -25
  37. package/lib/cjs/memory/default-memory/storage.d.ts +13 -0
  38. package/lib/cjs/memory/default-memory/storage.js +6 -0
  39. package/lib/cjs/memory/memory.d.ts +3 -2
  40. package/lib/cjs/memory/memory.js +1 -1
  41. package/lib/cjs/memory/retriever.d.ts +2 -2
  42. package/lib/cjs/prompt/prompt-builder.d.ts +10 -4
  43. package/lib/cjs/prompt/prompt-builder.js +4 -4
  44. package/lib/cjs/prompt/template.d.ts +3 -3
  45. package/lib/cjs/utils/json-schema.js +1 -1
  46. package/lib/cjs/utils/logger.d.ts +33 -8
  47. package/lib/cjs/utils/logger.js +63 -5
  48. package/lib/cjs/utils/model-utils.d.ts +1 -1
  49. package/lib/cjs/utils/stream-utils.d.ts +3 -1
  50. package/lib/cjs/utils/stream-utils.js +31 -1
  51. package/lib/cjs/utils/type-utils.d.ts +7 -2
  52. package/lib/dts/agents/agent.d.ts +168 -29
  53. package/lib/dts/agents/ai-agent.d.ts +7 -7
  54. package/lib/{cjs/models → dts/agents}/chat-model.d.ts +29 -19
  55. package/lib/dts/agents/guide-rail-agent.d.ts +62 -0
  56. package/lib/dts/agents/mcp-agent.d.ts +3 -4
  57. package/lib/dts/agents/team-agent.d.ts +7 -8
  58. package/lib/dts/agents/user-agent.d.ts +4 -4
  59. package/lib/dts/aigne/aigne.d.ts +13 -11
  60. package/lib/dts/aigne/context.d.ts +19 -8
  61. package/lib/dts/index.d.ts +2 -1
  62. package/lib/dts/loader/agent-yaml.d.ts +2 -2
  63. package/lib/dts/loader/index.d.ts +18 -11
  64. package/lib/dts/memory/default-memory/default-memory-storage/index.d.ts +30 -0
  65. package/lib/dts/memory/default-memory/default-memory-storage/migrate.d.ts +7 -0
  66. package/lib/dts/memory/default-memory/default-memory-storage/migrations/20250523165801-init.d.ts +7 -0
  67. package/lib/dts/memory/default-memory/default-memory-storage/models/memory.d.ts +10 -0
  68. package/lib/dts/memory/default-memory/index.d.ts +10 -0
  69. package/lib/dts/memory/default-memory/storage.d.ts +13 -0
  70. package/lib/dts/memory/memory.d.ts +3 -2
  71. package/lib/dts/memory/retriever.d.ts +2 -2
  72. package/lib/dts/prompt/prompt-builder.d.ts +10 -4
  73. package/lib/dts/prompt/template.d.ts +3 -3
  74. package/lib/dts/utils/logger.d.ts +33 -8
  75. package/lib/dts/utils/model-utils.d.ts +1 -1
  76. package/lib/dts/utils/stream-utils.d.ts +3 -1
  77. package/lib/dts/utils/type-utils.d.ts +7 -2
  78. package/lib/esm/agents/agent.d.ts +168 -29
  79. package/lib/esm/agents/agent.js +152 -56
  80. package/lib/esm/agents/ai-agent.d.ts +7 -7
  81. package/lib/esm/agents/ai-agent.js +18 -14
  82. package/lib/{dts/models → esm/agents}/chat-model.d.ts +29 -19
  83. package/lib/esm/{models → agents}/chat-model.js +56 -15
  84. package/lib/esm/agents/guide-rail-agent.d.ts +62 -0
  85. package/lib/esm/agents/guide-rail-agent.js +11 -0
  86. package/lib/esm/agents/mcp-agent.d.ts +3 -4
  87. package/lib/esm/agents/mcp-agent.js +11 -11
  88. package/lib/esm/agents/team-agent.d.ts +7 -8
  89. package/lib/esm/agents/team-agent.js +10 -10
  90. package/lib/esm/agents/user-agent.d.ts +4 -4
  91. package/lib/esm/agents/user-agent.js +10 -10
  92. package/lib/esm/aigne/aigne.d.ts +13 -11
  93. package/lib/esm/aigne/aigne.js +7 -6
  94. package/lib/esm/aigne/context.d.ts +19 -8
  95. package/lib/esm/aigne/context.js +28 -8
  96. package/lib/esm/index.d.ts +2 -1
  97. package/lib/esm/index.js +2 -1
  98. package/lib/esm/loader/agent-yaml.d.ts +2 -2
  99. package/lib/esm/loader/index.d.ts +18 -11
  100. package/lib/esm/loader/index.js +8 -27
  101. package/lib/esm/memory/default-memory/default-memory-storage/index.d.ts +30 -0
  102. package/lib/esm/memory/default-memory/default-memory-storage/index.js +64 -0
  103. package/lib/esm/memory/default-memory/default-memory-storage/migrate.d.ts +7 -0
  104. package/lib/esm/memory/default-memory/default-memory-storage/migrate.js +16 -0
  105. package/lib/esm/memory/default-memory/default-memory-storage/migrations/20250523165801-init.d.ts +7 -0
  106. package/lib/esm/memory/default-memory/default-memory-storage/migrations/20250523165801-init.js +28 -0
  107. package/lib/esm/memory/default-memory/default-memory-storage/models/memory.d.ts +10 -0
  108. package/lib/esm/memory/default-memory/default-memory-storage/models/memory.js +29 -0
  109. package/lib/esm/memory/default-memory/index.d.ts +10 -0
  110. package/lib/esm/memory/{default-memory.js → default-memory/index.js} +15 -24
  111. package/lib/esm/memory/default-memory/storage.d.ts +13 -0
  112. package/lib/esm/memory/default-memory/storage.js +2 -0
  113. package/lib/esm/memory/memory.d.ts +3 -2
  114. package/lib/esm/memory/memory.js +2 -2
  115. package/lib/esm/memory/retriever.d.ts +2 -2
  116. package/lib/esm/prompt/prompt-builder.d.ts +10 -4
  117. package/lib/esm/prompt/prompt-builder.js +4 -4
  118. package/lib/esm/prompt/template.d.ts +3 -3
  119. package/lib/esm/utils/json-schema.js +1 -1
  120. package/lib/esm/utils/logger.d.ts +33 -8
  121. package/lib/esm/utils/logger.js +61 -4
  122. package/lib/esm/utils/model-utils.d.ts +1 -1
  123. package/lib/esm/utils/stream-utils.d.ts +3 -1
  124. package/lib/esm/utils/stream-utils.js +29 -1
  125. package/lib/esm/utils/type-utils.d.ts +7 -2
  126. package/package.json +4 -20
  127. package/lib/cjs/client/client.d.ts +0 -97
  128. package/lib/cjs/client/client.js +0 -87
  129. package/lib/cjs/client/index.d.ts +0 -1
  130. package/lib/cjs/client/index.js +0 -17
  131. package/lib/cjs/memory/default-memory.d.ts +0 -16
  132. package/lib/cjs/models/bedrock-chat-model.d.ts +0 -79
  133. package/lib/cjs/models/bedrock-chat-model.js +0 -303
  134. package/lib/cjs/models/claude-chat-model.d.ts +0 -114
  135. package/lib/cjs/models/claude-chat-model.js +0 -317
  136. package/lib/cjs/models/deepseek-chat-model.d.ts +0 -23
  137. package/lib/cjs/models/deepseek-chat-model.js +0 -35
  138. package/lib/cjs/models/gemini-chat-model.d.ts +0 -23
  139. package/lib/cjs/models/gemini-chat-model.js +0 -35
  140. package/lib/cjs/models/ollama-chat-model.d.ts +0 -22
  141. package/lib/cjs/models/ollama-chat-model.js +0 -34
  142. package/lib/cjs/models/open-router-chat-model.d.ts +0 -22
  143. package/lib/cjs/models/open-router-chat-model.js +0 -34
  144. package/lib/cjs/models/openai-chat-model.d.ts +0 -166
  145. package/lib/cjs/models/openai-chat-model.js +0 -415
  146. package/lib/cjs/models/xai-chat-model.d.ts +0 -21
  147. package/lib/cjs/models/xai-chat-model.js +0 -33
  148. package/lib/cjs/server/error.d.ts +0 -15
  149. package/lib/cjs/server/error.js +0 -22
  150. package/lib/cjs/server/index.d.ts +0 -2
  151. package/lib/cjs/server/index.js +0 -18
  152. package/lib/cjs/server/server.d.ts +0 -135
  153. package/lib/cjs/server/server.js +0 -187
  154. package/lib/dts/client/client.d.ts +0 -97
  155. package/lib/dts/client/index.d.ts +0 -1
  156. package/lib/dts/memory/default-memory.d.ts +0 -16
  157. package/lib/dts/models/bedrock-chat-model.d.ts +0 -79
  158. package/lib/dts/models/claude-chat-model.d.ts +0 -114
  159. package/lib/dts/models/deepseek-chat-model.d.ts +0 -23
  160. package/lib/dts/models/gemini-chat-model.d.ts +0 -23
  161. package/lib/dts/models/ollama-chat-model.d.ts +0 -22
  162. package/lib/dts/models/open-router-chat-model.d.ts +0 -22
  163. package/lib/dts/models/openai-chat-model.d.ts +0 -166
  164. package/lib/dts/models/xai-chat-model.d.ts +0 -21
  165. package/lib/dts/server/error.d.ts +0 -15
  166. package/lib/dts/server/index.d.ts +0 -2
  167. package/lib/dts/server/server.d.ts +0 -135
  168. package/lib/esm/client/client.d.ts +0 -97
  169. package/lib/esm/client/client.js +0 -83
  170. package/lib/esm/client/index.d.ts +0 -1
  171. package/lib/esm/client/index.js +0 -1
  172. package/lib/esm/memory/default-memory.d.ts +0 -16
  173. package/lib/esm/models/bedrock-chat-model.d.ts +0 -79
  174. package/lib/esm/models/bedrock-chat-model.js +0 -298
  175. package/lib/esm/models/claude-chat-model.d.ts +0 -114
  176. package/lib/esm/models/claude-chat-model.js +0 -310
  177. package/lib/esm/models/deepseek-chat-model.d.ts +0 -23
  178. package/lib/esm/models/deepseek-chat-model.js +0 -31
  179. package/lib/esm/models/gemini-chat-model.d.ts +0 -23
  180. package/lib/esm/models/gemini-chat-model.js +0 -31
  181. package/lib/esm/models/ollama-chat-model.d.ts +0 -22
  182. package/lib/esm/models/ollama-chat-model.js +0 -30
  183. package/lib/esm/models/open-router-chat-model.d.ts +0 -22
  184. package/lib/esm/models/open-router-chat-model.js +0 -30
  185. package/lib/esm/models/openai-chat-model.d.ts +0 -166
  186. package/lib/esm/models/openai-chat-model.js +0 -405
  187. package/lib/esm/models/xai-chat-model.d.ts +0 -21
  188. package/lib/esm/models/xai-chat-model.js +0 -29
  189. package/lib/esm/server/error.d.ts +0 -15
  190. package/lib/esm/server/error.js +0 -18
  191. package/lib/esm/server/index.d.ts +0 -2
  192. package/lib/esm/server/index.js +0 -2
  193. package/lib/esm/server/server.d.ts +0 -135
  194. package/lib/esm/server/server.js +0 -180
@@ -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, context: Context): Promise<void>;
17
+ protected publishToTopics(output: O, options: AgentInvokeOptions): Promise<void>;
18
18
  invoke: Agent<I, O>["invoke"];
19
- process(input: I, context: Context): Promise<AgentProcessResult<O>>;
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(_context: Context): void;
26
+ protected checkAgentInvokesUsage(_options: AgentInvokeOptions): void;
27
27
  }
@@ -1,7 +1,8 @@
1
1
  import { Agent, type AgentResponse, type AgentResponseStream, type Message } from "../agents/agent.js";
2
+ import { ChatModel } from "../agents/chat-model.js";
2
3
  import type { UserAgent } from "../agents/user-agent.js";
3
- import { ChatModel } from "../models/chat-model.js";
4
- import { AIGNEContext, type InvokeOptions } from "./context.js";
4
+ import { type LoadOptions } from "../loader/index.js";
5
+ import { AIGNEContext, type Context, type InvokeOptions, type UserContext } from "./context.js";
5
6
  import { type MessagePayload, MessageQueue, type MessageQueueListener, type Unsubscribe } from "./message-queue.js";
6
7
  import type { ContextLimits } from "./usage.js";
7
8
  /**
@@ -45,7 +46,7 @@ export interface AIGNEOptions {
45
46
  * Here's an example of how to use AIGNE with streaming response:
46
47
  * {@includeCode ../../test/aigne/aigne.test.ts#example-streaming}
47
48
  */
48
- export declare class AIGNE {
49
+ export declare class AIGNE<U extends UserContext = UserContext> {
49
50
  /**
50
51
  * Loads an AIGNE instance from a directory containing an aigne.yaml file and agent definitions.
51
52
  * This static method provides a convenient way to initialize an AIGNE system from configuration files.
@@ -54,7 +55,7 @@ export declare class AIGNE {
54
55
  * @param options - Options to override the loaded configuration.
55
56
  * @returns A fully initialized AIGNE instance with configured agents and skills.
56
57
  */
57
- static load(path: string, options?: AIGNEOptions): Promise<AIGNE>;
58
+ static load(path: string, options: AIGNEOptions & Pick<LoadOptions, "models">): Promise<AIGNE>;
58
59
  /**
59
60
  * Creates a new AIGNE instance with the specified options.
60
61
  *
@@ -110,7 +111,7 @@ export declare class AIGNE {
110
111
  *
111
112
  * @returns A new AIGNEContext instance bound to this AIGNE.
112
113
  */
113
- newContext(): AIGNEContext;
114
+ newContext(options?: Partial<Context>): AIGNEContext;
114
115
  /**
115
116
  * Creates a user agent for consistent interactions with a specified agent.
116
117
  * This method allows you to create a wrapper around an agent for repeated invocations.
@@ -133,7 +134,7 @@ export declare class AIGNE {
133
134
  * @param options.streaming - Must be false to return a response stream
134
135
  * @returns A promise resolving to a tuple containing the agent's response and the final active agent
135
136
  */
136
- 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> & {
137
138
  returnActiveAgent: true;
138
139
  streaming?: false;
139
140
  }): Promise<[O, Agent]>;
@@ -147,7 +148,7 @@ export declare class AIGNE {
147
148
  * @param options.streaming - Must be true to return a response stream
148
149
  * @returns A promise resolving to a tuple containing the agent's response stream and a promise for the final agent
149
150
  */
150
- 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> & {
151
152
  returnActiveAgent: true;
152
153
  streaming: true;
153
154
  }): Promise<[AgentResponseStream<O>, Promise<Agent>]>;
@@ -164,7 +165,7 @@ export declare class AIGNE {
164
165
  * Here's a simple example of how to invoke an agent:
165
166
  * {@includeCode ../../test/aigne/aigne.test.ts#example-simple}
166
167
  */
167
- 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> & {
168
169
  returnActiveAgent?: false;
169
170
  streaming?: false;
170
171
  }): Promise<O>;
@@ -181,7 +182,7 @@ export declare class AIGNE {
181
182
  * Here's an example of how to invoke an agent with streaming response:
182
183
  * {@includeCode ../../test/aigne/aigne.test.ts#example-streaming}
183
184
  */
184
- 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> & {
185
186
  returnActiveAgent?: false;
186
187
  streaming: true;
187
188
  }): Promise<AgentResponseStream<O>>;
@@ -195,7 +196,7 @@ export declare class AIGNE {
195
196
  * @returns Either a UserAgent (when no message provided) or a promise resolving to the agent's response
196
197
  * with optional active agent information based on the provided options
197
198
  */
198
- 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]>;
199
200
  /**
200
201
  * Publishes a message to the message queue for inter-agent communication.
201
202
  * This method broadcasts a message to all subscribers of the specified topic(s).
@@ -203,12 +204,13 @@ export declare class AIGNE {
203
204
  *
204
205
  * @param topic - The topic or array of topics to publish the message to
205
206
  * @param payload - The message payload to be delivered to subscribers
207
+ * @param options - Optional configuration parameters for the publish operation
206
208
  *
207
209
  * @example
208
210
  * Here's an example of how to publish a message:
209
211
  * {@includeCode ../../test/aigne/aigne.test.ts#example-publish-message}
210
212
  */
211
- 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;
212
214
  /**
213
215
  * Subscribes to receive the next message on a specific topic.
214
216
  * This overload returns a Promise that resolves with the next message published to the topic.
@@ -1,7 +1,7 @@
1
1
  import EventEmitter from "node:events";
2
2
  import { Agent, type AgentInvokeOptions, type AgentProcessAsyncGenerator, type AgentResponse, type AgentResponseStream, type Message } from "../agents/agent.js";
3
+ import type { ChatModel } from "../agents/chat-model.js";
3
4
  import { UserAgent } from "../agents/user-agent.js";
4
- import type { ChatModel } from "../models/chat-model.js";
5
5
  import { type OmitPropertiesFromArrayFirstElement } from "../utils/type-utils.js";
6
6
  import type { Args, Listener, TypedEventEmitter } from "../utils/typed-event-emtter.js";
7
7
  import { type MessagePayload, MessageQueue, type MessageQueueListener, type Unsubscribe } from "./message-queue.js";
@@ -38,19 +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
+ sourceAgent?: Agent;
45
+ userContext?: U;
44
46
  }
45
47
  /**
46
48
  * @hidden
47
49
  */
48
- export interface Context extends TypedEventEmitter<ContextEventMap, ContextEmitEventMap> {
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> {
49
56
  model?: ChatModel;
50
57
  skills?: Agent[];
51
58
  usage: ContextUsage;
52
59
  limits?: ContextLimits;
53
60
  status?: "normal" | "timeout";
61
+ userContext: U;
54
62
  /**
55
63
  * Create a user agent to consistently invoke an agent
56
64
  * @param agent Agent to invoke
@@ -91,7 +99,7 @@ export interface Context extends TypedEventEmitter<ContextEventMap, ContextEmitE
91
99
  * @param topic topic name, or an array of topic names
92
100
  * @param payload message to publish
93
101
  */
94
- 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;
95
103
  subscribe(topic: string | string[], listener?: undefined): Promise<MessagePayload>;
96
104
  subscribe(topic: string | string[], listener: MessageQueueListener): Unsubscribe;
97
105
  subscribe(topic: string | string[], listener?: MessageQueueListener): Unsubscribe | Promise<MessagePayload>;
@@ -113,15 +121,17 @@ export interface Context extends TypedEventEmitter<ContextEventMap, ContextEmitE
113
121
  * @hidden
114
122
  */
115
123
  export declare class AIGNEContext implements Context {
116
- constructor(parent?: ConstructorParameters<typeof AIGNEContextInternal>[0]);
124
+ constructor(...[parent, ...args]: ConstructorParameters<typeof AIGNEContextShared>);
117
125
  parentId?: string;
118
126
  id: string;
119
- readonly internal: AIGNEContextInternal;
127
+ readonly internal: AIGNEContextShared;
120
128
  get model(): ChatModel | undefined;
121
129
  get skills(): Agent<Message, Message>[] | undefined;
122
130
  get limits(): ContextLimits | undefined;
123
131
  get status(): "normal" | "timeout";
124
132
  get usage(): ContextUsage;
133
+ get userContext(): Context["userContext"];
134
+ set userContext(userContext: Context["userContext"]);
125
135
  newContext({ reset }?: {
126
136
  reset?: boolean;
127
137
  }): AIGNEContext;
@@ -134,17 +144,18 @@ export declare class AIGNEContext implements Context {
134
144
  once<K extends keyof ContextEventMap>(eventName: K, listener: Listener<K, ContextEventMap>): this;
135
145
  off<K extends keyof ContextEventMap>(eventName: K, listener: Listener<K, ContextEventMap>): this;
136
146
  }
137
- declare class AIGNEContextInternal {
147
+ declare class AIGNEContextShared {
138
148
  private readonly parent?;
139
149
  constructor(parent?: (Pick<Context, "model" | "skills" | "limits"> & {
140
150
  messageQueue?: MessageQueue;
141
- }) | undefined);
151
+ }) | undefined, overrides?: Partial<Context>);
142
152
  readonly messageQueue: MessageQueue;
143
153
  readonly events: EventEmitter<ContextEventMap>;
144
154
  get model(): ChatModel | undefined;
145
155
  get skills(): Agent<Message, Message>[] | undefined;
146
156
  get limits(): ContextLimits | undefined;
147
157
  usage: ContextUsage;
158
+ userContext: Context["userContext"];
148
159
  private abortController;
149
160
  private timer?;
150
161
  private initTimeout;
@@ -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 "./models/chat-model.js";
9
10
  export * from "./prompt/prompt-builder.js";
10
11
  export * from "./prompt/template.js";
@@ -14,16 +14,16 @@ export declare function loadAgentFromYamlFile(path: string): Promise<{
14
14
  }, {
15
15
  [x: string]: any;
16
16
  }> | undefined;
17
- toolChoice?: AIAgentToolChoice | undefined;
18
17
  outputSchema?: ZodObject<Record<string, ZodType<any, z.ZodTypeDef, any>>, z.UnknownKeysParam, z.ZodTypeAny, {
19
18
  [x: string]: any;
20
19
  }, {
21
20
  [x: string]: any;
22
21
  }> | undefined;
23
22
  outputKey?: string | undefined;
23
+ toolChoice?: AIAgentToolChoice | undefined;
24
24
  } | {
25
25
  type: "mcp";
26
26
  url?: string | undefined;
27
- command?: string | undefined;
28
27
  args?: string[] | undefined;
28
+ command?: string | undefined;
29
29
  }>;
@@ -1,7 +1,14 @@
1
+ import type { Camelize } from "camelize-ts";
1
2
  import { z } from "zod";
2
3
  import { type Agent } from "../agents/agent.js";
3
- import type { ChatModel, ChatModelOptions } from "../models/chat-model.js";
4
+ import type { ChatModel, ChatModelOptions } from "../agents/chat-model.js";
4
5
  export interface LoadOptions {
6
+ models: {
7
+ new (parameters: {
8
+ model?: string;
9
+ modelOptions?: ChatModelOptions;
10
+ }): ChatModel;
11
+ }[];
5
12
  path: string;
6
13
  }
7
14
  export declare function load(options: LoadOptions): Promise<{
@@ -15,12 +22,12 @@ export declare function load(options: LoadOptions): Promise<{
15
22
  temperature?: number | null | undefined;
16
23
  provider?: string | null | undefined;
17
24
  top_p?: number | null | undefined;
18
- frequent_penalty?: number | null | undefined;
25
+ frequency_penalty?: number | null | undefined;
19
26
  presence_penalty?: number | null | undefined;
20
27
  } | null | undefined;
21
28
  }>;
22
29
  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>;
30
+ export declare function loadModel(models: LoadOptions["models"], model?: Camelize<z.infer<typeof aigneFileSchema>["chat_model"]>, modelOptions?: ChatModelOptions): Promise<ChatModel | undefined>;
24
31
  declare const aigneFileSchema: z.ZodObject<{
25
32
  name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
26
33
  description: z.ZodOptional<z.ZodNullable<z.ZodString>>;
@@ -29,35 +36,35 @@ declare const aigneFileSchema: z.ZodObject<{
29
36
  name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
30
37
  temperature: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
31
38
  top_p: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
32
- frequent_penalty: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
39
+ frequency_penalty: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
33
40
  presence_penalty: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
34
41
  }, "strip", z.ZodTypeAny, {
35
42
  name?: string | null | undefined;
36
43
  temperature?: number | null | undefined;
37
44
  provider?: string | null | undefined;
38
45
  top_p?: number | null | undefined;
39
- frequent_penalty?: number | null | undefined;
46
+ frequency_penalty?: number | null | undefined;
40
47
  presence_penalty?: number | null | undefined;
41
48
  }, {
42
49
  name?: string | null | undefined;
43
50
  temperature?: number | null | undefined;
44
51
  provider?: string | null | undefined;
45
52
  top_p?: number | null | undefined;
46
- frequent_penalty?: number | null | undefined;
53
+ frequency_penalty?: number | null | undefined;
47
54
  presence_penalty?: number | null | undefined;
48
55
  }>]>>>, {
49
56
  name?: string | null | undefined;
50
57
  temperature?: number | null | undefined;
51
58
  provider?: string | null | undefined;
52
59
  top_p?: number | null | undefined;
53
- frequent_penalty?: number | null | undefined;
60
+ frequency_penalty?: number | null | undefined;
54
61
  presence_penalty?: number | null | undefined;
55
62
  } | null | undefined, string | {
56
63
  name?: string | null | undefined;
57
64
  temperature?: number | null | undefined;
58
65
  provider?: string | null | undefined;
59
66
  top_p?: number | null | undefined;
60
- frequent_penalty?: number | null | undefined;
67
+ frequency_penalty?: number | null | undefined;
61
68
  presence_penalty?: number | null | undefined;
62
69
  } | null | undefined>;
63
70
  agents: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString, "many">>>;
@@ -71,7 +78,7 @@ declare const aigneFileSchema: z.ZodObject<{
71
78
  temperature?: number | null | undefined;
72
79
  provider?: string | null | undefined;
73
80
  top_p?: number | null | undefined;
74
- frequent_penalty?: number | null | undefined;
81
+ frequency_penalty?: number | null | undefined;
75
82
  presence_penalty?: number | null | undefined;
76
83
  } | null | undefined;
77
84
  agents?: string[] | null | undefined;
@@ -84,7 +91,7 @@ declare const aigneFileSchema: z.ZodObject<{
84
91
  temperature?: number | null | undefined;
85
92
  provider?: string | null | undefined;
86
93
  top_p?: number | null | undefined;
87
- frequent_penalty?: number | null | undefined;
94
+ frequency_penalty?: number | null | undefined;
88
95
  presence_penalty?: number | null | undefined;
89
96
  } | null | undefined;
90
97
  agents?: string[] | null | undefined;
@@ -98,7 +105,7 @@ export declare function loadAIGNEFile(path: string): Promise<{
98
105
  temperature?: number | null | undefined;
99
106
  provider?: string | null | undefined;
100
107
  top_p?: number | null | undefined;
101
- frequent_penalty?: number | null | undefined;
108
+ frequency_penalty?: number | null | undefined;
102
109
  presence_penalty?: number | null | undefined;
103
110
  } | null | undefined;
104
111
  agents?: string[] | null | undefined;
@@ -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>;
@@ -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, _context: Context): Promise<Message>;
66
+ process(_input: Message, _options: AgentInvokeOptions): Promise<Message>;
66
67
  /**
67
68
  * Retrieves memories based on the provided input criteria.
68
69
  *
@@ -39,11 +39,11 @@ export declare const memoryRetrieverInputSchema: z.ZodObject<{
39
39
  limit: z.ZodOptional<z.ZodNumber>;
40
40
  search: z.ZodOptional<z.ZodString>;
41
41
  }, "strip", z.ZodTypeAny, {
42
- limit?: number | undefined;
43
42
  search?: string | undefined;
44
- }, {
45
43
  limit?: number | undefined;
44
+ }, {
46
45
  search?: string | undefined;
46
+ limit?: number | undefined;
47
47
  }>;
48
48
  /**
49
49
  * @hidden
@@ -1,17 +1,23 @@
1
1
  import type { GetPromptResult } from "@modelcontextprotocol/sdk/types.js";
2
2
  import { Agent, type Message } from "../agents/agent.js";
3
3
  import type { AIAgent } from "../agents/ai-agent.js";
4
+ import type { ChatModel, ChatModelInput } from "../agents/chat-model.js";
4
5
  import type { Context } from "../aigne/context.js";
5
6
  import type { MemoryAgent } from "../memory/memory.js";
6
- 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
- export declare function createMessage<I extends Message>(message: string | I): I;
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;
13
19
  }
14
- export interface PromptBuilderBuildOptions {
20
+ export interface PromptBuildOptions {
15
21
  memory?: MemoryAgent | MemoryAgent[];
16
22
  context: Context;
17
23
  agent?: AIAgent;
@@ -32,7 +38,7 @@ export declare class PromptBuilder {
32
38
  private static fromMCPPromptResult;
33
39
  constructor(options?: PromptBuilderOptions);
34
40
  instructions?: string | ChatMessagesTemplate;
35
- build(options: PromptBuilderBuildOptions): Promise<ChatModelInput & {
41
+ build(options: PromptBuildOptions): Promise<ChatModelInput & {
36
42
  toolAgents?: Agent[];
37
43
  }>;
38
44
  private buildMessages;
@@ -1,4 +1,4 @@
1
- import type { ChatModelInputMessage, ChatModelInputMessageContent, ChatModelOutputToolCall } from "../models/chat-model.js";
1
+ import type { ChatModelInputMessage, ChatModelInputMessageContent, ChatModelOutputToolCall } from "../agents/chat-model.js";
2
2
  export declare class PromptTemplate {
3
3
  template: string;
4
4
  static from(template: string): PromptTemplate;
@@ -24,7 +24,7 @@ export declare class AgentMessageTemplate extends ChatMessageTemplate {
24
24
  constructor(content?: ChatModelInputMessage["content"], toolCalls?: ChatModelOutputToolCall[] | undefined, name?: string);
25
25
  format(variables?: Record<string, unknown>): {
26
26
  toolCalls: ChatModelOutputToolCall[] | undefined;
27
- role: import("../models/chat-model.js").Role;
27
+ role: import("../agents/chat-model.js").Role;
28
28
  content?: ChatModelInputMessageContent;
29
29
  toolCallId?: string;
30
30
  name?: string;
@@ -36,7 +36,7 @@ export declare class ToolMessageTemplate extends ChatMessageTemplate {
36
36
  constructor(content: object | string, toolCallId: string, name?: string);
37
37
  format(variables?: Record<string, unknown>): {
38
38
  toolCallId: string;
39
- role: import("../models/chat-model.js").Role;
39
+ role: import("../agents/chat-model.js").Role;
40
40
  content?: ChatModelInputMessageContent;
41
41
  toolCalls?: {
42
42
  id: string;
@@ -1,8 +1,33 @@
1
- import debug from "debug";
2
- export declare const logger: debug.Debug & {
3
- debug: debug.Debug;
4
- default: debug.Debug;
5
- } & {
6
- core: debug.Debugger;
7
- mcp: debug.Debugger;
8
- };
1
+ export declare enum LogLevel {
2
+ ERROR = "error",
3
+ WARN = "warn",
4
+ INFO = "info",
5
+ DEBUG = "debug"
6
+ }
7
+ export declare class Logger {
8
+ constructor(options: {
9
+ level: LogLevel;
10
+ ns: string;
11
+ });
12
+ level: LogLevel;
13
+ private debugLogger;
14
+ private infoLogger;
15
+ private warnLogger;
16
+ private errorLogger;
17
+ logMessage: {
18
+ (...data: any[]): void;
19
+ (...data: any[]): void;
20
+ (message?: any, ...optionalParams: any[]): void;
21
+ };
22
+ logError: {
23
+ (...data: any[]): void;
24
+ (...data: any[]): void;
25
+ (message?: any, ...optionalParams: any[]): void;
26
+ };
27
+ debug(message: string, ...args: unknown[]): void;
28
+ info(message: string, ...args: unknown[]): void;
29
+ warn(message: string, ...args: unknown[]): void;
30
+ error(message: string, ...args: unknown[]): void;
31
+ enabled(level: LogLevel): boolean;
32
+ }
33
+ export declare const logger: Logger;
@@ -1,3 +1,3 @@
1
- import type { ChatModelOutputUsage } from "../models/chat-model.js";
1
+ import type { ChatModelOutputUsage } from "../agents/chat-model.js";
2
2
  import type { Nullish } from "./type-utils.js";
3
3
  export declare function mergeUsage(...usages: Nullish<ChatModelOutputUsage>[]): ChatModelOutputUsage;
@@ -6,7 +6,7 @@ export declare function mergeAgentResponseChunk<T extends Message>(output: T, ch
6
6
  export declare function agentResponseStreamToObject<T extends Message>(stream: AgentResponseStream<T> | AgentProcessAsyncGenerator<T>): Promise<T>;
7
7
  export declare function asyncGeneratorToReadableStream<T extends Message>(generator: AgentProcessAsyncGenerator<T>): AgentResponseStream<T>;
8
8
  export declare function onAgentResponseStreamEnd<T extends Message>(stream: AgentResponseStream<T>, callback: (result: T) => PromiseOrValue<Partial<T> | void>, options?: {
9
- errorCallback?: (error: Error) => Error;
9
+ errorCallback?: (error: Error) => PromiseOrValue<Error>;
10
10
  processChunk?: (chunk: AgentResponseChunk<T>) => AgentResponseChunk<T>;
11
11
  }): ReadableStream<any>;
12
12
  export declare function isAsyncGenerator<T extends AsyncGenerator>(value: AsyncGenerator | unknown): value is T;
@@ -19,3 +19,5 @@ export declare function readableStreamToArray<T>(stream: ReadableStream<T>, opti
19
19
  catchError?: false;
20
20
  }): Promise<T[]>;
21
21
  export declare function stringToAgentResponseStream(str: string, key?: "text" | typeof MESSAGE_KEY | string): AgentResponseStream<Message>;
22
+ export declare function toReadableStream(stream: NodeJS.ReadStream): ReadableStream<Uint8Array<ArrayBufferLike>>;
23
+ export declare function readAllString(stream: NodeJS.ReadStream | ReadableStream): Promise<string>;
@@ -1,7 +1,12 @@
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;
5
+ export type XOr<T, K extends keyof T, O extends keyof T> = (Omit<T, O> & {
6
+ [key in O]?: undefined;
7
+ }) | (Omit<T, K> & {
8
+ [key in K]?: undefined;
9
+ });
5
10
  export declare function isNil(value: unknown): value is null | undefined;
6
11
  export declare function isRecord<T>(value: unknown): value is Record<string, T>;
7
12
  export declare function isEmpty(obj: unknown): boolean;
@@ -15,6 +20,6 @@ export declare function orArrayToArray<T>(value?: T | T[]): T[];
15
20
  export declare function createAccessorArray<T>(array: T[], accessor: (array: T[], name: string) => T | undefined): T[] & {
16
21
  [key: string]: T;
17
22
  };
18
- export declare function checkArguments<T>(prefix: string, schema: ZodType<T>, args: T | unknown): T;
23
+ export declare function checkArguments<T extends ZodType>(prefix: string, schema: T, args: unknown): z.infer<T>;
19
24
  export declare function tryOrThrow<P extends PromiseOrValue<unknown>>(fn: () => P, error: string | Error | ((error: Error) => Error)): P;
20
25
  export declare function tryOrThrow<P extends PromiseOrValue<unknown>>(fn: () => P, error?: Nullish<string | Error | ((error: Error) => Nullish<Error>)>): P | undefined;