@google/adk 1.0.0 → 1.2.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 (166) hide show
  1. package/dist/cjs/agents/functions.js +4 -0
  2. package/dist/cjs/auth/oauth2/oauth2_discovery.js +26 -2
  3. package/dist/cjs/code_executors/agent_engine_sandbox_code_executor.js +305 -0
  4. package/dist/cjs/code_executors/code_execution_utils.js +1 -1
  5. package/dist/cjs/common.js +19 -0
  6. package/dist/cjs/events/event.js +3 -1
  7. package/dist/cjs/index.js +97 -125
  8. package/dist/cjs/integrations/agent_registry/agent_registry.js +362 -0
  9. package/dist/cjs/integrations/agent_registry/agent_registry_mcp_toolset.js +103 -0
  10. package/dist/cjs/integrations/agent_registry/helpers.js +57 -0
  11. package/dist/cjs/integrations/agent_registry/types.js +50 -0
  12. package/dist/cjs/memory/vertex_ai_memory_bank_service.js +496 -0
  13. package/dist/cjs/runner/in_memory_runner.js +10 -5
  14. package/dist/cjs/runner/runner.js +32 -2
  15. package/dist/cjs/sessions/database_session_service.js +49 -3
  16. package/dist/cjs/sessions/in_memory_session_service.js +70 -14
  17. package/dist/cjs/sessions/registry.js +4 -0
  18. package/dist/cjs/sessions/vertex_ai_session_service.js +428 -0
  19. package/dist/cjs/tools/agent_tool.js +11 -6
  20. package/dist/cjs/tools/exit_loop_tool.js +9 -0
  21. package/dist/cjs/tools/function_tool.js +7 -2
  22. package/dist/cjs/tools/google_maps_grounding_tool.js +80 -0
  23. package/dist/cjs/tools/long_running_tool.js +2 -1
  24. package/dist/cjs/tools/mcp/mcp_session_manager.js +11 -0
  25. package/dist/cjs/tools/mcp/mcp_tool.js +12 -7
  26. package/dist/cjs/tools/mcp/mcp_toolset.js +27 -4
  27. package/dist/cjs/tools/openapi_tool/auth/auth_helpers.js +78 -0
  28. package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +84 -0
  29. package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +133 -0
  30. package/dist/cjs/tools/skill/load_skill_resource_tool.js +2 -25
  31. package/dist/cjs/tools/url_context_tool.js +73 -0
  32. package/dist/cjs/tools/vertex_ai_search_tool.js +127 -0
  33. package/dist/cjs/tools/vertex_rag_retrieval_tool.js +64 -0
  34. package/dist/cjs/utils/file_utils.js +28 -0
  35. package/dist/cjs/utils/gemini_schema_util.js +18 -0
  36. package/dist/cjs/utils/model_name.js +8 -2
  37. package/dist/cjs/utils/partial_copy.js +51 -0
  38. package/dist/cjs/utils/streaming_utils.js +167 -121
  39. package/dist/cjs/utils/vertex_ai_utils.js +50 -0
  40. package/dist/cjs/version.js +1 -1
  41. package/dist/esm/agents/functions.js +4 -0
  42. package/dist/esm/auth/oauth2/oauth2_discovery.js +26 -2
  43. package/dist/esm/code_executors/agent_engine_sandbox_code_executor.js +281 -0
  44. package/dist/esm/code_executors/code_execution_utils.js +1 -1
  45. package/dist/esm/common.js +15 -0
  46. package/dist/esm/events/event.js +3 -1
  47. package/dist/esm/index.js +54 -130
  48. package/dist/esm/integrations/agent_registry/agent_registry.js +333 -0
  49. package/dist/esm/integrations/agent_registry/agent_registry_mcp_toolset.js +77 -0
  50. package/dist/esm/integrations/agent_registry/helpers.js +28 -0
  51. package/dist/esm/integrations/agent_registry/types.js +20 -0
  52. package/dist/esm/memory/vertex_ai_memory_bank_service.js +468 -0
  53. package/dist/esm/runner/in_memory_runner.js +10 -5
  54. package/dist/esm/runner/runner.js +32 -2
  55. package/dist/esm/sessions/database_session_service.js +49 -3
  56. package/dist/esm/sessions/in_memory_session_service.js +70 -14
  57. package/dist/esm/sessions/registry.js +7 -0
  58. package/dist/esm/sessions/vertex_ai_session_service.js +403 -0
  59. package/dist/esm/tools/agent_tool.js +11 -6
  60. package/dist/esm/tools/exit_loop_tool.js +9 -0
  61. package/dist/esm/tools/function_tool.js +7 -2
  62. package/dist/esm/tools/google_maps_grounding_tool.js +54 -0
  63. package/dist/esm/tools/long_running_tool.js +2 -1
  64. package/dist/esm/tools/mcp/mcp_session_manager.js +11 -0
  65. package/dist/esm/tools/mcp/mcp_tool.js +12 -7
  66. package/dist/esm/tools/mcp/mcp_toolset.js +27 -4
  67. package/dist/esm/tools/openapi_tool/auth/auth_helpers.js +48 -0
  68. package/dist/esm/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +60 -0
  69. package/dist/esm/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +111 -0
  70. package/dist/esm/tools/skill/load_skill_resource_tool.js +1 -24
  71. package/dist/esm/tools/url_context_tool.js +44 -0
  72. package/dist/esm/tools/vertex_ai_search_tool.js +103 -0
  73. package/dist/esm/tools/vertex_rag_retrieval_tool.js +36 -0
  74. package/dist/esm/utils/file_utils.js +26 -0
  75. package/dist/esm/utils/gemini_schema_util.js +18 -0
  76. package/dist/esm/utils/model_name.js +6 -1
  77. package/dist/esm/utils/partial_copy.js +23 -0
  78. package/dist/esm/utils/streaming_utils.js +165 -120
  79. package/dist/esm/utils/vertex_ai_utils.js +22 -0
  80. package/dist/esm/version.js +1 -1
  81. package/dist/types/a2a/a2a_remote_agent.d.ts +14 -0
  82. package/dist/types/agents/processors/base_llm_processor.d.ts +12 -4
  83. package/dist/types/agents/processors/basic_llm_request_processor.d.ts +5 -0
  84. package/dist/types/agents/processors/identity_llm_request_processor.d.ts +4 -0
  85. package/dist/types/agents/processors/request_confirmation_llm_request_processor.d.ts +5 -0
  86. package/dist/types/agents/run_config.d.ts +15 -0
  87. package/dist/types/code_executors/agent_engine_sandbox_code_executor.d.ts +51 -0
  88. package/dist/types/common.d.ts +7 -0
  89. package/dist/types/events/event_actions.d.ts +24 -6
  90. package/dist/types/events/structured_events.d.ts +13 -0
  91. package/dist/types/examples/example_util.d.ts +25 -0
  92. package/dist/types/index.d.ts +6 -0
  93. package/dist/types/integrations/agent_registry/agent_registry.d.ts +94 -0
  94. package/dist/types/integrations/agent_registry/agent_registry_mcp_toolset.d.ts +43 -0
  95. package/dist/types/integrations/agent_registry/helpers.d.ts +7 -0
  96. package/dist/types/integrations/agent_registry/types.d.ts +101 -0
  97. package/dist/types/memory/vertex_ai_memory_bank_service.d.ts +52 -0
  98. package/dist/types/runner/in_memory_runner.d.ts +28 -1
  99. package/dist/types/runner/runner.d.ts +47 -0
  100. package/dist/types/sessions/base_session_service.d.ts +18 -0
  101. package/dist/types/sessions/database_session_service.d.ts +1 -1
  102. package/dist/types/sessions/in_memory_session_service.d.ts +1 -1
  103. package/dist/types/sessions/vertex_ai_session_service.d.ts +37 -0
  104. package/dist/types/tools/exit_loop_tool.d.ts +9 -0
  105. package/dist/types/tools/function_tool.d.ts +22 -2
  106. package/dist/types/tools/google_maps_grounding_tool.d.ts +22 -0
  107. package/dist/types/tools/long_running_tool.d.ts +11 -1
  108. package/dist/types/tools/mcp/mcp_session_manager.d.ts +3 -0
  109. package/dist/types/tools/mcp/mcp_tool.d.ts +7 -1
  110. package/dist/types/tools/mcp/mcp_toolset.d.ts +7 -1
  111. package/dist/types/tools/openapi_tool/auth/auth_helpers.d.ts +25 -0
  112. package/dist/types/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.d.ts +20 -0
  113. package/dist/types/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.d.ts +20 -0
  114. package/dist/types/tools/url_context_tool.d.ts +17 -0
  115. package/dist/types/tools/vertex_ai_search_tool.d.ts +55 -0
  116. package/dist/types/tools/vertex_rag_retrieval_tool.d.ts +42 -0
  117. package/dist/types/utils/file_utils.d.ts +2 -0
  118. package/dist/types/utils/model_name.d.ts +4 -0
  119. package/dist/types/utils/partial_copy.d.ts +13 -0
  120. package/dist/types/utils/streaming_utils.d.ts +8 -17
  121. package/dist/types/utils/vertex_ai_utils.d.ts +14 -0
  122. package/dist/types/version.d.ts +1 -1
  123. package/dist/web/agents/functions.js +4 -0
  124. package/dist/web/auth/oauth2/oauth2_discovery.js +26 -2
  125. package/dist/web/code_executors/agent_engine_sandbox_code_executor.js +281 -0
  126. package/dist/web/code_executors/code_execution_utils.js +1 -1
  127. package/dist/web/common.js +15 -0
  128. package/dist/web/events/event.js +3 -1
  129. package/dist/web/index.js +54 -12
  130. package/dist/web/integrations/agent_registry/agent_registry.js +333 -0
  131. package/dist/web/integrations/agent_registry/agent_registry_mcp_toolset.js +90 -0
  132. package/dist/web/integrations/agent_registry/helpers.js +28 -0
  133. package/dist/web/integrations/agent_registry/types.js +20 -0
  134. package/dist/web/memory/vertex_ai_memory_bank_service.js +475 -0
  135. package/dist/web/runner/in_memory_runner.js +10 -5
  136. package/dist/web/runner/runner.js +32 -2
  137. package/dist/web/sessions/database_session_service.js +49 -3
  138. package/dist/web/sessions/in_memory_session_service.js +70 -14
  139. package/dist/web/sessions/registry.js +7 -0
  140. package/dist/web/sessions/vertex_ai_session_service.js +414 -0
  141. package/dist/web/tools/agent_tool.js +11 -6
  142. package/dist/web/tools/exit_loop_tool.js +9 -0
  143. package/dist/web/tools/function_tool.js +7 -2
  144. package/dist/web/tools/google_maps_grounding_tool.js +54 -0
  145. package/dist/web/tools/long_running_tool.js +2 -1
  146. package/dist/web/tools/mcp/mcp_session_manager.js +11 -0
  147. package/dist/web/tools/mcp/mcp_tool.js +12 -7
  148. package/dist/web/tools/mcp/mcp_toolset.js +27 -4
  149. package/dist/web/tools/openapi_tool/auth/auth_helpers.js +48 -0
  150. package/dist/web/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +60 -0
  151. package/dist/web/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +111 -0
  152. package/dist/web/tools/skill/load_skill_resource_tool.js +1 -24
  153. package/dist/web/tools/url_context_tool.js +44 -0
  154. package/dist/web/tools/vertex_ai_search_tool.js +103 -0
  155. package/dist/web/tools/vertex_rag_retrieval_tool.js +36 -0
  156. package/dist/web/utils/file_utils.js +26 -0
  157. package/dist/web/utils/gemini_schema_util.js +18 -0
  158. package/dist/web/utils/model_name.js +6 -1
  159. package/dist/web/utils/partial_copy.js +23 -0
  160. package/dist/web/utils/streaming_utils.js +219 -121
  161. package/dist/web/utils/vertex_ai_utils.js +22 -0
  162. package/dist/web/version.js +1 -1
  163. package/package.json +3 -2
  164. package/dist/cjs/index.js.map +0 -7
  165. package/dist/esm/index.js.map +0 -7
  166. package/dist/web/index.js.map +0 -7
