@google/adk 0.2.5 → 0.4.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 (264) hide show
  1. package/dist/cjs/a2a/part_converter_utils.js +210 -0
  2. package/dist/cjs/agents/active_streaming_tool.js +1 -1
  3. package/dist/cjs/agents/base_agent.js +46 -24
  4. package/dist/cjs/agents/base_llm_processor.js +1 -1
  5. package/dist/cjs/agents/callback_context.js +5 -2
  6. package/dist/cjs/agents/content_processor_utils.js +16 -8
  7. package/dist/cjs/agents/functions.js +81 -30
  8. package/dist/cjs/agents/instructions.js +1 -1
  9. package/dist/cjs/agents/invocation_context.js +1 -1
  10. package/dist/cjs/agents/live_request_queue.js +1 -1
  11. package/dist/cjs/agents/llm_agent.js +106 -62
  12. package/dist/cjs/agents/loop_agent.js +3 -2
  13. package/dist/cjs/agents/parallel_agent.js +4 -5
  14. package/dist/cjs/agents/readonly_context.js +13 -1
  15. package/dist/cjs/agents/run_config.js +2 -1
  16. package/dist/cjs/agents/sequential_agent.js +1 -1
  17. package/dist/cjs/agents/transcription_entry.js +1 -1
  18. package/dist/cjs/artifacts/base_artifact_service.js +1 -1
  19. package/dist/cjs/artifacts/file_artifact_service.js +491 -0
  20. package/dist/cjs/artifacts/gcs_artifact_service.js +145 -58
  21. package/dist/cjs/artifacts/in_memory_artifact_service.js +72 -10
  22. package/dist/cjs/artifacts/registry.js +55 -0
  23. package/dist/cjs/auth/auth_credential.js +1 -1
  24. package/dist/cjs/auth/auth_handler.js +4 -2
  25. package/dist/cjs/auth/auth_schemes.js +1 -1
  26. package/dist/cjs/auth/auth_tool.js +1 -1
  27. package/dist/cjs/auth/credential_service/base_credential_service.js +1 -1
  28. package/dist/cjs/auth/credential_service/in_memory_credential_service.js +1 -1
  29. package/dist/cjs/auth/exchanger/base_credential_exchanger.js +1 -1
  30. package/dist/cjs/auth/exchanger/credential_exchanger_registry.js +1 -1
  31. package/dist/cjs/code_executors/base_code_executor.js +4 -2
  32. package/dist/cjs/code_executors/built_in_code_executor.js +8 -4
  33. package/dist/cjs/code_executors/code_execution_utils.js +1 -1
  34. package/dist/cjs/code_executors/code_executor_context.js +6 -6
  35. package/dist/cjs/common.js +18 -1
  36. package/dist/cjs/events/event.js +34 -7
  37. package/dist/cjs/events/event_actions.js +2 -2
  38. package/dist/cjs/events/structured_events.js +105 -0
  39. package/dist/cjs/examples/base_example_provider.js +1 -1
  40. package/dist/cjs/examples/example.js +1 -1
  41. package/dist/cjs/examples/example_util.js +1 -1
  42. package/dist/cjs/index.js +54 -83
  43. package/dist/cjs/index_web.js +1 -1
  44. package/dist/cjs/memory/base_memory_service.js +1 -1
  45. package/dist/cjs/memory/in_memory_memory_service.js +4 -2
  46. package/dist/cjs/memory/memory_entry.js +1 -1
  47. package/dist/cjs/models/apigee_llm.js +182 -0
  48. package/dist/cjs/models/base_llm.js +9 -5
  49. package/dist/cjs/models/base_llm_connection.js +1 -1
  50. package/dist/cjs/models/gemini_llm_connection.js +2 -1
  51. package/dist/cjs/models/google_llm.js +73 -54
  52. package/dist/cjs/models/llm_request.js +1 -1
  53. package/dist/cjs/models/llm_response.js +1 -1
  54. package/dist/cjs/models/registry.js +3 -1
  55. package/dist/cjs/plugins/base_plugin.js +13 -1
  56. package/dist/cjs/plugins/logging_plugin.js +51 -14
  57. package/dist/cjs/plugins/plugin_manager.js +57 -25
  58. package/dist/cjs/plugins/security_plugin.js +2 -2
  59. package/dist/cjs/runner/in_memory_runner.js +1 -1
  60. package/dist/cjs/runner/runner.js +142 -96
  61. package/dist/cjs/sessions/base_session_service.js +53 -3
  62. package/dist/cjs/sessions/database_session_service.js +364 -0
  63. package/dist/cjs/sessions/db/operations.js +114 -0
  64. package/dist/cjs/sessions/db/schema.js +204 -0
  65. package/dist/cjs/sessions/in_memory_session_service.js +60 -34
  66. package/dist/cjs/sessions/registry.js +49 -0
  67. package/dist/cjs/sessions/session.js +1 -1
  68. package/dist/cjs/sessions/state.js +1 -1
  69. package/dist/cjs/telemetry/google_cloud.js +8 -10
  70. package/dist/cjs/telemetry/setup.js +16 -8
  71. package/dist/cjs/telemetry/tracing.js +38 -16
  72. package/dist/cjs/tools/agent_tool.js +9 -5
  73. package/dist/cjs/tools/base_tool.js +5 -3
  74. package/dist/cjs/tools/base_toolset.js +1 -1
  75. package/dist/cjs/tools/forwarding_artifact_service.js +18 -2
  76. package/dist/cjs/tools/function_tool.js +2 -3
  77. package/dist/cjs/tools/google_search_tool.js +2 -3
  78. package/dist/cjs/tools/long_running_tool.js +1 -1
  79. package/dist/cjs/tools/mcp/mcp_session_manager.js +17 -11
  80. package/dist/cjs/tools/mcp/mcp_tool.js +2 -4
  81. package/dist/cjs/tools/mcp/mcp_toolset.js +2 -2
  82. package/dist/cjs/tools/tool_confirmation.js +1 -1
  83. package/dist/cjs/tools/tool_context.js +1 -1
  84. package/dist/cjs/utils/client_labels.js +1 -1
  85. package/dist/cjs/utils/env_aware_utils.js +11 -2
  86. package/dist/cjs/utils/gemini_schema_util.js +10 -5
  87. package/dist/cjs/utils/logger.js +48 -4
  88. package/dist/cjs/utils/model_name.js +1 -1
  89. package/dist/cjs/utils/object_notation_utils.js +78 -0
  90. package/dist/cjs/utils/simple_zod_to_json.js +101 -142
  91. package/dist/cjs/utils/variant_utils.js +3 -9
  92. package/dist/cjs/version.js +2 -2
  93. package/dist/esm/a2a/part_converter_utils.js +171 -0
  94. package/dist/esm/agents/base_agent.js +50 -24
  95. package/dist/esm/agents/callback_context.js +4 -1
  96. package/dist/esm/agents/content_processor_utils.js +25 -9
  97. package/dist/esm/agents/functions.js +84 -29
  98. package/dist/esm/agents/llm_agent.js +110 -62
  99. package/dist/esm/agents/loop_agent.js +2 -1
  100. package/dist/esm/agents/parallel_agent.js +3 -4
  101. package/dist/esm/agents/readonly_context.js +12 -0
  102. package/dist/esm/agents/run_config.js +1 -0
  103. package/dist/esm/artifacts/file_artifact_service.js +451 -0
  104. package/dist/esm/artifacts/gcs_artifact_service.js +144 -57
  105. package/dist/esm/artifacts/in_memory_artifact_service.js +69 -8
  106. package/dist/esm/artifacts/registry.js +28 -0
  107. package/dist/esm/auth/auth_handler.js +3 -1
  108. package/dist/esm/code_executors/base_code_executor.js +3 -1
  109. package/dist/esm/code_executors/built_in_code_executor.js +7 -3
  110. package/dist/esm/code_executors/code_executor_context.js +5 -5
  111. package/dist/esm/common.js +12 -2
  112. package/dist/esm/events/event.js +30 -5
  113. package/dist/esm/events/event_actions.js +1 -1
  114. package/dist/esm/events/structured_events.js +74 -0
  115. package/dist/esm/index.js +18 -88
  116. package/dist/esm/memory/in_memory_memory_service.js +3 -1
  117. package/dist/esm/models/apigee_llm.js +152 -0
  118. package/dist/esm/models/base_llm.js +8 -4
  119. package/dist/esm/models/gemini_llm_connection.js +1 -0
  120. package/dist/esm/models/google_llm.js +75 -53
  121. package/dist/esm/models/registry.js +2 -0
  122. package/dist/esm/plugins/base_plugin.js +12 -0
  123. package/dist/esm/plugins/logging_plugin.js +55 -14
  124. package/dist/esm/plugins/plugin_manager.js +56 -24
  125. package/dist/esm/plugins/security_plugin.js +1 -1
  126. package/dist/esm/runner/runner.js +145 -96
  127. package/dist/esm/sessions/base_session_service.js +49 -1
  128. package/dist/esm/sessions/database_session_service.js +350 -0
  129. package/dist/esm/sessions/db/operations.js +87 -0
  130. package/dist/esm/sessions/db/schema.js +172 -0
  131. package/dist/esm/sessions/in_memory_session_service.js +61 -33
  132. package/dist/esm/sessions/registry.js +25 -0
  133. package/dist/esm/telemetry/google_cloud.js +7 -9
  134. package/dist/esm/telemetry/setup.js +23 -9
  135. package/dist/esm/telemetry/tracing.js +37 -15
  136. package/dist/esm/tools/agent_tool.js +8 -4
  137. package/dist/esm/tools/base_tool.js +4 -2
  138. package/dist/esm/tools/forwarding_artifact_service.js +17 -1
  139. package/dist/esm/tools/function_tool.js +1 -2
  140. package/dist/esm/tools/google_search_tool.js +2 -5
  141. package/dist/esm/tools/long_running_tool.js +3 -1
  142. package/dist/esm/tools/mcp/mcp_session_manager.js +22 -12
  143. package/dist/esm/tools/mcp/mcp_tool.js +1 -3
  144. package/dist/esm/tools/mcp/mcp_toolset.js +1 -1
  145. package/dist/esm/utils/env_aware_utils.js +9 -1
  146. package/dist/esm/utils/gemini_schema_util.js +9 -4
  147. package/dist/esm/utils/logger.js +43 -2
  148. package/dist/esm/utils/object_notation_utils.js +47 -0
  149. package/dist/esm/utils/simple_zod_to_json.js +102 -141
  150. package/dist/esm/utils/variant_utils.js +1 -7
  151. package/dist/esm/version.js +1 -1
  152. package/dist/types/a2a/part_converter_utils.d.ts +47 -0
  153. package/dist/types/agents/base_agent.d.ts +2 -1
  154. package/dist/types/agents/callback_context.d.ts +1 -1
  155. package/dist/types/agents/llm_agent.d.ts +12 -12
  156. package/dist/types/agents/loop_agent.d.ts +1 -1
  157. package/dist/types/agents/parallel_agent.d.ts +1 -1
  158. package/dist/types/agents/readonly_context.d.ts +8 -0
  159. package/dist/types/agents/run_config.d.ts +6 -0
  160. package/dist/types/artifacts/base_artifact_service.d.ts +31 -0
  161. package/dist/types/artifacts/file_artifact_service.d.ts +43 -0
  162. package/dist/types/artifacts/gcs_artifact_service.d.ts +3 -1
  163. package/dist/types/artifacts/in_memory_artifact_service.d.ts +8 -5
  164. package/dist/types/artifacts/registry.d.ts +7 -0
  165. package/dist/types/code_executors/built_in_code_executor.d.ts +1 -1
  166. package/dist/types/code_executors/code_executor_context.d.ts +2 -4
  167. package/dist/types/common.d.ts +13 -3
  168. package/dist/types/events/event.d.ts +15 -1
  169. package/dist/types/events/event_actions.d.ts +1 -1
  170. package/dist/types/events/structured_events.d.ts +106 -0
  171. package/dist/types/index.d.ts +7 -3
  172. package/dist/types/models/apigee_llm.d.ts +59 -0
  173. package/dist/types/models/base_llm_connection.d.ts +1 -1
  174. package/dist/types/models/google_llm.d.ts +5 -2
  175. package/dist/types/models/llm_response.d.ts +1 -1
  176. package/dist/types/plugins/logging_plugin.d.ts +12 -12
  177. package/dist/types/plugins/plugin_manager.d.ts +12 -12
  178. package/dist/types/plugins/security_plugin.d.ts +1 -1
  179. package/dist/types/runner/runner.d.ts +16 -1
  180. package/dist/types/sessions/base_session_service.d.ts +20 -0
  181. package/dist/types/sessions/database_session_service.d.ts +31 -0
  182. package/dist/types/sessions/db/operations.d.ts +29 -0
  183. package/dist/types/sessions/db/schema.d.ts +45 -0
  184. package/dist/types/sessions/in_memory_session_service.d.ts +9 -6
  185. package/dist/types/sessions/registry.d.ts +7 -0
  186. package/dist/types/telemetry/setup.d.ts +1 -1
  187. package/dist/types/telemetry/tracing.d.ts +7 -6
  188. package/dist/types/tools/agent_tool.d.ts +1 -1
  189. package/dist/types/tools/base_tool.d.ts +1 -1
  190. package/dist/types/tools/base_toolset.d.ts +2 -1
  191. package/dist/types/tools/forwarding_artifact_service.d.ts +4 -2
  192. package/dist/types/tools/function_tool.d.ts +4 -3
  193. package/dist/types/tools/google_search_tool.d.ts +3 -3
  194. package/dist/types/tools/mcp/mcp_session_manager.d.ts +10 -3
  195. package/dist/types/tools/mcp/mcp_toolset.d.ts +1 -2
  196. package/dist/types/utils/env_aware_utils.d.ts +7 -0
  197. package/dist/types/utils/gemini_schema_util.d.ts +4 -12
  198. package/dist/types/utils/logger.d.ts +11 -10
  199. package/dist/types/utils/object_notation_utils.d.ts +21 -0
  200. package/dist/types/utils/simple_zod_to_json.d.ts +5 -4
  201. package/dist/types/version.d.ts +1 -1
  202. package/dist/web/a2a/part_converter_utils.js +171 -0
  203. package/dist/web/agents/base_agent.js +96 -35
  204. package/dist/web/agents/callback_context.js +4 -1
  205. package/dist/web/agents/content_processor_utils.js +25 -9
  206. package/dist/web/agents/functions.js +84 -29
  207. package/dist/web/agents/llm_agent.js +166 -83
  208. package/dist/web/agents/loop_agent.js +2 -1
  209. package/dist/web/agents/parallel_agent.js +3 -4
  210. package/dist/web/agents/readonly_context.js +12 -0
  211. package/dist/web/agents/run_config.js +2 -1
  212. package/dist/web/artifacts/file_artifact_service.js +506 -0
  213. package/dist/web/artifacts/gcs_artifact_service.js +139 -54
  214. package/dist/web/artifacts/in_memory_artifact_service.js +69 -8
  215. package/dist/web/artifacts/registry.js +28 -0
  216. package/dist/web/auth/auth_handler.js +3 -1
  217. package/dist/web/code_executors/base_code_executor.js +3 -1
  218. package/dist/web/code_executors/built_in_code_executor.js +7 -3
  219. package/dist/web/code_executors/code_executor_context.js +5 -5
  220. package/dist/web/common.js +12 -2
  221. package/dist/web/events/event.js +30 -5
  222. package/dist/web/events/event_actions.js +1 -1
  223. package/dist/web/events/structured_events.js +74 -0
  224. package/dist/web/index.js +18 -8
  225. package/dist/web/memory/in_memory_memory_service.js +3 -1
  226. package/dist/web/models/apigee_llm.js +219 -0
  227. package/dist/web/models/base_llm.js +8 -4
  228. package/dist/web/models/gemini_llm_connection.js +1 -0
  229. package/dist/web/models/google_llm.js +75 -50
  230. package/dist/web/models/registry.js +2 -0
  231. package/dist/web/plugins/base_plugin.js +12 -0
  232. package/dist/web/plugins/logging_plugin.js +55 -14
  233. package/dist/web/plugins/plugin_manager.js +56 -24
  234. package/dist/web/plugins/security_plugin.js +1 -1
  235. package/dist/web/runner/runner.js +192 -108
  236. package/dist/web/sessions/base_session_service.js +49 -1
  237. package/dist/web/sessions/database_session_service.js +368 -0
  238. package/dist/web/sessions/db/operations.js +87 -0
  239. package/dist/web/sessions/db/schema.js +172 -0
  240. package/dist/web/sessions/in_memory_session_service.js +61 -33
  241. package/dist/web/sessions/registry.js +25 -0
  242. package/dist/web/telemetry/google_cloud.js +7 -9
  243. package/dist/web/telemetry/setup.js +23 -9
  244. package/dist/web/telemetry/tracing.js +37 -15
  245. package/dist/web/tools/agent_tool.js +8 -4
  246. package/dist/web/tools/base_tool.js +4 -2
  247. package/dist/web/tools/forwarding_artifact_service.js +17 -1
  248. package/dist/web/tools/function_tool.js +1 -2
  249. package/dist/web/tools/google_search_tool.js +2 -5
  250. package/dist/web/tools/long_running_tool.js +3 -1
  251. package/dist/web/tools/mcp/mcp_session_manager.js +22 -12
  252. package/dist/web/tools/mcp/mcp_tool.js +1 -3
  253. package/dist/web/tools/mcp/mcp_toolset.js +1 -1
  254. package/dist/web/utils/env_aware_utils.js +9 -1
  255. package/dist/web/utils/gemini_schema_util.js +9 -4
  256. package/dist/web/utils/logger.js +43 -2
  257. package/dist/web/utils/object_notation_utils.js +47 -0
  258. package/dist/web/utils/simple_zod_to_json.js +102 -155
  259. package/dist/web/utils/variant_utils.js +1 -7
  260. package/dist/web/version.js +1 -1
  261. package/package.json +16 -5
  262. package/dist/cjs/index.js.map +0 -7
  263. package/dist/esm/index.js.map +0 -7
  264. package/dist/web/index.js.map +0 -7
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright 2025 Google LLC
3
+ * Copyright 2026 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
 
