@google/adk 2.2.1 → 2.3.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 (226) hide show
  1. package/dist/cjs/a2a/a2a_remote_agent.js +4 -1
  2. package/dist/cjs/a2a/agent_card.js +102 -26
  3. package/dist/cjs/a2a/agent_to_a2a.js +1 -1
  4. package/dist/cjs/agents/functions.js +199 -25
  5. package/dist/cjs/agents/instructions.js +4 -1
  6. package/dist/cjs/agents/invocation_context.js +26 -4
  7. package/dist/cjs/agents/langgraph_agent.js +152 -0
  8. package/dist/cjs/agents/llm_agent.js +175 -101
  9. package/dist/cjs/agents/processors/code_execution_request_processor.js +10 -6
  10. package/dist/cjs/agents/remote_agent.js +187 -0
  11. package/dist/cjs/artifacts/in_memory_artifact_service.js +14 -0
  12. package/dist/cjs/auth/auth_handler.js +37 -5
  13. package/dist/cjs/auth/auth_schemes.js +9 -0
  14. package/dist/cjs/cli/cli_eval.js +532 -0
  15. package/dist/cjs/cli/utils/envs.js +116 -0
  16. package/dist/cjs/cli/utils/evals.js +137 -0
  17. package/dist/cjs/cli/utils/logs.js +150 -0
  18. package/dist/cjs/code_executors/agent_engine_sandbox_code_executor.js +7 -2
  19. package/dist/cjs/code_executors/code_execution_utils.js +48 -16
  20. package/dist/cjs/code_executors/code_executor_context.js +6 -2
  21. package/dist/cjs/common.js +72 -0
  22. package/dist/cjs/context/summarizers/llm_summarizer.js +12 -10
  23. package/dist/cjs/context/token_based_context_compactor.js +2 -1
  24. package/dist/cjs/events/event.js +4 -2
  25. package/dist/cjs/examples/example_util.js +23 -2
  26. package/dist/cjs/flows/llm_flows/audio_transcriber.js +170 -0
  27. package/dist/cjs/index.js +97 -1
  28. package/dist/cjs/integrations/agent_registry/helpers.js +1 -1
  29. package/dist/cjs/models/gemini_llm_connection.js +16 -8
  30. package/dist/cjs/models/google_llm.js +13 -16
  31. package/dist/cjs/models/llm_response.js +9 -1
  32. package/dist/cjs/models/registry.js +1 -1
  33. package/dist/cjs/models/routed_llm.js +9 -8
  34. package/dist/cjs/planners/plan_re_act_planner.js +1 -1
  35. package/dist/cjs/runner/in_memory_runner.js +6 -11
  36. package/dist/cjs/runner/runner.js +105 -33
  37. package/dist/cjs/sessions/db/operations.js +1 -1
  38. package/dist/cjs/sessions/in_memory_session_service.js +3 -1
  39. package/dist/cjs/sessions/state.js +8 -4
  40. package/dist/cjs/sessions/vertex_ai_session_service.js +34 -15
  41. package/dist/cjs/telemetry/tracing.js +97 -66
  42. package/dist/cjs/tools/agent_tool.js +44 -0
  43. package/dist/cjs/tools/apihub_tool/apihub_toolset.js +142 -0
  44. package/dist/cjs/tools/apihub_tool/clients/apihub_client.js +272 -0
  45. package/dist/cjs/tools/apihub_tool/clients/secret_client.js +148 -0
  46. package/dist/cjs/tools/apihub_tool/clients/service_account.js +48 -0
  47. package/dist/cjs/tools/application_integration_tool/application_integration_toolset.js +185 -0
  48. package/dist/cjs/tools/application_integration_tool/clients/cloud_request.js +133 -0
  49. package/dist/cjs/tools/application_integration_tool/clients/connections_client.js +603 -0
  50. package/dist/cjs/tools/application_integration_tool/clients/integration_client.js +219 -0
  51. package/dist/cjs/tools/crewai_tool.js +132 -0
  52. package/dist/cjs/tools/example_tool.js +10 -0
  53. package/dist/cjs/tools/function_tool.js +319 -0
  54. package/dist/cjs/tools/google_api_tool/google_api_tool.js +97 -0
  55. package/dist/cjs/tools/google_api_tool/google_api_tool_set.js +226 -0
  56. package/dist/cjs/tools/google_api_tool/google_api_tool_sets.js +58 -0
  57. package/dist/cjs/tools/google_api_tool/googleapi_to_openapi_converter.js +440 -0
  58. package/dist/cjs/tools/google_api_tool/index.js +64 -0
  59. package/dist/cjs/tools/langchain_tool.js +172 -0
  60. package/dist/cjs/tools/mcp/index.js +12 -0
  61. package/dist/cjs/tools/mcp/mcp_session_manager.js +25 -0
  62. package/dist/cjs/tools/openapi_tool/auth/auth_helpers.js +1 -2
  63. package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +46 -2
  64. package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/oauth2_exchanger.js +2 -1
  65. package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +94 -10
  66. package/dist/cjs/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +14 -2
  67. package/dist/cjs/tools/retrieval/base_retrieval_tool.js +18 -3
  68. package/dist/cjs/tools/toolbox_tool.js +108 -0
  69. package/dist/cjs/utils/env_aware_utils.js +6 -8
  70. package/dist/cjs/utils/error_utils.js +11 -11
  71. package/dist/cjs/utils/file_extension_utils.js +11 -0
  72. package/dist/cjs/utils/file_utils.js +2 -24
  73. package/dist/cjs/utils/gemini_schema_util.js +4 -1
  74. package/dist/cjs/utils/json_utils.js +49 -0
  75. package/dist/cjs/utils/live_connection_utils.js +4 -5
  76. package/dist/cjs/utils/logger_node.js +7 -1
  77. package/dist/cjs/utils/object_notation_utils.js +6 -3
  78. package/dist/cjs/utils/streaming_utils.js +12 -12
  79. package/dist/cjs/version.js +1 -1
  80. package/dist/esm/a2a/a2a_remote_agent.js +4 -1
  81. package/dist/esm/a2a/agent_card.js +103 -27
  82. package/dist/esm/a2a/agent_to_a2a.js +5 -2
  83. package/dist/esm/agents/functions.js +198 -25
  84. package/dist/esm/agents/instructions.js +4 -1
  85. package/dist/esm/agents/invocation_context.js +24 -4
  86. package/dist/esm/agents/langgraph_agent.js +123 -0
  87. package/dist/esm/agents/llm_agent.js +185 -104
  88. package/dist/esm/agents/processors/code_execution_request_processor.js +13 -8
  89. package/dist/esm/agents/remote_agent.js +164 -0
  90. package/dist/esm/artifacts/in_memory_artifact_service.js +14 -0
  91. package/dist/esm/auth/auth_handler.js +37 -5
  92. package/dist/esm/auth/auth_schemes.js +8 -0
  93. package/dist/esm/cli/cli_eval.js +510 -0
  94. package/dist/esm/cli/utils/envs.js +78 -0
  95. package/dist/esm/cli/utils/evals.js +109 -0
  96. package/dist/esm/cli/utils/logs.js +111 -0
  97. package/dist/esm/code_executors/agent_engine_sandbox_code_executor.js +7 -2
  98. package/dist/esm/code_executors/code_execution_utils.js +46 -16
  99. package/dist/esm/code_executors/code_executor_context.js +5 -2
  100. package/dist/esm/common.js +67 -3
  101. package/dist/esm/context/summarizers/llm_summarizer.js +12 -10
  102. package/dist/esm/context/token_based_context_compactor.js +2 -1
  103. package/dist/esm/events/event.js +4 -2
  104. package/dist/esm/examples/example_util.js +21 -1
  105. package/dist/esm/flows/llm_flows/audio_transcriber.js +142 -0
  106. package/dist/esm/index.js +99 -1
  107. package/dist/esm/integrations/agent_registry/helpers.js +1 -1
  108. package/dist/esm/models/gemini_llm_connection.js +16 -8
  109. package/dist/esm/models/google_llm.js +14 -17
  110. package/dist/esm/models/llm_response.js +9 -1
  111. package/dist/esm/models/registry.js +1 -1
  112. package/dist/esm/models/routed_llm.js +9 -8
  113. package/dist/esm/planners/plan_re_act_planner.js +1 -1
  114. package/dist/esm/runner/in_memory_runner.js +6 -11
  115. package/dist/esm/runner/runner.js +105 -33
  116. package/dist/esm/sessions/db/operations.js +1 -1
  117. package/dist/esm/sessions/in_memory_session_service.js +3 -1
  118. package/dist/esm/sessions/state.js +8 -4
  119. package/dist/esm/sessions/vertex_ai_session_service.js +34 -15
  120. package/dist/esm/telemetry/tracing.js +97 -66
  121. package/dist/esm/tools/agent_tool.js +44 -0
  122. package/dist/esm/tools/apihub_tool/apihub_toolset.js +106 -0
  123. package/dist/esm/tools/apihub_tool/clients/apihub_client.js +244 -0
  124. package/dist/esm/tools/apihub_tool/clients/secret_client.js +132 -0
  125. package/dist/esm/tools/apihub_tool/clients/service_account.js +21 -0
  126. package/dist/esm/tools/application_integration_tool/application_integration_toolset.js +163 -0
  127. package/dist/esm/tools/application_integration_tool/clients/cloud_request.js +103 -0
  128. package/dist/esm/tools/application_integration_tool/clients/connections_client.js +561 -0
  129. package/dist/esm/tools/application_integration_tool/clients/integration_client.js +215 -0
  130. package/dist/esm/tools/crewai_tool.js +107 -0
  131. package/dist/esm/tools/example_tool.js +13 -1
  132. package/dist/esm/tools/function_tool.js +316 -0
  133. package/dist/esm/tools/google_api_tool/google_api_tool.js +70 -0
  134. package/dist/esm/tools/google_api_tool/google_api_tool_set.js +188 -0
  135. package/dist/esm/tools/google_api_tool/google_api_tool_sets.js +24 -0
  136. package/dist/esm/tools/google_api_tool/googleapi_to_openapi_converter.js +393 -0
  137. package/dist/esm/tools/google_api_tool/index.js +33 -0
  138. package/dist/esm/tools/langchain_tool.js +148 -0
  139. package/dist/esm/tools/mcp/index.js +6 -0
  140. package/dist/esm/tools/mcp/mcp_session_manager.js +25 -0
  141. package/dist/esm/tools/openapi_tool/auth/auth_helpers.js +1 -2
  142. package/dist/esm/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +50 -3
  143. package/dist/esm/tools/openapi_tool/auth/credential_exchangers/oauth2_exchanger.js +2 -1
  144. package/dist/esm/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +94 -10
  145. package/dist/esm/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +15 -2
  146. package/dist/esm/tools/retrieval/base_retrieval_tool.js +16 -2
  147. package/dist/esm/tools/toolbox_tool.js +80 -0
  148. package/dist/esm/utils/env_aware_utils.js +6 -8
  149. package/dist/esm/utils/error_utils.js +9 -10
  150. package/dist/esm/utils/file_extension_utils.js +11 -0
  151. package/dist/esm/utils/file_utils.js +2 -23
  152. package/dist/esm/utils/gemini_schema_util.js +4 -1
  153. package/dist/esm/utils/json_utils.js +21 -0
  154. package/dist/esm/utils/live_connection_utils.js +4 -5
  155. package/dist/esm/utils/logger_node.js +7 -1
  156. package/dist/esm/utils/object_notation_utils.js +4 -2
  157. package/dist/esm/utils/streaming_utils.js +11 -11
  158. package/dist/esm/version.js +1 -1
  159. package/dist/types/a2a/a2a_remote_agent.d.ts +9 -0
  160. package/dist/types/a2a/agent_card.d.ts +44 -1
  161. package/dist/types/a2a/agent_to_a2a.d.ts +9 -0
  162. package/dist/types/a2a/index.d.ts +1 -0
  163. package/dist/types/agents/functions.d.ts +33 -1
  164. package/dist/types/agents/invocation_context.d.ts +20 -1
  165. package/dist/types/agents/langgraph_agent.d.ts +153 -0
  166. package/dist/types/agents/remote_agent.d.ts +68 -0
  167. package/dist/types/auth/auth_handler.d.ts +28 -1
  168. package/dist/types/auth/auth_schemes.d.ts +13 -0
  169. package/dist/types/cli/cli_eval.d.ts +173 -0
  170. package/dist/types/cli/utils/envs.d.ts +23 -0
  171. package/dist/types/cli/utils/evals.d.ts +47 -0
  172. package/dist/types/cli/utils/logs.d.ts +38 -0
  173. package/dist/types/code_executors/code_execution_utils.d.ts +39 -0
  174. package/dist/types/code_executors/code_executor_context.d.ts +1 -0
  175. package/dist/types/common.d.ts +27 -4
  176. package/dist/types/events/event.d.ts +4 -0
  177. package/dist/types/examples/example_util.d.ts +17 -0
  178. package/dist/types/flows/llm_flows/audio_transcriber.d.ts +85 -0
  179. package/dist/types/index.d.ts +16 -1
  180. package/dist/types/models/gemini_llm_connection.d.ts +6 -7
  181. package/dist/types/models/routed_llm.d.ts +1 -1
  182. package/dist/types/runner/in_memory_runner.d.ts +2 -1
  183. package/dist/types/runner/runner.d.ts +34 -0
  184. package/dist/types/sessions/state.d.ts +5 -1
  185. package/dist/types/sessions/vertex_ai_session_service.d.ts +8 -0
  186. package/dist/types/skills/skill.d.ts +1 -1
  187. package/dist/types/telemetry/tracing.d.ts +4 -2
  188. package/dist/types/tools/apihub_tool/apihub_toolset.d.ts +122 -0
  189. package/dist/types/tools/apihub_tool/clients/apihub_client.d.ts +142 -0
  190. package/dist/types/tools/apihub_tool/clients/secret_client.d.ts +55 -0
  191. package/dist/types/tools/apihub_tool/clients/service_account.d.ts +11 -0
  192. package/dist/types/tools/application_integration_tool/application_integration_toolset.d.ts +86 -0
  193. package/dist/types/tools/application_integration_tool/clients/cloud_request.d.ts +53 -0
  194. package/dist/types/tools/application_integration_tool/clients/connections_client.d.ts +215 -0
  195. package/dist/types/tools/application_integration_tool/clients/integration_client.d.ts +72 -0
  196. package/dist/types/tools/crewai_tool.d.ts +85 -0
  197. package/dist/types/tools/example_tool.d.ts +10 -0
  198. package/dist/types/tools/function_tool.d.ts +32 -0
  199. package/dist/types/tools/google_api_tool/google_api_tool.d.ts +30 -0
  200. package/dist/types/tools/google_api_tool/google_api_tool_set.d.ts +78 -0
  201. package/dist/types/tools/google_api_tool/google_api_tool_sets.d.ts +33 -0
  202. package/dist/types/tools/google_api_tool/googleapi_to_openapi_converter.d.ts +164 -0
  203. package/dist/types/tools/google_api_tool/index.d.ts +11 -0
  204. package/dist/types/tools/langchain_tool.d.ts +103 -0
  205. package/dist/types/tools/mcp/index.d.ts +3 -0
  206. package/dist/types/tools/mcp/mcp_session_manager.d.ts +34 -1
  207. package/dist/types/tools/mcp/mcp_toolset.d.ts +15 -0
  208. package/dist/types/tools/openapi_tool/auth/auth_helpers.d.ts +19 -0
  209. package/dist/types/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.d.ts +18 -1
  210. package/dist/types/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.d.ts +2 -1
  211. package/dist/types/tools/retrieval/base_retrieval_tool.d.ts +15 -0
  212. package/dist/types/tools/toolbox_tool.d.ts +73 -0
  213. package/dist/types/utils/env_aware_utils.d.ts +18 -2
  214. package/dist/types/utils/error_utils.d.ts +7 -0
  215. package/dist/types/utils/file_utils.d.ts +6 -1
  216. package/dist/types/utils/gemini_schema_util.d.ts +1 -2
  217. package/dist/types/utils/json_utils.d.ts +11 -0
  218. package/dist/types/utils/object_notation_utils.d.ts +7 -0
  219. package/dist/types/utils/streaming_utils.d.ts +11 -4
  220. package/dist/types/version.d.ts +1 -1
  221. package/dist/web/index_web.js +102 -103
  222. package/dist/web/index_web.js.map +4 -4
  223. package/package.json +8 -3
  224. package/dist/cjs/models/gemini_continuation.js +0 -232
  225. package/dist/esm/models/gemini_continuation.js +0 -205
  226. package/dist/types/models/gemini_continuation.d.ts +0 -59