@@ -12,15 +12,8 @@ import { JSONPath } from "jsonpath-plus";
12
12
  import { generateClientFunctionCallId } from "../agents/functions.js";
13
13
  import { FeatureName, isFeatureEnabled } from "../features/feature_registry.js";
14
14
  import { createLlmResponse } from "../models/llm_response.js";
15
- class StreamingResponseAggregator {
16
- constructor(isProgressiveMode = isFeatureEnabled(
17
- FeatureName.PROGRESSIVE_SSE_STREAMING
18
- )) {
19
- this.isProgressiveMode = isProgressiveMode;
20
- // For non-progressive SSE streaming mode
21
- this.text = "";
22
- this.thoughtText = "";
23
- // For progressive SSE streaming mode: accumulate parts in order
15
+ class ProgressiveStrategy {
16
+ constructor() {
24
17
  this.partsSequence = [];
25
18
  this.currentTextBuffer = "";
26
19
  this.currentFcArgs = {};
@@ -147,11 +140,6 @@ class StreamingResponseAggregator {
147
140
  if (!fc) {
148
141
  return;
149
142
  }
150
- if (part.thoughtSignature) {
151
- this.lastThoughtSignature = part.thoughtSignature;
152
- } else if (this.lastThoughtSignature) {
153
- part.thoughtSignature = this.lastThoughtSignature.toString();
154
- }
155
143
  if (fc.partialArgs || fc.willContinue) {
156
144
  if (!fc.id && !this.currentFcId) {
157
145
  fc.id = generateClientFunctionCallId();
@@ -170,63 +158,103 @@ class StreamingResponseAggregator {
170
158
  }
171
159
  }
172
160
  }
173
- async *processResponse(response) {
174
- var _a, _b, _c;
175
- this.response = response;
176
- const llmResponse = createLlmResponse(response);
177
- this.usageMetadata = llmResponse.usageMetadata;
178
- if (llmResponse.groundingMetadata) {
179
- this.groundingMetadata = llmResponse.groundingMetadata;
180
- }
181
- if (llmResponse.citationMetadata) {
182
- this.citationMetadata = llmResponse.citationMetadata;
183
- }
184
- if (llmResponse.finishReason) {
185
- this.finishReason = llmResponse.finishReason;
186
- }
161
+ async *processResponse(llmResponse) {
162
+ var _a;
187
163
  if (llmResponse.content && llmResponse.content.parts) {
188
164
  for (const part of llmResponse.content.parts) {
189
- if (part.thoughtSignature) {
190
- this.lastThoughtSignature = part.thoughtSignature;
191
- } else if (part.functionCall && this.lastThoughtSignature) {
192
- part.thoughtSignature = this.lastThoughtSignature.toString();
165
+ if (part.text) {
166
+ const isThought = (_a = part.thought) != null ? _a : false;
167
+ if (this.currentTextBuffer && isThought !== this.currentTextIsThought) {
168
+ this.flushTextBufferToSequence();
169
+ }
170
+ if (!this.currentTextBuffer) {
171
+ this.currentTextIsThought = isThought;
172
+ }
173
+ this.currentTextBuffer += part.text;
174
+ } else if (part.functionCall) {
175
+ this.processFunctionCallPart(part);
176
+ } else {
177
+ this.flushTextBufferToSequence();
178
+ this.partsSequence.push(part);
193
179
  }
194
180
  }
195
181
  }
196
- if (this.isProgressiveMode) {
197
- if (llmResponse.content && llmResponse.content.parts) {
198
- for (const part of llmResponse.content.parts) {
199
- if (part.text) {
200
- const isThought = (_a = part.thought) != null ? _a : false;
201
- if (this.currentTextBuffer && isThought !== this.currentTextIsThought) {
202
- this.flushTextBufferToSequence();
203
- }
204
- if (!this.currentTextBuffer) {
205
- this.currentTextIsThought = isThought;
206
- }
207
- this.currentTextBuffer += part.text;
208
- } else if (part.functionCall) {
209
- this.processFunctionCallPart(part);
182
+ llmResponse.partial = true;
183
+ yield llmResponse;
184
+ }
185
+ close() {
186
+ this.flushTextBufferToSequence();
187
+ this.flushFunctionCallToSequence();
188
+ const finalParts = this.partsSequence;
189
+ if (finalParts.length === 0) {
190
+ return void 0;
191
+ }
192
+ return finalParts;
193
+ }
194
+ }
195
+ class NonProgressiveStrategy {
196
+ constructor() {
197
+ this.text = "";
198
+ this.thoughtText = "";
199
+ }
200
+ async *processResponse(llmResponse) {
201
+ var _a;
202
+ if ((_a = llmResponse.content) == null ? void 0 : _a.parts) {
203
+ const nonTextParts = [];
204
+ let sawTextPart = false;
205
+ for (const part of llmResponse.content.parts) {
206
+ if (typeof part.text === "string") {
207
+ sawTextPart = true;
208
+ if (part.thought) {
209
+ this.thoughtText += part.text;
210
210
  } else {
211
- this.flushTextBufferToSequence();
212
- this.partsSequence.push(part);
211
+ this.text += part.text;
213
212
  }
213
+ continue;
214
+ }
215
+ if (part.functionCall && !part.functionCall.id) {
216
+ part.functionCall.id = generateClientFunctionCallId();
214
217
  }
218
+ nonTextParts.push(part);
215
219
  }
216
- llmResponse.partial = true;
217
- yield llmResponse;
218
- return;
219
- }
220
- if (llmResponse.content && llmResponse.content.parts && typeof ((_b = llmResponse.content.parts[0]) == null ? void 0 : _b.text) === "string") {
221
- const part0 = llmResponse.content.parts[0];
222
- const partText = part0.text || "";
223
- if (part0.thought) {
224
- this.thoughtText += partText;
225
- } else {
226
- this.text += partText;
220
+ if (nonTextParts.length > 0) {
221
+ if (this.thoughtText || this.text) {
222
+ const parts = [];
223
+ if (this.thoughtText) {
224
+ parts.push({ text: this.thoughtText, thought: true });
225
+ }
226
+ if (this.text) {
227
+ parts.push({ text: this.text });
228
+ }
229
+ yield {
230
+ content: {
231
+ role: "model",
232
+ parts
233
+ },
234
+ usageMetadata: llmResponse.usageMetadata,
235
+ partial: false
236
+ };
237
+ this.thoughtText = "";
238
+ this.text = "";
239
+ }
240
+ yield {
241
+ ...llmResponse,
242
+ content: {
243
+ role: llmResponse.content.role,
244
+ parts: nonTextParts
245
+ },
246
+ partial: false
247
+ };
248
+ return;
249
+ }
250
+ if (sawTextPart) {
251
+ llmResponse.partial = true;
227
252
  }
228
- llmResponse.partial = true;
229
- } else if ((this.thoughtText || this.text) && (!llmResponse.content || !llmResponse.content.parts || !((_c = llmResponse.content.parts[0]) == null ? void 0 : _c.inlineData))) {
253
+ }
254
+ yield llmResponse;
255
+ }
256
+ close() {
257
+ if (this.text || this.thoughtText) {
230
258
  const parts = [];
231
259
  if (this.thoughtText) {
232
260
  parts.push({ text: this.thoughtText, thought: true });
@@ -234,74 +262,91 @@ class StreamingResponseAggregator {
234
262
  if (this.text) {
235
263
  parts.push({ text: this.text });
236
264
  }
237
- yield {
238
- content: {
239
- role: "model",
240
- parts
241
- },
242
- usageMetadata: llmResponse.usageMetadata,
243
- partial: false
244
- };
245
- this.thoughtText = "";
246
- this.text = "";
265
+ return parts;
247
266
  }
248
- yield llmResponse;
267
+ return void 0;
249
268
  }
250
- close() {
269
+ }
270
+ class StreamingResponseAggregator {
271
+ constructor(isProgressiveMode = isFeatureEnabled(
272
+ FeatureName.PROGRESSIVE_SSE_STREAMING
273
+ )) {
274
+ this.isProgressiveMode = isProgressiveMode;
275
+ this.lastThoughtSignature = {};
276
+ this.sawFunctionCall = false;
277
+ this.strategy = this.isProgressiveMode ? new ProgressiveStrategy() : new NonProgressiveStrategy();
278
+ }
279
+ async *processResponse(response) {
251
280
  var _a, _b;
252
- if (!((_a = this.response) == null ? void 0 : _a.candidates) || this.response.candidates.length === 0) {
253
- return;
281
+ const llmResponse = createLlmResponse(response);
282
+ const parts = (_b = (_a = llmResponse.content) == null ? void 0 : _a.parts) != null ? _b : [];
283
+ if (parts.some((part) => part.functionCall)) {
284
+ this.sawFunctionCall = true;
254
285
  }
255
- if (this.isProgressiveMode) {
256
- this.flushTextBufferToSequence();
257
- this.flushFunctionCallToSequence();
258
- const finalParts = this.partsSequence;
259
- if (finalParts.length === 0) {
260
- return;
286
+ if (this.sawFunctionCall && llmResponse.finishReason === FinishReason.STOP && parts.length > 0 && parts.every(isEmptyContentPart)) {
287
+ if (llmResponse.usageMetadata) {
288
+ this.usageMetadata = llmResponse.usageMetadata;
261
289
  }
262
- const candidate = this.response.candidates[0];
263
- const finishReason = (_b = this.finishReason) != null ? _b : candidate.finishReason;
264
- return {
265
- content: {
266
- role: "model",
267
- parts: finalParts
268
- },
269
- groundingMetadata: this.groundingMetadata,
270
- citationMetadata: this.citationMetadata,
271
- errorCode: finishReason === FinishReason.STOP ? void 0 : finishReason,
272
- errorMessage: finishReason === FinishReason.STOP ? void 0 : candidate.finishMessage,
273
- usageMetadata: this.usageMetadata,
274
- finishReason,
275
- partial: false
276
- };
277
- }
278
- if ((this.text || this.thoughtText) && this.response.candidates && this.response.candidates.length > 0) {
279
- const parts = [];
280
- if (this.thoughtText) {
281
- parts.push({ text: this.thoughtText, thought: true });
290
+ if (llmResponse.groundingMetadata) {
291
+ this.groundingMetadata = llmResponse.groundingMetadata;
282
292
  }
283
- if (this.text) {
284
- parts.push({ text: this.text });
293
+ if (llmResponse.citationMetadata) {
294
+ this.citationMetadata = llmResponse.citationMetadata;
285
295
  }
286
- const candidate = this.response.candidates[0];
287
- const finishReason = candidate.finishReason;
288
- return {
289
- content: {
290
- role: "model",
291
- parts
292
- },
293
- groundingMetadata: this.groundingMetadata,
294
- citationMetadata: this.citationMetadata,
295
- errorCode: finishReason === FinishReason.STOP ? void 0 : finishReason,
296
- errorMessage: finishReason === FinishReason.STOP ? void 0 : candidate.finishMessage,
297
- usageMetadata: this.usageMetadata,
298
- finishReason,
299
- partial: false
300
- };
296
+ if (llmResponse.finishReason) {
297
+ this.finishReason = llmResponse.finishReason;
298
+ }
299
+ return;
301
300
  }
302
- return void 0;
301
+ this.response = response;
302
+ this.usageMetadata = llmResponse.usageMetadata;
303
+ if (llmResponse.groundingMetadata) {
304
+ this.groundingMetadata = llmResponse.groundingMetadata;
305
+ }
306
+ if (llmResponse.citationMetadata) {
307
+ this.citationMetadata = llmResponse.citationMetadata;
308
+ }
309
+ if (llmResponse.finishReason) {
310
+ this.finishReason = llmResponse.finishReason;
311
+ }
312
+ if (llmResponse.content && llmResponse.content.parts) {
313
+ for (const part of llmResponse.content.parts) {
314
+ if (part.thoughtSignature) {
315
+ this.lastThoughtSignature.value = part.thoughtSignature;
316
+ } else if (part.functionCall && this.lastThoughtSignature.value) {
317
+ part.thoughtSignature = this.lastThoughtSignature.value.toString();
318
+ }
319
+ }
320
+ }
321
+ yield* this.strategy.processResponse(llmResponse);
322
+ }
323
+ close() {
324
+ var _a, _b, _c;
325
+ const finalParts = this.strategy.close();
326
+ if (!finalParts) {
327
+ return void 0;
328
+ }
329
+ const candidate = (_b = (_a = this.response) == null ? void 0 : _a.candidates) == null ? void 0 : _b[0];
330
+ const finishReason = (_c = this.finishReason) != null ? _c : candidate == null ? void 0 : candidate.finishReason;
331
+ return {
332
+ content: {
333
+ role: "model",
334
+ parts: finalParts
335
+ },
336
+ groundingMetadata: this.groundingMetadata,
337
+ citationMetadata: this.citationMetadata,
338
+ errorCode: finishReason === FinishReason.STOP ? void 0 : finishReason,
339
+ errorMessage: finishReason === FinishReason.STOP ? void 0 : candidate == null ? void 0 : candidate.finishMessage,
340
+ usageMetadata: this.usageMetadata,
341
+ finishReason,
342
+ partial: false
343
+ };
303
344
  }
304
345
  }
346
+ function isEmptyContentPart(part) {
347
+ return !part.functionCall && !part.functionResponse && !part.fileData && !part.inlineData && !part.executableCode && !part.codeExecutionResult && (!part.text || part.text === "");
348
+ }
305
349
  export {
306
- StreamingResponseAggregator
350
+ StreamingResponseAggregator,
351
+ isEmptyContentPart
307
352
  };
@@ -0,0 +1,22 @@
1
+ import {createRequire as topLevelCreateRequire} from 'module';
2
+ const require = topLevelCreateRequire(import.meta.url);
3
+ /**
4
+ * @license
5
+ * Copyright 2026 Google LLC
6
+ * SPDX-License-Identifier: Apache-2.0
7
+ */
8
+ import { getBooleanEnvVar } from "./env_aware_utils.js";
9
+ function getExpressModeApiKey(project, location, expressModeApiKey) {
10
+ if ((project || location) && expressModeApiKey) {
11
+ throw new Error(
12
+ "Cannot specify project or location and expressModeApiKey. Either use project and location, or just the expressModeApiKey."
13
+ );
14
+ }
15
+ if (getBooleanEnvVar("GOOGLE_GENAI_USE_VERTEXAI")) {
16
+ return expressModeApiKey || process.env.GOOGLE_API_KEY;
17
+ }
18
+ return void 0;
19
+ }
20
+ export {
21
+ getExpressModeApiKey
22
+ };
@@ -5,7 +5,7 @@ const require = topLevelCreateRequire(import.meta.url);
5
5
  * Copyright 2025 Google LLC
6
6
  * SPDX-License-Identifier: Apache-2.0
7
7
  */
8
- const version = "1.0.0";
8
+ const version = "1.2.0";
9
9
  export {
10
10
  version
11
11
  };
@@ -16,11 +16,25 @@ export type A2AStreamEventData = Message | Task | TaskStatusUpdateEvent | TaskAr
16
16
  /**
17
17
  * Callback called before sending a request to the remote agent.
18
18
  * Allows modifying the request parameters.
19
+ *
20
+ * @param ctx - The current invocation context, providing access to session
21
+ * state, agent metadata, and services.
22
+ * @param params - The A2A message send parameters that will be sent to the
23
+ * remote agent. Mutations to this object are reflected in the outgoing
24
+ * request.
25
+ * @returns A Promise or void. Returning a rejected Promise aborts the request.
19
26
  */
20
27
  export type BeforeA2ARequestCallback = (ctx: InvocationContext, params: MessageSendParams) => Promise<void> | void;
21
28
  /**
22
29
  * Callback called after receiving a response from the remote agent.
23
30
  * Allows inspecting or modifying the response.
31
+ *
32
+ * @param ctx - The current invocation context, providing access to session
33
+ * state, agent metadata, and services.
34
+ * @param resp - The raw A2A stream event data received from the remote agent,
35
+ * before conversion to an ADK event.
36
+ * @returns A Promise or void. Returning a rejected Promise stops further
37
+ * processing of the response.
24
38
  */
25
39
  export type AfterA2ARequestCallback = (ctx: InvocationContext, resp: A2AStreamEventData) => Promise<void> | void;
26
40
  /**
@@ -8,20 +8,28 @@ import { LlmRequest } from '../../models/llm_request.js';
8
8
  import { LlmResponse } from '../../models/llm_response.js';
9
9
  import { InvocationContext } from '../invocation_context.js';
10
10
  /**
11
- * Base class for LLM request processor.
11
+ * Base class for LLM request processors. Implementations mutate or augment
12
+ * the {@link LlmRequest} before it is sent to the model.
12
13
  */
13
14
  export declare abstract class BaseLlmRequestProcessor {
14
15
  /**
15
- * Runs the processor.
16
+ * Runs the processor, optionally yielding intermediate {@link Event}s.
17
+ *
18
+ * @param invocationContext - The current invocation context.
19
+ * @param llmRequest - The request object to populate or mutate in place.
16
20
  */
17
21
  abstract runAsync(invocationContext: InvocationContext, llmRequest: LlmRequest): AsyncGenerator<Event, void, void>;
18
22
  }
19
23
  /**
20
- * Base class for LLM response processor.
24
+ * Base class for LLM response processors. Implementations inspect or
25
+ * transform the {@link LlmResponse} after it is received from the model.
21
26
  */
22
27
  export declare abstract class BaseLlmResponseProcessor {
23
28
  /**
24
- * Processes the LLM response.
29
+ * Runs the processor, optionally yielding intermediate {@link Event}s.
30
+ *
31
+ * @param invocationContext - The current invocation context.
32
+ * @param llmResponse - The response received from the model.
25
33
  */
26
34
  abstract runAsync(invocationContext: InvocationContext, llmResponse: LlmResponse): AsyncGenerator<Event, void, void>;
27
35
  }
@@ -7,6 +7,11 @@ import { Event } from '../../events/event.js';
7
7
  import { LlmRequest } from '../../models/llm_request.js';
8
8
  import { InvocationContext } from '../invocation_context.js';
9
9
  import { BaseLlmRequestProcessor } from './base_llm_processor.js';
10
+ /**
11
+ * Populates the {@link LlmRequest} with model configuration derived from the
12
+ * agent, including the model name, generation config, output schema, and live
13
+ * connect settings.
14
+ */
10
15
  export declare class BasicLlmRequestProcessor extends BaseLlmRequestProcessor {
11
16
  runAsync(invocationContext: InvocationContext, llmRequest: LlmRequest): AsyncGenerator<Event, void, void>;
12
17
  }
@@ -7,6 +7,10 @@ import { Event } from '../../events/event.js';
7
7
  import { LlmRequest } from '../../models/llm_request.js';
8
8
  import { InvocationContext } from '../invocation_context.js';
9
9
  import { BaseLlmRequestProcessor } from './base_llm_processor.js';
10
+ /**
11
+ * Appends identity instructions to the {@link LlmRequest} system prompt,
12
+ * informing the model of the agent's name and description.
13
+ */
10
14
  export declare class IdentityLlmRequestProcessor extends BaseLlmRequestProcessor {
11
15
  runAsync(invocationContext: InvocationContext, llmRequest: LlmRequest): AsyncGenerator<Event, void, undefined>;
12
16
  }
@@ -6,6 +6,11 @@
6
6
  import { Event } from '../../events/event.js';
7
7
  import { InvocationContext } from '../invocation_context.js';
8
8
  import { BaseLlmRequestProcessor } from './base_llm_processor.js';
9
+ /**
10
+ * Resumes tool calls that were paused for user confirmation. Scans the session
11
+ * event history for pending confirmation responses and re-invokes the
12
+ * corresponding tools before the next LLM turn.
13
+ */
9
14
  export declare class RequestConfirmationLlmRequestProcessor extends BaseLlmRequestProcessor {
10
15
  /** Handles tool confirmation information to build the LLM request. */
11
16
  runAsync(invocationContext: InvocationContext): AsyncGenerator<Event, void, void>;
@@ -78,6 +78,21 @@ export interface RunConfig {
78
78
  */
79
79
  pauseOnToolCalls?: boolean;
80
80
  }
81
+ /**
82
+ * Creates a {@link RunConfig} with production-safe defaults.
83
+ *
84
+ * Default values applied when the corresponding field is absent from `params`:
85
+ * - `saveInputBlobsAsArtifacts` → `false`
86
+ * - `supportCfc` → `false`
87
+ * - `enableAffectiveDialog` → `false`
88
+ * - `streamingMode` → {@link StreamingMode.NONE}
89
+ * - `maxLlmCalls` → `500` (validated via `validateMaxLlmCalls`)
90
+ * - `pauseOnToolCalls` → `false`
91
+ *
92
+ * @param params - Optional partial {@link RunConfig} overriding defaults.
93
+ * @returns A merged {@link RunConfig} object.
94
+ * @throws {Error} When `params.maxLlmCalls` exceeds `Number.MAX_SAFE_INTEGER`.
95
+ */
81
96
  export declare function createRunConfig(params?: Partial<RunConfig>): {
82
97
  speechConfig?: SpeechConfig | undefined;
83
98
  responseModalities?: Modality[] | undefined;
@@ -0,0 +1,51 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { Client } from '@google-cloud/vertexai';
7
+ import { BaseCodeExecutor, ExecuteCodeParams } from './base_code_executor.js';
8
+ import { CodeExecutionResult } from './code_execution_utils.js';
9
+ /**
10
+ * Options for AgentEngineSandboxCodeExecutor.
11
+ */
12
+ export interface AgentEngineSandboxCodeExecutorOptions {
13
+ /**
14
+ * If set, load the existing resource name of the code execution sandbox.
15
+ * Format: projects/123/locations/us-central1/reasoningEngines/456/sandboxEnvironments/789
16
+ */
17
+ sandboxResourceName?: string;
18
+ /**
19
+ * The resource name of the agent engine to use to create the code execution sandbox.
20
+ * Format: projects/123/locations/us-central1/reasoningEngines/456
21
+ */
22
+ agentEngineResourceName?: string;
23
+ /**
24
+ * Project ID to use. If not provided, read from GOOGLE_CLOUD_PROJECT env var.
25
+ */
26
+ projectId?: string;
27
+ /**
28
+ * Location to use. If not provided, read from GOOGLE_CLOUD_LOCATION env var or default to 'us-central1'.
29
+ */
30
+ location?: string;
31
+ /**
32
+ * Optional client instance to use. If not provided, a new one will be created.
33
+ * Primarily for testing.
34
+ */
35
+ client?: Client;
36
+ }
37
+ /**
38
+ * A code executor that uses Agent Engine Code Execution Sandbox to execute code.
39
+ */
40
+ export declare class AgentEngineSandboxCodeExecutor extends BaseCodeExecutor {
41
+ sandboxResourceName?: string;
42
+ agentEngineResourceName?: string;
43
+ private projectId?;
44
+ private location?;
45
+ private client;
46
+ private agentEngineCreationPromise?;
47
+ constructor(options?: AgentEngineSandboxCodeExecutorOptions);
48
+ executeCode(params: ExecuteCodeParams): Promise<CodeExecutionResult>;
49
+ private getOrCreateAgentEngine;
50
+ private getOrCreateSandbox;
51
+ }
@@ -73,6 +73,8 @@ export type { Example } from './examples/example.js';
73
73
  export type { BaseMemoryService, SearchMemoryRequest, SearchMemoryResponse, } from './memory/base_memory_service.js';
74
74
  export { InMemoryMemoryService } from './memory/in_memory_memory_service.js';
75
75
  export type { MemoryEntry } from './memory/memory_entry.js';
76
+ export { VertexAiMemoryBankService } from './memory/vertex_ai_memory_bank_service.js';
77
+ export type { VertexAiMemoryBankServiceOptions } from './memory/vertex_ai_memory_bank_service.js';
76
78
  export { ApigeeLlm } from './models/apigee_llm.js';
77
79
  export type { ApigeeLlmParams } from './models/apigee_llm.js';
78
80
  export { BaseLlm, isBaseLlm } from './models/base_llm.js';
@@ -108,12 +110,17 @@ export type { ToolPredicate } from './tools/base_toolset.js';
108
110
  export { EXIT_LOOP, ExitLoopTool } from './tools/exit_loop_tool.js';
109
111
  export { FunctionTool, isFunctionTool } from './tools/function_tool.js';
110
112
  export type { ToolExecuteArgument, ToolExecuteFunction, ToolInputParameters, ToolOptions, } from './tools/function_tool.js';
113
+ export { GOOGLE_MAPS_GROUNDING, GoogleMapsGroundingTool, } from './tools/google_maps_grounding_tool.js';
111
114
  export { GOOGLE_SEARCH, GoogleSearchTool } from './tools/google_search_tool.js';
112
115
  export { LOAD_ARTIFACTS, LoadArtifactsTool, } from './tools/load_artifacts_tool.js';
113
116
  export { LOAD_MEMORY, LoadMemoryTool } from './tools/load_memory_tool.js';
114
117
  export { LongRunningFunctionTool } from './tools/long_running_tool.js';
115
118
  export { PRELOAD_MEMORY, PreloadMemoryTool, } from './tools/preload_memory_tool.js';
116
119
  export { ToolConfirmation } from './tools/tool_confirmation.js';
120
+ export { URL_CONTEXT, UrlContextTool } from './tools/url_context_tool.js';
121
+ export { VertexAiSearchTool } from './tools/vertex_ai_search_tool.js';
122
+ export type { DataStoreParams, SearchEngineParams, VertexAISearchConfig, VertexAISearchDataStoreSpec, VertexAiSearchToolParams, } from './tools/vertex_ai_search_tool.js';
123
+ export { VertexRagRetrievalTool } from './tools/vertex_rag_retrieval_tool.js';
117
124
  export { LogLevel, getLogger, setLogLevel, setLogger } from './utils/logger.js';
118
125
  export type { Logger } from './utils/logger.js';
119
126
  export { isGemini2OrAbove } from './utils/model_name.js';
@@ -58,17 +58,35 @@ export interface EventActions {
58
58
  };
59
59
  }
60
60
  /**
61
- * Creates an EventActions object.
61
+ * Creates an {@link EventActions} object with default empty-dict values for
62
+ * all dictionary fields.
63
+ *
64
+ * @param state - Optional partial {@link EventActions} whose properties
65
+ * override the defaults. Dictionary fields (`stateDelta`, `artifactDelta`,
66
+ * `requestedAuthConfigs`, `requestedToolConfirmations`) default to `{}`;
67
+ * scalar fields (`skipSummarization`, `transferToAgent`, `escalate`) default
68
+ * to `undefined`.
69
+ * @returns A fully populated {@link EventActions} object.
62
70
  */
63
71
  export declare function createEventActions(state?: Partial<EventActions>): EventActions;
64
72
  /**
65
- * Merges a list of EventActions objects into a single EventActions object.
73
+ * Merges a list of {@link EventActions} objects into a single
74
+ * {@link EventActions} object.
66
75
  *
67
- * 1. It merges dictionaries (stateDelta, artifactDelta, requestedAuthConfigs)
68
- * by adding all the properties from each source.
76
+ * Merge semantics:
77
+ * 1. **Dictionary fields** (`stateDelta`, `artifactDelta`,
78
+ * `requestedAuthConfigs`, `requestedToolConfirmations`) — all entries from
79
+ * every source are combined via `Object.assign`. Later sources win on
80
+ * duplicate keys.
81
+ * 2. **Scalar fields** (`skipSummarization`, `transferToAgent`, `escalate`) —
82
+ * last-writer-wins: the value from the last source that sets the field is
83
+ * kept.
69
84
  *
70
- * 2. For other properties (skipSummarization,transferToAgent, escalate), the
71
- * last one wins.
85
+ * @param sources - Ordered list of partial {@link EventActions} to merge.
86
+ * Falsy entries are silently skipped.
87
+ * @param target - Optional base {@link EventActions} to merge into. When
88
+ * provided it is used as the starting state before applying `sources`.
89
+ * @returns A new {@link EventActions} containing the merged result.
72
90
  */
73
91
  export declare function mergeEventActions(sources: Array<Partial<EventActions>>, target?: EventActions): EventActions;
74
92
  export {};
@@ -7,17 +7,30 @@ import { CodeExecutionResult, ExecutableCode, FunctionCall, FunctionResponse } f
7
7
  import { Event } from './event.js';
8
8
  /**
9
9
  * The types of events that can be parsed from a raw Event.
10
+ *
11
+ * Each value corresponds to one category of structured output that
12
+ * {@link toStructuredEvents} may produce from a raw {@link Event}.
10
13
  */
11
14
  export declare enum EventType {
15
+ /** A reasoning trace (thought) emitted by the model. */
12
16
  THOUGHT = "thought",
17
+ /** A text delta intended for the end user. */
13
18
  CONTENT = "content",
19
+ /** A request from the model to execute a tool (function call). */
14
20
  TOOL_CALL = "tool_call",
21
+ /** The result returned by a tool execution (function response). */
15
22
  TOOL_RESULT = "tool_result",
23
+ /** A request from the model to execute code. */
16
24
  CALL_CODE = "call_code",
25
+ /** The result of a code execution. */
17
26
  CODE_RESULT = "code_result",
27
+ /** A runtime error signalled via `event.errorCode`. */
18
28
  ERROR = "error",
29
+ /** A generic activity or status update. */
19
30
  ACTIVITY = "activity",
31
+ /** A request for the user to confirm one or more tool calls. */
20
32
  TOOL_CONFIRMATION = "tool_confirmation",
33
+ /** The agent has produced its final response for this turn. */
21
34
  FINISHED = "finished"
22
35
  }
23
36
  /**