@google/adk 2.4.0 → 2.5.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 (326) hide show
  1. package/dist/cjs/a2a/a2a_remote_agent.js +17 -2
  2. package/dist/cjs/a2a/a2a_remote_agent_utils.js +8 -4
  3. package/dist/cjs/a2a/agent_card.js +5 -81
  4. package/dist/cjs/a2a/agent_to_a2a.js +7 -0
  5. package/dist/cjs/a2a/event_converter_utils.js +10 -3
  6. package/dist/cjs/agents/agent_engine_client.js +282 -55
  7. package/dist/cjs/agents/base_agent.js +111 -68
  8. package/dist/cjs/agents/functions.js +62 -85
  9. package/dist/cjs/agents/instructions.js +7 -6
  10. package/dist/cjs/agents/invocation_context.js +2 -2
  11. package/dist/cjs/agents/llm_agent.js +105 -95
  12. package/dist/cjs/agents/processors/content_processor_utils.js +42 -15
  13. package/dist/cjs/agents/processors/content_request_processor.js +28 -11
  14. package/dist/cjs/agents/processors/context_compactor_request_processor.js +5 -1
  15. package/dist/cjs/agents/processors/instructions_llm_request_processor.js +1 -1
  16. package/dist/cjs/agents/processors/nl_planning_processor.js +2 -1
  17. package/dist/cjs/artifacts/file_artifact_service.js +1 -1
  18. package/dist/cjs/cli/cli_eval.js +884 -17
  19. package/dist/cjs/cli/utils/cleanup.js +84 -0
  20. package/dist/cjs/cli/utils/envs.js +33 -2
  21. package/dist/cjs/cli/utils/evals.js +75 -8
  22. package/dist/cjs/cli/utils/logs.js +128 -9
  23. package/dist/cjs/cli/utils/path_validation.js +83 -0
  24. package/dist/cjs/code_executors/container_code_executor.js +158 -36
  25. package/dist/cjs/common.js +50 -12
  26. package/dist/cjs/context/compaction_utils.js +19 -0
  27. package/dist/cjs/events/event.js +7 -3
  28. package/dist/cjs/features/feature_registry.js +5 -0
  29. package/dist/cjs/index.js +29 -14
  30. package/dist/cjs/models/google_llm.js +33 -2
  31. package/dist/cjs/models/interactions_utils.js +3 -0
  32. package/dist/cjs/plugins/base_plugin.js +45 -21
  33. package/dist/cjs/plugins/plugin_manager.js +27 -0
  34. package/dist/cjs/runner/runner.js +306 -189
  35. package/dist/cjs/sessions/base_session_service.js +1 -4
  36. package/dist/cjs/sessions/database_session_service.js +191 -19
  37. package/dist/cjs/sessions/db/operations.js +70 -1
  38. package/dist/cjs/sessions/db/schema.js +4 -0
  39. package/dist/cjs/sessions/in_memory_session_service.js +2 -2
  40. package/dist/cjs/sessions/vertex_ai_session_service.js +11 -3
  41. package/dist/cjs/skills/loader.js +29 -28
  42. package/dist/cjs/telemetry/api/instrumentation.js +632 -0
  43. package/dist/cjs/telemetry/api/internal/common/accumulators.js +169 -0
  44. package/dist/cjs/telemetry/api/internal/common/attributes.js +131 -0
  45. package/dist/cjs/telemetry/api/internal/common/config.js +159 -0
  46. package/dist/cjs/telemetry/api/internal/common/error.js +98 -0
  47. package/dist/cjs/telemetry/api/internal/common/finish_reason.js +63 -0
  48. package/dist/cjs/telemetry/api/internal/common/genai_messages.js +217 -0
  49. package/dist/cjs/telemetry/api/internal/common/http_exchange.js +169 -0
  50. package/dist/cjs/telemetry/api/internal/common/provider_name.js +87 -0
  51. package/dist/cjs/telemetry/api/internal/common/redaction.js +148 -0
  52. package/dist/cjs/telemetry/api/internal/common/serialization.js +58 -0
  53. package/dist/cjs/telemetry/api/internal/common/token_usage.js +118 -0
  54. package/dist/cjs/telemetry/api/internal/logs/inference.js +50 -0
  55. package/dist/cjs/telemetry/api/internal/logs/logger.js +46 -0
  56. package/dist/cjs/telemetry/api/internal/logs/mcp.js +141 -0
  57. package/dist/cjs/telemetry/api/internal/metrics/agent.js +128 -0
  58. package/dist/cjs/telemetry/api/internal/metrics/inference_start_hook.js +56 -0
  59. package/dist/cjs/telemetry/api/internal/metrics/meters.js +189 -0
  60. package/dist/cjs/telemetry/api/internal/metrics/tool.js +147 -0
  61. package/dist/cjs/telemetry/api/internal/metrics/workflow.js +132 -0
  62. package/dist/cjs/telemetry/api/internal/trace/agent.js +52 -0
  63. package/dist/cjs/telemetry/api/internal/trace/compaction.js +78 -0
  64. package/dist/cjs/telemetry/api/internal/trace/inference.js +132 -0
  65. package/dist/cjs/telemetry/api/internal/trace/live.js +52 -0
  66. package/dist/cjs/telemetry/api/internal/trace/node.js +73 -0
  67. package/dist/cjs/telemetry/api/internal/trace/propagation.js +67 -0
  68. package/dist/cjs/telemetry/api/internal/trace/tool.js +122 -0
  69. package/dist/cjs/telemetry/api/internal/trace/tracer.js +77 -0
  70. package/dist/cjs/telemetry/api/internal/trace/workflow.js +77 -0
  71. package/dist/cjs/telemetry/export/agent_engine.js +90 -0
  72. package/dist/cjs/telemetry/export/agent_runtime.js +73 -0
  73. package/dist/cjs/telemetry/export/google_cloud.js +763 -0
  74. package/dist/cjs/telemetry/export/request_driven_metric_reader.js +303 -0
  75. package/dist/cjs/telemetry/{setup.js → export/setup.js} +72 -5
  76. package/dist/cjs/tools/agent_tool.js +9 -1
  77. package/dist/cjs/tools/application_integration_tool/application_integration_toolset.js +22 -34
  78. package/dist/cjs/tools/application_integration_tool/clients/connections_client.js +60 -20
  79. package/dist/cjs/tools/application_integration_tool/clients/integration_client.js +26 -10
  80. package/dist/cjs/tools/application_integration_tool/integration_connector_tool.js +14 -23
  81. package/dist/cjs/tools/base_toolset.js +1 -1
  82. package/dist/cjs/tools/computer_use/base_computer.js +125 -0
  83. package/dist/cjs/tools/computer_use/computer_use_actions.js +502 -0
  84. package/dist/cjs/tools/computer_use/computer_use_tool.js +244 -0
  85. package/dist/cjs/tools/computer_use/computer_use_toolset.js +360 -0
  86. package/dist/cjs/tools/function_tool.js +15 -5
  87. package/dist/cjs/tools/google_api_tool/google_api_toolset.js +3 -2
  88. package/dist/cjs/tools/google_api_tool/googleapi_to_openapi_converter.js +3 -1
  89. package/dist/cjs/tools/load_artifacts_tool.js +15 -5
  90. package/dist/cjs/tools/load_memory_tool.js +2 -5
  91. package/dist/cjs/tools/mcp/mcp_session_manager.js +23 -3
  92. package/dist/cjs/tools/mcp/mcp_tool.js +7 -3
  93. package/dist/cjs/tools/mcp/mcp_toolset.js +18 -6
  94. package/dist/cjs/tools/openapi_tool/auth/auth_helpers.js +30 -29
  95. package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/oauth2_exchanger.js +2 -2
  96. package/dist/cjs/tools/openapi_tool/rest_api_tool.js +45 -14
  97. package/dist/cjs/tools/skill/load_skill_resource_tool.js +7 -0
  98. package/dist/cjs/tools/skill/load_skill_tool.js +3 -0
  99. package/dist/cjs/tools/skill/run_skill_script_tool.js +12 -2
  100. package/dist/cjs/tools/toolbox_toolset.js +47 -28
  101. package/dist/cjs/utils/async_queue.js +37 -3
  102. package/dist/cjs/utils/client_labels.js +9 -11
  103. package/dist/cjs/utils/env_aware_utils.js +13 -7
  104. package/dist/cjs/utils/error_utils.js +40 -2
  105. package/dist/cjs/utils/failover_utils.js +10 -9
  106. package/dist/cjs/utils/gemini_schema_util.js +125 -12
  107. package/dist/cjs/utils/id_provider.js +63 -0
  108. package/dist/cjs/utils/model_name.js +15 -0
  109. package/dist/cjs/utils/simple_zod_to_json.js +13 -31
  110. package/dist/cjs/utils/ssrf_guard.js +46 -16
  111. package/dist/cjs/version.js +1 -1
  112. package/dist/cjs/workflow/index.js +2 -0
  113. package/dist/cjs/workflow/node_runner.js +24 -80
  114. package/dist/cjs/workflow/nodes/parallel_worker.js +18 -7
  115. package/dist/cjs/workflow/run_llm_agent_as_node.js +19 -14
  116. package/dist/cjs/workflow/utils/retry_utils.js +2 -2
  117. package/dist/cjs/workflow/workflow.js +12 -12
  118. package/dist/esm/a2a/a2a_remote_agent.js +23 -3
  119. package/dist/esm/a2a/a2a_remote_agent_utils.js +8 -4
  120. package/dist/esm/a2a/agent_card.js +5 -83
  121. package/dist/esm/a2a/agent_to_a2a.js +7 -0
  122. package/dist/esm/a2a/event_converter_utils.js +10 -3
  123. package/dist/esm/agents/agent_engine_client.js +293 -55
  124. package/dist/esm/agents/base_agent.js +111 -72
  125. package/dist/esm/agents/functions.js +67 -89
  126. package/dist/esm/agents/instructions.js +7 -6
  127. package/dist/esm/agents/invocation_context.js +2 -2
  128. package/dist/esm/agents/llm_agent.js +111 -100
  129. package/dist/esm/agents/processors/content_processor_utils.js +42 -15
  130. package/dist/esm/agents/processors/content_request_processor.js +28 -11
  131. package/dist/esm/agents/processors/context_compactor_request_processor.js +5 -1
  132. package/dist/esm/agents/processors/instructions_llm_request_processor.js +1 -1
  133. package/dist/esm/agents/processors/nl_planning_processor.js +2 -1
  134. package/dist/esm/artifacts/file_artifact_service.js +1 -1
  135. package/dist/esm/cli/cli_eval.js +880 -17
  136. package/dist/esm/cli/utils/cleanup.js +56 -0
  137. package/dist/esm/cli/utils/envs.js +33 -2
  138. package/dist/esm/cli/utils/evals.js +74 -8
  139. package/dist/esm/cli/utils/logs.js +128 -9
  140. package/dist/esm/cli/utils/path_validation.js +45 -0
  141. package/dist/esm/code_executors/container_code_executor.js +158 -36
  142. package/dist/esm/common.js +49 -6
  143. package/dist/esm/context/compaction_utils.js +19 -0
  144. package/dist/esm/events/event.js +7 -3
  145. package/dist/esm/features/feature_registry.js +5 -0
  146. package/dist/esm/index.js +27 -15
  147. package/dist/esm/models/google_llm.js +33 -2
  148. package/dist/esm/models/interactions_utils.js +3 -0
  149. package/dist/esm/plugins/base_plugin.js +45 -21
  150. package/dist/esm/plugins/plugin_manager.js +27 -0
  151. package/dist/esm/runner/runner.js +310 -192
  152. package/dist/esm/sessions/base_session_service.js +1 -4
  153. package/dist/esm/sessions/database_session_service.js +191 -19
  154. package/dist/esm/sessions/db/operations.js +70 -1
  155. package/dist/esm/sessions/db/schema.js +4 -0
  156. package/dist/esm/sessions/in_memory_session_service.js +2 -2
  157. package/dist/esm/sessions/vertex_ai_session_service.js +11 -3
  158. package/dist/esm/skills/loader.js +29 -28
  159. package/dist/esm/telemetry/api/instrumentation.js +655 -0
  160. package/dist/esm/telemetry/api/internal/common/accumulators.js +139 -0
  161. package/dist/esm/telemetry/api/internal/common/attributes.js +94 -0
  162. package/dist/esm/telemetry/api/internal/common/config.js +128 -0
  163. package/dist/esm/telemetry/api/internal/common/error.js +69 -0
  164. package/dist/esm/telemetry/api/internal/common/finish_reason.js +35 -0
  165. package/dist/esm/telemetry/api/internal/common/genai_messages.js +188 -0
  166. package/dist/esm/telemetry/api/internal/common/http_exchange.js +142 -0
  167. package/dist/esm/telemetry/api/internal/common/provider_name.js +59 -0
  168. package/dist/esm/telemetry/api/internal/common/redaction.js +121 -0
  169. package/dist/esm/telemetry/api/internal/common/serialization.js +30 -0
  170. package/dist/esm/telemetry/api/internal/common/token_usage.js +85 -0
  171. package/dist/esm/telemetry/api/internal/logs/inference.js +23 -0
  172. package/dist/esm/telemetry/api/internal/logs/logger.js +19 -0
  173. package/dist/esm/telemetry/api/internal/logs/mcp.js +113 -0
  174. package/dist/esm/telemetry/api/internal/metrics/agent.js +107 -0
  175. package/dist/esm/telemetry/api/internal/metrics/inference_start_hook.js +29 -0
  176. package/dist/esm/telemetry/api/internal/metrics/meters.js +165 -0
  177. package/dist/esm/telemetry/api/internal/metrics/tool.js +119 -0
  178. package/dist/esm/telemetry/api/internal/metrics/workflow.js +112 -0
  179. package/dist/esm/telemetry/api/internal/trace/agent.js +25 -0
  180. package/dist/esm/telemetry/api/internal/trace/compaction.js +50 -0
  181. package/dist/esm/telemetry/api/internal/trace/inference.js +107 -0
  182. package/dist/esm/telemetry/api/internal/trace/live.js +28 -0
  183. package/dist/esm/telemetry/api/internal/trace/node.js +44 -0
  184. package/dist/esm/telemetry/api/internal/trace/propagation.js +39 -0
  185. package/dist/esm/telemetry/api/internal/trace/tool.js +96 -0
  186. package/dist/esm/telemetry/api/internal/trace/tracer.js +52 -0
  187. package/dist/esm/telemetry/api/internal/trace/workflow.js +54 -0
  188. package/dist/esm/telemetry/export/agent_engine.js +67 -0
  189. package/dist/esm/telemetry/export/agent_runtime.js +46 -0
  190. package/dist/esm/telemetry/export/google_cloud.js +733 -0
  191. package/dist/esm/telemetry/export/request_driven_metric_reader.js +276 -0
  192. package/dist/esm/telemetry/export/setup.js +160 -0
  193. package/dist/esm/tools/agent_tool.js +9 -1
  194. package/dist/esm/tools/application_integration_tool/application_integration_toolset.js +23 -35
  195. package/dist/esm/tools/application_integration_tool/clients/connections_client.js +64 -21
  196. package/dist/esm/tools/application_integration_tool/clients/integration_client.js +26 -10
  197. package/dist/esm/tools/application_integration_tool/integration_connector_tool.js +14 -23
  198. package/dist/esm/tools/base_toolset.js +1 -1
  199. package/dist/esm/tools/computer_use/base_computer.js +99 -0
  200. package/dist/esm/tools/computer_use/computer_use_actions.js +477 -0
  201. package/dist/esm/tools/computer_use/computer_use_tool.js +217 -0
  202. package/dist/esm/tools/computer_use/computer_use_toolset.js +344 -0
  203. package/dist/esm/tools/function_tool.js +15 -5
  204. package/dist/esm/tools/google_api_tool/google_api_toolset.js +3 -2
  205. package/dist/esm/tools/google_api_tool/googleapi_to_openapi_converter.js +3 -1
  206. package/dist/esm/tools/load_artifacts_tool.js +15 -5
  207. package/dist/esm/tools/load_memory_tool.js +2 -5
  208. package/dist/esm/tools/mcp/mcp_session_manager.js +23 -3
  209. package/dist/esm/tools/mcp/mcp_tool.js +7 -3
  210. package/dist/esm/tools/mcp/mcp_toolset.js +18 -6
  211. package/dist/esm/tools/openapi_tool/auth/auth_helpers.js +27 -26
  212. package/dist/esm/tools/openapi_tool/auth/credential_exchangers/oauth2_exchanger.js +2 -2
  213. package/dist/esm/tools/openapi_tool/rest_api_tool.js +45 -14
  214. package/dist/esm/tools/skill/load_skill_resource_tool.js +7 -0
  215. package/dist/esm/tools/skill/load_skill_tool.js +3 -0
  216. package/dist/esm/tools/skill/run_skill_script_tool.js +12 -2
  217. package/dist/esm/tools/toolbox_toolset.js +47 -28
  218. package/dist/esm/utils/async_queue.js +37 -3
  219. package/dist/esm/utils/client_labels.js +9 -11
  220. package/dist/esm/utils/env_aware_utils.js +12 -7
  221. package/dist/esm/utils/error_utils.js +37 -1
  222. package/dist/esm/utils/failover_utils.js +10 -9
  223. package/dist/esm/utils/gemini_schema_util.js +124 -11
  224. package/dist/esm/utils/id_provider.js +33 -0
  225. package/dist/esm/utils/model_name.js +14 -0
  226. package/dist/esm/utils/simple_zod_to_json.js +13 -31
  227. package/dist/esm/utils/ssrf_guard.js +55 -15
  228. package/dist/esm/version.js +1 -1
  229. package/dist/esm/workflow/index.js +2 -1
  230. package/dist/esm/workflow/node_runner.js +26 -80
  231. package/dist/esm/workflow/nodes/parallel_worker.js +16 -6
  232. package/dist/esm/workflow/run_llm_agent_as_node.js +19 -14
  233. package/dist/esm/workflow/utils/retry_utils.js +2 -2
  234. package/dist/esm/workflow/workflow.js +12 -12
  235. package/dist/types/a2a/a2a_remote_agent.d.ts +6 -0
  236. package/dist/types/a2a/a2a_remote_agent_utils.d.ts +3 -2
  237. package/dist/types/agents/agent_engine_client.d.ts +121 -3
  238. package/dist/types/agents/base_agent.d.ts +2 -0
  239. package/dist/types/agents/processors/content_processor_utils.d.ts +9 -9
  240. package/dist/types/agents/run_config.d.ts +14 -0
  241. package/dist/types/cli/cli_eval.d.ts +172 -9
  242. package/dist/types/cli/utils/cleanup.d.ts +18 -0
  243. package/dist/types/cli/utils/envs.d.ts +13 -3
  244. package/dist/types/cli/utils/evals.d.ts +64 -1
  245. package/dist/types/cli/utils/logs.d.ts +19 -2
  246. package/dist/types/cli/utils/path_validation.d.ts +30 -0
  247. package/dist/types/code_executors/container_code_executor.d.ts +49 -8
  248. package/dist/types/common.d.ts +16 -9
  249. package/dist/types/context/compaction_utils.d.ts +13 -1
  250. package/dist/types/events/event.d.ts +3 -0
  251. package/dist/types/features/feature_registry.d.ts +1 -0
  252. package/dist/types/index.d.ts +9 -6
  253. package/dist/types/plugins/base_plugin.d.ts +50 -21
  254. package/dist/types/plugins/plugin_manager.d.ts +13 -0
  255. package/dist/types/runner/runner.d.ts +11 -0
  256. package/dist/types/sessions/base_session_service.d.ts +0 -2
  257. package/dist/types/sessions/db/operations.d.ts +2 -1
  258. package/dist/types/sessions/db/schema.d.ts +5 -3
  259. package/dist/types/telemetry/api/instrumentation.d.ts +259 -0
  260. package/dist/types/telemetry/api/internal/common/accumulators.d.ts +91 -0
  261. package/dist/types/telemetry/api/internal/common/attributes.d.ts +90 -0
  262. package/dist/types/telemetry/api/internal/common/config.d.ts +61 -0
  263. package/dist/types/telemetry/api/internal/common/error.d.ts +29 -0
  264. package/dist/types/telemetry/api/internal/common/finish_reason.d.ts +18 -0
  265. package/dist/types/telemetry/api/internal/common/genai_messages.d.ts +26 -0
  266. package/dist/types/telemetry/api/internal/common/http_exchange.d.ts +50 -0
  267. package/dist/types/telemetry/api/internal/common/provider_name.d.ts +16 -0
  268. package/dist/types/telemetry/api/internal/common/redaction.d.ts +14 -0
  269. package/dist/types/telemetry/api/internal/common/serialization.d.ts +18 -0
  270. package/dist/types/telemetry/api/internal/common/token_usage.d.ts +47 -0
  271. package/dist/types/telemetry/api/internal/logs/inference.d.ts +15 -0
  272. package/dist/types/telemetry/api/internal/logs/logger.d.ts +13 -0
  273. package/dist/types/telemetry/api/internal/logs/mcp.d.ts +31 -0
  274. package/dist/types/telemetry/api/internal/metrics/agent.d.ts +28 -0
  275. package/dist/types/telemetry/api/internal/metrics/inference_start_hook.d.ts +12 -0
  276. package/dist/types/telemetry/api/internal/metrics/meters.d.ts +57 -0
  277. package/dist/types/telemetry/api/internal/metrics/tool.d.ts +44 -0
  278. package/dist/types/telemetry/api/internal/metrics/workflow.d.ts +32 -0
  279. package/dist/types/telemetry/api/internal/trace/agent.d.ts +14 -0
  280. package/dist/types/telemetry/api/internal/trace/compaction.d.ts +20 -0
  281. package/dist/types/telemetry/api/internal/trace/inference.d.ts +31 -0
  282. package/dist/types/telemetry/api/internal/trace/live.d.ts +21 -0
  283. package/dist/types/telemetry/api/internal/trace/node.d.ts +22 -0
  284. package/dist/types/telemetry/api/internal/trace/propagation.d.ts +22 -0
  285. package/dist/types/telemetry/api/internal/trace/tool.d.ts +57 -0
  286. package/dist/types/telemetry/api/internal/trace/tracer.d.ts +31 -0
  287. package/dist/types/telemetry/api/internal/trace/workflow.d.ts +21 -0
  288. package/dist/types/telemetry/export/agent_engine.d.ts +23 -0
  289. package/dist/types/telemetry/export/agent_runtime.d.ts +40 -0
  290. package/dist/types/telemetry/export/google_cloud.d.ts +189 -0
  291. package/dist/types/telemetry/export/request_driven_metric_reader.d.ts +144 -0
  292. package/dist/types/telemetry/{setup.d.ts → export/setup.d.ts} +3 -0
  293. package/dist/types/tools/agent_tool.d.ts +1 -1
  294. package/dist/types/tools/application_integration_tool/clients/connections_client.d.ts +13 -4
  295. package/dist/types/tools/base_toolset.d.ts +1 -1
  296. package/dist/types/tools/computer_use/base_computer.d.ts +281 -0
  297. package/dist/types/tools/computer_use/computer_use_actions.d.ts +53 -0
  298. package/dist/types/tools/computer_use/computer_use_tool.d.ts +108 -0
  299. package/dist/types/tools/computer_use/computer_use_toolset.d.ts +132 -0
  300. package/dist/types/tools/google_api_tool/google_api_toolset.d.ts +2 -0
  301. package/dist/types/tools/load_artifacts_tool.d.ts +5 -1
  302. package/dist/types/tools/load_memory_tool.d.ts +13 -7
  303. package/dist/types/tools/mcp/mcp_session_manager.d.ts +16 -0
  304. package/dist/types/tools/openapi_tool/auth/auth_helpers.d.ts +8 -8
  305. package/dist/types/tools/openapi_tool/openapi_spec_parser/operation_parser.d.ts +7 -3
  306. package/dist/types/tools/toolbox_toolset.d.ts +15 -20
  307. package/dist/types/utils/async_queue.d.ts +14 -0
  308. package/dist/types/utils/env_aware_utils.d.ts +11 -0
  309. package/dist/types/utils/error_utils.d.ts +4 -0
  310. package/dist/types/utils/gemini_schema_util.d.ts +27 -6
  311. package/dist/types/utils/id_provider.d.ts +43 -0
  312. package/dist/types/utils/model_name.d.ts +8 -0
  313. package/dist/types/utils/ssrf_guard.d.ts +2 -0
  314. package/dist/types/version.d.ts +1 -1
  315. package/dist/types/workflow/index.d.ts +1 -1
  316. package/dist/types/workflow/nodes/parallel_worker.d.ts +8 -1
  317. package/dist/web/index_web.js +86 -88
  318. package/dist/web/index_web.js.map +4 -4
  319. package/package.json +13 -15
  320. package/dist/cjs/telemetry/google_cloud.js +0 -116
  321. package/dist/cjs/telemetry/tracing.js +0 -393
  322. package/dist/esm/telemetry/google_cloud.js +0 -99
  323. package/dist/esm/telemetry/setup.js +0 -88
  324. package/dist/esm/telemetry/tracing.js +0 -361
  325. package/dist/types/telemetry/google_cloud.d.ts +0 -9
  326. package/dist/types/telemetry/tracing.d.ts +0 -143