@@ -21,7 +21,10 @@ import {
21
21
  mergeEventActions
22
22
  } from "../events/event_actions.js";
23
23
  import { BaseTool } from "../tools/base_tool.js";
24
+ import { isFunctionTool } from "../tools/function_tool.js";
24
25
  import { logger } from "../utils/logger.js";
26
+ import { Task } from "../utils/task.js";
27
+ import { ActiveStreamingTool } from "./active_streaming_tool.js";
25
28
  import { Context } from "./context.js";
26
29
  import {
27
30
  REQUEST_CONFIRMATION_FUNCTION_CALL_NAME,
@@ -50,6 +53,8 @@ import {
50
53
  } from "./framework_function_calls.js";
51
54
  const functionsExportedForTestingOnly = {
52
55
  handleFunctionCallList,
56
+ handleFunctionCallsLive,
57
+ processFunctionLiveHelper,
53
58
  generateAuthEvent,
54
59
  generateRequestConfirmationEvent
55
60
  };
@@ -152,7 +157,8 @@ async function callToolAsync(tool, args, toolContext) {
152
157
  result,
153
158
  toolContext,
154
159
  toolContext.invocationContext
155
- )
160
+ ),
161
+ invocationContext: toolContext.invocationContext
156
162
  });
157
163
  return result;
