@agentscope-ai/agentscope 0.0.2

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 (136) hide show
  1. package/dist/agent/index.d.mts +234 -0
  2. package/dist/agent/index.d.ts +234 -0
  3. package/dist/agent/index.js +1412 -0
  4. package/dist/agent/index.js.map +1 -0
  5. package/dist/agent/index.mjs +1375 -0
  6. package/dist/agent/index.mjs.map +1 -0
  7. package/dist/base-BOx3UzOl.d.mts +41 -0
  8. package/dist/base-BoIps2RL.d.ts +41 -0
  9. package/dist/base-C7jwyH4Z.d.mts +52 -0
  10. package/dist/base-Cwi4bjze.d.ts +127 -0
  11. package/dist/base-DYlBMCy_.d.mts +127 -0
  12. package/dist/base-NX-knWOv.d.ts +52 -0
  13. package/dist/block-VsnHrllL.d.mts +48 -0
  14. package/dist/block-VsnHrllL.d.ts +48 -0
  15. package/dist/event/index.d.mts +181 -0
  16. package/dist/event/index.d.ts +181 -0
  17. package/dist/event/index.js +58 -0
  18. package/dist/event/index.js.map +1 -0
  19. package/dist/event/index.mjs +33 -0
  20. package/dist/event/index.mjs.map +1 -0
  21. package/dist/formatter/index.d.mts +187 -0
  22. package/dist/formatter/index.d.ts +187 -0
  23. package/dist/formatter/index.js +647 -0
  24. package/dist/formatter/index.js.map +1 -0
  25. package/dist/formatter/index.mjs +616 -0
  26. package/dist/formatter/index.mjs.map +1 -0
  27. package/dist/index-BTJDlKvQ.d.mts +195 -0
  28. package/dist/index-BcatlwXQ.d.ts +195 -0
  29. package/dist/index-CAxQAkiP.d.mts +21 -0
  30. package/dist/index-CAxQAkiP.d.ts +21 -0
  31. package/dist/mcp/index.d.mts +9 -0
  32. package/dist/mcp/index.d.ts +9 -0
  33. package/dist/mcp/index.js +432 -0
  34. package/dist/mcp/index.js.map +1 -0
  35. package/dist/mcp/index.mjs +408 -0
  36. package/dist/mcp/index.mjs.map +1 -0
  37. package/dist/message/index.d.mts +10 -0
  38. package/dist/message/index.d.ts +10 -0
  39. package/dist/message/index.js +67 -0
  40. package/dist/message/index.js.map +1 -0
  41. package/dist/message/index.mjs +37 -0
  42. package/dist/message/index.mjs.map +1 -0
  43. package/dist/message-CkN21KaY.d.mts +99 -0
  44. package/dist/message-CzLeTlua.d.ts +99 -0
  45. package/dist/model/index.d.mts +377 -0
  46. package/dist/model/index.d.ts +377 -0
  47. package/dist/model/index.js +1880 -0
  48. package/dist/model/index.js.map +1 -0
  49. package/dist/model/index.mjs +1849 -0
  50. package/dist/model/index.mjs.map +1 -0
  51. package/dist/storage/index.d.mts +68 -0
  52. package/dist/storage/index.d.ts +68 -0
  53. package/dist/storage/index.js +250 -0
  54. package/dist/storage/index.js.map +1 -0
  55. package/dist/storage/index.mjs +212 -0
  56. package/dist/storage/index.mjs.map +1 -0
  57. package/dist/tool/index.d.mts +311 -0
  58. package/dist/tool/index.d.ts +311 -0
  59. package/dist/tool/index.js +1494 -0
  60. package/dist/tool/index.js.map +1 -0
  61. package/dist/tool/index.mjs +1447 -0
  62. package/dist/tool/index.mjs.map +1 -0
  63. package/dist/toolkit-CEpulFi0.d.ts +99 -0
  64. package/dist/toolkit-CGEZSZPa.d.mts +99 -0
  65. package/jest.config.js +11 -0
  66. package/package.json +92 -0
  67. package/src/_utils/common.ts +104 -0
  68. package/src/_utils/index.ts +1 -0
  69. package/src/agent/agent-base.ts +0 -0
  70. package/src/agent/agent.test.ts +1028 -0
  71. package/src/agent/agent.ts +1032 -0
  72. package/src/agent/index.ts +2 -0
  73. package/src/agent/interfaces.ts +23 -0
  74. package/src/agent/test-compression.ts +72 -0
  75. package/src/event/index.ts +250 -0
  76. package/src/formatter/base.ts +133 -0
  77. package/src/formatter/dashscope-chat-formatter.test.ts +372 -0
  78. package/src/formatter/dashscope-chat-formatter.ts +163 -0
  79. package/src/formatter/deepseek-chat-formatter.ts +130 -0
  80. package/src/formatter/index.ts +5 -0
  81. package/src/formatter/ollama-chat-formatter.ts +67 -0
  82. package/src/formatter/openai-chat-formatter.test.ts +263 -0
  83. package/src/formatter/openai-chat-formatter.ts +301 -0
  84. package/src/formatter/openai.md +767 -0
  85. package/src/mcp/base.ts +114 -0
  86. package/src/mcp/http.test.ts +303 -0
  87. package/src/mcp/http.ts +224 -0
  88. package/src/mcp/index.ts +2 -0
  89. package/src/mcp/stdio.test.ts +91 -0
  90. package/src/mcp/stdio.ts +119 -0
  91. package/src/message/block.ts +60 -0
  92. package/src/message/enums.ts +4 -0
  93. package/src/message/index.ts +12 -0
  94. package/src/message/message.test.ts +80 -0
  95. package/src/message/message.ts +131 -0
  96. package/src/model/base.ts +226 -0
  97. package/src/model/dashscope-model.test.ts +335 -0
  98. package/src/model/dashscope-model.ts +441 -0
  99. package/src/model/deepseek-model.test.ts +279 -0
  100. package/src/model/deepseek-model.ts +401 -0
  101. package/src/model/index.ts +7 -0
  102. package/src/model/ollama-model.test.ts +307 -0
  103. package/src/model/ollama-model.ts +356 -0
  104. package/src/model/openai-model.ts +327 -0
  105. package/src/model/response.ts +22 -0
  106. package/src/model/usage.ts +12 -0
  107. package/src/storage/base.ts +52 -0
  108. package/src/storage/file-system.test.ts +587 -0
  109. package/src/storage/file-system.ts +269 -0
  110. package/src/storage/index.ts +2 -0
  111. package/src/tool/base.ts +23 -0
  112. package/src/tool/bash.test.ts +174 -0
  113. package/src/tool/bash.ts +152 -0
  114. package/src/tool/edit.test.ts +83 -0
  115. package/src/tool/edit.ts +95 -0
  116. package/src/tool/glob.test.ts +63 -0
  117. package/src/tool/glob.ts +166 -0
  118. package/src/tool/grep.test.ts +74 -0
  119. package/src/tool/grep.ts +256 -0
  120. package/src/tool/index.ts +10 -0
  121. package/src/tool/read.test.ts +77 -0
  122. package/src/tool/read.ts +117 -0
  123. package/src/tool/response.ts +82 -0
  124. package/src/tool/task.test.ts +299 -0
  125. package/src/tool/task.ts +399 -0
  126. package/src/tool/toolkit.test.ts +636 -0
  127. package/src/tool/toolkit.ts +601 -0
  128. package/src/tool/write.test.ts +52 -0
  129. package/src/tool/write.ts +57 -0
  130. package/src/type/index.ts +52 -0
  131. package/tsconfig.build.json +4 -0
  132. package/tsconfig.cjs.json +11 -0
  133. package/tsconfig.esm.json +10 -0
  134. package/tsconfig.json +14 -0
  135. package/tsup.config.ts +20 -0
  136. package/typedoc.json +52 -0
