@softactivate/adk 1.1.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 (141) 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 +3 -0
  6. package/dist/cjs/events/event.js +2 -0
  7. package/dist/cjs/index.js +14 -0
  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 +17 -8
  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/long_running_tool.js +2 -1
  23. package/dist/cjs/tools/mcp/mcp_session_manager.js +11 -0
  24. package/dist/cjs/tools/mcp/mcp_tool.js +10 -7
  25. package/dist/cjs/tools/mcp/mcp_toolset.js +10 -2
  26. package/dist/cjs/tools/openapi_tool/auth/auth_helpers.js +78 -0
  27. package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +84 -0
  28. package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +133 -0
  29. package/dist/cjs/tools/skill/load_skill_resource_tool.js +2 -25
  30. package/dist/cjs/utils/file_utils.js +28 -0
  31. package/dist/cjs/utils/gemini_schema_util.js +18 -0
  32. package/dist/cjs/utils/partial_copy.js +51 -0
  33. package/dist/cjs/utils/streaming_utils.js +167 -118
  34. package/dist/cjs/utils/vertex_ai_utils.js +50 -0
  35. package/dist/cjs/version.js +1 -1
  36. package/dist/esm/agents/functions.js +4 -0
  37. package/dist/esm/auth/oauth2/oauth2_discovery.js +26 -2
  38. package/dist/esm/code_executors/agent_engine_sandbox_code_executor.js +281 -0
  39. package/dist/esm/code_executors/code_execution_utils.js +1 -1
  40. package/dist/esm/common.js +2 -0
  41. package/dist/esm/events/event.js +2 -0
  42. package/dist/esm/index.js +11 -0
  43. package/dist/esm/integrations/agent_registry/agent_registry.js +333 -0
  44. package/dist/esm/integrations/agent_registry/agent_registry_mcp_toolset.js +77 -0
  45. package/dist/esm/integrations/agent_registry/helpers.js +28 -0
  46. package/dist/esm/integrations/agent_registry/types.js +20 -0
  47. package/dist/esm/memory/vertex_ai_memory_bank_service.js +468 -0
  48. package/dist/esm/runner/in_memory_runner.js +10 -5
  49. package/dist/esm/runner/runner.js +32 -2
  50. package/dist/esm/sessions/database_session_service.js +49 -3
  51. package/dist/esm/sessions/in_memory_session_service.js +70 -14
  52. package/dist/esm/sessions/registry.js +7 -0
  53. package/dist/esm/sessions/vertex_ai_session_service.js +403 -0
  54. package/dist/esm/tools/agent_tool.js +17 -8
  55. package/dist/esm/tools/exit_loop_tool.js +9 -0
  56. package/dist/esm/tools/function_tool.js +7 -2
  57. package/dist/esm/tools/long_running_tool.js +2 -1
  58. package/dist/esm/tools/mcp/mcp_session_manager.js +11 -0
  59. package/dist/esm/tools/mcp/mcp_tool.js +10 -7
  60. package/dist/esm/tools/mcp/mcp_toolset.js +10 -2
  61. package/dist/esm/tools/openapi_tool/auth/auth_helpers.js +48 -0
  62. package/dist/esm/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +60 -0
  63. package/dist/esm/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +111 -0
  64. package/dist/esm/tools/skill/load_skill_resource_tool.js +1 -24
  65. package/dist/esm/utils/file_utils.js +26 -0
  66. package/dist/esm/utils/gemini_schema_util.js +18 -0
  67. package/dist/esm/utils/partial_copy.js +23 -0
  68. package/dist/esm/utils/streaming_utils.js +165 -117
  69. package/dist/esm/utils/vertex_ai_utils.js +22 -0
  70. package/dist/esm/version.js +1 -1
  71. package/dist/types/a2a/a2a_remote_agent.d.ts +14 -0
  72. package/dist/types/agents/processors/base_llm_processor.d.ts +12 -4
  73. package/dist/types/agents/processors/basic_llm_request_processor.d.ts +5 -0
  74. package/dist/types/agents/processors/identity_llm_request_processor.d.ts +4 -0
  75. package/dist/types/agents/processors/request_confirmation_llm_request_processor.d.ts +5 -0
  76. package/dist/types/agents/run_config.d.ts +15 -0
  77. package/dist/types/code_executors/agent_engine_sandbox_code_executor.d.ts +51 -0
  78. package/dist/types/common.d.ts +2 -0
  79. package/dist/types/events/event_actions.d.ts +24 -6
  80. package/dist/types/events/structured_events.d.ts +13 -0
  81. package/dist/types/examples/example_util.d.ts +25 -0
  82. package/dist/types/index.d.ts +6 -0
  83. package/dist/types/integrations/agent_registry/agent_registry.d.ts +94 -0
  84. package/dist/types/integrations/agent_registry/agent_registry_mcp_toolset.d.ts +43 -0
  85. package/dist/types/integrations/agent_registry/helpers.d.ts +7 -0
  86. package/dist/types/integrations/agent_registry/types.d.ts +101 -0
  87. package/dist/types/memory/vertex_ai_memory_bank_service.d.ts +52 -0
  88. package/dist/types/runner/in_memory_runner.d.ts +28 -1
  89. package/dist/types/runner/runner.d.ts +47 -0
  90. package/dist/types/sessions/base_session_service.d.ts +18 -0
  91. package/dist/types/sessions/database_session_service.d.ts +1 -1
  92. package/dist/types/sessions/in_memory_session_service.d.ts +1 -1
  93. package/dist/types/sessions/vertex_ai_session_service.d.ts +37 -0
  94. package/dist/types/tools/exit_loop_tool.d.ts +9 -0
  95. package/dist/types/tools/function_tool.d.ts +22 -2
  96. package/dist/types/tools/long_running_tool.d.ts +11 -1
  97. package/dist/types/tools/mcp/mcp_session_manager.d.ts +3 -0
  98. package/dist/types/tools/openapi_tool/auth/auth_helpers.d.ts +25 -0
  99. package/dist/types/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.d.ts +20 -0
  100. package/dist/types/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.d.ts +20 -0
  101. package/dist/types/utils/file_utils.d.ts +2 -0
  102. package/dist/types/utils/partial_copy.d.ts +13 -0
  103. package/dist/types/utils/streaming_utils.d.ts +8 -17
  104. package/dist/types/utils/vertex_ai_utils.d.ts +14 -0
  105. package/dist/types/version.d.ts +1 -1
  106. package/dist/web/agents/functions.js +4 -0
  107. package/dist/web/auth/oauth2/oauth2_discovery.js +26 -2
  108. package/dist/web/code_executors/agent_engine_sandbox_code_executor.js +281 -0
  109. package/dist/web/code_executors/code_execution_utils.js +1 -1
  110. package/dist/web/common.js +2 -0
  111. package/dist/web/events/event.js +2 -0
  112. package/dist/web/index.js +11 -0
  113. package/dist/web/integrations/agent_registry/agent_registry.js +333 -0
  114. package/dist/web/integrations/agent_registry/agent_registry_mcp_toolset.js +90 -0
  115. package/dist/web/integrations/agent_registry/helpers.js +28 -0
  116. package/dist/web/integrations/agent_registry/types.js +20 -0
  117. package/dist/web/memory/vertex_ai_memory_bank_service.js +475 -0
  118. package/dist/web/runner/in_memory_runner.js +10 -5
  119. package/dist/web/runner/runner.js +32 -2
  120. package/dist/web/sessions/database_session_service.js +49 -3
  121. package/dist/web/sessions/in_memory_session_service.js +70 -14
  122. package/dist/web/sessions/registry.js +7 -0
  123. package/dist/web/sessions/vertex_ai_session_service.js +414 -0
  124. package/dist/web/tools/agent_tool.js +17 -8
  125. package/dist/web/tools/exit_loop_tool.js +9 -0
  126. package/dist/web/tools/function_tool.js +7 -2
  127. package/dist/web/tools/long_running_tool.js +2 -1
  128. package/dist/web/tools/mcp/mcp_session_manager.js +11 -0
  129. package/dist/web/tools/mcp/mcp_tool.js +10 -7
  130. package/dist/web/tools/mcp/mcp_toolset.js +10 -2
  131. package/dist/web/tools/openapi_tool/auth/auth_helpers.js +48 -0
  132. package/dist/web/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +60 -0
  133. package/dist/web/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +111 -0
  134. package/dist/web/tools/skill/load_skill_resource_tool.js +1 -24
  135. package/dist/web/utils/file_utils.js +26 -0
  136. package/dist/web/utils/gemini_schema_util.js +18 -0
  137. package/dist/web/utils/partial_copy.js +23 -0
  138. package/dist/web/utils/streaming_utils.js +218 -117
  139. package/dist/web/utils/vertex_ai_utils.js +22 -0
  140. package/dist/web/version.js +1 -1
  141. package/package.json +2 -1
