@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
package/CHANGELOG.md CHANGED
@@ -22,6 +22,28 @@
22
22
  * rename @aigne/core-next to @aigne/core ([3a81009](https://github.com/AIGNE-io/aigne-framework/commit/3a8100962c81813217b687ae28e8de604419c622))
23
23
  * use text resource from MCP correctly ([8b9eba8](https://github.com/AIGNE-io/aigne-framework/commit/8b9eba83352ec096a2a5d4f410d4c4bde7420bce))
24
24
 
25
+ ## [1.17.0](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.16.0...core-v1.17.0) (2025-05-25)
26
+
27
+
28
+ ### Features
29
+
30
+ * add user context support ([#131](https://github.com/AIGNE-io/aigne-framework/issues/131)) ([4dd9d20](https://github.com/AIGNE-io/aigne-framework/commit/4dd9d20953f6ac33933723db56efd9b44bafeb02))
31
+
32
+ ## [1.16.0](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.15.0...core-v1.16.0) (2025-05-23)
33
+
34
+
35
+ ### Features
36
+
37
+ * add `--chat` option for `run` command ([#120](https://github.com/AIGNE-io/aigne-framework/issues/120)) ([7699550](https://github.com/AIGNE-io/aigne-framework/commit/76995507001ca33b09b29f72ff588dae513cb340))
38
+ * **core:** support check output with guide rail agents ([#117](https://github.com/AIGNE-io/aigne-framework/issues/117)) ([bdf7ab3](https://github.com/AIGNE-io/aigne-framework/commit/bdf7ab31789379ba5b0fd920541a469cb86150ff))
39
+ * **core:** support lifecycle hooks for agent ([#124](https://github.com/AIGNE-io/aigne-framework/issues/124)) ([0af6afa](https://github.com/AIGNE-io/aigne-framework/commit/0af6afa923dcb917d545fd4535cabe7804fa84c9))
40
+ * **models:** publish model adapters as standalone packages ([#126](https://github.com/AIGNE-io/aigne-framework/issues/126)) ([588b8ae](https://github.com/AIGNE-io/aigne-framework/commit/588b8aea6abcee5fa87def1358bf51f84021c6ef))
41
+
42
+
43
+ ### Bug Fixes
44
+
45
+ * automatically convert tool names to a valid format ([#128](https://github.com/AIGNE-io/aigne-framework/issues/128)) ([e9ee91d](https://github.com/AIGNE-io/aigne-framework/commit/e9ee91d9d782fa19000adb4cf95b9d65196ab651))
46
+
25
47
  ## [1.15.0](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.14.0...core-v1.15.0) (2025-05-15)
26
48
 
27
49
 
package/README.md CHANGED
@@ -16,12 +16,12 @@ Core library of [AIGNE Framework](https://github.com/AIGNE-io/aigne-framework) f
16
16
 
17
17
  ## Features
18
18
 
19
- - **Multiple AI Model Support**: Built-in support for OpenAI, Gemini, Claude, Nova, and other mainstream AI models, easily extensible to support additional models
20
- - **Agent System**: Powerful agent abstractions supporting AI agents, function agents, MCP agents, and more
21
- - **AIGNE Environment**: Flexible handling communication between agents and workflow execution
22
- - **Workflow Patterns**: Support for sequential, concurrent, routing, handoff, and other workflow patterns
23
- - **MCP Protocol Integration**: Seamless integration with external systems through the Model Context Protocol
24
- - **TypeScript Support**: Comprehensive type definitions providing an excellent development experience
19
+ * **Multiple AI Model Support**: Built-in support for OpenAI, Gemini, Claude, Nova, and other mainstream AI models, easily extensible to support additional models
20
+ * **Agent System**: Powerful agent abstractions supporting AI agents, function agents, MCP agents, and more
21
+ * **AIGNE Environment**: Flexible handling communication between agents and workflow execution
22
+ * **Workflow Patterns**: Support for sequential, concurrent, routing, handoff, and other workflow patterns
23
+ * **MCP Protocol Integration**: Seamless integration with external systems through the Model Context Protocol
24
+ * **TypeScript Support**: Comprehensive type definitions providing an excellent development experience
25
25
 
26
26
  ## Installation
27
27
 
@@ -68,7 +68,9 @@ const aigne = new AIGNE({ model });
68
68
  const userAgent = await aigne.invoke(agent);
69
69
 
70
70
  // Send a message to the agent
71
- const response = await userAgent.invoke("Hello, can you help me write a short article?");
71
+ const response = await userAgent.invoke(
72
+ "Hello, can you help me write a short article?",
73
+ );
72
74
  console.log(response);
73
75
  ```
74
76
 
package/README.zh.md CHANGED
@@ -16,12 +16,12 @@
16
16
 
17
17
  ## 特性
18
18
 
19
- - **多 AI 模型支持**:内置支持 OpenAI、Gemini、Claude、Nova 等主流 AI 模型,可轻松扩展支持其他模型
20
- - **代理系统**:强大的代理抽象,支持 AI 代理、功能代理、MCP 代理等
21
- - **AIGNE 环境**:灵活处理代理之间的通信和工作流执行
22
- - **工作流模式**:支持顺序、并发、路由、交接等多种工作流模式
23
- - **MCP 协议集成**:通过模型上下文协议与外部系统无缝集成
24
- - **TypeScript 支持**:全面的类型定义,提供出色的开发体验
19
+ * **多 AI 模型支持**:内置支持 OpenAI、Gemini、Claude、Nova 等主流 AI 模型,可轻松扩展支持其他模型
20
+ * **代理系统**:强大的代理抽象,支持 AI 代理、功能代理、MCP 代理等
21
+ * **AIGNE 环境**:灵活处理代理之间的通信和工作流执行
22
+ * **工作流模式**:支持顺序、并发、路由、交接等多种工作流模式
23
+ * **MCP 协议集成**:通过模型上下文协议与外部系统无缝集成
24
+ * **TypeScript 支持**:全面的类型定义,提供出色的开发体验
25
25
 
26
26
  ## 安装
27
27
 
@@ -68,7 +68,9 @@ const aigne = new AIGNE({ model });
68
68
  const userAgent = await aigne.invoke(agent);
69
69
 
70
70
  // 向代理发送消息
71
- const response = await userAgent.invoke("Hello, can you help me write a short article?");
71
+ const response = await userAgent.invoke(
72
+ "Hello, can you help me write a short article?",
73
+ );
72
74
  console.log(response);
73
75
  ```
74
76
 
@@ -1,9 +1,10 @@
1
1
  import { inspect } from "node:util";
2
2
  import { ZodObject, type ZodType } from "zod";
3
- import type { Context } from "../aigne/context.js";
3
+ import type { Context, UserContext } from "../aigne/context.js";
4
4
  import type { MessagePayload } from "../aigne/message-queue.js";
5
5
  import type { MemoryAgent } from "../memory/memory.js";
6
- import { type Nullish, type PromiseOrValue } from "../utils/type-utils.js";
6
+ import { type Nullish, type PromiseOrValue, type XOr } from "../utils/type-utils.js";
7
+ import type { GuideRailAgent, GuideRailAgentOutput } from "./guide-rail-agent.js";
7
8
  import { type TransferAgentOutput } from "./types.js";
8
9
  export * from "./types.js";
9
10
  /**
@@ -29,7 +30,7 @@ export type PublishTopic<O extends Message> = string | string[] | ((output: O) =
29
30
  * @template I The agent input message type
30
31
  * @template O The agent output message type
31
32
  */
32
- export interface AgentOptions<I extends Message = Message, O extends Message = Message> {
33
+ export interface AgentOptions<I extends Message = Message, O extends Message = Message> extends Partial<Pick<Agent, "guideRails" | "hooks">> {
33
34
  /**
34
35
  * Topics the agent should subscribe to
35
36
  *
@@ -98,7 +99,21 @@ export interface AgentOptions<I extends Message = Message, O extends Message = M
98
99
  export declare const agentOptionsSchema: ZodObject<{
99
100
  [key in keyof AgentOptions]: ZodType<AgentOptions[key]>;
100
101
  }>;
101
- export interface AgentInvokeOptions {
102
+ export interface AgentInvokeOptions<U extends UserContext = UserContext> {
103
+ /**
104
+ * The execution context for the agent
105
+ *
106
+ * The context provides the runtime environment for agent execution, including:
107
+ * - Event emission and subscription management
108
+ * - Inter-agent communication and message passing
109
+ * - Resource usage tracking and limits enforcement
110
+ * - Timeout and status management
111
+ * - Memory and state management across agent invocations
112
+ *
113
+ * Each agent invocation requires a context to coordinate with the broader
114
+ * agent system and maintain proper isolation and resource control.
115
+ */
116
+ context: Context<U>;
102
117
  /**
103
118
  * Whether to enable streaming response
104
119
  *
@@ -139,6 +154,35 @@ export declare abstract class Agent<I extends Message = Message, O extends Messa
139
154
  * List of memories this agent can use
140
155
  */
141
156
  readonly memories: MemoryAgent[];
157
+ /**
158
+ * Lifecycle hooks for agent processing.
159
+ *
160
+ * Hooks enable tracing, logging, monitoring, and custom behavior
161
+ * without modifying the core agent implementation
162
+ *
163
+ * @example
164
+ * Here's an example of using hooks:
165
+ * {@includeCode ../../test/agents/agent.test.ts#example-agent-hooks}
166
+ */
167
+ readonly hooks: AgentHooks;
168
+ /**
169
+ * List of GuideRail agents applied to this agent
170
+ *
171
+ * GuideRail agents validate, transform, or control the message flow by:
172
+ * - Enforcing rules and safety policies
173
+ * - Validating inputs/outputs against specific criteria
174
+ * - Implementing business logic validations
175
+ * - Monitoring and auditing agent behavior
176
+ *
177
+ * Each GuideRail agent can examine both input and expected output,
178
+ * and has the ability to abort the process with an explanation
179
+ *
180
+ * @example
181
+ * Here's an example of using GuideRail agents:
182
+ *
183
+ * {@includeCode ../../test/agents/agent.test.ts#example-agent-guide-rails}
184
+ */
185
+ readonly guideRails?: GuideRailAgent[];
142
186
  /**
143
187
  * Name of the agent, used for identification and logging
144
188
  *
@@ -248,7 +292,7 @@ export declare abstract class Agent<I extends Message = Message, O extends Messa
248
292
  /**
249
293
  * Check context status to ensure it hasn't timed out
250
294
  *
251
- * @param context The context to check
295
+ * @param options Invocation options containing context
252
296
  * @throws Error if the context has timed out
253
297
  */
254
298
  private checkContextStatus;
@@ -260,7 +304,6 @@ export declare abstract class Agent<I extends Message = Message, O extends Messa
260
304
  * suitable for scenarios where a complete result is needed at once.
261
305
  *
262
306
  * @param input Input message to the agent, can be a string or structured object
263
- * @param context Execution context, providing environment and resource access
264
307
  * @param options Invocation options, must set streaming to false or leave unset
265
308
  * @returns Final JSON response
266
309
  *
@@ -268,7 +311,7 @@ export declare abstract class Agent<I extends Message = Message, O extends Messa
268
311
  * Here's an example of invoking an agent with regular mode:
269
312
  * {@includeCode ../../test/agents/agent.test.ts#example-invoke}
270
313
  */
271
- invoke(input: I | string, context?: Context, options?: AgentInvokeOptions & {
314
+ invoke(input: I | string, options?: Partial<AgentInvokeOptions> & {
272
315
  streaming?: false;
273
316
  }): Promise<O>;
274
317
  /**
@@ -279,7 +322,6 @@ export declare abstract class Agent<I extends Message = Message, O extends Messa
279
322
  * chat bot typing effects.
280
323
  *
281
324
  * @param input Input message to the agent, can be a string or structured object
282
- * @param context Execution context, providing environment and resource access
283
325
  * @param options Invocation options, must set streaming to true for this overload
284
326
  * @returns Streaming response object
285
327
  *
@@ -287,7 +329,7 @@ export declare abstract class Agent<I extends Message = Message, O extends Messa
287
329
  * Here's an example of invoking an agent with streaming response:
288
330
  * {@includeCode ../../test/agents/agent.test.ts#example-invoke-streaming}
289
331
  */
290
- invoke(input: I | string, context: Context | undefined, options: {
332
+ invoke(input: I | string, options: Partial<AgentInvokeOptions> & {
291
333
  streaming: true;
292
334
  }): Promise<AgentResponseStream<O>>;
293
335
  /**
@@ -296,11 +338,11 @@ export declare abstract class Agent<I extends Message = Message, O extends Messa
296
338
  * Returns either streaming or regular response based on the streaming parameter in options
297
339
  *
298
340
  * @param input Input message to the agent
299
- * @param context Execution context
300
341
  * @param options Invocation options
301
342
  * @returns Agent response (streaming or regular)
302
343
  */
303
- invoke(input: I | string, context?: Context, options?: AgentInvokeOptions): Promise<AgentResponse<O>>;
344
+ invoke(input: I | string, options?: Partial<AgentInvokeOptions>): Promise<AgentResponse<O>>;
345
+ protected invokeSkill<I extends Message, O extends Message>(skill: Agent<I, O>, input: I, options: AgentInvokeOptions): Promise<O>;
304
346
  /**
305
347
  * Process agent output
306
348
  *
@@ -308,7 +350,7 @@ export declare abstract class Agent<I extends Message = Message, O extends Messa
308
350
  *
309
351
  * @param input Original input message
310
352
  * @param output Raw output produced by the agent
311
- * @param context Execution context
353
+ * @param options Invocation options
312
354
  * @returns Final processed output
313
355
  */
314
356
  private processAgentOutput;
@@ -318,8 +360,7 @@ export declare abstract class Agent<I extends Message = Message, O extends Messa
318
360
  * Logs error information, triggers failure events, and re-throws the error
319
361
  *
320
362
  * @param error Caught error
321
- * @param context Execution context
322
- * @throws Always throws the received error
363
+ * @param options Invocation options
323
364
  */
324
365
  private processAgentError;
325
366
  /**
@@ -328,10 +369,10 @@ export declare abstract class Agent<I extends Message = Message, O extends Messa
328
369
  * If the context has a maximum invocation limit set, checks if the limit
329
370
  * has been exceeded and increments the invocation counter
330
371
  *
331
- * @param context Execution context
372
+ * @param options Invocation options containing context and limits
332
373
  * @throws Error if maximum invocation limit is exceeded
333
374
  */
334
- protected checkAgentInvokesUsage(context: Context): void;
375
+ protected checkAgentInvokesUsage(options: AgentInvokeOptions): void;
335
376
  /**
336
377
  * Pre-processing operations before handling input
337
378
  *
@@ -340,9 +381,27 @@ export declare abstract class Agent<I extends Message = Message, O extends Messa
340
381
  * - Verifying invocation limits
341
382
  *
342
383
  * @param _ Input message (unused)
343
- * @param context Execution context
384
+ * @param options Options for agent invocation
344
385
  */
345
- protected preprocess(_: I, context: Context): void;
386
+ protected preprocess(_: I, options: AgentInvokeOptions): Promise<void>;
387
+ private checkResponseByGuideRails;
388
+ private runGuideRails;
389
+ /**
390
+ * Handle errors detected by GuideRail agents
391
+ *
392
+ * This method is called when a GuideRail agent aborts the process, providing
393
+ * a way for agents to customize error handling behavior. By default, it simply
394
+ * returns the original error, but subclasses can override this method to:
395
+ * - Transform the error into a more specific response
396
+ * - Apply recovery strategies
397
+ * - Log or report the error in a custom format
398
+ * - Return a fallback output instead of an error
399
+ *
400
+ * @param error The GuideRail agent output containing abort=true and a reason
401
+ * @returns Either the original/modified error or a substitute output object
402
+ * which will be tagged with $status: "GuideRailError"
403
+ */
404
+ protected onGuideRailError(error: GuideRailAgentOutput): Promise<O | GuideRailAgentOutput>;
346
405
  /**
347
406
  * Post-processing operations after handling output
348
407
  *
@@ -352,10 +411,10 @@ export declare abstract class Agent<I extends Message = Message, O extends Messa
352
411
  *
353
412
  * @param input Input message
354
413
  * @param output Output message
355
- * @param context Execution context
414
+ * @param options Options for agent invocation
356
415
  */
357
- protected postprocess(input: I, output: O, context: Context): void;
358
- protected publishToTopics(output: Message, context: Context): Promise<void>;
416
+ protected postprocess(input: I, output: O, options: AgentInvokeOptions): Promise<void>;
417
+ protected publishToTopics(output: Message, options: AgentInvokeOptions): Promise<void>;
359
418
  /**
360
419
  * Core processing method of the agent, must be implemented in subclasses
361
420
  *
@@ -367,7 +426,7 @@ export declare abstract class Agent<I extends Message = Message, O extends Messa
367
426
  * - Another agent instance (transfer agent)
368
427
  *
369
428
  * @param input Input message
370
- * @param context Execution context
429
+ * @param options Options for agent invocation
371
430
  * @returns Processing result
372
431
  *
373
432
  * @example
@@ -386,7 +445,7 @@ export declare abstract class Agent<I extends Message = Message, O extends Messa
386
445
  * Example of transfer to another agent:
387
446
  * {@includeCode ../../test/agents/agent.test.ts#example-process-transfer}
388
447
  */
389
- abstract process(input: I, context: Context): PromiseOrValue<AgentProcessResult<O>>;
448
+ abstract process(input: I, options: AgentInvokeOptions): PromiseOrValue<AgentProcessResult<O>>;
390
449
  /**
391
450
  * Shut down the agent and clean up resources
392
451
  *
@@ -419,6 +478,86 @@ export declare abstract class Agent<I extends Message = Message, O extends Messa
419
478
  */
420
479
  [Symbol.asyncDispose](): Promise<void>;
421
480
  }
481
+ /**
482
+ * Lifecycle hooks for agent execution
483
+ *
484
+ * Hooks provide a way to intercept and extend agent behavior at key points during
485
+ * the agent's lifecycle, enabling custom functionality like logging, monitoring,
486
+ * tracing, error handling, and more.
487
+ */
488
+ export interface AgentHooks<I extends Message = Message, O extends Message = Message> {
489
+ /**
490
+ * Called when agent processing begins
491
+ *
492
+ * This hook runs before the agent processes input, allowing for
493
+ * setup operations, logging, or input transformations.
494
+ *
495
+ * @param event Object containing the input message
496
+ */
497
+ onStart?: (event: {
498
+ context: Context;
499
+ input: I;
500
+ }) => PromiseOrValue<void>;
501
+ /**
502
+ * Called when agent processing completes or fails
503
+ *
504
+ * This hook runs after processing finishes, receiving either the output
505
+ * or an error if processing failed. Useful for cleanup operations,
506
+ * logging results, or error handling.
507
+ *
508
+ * @param event Object containing the input message and either output or error
509
+ */
510
+ onEnd?: (event: XOr<{
511
+ context: Context;
512
+ input: I;
513
+ output: O;
514
+ error: Error;
515
+ }, "output", "error">) => PromiseOrValue<void>;
516
+ /**
517
+ * Called before a skill (sub-agent) is invoked
518
+ *
519
+ * This hook runs when the agent delegates work to a skill,
520
+ * allowing for tracking skill usage or transforming input to the skill.
521
+ *
522
+ * @param event Object containing the skill being used and input message
523
+ */
524
+ onSkillStart?: (event: {
525
+ context: Context;
526
+ skill: Agent;
527
+ input: I;
528
+ }) => PromiseOrValue<void>;
529
+ /**
530
+ * Called after a skill (sub-agent) completes or fails
531
+ *
532
+ * This hook runs when a skill finishes execution, receiving either the output
533
+ * or an error if the skill failed. Useful for monitoring skill performance
534
+ * or handling skill-specific errors.
535
+ *
536
+ * @param event Object containing the skill used, input message, and either output or error
537
+ */
538
+ onSkillEnd?: (event: XOr<{
539
+ context: Context;
540
+ skill: Agent;
541
+ input: I;
542
+ output: O;
543
+ error: Error;
544
+ }, "output", "error">) => PromiseOrValue<void>;
545
+ /**
546
+ * Called when an agent hands off processing to another agent
547
+ *
548
+ * This hook runs when a source agent transfers control to a target agent,
549
+ * allowing for tracking of handoffs between agents and monitoring the flow
550
+ * of processing in multi-agent systems.
551
+ *
552
+ * @param event Object containing the source agent, target agent, and input message
553
+ */
554
+ onHandoff?: (event: {
555
+ context: Context;
556
+ source: Agent;
557
+ target: Agent;
558
+ input: I;
559
+ }) => PromiseOrValue<void>;
560
+ }
422
561
  /**
423
562
  * Response type for an agent, can be:
424
563
  * - Direct response object
@@ -427,7 +566,7 @@ export declare abstract class Agent<I extends Message = Message, O extends Messa
427
566
  *
428
567
  * @template T Response data type
429
568
  */
430
- export type AgentResponse<T> = T | TransferAgentOutput | AgentResponseStream<T>;
569
+ export type AgentResponse<T> = T | AgentResponseStream<T> | TransferAgentOutput | GuideRailAgentOutput;
431
570
  /**
432
571
  * Streaming response type for an agent
433
572
  *
@@ -464,7 +603,7 @@ export interface AgentResponseDelta<T> {
464
603
  }> | Partial<{
465
604
  [key: string]: string;
466
605
  }>;
467
- json?: Partial<T | TransferAgentOutput>;
606
+ json?: Partial<T> | TransferAgentOutput;
468
607
  };
469
608
  }
470
609
  /**
@@ -496,7 +635,7 @@ export declare function jsonDelta<T extends Message>(jsonDelta: NonNullable<Agen
496
635
  *
497
636
  * @template O Agent output message type
498
637
  */
499
- export type AgentProcessAsyncGenerator<O extends Message> = AsyncGenerator<AgentResponseChunk<O>, Partial<O | TransferAgentOutput> | undefined | void>;
638
+ export type AgentProcessAsyncGenerator<O extends Message> = AsyncGenerator<AgentResponseChunk<O>, Partial<O> | TransferAgentOutput | undefined | void>;
500
639
  /**
501
640
  * Result type for agent processing method, can be:
502
641
  * - Direct or streaming response
@@ -586,10 +725,10 @@ export declare class FunctionAgent<I extends Message = Message, O extends Messag
586
725
  * Process input implementation, calls the configured processing function
587
726
  *
588
727
  * @param input Input message
589
- * @param context Execution context
728
+ * @param options Invocation options
590
729
  * @returns Processing result
591
730
  */
592
- process(input: I, context: Context): PromiseOrValue<AgentProcessResult<O>>;
731
+ process(input: I, options: AgentInvokeOptions): PromiseOrValue<AgentProcessResult<O>>;
593
732
  }
594
733
  /**
595
734
  * Function type for function agents
@@ -602,4 +741,4 @@ export declare class FunctionAgent<I extends Message = Message, O extends Messag
602
741
  * @param context Execution context
603
742
  * @returns Processing result, can be synchronous or asynchronous
604
743
  */
605
- export type FunctionAgentFn<I extends Message = any, O extends Message = any> = (input: I, context: Context) => PromiseOrValue<AgentProcessResult<O>>;
744
+ export type FunctionAgentFn<I extends Message = any, O extends Message = any> = (input: I, options: AgentInvokeOptions) => PromiseOrValue<AgentProcessResult<O>>;