158
164
  } finally {
@@ -213,6 +219,30 @@ async function handleFunctionCallsAsync({
213
219
  });
214
220
  }
215
221
  __name(handleFunctionCallsAsync, "handleFunctionCallsAsync");
222
+ async function handleFunctionCallsLive({
223
+ invocationContext,
224
+ functionCallEvent,
225
+ toolsDict,
226
+ beforeToolCallbacks,
227
+ afterToolCallbacks,
228
+ filters,
229
+ toolConfirmationDict,
230
+ resumeInputsDict
231
+ }) {
232
+ const functionCalls = getFunctionCalls(functionCallEvent);
233
+ return handleFunctionCallList({
234
+ invocationContext,
235
+ functionCalls,
236
+ toolsDict,
237
+ beforeToolCallbacks,
238
+ afterToolCallbacks,
239
+ filters,
240
+ toolConfirmationDict,
241
+ resumeInputsDict,
242
+ isLive: true
243
+ });
244
+ }
245
+ __name(handleFunctionCallsLive, "handleFunctionCallsLive");
216
246
  function normalizeCallbackResponse(response) {
217
247
  if (response == null) {
218
248
  return void 0;
@@ -298,7 +328,8 @@ async function handleFunctionCallList({
298
328
  afterToolCallbacks,
299
329
  filters,
300
330
  toolConfirmationDict,
301
- resumeInputsDict
331
+ resumeInputsDict,
332
+ isLive = false
302
333
  }) {
303
334
  var _a2;
304
335
  const functionResponseEvents = [];
@@ -335,7 +366,6 @@ async function handleFunctionCallList({
335
366
  logger.debug(`execute_tool ${tool.name}`);
336
367
  const functionArgs = (_a2 = functionCall.args) != null ? _a2 : {};
337
368
  let functionResponse = null;
338
- let functionResponseError;
339
369
  functionResponse = await invocationContext.pluginManager.runBeforeToolCallback({
340
370
  tool,
341
371
  toolArgs: functionArgs,
@@ -356,7 +386,18 @@ async function handleFunctionCallList({
356
386
  functionResponse = normalizeCallbackResponse(functionResponse);
357
387
  if (functionResponse == null) {
358
388
  try {
359
- functionResponse = await callToolAsync(tool, functionArgs, toolContext);
389
+ const rawFunctionResponse = isLive ? await processFunctionLiveHelper({
390
+ tool,
391
+ toolContext,
392
+ functionCall,
393
+ functionArgs,
394
+ invocationContext
395
+ }) : await callToolAsync(tool, functionArgs, toolContext);
396
+ if (rawFunctionResponse == null && !tool.isLongRunning) {
397
+ functionResponse = { result: rawFunctionResponse };
398
+ } else {
399
+ functionResponse = normalizeCallbackResponse(rawFunctionResponse);
400
+ }
360
401
  } catch (e) {
361
402
  if (e instanceof Error) {
362
403
  const onToolErrorResponse = await invocationContext.pluginManager.runOnToolErrorCallback({
@@ -368,18 +409,19 @@ async function handleFunctionCallList({
368
409
  if (onToolErrorResponse != null) {
369
410
  functionResponse = normalizeCallbackResponse(onToolErrorResponse);
370
411
  } else {
371
- functionResponseError = e.message;
412
+ functionResponse = { error: e.message };
372
413
  }
373
414
  } else {
374
- functionResponseError = e;
415
+ functionResponse = { error: e };
375
416
  }
376
417
  }
377
418
  }
419
+ const callbackResult = functionResponse != null ? functionResponse : {};
378
420
  let alteredFunctionResponse = await invocationContext.pluginManager.runAfterToolCallback({
379
421
  tool,
380
422
  toolArgs: functionArgs,
381
423
  toolContext,
382
- result: functionResponse
424
+ result: callbackResult
383
425
  });
384
426
  if (alteredFunctionResponse == null) {
385
427
  for (const callback of afterToolCallbacks) {
@@ -387,7 +429,7 @@ async function handleFunctionCallList({
387
429
  tool,
388
430
  args: functionArgs,
389
431
  context: toolContext,
390
- response: functionResponse
432
+ response: callbackResult
391
433
  });
392
434
  if (alteredFunctionResponse) {
393
435
  break;
@@ -410,13 +452,6 @@ async function handleFunctionCallList({
410
452
  }
411
453
  continue;
412
454
  }
413
- if (functionResponseError) {
414
- functionResponse = { error: functionResponseError };
415
- } else if (functionResponse == null) {
416
- functionResponse = { result: functionResponse };
417
- } else {
418
- functionResponse = normalizeCallbackResponse(functionResponse);
419
- }
420
455
  const functionResponseEvent = createEvent({
421
456
  invocationId: invocationContext.invocationId,
422
457
  author: toolEventAuthor(invocationContext),
@@ -430,11 +465,6 @@ async function handleFunctionCallList({
430
465
  actions: toolContext.actions,
431
466
  branch: invocationContext.branch
432
467
  });
433
- logger.debug("traceToolCall", {
434
- tool: tool.name,
435
- args: functionArgs,
436
- functionResponseEvent: functionResponseEvent.id
437
- });
438
468
  functionResponseEvents.push(functionResponseEvent);
439
469
  }
440
470
  if (!functionResponseEvents.length) {
@@ -447,13 +477,10 @@ async function handleFunctionCallList({
447
477
  tracer.startActiveSpan("execute_tool (merged)", (span) => {
448
478
  try {
449
479
  logger.debug("execute_tool (merged)");
450
- logger.debug("traceMergedToolCalls", {
451
- responseEventId: mergedEvent.id,
452
- functionResponseEvent: mergedEvent.id
453
- });
454
480
  traceMergedToolCalls({
455
481
  responseEventId: mergedEvent.id,
456
- functionResponseEvent: mergedEvent
482
+ functionResponseEvent: mergedEvent,
483
+ invocationContext
457
484
  });
458
485
  } finally {
459
486
  span.end();
@@ -491,6 +518,151 @@ function mergeParallelFunctionResponseEvents(functionResponseEvents) {
491
518
  });
492
519
  }
493
520
  __name(mergeParallelFunctionResponseEvents, "mergeParallelFunctionResponseEvents");
521
+ function isAsyncGeneratorFunction(fn) {
522
+ return typeof fn === "function" && Object.prototype.toString.call(fn) === "[object AsyncGeneratorFunction]";
523
+ }
524
+ __name(isAsyncGeneratorFunction, "isAsyncGeneratorFunction");
525
+ function isStreamingTool(tool) {
526
+ const candidate = tool;
527
+ if (typeof candidate._callLive !== "function") {
528
+ return false;
529
+ }
530
+ if (isFunctionTool(tool)) {
531
+ return isAsyncGeneratorFunction(candidate.execute);
532
+ }
533
+ return isAsyncGeneratorFunction(candidate.execute) || isAsyncGeneratorFunction(candidate.func) || isAsyncGeneratorFunction(candidate._callLive);
534
+ }
535
+ __name(isStreamingTool, "isStreamingTool");
536
+ async function* callToolLive({
537
+ tool,
538
+ args,
539
+ toolContext,
540
+ invocationContext
541
+ }) {
542
+ const results = tool._callLive({
543
+ args,
544
+ toolContext,
545
+ invocationContext
546
+ });
547
+ for await (const result of results) {
548
+ yield result;
549
+ }
550
+ }
551
+ __name(callToolLive, "callToolLive");
552
+ async function waitForTaskWithTimeout(task, timeoutMs) {
553
+ let timeoutId;
554
+ const timeoutPromise = new Promise((resolve) => {
555
+ timeoutId = setTimeout(resolve, timeoutMs);
556
+ });
557
+ try {
558
+ await Promise.race([
559
+ task.promise.then(
560
+ () => void 0,
561
+ () => void 0
562
+ ),
563
+ timeoutPromise
564
+ ]);
565
+ } finally {
566
+ if (timeoutId !== void 0) {
567
+ clearTimeout(timeoutId);
568
+ }
569
+ }
570
+ }
571
+ __name(waitForTaskWithTimeout, "waitForTaskWithTimeout");
572
+ const STOP_STREAMING_FUNCTION_NAME = "stop_streaming";
573
+ const STOP_STREAMING_TIMEOUT_MS = 1e3;
574
+ async function processFunctionLiveHelper({
575
+ tool,
576
+ toolContext,
577
+ functionCall,
578
+ functionArgs,
579
+ invocationContext
580
+ }) {
581
+ var _a2, _b2;
582
+ let functionResponse = void 0;
583
+ const targetFunctionName = typeof functionArgs["function_name"] === "string" ? functionArgs["function_name"] : typeof functionArgs["functionName"] === "string" ? functionArgs["functionName"] : void 0;
584
+ if (functionCall.name === STOP_STREAMING_FUNCTION_NAME && targetFunctionName !== void 0) {
585
+ const activeTasks = invocationContext.activeStreamingTools;
586
+ const activeTask = (_a2 = activeTasks == null ? void 0 : activeTasks[targetFunctionName]) == null ? void 0 : _a2.task;
587
+ if (activeTasks && activeTask && !activeTask.done()) {
588
+ activeTask.cancel();
589
+ await waitForTaskWithTimeout(activeTask, STOP_STREAMING_TIMEOUT_MS);
590
+ if (!activeTask.done()) {
591
+ logger.warn(`The task for ${targetFunctionName} is not cancelled yet.`);
592
+ functionResponse = {
593
+ status: `The task is not cancelled yet for ${targetFunctionName}.`
594
+ };
595
+ } else {
596
+ activeTasks[targetFunctionName].task = void 0;
597
+ functionResponse = {
598
+ status: `Successfully stopped streaming function ${targetFunctionName}`
599
+ };
600
+ }
601
+ } else {
602
+ functionResponse = {
603
+ status: `No active streaming function named ${targetFunctionName} found`
604
+ };
605
+ }
606
+ } else if (isStreamingTool(tool)) {
607
+ const task = new Task(async (abortSignal) => {
608
+ var _a3, _b3;
609
+ const generator = callToolLive({
610
+ tool,
611
+ args: functionArgs,
612
+ toolContext,
613
+ invocationContext
614
+ });
615
+ let abortCleanup;
616
+ const abortPromise = new Promise(
617
+ (resolve) => {
618
+ if (abortSignal.aborted) {
619
+ resolve({ value: void 0, done: true });
620
+ return;
621
+ }
622
+ const onAbort = /* @__PURE__ */ __name(() => {
623
+ resolve({ value: void 0, done: true });
624
+ }, "onAbort");
625
+ abortSignal.addEventListener("abort", onAbort, { once: true });
626
+ abortCleanup = /* @__PURE__ */ __name(() => abortSignal.removeEventListener("abort", onAbort), "abortCleanup");
627
+ }
628
+ );
629
+ try {
630
+ while (!abortSignal.aborted) {
631
+ const nextResult = await Promise.race([
632
+ generator.next(),
633
+ abortPromise
634
+ ]);
635
+ if (abortSignal.aborted || nextResult.done) {
636
+ break;
637
+ }
638
+ const result = nextResult.value;
639
+ const updatedContent = createUserContent(
640
+ `Function ${tool.name} returned: ${String(result)}`
641
+ );
642
+ (_a3 = invocationContext.liveRequestQueue) == null ? void 0 : _a3.sendContent(updatedContent);
643
+ }
644
+ } finally {
645
+ abortCleanup == null ? void 0 : abortCleanup();
646
+ if (abortSignal.aborted) {
647
+ void ((_b3 = generator.return) == null ? void 0 : _b3.call(generator, void 0));
648
+ }
649
+ }
650
+ });
651
+ (_b2 = invocationContext.activeStreamingTools) != null ? _b2 : invocationContext.activeStreamingTools = {};
652
+ if (tool.name in invocationContext.activeStreamingTools) {
653
+ invocationContext.activeStreamingTools[tool.name].task = task;
654
+ } else {
655
+ invocationContext.activeStreamingTools[tool.name] = new ActiveStreamingTool({ task });
656
+ }
657
+ functionResponse = {
658
+ status: "The function is running asynchronously and the results are pending."
659
+ };
660
+ } else {
661
+ functionResponse = await callToolAsync(tool, functionArgs, toolContext);
662
+ }
663
+ return functionResponse;
664
+ }
665
+ __name(processFunctionLiveHelper, "processFunctionLiveHelper");
494
666
  function findEventByFunctionCallId(events, functionCallId, endIndex = events.length) {
495
667
  for (let i = endIndex - 1; i >= 0; i--) {
496
668
  const event = events[i];
@@ -559,6 +731,7 @@ export {
559
731
  getLongRunningFunctionCalls,
560
732
  handleFunctionCallList,
561
733
  handleFunctionCallsAsync,
734
+ handleFunctionCallsLive,
562
735
  isToolNotFound,
563
736
  mergeParallelFunctionResponseEvents,
564
737
  populateClientFunctionCallId,
@@ -91,7 +91,10 @@ async function injectSessionState(template, readonlyContext) {
91
91
  resolved: resolveSourceNode(match[0], match[1], match[2], scope)
92
92
  })) : [];
93
93
  const pattern = /\{+[^{}]*}+/g;
94
- const matches = Array.from(template.matchAll(pattern));
94
+ const matches = Array.from(template.matchAll(pattern)).filter((match) => {
95
+ const previous = template[match.index - 1];
96
+ return previous !== "$" && previous !== "\\";
97
+ });
95
98
  if (matches.length === 0 && sourceMatches.length === 0) {
96
99
  return template;
97
100
  }
@@ -7,7 +7,25 @@ var __name = (target, value) => __defProp(target, "name", { value, configurable:
7
7
  * Copyright 2025 Google LLC
8
8
  * SPDX-License-Identifier: Apache-2.0
9
9
  */
10
+ var _a, _b;
10
11
  import { randomUUID } from "../utils/env_aware_utils.js";
12
+ const LLM_CALLS_LIMIT_EXCEEDED_ERROR_SIGNATURE_SYMBOL = /* @__PURE__ */ Symbol.for(
13
+ "google.adk.llmCallsLimitExceededError"
14
+ );
15
+ const _LlmCallsLimitExceededError = class _LlmCallsLimitExceededError extends (_b = Error, _a = LLM_CALLS_LIMIT_EXCEEDED_ERROR_SIGNATURE_SYMBOL, _b) {
16
+ constructor(message) {
17
+ super(message);
18
+ this[_a] = true;
19
+ this.name = "LlmCallsLimitExceededError";
20
+ Object.setPrototypeOf(this, _LlmCallsLimitExceededError.prototype);
21
+ }
22
+ };
23
+ __name(_LlmCallsLimitExceededError, "LlmCallsLimitExceededError");
24
+ let LlmCallsLimitExceededError = _LlmCallsLimitExceededError;
25
+ function isLlmCallsLimitExceededError(obj) {
26
+ return typeof obj === "object" && obj !== null && LLM_CALLS_LIMIT_EXCEEDED_ERROR_SIGNATURE_SYMBOL in obj && obj[LLM_CALLS_LIMIT_EXCEEDED_ERROR_SIGNATURE_SYMBOL] === true;
27
+ }
28
+ __name(isLlmCallsLimitExceededError, "isLlmCallsLimitExceededError");
11
29
  const _InvocationCostManager = class _InvocationCostManager {
12
30
  constructor() {
13
31
  this.numberOfLlmCalls = 0;
@@ -21,7 +39,7 @@ const _InvocationCostManager = class _InvocationCostManager {
21
39
  incrementAndEnforceLlmCallsLimit(runConfig) {
22
40
  this.numberOfLlmCalls++;
23
41
  if (runConfig && runConfig.maxLlmCalls > 0 && this.numberOfLlmCalls > runConfig.maxLlmCalls) {
24
- throw new Error(
42
+ throw new LlmCallsLimitExceededError(
25
43
  `Max number of llm calls limit of ${runConfig.maxLlmCalls} exceeded`
26
44
  );
27
45
  }
@@ -34,7 +52,7 @@ const _InvocationContext = class _InvocationContext {
34
52
  * @param params The parameters for creating an invocation context.
35
53
  */
36
54
  constructor(params) {
37
- var _a, _b;
55
+ var _a2, _b2;
38
56
  this.artifactService = params.artifactService;
39
57
  this.sessionService = params.sessionService;
40
58
  this.memoryService = params.memoryService;
@@ -51,9 +69,9 @@ const _InvocationContext = class _InvocationContext {
51
69
  this.abortSignal = params.abortSignal;
52
70
  this.workflowInstructionScope = params.workflowInstructionScope;
53
71
  this.isolationScope = params.isolationScope;
54
- this.nodeToolDepth = (_a = params.nodeToolDepth) != null ? _a : 0;
72
+ this.nodeToolDepth = (_a2 = params.nodeToolDepth) != null ? _a2 : 0;
55
73
  this.a2aMetadata = params.a2aMetadata;
56
- this.invocationCostManager = (_b = params.invocationCostManager) != null ? _b : new InvocationCostManager();
74
+ this.invocationCostManager = (_b2 = params.invocationCostManager) != null ? _b2 : new InvocationCostManager();
57
75
  this.liveRequestQueue = params.liveRequestQueue;
58
76
  this.liveSessionResumptionHandle = params.liveSessionResumptionHandle;
59
77
  }
@@ -107,6 +125,8 @@ function requireAgent(ctx) {
107
125
  __name(requireAgent, "requireAgent");
108
126
  export {
109
127
  InvocationContext,
128
+ LlmCallsLimitExceededError,
129
+ isLlmCallsLimitExceededError,
110
130
  newInvocationContextId,
111
131
  requireAgent
112
132
  };
@@ -0,0 +1,123 @@
1
+ import {createRequire as topLevelCreateRequire} from 'module';
2
+ const require = topLevelCreateRequire(import.meta.url);
3
+ var __defProp = Object.defineProperty;
4
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
5
+ /**
6
+ * @license
7
+ * Copyright 2026 Google LLC
8
+ * SPDX-License-Identifier: Apache-2.0
9
+ */
10
+ var _a, _b;
11
+ import { createEvent } from "../events/event.js";
12
+ import { BaseAgent } from "./base_agent.js";
13
+ function getLastHumanMessages(events) {
14
+ var _a2, _b2, _c;
15
+ const messages = [];
16
+ for (let i = events.length - 1; i >= 0; i--) {
17
+ const event = events[i];
18
+ if (messages.length > 0 && event.author !== "user") {
19
+ break;
20
+ }
21
+ const text = (_c = (_b2 = (_a2 = event.content) == null ? void 0 : _a2.parts) == null ? void 0 : _b2[0]) == null ? void 0 : _c.text;
22
+ if (event.author === "user" && text !== void 0) {
23
+ messages.push({ type: "human", content: text });
24
+ }
25
+ }
26
+ return messages.reverse();
27
+ }
28
+ __name(getLastHumanMessages, "getLastHumanMessages");
29
+ function extractMessageText(content) {
30
+ if (typeof content === "string") {
31
+ return content;
32
+ }
33
+ return content.map((part) => {
34
+ var _a2;
35
+ return typeof part === "string" ? part : (_a2 = part.text) != null ? _a2 : "";
36
+ }).join("");
37
+ }
38
+ __name(extractMessageText, "extractMessageText");
39
+ const LANGGRAPH_AGENT_SIGNATURE_SYMBOL = /* @__PURE__ */ Symbol.for(
40
+ "google.adk.langGraphAgent"
41
+ );
42
+ function isLangGraphAgent(obj) {
43
+ return typeof obj === "object" && obj !== null && LANGGRAPH_AGENT_SIGNATURE_SYMBOL in obj && obj[LANGGRAPH_AGENT_SIGNATURE_SYMBOL] === true;
44
+ }
45
+ __name(isLangGraphAgent, "isLangGraphAgent");
46
+ const _LangGraphAgent = class _LangGraphAgent extends (_b = BaseAgent, _a = LANGGRAPH_AGENT_SIGNATURE_SYMBOL, _b) {
47
+ constructor(config) {
48
+ var _a2;
49
+ super(config);
50
+ this[_a] = true;
51
+ this.graph = config.graph;
52
+ this.instruction = (_a2 = config.instruction) != null ? _a2 : "";
53
+ }
54
+ async *runAsyncImpl(ctx) {
55
+ var _a2, _b2, _c;
56
+ const config = {
57
+ // LangGraph.js checkpointers read `configurable.thread_id`.
58
+ configurable: { thread_id: ctx.session.id }
59
+ };
60
+ let currentGraphState;
61
+ if (this.graph.checkpointer) {
62
+ if (typeof this.graph.getState !== "function") {
63
+ throw new Error(
64
+ `LangGraphAgent '${this.name}' requires graph.getState() when graph.checkpointer is configured.`
65
+ );
66
+ }
67
+ currentGraphState = await this.graph.getState(config);
68
+ }
69
+ const graphMessages = (_b2 = (_a2 = currentGraphState == null ? void 0 : currentGraphState.values) == null ? void 0 : _a2.messages) != null ? _b2 : [];
70
+ const messages = this.instruction && graphMessages.length === 0 ? [{ type: "system", content: this.instruction }] : [];
71
+ messages.push(...this.getMessages(ctx.session.events));
72
+ const finalState = await this.graph.invoke({ messages }, config);
73
+ const finalMessages = (_c = finalState.messages) != null ? _c : [];
74
+ const lastMessage = finalMessages[finalMessages.length - 1];
75
+ if (!lastMessage) {
76
+ throw new Error(
77
+ `LangGraphAgent '${this.name}' received no messages from graph.invoke().`
78
+ );
79
+ }
80
+ yield createEvent({
81
+ invocationId: ctx.invocationId,
82
+ author: this.name,
83
+ branch: ctx.branch,
84
+ content: {
85
+ role: "model",
86
+ parts: [{ text: extractMessageText(lastMessage.content) }]
87
+ }
88
+ });
89
+ }
90
+ async *runLiveImpl(_ctx) {
91
+ yield* [];
92
+ throw new Error("This is not supported yet for LangGraphAgent.");
93
+ }
94
+ getMessages(events) {
95
+ if (this.graph.checkpointer) {
96
+ return getLastHumanMessages(events);
97
+ }
98
+ return this.getConversationWithAgent(events);
99
+ }
100
+ getConversationWithAgent(events) {
101
+ var _a2, _b2, _c;
102
+ const messages = [];
103
+ for (const event of events) {
104
+ const text = (_c = (_b2 = (_a2 = event.content) == null ? void 0 : _a2.parts) == null ? void 0 : _b2[0]) == null ? void 0 : _c.text;
105
+ if (text === void 0) {
106
+ continue;
107
+ }
108
+ if (event.author === "user") {
109
+ messages.push({ type: "human", content: text });
110
+ } else if (event.author === this.name) {
111
+ messages.push({ type: "ai", content: text });
112
+ }
113
+ }
114
+ return messages;
115
+ }
116
+ };
117
+ __name(_LangGraphAgent, "LangGraphAgent");
118
+ let LangGraphAgent = _LangGraphAgent;
119
+ export {
120
+ LangGraphAgent,
121
+ getLastHumanMessages,
122
+ isLangGraphAgent
123
+ };