@@ -30,6 +30,7 @@ __export(llm_agent_exports, {
30
30
  responseProcessor: () => responseProcessor
31
31
  });
32
32
  module.exports = __toCommonJS(llm_agent_exports);
33
+ var import_api = require("@opentelemetry/api");
33
34
  var import_lodash_es = require("lodash-es");
34
35
  var import_zod = require("zod");
35
36
  var import_base_code_executor = require("../code_executors/base_code_executor.js");
@@ -48,6 +49,8 @@ var import_tool_confirmation = require("../tools/tool_confirmation.js");
48
49
  var import_tool_context = require("../tools/tool_context.js");
49
50
  var import_env_aware_utils = require("../utils/env_aware_utils.js");
50
51
  var import_logger = require("../utils/logger.js");
52
+ var import_tracing = require("../telemetry/tracing.js");
53
+ var import_simple_zod_to_json = require("../utils/simple_zod_to_json.js");
51
54
  var import_base_agent = require("./base_agent.js");
52
55
  var import_base_llm_processor = require("./base_llm_processor.js");
53
56
  var import_callback_context = require("./callback_context.js");
@@ -63,13 +66,14 @@ var import_run_config = require("./run_config.js");
63
66
  */
64
67
  var _a, _b;
65
68
  const ADK_AGENT_NAME_LABEL_KEY = "adk_agent_name";