@@ -8,7 +8,9 @@ var __name = (target, value) => __defProp(target, "name", { value, configurable:
8
8
  * SPDX-License-Identifier: Apache-2.0
9
9
  */
10
10
  var _a, _b;
11
- import { createUserContent } from "@google/genai";
11
+ import {
12
+ createUserContent
13
+ } from "@google/genai";
12
14
  import { isEmpty } from "lodash-es";
13
15
  import {
14
16
  createEvent,
@@ -21,6 +23,7 @@ import {
21
23
  mergeEventActions
22
24
  } from "../events/event_actions.js";
23
25
  import { BaseTool } from "../tools/base_tool.js";
26
+ import { isComputerUseTool } from "../tools/computer_use/computer_use_tool.js";
24
27
  import { isFunctionTool } from "../tools/function_tool.js";
25
28
  import { logger } from "../utils/logger.js";
26
29
  import { Task } from "../utils/task.js";
@@ -31,10 +34,9 @@ import {
31
34
  REQUEST_CREDENTIAL_FUNCTION_CALL_NAME
32
35
  } from "./framework_function_calls.js";
33
36
  import {
34
- traceMergedToolCalls,
35
- tracer,
36
- traceToolCall
37
- } from "../telemetry/tracing.js";
37
+ recordMergedToolCalls,
38
+ recordToolExecution
39
+ } from "../telemetry/api/instrumentation.js";
38
40
  function toolEventAuthor(invocationContext) {
39
41
  var _a2, _b2;
40
42
  return (_b2 = (_a2 = invocationContext.agent) == null ? void 0 : _a2.name) != null ? _b2 : "";
@@ -145,56 +147,45 @@ function generateRequestConfirmationEvent({
145
147
  }
146
148
  __name(generateRequestConfirmationEvent, "generateRequestConfirmationEvent");
147
149
  async function callToolAsync(tool, args, toolContext) {
148
- return tracer.startActiveSpan(`execute_tool ${tool.name}`, async (span) => {
149
- try {
150
+ return recordToolExecution(
151
+ { tool, args, invocationContext: toolContext.invocationContext },
152
+ async (scope) => {
150
153
  logger.debug(`callToolAsync ${tool.name}`);
151
154
  const result = await tool.runAsync({ args, toolContext });
152
- traceToolCall({
153
- tool,
154
- args,
155
- span,
155
+ scope.recordSuccess({
156
156
  functionResponseEvent: buildResponseEvent(
157
157
  tool,
158
158
  result,
159
159
  toolContext,
160
160
  toolContext.invocationContext
161
161
  ),
162
- errorType: getToolResponseErrorType(result),
163
- invocationContext: toolContext.invocationContext
162
+ rawResult: result
164
163
  });
165
164
  return result;
166
- } catch (error) {
167
- traceToolCall({
168
- tool,
169
- args,
170
- span,
171
- error,
172
- invocationContext: toolContext.invocationContext
173
- });
174
- throw error;
175
- } finally {
176
- span.end();
177
165
  }
178
- });
166
+ );
179
167
  }
180
168
  __name(callToolAsync, "callToolAsync");
181
- function getToolResponseErrorType(result) {
182
- var _a2;
183
- if (result === null || typeof result !== "object" || Array.isArray(result)) {
184
- return void 0;
185
- }
186
- try {
187
- if (!Object.hasOwn(result, "error")) {
188
- return void 0;
189
- }
190
- const response = result;
191
- const errorType = (_a2 = response.errorType) != null ? _a2 : response.error_type;
192
- return typeof errorType === "string" ? errorType : void 0;
193
- } catch {
194
- return void 0;
169
+ const BASE64 = /^[A-Za-z0-9+/]*={0,2}$/;
170
+ function buildFunctionResponse({
171
+ tool,
172
+ id,
173
+ response
174
+ }) {
175
+ const image = isComputerUseTool(tool) ? response == null ? void 0 : response["image"] : void 0;
176
+ if (typeof image !== "object" || image === null || !("data" in image) || !("mimetype" in image) || typeof image.data !== "string" || typeof image.mimetype !== "string" || !BASE64.test(image.data)) {
177
+ return { id, name: tool.name, response };
195
178
  }
179
+ const rest = { ...response };
180
+ delete rest["image"];
181
+ return {
182
+ id,
183
+ name: tool.name,
184
+ response: rest,
185
+ parts: [{ inlineData: { data: image.data, mimeType: image.mimetype } }]
186
+ };
196
187
  }
197
- __name(getToolResponseErrorType, "getToolResponseErrorType");
188
+ __name(buildFunctionResponse, "buildFunctionResponse");
198
189
  function buildResponseEvent(tool, functionResult, toolContext, invocationContext) {
199
190
  let responseResult;
200
191
  if (typeof functionResult !== "object" || functionResult == null) {
@@ -205,11 +196,11 @@ function buildResponseEvent(tool, functionResult, toolContext, invocationContext
205
196
  responseResult = functionResult;
206
197
  }
207
198
  const partFunctionResponse = {
208
- functionResponse: {
209
- name: tool.name,
210
- response: responseResult,
211
- id: toolContext.functionCallId
212
- }
199
+ functionResponse: buildFunctionResponse({
200
+ tool,
201
+ id: toolContext.functionCallId,
202
+ response: responseResult
203
+ })
213
204
  };
214
205
  const content = {
215
206
  role: "user",
@@ -312,38 +303,35 @@ async function answerUnresolvableCall({
312
303
  toolsDict,
313
304
  toolContext
314
305
  }) {
315
- return tracer.startActiveSpan(
316
- `execute_tool ${functionCall.name || "<unnamed>"}`,
317
- async (span) => {
318
- var _a2, _b2;
319
- try {
320
- const toolName = functionCall.name || "<unnamed>";
321
- const error = new Error(
322
- `Function ${toolName} is not found in the toolsDict.`
323
- );
324
- const tool = new ToolNotFoundPlaceholder(toolName, error);
325
- const onToolErrorResponse = await invocationContext.pluginManager.runOnToolErrorCallback({
326
- tool,
327
- toolArgs: (_a2 = functionCall.args) != null ? _a2 : {},
328
- toolContext,
329
- error
330
- });
331
- if (onToolErrorResponse == null) {
332
- const callableTools = Object.keys(toolsDict);
333
- logger.warn(
334
- `Could not resolve tool '${toolName}' for function call '${(_b2 = functionCall.id) != null ? _b2 : ""}'. Callable tools: ${callableTools.length ? callableTools.join(", ") : "(none)"}.
306
+ var _a2;
307
+ const toolName = functionCall.name || "<unnamed>";
308
+ const error = new Error(
309
+ `Function ${toolName} is not found in the toolsDict.`
310
+ );
311
+ const tool = new ToolNotFoundPlaceholder(toolName, error);
312
+ return recordToolExecution(
313
+ { tool, args: (_a2 = functionCall.args) != null ? _a2 : {}, invocationContext },
314
+ async () => {
315
+ var _a3, _b2;
316
+ const onToolErrorResponse = await invocationContext.pluginManager.runOnToolErrorCallback({
317
+ tool,
318
+ toolArgs: (_a3 = functionCall.args) != null ? _a3 : {},
319
+ toolContext,
320
+ error
321
+ });
322
+ if (onToolErrorResponse == null) {
323
+ const callableTools = Object.keys(toolsDict);
324
+ logger.warn(
325
+ `Could not resolve tool '${toolName}' for function call '${(_b2 = functionCall.id) != null ? _b2 : ""}'. Callable tools: ${callableTools.length ? callableTools.join(", ") : "(none)"}.
335
326
  ` + RESOLUTION_FAILURE_CAUSES
336
- );
337
- }
338
- return buildResponseEvent(
339
- tool,
340
- onToolErrorResponse != null ? onToolErrorResponse : { error: error.message },
341
- toolContext,
342
- invocationContext
343
327
  );
344
- } finally {
345
- span.end();
346
328
  }
329
+ return buildResponseEvent(
330
+ tool,
331
+ onToolErrorResponse != null ? onToolErrorResponse : { error: error.message },
332
+ toolContext,
333
+ invocationContext
334
+ );
347
335
  }
348
336
  );
349
337
  }
@@ -484,11 +472,11 @@ async function handleFunctionCallList({
484
472
  invocationId: invocationContext.invocationId,
485
473
  author: toolEventAuthor(invocationContext),
486
474
  content: createUserContent({
487
- functionResponse: {
475
+ functionResponse: buildFunctionResponse({
476
+ tool,
488
477
  id: toolContext.functionCallId,
489
- name: tool.name,
490
478
  response: functionResponse
491
- }
479
+ })
492
480
  }),
493
481
  actions: toolContext.actions,
494
482
  branch: invocationContext.branch
@@ -502,18 +490,8 @@ async function handleFunctionCallList({
502
490
  functionResponseEvents
503
491
  );
504
492
  if (functionResponseEvents.length > 1) {
505
- tracer.startActiveSpan("execute_tool (merged)", (span) => {
506
- try {
507
- logger.debug("execute_tool (merged)");
508
- traceMergedToolCalls({
509
- responseEventId: mergedEvent.id,
510
- functionResponseEvent: mergedEvent,
511
- invocationContext
512
- });
513
- } finally {
514
- span.end();
515
- }
516
- });
493
+ logger.debug("execute_tool (merged)");
494
+ recordMergedToolCalls({ responseEventId: mergedEvent.id });
517
495
  }
518
496
  return mergedEvent;
519
497
  }
@@ -37,10 +37,13 @@ async function resolveKey(key, isOptional, rawMatch, readonlyContext) {
37
37
  }
38
38
  throw new Error(`Artifact ${fileName} not found.`);
39
39
  }
40
- return formatValue(asSafePartForLlm(artifact, fileName), true);
40
+ return formatValue(
41
+ asSafePartForLlm(artifact, fileName, { inlineMediaAsPlaceholder: true }),
42
+ true
43
+ );
41
44
  }
42
45
  if (isValidStateName(key)) {
43
- if (key in invocationContext.session.state) {
46
+ if (Object.hasOwn(invocationContext.session.state, key)) {
44
47
  return formatValue(invocationContext.session.state[key], false);
45
48
  }
46
49
  if (isOptional) {
@@ -162,14 +165,12 @@ async function injectSessionState(template, readonlyContext) {
162
165
  return result.join("");
163
166
  }
164
167
  __name(injectSessionState, "injectSessionState");
165
- const isIdentifierPattern = /* @__PURE__ */ (() => {
166
- return /^[a-zA-Z_][a-zA-Z0-9_]*$/;
167
- })();
168
+ const IDENTIFIER_PATTERN = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
168
169
  function isIdentifier(s) {
169
170
  if (s === "" || s === void 0) {
170
171
  return false;
171
172
  }
172
- return isIdentifierPattern.test(s);
173
+ return IDENTIFIER_PATTERN.test(s);
173
174
  }
174
175
  __name(isIdentifier, "isIdentifier");
175
176
  const VALID_PREFIXES = [State.APP_PREFIX, State.USER_PREFIX, State.TEMP_PREFIX];
@@ -8,7 +8,7 @@ var __name = (target, value) => __defProp(target, "name", { value, configurable:
8
8
  * SPDX-License-Identifier: Apache-2.0
9
9
  */
10
10
  var _a, _b;
11
- import { randomUUID } from "../utils/env_aware_utils.js";
11
+ import { newId } from "../utils/id_provider.js";
12
12
  const LLM_CALLS_LIMIT_EXCEEDED_ERROR_SIGNATURE_SYMBOL = /* @__PURE__ */ Symbol.for(
13
13
  "google.adk.llmCallsLimitExceededError"
14
14
  );
@@ -111,7 +111,7 @@ const _InvocationContext = class _InvocationContext {
111
111
  __name(_InvocationContext, "InvocationContext");
112
112
  let InvocationContext = _InvocationContext;
113
113
  function newInvocationContextId() {
114
- return `e-${randomUUID()}`;
114
+ return `e-${newId()}`;
115
115
  }
116
116
  __name(newInvocationContextId, "newInvocationContextId");
117
117
  function requireAgent(ctx) {
@@ -9,7 +9,6 @@ var __name = (target, value) => __defProp(target, "name", { value, configurable:
9
9
  */
10
10
  var _a, _b;
11
11
  import { Modality } from "@google/genai";
12
- import { context, trace } from "@opentelemetry/api";
13
12
  import { FinishTaskTool } from "../tools/finish_task_tool.js";
14
13
  import { FunctionTool } from "../tools/function_tool.js";
15
14
  import { AsyncQueue } from "../utils/async_queue.js";
@@ -26,7 +25,10 @@ import {
26
25
  isFinalResponse,
27
26
  populateClientFunctionCallId
28
27
  } from "../events/event.js";
29
- import { isDefaultEventActions } from "../events/event_actions.js";
28
+ import {
29
+ createEventActions,
30
+ isDefaultEventActions
31
+ } from "../events/event_actions.js";
30
32
  import { isBaseLlm } from "../models/base_llm.js";
31
33
  import { LLMRegistry } from "../models/registry.js";
32
34
  import { isBuiltInPlanner } from "../planners/built_in_planner.js";
@@ -36,11 +38,9 @@ import { logger } from "../utils/logger.js";
36
38
  import { canUseOutputSchemaWithTools } from "../utils/output_schema_utils.js";
37
39
  import { Context } from "./context.js";
38
40
  import {
39
- runAsyncGeneratorWithOtelContext,
40
- traceCallLlm,
41
- tracer,
42
- traceSendData
43
- } from "../telemetry/tracing.js";
41
+ recordInference,
42
+ recordSendData
43
+ } from "../telemetry/api/instrumentation.js";
44
44
  import { parseWithSchema } from "../utils/schema.js";
45
45
  import { isZodObject, zodObjectToSchema } from "../utils/simple_zod_to_json.js";
46
46
  import { BaseAgent } from "./base_agent.js";
@@ -103,6 +103,13 @@ function sleep(ms) {
103
103
  return new Promise((resolve) => setTimeout(resolve, ms));
104
104
  }
105
105
  __name(sleep, "sleep");
106
+ function hasSettledResponses(functionResponseEvent) {
107
+ const awaiting = functionResponseEvent.actions.requestedToolConfirmations;
108
+ return getFunctionResponses(functionResponseEvent).some(
109
+ (response) => !response.id || !Object.hasOwn(awaiting, response.id)
110
+ );
111
+ }
112
+ __name(hasSettledResponses, "hasSettledResponses");
106
113
  const LIVE_KEYS = [
107
114
  "responseModalities",
108
115
  "speechConfig",
@@ -128,14 +135,14 @@ function applyLiveRunConfig(runConfig, llmRequest) {
128
135
  }
129
136
  __name(applyLiveRunConfig, "applyLiveRunConfig");
130
137
  const ADK_AGENT_NAME_LABEL_KEY = "adk_agent_name";
131
- async function convertToolUnionToTools(toolUnion, context2) {
138
+ async function convertToolUnionToTools(toolUnion, context) {
132
139
  if (isBaseTool(toolUnion)) {
133
140
  return [toolUnion];
134
141
  }
135
142
  if (isBaseNode(toolUnion)) {
136
143
  return [new NodeTool(toolUnion)];
137
144
  }
138
- return await toolUnion.getTools(context2);
145
+ return await toolUnion.getTools(context);
139
146
  }
140
147
  __name(convertToolUnionToTools, "convertToolUnionToTools");
141
148
  const LLM_AGENT_SIGNATURE_SYMBOL = /* @__PURE__ */ Symbol.for("google.adk.llmAgent");
@@ -226,7 +233,7 @@ const _LlmAgent = class _LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNAT
226
233
  }
227
234
  if (config.generateContentConfig.responseSchema) {
228
235
  throw new Error(
229
- "Response schema must be set via LlmAgent.output_schema."
236
+ "Response schema must be set via LlmAgent.outputSchema."
230
237
  );
231
238
  }
232
239
  if (config.generateContentConfig.thinkingConfig && isBuiltInPlanner(this.planner) && this.planner.thinkingConfig) {
@@ -287,12 +294,12 @@ const _LlmAgent = class _LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNAT
287
294
  * @param context The context to retrieve the session state.
288
295
  * @returns The resolved instruction field.
289
296
  */
290
- async canonicalInstruction(context2) {
297
+ async canonicalInstruction(context) {
291
298
  if (typeof this.instruction === "string") {
292
299
  return { instruction: this.instruction, requireStateInjection: true };
293
300
  }
294
301
  return {
295
- instruction: await this.instruction(context2),
302
+ instruction: await this.instruction(context),
296
303
  requireStateInjection: false
297
304
  };
298
305
  }
@@ -304,7 +311,7 @@ const _LlmAgent = class _LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNAT
304
311
  * @returns The resolved globalInstruction field.
305
312
  * @deprecated Use GlobalInstructionPlugin instead.
306
313
  */
307
- async canonicalGlobalInstruction(context2) {
314
+ async canonicalGlobalInstruction(context) {
308
315
  if (typeof this.globalInstruction === "string") {
309
316
  return {
310
317
  instruction: this.globalInstruction,
@@ -312,7 +319,7 @@ const _LlmAgent = class _LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNAT
312
319
  };
313
320
  }
314
321
  return {
315
- instruction: await this.globalInstruction(context2),
322
+ instruction: await this.globalInstruction(context),
316
323
  requireStateInjection: false
317
324
  };
318
325
  }
@@ -321,10 +328,10 @@ const _LlmAgent = class _LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNAT
321
328
  *
322
329
  * This method is only for use by Agent Development Kit.
323
330
  */
324
- async canonicalTools(context2) {
331
+ async canonicalTools(context) {
325
332
  const resolvedTools = [];
326
333
  for (const toolUnion of this.tools) {
327
- const tools = await convertToolUnionToTools(toolUnion, context2);
334
+ const tools = await convertToolUnionToTools(toolUnion, context);
328
335
  resolvedTools.push(...tools);
329
336
  }
330
337
  return resolvedTools;
@@ -414,7 +421,15 @@ const _LlmAgent = class _LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNAT
414
421
  );
415
422
  return;
416
423
  }
417
- const resultStr = event.content.parts.map((part) => part.text ? part.text : "").join("");
424
+ if (!event.content.parts.some(
425
+ (part) => part.text !== void 0 && !part.thought
426
+ )) {
427
+ logger.debug(
428
+ `Skipping output save for agent ${this.name}: event has no text`
429
+ );
430
+ return;
431
+ }
432
+ const resultStr = event.content.parts.filter((part) => !part.thought).map((part) => part.text ? part.text : "").join("");
418
433
  let result = resultStr;
419
434
  if (this.outputSchema) {
420
435
  if (!resultStr.trim()) {
@@ -467,14 +482,14 @@ const _LlmAgent = class _LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNAT
467
482
  async *runImpl(ctx, nodeInput) {
468
483
  yield* runLlmAgentAsNode(this, ctx, nodeInput);
469
484
  }
470
- async *runAsyncImpl(context2) {
485
+ async *runAsyncImpl(context) {
471
486
  var _a2, _b2;
472
487
  while (true) {
473
488
  let lastEvent = void 0;
474
489
  let stepHadToolCalls = false;
475
490
  let stepTransferred = false;
476
- for await (const event of this.runOneStepAsync(context2)) {
477
- if ((_a2 = context2.abortSignal) == null ? void 0 : _a2.aborted) {
491
+ for await (const event of this.runOneStepAsync(context)) {
492
+ if ((_a2 = context.abortSignal) == null ? void 0 : _a2.aborted) {
478
493
  return;
479
494
  }
480
495
  lastEvent = event;
@@ -500,16 +515,16 @@ const _LlmAgent = class _LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNAT
500
515
  }
501
516
  }
502
517
  }
503
- async *runLiveImpl(context2) {
518
+ async *runLiveImpl(context) {
504
519
  var _a2;
505
- for await (const event of this.runLiveFlow(context2)) {
506
- if ((_a2 = context2.abortSignal) == null ? void 0 : _a2.aborted) {
520
+ for await (const event of this.runLiveFlow(context)) {
521
+ if ((_a2 = context.abortSignal) == null ? void 0 : _a2.aborted) {
507
522
  return;
508
523
  }
509
524
  this.maybeSaveOutputToState(event);
510
525
  yield event;
511
526
  }
512
- if (context2.endInvocation) {
527
+ if (context.endInvocation) {
513
528
  return;
514
529
  }
515
530
  }
@@ -586,18 +601,14 @@ const _LlmAgent = class _LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNAT
586
601
  throw err;
587
602
  }
588
603
  if (llmRequest.contents.length > 0 && !invocationContext.liveSessionResumptionHandle) {
589
- await tracer.startActiveSpan("send_data", async (span) => {
590
- try {
591
- await connection.sendHistory(llmRequest.contents);
592
- traceSendData({
593
- invocationContext,
594
- eventId: createNewEventId(),
595
- data: llmRequest.contents
596
- });
597
- } finally {
598
- span.end();
599
- }
600
- });
604
+ await recordSendData(
605
+ {
606
+ invocationContext,
607
+ eventId: createNewEventId(),
608
+ data: llmRequest.contents
609
+ },
610
+ () => connection.sendHistory(llmRequest.contents)
611
+ );
601
612
  }
602
613
  let sendError;
603
614
  const sendAbort = new AbortController();
@@ -975,57 +986,45 @@ const _LlmAgent = class _LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNAT
975
986
  if (invocationContext.endInvocation || ((_d = invocationContext.abortSignal) == null ? void 0 : _d.aborted)) {
976
987
  return;
977
988
  }
978
- const span = tracer.startSpan("call_llm");
979
- const ctx = trace.setSpan(context.active(), span);
980
- try {
981
- yield* runAsyncGeneratorWithOtelContext(
982
- ctx,
983
- this,
984
- async function* () {
985
- const responsesGenerator = /* @__PURE__ */ __name(async function* () {
986
- var _a3, _b3, _c2;
987
- for await (const llmResponse of this.callLlmAsync(
988
- invocationContext,
989
- llmRequest,
990
- modelResponseEvent
991
- )) {
992
- if ((_a3 = invocationContext.abortSignal) == null ? void 0 : _a3.aborted) {
993
- return;
994
- }
995
- if (((_b3 = invocationContext.runConfig) == null ? void 0 : _b3.supportCfc) && isEvent(llmResponse)) {
996
- modelResponseEvent.id = createNewEventId();
997
- modelResponseEvent.timestamp = (/* @__PURE__ */ new Date()).getTime();
998
- yield llmResponse;
999
- continue;
1000
- }
1001
- for await (const event of this.postprocess(
1002
- invocationContext,
1003
- llmRequest,
1004
- llmResponse,
1005
- modelResponseEvent
1006
- )) {
1007
- if ((_c2 = invocationContext.abortSignal) == null ? void 0 : _c2.aborted) {
1008
- return;
1009
- }
1010
- if (!event.partial) {
1011
- modelResponseEvent.id = createNewEventId();
1012
- modelResponseEvent.timestamp = (/* @__PURE__ */ new Date()).getTime();
1013
- }
1014
- yield event;
1015
- }
1016
- }
1017
- }, "responsesGenerator");
1018
- yield* this.runAndHandleError(
1019
- responsesGenerator.call(this),
1020
- invocationContext,
1021
- llmRequest,
1022
- modelResponseEvent
1023
- );
989
+ const responsesGenerator = /* @__PURE__ */ __name(async function* () {
990
+ var _a3, _b3, _c2;
991
+ for await (const llmResponse of this.callLlmAsync(
992
+ invocationContext,
993
+ llmRequest,
994
+ modelResponseEvent
995
+ )) {
996
+ if ((_a3 = invocationContext.abortSignal) == null ? void 0 : _a3.aborted) {
997
+ return;
1024
998
  }
1025
- );
1026
- } finally {
1027
- span.end();
1028
- }
999
+ if (((_b3 = invocationContext.runConfig) == null ? void 0 : _b3.supportCfc) && isEvent(llmResponse)) {
1000
+ modelResponseEvent.id = createNewEventId();
1001
+ modelResponseEvent.timestamp = (/* @__PURE__ */ new Date()).getTime();
1002
+ yield llmResponse;
1003
+ continue;
1004
+ }
1005
+ for await (const event of this.postprocess(
1006
+ invocationContext,
1007
+ llmRequest,
1008
+ llmResponse,
1009
+ modelResponseEvent
1010
+ )) {
1011
+ if ((_c2 = invocationContext.abortSignal) == null ? void 0 : _c2.aborted) {
1012
+ return;
1013
+ }
1014
+ if (!event.partial) {
1015
+ modelResponseEvent.id = createNewEventId();
1016
+ modelResponseEvent.timestamp = (/* @__PURE__ */ new Date()).getTime();
1017
+ }
1018
+ yield event;
1019
+ }
1020
+ }
1021
+ }, "responsesGenerator");
1022
+ yield* this.runAndHandleError(
1023
+ responsesGenerator.call(this),
1024
+ invocationContext,
1025
+ llmRequest,
1026
+ modelResponseEvent
1027
+ );
1029
1028
  }
1030
1029
  async *postprocess(invocationContext, llmRequest, llmResponse, modelResponseEvent) {
1031
1030
  var _a2, _b2, _c, _d, _e, _f;
@@ -1068,6 +1067,9 @@ const _LlmAgent = class _LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNAT
1068
1067
  if (!((_c = getFunctionCalls(mergedEvent)) == null ? void 0 : _c.length)) {
1069
1068
  return;
1070
1069
  }
1070
+ if (mergedEvent.partial) {
1071
+ return;
1072
+ }
1071
1073
  if ((_d = invocationContext.runConfig) == null ? void 0 : _d.pauseOnToolCalls) {
1072
1074
  invocationContext.endInvocation = true;
1073
1075
  return;
@@ -1114,6 +1116,15 @@ const _LlmAgent = class _LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNAT
1114
1116
  functionResponseEvent
1115
1117
  });
1116
1118
  if (toolConfirmationEvent) {
1119
+ if (hasSettledResponses(functionResponseEvent)) {
1120
+ const { requestedToolConfirmations, skipSummarization, ...settled } = functionResponseEvent.actions;
1121
+ functionResponseEvent.actions = createEventActions(settled);
1122
+ toolConfirmationEvent.actions = createEventActions({
1123
+ requestedToolConfirmations,
1124
+ skipSummarization
1125
+ });
1126
+ yield functionResponseEvent;
1127
+ }
1117
1128
  yield toolConfirmationEvent;
1118
1129
  invocationContext.endInvocation = true;
1119
1130
  return;
@@ -1151,7 +1162,7 @@ const _LlmAgent = class _LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNAT
1151
1162
  return agentToRun;
1152
1163
  }
1153
1164
  async *callLlmAsync(invocationContext, llmRequest, modelResponseEvent) {
1154
- var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j, _k;
1165
+ var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j;
1155
1166
  const beforeModelResponse = await this.handleBeforeModelCallback(
1156
1167
  invocationContext,
1157
1168
  llmRequest,
@@ -1199,20 +1210,20 @@ const _LlmAgent = class _LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNAT
1199
1210
  liveRequestQueue.close();
1200
1211
  }
1201
1212
  } else {
1202
- const responsesGenerator = llm.generateContentAsync(
1203
- llmRequest,
1204
- /* stream= */
1205
- ((_i = invocationContext.runConfig) == null ? void 0 : _i.streamingMode) === StreamingMode.SSE,
1206
- invocationContext.abortSignal
1213
+ const responsesGenerator = recordInference(
1214
+ { invocationContext, llmRequest, modelResponseEvent },
1215
+ () => {
1216
+ var _a3;
1217
+ return llm.generateContentAsync(
1218
+ llmRequest,
1219
+ /* stream= */
1220
+ ((_a3 = invocationContext.runConfig) == null ? void 0 : _a3.streamingMode) === StreamingMode.SSE,
1221
+ invocationContext.abortSignal
1222
+ );
1223
+ }
1207
1224
  );
1208
1225
  for await (const llmResponse of responsesGenerator) {
1209
- traceCallLlm({
1210
- invocationContext,
1211
- eventId: modelResponseEvent.id,
1212
- llmRequest,
1213
- llmResponse
1214
- });
1215
- if ((_j = invocationContext.abortSignal) == null ? void 0 : _j.aborted) {
1226
+ if ((_i = invocationContext.abortSignal) == null ? void 0 : _i.aborted) {
1216
1227
  return;
1217
1228
  }
1218
1229
  const alteredLlmResponse = await this.handleAfterModelCallback(
@@ -1220,7 +1231,7 @@ const _LlmAgent = class _LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNAT
1220
1231
  llmResponse,
1221
1232
  modelResponseEvent
1222
1233
  );
1223
- if ((_k = invocationContext.abortSignal) == null ? void 0 : _k.aborted) {
1234
+ if ((_j = invocationContext.abortSignal) == null ? void 0 : _j.aborted) {
1224
1235
  return;
1225
1236
  }
1226
1237
  yield alteredLlmResponse != null ? alteredLlmResponse : llmResponse;