@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
@@ -21,7 +21,7 @@ export type { VertexAiMemoryBankServiceOptions } from './memory/vertex_ai_memory
21
21
  export { VertexAiRagMemoryService } from './memory/vertex_ai_rag_memory_service.js';
22
22
  export type { VertexAiRagMemoryServiceOptions } from './memory/vertex_ai_rag_memory_service.js';
23
23
  export { DebugLoggingPlugin, isDebugLoggingPlugin, } from './plugins/debug_logging_plugin.js';
24
- export { DatabaseSessionService, isStaleSessionError, StaleSessionError, } from './sessions/database_session_service.js';
24
+ export { DatabaseSessionService } from './sessions/database_session_service.js';
25
25
  export type { DatabaseSessionServiceOptions } from './sessions/database_session_service.js';
26
26
  export { getSessionServiceFromUri } from './sessions/registry.js';
27
27
  export { VertexAiSessionService } from './sessions/vertex_ai_session_service.js';
@@ -38,7 +38,7 @@ export { IntegrationClient, type IntegrationClientOptions, } from './tools/appli
38
38
  export { IntegrationConnectorTool, type IntegrationConnectorToolOptions, } from './tools/application_integration_tool/integration_connector_tool.js';
39
39
  export { LOAD_WEB_PAGE, loadWebPage } from './tools/load_web_page.js';
40
40
  export type { LoadWebPageOptions } from './tools/load_web_page.js';
41
- export { credentialToParam, dictToAuthScheme, INTERNAL_AUTH_PREFIX, openidDictToSchemeCredential, openidUrlToSchemeCredential, serviceAccountDictToSchemeCredential, serviceAccountSchemeCredential, tokenToSchemeCredential, } from './tools/openapi_tool/auth/auth_helpers.js';
41
+ export { credentialToParam, INTERNAL_AUTH_PREFIX, openidRecordToSchemeCredential, openidUrlToSchemeCredential, recordToAuthScheme, serviceAccountRecordToSchemeCredential, serviceAccountSchemeCredential, tokenToSchemeCredential, } from './tools/openapi_tool/auth/auth_helpers.js';
42
42
  export type { OpenIdConfig } from './tools/openapi_tool/auth/auth_helpers.js';
43
43
  export { AutoAuthCredentialExchanger } from './tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js';
44
44
  export type { CustomCredentialExchangers } from './tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js';
@@ -64,12 +64,15 @@ export { RunSkillScriptTool } from './tools/skill/run_skill_script_tool.js';
64
64
  export { SkillToolset } from './tools/skill/skill_toolset.js';
65
65
  export type { JsonObject } from './utils/json_utils.js';
66
66
  export * from './integrations/agent_registry/agent_registry.js';
67
- export * from './telemetry/google_cloud.js';
68
- export * from './telemetry/setup.js';
67
+ export { runWithAgentEngineContext } from './telemetry/export/agent_engine.js';
68
+ export { agentRuntimeRequestHooks, type AgentRuntimeRequestHooks, } from './telemetry/export/agent_runtime.js';
69
+ export * from './telemetry/export/google_cloud.js';
70
+ export * from './telemetry/export/setup.js';
69
71
  export * from './tools/google_api_tool/index.js';
70
- export { DEFAULT_CRITERIA, EVAL_SESSION_ID_PREFIX, EvalStatus, getEvaluationCriteriaOrDefault, getRootAgent, MISSING_EVAL_DEPENDENCIES_MESSAGE, parseAndGetEvalsToRun, RESPONSE_EVALUATION_SCORE_KEY, RESPONSE_MATCH_SCORE_KEY, runEvals, TOOL_TRAJECTORY_SCORE_KEY, tryGetResetFunc, } from './cli/cli_eval.js';
71
- export type { AddSessionToEvalSetRequest, EvalEntry, EvalInitialSession, EvalMetric, EvalMetricResult, EvalResult, EvalSetItem, InvocationEvalMetricResult, RunEvalRequest, RunEvalResult, RunEvalsOptions, } from './cli/cli_eval.js';
72
+ export { convertEvalSetToSchema, DEFAULT_CRITERIA, EVAL_SESSION_ID_PREFIX, EvalStatus, getEvaluationCriteriaOrDefault, getRootAgent, loadEvalSetFromFile, LocalEvalSetResultsManager, LocalEvalSetsManager, MISSING_EVAL_DEPENDENCIES_MESSAGE, normalizeEvalCase, parseAndGetEvalsToRun, RESPONSE_EVALUATION_SCORE_KEY, RESPONSE_MATCH_SCORE_KEY, runEvals, TOOL_TRAJECTORY_SCORE_KEY, tryGetResetFunc, } from './cli/cli_eval.js';
73
+ export type { AddSessionToEvalSetRequest, EvalCaseResult, EvalEntry, EvalInitialSession, EvalMetric, EvalMetricResult, EvalResult, EvalSetItem, EvalSetResult, InvocationEvalMetricResult, RunEvalRequest, RunEvalResult, RunEvalsOptions, SaveEvalSetResultParams, } from './cli/cli_eval.js';
72
74
  export { loadDotenvForAgent, walkToRootUntilFound } from './cli/utils/envs.js';