66
- async function convertToolUnionToTools(toolUnion, context) {
67
- if (toolUnion instanceof import_base_tool.BaseTool) {
69
+ async function convertToolUnionToTools(toolUnion, context2) {
70
+ if ((0, import_base_tool.isBaseTool)(toolUnion)) {
68
71
  return [toolUnion];
69
72
  }
70
- return await toolUnion.getTools(context);
73
+ return await toolUnion.getTools(context2);
71
74
  }
72
75
  class BasicLlmRequestProcessor extends import_base_llm_processor.BaseLlmRequestProcessor {
76
+ // eslint-disable-next-line require-yield
73
77
  async *runAsync(invocationContext, llmRequest) {
74
78
  var _a2;
75
79
  const agent = invocationContext.agent;
@@ -94,6 +98,7 @@ class BasicLlmRequestProcessor extends import_base_llm_processor.BaseLlmRequestP
94
98
  }
95
99
  const BASIC_LLM_REQUEST_PROCESSOR = new BasicLlmRequestProcessor();
96
100
  class IdentityLlmRequestProcessor extends import_base_llm_processor.BaseLlmRequestProcessor {
101
+ // eslint-disable-next-line require-yield
97
102
  async *runAsync(invocationContext, llmRequest) {
98
103
  const agent = invocationContext.agent;
99
104
  const si = [`You are an agent. Your internal name is "${agent.name}".`];
@@ -108,9 +113,10 @@ class InstructionsLlmRequestProcessor extends import_base_llm_processor.BaseLlmR
108
113
  /**
109
114
  * Handles instructions and global instructions for LLM flow.
110
115
  */
116
+ // eslint-disable-next-line require-yield
111
117
  async *runAsync(invocationContext, llmRequest) {
112
118
  const agent = invocationContext.agent;
113
- if (!(agent instanceof LlmAgent) || !(agent.rootAgent instanceof LlmAgent)) {
119
+ if (!isLlmAgent(agent) || !isLlmAgent(agent.rootAgent)) {
114
120
  return;
115
121
  }
116
122
  const rootAgent = agent.rootAgent;
@@ -144,6 +150,7 @@ class InstructionsLlmRequestProcessor extends import_base_llm_processor.BaseLlmR
144
150
  }
145
151
  const INSTRUCTIONS_LLM_REQUEST_PROCESSOR = new InstructionsLlmRequestProcessor();
146
152
  class ContentRequestProcessor {
153
+ // eslint-disable-next-line require-yield
147
154
  async *runAsync(invocationContext, llmRequest) {
148
155
  const agent = invocationContext.agent;
149
156
  if (!agent || !isLlmAgent(agent)) {
@@ -185,8 +192,9 @@ class AgentTransferLlmRequestProcessor extends import_base_llm_processor.BaseLlm
185
192
  }
186
193
  });
187
194
  }
195
+ // eslint-disable-next-line require-yield
188
196
  async *runAsync(invocationContext, llmRequest) {
189
- if (!(invocationContext.agent instanceof LlmAgent)) {
197
+ if (!isLlmAgent(invocationContext.agent)) {
190
198
  return;
191
199
  }
192
200
  const transferTargets = this.getTransferTargets(invocationContext.agent);
@@ -253,7 +261,7 @@ to your parent agent.
253
261
  const AGENT_TRANSFER_LLM_REQUEST_PROCESSOR = new AgentTransferLlmRequestProcessor();
254
262
  class RequestConfirmationLlmRequestProcessor extends import_base_llm_processor.BaseLlmRequestProcessor {
255
263
  /** Handles tool confirmation information to build the LLM request. */
256
- async *runAsync(invocationContext, llmRequest) {
264
+ async *runAsync(invocationContext) {
257
265
  const agent = invocationContext.agent;
258
266
  if (!isLlmAgent(agent)) {
259
267
  return;
@@ -372,7 +380,7 @@ class RequestConfirmationLlmRequestProcessor extends import_base_llm_processor.B
372
380
  const REQUEST_CONFIRMATION_LLM_REQUEST_PROCESSOR = new RequestConfirmationLlmRequestProcessor();
373
381
  class CodeExecutionRequestProcessor extends import_base_llm_processor.BaseLlmRequestProcessor {
374
382
  async *runAsync(invocationContext, llmRequest) {
375
- if (!(invocationContext.agent instanceof LlmAgent)) {
383
+ if (!isLlmAgent(invocationContext.agent)) {
376
384
  return;
377
385
  }
378
386
  if (!invocationContext.agent.codeExecutor) {
@@ -386,7 +394,7 @@ class CodeExecutionRequestProcessor extends import_base_llm_processor.BaseLlmReq
386
394
  }
387
395
  for (const content of llmRequest.contents) {
388
396
  const delimeters = invocationContext.agent.codeExecutor.codeBlockDelimiters.length ? invocationContext.agent.codeExecutor.codeBlockDelimiters[0] : ["", ""];
389
- const codeExecutionParts = (0, import_code_execution_utils.convertCodeExecutionParts)(
397
+ (0, import_code_execution_utils.convertCodeExecutionParts)(
390
398
  content,
391
399
  delimeters,
392
400
  invocationContext.agent.codeExecutor.executionResultDelimiters
@@ -596,7 +604,7 @@ async function* runPostProcessor(invocationContext, llmResponse) {
596
604
  codeExecutorContext,
597
605
  codeExecutionResult
598
606
  );
599
- llmResponse.content = null;
607
+ llmResponse.content = void 0;
600
608
  }
601
609
  function extractAndReplaceInlineFiles(codeExecutorContext, llmRequest) {
602
610
  var _a2;
@@ -722,8 +730,8 @@ class LlmAgent extends (_b = import_base_agent.BaseAgent, _a = LLM_AGENT_SIGNATU
722
730
  this.disallowTransferToParent = (_d = config.disallowTransferToParent) != null ? _d : false;
723
731
  this.disallowTransferToPeers = (_e = config.disallowTransferToPeers) != null ? _e : false;
724
732
  this.includeContents = (_f = config.includeContents) != null ? _f : "default";
725
- this.inputSchema = config.inputSchema;
726
- this.outputSchema = config.outputSchema;
733
+ this.inputSchema = (0, import_simple_zod_to_json.isZodObject)(config.inputSchema) ? (0, import_simple_zod_to_json.zodObjectToSchema)(config.inputSchema) : config.inputSchema;
734
+ this.outputSchema = (0, import_simple_zod_to_json.isZodObject)(config.outputSchema) ? (0, import_simple_zod_to_json.zodObjectToSchema)(config.outputSchema) : config.outputSchema;
727
735
  this.outputKey = config.outputKey;
728
736
  this.beforeModelCallback = config.beforeModelCallback;
729
737
  this.afterModelCallback = config.afterModelCallback;
@@ -768,16 +776,6 @@ class LlmAgent extends (_b = import_base_agent.BaseAgent, _a = LLM_AGENT_SIGNATU
768
776
  this.disallowTransferToParent = true;
769
777
  this.disallowTransferToPeers = true;
770
778
  }
771
- if (this.subAgents && this.subAgents.length > 0) {
772
- throw new Error(
773
- `Invalid config for agent ${this.name}: if outputSchema is set, subAgents must be empty to disable agent transfer.`
774
- );
775
- }
776
- if (this.tools && this.tools.length > 0) {
777
- throw new Error(
778
- `Invalid config for agent ${this.name}: if outputSchema is set, tools must be empty`
779
- );
780
- }
781
779
  }
782
780
  }
783
781
  /**
@@ -809,12 +807,12 @@ class LlmAgent extends (_b = import_base_agent.BaseAgent, _a = LLM_AGENT_SIGNATU
809
807
  * @param context The context to retrieve the session state.
810
808
  * @returns The resolved instruction field.
811
809
  */
812
- async canonicalInstruction(context) {
810
+ async canonicalInstruction(context2) {
813
811
  if (typeof this.instruction === "string") {
814
812
  return { instruction: this.instruction, requireStateInjection: true };
815
813
  }
816
814
  return {
817
- instruction: await this.instruction(context),
815
+ instruction: await this.instruction(context2),
818
816
  requireStateInjection: false
819
817
  };
820
818
  }
@@ -825,12 +823,15 @@ class LlmAgent extends (_b = import_base_agent.BaseAgent, _a = LLM_AGENT_SIGNATU
825
823
  * @param context The context to retrieve the session state.
826
824
  * @returns The resolved globalInstruction field.
827
825
  */
828
- async canonicalGlobalInstruction(context) {
826
+ async canonicalGlobalInstruction(context2) {
829
827
  if (typeof this.globalInstruction === "string") {
830
- return { instruction: this.globalInstruction, requireStateInjection: true };
828
+ return {
829
+ instruction: this.globalInstruction,
830
+ requireStateInjection: true
831
+ };
831
832
  }
832
833
  return {
833
- instruction: await this.globalInstruction(context),
834
+ instruction: await this.globalInstruction(context2),
834
835
  requireStateInjection: false
835
836
  };
836
837
  }
@@ -839,10 +840,10 @@ class LlmAgent extends (_b = import_base_agent.BaseAgent, _a = LLM_AGENT_SIGNATU
839
840
  *
840
841
  * This method is only for use by Agent Development Kit.
841
842
  */
842
- async canonicalTools(context) {
843
+ async canonicalTools(context2) {
843
844
  const resolvedTools = [];
844
845
  for (const toolUnion of this.tools) {
845
- const tools = await convertToolUnionToTools(toolUnion, context);
846
+ const tools = await convertToolUnionToTools(toolUnion, context2);
846
847
  resolvedTools.push(...tools);
847
848
  }
848
849
  return resolvedTools;
@@ -946,10 +947,10 @@ class LlmAgent extends (_b = import_base_agent.BaseAgent, _a = LLM_AGENT_SIGNATU
946
947
  }
947
948
  event.actions.stateDelta[this.outputKey] = result;
948
949
  }
949
- async *runAsyncImpl(context) {
950
+ async *runAsyncImpl(context2) {
950
951
  while (true) {
951
952
  let lastEvent = void 0;
952
- for await (const event of this.runOneStepAsync(context)) {
953
+ for await (const event of this.runOneStepAsync(context2)) {
953
954
  lastEvent = event;
954
955
  this.maybeSaveOutputToState(event);
955
956
  yield event;
@@ -963,19 +964,20 @@ class LlmAgent extends (_b = import_base_agent.BaseAgent, _a = LLM_AGENT_SIGNATU
963
964
  }
964
965
  }
965
966
  }
966
- async *runLiveImpl(context) {
967
- for await (const event of this.runLiveFlow(context)) {
967
+ async *runLiveImpl(context2) {
968
+ for await (const event of this.runLiveFlow(context2)) {
968
969
  this.maybeSaveOutputToState(event);
969
970
  yield event;
970
971
  }
971
- if (context.endInvocation) {
972
+ if (context2.endInvocation) {
972
973
  return;
973
974
  }
974
975
  }
975
976
  // --------------------------------------------------------------------------
976
977
  // #START LlmFlow Logic
977
978
  // --------------------------------------------------------------------------
978
- async *runLiveFlow(invocationContext) {
979
+ // eslint-disable-next-line require-yield
980
+ async *runLiveFlow(_invocationContext) {
979
981
  await Promise.resolve();
980
982
  throw new Error("LlmAgent.runLiveFlow not implemented");
981
983
  }
@@ -1011,25 +1013,42 @@ class LlmAgent extends (_b = import_base_agent.BaseAgent, _a = LLM_AGENT_SIGNATU
1011
1013
  author: this.name,
1012
1014
  branch: invocationContext.branch
1013
1015
  });
1014
- for await (const llmResponse of this.callLlmAsync(
1015
- invocationContext,
1016
- llmRequest,
1017
- modelResponseEvent
1018
- )) {
1019
- for await (const event of this.postprocess(
1020
- invocationContext,
1021
- llmRequest,
1022
- llmResponse,
1023
- modelResponseEvent
1024
- )) {
1025
- modelResponseEvent.id = (0, import_event.createNewEventId)();
1026
- modelResponseEvent.timestamp = (/* @__PURE__ */ new Date()).getTime();
1027
- yield event;
1016
+ const span = import_tracing.tracer.startSpan("call_llm");
1017
+ const ctx = import_api.trace.setSpan(import_api.context.active(), span);
1018
+ yield* (0, import_tracing.runAsyncGeneratorWithOtelContext)(
1019
+ ctx,
1020
+ this,
1021
+ async function* () {
1022
+ const responsesGenerator = async function* () {
1023
+ for await (const llmResponse of this.callLlmAsync(
1024
+ invocationContext,
1025
+ llmRequest,
1026
+ modelResponseEvent
1027
+ )) {
1028
+ for await (const event of this.postprocess(
1029
+ invocationContext,
1030
+ llmRequest,
1031
+ llmResponse,
1032
+ modelResponseEvent
1033
+ )) {
1034
+ modelResponseEvent.id = (0, import_event.createNewEventId)();
1035
+ modelResponseEvent.timestamp = (/* @__PURE__ */ new Date()).getTime();
1036
+ yield event;
1037
+ }
1038
+ }
1039
+ };
1040
+ yield* this.runAndHandleError(
1041
+ responsesGenerator.call(this),
1042
+ invocationContext,
1043
+ llmRequest,
1044
+ modelResponseEvent
1045
+ );
1028
1046
  }
1029
- }
1047
+ );
1048
+ span.end();
1030
1049
  }
1031
1050
  async *postprocess(invocationContext, llmRequest, llmResponse, modelResponseEvent) {
1032
- var _a2;
1051
+ var _a2, _b2;
1033
1052
  for (const processor of this.responseProcessors) {
1034
1053
  for await (const event of processor.runAsync(
1035
1054
  invocationContext,
@@ -1058,6 +1077,10 @@ class LlmAgent extends (_b = import_base_agent.BaseAgent, _a = LLM_AGENT_SIGNATU
1058
1077
  if (!((_a2 = (0, import_event.getFunctionCalls)(mergedEvent)) == null ? void 0 : _a2.length)) {
1059
1078
  return;
1060
1079
  }
1080
+ if ((_b2 = invocationContext.runConfig) == null ? void 0 : _b2.pauseOnToolCalls) {
1081
+ invocationContext.endInvocation = true;
1082
+ return;
1083
+ }
1061
1084
  const functionResponseEvent = await (0, import_functions.handleFunctionCallsAsync)({
1062
1085
  invocationContext,
1063
1086
  functionCallEvent: mergedEvent,
@@ -1082,6 +1105,8 @@ class LlmAgent extends (_b = import_base_agent.BaseAgent, _a = LLM_AGENT_SIGNATU
1082
1105
  });
1083
1106
  if (toolConfirmationEvent) {
1084
1107
  yield toolConfirmationEvent;
1108
+ invocationContext.endInvocation = true;
1109
+ return;
1085
1110
  }
1086
1111
  yield functionResponseEvent;
1087
1112
  const nextAgentName = functionResponseEvent.actions.transferToAgent;
@@ -1138,12 +1163,13 @@ class LlmAgent extends (_b = import_base_agent.BaseAgent, _a = LLM_AGENT_SIGNATU
1138
1163
  /* stream= */
1139
1164
  ((_e = invocationContext.runConfig) == null ? void 0 : _e.streamingMode) === import_run_config.StreamingMode.SSE
1140
1165
  );
1141
- for await (const llmResponse of this.runAndHandleError(
1142
- responsesGenerator,
1143
- invocationContext,
1144
- llmRequest,
1145
- modelResponseEvent
1146
- )) {
1166
+ for await (const llmResponse of responsesGenerator) {
1167
+ (0, import_tracing.traceCallLlm)({
1168
+ invocationContext,
1169
+ eventId: modelResponseEvent.id,
1170
+ llmRequest,
1171
+ llmResponse
1172
+ });
1147
1173
  const alteredLlmResponse = await this.handleAfterModelCallback(
1148
1174
  invocationContext,
1149
1175
  llmResponse,
@@ -1218,11 +1244,29 @@ class LlmAgent extends (_b = import_base_agent.BaseAgent, _a = LLM_AGENT_SIGNATU
1218
1244
  if (onModelErrorCallbackResponse) {
1219
1245
  yield onModelErrorCallbackResponse;
1220
1246
  } else {
1221
- const errorResponse = JSON.parse(modelError.message);
1222
- yield {
1223
- errorCode: String(errorResponse.error.code),
1224
- errorMessage: errorResponse.error.message
1225
- };
1247
+ let errorCode = "UNKNOWN_ERROR";
1248
+ let errorMessage = modelError.message;
1249
+ try {
1250
+ const errorResponse = JSON.parse(modelError.message);
1251
+ if (errorResponse == null ? void 0 : errorResponse.error) {
1252
+ errorCode = String(errorResponse.error.code || "UNKNOWN_ERROR");
1253
+ errorMessage = errorResponse.error.message || errorMessage;
1254
+ }
1255
+ } catch {
1256
+ }
1257
+ if (modelResponseEvent.actions) {
1258
+ yield (0, import_event.createEvent)({
1259
+ invocationId: invocationContext.invocationId,
1260
+ author: this.name,
1261
+ errorCode,
1262
+ errorMessage
1263
+ });
1264
+ } else {
1265
+ yield {
1266
+ errorCode,
1267
+ errorMessage
1268
+ };
1269
+ }
1226
1270
  }
1227
1271
  } else {
1228
1272
  import_logger.logger.error("Unknown error during response generation", modelError);
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright 2025 Google LLC
3
+ * Copyright 2026 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
 
@@ -68,7 +68,8 @@ class LoopAgent extends (_b = import_base_agent.BaseAgent, _a = LOOP_AGENT_SIGNA
68
68
  }
69
69
  return;
70
70
  }
71
- async *runLiveImpl(context) {
71
+ // eslint-disable-next-line require-yield
72
+ async *runLiveImpl(_context) {
72
73
  throw new Error("This is not supported yet for LoopAgent.");
73
74
  }
74
75
  }
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright 2025 Google LLC
3
+ * Copyright 2026 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
 
@@ -50,15 +50,14 @@ class ParallelAgent extends (_b = import_base_agent.BaseAgent, _a = PARALLEL_AGE
50
50
  }
51
51
  async *runAsyncImpl(context) {
52
52
  const agentRuns = this.subAgents.map(
53
- (subAgent) => subAgent.runAsync(
54
- createBranchCtxForSubAgent(this, subAgent, context)
55
- )
53
+ (subAgent) => subAgent.runAsync(createBranchCtxForSubAgent(this, subAgent, context))
56
54
  );
57
55
  for await (const event of mergeAgentRuns(agentRuns)) {
58
56
  yield event;
59
57
  }
60
58
  }
61
- async *runLiveImpl(context) {
59
+ // eslint-disable-next-line require-yield
60
+ async *runLiveImpl(_context) {
62
61
  throw new Error("This is not supported yet for ParallelAgent.");
63
62
  }
64
63
  }
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright 2025 Google LLC
3
+ * Copyright 2026 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
 
@@ -49,6 +49,18 @@ class ReadonlyContext {
49
49
  get invocationId() {
50
50
  return this.invocationContext.invocationId;
51
51
  }
52
+ /**
53
+ * The user ID of the current session.
54
+ */
55
+ get userId() {
56
+ return this.invocationContext.userId;
57
+ }
58
+ /**
59
+ * The ID of the current session.
60
+ */
61
+ get sessionId() {
62
+ return this.invocationContext.session.id;
63
+ }
52
64
  /**
53
65
  * The current agent name.
54
66
  */
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright 2025 Google LLC
3
+ * Copyright 2026 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
 
@@ -47,6 +47,7 @@ function createRunConfig(params = {}) {
47
47
  enableAffectiveDialog: false,
48
48
  streamingMode: "none" /* NONE */,
49
49
  maxLlmCalls: validateMaxLlmCalls(params.maxLlmCalls || 500),
50
+ pauseOnToolCalls: false,
50
51
  ...params
51
52
  };
52
53
  }
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright 2025 Google LLC
3
+ * Copyright 2026 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
 
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright 2025 Google LLC
3
+ * Copyright 2026 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
 
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright 2025 Google LLC
3
+ * Copyright 2026 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6