@@ -0,0 +1,234 @@
1
+ import { z } from 'zod';
2
+ import { M as Msg } from '../message-CkN21KaY.mjs';
3
+ import { b as ToolCallBlock, C as ContentBlock, c as ToolResultBlock } from '../block-VsnHrllL.mjs';
4
+ import { C as ChatModelBase, a as ChatUsage, b as ChatResponse } from '../base-DYlBMCy_.mjs';
5
+ import { a as ToolResponse } from '../index-BTJDlKvQ.mjs';
6
+ import { T as Toolkit } from '../toolkit-CGEZSZPa.mjs';
7
+ import { UserConfirmResultEvent, ExternalExecutionResultEvent, AgentEvent, EventType, ToolResultTextDeltaEvent, ToolResultBinaryDeltaEvent, ToolResultEndEvent } from '../event/index.mjs';
8
+ import { a as ToolChoice } from '../index-CAxQAkiP.mjs';
9
+ import { S as StorageBase } from '../base-C7jwyH4Z.mjs';
10
+ import '../base-BOx3UzOl.mjs';
11
+ import '@modelcontextprotocol/sdk/client/index.js';
12
+ import '@modelcontextprotocol/sdk/client/sse.js';
13
+ import '@modelcontextprotocol/sdk/client/streamableHttp.js';
14
+ import '@modelcontextprotocol/sdk/shared/protocol.js';
15
+ import '@modelcontextprotocol/sdk/client/stdio.js';
16
+
17
+ interface ReplyOptions {
18
+ msgs?: Msg | Msg[];
19
+ event?: UserConfirmResultEvent | ExternalExecutionResultEvent;
20
+ structuredModel?: z.ZodObject;
21
+ }
22
+ interface ReasoningOptions {
23
+ toolChoice?: ToolChoice;
24
+ }
25
+ interface ActingOptions {
26
+ toolCall: ToolCallBlock;
27
+ }
28
+ interface ObserveOptions {
29
+ msg?: Msg | Msg[];
30
+ }
31
+
32
+ interface CompressionConfig {
33
+ /**
34
+ * Whether to enable memory compression.
35
+ */
36
+ enabled: boolean;
37
+ /**
38
+ * The token count threshold to trigger memory compression.
39
+ */
40
+ triggerThreshold: number;
41
+ /**
42
+ * The function to count the tokens of the messages in memory. If not provided, a heuristic token counting method will be used by default.
43
+ */
44
+ tokenCountFunc?: (msgs: Msg[]) => number;
45
+ /**
46
+ * The chat model used for compression. If not provided, the same model as the agent will be used by default.
47
+ */
48
+ compressionModel?: ChatModelBase;
49
+ /**
50
+ * The prompt template for memory compression. It should be designed to instruct the model to compress the input messages into a concise summary while preserving important information. If not provided, a default prompt will be used.
51
+ */
52
+ compressionPrompt?: string;
53
+ /**
54
+ * The JSON schema for the compressed summary. The model will be guided to compress the memory into a structured summary following this schema. If not provided, a default schema with a single text field will be used.
55
+ */
56
+ summarySchema?: z.ZodObject;
57
+ /**
58
+ * The number of recent messages to keep in the context without compression.
59
+ */
60
+ keepRecent?: number;
61
+ }
62
+ interface AgentOptions {
63
+ name: string;
64
+ sysPrompt: string;
65
+ model: ChatModelBase;
66
+ maxIters?: number;
67
+ toolkit?: Toolkit;
68
+ storage?: StorageBase;
69
+ compressionConfig?: CompressionConfig;
70
+ }
71
+ /**
72
+ * The unified agent class in AgentScope library.
73
+ */
74
+ declare class Agent {
75
+ name: string;
76
+ model: ChatModelBase;
77
+ maxIters: number;
78
+ toolkit: Toolkit;
79
+ storage?: StorageBase;
80
+ context: Msg[];
81
+ private _loaded;
82
+ private _sysPrompt;
83
+ compressionConfig?: CompressionConfig;
84
+ replyId: string;
85
+ curIter: number;
86
+ confirmedToolCallIds: string[];
87
+ curSummary: string;
88
+ /**
89
+ * Initialize an agent instance with the given parameters.
90
+ *
91
+ * @param options - The agent configuration options.
92
+ * @param options.name - The name of the agent.
93
+ * @param options.sysPrompt - The system prompt for the agent.
94
+ * @param options.model - The chat model to use.
95
+ * @param options.maxIters - Maximum iterations (default: 5).
96
+ * @param options.memory - Memory storage (default: InMemoryMemory).
97
+ * @param options.toolkit - Toolkit for tools (default: Toolkit).
98
+ */
99
+ constructor(options: AgentOptions);
100
+ /**
101
+ * Load the state from the storage if storage is provided and not loaded yet.
102
+ */
103
+ loadState(): Promise<void>;
104
+ /**
105
+ * Save the state of the current reply session to storage if storage is provided.
106
+ */
107
+ saveState(): Promise<void>;
108
+ /**
109
+ * Get the system prompt of the agent.
110
+ *
111
+ * @returns The system prompt string.
112
+ */
113
+ get sysPrompt(): string;
114
+ /**
115
+ * Reply to the given message and stream agent events as they are generated.
116
+ *
117
+ * @param options - The reply options containing the incoming message.
118
+ * @returns An async generator that yields agent events and resolves to the final reply message.
119
+ */
120
+ replyStream(options: ReplyOptions): AsyncGenerator<AgentEvent, Msg>;
121
+ /**
122
+ * Reply to the given message, consuming all streamed events internally.
123
+ *
124
+ * @param options - The reply options containing the incoming message.
125
+ * @param options.msgs - The incoming message(s) to reply to.
126
+ * @returns A promise that resolves to the final reply message.
127
+ */
128
+ reply(options: ReplyOptions): Promise<Msg>;
129
+ /**
130
+ * Save the given content blocks into the context as a new block in the last assistant message,
131
+ * or create a new assistant message if the last message is not from the assistant or has a different name.
132
+ * @param blocks
133
+ * @param usage
134
+ */
135
+ protected _saveToContext(blocks: ContentBlock[], usage?: ChatUsage): void;
136
+ /**
137
+ * Get the pending tool calls that have no results yet in the context.
138
+ * @returns An array of pending `ToolCallBlock`s that are waiting for execution results.
139
+ */
140
+ protected _getPendingToolCalls(): ToolCallBlock[];
141
+ /**
142
+ * Get the awaiting tool calls that require user confirmation or external execution.
143
+ * @returns An array of `ToolCallBlock`s that are waiting for user confirmation or external execution.
144
+ */
145
+ protected _getAwaitingToolCalls(): {
146
+ awaitingType?: EventType.REQUIRE_USER_CONFIRM | EventType.REQUIRE_EXTERNAL_EXECUTION;
147
+ expectedEventType?: EventType.USER_CONFIRM_RESULT | EventType.EXTERNAL_EXECUTION_RESULT;
148
+ awaitingToolCalls: ToolCallBlock[];
149
+ preToolCalls: ToolCallBlock[];
150
+ };
151
+ /**
152
+ * Core reply logic without middlewares. Observes the incoming message, runs
153
+ * reasoning/acting iterations up to `maxIters`, and returns the final response.
154
+ *
155
+ * @param options - The reply options containing the incoming message.
156
+ * @returns An async generator that yields agent events and resolves to the final reply message.
157
+ */
158
+ protected _reply(options?: ReplyOptions): AsyncGenerator<AgentEvent, Msg>;
159
+ /**
160
+ * Core reasoning logic without middlewares. Calls the model with the current
161
+ * memory and system prompt, converts the response to agent events, and saves
162
+ * the resulting message to memory.
163
+ *
164
+ * @param options - The reasoning options, including tool choice strategy.
165
+ * @returns An async generator that yields agent events and resolves to the content blocks of the model response.
166
+ */
167
+ protected _reasoning(options: ReasoningOptions): AsyncGenerator<AgentEvent, ChatResponse>;
168
+ /**
169
+ * Core acting logic without middlewares. Executes the given tool call, streams
170
+ * intermediate tool result events, and saves the final tool response to memory.
171
+ *
172
+ * @param options - The acting options containing the tool call to execute.
173
+ * @returns An async generator that yields tool result events.
174
+ */
175
+ protected _acting(options: ActingOptions): AsyncGenerator<AgentEvent, ToolResultBlock>;
176
+ /**
177
+ * Receive external observation message(s) and save them into memory.
178
+ *
179
+ * @param options - The observe options containing the message to store.
180
+ * @returns A promise that resolves when the message has been saved to memory.
181
+ */
182
+ protected _observe(options: ObserveOptions): Promise<void>;
183
+ /**
184
+ * Convert a `ChatResponse` chunk into a sequence of typed agent events.
185
+ * Tracks message IDs across calls via the mutable `responseId` object so that
186
+ * start/content/end events are correctly correlated.
187
+ *
188
+ * @param responseId - Mutable object tracking IDs for the current text, thinking, and tool-call messages.
189
+ * @param responseId.textMessageId - ID of the in-progress text message, or `null` if not yet started.
190
+ * @param responseId.thinkingMessageId - ID of the in-progress thinking message, or `null` if not yet started.
191
+ * @param responseId.textBlockId
192
+ * @param responseId.thinkingBlockId
193
+ * @param responseId.toolCallIds - List of tool-call IDs seen so far in this response.
194
+ * @param chunk - The chat response chunk to convert.
195
+ * @returns An async generator that yields the corresponding agent events.
196
+ */
197
+ protected convertChatResponseToEvent(responseId: {
198
+ textBlockId: string | null;
199
+ thinkingBlockId: string | null;
200
+ toolCallIds: string[];
201
+ }, chunk: ChatResponse): AsyncGenerator<AgentEvent>;
202
+ /**
203
+ * Convert a `ToolResponse` into a sequence of typed agent events, followed by
204
+ * a final `TOOL_RESULT_END` event.
205
+ *
206
+ * @param toolCall - The original tool-use block that triggered this response.
207
+ * @param toolRes - The tool response containing result content blocks.
208
+ * @returns An async generator that yields tool result events.
209
+ */
210
+ protected convertToolResponseToEvent(toolCall: ToolCallBlock, toolRes: ToolResponse): AsyncGenerator<ToolResultTextDeltaEvent | ToolResultBinaryDeltaEvent | ToolResultEndEvent, void, unknown>;
211
+ /**
212
+ * Convert the agent instance to a JSON-serializable object.
213
+ * @returns An object containing the agent's name and system prompt.
214
+ */
215
+ toJSON(): Promise<{
216
+ replyId: string;
217
+ confirmedToolCallIds: string[];
218
+ curIter: number;
219
+ }>;
220
+ /**
221
+ * Split the current context into two parts: one part that needs to be compressed and another part that should be reserved based on the compression configuration. The method calculates how many recent "units" (blocks or tool call pairs) to keep uncompressed according to the `keepRecent` setting in the compression configuration, and ensures that tool calls and their corresponding results are not separated during the split.
222
+ * @returns An object containing the `toCompressedContext` which includes the messages that need to be compressed, and the `reservedContext` which includes the recent messages that should be kept uncompressed.
223
+ */
224
+ protected _splitContextForCompression(): {
225
+ toCompressedContext: Msg[];
226
+ reservedContext: Msg[];
227
+ };
228
+ /**
229
+ * Compress the agent's memory using the specified compression model (if provided) or the original model.
230
+ */
231
+ protected compressMemoryIfNeeded(): Promise<void>;
232
+ }
233
+
234
+ export { type ActingOptions, Agent, type AgentOptions, type CompressionConfig, type ReasoningOptions, type ReplyOptions };
@@ -0,0 +1,234 @@
1
+ import { z } from 'zod';
2
+ import { M as Msg } from '../message-CzLeTlua.js';
3
+ import { b as ToolCallBlock, C as ContentBlock, c as ToolResultBlock } from '../block-VsnHrllL.js';
4
+ import { C as ChatModelBase, a as ChatUsage, b as ChatResponse } from '../base-Cwi4bjze.js';
5
+ import { a as ToolResponse } from '../index-BcatlwXQ.js';
6
+ import { T as Toolkit } from '../toolkit-CEpulFi0.js';
7
+ import { UserConfirmResultEvent, ExternalExecutionResultEvent, AgentEvent, EventType, ToolResultTextDeltaEvent, ToolResultBinaryDeltaEvent, ToolResultEndEvent } from '../event/index.js';
8
+ import { a as ToolChoice } from '../index-CAxQAkiP.js';
9
+ import { S as StorageBase } from '../base-NX-knWOv.js';
10
+ import '../base-BoIps2RL.js';
11
+ import '@modelcontextprotocol/sdk/client/index.js';
12
+ import '@modelcontextprotocol/sdk/client/sse.js';
13
+ import '@modelcontextprotocol/sdk/client/streamableHttp.js';
14
+ import '@modelcontextprotocol/sdk/shared/protocol.js';
15
+ import '@modelcontextprotocol/sdk/client/stdio.js';
16
+
17
+ interface ReplyOptions {
18
+ msgs?: Msg | Msg[];
19
+ event?: UserConfirmResultEvent | ExternalExecutionResultEvent;
20
+ structuredModel?: z.ZodObject;
21
+ }
22
+ interface ReasoningOptions {
23
+ toolChoice?: ToolChoice;
24
+ }
25
+ interface ActingOptions {
26
+ toolCall: ToolCallBlock;
27
+ }
28
+ interface ObserveOptions {
29
+ msg?: Msg | Msg[];
30
+ }
31
+
32
+ interface CompressionConfig {
33
+ /**
34
+ * Whether to enable memory compression.
35
+ */
36
+ enabled: boolean;
37
+ /**
38
+ * The token count threshold to trigger memory compression.
39
+ */
40
+ triggerThreshold: number;
41
+ /**
42
+ * The function to count the tokens of the messages in memory. If not provided, a heuristic token counting method will be used by default.
43
+ */
44
+ tokenCountFunc?: (msgs: Msg[]) => number;
45
+ /**
46
+ * The chat model used for compression. If not provided, the same model as the agent will be used by default.
47
+ */
48
+ compressionModel?: ChatModelBase;
49
+ /**
50
+ * The prompt template for memory compression. It should be designed to instruct the model to compress the input messages into a concise summary while preserving important information. If not provided, a default prompt will be used.
51
+ */
52
+ compressionPrompt?: string;
53
+ /**
54
+ * The JSON schema for the compressed summary. The model will be guided to compress the memory into a structured summary following this schema. If not provided, a default schema with a single text field will be used.
55
+ */
56
+ summarySchema?: z.ZodObject;
57
+ /**
58
+ * The number of recent messages to keep in the context without compression.
59
+ */
60
+ keepRecent?: number;
61
+ }
62
+ interface AgentOptions {
63
+ name: string;
64
+ sysPrompt: string;
65
+ model: ChatModelBase;
66
+ maxIters?: number;
67
+ toolkit?: Toolkit;
68
+ storage?: StorageBase;
69
+ compressionConfig?: CompressionConfig;
70
+ }
71
+ /**
72
+ * The unified agent class in AgentScope library.
73
+ */
74
+ declare class Agent {
75
+ name: string;
76
+ model: ChatModelBase;
77
+ maxIters: number;
78
+ toolkit: Toolkit;
79
+ storage?: StorageBase;
80
+ context: Msg[];
81
+ private _loaded;
82
+ private _sysPrompt;
83
+ compressionConfig?: CompressionConfig;
84
+ replyId: string;
85
+ curIter: number;
86
+ confirmedToolCallIds: string[];
87
+ curSummary: string;
88
+ /**
89
+ * Initialize an agent instance with the given parameters.
90
+ *
91
+ * @param options - The agent configuration options.
92
+ * @param options.name - The name of the agent.
93
+ * @param options.sysPrompt - The system prompt for the agent.
94
+ * @param options.model - The chat model to use.
95
+ * @param options.maxIters - Maximum iterations (default: 5).
96
+ * @param options.memory - Memory storage (default: InMemoryMemory).
97
+ * @param options.toolkit - Toolkit for tools (default: Toolkit).
98
+ */
99
+ constructor(options: AgentOptions);
100
+ /**
101
+ * Load the state from the storage if storage is provided and not loaded yet.
102
+ */
103
+ loadState(): Promise<void>;
104
+ /**
105
+ * Save the state of the current reply session to storage if storage is provided.
106
+ */
107
+ saveState(): Promise<void>;
108
+ /**
109
+ * Get the system prompt of the agent.
110
+ *
111
+ * @returns The system prompt string.
112
+ */
113
+ get sysPrompt(): string;
114
+ /**
115
+ * Reply to the given message and stream agent events as they are generated.
116
+ *
117
+ * @param options - The reply options containing the incoming message.
118
+ * @returns An async generator that yields agent events and resolves to the final reply message.
119
+ */
120
+ replyStream(options: ReplyOptions): AsyncGenerator<AgentEvent, Msg>;
121
+ /**
122
+ * Reply to the given message, consuming all streamed events internally.
123
+ *
124
+ * @param options - The reply options containing the incoming message.
125
+ * @param options.msgs - The incoming message(s) to reply to.
126
+ * @returns A promise that resolves to the final reply message.
127
+ */
128
+ reply(options: ReplyOptions): Promise<Msg>;
129
+ /**
130
+ * Save the given content blocks into the context as a new block in the last assistant message,
131
+ * or create a new assistant message if the last message is not from the assistant or has a different name.
132
+ * @param blocks
133
+ * @param usage
134
+ */
135
+ protected _saveToContext(blocks: ContentBlock[], usage?: ChatUsage): void;
136
+ /**
137
+ * Get the pending tool calls that have no results yet in the context.
138
+ * @returns An array of pending `ToolCallBlock`s that are waiting for execution results.
139
+ */
140
+ protected _getPendingToolCalls(): ToolCallBlock[];
141
+ /**
142
+ * Get the awaiting tool calls that require user confirmation or external execution.
143
+ * @returns An array of `ToolCallBlock`s that are waiting for user confirmation or external execution.
144
+ */
145
+ protected _getAwaitingToolCalls(): {
146
+ awaitingType?: EventType.REQUIRE_USER_CONFIRM | EventType.REQUIRE_EXTERNAL_EXECUTION;
147
+ expectedEventType?: EventType.USER_CONFIRM_RESULT | EventType.EXTERNAL_EXECUTION_RESULT;
148
+ awaitingToolCalls: ToolCallBlock[];
149
+ preToolCalls: ToolCallBlock[];
150
+ };
151
+ /**
152
+ * Core reply logic without middlewares. Observes the incoming message, runs
153
+ * reasoning/acting iterations up to `maxIters`, and returns the final response.
154
+ *
155
+ * @param options - The reply options containing the incoming message.
156
+ * @returns An async generator that yields agent events and resolves to the final reply message.
157
+ */
158
+ protected _reply(options?: ReplyOptions): AsyncGenerator<AgentEvent, Msg>;
159
+ /**
160
+ * Core reasoning logic without middlewares. Calls the model with the current
161
+ * memory and system prompt, converts the response to agent events, and saves
162
+ * the resulting message to memory.
163
+ *
164
+ * @param options - The reasoning options, including tool choice strategy.
165
+ * @returns An async generator that yields agent events and resolves to the content blocks of the model response.
166
+ */
167
+ protected _reasoning(options: ReasoningOptions): AsyncGenerator<AgentEvent, ChatResponse>;
168
+ /**
169
+ * Core acting logic without middlewares. Executes the given tool call, streams
170
+ * intermediate tool result events, and saves the final tool response to memory.
171
+ *
172
+ * @param options - The acting options containing the tool call to execute.
173
+ * @returns An async generator that yields tool result events.
174
+ */
175
+ protected _acting(options: ActingOptions): AsyncGenerator<AgentEvent, ToolResultBlock>;
176
+ /**
177
+ * Receive external observation message(s) and save them into memory.
178
+ *
179
+ * @param options - The observe options containing the message to store.
180
+ * @returns A promise that resolves when the message has been saved to memory.
181
+ */
182
+ protected _observe(options: ObserveOptions): Promise<void>;
183
+ /**
184
+ * Convert a `ChatResponse` chunk into a sequence of typed agent events.
185
+ * Tracks message IDs across calls via the mutable `responseId` object so that
186
+ * start/content/end events are correctly correlated.
187
+ *
188
+ * @param responseId - Mutable object tracking IDs for the current text, thinking, and tool-call messages.
189
+ * @param responseId.textMessageId - ID of the in-progress text message, or `null` if not yet started.
190
+ * @param responseId.thinkingMessageId - ID of the in-progress thinking message, or `null` if not yet started.
191
+ * @param responseId.textBlockId
192
+ * @param responseId.thinkingBlockId
193
+ * @param responseId.toolCallIds - List of tool-call IDs seen so far in this response.
194
+ * @param chunk - The chat response chunk to convert.
195
+ * @returns An async generator that yields the corresponding agent events.
196
+ */
197
+ protected convertChatResponseToEvent(responseId: {
198
+ textBlockId: string | null;
199
+ thinkingBlockId: string | null;
200
+ toolCallIds: string[];
201
+ }, chunk: ChatResponse): AsyncGenerator<AgentEvent>;
202
+ /**
203
+ * Convert a `ToolResponse` into a sequence of typed agent events, followed by
204
+ * a final `TOOL_RESULT_END` event.
205
+ *
206
+ * @param toolCall - The original tool-use block that triggered this response.
207
+ * @param toolRes - The tool response containing result content blocks.
208
+ * @returns An async generator that yields tool result events.
209
+ */
210
+ protected convertToolResponseToEvent(toolCall: ToolCallBlock, toolRes: ToolResponse): AsyncGenerator<ToolResultTextDeltaEvent | ToolResultBinaryDeltaEvent | ToolResultEndEvent, void, unknown>;
211
+ /**
212
+ * Convert the agent instance to a JSON-serializable object.
213
+ * @returns An object containing the agent's name and system prompt.
214
+ */
215
+ toJSON(): Promise<{
216
+ replyId: string;
217
+ confirmedToolCallIds: string[];
218
+ curIter: number;
219
+ }>;
220
+ /**
221
+ * Split the current context into two parts: one part that needs to be compressed and another part that should be reserved based on the compression configuration. The method calculates how many recent "units" (blocks or tool call pairs) to keep uncompressed according to the `keepRecent` setting in the compression configuration, and ensures that tool calls and their corresponding results are not separated during the split.
222
+ * @returns An object containing the `toCompressedContext` which includes the messages that need to be compressed, and the `reservedContext` which includes the recent messages that should be kept uncompressed.
223
+ */
224
+ protected _splitContextForCompression(): {
225
+ toCompressedContext: Msg[];
226
+ reservedContext: Msg[];
227
+ };
228
+ /**
229
+ * Compress the agent's memory using the specified compression model (if provided) or the original model.
230
+ */
231
+ protected compressMemoryIfNeeded(): Promise<void>;
232
+ }
233
+
234
+ export { type ActingOptions, Agent, type AgentOptions, type CompressionConfig, type ReasoningOptions, type ReplyOptions };