@google/adk 2.3.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 (396) 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 +399 -0
  7. package/dist/cjs/agents/base_agent.js +127 -68
  8. package/dist/cjs/agents/functions.js +64 -59
  9. package/dist/cjs/agents/instructions.js +8 -6
  10. package/dist/cjs/agents/invocation_context.js +2 -2
  11. package/dist/cjs/agents/llm_agent.js +124 -101
  12. package/dist/cjs/agents/processors/basic_llm_request_processor.js +1 -1
  13. package/dist/cjs/agents/processors/code_execution_request_processor.js +8 -0
  14. package/dist/cjs/agents/processors/content_processor_utils.js +72 -17
  15. package/dist/cjs/agents/processors/content_request_processor.js +51 -2
  16. package/dist/cjs/agents/processors/context_compactor_request_processor.js +5 -1
  17. package/dist/cjs/agents/processors/instructions_llm_request_processor.js +1 -1
  18. package/dist/cjs/agents/processors/nl_planning_processor.js +13 -3
  19. package/dist/cjs/artifacts/file_artifact_service.js +1 -1
  20. package/dist/cjs/cli/cli_eval.js +884 -17
  21. package/dist/cjs/cli/utils/cleanup.js +84 -0
  22. package/dist/cjs/cli/utils/envs.js +33 -2
  23. package/dist/cjs/cli/utils/evals.js +75 -8
  24. package/dist/cjs/cli/utils/logs.js +134 -15
  25. package/dist/cjs/cli/utils/path_validation.js +83 -0
  26. package/dist/cjs/code_executors/container_code_executor.js +171 -38
  27. package/dist/cjs/code_executors/unsafe_local_code_executor.js +6 -1
  28. package/dist/cjs/common.js +59 -32
  29. package/dist/cjs/context/compaction_utils.js +19 -0
  30. package/dist/cjs/errors/input_validation_error.js +3 -2
  31. package/dist/cjs/events/event.js +7 -3
  32. package/dist/cjs/features/feature_registry.js +5 -0
  33. package/dist/cjs/index.js +34 -12
  34. package/dist/cjs/models/google_llm.js +33 -2
  35. package/dist/cjs/models/interactions_utils.js +3 -0
  36. package/dist/cjs/plugins/base_plugin.js +54 -40
  37. package/dist/cjs/plugins/plugin_manager.js +27 -0
  38. package/dist/cjs/runner/runner.js +306 -189
  39. package/dist/cjs/sessions/base_session_service.js +15 -12
  40. package/dist/cjs/sessions/database_session_service.js +232 -38
  41. package/dist/cjs/sessions/db/operations.js +70 -1
  42. package/dist/cjs/sessions/db/schema.js +4 -0
  43. package/dist/cjs/sessions/in_memory_session_service.js +2 -2
  44. package/dist/cjs/sessions/stale_session_error.js +59 -0
  45. package/dist/cjs/sessions/vertex_ai_session_service.js +11 -3
  46. package/dist/cjs/skills/loader.js +76 -41
  47. package/dist/cjs/telemetry/api/instrumentation.js +632 -0
  48. package/dist/cjs/telemetry/api/internal/common/accumulators.js +169 -0
  49. package/dist/cjs/telemetry/api/internal/common/attributes.js +131 -0
  50. package/dist/cjs/telemetry/api/internal/common/config.js +159 -0
  51. package/dist/cjs/telemetry/api/internal/common/error.js +98 -0
  52. package/dist/cjs/telemetry/api/internal/common/finish_reason.js +63 -0
  53. package/dist/cjs/telemetry/api/internal/common/genai_messages.js +217 -0
  54. package/dist/cjs/telemetry/api/internal/common/http_exchange.js +169 -0
  55. package/dist/cjs/telemetry/api/internal/common/provider_name.js +87 -0
  56. package/dist/cjs/telemetry/api/internal/common/redaction.js +148 -0
  57. package/dist/cjs/telemetry/api/internal/common/serialization.js +58 -0
  58. package/dist/cjs/telemetry/api/internal/common/token_usage.js +118 -0
  59. package/dist/cjs/telemetry/api/internal/logs/inference.js +50 -0
  60. package/dist/cjs/telemetry/api/internal/logs/logger.js +46 -0
  61. package/dist/cjs/telemetry/api/internal/logs/mcp.js +141 -0
  62. package/dist/cjs/telemetry/api/internal/metrics/agent.js +128 -0
  63. package/dist/cjs/telemetry/api/internal/metrics/inference_start_hook.js +56 -0
  64. package/dist/cjs/telemetry/api/internal/metrics/meters.js +189 -0
  65. package/dist/cjs/telemetry/api/internal/metrics/tool.js +147 -0
  66. package/dist/cjs/telemetry/api/internal/metrics/workflow.js +132 -0
  67. package/dist/cjs/telemetry/api/internal/trace/agent.js +52 -0
  68. package/dist/cjs/telemetry/api/internal/trace/compaction.js +78 -0
  69. package/dist/cjs/telemetry/api/internal/trace/inference.js +132 -0
  70. package/dist/cjs/telemetry/api/internal/trace/live.js +52 -0
  71. package/dist/cjs/telemetry/api/internal/trace/node.js +73 -0
  72. package/dist/cjs/telemetry/api/internal/trace/propagation.js +67 -0
  73. package/dist/cjs/telemetry/api/internal/trace/tool.js +122 -0
  74. package/dist/cjs/telemetry/api/internal/trace/tracer.js +77 -0
  75. package/dist/cjs/telemetry/api/internal/trace/workflow.js +77 -0
  76. package/dist/cjs/telemetry/export/agent_engine.js +90 -0
  77. package/dist/cjs/telemetry/export/agent_runtime.js +73 -0
  78. package/dist/cjs/telemetry/export/google_cloud.js +763 -0
  79. package/dist/cjs/telemetry/export/request_driven_metric_reader.js +303 -0
  80. package/dist/cjs/telemetry/{setup.js → export/setup.js} +72 -6
  81. package/dist/cjs/tools/agent_tool.js +9 -1
  82. package/dist/cjs/tools/apihub_tool/apihub_toolset.js +18 -23
  83. package/dist/cjs/tools/application_integration_tool/application_integration_toolset.js +109 -43
  84. package/dist/cjs/tools/application_integration_tool/clients/connections_client.js +222 -114
  85. package/dist/cjs/tools/application_integration_tool/clients/integration_client.js +34 -14
  86. package/dist/cjs/tools/application_integration_tool/integration_connector_tool.js +175 -0
  87. package/dist/cjs/tools/base_toolset.js +1 -1
  88. package/dist/cjs/tools/computer_use/base_computer.js +125 -0
  89. package/dist/cjs/tools/computer_use/computer_use_actions.js +502 -0
  90. package/dist/cjs/tools/computer_use/computer_use_tool.js +244 -0
  91. package/dist/cjs/tools/computer_use/computer_use_toolset.js +360 -0
  92. package/dist/cjs/tools/function_tool.js +15 -5
  93. package/dist/cjs/tools/google_api_tool/google_api_tool.js +4 -1
  94. package/dist/cjs/tools/google_api_tool/google_api_toolset.js +174 -0
  95. package/dist/cjs/tools/google_api_tool/google_api_toolsets.js +124 -0
  96. package/dist/cjs/tools/google_api_tool/googleapi_to_openapi_converter.js +5 -3
  97. package/dist/cjs/tools/google_api_tool/index.js +20 -23
  98. package/dist/cjs/tools/load_artifacts_tool.js +27 -11
  99. package/dist/cjs/tools/load_memory_tool.js +14 -15
  100. package/dist/cjs/tools/mcp/mcp_session_manager.js +23 -3
  101. package/dist/cjs/tools/mcp/mcp_tool.js +7 -3
  102. package/dist/cjs/tools/mcp/mcp_toolset.js +19 -20
  103. package/dist/cjs/tools/openapi_tool/auth/auth_helpers.js +30 -29
  104. package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/oauth2_exchanger.js +4 -4
  105. package/dist/cjs/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js +20 -6
  106. package/dist/cjs/tools/openapi_tool/openapi_spec_parser/operation_parser.js +17 -6
  107. package/dist/cjs/tools/openapi_tool/openapi_toolset.js +7 -13
  108. package/dist/cjs/tools/openapi_tool/rest_api_tool.js +57 -10
  109. package/dist/cjs/tools/skill/load_skill_resource_tool.js +7 -0
  110. package/dist/cjs/tools/skill/load_skill_tool.js +3 -0
  111. package/dist/cjs/tools/skill/run_skill_script_tool.js +12 -2
  112. package/dist/cjs/tools/toolbox_toolset.js +193 -0
  113. package/dist/cjs/tools/webmcp/webmcp_toolset.js +1 -14
  114. package/dist/cjs/utils/async_queue.js +37 -3
  115. package/dist/cjs/utils/client_labels.js +17 -2
  116. package/dist/cjs/utils/env_aware_utils.js +13 -7
  117. package/dist/cjs/utils/error_utils.js +40 -2
  118. package/dist/cjs/utils/failover_utils.js +11 -10
  119. package/dist/cjs/utils/gemini_schema_util.js +145 -14
  120. package/dist/cjs/utils/id_provider.js +63 -0
  121. package/dist/cjs/utils/logger_node.js +4 -0
  122. package/dist/cjs/utils/model_name.js +15 -0
  123. package/dist/cjs/utils/output_schema_utils.js +5 -2
  124. package/dist/cjs/utils/simple_zod_to_json.js +13 -31
  125. package/dist/cjs/utils/ssrf_guard.js +46 -16
  126. package/dist/cjs/utils/task.js +1 -1
  127. package/dist/cjs/version.js +1 -1
  128. package/dist/cjs/workflow/index.js +2 -0
  129. package/dist/cjs/workflow/node_runner.js +24 -80
  130. package/dist/cjs/workflow/nodes/parallel_worker.js +18 -7
  131. package/dist/cjs/workflow/run_llm_agent_as_node.js +19 -14
  132. package/dist/cjs/workflow/utils/retry_utils.js +2 -2
  133. package/dist/cjs/workflow/workflow.js +12 -12
  134. package/dist/esm/a2a/a2a_remote_agent.js +23 -3
  135. package/dist/esm/a2a/a2a_remote_agent_utils.js +8 -4
  136. package/dist/esm/a2a/agent_card.js +5 -83
  137. package/dist/esm/a2a/agent_to_a2a.js +7 -0
  138. package/dist/esm/a2a/event_converter_utils.js +10 -3
  139. package/dist/esm/agents/agent_engine_client.js +382 -0
  140. package/dist/esm/agents/base_agent.js +127 -72
  141. package/dist/esm/agents/functions.js +69 -63
  142. package/dist/esm/agents/instructions.js +8 -6
  143. package/dist/esm/agents/invocation_context.js +2 -2
  144. package/dist/esm/agents/llm_agent.js +130 -106
  145. package/dist/esm/agents/processors/basic_llm_request_processor.js +1 -1
  146. package/dist/esm/agents/processors/code_execution_request_processor.js +8 -0
  147. package/dist/esm/agents/processors/content_processor_utils.js +72 -17
  148. package/dist/esm/agents/processors/content_request_processor.js +51 -2
  149. package/dist/esm/agents/processors/context_compactor_request_processor.js +5 -1
  150. package/dist/esm/agents/processors/instructions_llm_request_processor.js +1 -1
  151. package/dist/esm/agents/processors/nl_planning_processor.js +13 -3
  152. package/dist/esm/artifacts/file_artifact_service.js +1 -1
  153. package/dist/esm/cli/cli_eval.js +880 -17
  154. package/dist/esm/cli/utils/cleanup.js +56 -0
  155. package/dist/esm/cli/utils/envs.js +33 -2
  156. package/dist/esm/cli/utils/evals.js +74 -8
  157. package/dist/esm/cli/utils/logs.js +132 -13
  158. package/dist/esm/cli/utils/path_validation.js +45 -0
  159. package/dist/esm/code_executors/container_code_executor.js +171 -38
  160. package/dist/esm/code_executors/unsafe_local_code_executor.js +6 -1
  161. package/dist/esm/common.js +59 -19
  162. package/dist/esm/context/compaction_utils.js +19 -0
  163. package/dist/esm/errors/input_validation_error.js +3 -2
  164. package/dist/esm/events/event.js +7 -3
  165. package/dist/esm/features/feature_registry.js +5 -0
  166. package/dist/esm/index.js +36 -10
  167. package/dist/esm/models/google_llm.js +33 -2
  168. package/dist/esm/models/interactions_utils.js +3 -0
  169. package/dist/esm/plugins/base_plugin.js +54 -40
  170. package/dist/esm/plugins/plugin_manager.js +27 -0
  171. package/dist/esm/runner/runner.js +310 -192
  172. package/dist/esm/sessions/base_session_service.js +13 -11
  173. package/dist/esm/sessions/database_session_service.js +231 -38
  174. package/dist/esm/sessions/db/operations.js +70 -1
  175. package/dist/esm/sessions/db/schema.js +4 -0
  176. package/dist/esm/sessions/in_memory_session_service.js +2 -2
  177. package/dist/esm/sessions/stale_session_error.js +31 -0
  178. package/dist/esm/sessions/vertex_ai_session_service.js +11 -3
  179. package/dist/esm/skills/loader.js +76 -41
  180. package/dist/esm/telemetry/api/instrumentation.js +655 -0
  181. package/dist/esm/telemetry/api/internal/common/accumulators.js +139 -0
  182. package/dist/esm/telemetry/api/internal/common/attributes.js +94 -0
  183. package/dist/esm/telemetry/api/internal/common/config.js +128 -0
  184. package/dist/esm/telemetry/api/internal/common/error.js +69 -0
  185. package/dist/esm/telemetry/api/internal/common/finish_reason.js +35 -0
  186. package/dist/esm/telemetry/api/internal/common/genai_messages.js +188 -0
  187. package/dist/esm/telemetry/api/internal/common/http_exchange.js +142 -0
  188. package/dist/esm/telemetry/api/internal/common/provider_name.js +59 -0
  189. package/dist/esm/telemetry/api/internal/common/redaction.js +121 -0
  190. package/dist/esm/telemetry/api/internal/common/serialization.js +30 -0
  191. package/dist/esm/telemetry/api/internal/common/token_usage.js +85 -0
  192. package/dist/esm/telemetry/api/internal/logs/inference.js +23 -0
  193. package/dist/esm/telemetry/api/internal/logs/logger.js +19 -0
  194. package/dist/esm/telemetry/api/internal/logs/mcp.js +113 -0
  195. package/dist/esm/telemetry/api/internal/metrics/agent.js +107 -0
  196. package/dist/esm/telemetry/api/internal/metrics/inference_start_hook.js +29 -0
  197. package/dist/esm/telemetry/api/internal/metrics/meters.js +165 -0
  198. package/dist/esm/telemetry/api/internal/metrics/tool.js +119 -0
  199. package/dist/esm/telemetry/api/internal/metrics/workflow.js +112 -0
  200. package/dist/esm/telemetry/api/internal/trace/agent.js +25 -0
  201. package/dist/esm/telemetry/api/internal/trace/compaction.js +50 -0
  202. package/dist/esm/telemetry/api/internal/trace/inference.js +107 -0
  203. package/dist/esm/telemetry/api/internal/trace/live.js +28 -0
  204. package/dist/esm/telemetry/api/internal/trace/node.js +44 -0
  205. package/dist/esm/telemetry/api/internal/trace/propagation.js +39 -0
  206. package/dist/esm/telemetry/api/internal/trace/tool.js +96 -0
  207. package/dist/esm/telemetry/api/internal/trace/tracer.js +52 -0
  208. package/dist/esm/telemetry/api/internal/trace/workflow.js +54 -0
  209. package/dist/esm/telemetry/export/agent_engine.js +67 -0
  210. package/dist/esm/telemetry/export/agent_runtime.js +46 -0
  211. package/dist/esm/telemetry/export/google_cloud.js +733 -0
  212. package/dist/esm/telemetry/export/request_driven_metric_reader.js +276 -0
  213. package/dist/esm/telemetry/export/setup.js +160 -0
  214. package/dist/esm/tools/agent_tool.js +9 -1
  215. package/dist/esm/tools/apihub_tool/apihub_toolset.js +17 -22
  216. package/dist/esm/tools/application_integration_tool/application_integration_toolset.js +114 -44
  217. package/dist/esm/tools/application_integration_tool/clients/connections_client.js +226 -115
  218. package/dist/esm/tools/application_integration_tool/clients/integration_client.js +34 -14
  219. package/dist/esm/tools/application_integration_tool/integration_connector_tool.js +149 -0
  220. package/dist/esm/tools/base_toolset.js +1 -1
  221. package/dist/esm/tools/computer_use/base_computer.js +99 -0
  222. package/dist/esm/tools/computer_use/computer_use_actions.js +477 -0
  223. package/dist/esm/tools/computer_use/computer_use_tool.js +217 -0
  224. package/dist/esm/tools/computer_use/computer_use_toolset.js +344 -0
  225. package/dist/esm/tools/function_tool.js +15 -5
  226. package/dist/esm/tools/google_api_tool/google_api_tool.js +4 -1
  227. package/dist/esm/tools/google_api_tool/google_api_toolset.js +147 -0
  228. package/dist/esm/tools/google_api_tool/google_api_toolsets.js +94 -0
  229. package/dist/esm/tools/google_api_tool/googleapi_to_openapi_converter.js +5 -3
  230. package/dist/esm/tools/google_api_tool/index.js +18 -20
  231. package/dist/esm/tools/load_artifacts_tool.js +25 -10
  232. package/dist/esm/tools/load_memory_tool.js +14 -15
  233. package/dist/esm/tools/mcp/mcp_session_manager.js +23 -3
  234. package/dist/esm/tools/mcp/mcp_tool.js +7 -3
  235. package/dist/esm/tools/mcp/mcp_toolset.js +19 -20
  236. package/dist/esm/tools/openapi_tool/auth/auth_helpers.js +27 -26
  237. package/dist/esm/tools/openapi_tool/auth/credential_exchangers/oauth2_exchanger.js +4 -4
  238. package/dist/esm/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js +20 -6
  239. package/dist/esm/tools/openapi_tool/openapi_spec_parser/operation_parser.js +17 -6
  240. package/dist/esm/tools/openapi_tool/openapi_toolset.js +6 -12
  241. package/dist/esm/tools/openapi_tool/rest_api_tool.js +57 -10
  242. package/dist/esm/tools/skill/load_skill_resource_tool.js +7 -0
  243. package/dist/esm/tools/skill/load_skill_tool.js +3 -0
  244. package/dist/esm/tools/skill/run_skill_script_tool.js +12 -2
  245. package/dist/esm/tools/toolbox_toolset.js +167 -0
  246. package/dist/esm/tools/webmcp/webmcp_toolset.js +1 -14
  247. package/dist/esm/utils/async_queue.js +37 -3
  248. package/dist/esm/utils/client_labels.js +17 -2
  249. package/dist/esm/utils/env_aware_utils.js +12 -7
  250. package/dist/esm/utils/error_utils.js +37 -1
  251. package/dist/esm/utils/failover_utils.js +11 -10
  252. package/dist/esm/utils/gemini_schema_util.js +144 -14
  253. package/dist/esm/utils/id_provider.js +33 -0
  254. package/dist/esm/utils/logger_node.js +4 -0
  255. package/dist/esm/utils/model_name.js +14 -0
  256. package/dist/esm/utils/output_schema_utils.js +5 -2
  257. package/dist/esm/utils/simple_zod_to_json.js +13 -31
  258. package/dist/esm/utils/ssrf_guard.js +55 -15
  259. package/dist/esm/utils/task.js +1 -1
  260. package/dist/esm/version.js +1 -1
  261. package/dist/esm/workflow/index.js +2 -1
  262. package/dist/esm/workflow/node_runner.js +26 -80
  263. package/dist/esm/workflow/nodes/parallel_worker.js +16 -6
  264. package/dist/esm/workflow/run_llm_agent_as_node.js +19 -14
  265. package/dist/esm/workflow/utils/retry_utils.js +2 -2
  266. package/dist/esm/workflow/workflow.js +12 -12
  267. package/dist/types/a2a/a2a_remote_agent.d.ts +6 -0
  268. package/dist/types/a2a/a2a_remote_agent_utils.d.ts +3 -2
  269. package/dist/types/agents/agent_engine_client.d.ts +155 -0
  270. package/dist/types/agents/base_agent.d.ts +14 -0
  271. package/dist/types/agents/llm_agent.d.ts +5 -1
  272. package/dist/types/agents/processors/content_processor_utils.d.ts +12 -10
  273. package/dist/types/agents/processors/nl_planning_processor.d.ts +2 -1
  274. package/dist/types/agents/run_config.d.ts +14 -0
  275. package/dist/types/cli/cli_eval.d.ts +172 -9
  276. package/dist/types/cli/utils/cleanup.d.ts +18 -0
  277. package/dist/types/cli/utils/envs.d.ts +13 -3
  278. package/dist/types/cli/utils/evals.d.ts +64 -1
  279. package/dist/types/cli/utils/logs.d.ts +20 -3
  280. package/dist/types/cli/utils/path_validation.d.ts +30 -0
  281. package/dist/types/code_executors/container_code_executor.d.ts +62 -9
  282. package/dist/types/common.d.ts +21 -18
  283. package/dist/types/context/compaction_utils.d.ts +13 -1
  284. package/dist/types/errors/input_validation_error.d.ts +2 -1
  285. package/dist/types/events/event.d.ts +3 -0
  286. package/dist/types/features/feature_registry.d.ts +1 -0
  287. package/dist/types/index.d.ts +11 -6
  288. package/dist/types/plugins/base_plugin.d.ts +50 -31
  289. package/dist/types/plugins/plugin_manager.d.ts +13 -0
  290. package/dist/types/runner/runner.d.ts +11 -0
  291. package/dist/types/sessions/base_session_service.d.ts +5 -2
  292. package/dist/types/sessions/database_session_service.d.ts +17 -1
  293. package/dist/types/sessions/db/operations.d.ts +2 -1
  294. package/dist/types/sessions/db/schema.d.ts +5 -3
  295. package/dist/types/sessions/stale_session_error.d.ts +21 -0
  296. package/dist/types/skills/loader.d.ts +3 -2
  297. package/dist/types/telemetry/api/instrumentation.d.ts +259 -0
  298. package/dist/types/telemetry/api/internal/common/accumulators.d.ts +91 -0
  299. package/dist/types/telemetry/api/internal/common/attributes.d.ts +90 -0
  300. package/dist/types/telemetry/api/internal/common/config.d.ts +61 -0
  301. package/dist/types/telemetry/api/internal/common/error.d.ts +29 -0
  302. package/dist/types/telemetry/api/internal/common/finish_reason.d.ts +18 -0
  303. package/dist/types/telemetry/api/internal/common/genai_messages.d.ts +26 -0
  304. package/dist/types/telemetry/api/internal/common/http_exchange.d.ts +50 -0
  305. package/dist/types/telemetry/api/internal/common/provider_name.d.ts +16 -0
  306. package/dist/types/telemetry/api/internal/common/redaction.d.ts +14 -0
  307. package/dist/types/telemetry/api/internal/common/serialization.d.ts +18 -0
  308. package/dist/types/telemetry/api/internal/common/token_usage.d.ts +47 -0
  309. package/dist/types/telemetry/api/internal/logs/inference.d.ts +15 -0
  310. package/dist/types/telemetry/api/internal/logs/logger.d.ts +13 -0
  311. package/dist/types/telemetry/api/internal/logs/mcp.d.ts +31 -0
  312. package/dist/types/telemetry/api/internal/metrics/agent.d.ts +28 -0
  313. package/dist/types/telemetry/api/internal/metrics/inference_start_hook.d.ts +12 -0
  314. package/dist/types/telemetry/api/internal/metrics/meters.d.ts +57 -0
  315. package/dist/types/telemetry/api/internal/metrics/tool.d.ts +44 -0
  316. package/dist/types/telemetry/api/internal/metrics/workflow.d.ts +32 -0
  317. package/dist/types/telemetry/api/internal/trace/agent.d.ts +14 -0
  318. package/dist/types/telemetry/api/internal/trace/compaction.d.ts +20 -0
  319. package/dist/types/telemetry/api/internal/trace/inference.d.ts +31 -0
  320. package/dist/types/telemetry/api/internal/trace/live.d.ts +21 -0
  321. package/dist/types/telemetry/api/internal/trace/node.d.ts +22 -0
  322. package/dist/types/telemetry/api/internal/trace/propagation.d.ts +22 -0
  323. package/dist/types/telemetry/api/internal/trace/tool.d.ts +57 -0
  324. package/dist/types/telemetry/api/internal/trace/tracer.d.ts +31 -0
  325. package/dist/types/telemetry/api/internal/trace/workflow.d.ts +21 -0
  326. package/dist/types/telemetry/export/agent_engine.d.ts +23 -0
  327. package/dist/types/telemetry/export/agent_runtime.d.ts +40 -0
  328. package/dist/types/telemetry/export/google_cloud.d.ts +189 -0
  329. package/dist/types/telemetry/export/request_driven_metric_reader.d.ts +144 -0
  330. package/dist/types/telemetry/{setup.d.ts → export/setup.d.ts} +3 -0
  331. package/dist/types/tools/agent_tool.d.ts +1 -1
  332. package/dist/types/tools/apihub_tool/apihub_toolset.d.ts +14 -21
  333. package/dist/types/tools/application_integration_tool/application_integration_toolset.d.ts +32 -9
  334. package/dist/types/tools/application_integration_tool/clients/connections_client.d.ts +35 -12
  335. package/dist/types/tools/application_integration_tool/clients/integration_client.d.ts +3 -3
  336. package/dist/types/tools/application_integration_tool/integration_connector_tool.d.ts +70 -0
  337. package/dist/types/tools/base_toolset.d.ts +7 -6
  338. package/dist/types/tools/computer_use/base_computer.d.ts +281 -0
  339. package/dist/types/tools/computer_use/computer_use_actions.d.ts +53 -0
  340. package/dist/types/tools/computer_use/computer_use_tool.d.ts +108 -0
  341. package/dist/types/tools/computer_use/computer_use_toolset.d.ts +132 -0
  342. package/dist/types/tools/google_api_tool/google_api_tool.d.ts +10 -3
  343. package/dist/types/tools/google_api_tool/google_api_toolset.d.ts +57 -0
  344. package/dist/types/tools/google_api_tool/google_api_toolsets.d.ts +48 -0
  345. package/dist/types/tools/google_api_tool/googleapi_to_openapi_converter.d.ts +5 -4
  346. package/dist/types/tools/google_api_tool/index.d.ts +4 -5
  347. package/dist/types/tools/load_artifacts_tool.d.ts +18 -1
  348. package/dist/types/tools/load_memory_tool.d.ts +32 -4
  349. package/dist/types/tools/mcp/mcp_session_manager.d.ts +16 -0
  350. package/dist/types/tools/openapi_tool/auth/auth_helpers.d.ts +8 -8
  351. package/dist/types/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.d.ts +12 -0
  352. package/dist/types/tools/openapi_tool/openapi_spec_parser/operation_parser.d.ts +15 -3
  353. package/dist/types/tools/openapi_tool/openapi_toolset.d.ts +5 -0
  354. package/dist/types/tools/openapi_tool/rest_api_tool.d.ts +10 -0
  355. package/dist/types/tools/toolbox_toolset.d.ts +154 -0
  356. package/dist/types/utils/async_queue.d.ts +14 -0
  357. package/dist/types/utils/client_labels.d.ts +2 -1
  358. package/dist/types/utils/env_aware_utils.d.ts +11 -0
  359. package/dist/types/utils/error_utils.d.ts +4 -0
  360. package/dist/types/utils/gemini_schema_util.d.ts +29 -0
  361. package/dist/types/utils/id_provider.d.ts +43 -0
  362. package/dist/types/utils/model_name.d.ts +8 -0
  363. package/dist/types/utils/output_schema_utils.d.ts +3 -2
  364. package/dist/types/utils/simple_zod_to_json.d.ts +1 -2
  365. package/dist/types/utils/ssrf_guard.d.ts +2 -0
  366. package/dist/types/version.d.ts +1 -1
  367. package/dist/types/workflow/index.d.ts +1 -1
  368. package/dist/types/workflow/nodes/parallel_worker.d.ts +8 -1
  369. package/dist/web/index_web.js +94 -88
  370. package/dist/web/index_web.js.map +4 -4
  371. package/package.json +43 -38
  372. package/dist/cjs/agents/remote_agent.js +0 -187
  373. package/dist/cjs/telemetry/google_cloud.js +0 -116
  374. package/dist/cjs/telemetry/tracing.js +0 -350
  375. package/dist/cjs/tools/crewai_tool.js +0 -132
  376. package/dist/cjs/tools/google_api_tool/google_api_tool_set.js +0 -226
  377. package/dist/cjs/tools/google_api_tool/google_api_tool_sets.js +0 -58
  378. package/dist/cjs/tools/langchain_tool.js +0 -172
  379. package/dist/cjs/tools/toolbox_tool.js +0 -108
  380. package/dist/esm/agents/remote_agent.js +0 -164
  381. package/dist/esm/telemetry/google_cloud.js +0 -99
  382. package/dist/esm/telemetry/setup.js +0 -89
  383. package/dist/esm/telemetry/tracing.js +0 -315
  384. package/dist/esm/tools/crewai_tool.js +0 -107
  385. package/dist/esm/tools/google_api_tool/google_api_tool_set.js +0 -188
  386. package/dist/esm/tools/google_api_tool/google_api_tool_sets.js +0 -24
  387. package/dist/esm/tools/langchain_tool.js +0 -148
  388. package/dist/esm/tools/toolbox_tool.js +0 -80
  389. package/dist/types/agents/remote_agent.d.ts +0 -68
  390. package/dist/types/telemetry/google_cloud.d.ts +0 -9
  391. package/dist/types/telemetry/tracing.d.ts +0 -129
  392. package/dist/types/tools/crewai_tool.d.ts +0 -85
  393. package/dist/types/tools/google_api_tool/google_api_tool_set.d.ts +0 -78
  394. package/dist/types/tools/google_api_tool/google_api_tool_sets.d.ts +0 -33
  395. package/dist/types/tools/langchain_tool.d.ts +0 -103
  396. package/dist/types/tools/toolbox_tool.d.ts +0 -73