73
75
  export { LOGGING_FORMAT, logToTmpFolder, setupAdkLogger, } from './cli/utils/logs.js';
74
76
  export type { LogToTmpFolderOptions } from './cli/utils/logs.js';
77
+ export { validatePathSegment } from './cli/utils/path_validation.js';
75
78
  export * from './tools/mcp/index.js';
@@ -139,9 +139,9 @@ export declare abstract class BasePlugin {
139
139
  *
140
140
  * @param _params.invocationContext The context for the entire invocation, containing
141
141
  * session information, the root agent, etc.
142
- * @returns An optional `Event` to be returned to the ADK. Returning a value
143
- * to halt execution of the runner and ends the runner with that event.
144
- * Return `undefined` to proceed normally.
142
+ * @returns An optional `Content` to be returned to the ADK. Returning a value
143
+ * halts execution of the runner and ends the run with an event containing
144
+ * that content. Return `undefined` to proceed normally.
145
145
  */
146
146
  beforeRunCallback(_params: {
147
147
  invocationContext: InvocationContext;
@@ -165,10 +165,12 @@ export declare abstract class BasePlugin {
165
165
  event: Event;
166
166
  }): Promise<Event | undefined>;
167
167
  /**
168
- * Callback executed after an ADK runner run has completed.
168
+ * Callback executed after successful completion, abort, or early iterator close.
169
169
  *
170
170
  * This is the final callback in the ADK lifecycle, suitable for cleanup,
171
- * final logging, or reporting tasks.
171
+ * final logging, or reporting tasks. It is skipped when execution fails;
172
+ * {@link onRunErrorCallback} is called instead. Receiving this callback does
173
+ * not imply success: recognized cancellation still propagates to the caller.
172
174
  *
173
175
  * @param _params.invocationContext The context for the entire invocation.
174
176
  * @returns undefined
@@ -176,6 +178,28 @@ export declare abstract class BasePlugin {
176
178
  afterRunCallback(_params: {
177
179
  invocationContext: InvocationContext;
178
180
  }): Promise<void>;
181
+ /**
182
+ * Observes an error escaping an agent's execution or lifecycle callbacks.
183
+ *
184
+ * Notification-only: return values are ignored and callback failures are
185
+ * logged. The original execution error always propagates.
186
+ */
187
+ onAgentErrorCallback(_params: {
188
+ agent: BaseAgent;
189
+ callbackContext: Context;
190
+ error: Error;
191
+ }): Promise<void>;
192
+ /**
193
+ * Observes an error in the run lifecycle, including before/after-run callbacks.
194
+ *
195
+ * Notification-only: return values are ignored and callback failures are
196
+ * logged. The original execution error always propagates. A completion-hook
197
+ * failure during early iterator close is reported but does not prevent closing.
198
+ */
199
+ onRunErrorCallback(_params: {
200
+ invocationContext: InvocationContext;
201
+ error: Error;
202
+ }): Promise<void>;
179
203
  /**
180
204
  * Callback executed before an agent's primary logic is invoked.
181
205
  *
@@ -195,14 +219,14 @@ export declare abstract class BasePlugin {
195
219
  /**
196
220
  * Callback executed after an agent's primary logic has completed.
197
221
  *
198
- * This callback can be used to inspect, log, or modify the agent's final
199
- * result before it is returned.
222
+ * This callback can be used to inspect, log, or append an additional event
223
+ * after the agent's execution completes.
200
224
  *
201
225
  * @param _params.agent The agent that has just run.
202
226
  * @param _params.callbackContext The context for the agent invocation.
203
- * @returns An optional `Content` object. If a value is returned, it will
204
- * replace the agent's original result. Returning `undefined` uses the
205
- * original, unmodified result.
227
+ * @returns An optional `Content` object. If a value is returned, it will be
228
+ * emitted as an additional event appended after the agent's execution.
229
+ * Returning `undefined` emits no additional content event.
206
230
  */
207
231
  afterAgentCallback(_params: {
208
232
  agent: BaseAgent;
@@ -250,8 +274,8 @@ export declare abstract class BasePlugin {
250
274
  *
251
275
  * @param _params.callbackContext The context for the current agent call.
252
276
  * @param _params.llmRequest The prepared request object to be sent to the model.
253
- * @returns An optional value. The interpretation of a non-`undefined`
254
- * trigger an early exit and returns the response immediately. Returning
277
+ * @returns An optional `LlmResponse`. Returning a non-`undefined` value
278
+ * triggers an early exit and returns that response immediately. Returning
255
279
  * `undefined` allows the LLM request to proceed normally.
256
280
  */
257
281
  beforeModelCallback(_params: {
@@ -275,7 +299,7 @@ export declare abstract class BasePlugin {
275
299
  llmResponse: LlmResponse;
276
300
  }): Promise<LlmResponse | undefined>;
277
301
  /**
278
- * Callback executed when a model call encounters an error.
302
+ * Callback executed when a model call encounters an `Error`.
279
303
  *
280
304
  * This callback provides an opportunity to handle model errors gracefully,
281
305
  * potentially providing alternative responses or recovery mechanisms.
@@ -283,10 +307,11 @@ export declare abstract class BasePlugin {
283
307
  * @param _params.callbackContext The context for the current agent call.
284
308
  * @param _params.llmRequest The request that was sent to the model when the error
285
309
  * occurred.
286
- * @param _params.error The exception that was raised during model execution.
287
- * @returns An optional LlmResponse. If an LlmResponse is returned, it will be
288
- * used instead of propagating the error. Returning `undefined` allows
289
- * the original error to be raised.
310
+ * @param _params.error The `Error` instance thrown during model execution.
311
+ * @returns An optional `LlmResponse`. If an `LlmResponse` is returned, it
312
+ * will be used instead of the default error response. Returning
313
+ * `undefined` causes an error response/event with `errorCode` and
314
+ * `errorMessage` derived from `error` to be yielded.
290
315
  */
291
316
  onModelErrorCallback(_params: {
292
317
  callbackContext: Context;
@@ -376,7 +401,8 @@ export declare abstract class BasePlugin {
376
401
  result: Record<string, unknown>;
377
402
  }): Promise<Record<string, unknown> | undefined>;
378
403
  /**
379
- * Callback executed when a tool call encounters an error.
404
+ * Callback executed when a tool call encounters an `Error` or cannot be
405
+ * resolved.
380
406
  *
381
407
  * This callback provides an opportunity to handle tool errors gracefully,
382
408
  * potentially providing alternative responses or recovery mechanisms.
@@ -384,10 +410,13 @@ export declare abstract class BasePlugin {
384
410
  * @param _params.tool The tool instance that encountered an error.
385
411
  * @param _params.toolArgs The arguments that were passed to the tool.
386
412
  * @param _params.toolContext The context specific to the tool execution.
387
- * @param _params.error The exception that was raised during tool execution.
413
+ * @param _params.error The `Error` that was raised during tool resolution or
414
+ * execution.
388
415
  * @returns An optional dictionary. If a dictionary is returned, it will be
389
- * used as the tool response instead of propagating the error. Returning
390
- * `undefined` allows the original error to be raised.
416
+ * used as the tool response instead of the default error response.
417
+ * Returning `undefined` causes `{error: error.message}` to be returned as
418
+ * the tool response (unlike adk-python, which re-raises). Non-`Error`
419
+ * throwables bypass this callback and become `{error: thrownValue}`.
391
420
  */
392
421
  onToolErrorCallback(_params: {
393
422
  tool: BaseTool;
@@ -67,6 +67,19 @@ export declare class PluginManager {
67
67
  * the proper type for the plugin method.
68
68
  */
69
69
  private runCallbacks;
70
+ /** Notifies every plugin without allowing one failure to hide another. */
71
+ private runNotificationCallbacks;
72
+ /** Runs the notification-only agent error callback for every plugin. */
73
+ runOnAgentErrorCallback(params: {
74
+ agent: BaseAgent;
75
+ callbackContext: Context;
76
+ error: Error;
77
+ }): Promise<void>;
78
+ /** Runs the notification-only run error callback for every plugin. */
79
+ runOnRunErrorCallback(params: {
80
+ invocationContext: InvocationContext;
81
+ error: Error;
82
+ }): Promise<void>;
70
83
  /**
71
84
  * Runs the `onUserMessageCallback` for all plugins.
72
85
  */
@@ -177,6 +177,16 @@ export declare class Runner {
177
177
  abortSignal?: AbortSignal;
178
178
  customMetadata?: Record<string, unknown>;
179
179
  }): AsyncGenerator<Event, void, undefined>;
180
+ /**
181
+ * Closes the runner and cleans up all toolsets reachable from the root agent
182
+ * or workflow.
183
+ */
184
+ close(): Promise<void>;
185
+ private runAsyncWithPlugins;
186
+ /** Finalizes a started run, including when its consumer closes the iterator. */
187
+ private runWithPluginLifecycle;
188
+ private finishRun;
189
+ private notifyRunError;
180
190
  /**
181
191
  * Runs whatever this runner was given as its root.
182
192
  *
@@ -260,6 +270,7 @@ export declare class Runner {
260
270
  abortSignal?: AbortSignal;
261
271
  liveSessionResumptionHandle?: string;
262
272
  }): AsyncGenerator<Event, void, undefined>;
273
+ private runLiveWithPlugins;
263
274
  }
264
275
  /**
265
276
  * Determines the next agent to run to continue the session. This is primarily
@@ -156,8 +156,6 @@ export declare function trimTempDeltaState(event: Event): Event;
156
156
  * and `JSON.parse` makes `__proto__` an own key, so copying it into a plain
157
157
  * object literal would invoke the inherited `__proto__` setter: the entry is
158
158
  * dropped and the new state object is re-parented onto the attacker's object.
159
- * `State.get`/`State.has` use the `in` operator, so every key on that object
160
- * would then read back as session state.
161
159
  */
162
160
  export declare function trimTempState(state: Record<string, unknown>): Record<string, unknown>;
163
161
  /**
@@ -25,7 +25,8 @@ export type MikroORMOptions = Partial<Options>;
25
25
  */
26
26
  export declare function getConnectionOptionsFromUri(uri: string): Promise<MikroORMOptions>;
27
27
  /**
28
- * Creates a database and tables if they don't exist.
28
+ * Creates a database and any missing entity tables without altering existing
29
+ * tables.
29
30
  *
30
31
  * @param orm The MikroORM instance.
31
32
  * @returns Promise<void>
@@ -9,12 +9,14 @@ export declare const SCHEMA_VERSION_KEY = "schema_version";
9
9
  export declare const SCHEMA_VERSION_1_JSON = "1";
10
10
  export declare const STORAGE_KEY_COLUMN_LENGTH = 191;
11
11
  /**
12
- * Fractional-second digits requested for the stored event timestamp.
12
+ * Fractional-second digits requested for stored session, state, and event
13
+ * timestamp columns.
13
14
  *
14
15
  * MySQL and MariaDB round a `datetime` column to whole seconds unless a
15
16
  * precision is given. That collapses events written in the same second onto one
16
- * value and leaves their order undefined. Other backends are unaffected:
17
- * PostgreSQL already defaults to six digits and SQLite ignores the precision.
17
+ * value and rounds session `update_time` up across a second boundary. Other
18
+ * backends are unaffected: PostgreSQL already defaults to six digits and SQLite
19
+ * ignores the precision.
18
20
  */
19
21
  export declare const EVENT_TIMESTAMP_PRECISION = 6;
20
22
  export declare class StorageMetadata {
@@ -0,0 +1,259 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { Content } from '@google/genai';
7
+ import type { BaseAgent } from '../../agents/base_agent.js';
8
+ import type { InvocationContext } from '../../agents/invocation_context.js';
9
+ import type { RunConfig } from '../../agents/run_config.js';
10
+ import type { Event } from '../../events/event.js';
11
+ import type { LlmRequest } from '../../models/llm_request.js';
12
+ import type { LlmResponse } from '../../models/llm_response.js';
13
+ import type { ContextCompactionTrigger } from '../../plugins/base_plugin.js';
14
+ import type { Skill } from '../../skills/skill.js';
15
+ import type { BaseTool } from '../../tools/base_tool.js';
16
+ import type { BaseNode } from '../../workflow/base_node.js';
17
+ import { type IncomingHeaders } from './internal/trace/propagation.js';
18
+ export type { ContentCapturingMode, ExperimentalFeature, TelemetryConfig, } from './internal/common/config.js';
19
+ export type { IncomingHeaders } from './internal/trace/propagation.js';
20
+ /** Parameters for starting an invocation with {@link recordInvocation}. */
21
+ export interface RecordInvocationParams {
22
+ /** The runner's root agent or workflow. */
23
+ readonly entrypoint: BaseNode;
24
+ /** The session the invocation runs in. */
25
+ readonly sessionId: string;
26
+ /** The run's config, whose `telemetry` overrides apply to the invocation. */
27
+ readonly runConfig?: RunConfig;
28
+ }
29
+ /**
30
+ * Wraps a runner invocation in its root `invoke_workflow {entrypoint}` span.
31
+ *
32
+ * Every workflow started inside the invocation is nested below this span. A
33
+ * workflow entrypoint runs inside it rather than opening a second one.
34
+ */
35
+ export declare function recordInvocation<T>({ entrypoint, sessionId, runConfig }: RecordInvocationParams, createGenerator: () => AsyncGenerator<T, void, void>): AsyncGenerator<T, void, void>;
36
+ /** Parameters for starting an `invoke_agent` instrumentation scope. */
37
+ export interface RecordAgentInvocationParams {
38
+ readonly agent: BaseAgent;
39
+ /** The context the agent was invoked with. */
40
+ readonly invocationContext: InvocationContext;
41
+ }
42
+ /**
43
+ * Wraps an agent invocation in an `invoke_agent {agent.name}` span.
44
+ */
45
+ export declare function recordAgentInvocation<T>({ agent, invocationContext }: RecordAgentInvocationParams, createGenerator: () => AsyncGenerator<T, void, void>): AsyncGenerator<T, void, void>;
46
+ /** Parameters for recording one model call with {@link recordInference}. */
47
+ export interface RecordInferenceParams {
48
+ readonly invocationContext: InvocationContext;
49
+ readonly llmRequest: LlmRequest;
50
+ /** The event the model's responses are merged into. */
51
+ readonly modelResponseEvent: Event;
52
+ }
53
+ /**
54
+ * Wraps one model call in a `generate_content {model}` span and its
55
+ * `gen_ai.client.inference.operation.details` log record.
56
+ *
57
+ * Returns the model's responses unchanged. The span is current only while the
58
+ * model stream is being pulled, never while the caller handles a response, and
59
+ * it ends at the first response that reports a finish reason, before that
60
+ * response is returned. If the stream ends, fails or is closed before one
61
+ * arrives, the span ends then. Each call emits exactly one log record, while
62
+ * the span is still open.
63
+ */
64
+ export declare function recordInference(params: RecordInferenceParams, createStream: () => AsyncGenerator<LlmResponse, void, void>): AsyncGenerator<LlmResponse, void, void>;
65
+ /** Parameters for recording a live `send_data` span. */
66
+ export interface RecordSendDataParams {
67
+ readonly invocationContext: InvocationContext;
68
+ readonly eventId: string;
69
+ readonly data: Content[];
70
+ }
71
+ /**
72
+ * Wraps an async operation in a `send_data` span and records the live data
73
+ * payload attributes when the operation completes.
74
+ */
75
+ export declare function recordSendData<T>(params: RecordSendDataParams, fn: () => Promise<T>): Promise<T>;
76
+ /** Parameters for starting an `execute_tool` instrumentation scope. */
77
+ export interface RecordToolExecutionParams {
78
+ readonly tool: BaseTool;
79
+ readonly args: Record<string, unknown>;
80
+ readonly invocationContext: InvocationContext;
81
+ }
82
+ /** Parameters for recording a completed tool execution on its scope. */
83
+ export interface ToolExecutionSuccessParams {
84
+ readonly functionResponseEvent?: Event;
85
+ /**
86
+ * The raw value returned by the tool before normalization into a
87
+ * `functionResponse` event, used to inspect any response-reported error type.
88
+ */
89
+ readonly rawResult: unknown;
90
+ }
91
+ /** Scope handle passed to the body of {@link recordToolExecution}. */
92
+ export interface ToolExecutionScope {
93
+ /**
94
+ * Records the tool's response, including an error the tool reported in it
95
+ * rather than throwing.
96
+ */
97
+ recordSuccess(params: ToolExecutionSuccessParams): void;
98
+ }
99
+ /**
100
+ * Wraps a single tool call in an `execute_tool {tool.name}` span.
101
+ *
102
+ * An error that escapes `fn` is recorded on the span as `error.type` and an
103
+ * ERROR status, as is an error the tool reports in its response. Skill tools
104
+ * running inside report to the span through {@link recordSkillActivity}.
105
+ */
106
+ export declare function recordToolExecution<T>({ tool, args, invocationContext }: RecordToolExecutionParams, fn: (scope: ToolExecutionScope) => Promise<T>): Promise<T>;
107
+ /** What a skill tool is doing, reported with {@link recordSkillActivity}. */
108
+ export type SkillActivity = {
109
+ readonly kind: 'load';
110
+ readonly skillName: string;
111
+ } | {
112
+ readonly kind: 'resource';
113
+ readonly skillName: string;
114
+ readonly resourcePath: string;
115
+ } | {
116
+ readonly kind: 'script';
117
+ readonly skillName: string;
118
+ readonly scriptPath: string;
119
+ };
120
+ /** Handle returned by {@link recordSkillActivity}. */
121
+ export interface SkillActivityScope {
122
+ /** Records the skill the tool resolved. */
123
+ recordSkill(skill: Skill): void;
124
+ }
125
+ /**
126
+ * Reports what a skill tool is doing to the `execute_tool` span it runs
127
+ * under, which is renamed after the skill and records its attributes when the
128
+ * tool call ends.
129
+ *
130
+ * Does nothing outside a tool call. A second report in the same tool call
131
+ * replaces the first.
132
+ */
133
+ export declare function recordSkillActivity(activity: SkillActivity): SkillActivityScope;
134
+ /** Parameters for recording a merged tool calls span. */
135
+ export interface RecordMergedToolCallsParams {
136
+ /** The id of the event that merges the parallel tool responses. */
137
+ readonly responseEventId: string;
138
+ }
139
+ /**
140
+ * Starts and immediately ends an `execute_tool (merged)` span for parallel
141
+ * tool calls whose responses were merged into one event.
142
+ */
143
+ export declare function recordMergedToolCalls({ responseEventId, }: RecordMergedToolCallsParams): void;
144
+ /**
145
+ * A synchronously started span scope for workflow orchestration.
146
+ *
147
+ * Workflow and node scopes return this handle instead of wrapping a callback.
148
+ * Their spans must start at the moment the work is scheduled, and the scope
149
+ * must hand the caller's promise back unchanged: an `async` wrapper adds
150
+ * promise ticks, which changes how concurrently scheduled nodes interleave.
151
+ */
152
+ export interface SyncStartedScope {
153
+ /**
154
+ * Runs `fn` with this scope's span as the active span and returns its result
155
+ * as is, without awaiting it.
156
+ */
157
+ run<T>(fn: () => T): T;
158
+ /**
159
+ * Ends the span, with an ERROR status when `error` is given. Safe to call
160
+ * more than once; only the first call counts.
161
+ */
162
+ end(error?: unknown): void;
163
+ }
164
+ /** Parameters for starting an `invoke_workflow` instrumentation scope. */
165
+ export interface RecordWorkflowInvocationParams {
166
+ readonly workflow: BaseNode;
167
+ readonly sessionId: string;
168
+ }
169
+ /**
170
+ * Starts the `invoke_workflow {workflow.name}` scope of a workflow run,
171
+ * synchronously.
172
+ *
173
+ * The workflow the runner was entered at runs in the runner's span instead,
174
+ * so its scope opens nothing. A workflow started inside another workflow is
175
+ * marked nested. The caller runs the orchestration through `scope.run` and
176
+ * calls `scope.end()` once it settles.
177
+ */
178
+ export declare function recordWorkflowInvocation({ workflow, sessionId, }: RecordWorkflowInvocationParams): SyncStartedScope;
179
+ /** Parameters for starting a workflow node's instrumentation scope. */
180
+ export interface RecordNodeInvocationParams {
181
+ readonly node: BaseNode;
182
+ /** The name the node runs under, which may differ from `node.name`. */
183
+ readonly nodeName: string;
184
+ readonly sessionId: string;
185
+ }
186
+ /** Scope handle returned by {@link recordNodeInvocation}. */
187
+ export interface NodeInvocationScope extends SyncStartedScope {
188
+ /** Records an event the node emitted. */
189
+ recordEvent(event: Event): void;
190
+ }
191
+ /**
192
+ * Starts the scope of one workflow node run, synchronously.
193
+ *
194
+ * A plain node runs in an `invoke_node {nodeName}` span that records the ids
195
+ * of the events it emitted. An agent or workflow node opens no node span: its
196
+ * own `invoke_agent` or `invoke_workflow` span stands for it.
197
+ *
198
+ * The span's parent is the span active at the call, so call this when the node
199
+ * is scheduled. The caller runs the node body through `scope.run` and calls
200
+ * `scope.end()` when the node work finishes.
201
+ */
202
+ export declare function recordNodeInvocation({ node, nodeName, sessionId, }: RecordNodeInvocationParams): NodeInvocationScope;
203
+ /** Parameters for recording a context compaction. */
204
+ export interface RecordCompactionParams {
205
+ readonly invocationContext: InvocationContext;
206
+ readonly trigger: ContextCompactionTrigger;
207
+ }
208
+ /**
209
+ * Wraps a context compaction in a `compact_events {trigger}` span, recording
210
+ * the summary event it added to the session.
211
+ */
212
+ export declare function recordCompaction<T>({ invocationContext, trigger }: RecordCompactionParams, fn: () => Promise<T>): Promise<T>;
213
+ /** A `fetch` as the MCP HTTP transports call it. */
214
+ export type McpFetch = (url: string | URL, init?: Parameters<typeof globalThis.fetch>[1]) => Promise<Response>;
215
+ /**
216
+ * Returns a `fetch` for an MCP HTTP transport that reports each exchange as
217
+ * an `adk.experimental.mcp.http.client.response.end` log record, parented to
218
+ * the span active when the request was sent.
219
+ *
220
+ * Returns `fetch` unchanged, `undefined` included, unless the experimental
221
+ * `mcp` telemetry feature is enabled in the environment, which is read when
222
+ * this is called, so call it when the transport is built. The returned
223
+ * function sends each request with `fetch`, or the global `fetch` when that is
224
+ * `undefined`, and resolves with its response as soon as it arrives: the
225
+ * record is written in the background, and a failure to write it is logged,
226
+ * never thrown.
227
+ */
228
+ export declare function instrumentMcpFetch(fetch: McpFetch | undefined): McpFetch | undefined;
229
+ /** A `fetch`-compatible function. */
230
+ export type FetchFunction = (input: Parameters<typeof globalThis.fetch>[0], init?: Parameters<typeof globalThis.fetch>[1]) => Promise<Response>;
231
+ /**
232
+ * Returns a `fetch` that sends the active trace context with each request.
233
+ *
234
+ * At each call, the globally registered propagator writes the active context
235
+ * into the request headers: W3C `traceparent` and `tracestate` by default. A
236
+ * header the caller already sets is kept. When the propagator writes nothing,
237
+ * for example with no active trace, the request is sent with its arguments
238
+ * unchanged. A propagator error is logged, never thrown.
239
+ *
240
+ * @param fetchImpl The `fetch` that sends the request. Defaults to the global
241
+ * `fetch`, read at each call.
242
+ */
243
+ export declare function propagateTraceContext(fetchImpl?: FetchFunction): FetchFunction;
244
+ /**
245
+ * Runs `fn` in the trace context that an incoming request carries.
246
+ *
247
+ * When no span is active, the globally registered propagator reads the
248
+ * headers (W3C `traceparent` and `tracestate` by default), and a valid remote
249
+ * span becomes the parent of the invocation spans `fn` starts. An already
250
+ * active span, such as an HTTP server span or a remote parent set earlier,
251
+ * stays the parent, and the headers are ignored. Missing or malformed headers
252
+ * leave the context unchanged; a propagator error is logged, never thrown.
253
+ *
254
+ * @param headers The incoming request headers, such as Node's
255
+ * `IncomingMessage.headers`.
256
+ * @param fn The request handler to run.
257
+ * @returns What `fn` returns.
258
+ */
259
+ export declare function runWithRemoteTraceContext<T>(headers: IncomingHeaders, fn: () => T): T;
@@ -0,0 +1,91 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { type Context } from '@opentelemetry/api';
7
+ import type { ResolvedTelemetryConfig } from './config.js';
8
+ import { TokenUsage } from './token_usage.js';
9
+ declare const WORKFLOW_FRAME_SYMBOL: unique symbol;
10
+ /** An accumulator's totals at flush time. */
11
+ export interface Totals {
12
+ /** `undefined` until a model call reports usage (not the same as zero). */
13
+ tokens?: TokenUsage;
14
+ inferenceCalls: number;
15
+ toolCalls: number;
16
+ skillLoads: number;
17
+ compactions: number;
18
+ }
19
+ /** State accumulated across one agent invocation or one workflow. */
20
+ export interface Accumulator {
21
+ readonly totals: Totals;
22
+ }
23
+ /**
24
+ * State accumulated across one `invoke_workflow`, root or nested.
25
+ *
26
+ * The `parent` chain is walked when a call records against every enclosing
27
+ * workflow; its presence is what `gen_ai.workflow.nested` reports.
28
+ */
29
+ export interface WorkflowFrame extends Accumulator {
30
+ readonly [WORKFLOW_FRAME_SYMBOL]: true;
31
+ readonly parent: WorkflowFrame | undefined;
32
+ /** The agent or workflow the turn entered at, inherited by nested workflows. */
33
+ readonly rootAgentName: string;
34
+ readonly workflowName: string;
35
+ /** The config the turn was claimed under, inherited by nested workflows. */
36
+ readonly config: ResolvedTelemetryConfig;
37
+ /**
38
+ * The runner's workflow entrypoint, which runs inside this frame instead of
39
+ * opening its own. Cleared once that workflow has claimed it.
40
+ */
41
+ entrypoint: object | undefined;
42
+ }
43
+ /**
44
+ * Opens an agent accumulator frame on `parentContext`, so model and tool calls
45
+ * running inside count their exclusive totals against this agent invocation.
46
+ */
47
+ export declare function openAgentFrame(parentContext?: Context): {
48
+ readonly frame: Accumulator;
49
+ readonly context: Context;
50
+ };
51
+ /** Parameters for {@link openWorkflowFrame}. */
52
+ export interface OpenWorkflowFrameParams {
53
+ readonly workflowName: string;
54
+ /** The config to use when this is the root workflow frame. */
55
+ readonly config: ResolvedTelemetryConfig;
56
+ readonly entrypoint?: object;
57
+ readonly parentContext?: Context;
58
+ }
59
+ /**
60
+ * Opens a workflow accumulator frame on `parentContext`, linked to any
61
+ * enclosing workflow frame and inheriting its root agent name and telemetry
62
+ * config.
63
+ */
64
+ export declare function openWorkflowFrame({ workflowName, config, entrypoint, parentContext, }: OpenWorkflowFrameParams): {
65
+ readonly frame: WorkflowFrame;
66
+ readonly context: Context;
67
+ };
68
+ /**
69
+ * Hands the runner's entrypoint frame to the workflow it was opened for, once.
70
+ *
71
+ * @returns The context to run the workflow under, or `undefined` when
72
+ * `workflow` is not the unclaimed entrypoint of the enclosing frame.
73
+ */
74
+ export declare function claimEntrypointWorkflowFrame(workflow: object, ctx?: Context): Context | undefined;
75
+ /**
76
+ * Every accumulator a call belongs to, captured from the context when the call
77
+ * starts: the innermost agent (exclusive) and each enclosing workflow
78
+ * (inclusive).
79
+ */
80
+ export interface CapturedAccumulators {
81
+ addInferenceCall(): void;
82
+ addToolCall(): void;
83
+ addSkillLoad(): void;
84
+ addCompaction(): void;
85
+ addTokens(usage: TokenUsage): void;
86
+ }
87
+ /**
88
+ * Captures the active agent and workflow accumulators from `ctx`.
89
+ */
90
+ export declare function captureAccumulators(ctx?: Context): CapturedAccumulators;
91
+ export {};