@@ -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,108 +158,102 @@ 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
214
  }
215
+ if (part.functionCall && !part.functionCall.id) {
216
+ part.functionCall.id = generateClientFunctionCallId();
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;
227
- }
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))) {
230
- const parts = [];
231
- if (this.thoughtText) {
232
- parts.push({ text: this.thoughtText, thought: true });
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;
233
249
  }
234
- if (this.text) {
235
- parts.push({ text: this.text });
250
+ if (sawTextPart) {
251
+ llmResponse.partial = true;
236
252
  }
237
- yield {
238
- content: {
239
- role: "model",
240
- parts
241
- },
242
- usageMetadata: llmResponse.usageMetadata,
243
- partial: false
244
- };
245
- this.thoughtText = "";
246
- this.text = "";
247
253
  }
248
254
  yield llmResponse;
249
255
  }
250
256
  close() {
251
- var _a, _b, _c, _d, _e, _f;
252
- if (this.isProgressiveMode) {
253
- this.flushTextBufferToSequence();
254
- this.flushFunctionCallToSequence();
255
- const finalParts = this.partsSequence;
256
- if (finalParts.length === 0) {
257
- return;
258
- }
259
- const candidate = (_b = (_a = this.response) == null ? void 0 : _a.candidates) == null ? void 0 : _b[0];
260
- const finishReason = (_c = this.finishReason) != null ? _c : candidate == null ? void 0 : candidate.finishReason;
261
- return {
262
- content: {
263
- role: "model",
264
- parts: finalParts
265
- },
266
- groundingMetadata: this.groundingMetadata,
267
- citationMetadata: this.citationMetadata,
268
- errorCode: finishReason === FinishReason.STOP ? void 0 : finishReason,
269
- errorMessage: finishReason === FinishReason.STOP ? void 0 : candidate == null ? void 0 : candidate.finishMessage,
270
- usageMetadata: this.usageMetadata,
271
- finishReason,
272
- partial: false
273
- };
274
- }
275
257
  if (this.text || this.thoughtText) {
276
258
  const parts = [];
277
259
  if (this.thoughtText) {
@@ -280,25 +262,91 @@ class StreamingResponseAggregator {
280
262
  if (this.text) {
281
263
  parts.push({ text: this.text });
282
264
  }
283
- const candidate = (_e = (_d = this.response) == null ? void 0 : _d.candidates) == null ? void 0 : _e[0];
284
- const finishReason = (_f = this.finishReason) != null ? _f : candidate == null ? void 0 : candidate.finishReason;
285
- return {
286
- content: {
287
- role: "model",
288
- parts
289
- },
290
- groundingMetadata: this.groundingMetadata,
291
- citationMetadata: this.citationMetadata,
292
- errorCode: finishReason === FinishReason.STOP ? void 0 : finishReason,
293
- errorMessage: finishReason === FinishReason.STOP ? void 0 : candidate == null ? void 0 : candidate.finishMessage,
294
- usageMetadata: this.usageMetadata,
295
- finishReason,
296
- partial: false
297
- };
265
+ return parts;
298
266
  }
299
267
  return void 0;
300
268
  }
301
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) {
280
+ var _a, _b;
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;
285
+ }
286
+ if (this.sawFunctionCall && llmResponse.finishReason === FinishReason.STOP && parts.length > 0 && parts.every(isEmptyContentPart)) {
287
+ if (llmResponse.usageMetadata) {
288
+ this.usageMetadata = llmResponse.usageMetadata;
289
+ }
290
+ if (llmResponse.groundingMetadata) {
291
+ this.groundingMetadata = llmResponse.groundingMetadata;
292
+ }
293
+ if (llmResponse.citationMetadata) {
294
+ this.citationMetadata = llmResponse.citationMetadata;
295
+ }
296
+ if (llmResponse.finishReason) {
297
+ this.finishReason = llmResponse.finishReason;
298
+ }
299
+ return;
300
+ }
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
+ };
344
+ }
345
+ }
346
+ function isEmptyContentPart(part) {
347
+ return !part.functionCall && !part.functionResponse && !part.fileData && !part.inlineData && !part.executableCode && !part.codeExecutionResult && (!part.text || part.text === "");
348
+ }
302
349
  export {
303
- StreamingResponseAggregator
350
+ StreamingResponseAggregator,
351
+ isEmptyContentPart
304
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.1.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';
@@ -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
  /**
@@ -8,6 +8,31 @@ import { Example } from './example.js';
8
8
  /**
9
9
  * Converts a list of examples to a string that can be used in a system
10
10
  * instruction.
11
+ *
12
+ * When `model` is undefined or contains `"gemini-2"`, function calls and
13
+ * responses are formatted with plain triple-backtick fences. For other model
14
+ * names the legacy `tool_code` / `tool_outputs` fences are used instead.
15
+ *
16
+ * @param examples - The few-shot examples to convert.
17
+ * @param model - Optional model name used to select the function-call fence
18
+ * style. Defaults to the gemini-2 style when omitted.
19
+ * @returns A formatted string wrapped in `<EXAMPLES>…</EXAMPLES>` tags,
20
+ * suitable for inclusion in a system instruction.
11
21
  */
12
22
  export declare function convertExamplesToText(examples: Example[], model?: string): string;
23
+ /**
24
+ * Builds the few-shot portion of a system instruction from a list of examples
25
+ * or a {@link BaseExampleProvider}.
26
+ *
27
+ * @param examples - Either an array of {@link Example} objects or a
28
+ * {@link BaseExampleProvider} whose `getExamples` method is called with
29
+ * `query` to obtain the examples dynamically.
30
+ * @param query - The user query passed to {@link BaseExampleProvider.getExamples}
31
+ * when `examples` is a provider. Ignored when `examples` is an array.
32
+ * @param model - Optional model name forwarded to
33
+ * {@link convertExamplesToText} to select the function-call fence style.
34
+ * @returns A formatted string ready to be appended to a system instruction.
35
+ * @throws {Error} When `examples` is neither an array nor a
36
+ * {@link BaseExampleProvider}.
37
+ */
13
38
  export declare function buildExampleSi(examples: Example[] | BaseExampleProvider, query: string, model?: string): string;