@@ -30,9 +30,10 @@ __export(base_agent_exports, {
30
30
  isBaseAgent: () => isBaseAgent
31
31
  });
32
32
  module.exports = __toCommonJS(base_agent_exports);
33
- var import_api = require("@opentelemetry/api");
34
33
  var import_event = require("../events/event.js");
35
- var import_tracing = require("../telemetry/tracing.js");
34
+ var import_instrumentation = require("../telemetry/api/instrumentation.js");
35
+ var import_error_utils = require("../utils/error_utils.js");
36
+ var import_logger = require("../utils/logger.js");
36
37
  var import_base_node = require("../workflow/base_node.js");
37
38
  var import_context = require("./context.js");
38
39
  var import_invocation_context = require("./invocation_context.js");
@@ -122,38 +123,38 @@ const _BaseAgent = class _BaseAgent extends (_b = import_base_node.BaseNode, _a
122
123
  * @returns An AsyncGenerator that yields the events generated by the agent.
123
124
  */
124
125
  async *runAsync(parentContext) {
125
- const span = import_tracing.tracer.startSpan(`invoke_agent ${this.name}`);
126
- const ctx = import_api.trace.setSpan(import_api.context.active(), span);
127
- try {
128
- yield* (0, import_tracing.runAsyncGeneratorWithOtelContext)(
129
- ctx,
130
- this,
131
- async function* () {
132
- var _a2, _b2;
133
- const context2 = this.createInvocationContext(parentContext);
134
- const beforeAgentCallbackEvent = await this.handleBeforeAgentCallback(context2);
126
+ const agentCtx = this;
127
+ yield* (0, import_instrumentation.recordAgentInvocation)(
128
+ { agent: this, invocationContext: parentContext },
129
+ async function* () {
130
+ var _a2, _b2;
131
+ const context = agentCtx.createInvocationContext(parentContext);
132
+ try {
133
+ const beforeAgentCallbackEvent = await agentCtx.handleBeforeAgentCallback(context);
135
134
  if (beforeAgentCallbackEvent) {
136
135
  yield beforeAgentCallbackEvent;
137
136
  }
138
- if (context2.endInvocation || ((_a2 = parentContext.abortSignal) == null ? void 0 : _a2.aborted)) {
137
+ if (context.endInvocation || ((_a2 = parentContext.abortSignal) == null ? void 0 : _a2.aborted)) {
139
138
  return;
140
139
  }
141
- (0, import_tracing.traceAgentInvocation)({ agent: this, invocationContext: context2 });
142
- for await (const event of this.runAsyncImpl(context2)) {
140
+ for await (const event of agentCtx.runAsyncImpl(context)) {
143
141
  yield event;
144
142
  }
145
- if (context2.endInvocation || ((_b2 = parentContext.abortSignal) == null ? void 0 : _b2.aborted)) {
143
+ if (context.endInvocation || ((_b2 = parentContext.abortSignal) == null ? void 0 : _b2.aborted)) {
146
144
  return;
147
145
  }
148
- const afterAgentCallbackEvent = await this.handleAfterAgentCallback(context2);
146
+ const afterAgentCallbackEvent = await agentCtx.handleAfterAgentCallback(context);
149
147
  if (afterAgentCallbackEvent) {
150
148
  yield afterAgentCallbackEvent;
151
149
  }
150
+ } catch (error) {
151
+ if (!(0, import_error_utils.isInvocationCancellation)(error, context.abortSignal)) {
152
+ await agentCtx.handleAgentErrorCallback(context, error);
153
+ }
154
+ throw error;
152
155
  }
153
- );
154
- } finally {
155
- span.end();
156
- }
156
+ }
157
+ );
157
158
  }
158
159
  /**
159
160
  * Runs this agent as a workflow node.
@@ -188,36 +189,52 @@ const _BaseAgent = class _BaseAgent extends (_b = import_base_node.BaseNode, _a
188
189
  * @returns An AsyncGenerator that yields the events generated by the agent.
189
190
  */
190
191
  async *runLive(parentContext) {
191
- const span = import_tracing.tracer.startSpan(`invoke_agent ${this.name}`);
192
- const ctx = import_api.trace.setSpan(import_api.context.active(), span);
193
- try {
194
- yield* (0, import_tracing.runAsyncGeneratorWithOtelContext)(
195
- ctx,
196
- this,
197
- async function* () {
198
- var _a2, _b2;
199
- const context2 = this.createInvocationContext(parentContext);
200
- const beforeAgentCallbackEvent = await this.handleBeforeAgentCallback(context2);
192
+ const agentCtx = this;
193
+ yield* (0, import_instrumentation.recordAgentInvocation)(
194
+ { agent: this, invocationContext: parentContext },
195
+ async function* () {
196
+ var _a2, _b2;
197
+ const context = agentCtx.createInvocationContext(parentContext);
198
+ try {
199
+ const beforeAgentCallbackEvent = await agentCtx.handleBeforeAgentCallback(context);
201
200
  if (beforeAgentCallbackEvent) {
202
201
  yield beforeAgentCallbackEvent;
203
202
  }
204
- if (context2.endInvocation || ((_a2 = parentContext.abortSignal) == null ? void 0 : _a2.aborted)) {
203
+ if (context.endInvocation || ((_a2 = parentContext.abortSignal) == null ? void 0 : _a2.aborted)) {
205
204
  return;
206
205
  }
207
- for await (const event of this.runLiveImpl(context2)) {
206
+ for await (const event of agentCtx.runLiveImpl(context)) {
208
207
  yield event;
209
208
  }
210
- if (context2.endInvocation || ((_b2 = parentContext.abortSignal) == null ? void 0 : _b2.aborted)) {
209
+ if (context.endInvocation || ((_b2 = parentContext.abortSignal) == null ? void 0 : _b2.aborted)) {
211
210
  return;
212
211
  }
213
- const afterAgentCallbackEvent = await this.handleAfterAgentCallback(context2);
212
+ const afterAgentCallbackEvent = await agentCtx.handleAfterAgentCallback(context);
214
213
  if (afterAgentCallbackEvent) {
215
214
  yield afterAgentCallbackEvent;
216
215
  }
216
+ } catch (error) {
217
+ if (!(0, import_error_utils.isInvocationCancellation)(error, context.abortSignal)) {
218
+ await agentCtx.handleAgentErrorCallback(context, error);
219
+ }
220
+ throw error;
217
221
  }
222
+ }
223
+ );
224
+ }
225
+ /** Reports execution failures without replacing the original thrown value. */
226
+ async handleAgentErrorCallback(invocationContext, error) {
227
+ try {
228
+ await invocationContext.pluginManager.runOnAgentErrorCallback({
229
+ agent: this,
230
+ callbackContext: new import_context.Context({ invocationContext }),
231
+ error: (0, import_error_utils.toError)(error)
232
+ });
233
+ } catch (callbackError) {
234
+ import_logger.logger.error(
235
+ "Agent error notification failed; preserving the original error.",
236
+ callbackError
218
237
  );
219
- } finally {
220
- span.end();
221
238
  }
222
239
  }
223
240
  /**
@@ -259,6 +276,22 @@ const _BaseAgent = class _BaseAgent extends (_b = import_base_node.BaseNode, _a
259
276
  agent: this
260
277
  });
261
278
  }
279
+ /**
280
+ * The resolved beforeAgentCallback field as a list of SingleAgentCallback.
281
+ *
282
+ * This method is only for use by Agent Development Kit.
283
+ */
284
+ get canonicalBeforeAgentCallbacks() {
285
+ return this.beforeAgentCallback;
286
+ }
287
+ /**
288
+ * The resolved afterAgentCallback field as a list of SingleAgentCallback.
289
+ *
290
+ * This method is only for use by Agent Development Kit.
291
+ */
292
+ get canonicalAfterAgentCallbacks() {
293
+ return this.afterAgentCallback;
294
+ }
262
295
  /**
263
296
  * Runs the before agent callback if it exists.
264
297
  *
@@ -267,27 +300,40 @@ const _BaseAgent = class _BaseAgent extends (_b = import_base_node.BaseNode, _a
267
300
  * generated.
268
301
  */
269
302
  async handleBeforeAgentCallback(invocationContext) {
270
- var _a2;
271
- if (this.beforeAgentCallback.length === 0) {
303
+ var _a2, _b2, _c;
304
+ const hasPlugins = Boolean((_a2 = invocationContext.pluginManager) == null ? void 0 : _a2.hasPlugins);
305
+ if (!hasPlugins && this.canonicalBeforeAgentCallbacks.length === 0) {
272
306
  return void 0;
273
307
  }
274
308
  const callbackContext = new import_context.Context({ invocationContext });
275
- for (const callback of this.beforeAgentCallback) {
276
- const content = await callback(callbackContext);
277
- if ((_a2 = invocationContext.abortSignal) == null ? void 0 : _a2.aborted) {
278
- return;
279
- }
280
- if (content) {
281
- invocationContext.endInvocation = true;
282
- return (0, import_event.createEvent)({
283
- invocationId: invocationContext.invocationId,
284
- author: this.name,
285
- branch: invocationContext.branch,
286
- content,
287
- actions: callbackContext.eventActions
288
- });
309
+ let content = hasPlugins ? await invocationContext.pluginManager.runBeforeAgentCallback({
310
+ agent: this,
311
+ callbackContext
312
+ }) : void 0;
313
+ if ((_b2 = invocationContext.abortSignal) == null ? void 0 : _b2.aborted) {
314
+ return;
315
+ }
316
+ if (!content) {
317
+ for (const callback of this.canonicalBeforeAgentCallbacks) {
318
+ content = await callback(callbackContext);
319
+ if ((_c = invocationContext.abortSignal) == null ? void 0 : _c.aborted) {
320
+ return;
321
+ }
322
+ if (content) {
323
+ break;
324
+ }
289
325
  }
290
326
  }
327
+ if (content) {
328
+ invocationContext.endInvocation = true;
329
+ return (0, import_event.createEvent)({
330
+ invocationId: invocationContext.invocationId,
331
+ author: this.name,
332
+ branch: invocationContext.branch,
333
+ content,
334
+ actions: callbackContext.eventActions
335
+ });
336
+ }
291
337
  if (callbackContext.state.hasDelta()) {
292
338
  return (0, import_event.createEvent)({
293
339
  invocationId: invocationContext.invocationId,
@@ -306,26 +352,39 @@ const _BaseAgent = class _BaseAgent extends (_b = import_base_node.BaseNode, _a
306
352
  * generated.
307
353
  */
308
354
  async handleAfterAgentCallback(invocationContext) {
309
- var _a2;
310
- if (this.afterAgentCallback.length === 0) {
355
+ var _a2, _b2, _c;
356
+ const hasPlugins = Boolean((_a2 = invocationContext.pluginManager) == null ? void 0 : _a2.hasPlugins);
357
+ if (!hasPlugins && this.canonicalAfterAgentCallbacks.length === 0) {
311
358
  return void 0;
312
359
  }
313
360
  const callbackContext = new import_context.Context({ invocationContext });
314
- for (const callback of this.afterAgentCallback) {
315
- const content = await callback(callbackContext);
316
- if ((_a2 = invocationContext.abortSignal) == null ? void 0 : _a2.aborted) {
317
- return;
318
- }
319
- if (content) {
320
- return (0, import_event.createEvent)({
321
- invocationId: invocationContext.invocationId,
322
- author: this.name,
323
- branch: invocationContext.branch,
324
- content,
325
- actions: callbackContext.eventActions
326
- });
361
+ let content = hasPlugins ? await invocationContext.pluginManager.runAfterAgentCallback({
362
+ agent: this,
363
+ callbackContext
364
+ }) : void 0;
365
+ if ((_b2 = invocationContext.abortSignal) == null ? void 0 : _b2.aborted) {
366
+ return;
367
+ }
368
+ if (!content) {
369
+ for (const callback of this.canonicalAfterAgentCallbacks) {
370
+ content = await callback(callbackContext);
371
+ if ((_c = invocationContext.abortSignal) == null ? void 0 : _c.aborted) {
372
+ return;
373
+ }
374
+ if (content) {
375
+ break;
376
+ }
327
377
  }
328
378
  }
379
+ if (content) {
380
+ return (0, import_event.createEvent)({
381
+ invocationId: invocationContext.invocationId,
382
+ author: this.name,
383
+ branch: invocationContext.branch,
384
+ content,
385
+ actions: callbackContext.eventActions
386
+ });
387
+ }
329
388
  if (callbackContext.state.hasDelta()) {
330
389
  return (0, import_event.createEvent)({
331
390
  invocationId: invocationContext.invocationId,
@@ -51,13 +51,14 @@ var import_lodash_es = require("lodash-es");
51
51
  var import_event = require("../events/event.js");
52
52
  var import_event_actions = require("../events/event_actions.js");
53
53
  var import_base_tool = require("../tools/base_tool.js");
54
+ var import_computer_use_tool = require("../tools/computer_use/computer_use_tool.js");
54
55
  var import_function_tool = require("../tools/function_tool.js");
55
56
  var import_logger = require("../utils/logger.js");
56
57
  var import_task = require("../utils/task.js");
57
58
  var import_active_streaming_tool = require("./active_streaming_tool.js");
58
59
  var import_context = require("./context.js");
59
60
  var import_framework_function_calls = require("./framework_function_calls.js");
60
- var import_tracing = require("../telemetry/tracing.js");
61
+ var import_instrumentation = require("../telemetry/api/instrumentation.js");
61
62
  var import_event2 = require("../events/event.js");
62
63
  var import_framework_function_calls2 = require("./framework_function_calls.js");
63
64
  /**
@@ -165,28 +166,45 @@ function generateRequestConfirmationEvent({
165
166
  }
166
167
  __name(generateRequestConfirmationEvent, "generateRequestConfirmationEvent");
167
168
  async function callToolAsync(tool, args, toolContext) {
168
- return import_tracing.tracer.startActiveSpan(`execute_tool ${tool.name}`, async (span) => {
169
- try {
169
+ return (0, import_instrumentation.recordToolExecution)(
170
+ { tool, args, invocationContext: toolContext.invocationContext },
171
+ async (scope) => {
170
172
  import_logger.logger.debug(`callToolAsync ${tool.name}`);
171
173
  const result = await tool.runAsync({ args, toolContext });
172
- (0, import_tracing.traceToolCall)({
173
- tool,
174
- args,
174
+ scope.recordSuccess({
175
175
  functionResponseEvent: buildResponseEvent(
176
176
  tool,
177
177
  result,
178
178
  toolContext,
179
179
  toolContext.invocationContext
180
180
  ),
181
- invocationContext: toolContext.invocationContext
181
+ rawResult: result
182
182
  });
183
183
  return result;
184
- } finally {
185
- span.end();
186
184
  }
187
- });
185
+ );
188
186
  }
189
187
  __name(callToolAsync, "callToolAsync");
188
+ const BASE64 = /^[A-Za-z0-9+/]*={0,2}$/;
189
+ function buildFunctionResponse({
190
+ tool,
191
+ id,
192
+ response
193
+ }) {
194
+ const image = (0, import_computer_use_tool.isComputerUseTool)(tool) ? response == null ? void 0 : response["image"] : void 0;
195
+ if (typeof image !== "object" || image === null || !("data" in image) || !("mimetype" in image) || typeof image.data !== "string" || typeof image.mimetype !== "string" || !BASE64.test(image.data)) {
196
+ return { id, name: tool.name, response };
197
+ }
198
+ const rest = { ...response };
199
+ delete rest["image"];
200
+ return {
201
+ id,
202
+ name: tool.name,
203
+ response: rest,
204
+ parts: [{ inlineData: { data: image.data, mimeType: image.mimetype } }]
205
+ };
206
+ }
207
+ __name(buildFunctionResponse, "buildFunctionResponse");
190
208
  function buildResponseEvent(tool, functionResult, toolContext, invocationContext) {
191
209
  let responseResult;
192
210
  if (typeof functionResult !== "object" || functionResult == null) {
@@ -197,11 +215,11 @@ function buildResponseEvent(tool, functionResult, toolContext, invocationContext
197
215
  responseResult = functionResult;
198
216
  }
199
217
  const partFunctionResponse = {
200
- functionResponse: {
201
- name: tool.name,
202
- response: responseResult,
203
- id: toolContext.functionCallId
204
- }
218
+ functionResponse: buildFunctionResponse({
219
+ tool,
220
+ id: toolContext.functionCallId,
221
+ response: responseResult
222
+ })
205
223
  };
206
224
  const content = {
207
225
  role: "user",
@@ -304,38 +322,35 @@ async function answerUnresolvableCall({
304
322
  toolsDict,
305
323
  toolContext
306
324
  }) {
307
- return import_tracing.tracer.startActiveSpan(
308
- `execute_tool ${functionCall.name || "<unnamed>"}`,
309
- async (span) => {
310
- var _a2, _b2;
311
- try {
312
- const toolName = functionCall.name || "<unnamed>";
313
- const error = new Error(
314
- `Function ${toolName} is not found in the toolsDict.`
315
- );
316
- const tool = new ToolNotFoundPlaceholder(toolName, error);
317
- const onToolErrorResponse = await invocationContext.pluginManager.runOnToolErrorCallback({
318
- tool,
319
- toolArgs: (_a2 = functionCall.args) != null ? _a2 : {},
320
- toolContext,
321
- error
322
- });
323
- if (onToolErrorResponse == null) {
324
- const callableTools = Object.keys(toolsDict);
325
- import_logger.logger.warn(
326
- `Could not resolve tool '${toolName}' for function call '${(_b2 = functionCall.id) != null ? _b2 : ""}'. Callable tools: ${callableTools.length ? callableTools.join(", ") : "(none)"}.
325
+ var _a2;
326
+ const toolName = functionCall.name || "<unnamed>";
327
+ const error = new Error(
328
+ `Function ${toolName} is not found in the toolsDict.`
329
+ );
330
+ const tool = new ToolNotFoundPlaceholder(toolName, error);
331
+ return (0, import_instrumentation.recordToolExecution)(
332
+ { tool, args: (_a2 = functionCall.args) != null ? _a2 : {}, invocationContext },
333
+ async () => {
334
+ var _a3, _b2;
335
+ const onToolErrorResponse = await invocationContext.pluginManager.runOnToolErrorCallback({
336
+ tool,
337
+ toolArgs: (_a3 = functionCall.args) != null ? _a3 : {},
338
+ toolContext,
339
+ error
340
+ });
341
+ if (onToolErrorResponse == null) {
342
+ const callableTools = Object.keys(toolsDict);
343
+ import_logger.logger.warn(
344
+ `Could not resolve tool '${toolName}' for function call '${(_b2 = functionCall.id) != null ? _b2 : ""}'. Callable tools: ${callableTools.length ? callableTools.join(", ") : "(none)"}.
327
345
  ` + RESOLUTION_FAILURE_CAUSES
328
- );
329
- }
330
- return buildResponseEvent(
331
- tool,
332
- onToolErrorResponse != null ? onToolErrorResponse : { error: error.message },
333
- toolContext,
334
- invocationContext
335
346
  );
336
- } finally {
337
- span.end();
338
347
  }
348
+ return buildResponseEvent(
349
+ tool,
350
+ onToolErrorResponse != null ? onToolErrorResponse : { error: error.message },
351
+ toolContext,
352
+ invocationContext
353
+ );
339
354
  }
340
355
  );
341
356
  }
@@ -476,11 +491,11 @@ async function handleFunctionCallList({
476
491
  invocationId: invocationContext.invocationId,
477
492
  author: toolEventAuthor(invocationContext),
478
493
  content: (0, import_genai.createUserContent)({
479
- functionResponse: {
494
+ functionResponse: buildFunctionResponse({
495
+ tool,
480
496
  id: toolContext.functionCallId,
481
- name: tool.name,
482
497
  response: functionResponse
483
- }
498
+ })
484
499
  }),
485
500
  actions: toolContext.actions,
486
501
  branch: invocationContext.branch
@@ -494,18 +509,8 @@ async function handleFunctionCallList({
494
509
  functionResponseEvents
495
510
  );
496
511
  if (functionResponseEvents.length > 1) {
497
- import_tracing.tracer.startActiveSpan("execute_tool (merged)", (span) => {
498
- try {
499
- import_logger.logger.debug("execute_tool (merged)");
500
- (0, import_tracing.traceMergedToolCalls)({
501
- responseEventId: mergedEvent.id,
502
- functionResponseEvent: mergedEvent,
503
- invocationContext
504
- });
505
- } finally {
506
- span.end();
507
- }
508
- });
512
+ import_logger.logger.debug("execute_tool (merged)");
513
+ (0, import_instrumentation.recordMergedToolCalls)({ responseEventId: mergedEvent.id });
509
514
  }
510
515
  return mergedEvent;
511
516
  }
@@ -29,6 +29,7 @@ __export(instructions_exports, {
29
29
  });
30
30
  module.exports = __toCommonJS(instructions_exports);
31
31
  var import_state = require("../sessions/state.js");
32
+ var import_load_artifacts_tool = require("../tools/load_artifacts_tool.js");
32
33
  /**
33
34
  * @license
34
35
  * Copyright 2025 Google LLC
@@ -62,10 +63,13 @@ async function resolveKey(key, isOptional, rawMatch, readonlyContext) {
62
63
  }
63
64
  throw new Error(`Artifact ${fileName} not found.`);
64
65
  }
65
- return formatValue(artifact, true);
66
+ return formatValue(
67
+ (0, import_load_artifacts_tool.asSafePartForLlm)(artifact, fileName, { inlineMediaAsPlaceholder: true }),
68
+ true
69
+ );
66
70
  }
67
71
  if (isValidStateName(key)) {
68
- if (key in invocationContext.session.state) {
72
+ if (Object.hasOwn(invocationContext.session.state, key)) {
69
73
  return formatValue(invocationContext.session.state[key], false);
70
74
  }
71
75
  if (isOptional) {
@@ -187,14 +191,12 @@ async function injectSessionState(template, readonlyContext) {
187
191
  return result.join("");
188
192
  }
189
193
  __name(injectSessionState, "injectSessionState");
190
- const isIdentifierPattern = /* @__PURE__ */ (() => {
191
- return /^[a-zA-Z_][a-zA-Z0-9_]*$/;
192
- })();
194
+ const IDENTIFIER_PATTERN = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
193
195
  function isIdentifier(s) {
194
196
  if (s === "" || s === void 0) {
195
197
  return false;
196
198
  }
197
- return isIdentifierPattern.test(s);
199
+ return IDENTIFIER_PATTERN.test(s);
198
200
  }
199
201
  __name(isIdentifier, "isIdentifier");
200
202
  const VALID_PREFIXES = [import_state.State.APP_PREFIX, import_state.State.USER_PREFIX, import_state.State.TEMP_PREFIX];
@@ -32,7 +32,7 @@ __export(invocation_context_exports, {
32
32
  requireAgent: () => requireAgent
33
33
  });
34
34
  module.exports = __toCommonJS(invocation_context_exports);
35
- var import_env_aware_utils = require("../utils/env_aware_utils.js");
35
+ var import_id_provider = require("../utils/id_provider.js");
36
36
  /**
37
37
  * @license
38
38
  * Copyright 2025 Google LLC
@@ -141,7 +141,7 @@ const _InvocationContext = class _InvocationContext {
141
141
  __name(_InvocationContext, "InvocationContext");
142
142
  let InvocationContext = _InvocationContext;
143
143
  function newInvocationContextId() {
144
- return `e-${(0, import_env_aware_utils.randomUUID)()}`;
144
+ return `e-${(0, import_id_provider.newId)()}`;
145
145
  }
146
146
  __name(newInvocationContextId, "newInvocationContextId");
147
147
  function requireAgent(ctx) {