@google/adk 1.4.0 → 1.6.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 (213) hide show
  1. package/dist/cjs/a2a/a2a_remote_agent.js +12 -2
  2. package/dist/cjs/a2a/agent_to_a2a.js +18 -3
  3. package/dist/cjs/a2a/auth.js +65 -0
  4. package/dist/cjs/a2a/event_converter_utils.js +47 -18
  5. package/dist/cjs/a2a/metadata_converter_utils.js +1 -1
  6. package/dist/cjs/agents/base_agent.js +39 -0
  7. package/dist/cjs/agents/functions.js +26 -28
  8. package/dist/cjs/agents/llm_agent.js +4 -2
  9. package/dist/cjs/agents/loop_agent.js +15 -3
  10. package/dist/cjs/agents/processors/basic_llm_request_processor.js +3 -2
  11. package/dist/cjs/agents/processors/content_processor_utils.js +2 -1
  12. package/dist/cjs/agents/processors/content_request_processor.js +2 -21
  13. package/dist/cjs/agents/processors/instructions_llm_request_processor.js +3 -1
  14. package/dist/cjs/agents/routed_agent.js +31 -0
  15. package/dist/cjs/agents/run_config.js +3 -2
  16. package/dist/cjs/artifacts/in_memory_artifact_service.js +17 -9
  17. package/dist/cjs/auth/credential_service/in_memory_credential_service.js +14 -3
  18. package/dist/cjs/code_executors/unsafe_local_code_executor.js +23 -12
  19. package/dist/cjs/common.js +35 -0
  20. package/dist/cjs/context/agent_controlled_context_compactor.js +2 -11
  21. package/dist/cjs/context/anchored_context_compactor.js +127 -0
  22. package/dist/cjs/context/compaction_utils.js +64 -0
  23. package/dist/cjs/context/token_based_context_compactor.js +13 -44
  24. package/dist/cjs/events/compacted_event.js +9 -3
  25. package/dist/cjs/events/event.js +28 -0
  26. package/dist/cjs/index.js +7 -0
  27. package/dist/cjs/integrations/agent_registry/agent_registry_mcp_toolset.js +9 -1
  28. package/dist/cjs/memory/in_memory_memory_service.js +13 -2
  29. package/dist/cjs/memory/vertex_ai_memory_bank_service.js +3 -0
  30. package/dist/cjs/plugins/base_plugin.js +4 -2
  31. package/dist/cjs/plugins/global_instruction_plugin.js +97 -0
  32. package/dist/cjs/runner/runner.js +69 -23
  33. package/dist/cjs/sessions/base_session_service.js +8 -3
  34. package/dist/cjs/sessions/in_memory_session_service.js +8 -8
  35. package/dist/cjs/sessions/vertex_ai_session_service.js +22 -10
  36. package/dist/cjs/skills/loader.js +40 -6
  37. package/dist/cjs/tools/enterprise_web_search_tool.js +81 -0
  38. package/dist/cjs/tools/example_tool.js +68 -0
  39. package/dist/cjs/tools/get_user_choice_tool.js +53 -0
  40. package/dist/cjs/tools/load_web_page.js +250 -0
  41. package/dist/cjs/tools/mcp/load_mcp_resource_tool.js +140 -0
  42. package/dist/cjs/tools/mcp/mcp_session_manager.js +35 -21
  43. package/dist/cjs/tools/mcp/mcp_toolset.js +63 -0
  44. package/dist/cjs/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +13 -10
  45. package/dist/cjs/tools/request_input_tool.js +54 -0
  46. package/dist/cjs/tools/skill/run_skill_inline_script_tool.js +54 -4
  47. package/dist/cjs/tools/skill/skill_toolset.js +4 -2
  48. package/dist/cjs/utils/branch_trie.js +41 -0
  49. package/dist/cjs/utils/crypto_shim.js +43 -0
  50. package/dist/cjs/utils/env_aware_utils.js +15 -13
  51. package/dist/cjs/utils/error_utils.js +120 -0
  52. package/dist/cjs/utils/file_utils.js +5 -2
  53. package/dist/cjs/utils/output_schema_utils.js +43 -0
  54. package/dist/cjs/utils/streaming_utils.js +5 -5
  55. package/dist/cjs/utils/vertex_ai_utils.js +3 -0
  56. package/dist/cjs/version.js +1 -1
  57. package/dist/esm/a2a/a2a_remote_agent.js +12 -2
  58. package/dist/esm/a2a/agent_to_a2a.js +18 -3
  59. package/dist/esm/a2a/auth.js +37 -0
  60. package/dist/esm/a2a/event_converter_utils.js +47 -18
  61. package/dist/esm/a2a/metadata_converter_utils.js +1 -1
  62. package/dist/esm/agents/base_agent.js +39 -0
  63. package/dist/esm/agents/functions.js +27 -24
  64. package/dist/esm/agents/llm_agent.js +6 -4
  65. package/dist/esm/agents/loop_agent.js +15 -3
  66. package/dist/esm/agents/processors/basic_llm_request_processor.js +3 -2
  67. package/dist/esm/agents/processors/content_processor_utils.js +2 -1
  68. package/dist/esm/agents/processors/content_request_processor.js +2 -21
  69. package/dist/esm/agents/processors/instructions_llm_request_processor.js +3 -1
  70. package/dist/esm/agents/routed_agent.js +31 -0
  71. package/dist/esm/agents/run_config.js +3 -2
  72. package/dist/esm/artifacts/in_memory_artifact_service.js +17 -9
  73. package/dist/esm/auth/credential_service/in_memory_credential_service.js +14 -3
  74. package/dist/esm/code_executors/unsafe_local_code_executor.js +22 -11
  75. package/dist/esm/common.js +29 -1
  76. package/dist/esm/context/agent_controlled_context_compactor.js +2 -11
  77. package/dist/esm/context/anchored_context_compactor.js +99 -0
  78. package/dist/esm/context/compaction_utils.js +38 -0
  79. package/dist/esm/context/token_based_context_compactor.js +16 -44
  80. package/dist/esm/events/compacted_event.js +7 -2
  81. package/dist/esm/events/event.js +24 -0
  82. package/dist/esm/index.js +8 -1
  83. package/dist/esm/integrations/agent_registry/agent_registry_mcp_toolset.js +9 -1
  84. package/dist/esm/memory/in_memory_memory_service.js +13 -2
  85. package/dist/esm/memory/vertex_ai_memory_bank_service.js +7 -1
  86. package/dist/esm/plugins/base_plugin.js +4 -2
  87. package/dist/esm/plugins/global_instruction_plugin.js +69 -0
  88. package/dist/esm/runner/runner.js +69 -23
  89. package/dist/esm/sessions/base_session_service.js +8 -3
  90. package/dist/esm/sessions/in_memory_session_service.js +8 -8
  91. package/dist/esm/sessions/vertex_ai_session_service.js +26 -11
  92. package/dist/esm/skills/loader.js +40 -6
  93. package/dist/esm/tools/enterprise_web_search_tool.js +55 -0
  94. package/dist/esm/tools/example_tool.js +42 -0
  95. package/dist/esm/tools/get_user_choice_tool.js +25 -0
  96. package/dist/esm/tools/load_web_page.js +221 -0
  97. package/dist/esm/tools/mcp/load_mcp_resource_tool.js +114 -0
  98. package/dist/esm/tools/mcp/mcp_session_manager.js +35 -21
  99. package/dist/esm/tools/mcp/mcp_toolset.js +63 -0
  100. package/dist/esm/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +13 -10
  101. package/dist/esm/tools/request_input_tool.js +26 -0
  102. package/dist/esm/tools/skill/run_skill_inline_script_tool.js +53 -4
  103. package/dist/esm/tools/skill/skill_toolset.js +4 -2
  104. package/dist/esm/utils/branch_trie.js +13 -0
  105. package/dist/esm/utils/crypto_shim.js +15 -0
  106. package/dist/esm/utils/env_aware_utils.js +15 -13
  107. package/dist/esm/utils/error_utils.js +92 -0
  108. package/dist/esm/utils/file_utils.js +5 -2
  109. package/dist/esm/utils/output_schema_utils.js +15 -0
  110. package/dist/esm/utils/streaming_utils.js +1 -1
  111. package/dist/esm/utils/vertex_ai_utils.js +2 -0
  112. package/dist/esm/version.js +1 -1
  113. package/dist/types/a2a/a2a_remote_agent.d.ts +5 -1
  114. package/dist/types/a2a/agent_to_a2a.d.ts +38 -0
  115. package/dist/types/a2a/auth.d.ts +30 -0
  116. package/dist/types/a2a/event_converter_utils.d.ts +4 -1
  117. package/dist/types/agents/base_agent.d.ts +29 -1
  118. package/dist/types/agents/functions.d.ts +1 -9
  119. package/dist/types/agents/llm_agent.d.ts +5 -1
  120. package/dist/types/agents/loop_agent.d.ts +2 -2
  121. package/dist/types/agents/routed_agent.d.ts +24 -1
  122. package/dist/types/agents/run_config.d.ts +1 -1
  123. package/dist/types/auth/credential_service/in_memory_credential_service.d.ts +11 -0
  124. package/dist/types/code_executors/unsafe_local_code_executor.d.ts +5 -1
  125. package/dist/types/common.d.ts +11 -2
  126. package/dist/types/context/agent_controlled_context_compactor.d.ts +0 -1
  127. package/dist/types/context/anchored_context_compactor.d.ts +35 -0
  128. package/dist/types/context/compaction_utils.d.ts +23 -0
  129. package/dist/types/context/token_based_context_compactor.d.ts +0 -1
  130. package/dist/types/events/compacted_event.d.ts +10 -0
  131. package/dist/types/events/event.d.ts +13 -0
  132. package/dist/types/index.d.ts +5 -3
  133. package/dist/types/memory/in_memory_memory_service.d.ts +11 -0
  134. package/dist/types/plugins/base_plugin.d.ts +4 -2
  135. package/dist/types/plugins/global_instruction_plugin.d.ts +38 -0
  136. package/dist/types/runner/runner.d.ts +1 -1
  137. package/dist/types/sessions/base_session_service.d.ts +8 -0
  138. package/dist/types/sessions/in_memory_session_service.d.ts +9 -0
  139. package/dist/types/sessions/vertex_ai_session_service.d.ts +19 -1
  140. package/dist/types/skills/loader.d.ts +5 -0
  141. package/dist/types/tools/enterprise_web_search_tool.d.ts +26 -0
  142. package/dist/types/tools/example_tool.d.ts +21 -0
  143. package/dist/types/tools/get_user_choice_tool.d.ts +14 -0
  144. package/dist/types/tools/load_web_page.d.ts +33 -0
  145. package/dist/types/tools/mcp/load_mcp_resource_tool.d.ts +26 -0
  146. package/dist/types/tools/mcp/mcp_toolset.d.ts +27 -0
  147. package/dist/types/tools/request_input_tool.d.ts +15 -0
  148. package/dist/types/tools/skill/run_skill_inline_script_tool.d.ts +25 -0
  149. package/dist/types/tools/skill/skill_toolset.d.ts +9 -0
  150. package/dist/types/utils/branch_trie.d.ts +14 -0
  151. package/dist/types/utils/crypto_shim.d.ts +16 -0
  152. package/dist/types/utils/env_aware_utils.d.ts +23 -0
  153. package/dist/types/utils/error_utils.d.ts +18 -0
  154. package/dist/types/utils/output_schema_utils.d.ts +18 -0
  155. package/dist/types/utils/vertex_ai_utils.d.ts +1 -0
  156. package/dist/types/version.d.ts +1 -1
  157. package/dist/web/a2a/a2a_remote_agent.js +12 -2
  158. package/dist/web/a2a/agent_to_a2a.js +18 -3
  159. package/dist/web/a2a/auth.js +37 -0
  160. package/dist/web/a2a/event_converter_utils.js +47 -18
  161. package/dist/web/a2a/metadata_converter_utils.js +1 -1
  162. package/dist/web/agents/base_agent.js +39 -0
  163. package/dist/web/agents/functions.js +27 -24
  164. package/dist/web/agents/llm_agent.js +6 -4
  165. package/dist/web/agents/loop_agent.js +27 -3
  166. package/dist/web/agents/processors/basic_llm_request_processor.js +3 -2
  167. package/dist/web/agents/processors/content_processor_utils.js +2 -1
  168. package/dist/web/agents/processors/content_request_processor.js +2 -21
  169. package/dist/web/agents/processors/instructions_llm_request_processor.js +3 -1
  170. package/dist/web/agents/routed_agent.js +31 -0
  171. package/dist/web/agents/run_config.js +8 -3
  172. package/dist/web/artifacts/in_memory_artifact_service.js +17 -9
  173. package/dist/web/auth/credential_service/in_memory_credential_service.js +14 -3
  174. package/dist/web/code_executors/unsafe_local_code_executor.js +22 -11
  175. package/dist/web/common.js +29 -1
  176. package/dist/web/context/agent_controlled_context_compactor.js +2 -11
  177. package/dist/web/context/anchored_context_compactor.js +117 -0
  178. package/dist/web/context/compaction_utils.js +38 -0
  179. package/dist/web/context/token_based_context_compactor.js +16 -44
  180. package/dist/web/events/compacted_event.js +7 -2
  181. package/dist/web/events/event.js +24 -0
  182. package/dist/web/index.js +8 -1
  183. package/dist/web/integrations/agent_registry/agent_registry_mcp_toolset.js +9 -1
  184. package/dist/web/memory/in_memory_memory_service.js +13 -2
  185. package/dist/web/memory/vertex_ai_memory_bank_service.js +7 -1
  186. package/dist/web/plugins/base_plugin.js +4 -2
  187. package/dist/web/plugins/global_instruction_plugin.js +67 -0
  188. package/dist/web/runner/runner.js +65 -22
  189. package/dist/web/sessions/base_session_service.js +8 -3
  190. package/dist/web/sessions/in_memory_session_service.js +8 -8
  191. package/dist/web/sessions/vertex_ai_session_service.js +24 -11
  192. package/dist/web/skills/loader.js +40 -6
  193. package/dist/web/tools/enterprise_web_search_tool.js +55 -0
  194. package/dist/web/tools/example_tool.js +42 -0
  195. package/dist/web/tools/get_user_choice_tool.js +25 -0
  196. package/dist/web/tools/load_web_page.js +221 -0
  197. package/dist/web/tools/mcp/load_mcp_resource_tool.js +107 -0
  198. package/dist/web/tools/mcp/mcp_session_manager.js +35 -21
  199. package/dist/web/tools/mcp/mcp_toolset.js +63 -0
  200. package/dist/web/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +13 -10
  201. package/dist/web/tools/request_input_tool.js +26 -0
  202. package/dist/web/tools/skill/run_skill_inline_script_tool.js +51 -4
  203. package/dist/web/tools/skill/skill_toolset.js +4 -2
  204. package/dist/web/utils/branch_trie.js +13 -0
  205. package/dist/web/utils/crypto_shim.js +15 -0
  206. package/dist/web/utils/env_aware_utils.js +15 -13
  207. package/dist/web/utils/error_utils.js +92 -0
  208. package/dist/web/utils/file_utils.js +5 -2
  209. package/dist/web/utils/output_schema_utils.js +15 -0
  210. package/dist/web/utils/streaming_utils.js +1 -1
  211. package/dist/web/utils/vertex_ai_utils.js +2 -0
  212. package/dist/web/version.js +1 -1
  213. package/package.json +1 -1
@@ -9,11 +9,11 @@ import { createUserContent } from "@google/genai";
9
9
  import { isEmpty } from "lodash-es";
10
10
  import {
11
11
  createEvent,
12
+ generateClientFunctionCallId,
12
13
  getFunctionCalls,
13
14
  getFunctionResponses
14
15
  } from "../events/event.js";
15
16
  import { mergeEventActions } from "../events/event_actions.js";
16
- import { randomUUID } from "../utils/env_aware_utils.js";
17
17
  import { logger } from "../utils/logger.js";
18
18
  import { Context } from "./context.js";
19
19
  import {
@@ -21,7 +21,11 @@ import {
21
21
  tracer,
22
22
  traceToolCall
23
23
  } from "../telemetry/tracing.js";
24
- const AF_FUNCTION_CALL_ID_PREFIX = "adk-";
24
+ import {
25
+ AF_FUNCTION_CALL_ID_PREFIX,
26
+ generateClientFunctionCallId as generateClientFunctionCallId2,
27
+ populateClientFunctionCallId
28
+ } from "../events/event.js";
25
29
  const REQUEST_EUC_FUNCTION_CALL_NAME = "adk_request_credential";
26
30
  const REQUEST_CONFIRMATION_FUNCTION_CALL_NAME = "adk_request_confirmation";
27
31
  const functionsExportedForTestingOnly = {
@@ -29,20 +33,6 @@ const functionsExportedForTestingOnly = {
29
33
  generateAuthEvent,
30
34
  generateRequestConfirmationEvent
31
35
  };
32
- function generateClientFunctionCallId() {
33
- return `${AF_FUNCTION_CALL_ID_PREFIX}${randomUUID()}`;
34
- }
35
- function populateClientFunctionCallId(modelResponseEvent) {
36
- const functionCalls = getFunctionCalls(modelResponseEvent);
37
- if (!functionCalls) {
38
- return;
39
- }
40
- for (const functionCall of functionCalls) {
41
- if (!functionCall.id) {
42
- functionCall.id = generateClientFunctionCallId();
43
- }
44
- }
45
- }
46
36
  function getLongRunningFunctionCalls(functionCalls, toolsDict) {
47
37
  const longRunningToolIds = /* @__PURE__ */ new Set();
48
38
  for (const functionCall of functionCalls) {
@@ -195,6 +185,18 @@ async function handleFunctionCallsAsync({
195
185
  toolConfirmationDict
196
186
  });
197
187
  }
188
+ function normalizeCallbackResponse(response) {
189
+ if (response == null) {
190
+ return void 0;
191
+ }
192
+ if (typeof response !== "object") {
193
+ return { result: response };
194
+ }
195
+ if (Array.isArray(response)) {
196
+ return { results: response };
197
+ }
198
+ return response;
199
+ }
198
200
  async function handleFunctionCallList({
199
201
  invocationContext,
200
202
  functionCalls,
@@ -241,6 +243,7 @@ async function handleFunctionCallList({
241
243
  }
242
244
  }
243
245
  }
246
+ functionResponse = normalizeCallbackResponse(functionResponse);
244
247
  if (functionResponse == null) {
245
248
  try {
246
249
  functionResponse = await callToolAsync(tool, functionArgs, toolContext);
@@ -252,8 +255,8 @@ async function handleFunctionCallList({
252
255
  toolContext,
253
256
  error: e
254
257
  });
255
- if (onToolErrorResponse) {
256
- functionResponse = onToolErrorResponse;
258
+ if (onToolErrorResponse != null) {
259
+ functionResponse = normalizeCallbackResponse(onToolErrorResponse);
257
260
  } else {
258
261
  functionResponseError = e.message;
259
262
  }
@@ -282,17 +285,17 @@ async function handleFunctionCallList({
282
285
  }
283
286
  }
284
287
  if (alteredFunctionResponse != null) {
285
- functionResponse = alteredFunctionResponse;
288
+ functionResponse = normalizeCallbackResponse(alteredFunctionResponse);
286
289
  }
287
- if (tool.isLongRunning && !functionResponse) {
290
+ if (tool.isLongRunning && functionResponse == null) {
288
291
  continue;
289
292
  }
290
293
  if (functionResponseError) {
291
294
  functionResponse = { error: functionResponseError };
292
- } else if (typeof functionResponse !== "object" || functionResponse == null) {
295
+ } else if (functionResponse == null) {
293
296
  functionResponse = { result: functionResponse };
294
- } else if (Array.isArray(functionResponse)) {
295
- functionResponse = { results: functionResponse };
297
+ } else {
298
+ functionResponse = normalizeCallbackResponse(functionResponse);
296
299
  }
297
300
  const functionResponseEvent = createEvent({
298
301
  invocationId: invocationContext.invocationId,
@@ -420,7 +423,7 @@ export {
420
423
  findMatchingFunctionCall,
421
424
  functionsExportedForTestingOnly,
422
425
  generateAuthEvent,
423
- generateClientFunctionCallId,
426
+ generateClientFunctionCallId2 as generateClientFunctionCallId,
424
427
  generateRequestConfirmationEvent,
425
428
  getLongRunningFunctionCalls,
426
429
  handleFunctionCallList,
@@ -13,12 +13,14 @@ import {
13
13
  createNewEventId,
14
14
  getFunctionCalls,
15
15
  getFunctionResponses,
16
- isFinalResponse
16
+ isFinalResponse,
17
+ populateClientFunctionCallId
17
18
  } from "../events/event.js";
18
19
  import { isBaseLlm } from "../models/base_llm.js";
19
20
  import { LLMRegistry } from "../models/registry.js";
20
21
  import { isBaseTool } from "../tools/base_tool.js";
21
22
  import { logger } from "../utils/logger.js";
23
+ import { canUseOutputSchemaWithTools } from "../utils/output_schema_utils.js";
22
24
  import { Context } from "./context.js";
23
25
  import {
24
26
  runAsyncGeneratorWithOtelContext,
@@ -31,8 +33,7 @@ import {
31
33
  generateAuthEvent,
32
34
  generateRequestConfirmationEvent,
33
35
  getLongRunningFunctionCalls,
34
- handleFunctionCallsAsync,
35
- populateClientFunctionCallId
36
+ handleFunctionCallsAsync
36
37
  } from "./functions.js";
37
38
  import { AUTH_PREPROCESSOR } from "../auth/auth_preprocessor.js";
38
39
  import { AGENT_TRANSFER_LLM_REQUEST_PROCESSOR } from "./processors/agent_transfer_llm_request_processor.js";
@@ -183,6 +184,7 @@ class LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNATURE_SYMBOL, _b) {
183
184
  * This method is only for use by Agent Development Kit.
184
185
  * @param context The context to retrieve the session state.
185
186
  * @returns The resolved globalInstruction field.
187
+ * @deprecated Use GlobalInstructionPlugin instead.
186
188
  */
187
189
  async canonicalGlobalInstruction(context2) {
188
190
  if (typeof this.globalInstruction === "string") {
@@ -391,7 +393,7 @@ class LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNATURE_SYMBOL, _b) {
391
393
  }
392
394
  }
393
395
  const allTools = [...this.tools];
394
- if (this.outputSchema && allTools.length > 0) {
396
+ if (this.outputSchema && allTools.length > 0 && !canUseOutputSchemaWithTools(this.canonicalModel.model)) {
395
397
  const setModelResponseTool = new FunctionTool({
396
398
  name: "set_model_response",
397
399
  description: "Call this tool to submit your final response conforming to the output schema. Use this tool only when you have collected all the information and are ready to return the final answer.",
@@ -44,9 +44,21 @@ class LoopAgent extends (_b = BaseAgent, _a = LOOP_AGENT_SIGNATURE_SYMBOL, _b) {
44
44
  }
45
45
  return;
46
46
  }
47
- // eslint-disable-next-line require-yield
48
- async *runLiveImpl(_context) {
49
- throw new Error("This is not supported yet for LoopAgent.");
47
+ async *runLiveImpl(context) {
48
+ var _a2, _b2;
49
+ for (let iteration = 0; iteration < this.maxIterations; iteration++) {
50
+ for (const subAgent of this.subAgents) {
51
+ for await (const event of subAgent.runLive(context)) {
52
+ if ((_a2 = context.abortSignal) == null ? void 0 : _a2.aborted) {
53
+ return;
54
+ }
55
+ yield event;
56
+ if ((_b2 = event.actions) == null ? void 0 : _b2.escalate) {
57
+ return;
58
+ }
59
+ }
60
+ }
61
+ }
50
62
  }
51
63
  }
52
64
  export {
@@ -6,6 +6,7 @@ const require = topLevelCreateRequire(import.meta.url);
6
6
  * SPDX-License-Identifier: Apache-2.0
7
7
  */
8
8
  import { setOutputSchema } from "../../models/llm_request.js";
9
+ import { canUseOutputSchemaWithTools } from "../../utils/output_schema_utils.js";
9
10
  import { isLlmAgent } from "../llm_agent.js";
10
11
  import { BaseLlmRequestProcessor } from "./base_llm_processor.js";
11
12
  class BasicLlmRequestProcessor extends BaseLlmRequestProcessor {
@@ -18,14 +19,14 @@ class BasicLlmRequestProcessor extends BaseLlmRequestProcessor {
18
19
  */
19
20
  // eslint-disable-next-line require-yield
20
21
  async *runAsync(invocationContext, llmRequest) {
21
- var _a;
22
+ var _a, _b;
22
23
  const agent = invocationContext.agent;
23
24
  if (!isLlmAgent(agent)) {
24
25
  return;
25
26
  }
26
27
  llmRequest.model = agent.canonicalModel.model;
27
28
  llmRequest.config = { ...(_a = agent.generateContentConfig) != null ? _a : {} };
28
- if (agent.outputSchema && (!agent.tools || agent.tools.length === 0)) {
29
+ if (agent.outputSchema && (!((_b = agent.tools) == null ? void 0 : _b.length) || canUseOutputSchemaWithTools(agent.canonicalModel.model))) {
29
30
  setOutputSchema(llmRequest, agent.outputSchema);
30
31
  }
31
32
  if (invocationContext.runConfig) {
@@ -15,6 +15,7 @@ import {
15
15
  getFunctionCalls,
16
16
  getFunctionResponses
17
17
  } from "../../events/event.js";
18
+ import { isSegmentPrefix } from "../../utils/branch_trie.js";
18
19
  import {
19
20
  AF_FUNCTION_CALL_ID_PREFIX,
20
21
  REQUEST_CONFIRMATION_FUNCTION_CALL_NAME,
@@ -42,7 +43,7 @@ function getContents(events, agentName, currentBranch) {
42
43
  if (!((_a = event.content) == null ? void 0 : _a.role) || ((_c = (_b = event.content.parts) == null ? void 0 : _b[0]) == null ? void 0 : _c.text) === "") {
43
44
  continue;
44
45
  }
45
- if (currentBranch && event.branch && !currentBranch.startsWith(event.branch)) {
46
+ if (currentBranch && event.branch && !isSegmentPrefix(currentBranch, event.branch)) {
46
47
  continue;
47
48
  }
48
49
  if (isAuthEvent(event)) {
@@ -5,7 +5,7 @@ const require = topLevelCreateRequire(import.meta.url);
5
5
  * Copyright 2025 Google LLC
6
6
  * SPDX-License-Identifier: Apache-2.0
7
7
  */
8
- import { isCompactedEvent } from "../../events/compacted_event.js";
8
+ import { getActiveEvents } from "../../context/compaction_utils.js";
9
9
  import { isLlmAgent } from "../llm_agent.js";
10
10
  import {
11
11
  getContents,
@@ -25,26 +25,7 @@ class ContentRequestProcessor {
25
25
  if (!agent || !isLlmAgent(agent)) {
26
26
  return;
27
27
  }
28
- let events = invocationContext.session.events;
29
- const compactedEvents = events.filter(isCompactedEvent);
30
- const latestCompactedEvent = compactedEvents.length > 0 ? compactedEvents.reduce(
31
- (latest, current) => current.endTime > latest.endTime ? current : latest
32
- ) : void 0;
33
- if (latestCompactedEvent) {
34
- const remainingEvents = events.filter((event) => {
35
- if (event === latestCompactedEvent) {
36
- return false;
37
- }
38
- if (isCompactedEvent(event)) {
39
- return false;
40
- }
41
- if (event.timestamp <= latestCompactedEvent.endTime) {
42
- return false;
43
- }
44
- return true;
45
- });
46
- events = [latestCompactedEvent, ...remainingEvents];
47
- }
28
+ const events = getActiveEvents(invocationContext.session.events);
48
29
  if (agent.includeContents === "default") {
49
30
  llmRequest.contents = getContents(
50
31
  events,
@@ -6,6 +6,7 @@ const require = topLevelCreateRequire(import.meta.url);
6
6
  * SPDX-License-Identifier: Apache-2.0
7
7
  */
8
8
  import { appendInstructions } from "../../models/llm_request.js";
9
+ import { canUseOutputSchemaWithTools } from "../../utils/output_schema_utils.js";
9
10
  import { injectSessionState } from "../instructions.js";
10
11
  import { isLlmAgent } from "../llm_agent.js";
11
12
  import { ReadonlyContext } from "../readonly_context.js";
@@ -16,6 +17,7 @@ class InstructionsLlmRequestProcessor extends BaseLlmRequestProcessor {
16
17
  */
17
18
  // eslint-disable-next-line require-yield
18
19
  async *runAsync(invocationContext, llmRequest) {
20
+ var _a;
19
21
  const agent = invocationContext.agent;
20
22
  if (!isLlmAgent(agent)) {
21
23
  return;
@@ -47,7 +49,7 @@ class InstructionsLlmRequestProcessor extends BaseLlmRequestProcessor {
47
49
  }
48
50
  appendInstructions(llmRequest, [instructionWithState]);
49
51
  }
50
- if (agent.outputSchema && agent.tools && agent.tools.length > 0) {
52
+ if (agent.outputSchema && ((_a = agent.tools) == null ? void 0 : _a.length) && !canUseOutputSchemaWithTools(agent.canonicalModel.model)) {
51
53
  appendInstructions(llmRequest, [
52
54
  'To output the final result, you must call the "set_model_response" function with the appropriate values. Do not output anything else.'
53
55
  ]);
@@ -38,6 +38,29 @@ let RoutedAgent = class extends (_b = BaseAgent, _a = ROUTED_AGENT_SIGNATURE_SYM
38
38
  }
39
39
  this.router = config.router;
40
40
  }
41
+ /**
42
+ * Creates a detached copy of this routed agent.
43
+ *
44
+ * The inherited {@link BaseAgent.clone} only deep-clones `subAgents`, but a
45
+ * `RoutedAgent` derives its routing targets from `config.agents`. Rebuilding
46
+ * through the base clone alone would re-read the already-parented original
47
+ * agents and throw "already has a parent agent". This override deep-clones the
48
+ * routing targets (unless the caller overrides `agents`) so the rebuilt
49
+ * constructor re-parents fresh, detached copies. The array-vs-record shape
50
+ * and, for records, the keys are preserved so the router keeps selecting the
51
+ * same targets.
52
+ *
53
+ * @param overrides Config fields to override on the clone. Overriding
54
+ * `parentAgent` is rejected by the base implementation.
55
+ * @returns A new detached `RoutedAgent` of the same concrete class.
56
+ */
57
+ clone(overrides) {
58
+ const nextOverrides = { ...overrides };
59
+ if (!("agents" in nextOverrides)) {
60
+ nextOverrides.agents = cloneRoutingTargets(this.config.agents);
61
+ }
62
+ return super.clone(nextOverrides);
63
+ }
41
64
  /**
42
65
  * Runs the selected agent via text-based conversation.
43
66
  */
@@ -64,6 +87,14 @@ let RoutedAgent = class extends (_b = BaseAgent, _a = ROUTED_AGENT_SIGNATURE_SYM
64
87
  RoutedAgent = __decorateClass([
65
88
  experimental
66
89
  ], RoutedAgent);
90
+ function cloneRoutingTargets(agents) {
91
+ if (Array.isArray(agents)) {
92
+ return agents.map((agent) => agent.clone());
93
+ }
94
+ return Object.fromEntries(
95
+ Object.entries(agents).map(([key, agent]) => [key, agent.clone()])
96
+ );
97
+ }
67
98
  export {
68
99
  RoutedAgent,
69
100
  isRoutedAgent
@@ -13,14 +13,15 @@ var StreamingMode = /* @__PURE__ */ ((StreamingMode2) => {
13
13
  return StreamingMode2;
14
14
  })(StreamingMode || {});
15
15
  function createRunConfig(params = {}) {
16
+ var _a;
16
17
  return {
17
18
  saveInputBlobsAsArtifacts: false,
18
19
  supportCfc: false,
19
20
  enableAffectiveDialog: false,
20
21
  streamingMode: "none" /* NONE */,
21
- maxLlmCalls: validateMaxLlmCalls(params.maxLlmCalls || 500),
22
22
  pauseOnToolCalls: false,
23
- ...params
23
+ ...params,
24
+ maxLlmCalls: validateMaxLlmCalls((_a = params.maxLlmCalls) != null ? _a : 500)
24
25
  };
25
26
  }
26
27
  function validateMaxLlmCalls(value) {
@@ -5,6 +5,7 @@ const require = topLevelCreateRequire(import.meta.url);
5
5
  * Copyright 2025 Google LLC
6
6
  * SPDX-License-Identifier: Apache-2.0
7
7
  */
8
+ import { logger } from "../utils/logger.js";
8
9
  function isInMemoryConnectionString(uri) {
9
10
  return uri === "memory://";
10
11
  }
@@ -56,6 +57,12 @@ class InMemoryArtifactService {
56
57
  if (version === void 0) {
57
58
  version = versions.length - 1;
58
59
  }
60
+ if (!versions[version]) {
61
+ logger.warn(
62
+ `[InMemoryArtifactService] loadArtifact: Artifact ${filename} version ${version} not found`
63
+ );
64
+ return Promise.resolve(void 0);
65
+ }
59
66
  return Promise.resolve(versions[version].part);
60
67
  }
61
68
  listArtifactKeys({
@@ -63,16 +70,14 @@ class InMemoryArtifactService {
63
70
  userId,
64
71
  sessionId
65
72
  }) {
66
- const sessionPrefix = `${appName}/${userId}/${sessionId}/`;
67
- const usernamespacePrefix = `${appName}/${userId}/user/`;
73
+ const sessionPrefix = artifactPrefix("session", appName, userId, sessionId);
74
+ const userPrefix = artifactPrefix("user", appName, userId);
68
75
  const filenames = [];
69
76
  for (const path in this.artifacts) {
70
77
  if (path.startsWith(sessionPrefix)) {
71
- const filename = path.replace(sessionPrefix, "");
72
- filenames.push(filename);
73
- } else if (path.startsWith(usernamespacePrefix)) {
74
- const filename = path.replace(usernamespacePrefix, "");
75
- filenames.push(filename);
78
+ filenames.push(decodeURIComponent(path.slice(sessionPrefix.length)));
79
+ } else if (path.startsWith(userPrefix)) {
80
+ filenames.push(decodeURIComponent(path.slice(userPrefix.length)));
76
81
  }
77
82
  }
78
83
  return Promise.resolve(filenames.sort());
@@ -143,9 +148,12 @@ class InMemoryArtifactService {
143
148
  }
144
149
  function artifactPath(appName, userId, sessionId, filename) {
145
150
  if (fileHasUserNamespace(filename)) {
146
- return `${appName}/${userId}/user/${filename}`;
151
+ return `${artifactPrefix("user", appName, userId)}${encodeURIComponent(filename)}`;
147
152
  }
148
- return `${appName}/${userId}/${sessionId}/${filename}`;
153
+ return `${artifactPrefix("session", appName, userId, sessionId)}${encodeURIComponent(filename)}`;
154
+ }
155
+ function artifactPrefix(scope, ...parts) {
156
+ return `${[scope, ...parts].map(encodeURIComponent).join("/")}/`;
149
157
  }
150
158
  function fileHasUserNamespace(filename) {
151
159
  return filename.startsWith("user:");
@@ -7,7 +7,18 @@ const require = topLevelCreateRequire(import.meta.url);
7
7
  */
8
8
  class InMemoryCredentialService {
9
9
  constructor() {
10
- this.credentials = {};
10
+ /**
11
+ * A map from app name to a map from user ID to a map from credential key to
12
+ * credential.
13
+ *
14
+ * `appName`, `userId` and `credentialKey` are all attacker-influenced, so
15
+ * every level is created with `Object.create(null)`. On an ordinary `{}`
16
+ * literal a key of `__proto__` resolves to the inherited `__proto__`
17
+ * accessor rather than creating an own property, so nested assignment
18
+ * pollutes every object in the process, and a lookup of an inherited key
19
+ * such as `toString` returns a function instead of `undefined`.
20
+ */
21
+ this.credentials = /* @__PURE__ */ Object.create(null);
11
22
  }
12
23
  loadCredential(authConfig, toolContext) {
13
24
  const credentialBucket = this.getBucketForCurrentContext(toolContext);
@@ -22,10 +33,10 @@ class InMemoryCredentialService {
22
33
  getBucketForCurrentContext(toolContext) {
23
34
  const { appName, userId } = toolContext.invocationContext.session;
24
35
  if (!this.credentials[appName]) {
25
- this.credentials[appName] = {};
36
+ this.credentials[appName] = /* @__PURE__ */ Object.create(null);
26
37
  }
27
38
  if (!this.credentials[appName][userId]) {
28
- this.credentials[appName][userId] = {};
39
+ this.credentials[appName][userId] = /* @__PURE__ */ Object.create(null);
29
40
  }
30
41
  return this.credentials[appName][userId];
31
42
  }
@@ -5,7 +5,7 @@ const require = topLevelCreateRequire(import.meta.url);
5
5
  * Copyright 2026 Google LLC
6
6
  * SPDX-License-Identifier: Apache-2.0
7
7
  */
8
- import { spawn } from "child_process";
8
+ import { spawn } from "node:child_process";
9
9
  import * as fs from "node:fs/promises";
10
10
  import * as os from "node:os";
11
11
  import * as path from "node:path";
@@ -17,13 +17,21 @@ import {
17
17
  CodeExecutionLanguage
18
18
  } from "./code_execution_utils.js";
19
19
  const IS_WINDOWS = os.platform() === "win32";
20
+ const POWERSHELL_BASE_ARGS = [
21
+ "-NoLogo",
22
+ "-NoProfile",
23
+ "-ExecutionPolicy",
24
+ "Bypass",
25
+ "-File"
26
+ ];
27
+ const CMD_BASE_ARGS = ["/D", "/c"];
28
+ function isPowerShellCommand(commandPath) {
29
+ return /^(powershell|pwsh)(\.exe)?$/i.test(path.win32.basename(commandPath));
30
+ }
20
31
  async function createTempScriptFile(code, language, shellCommandPath) {
21
- const tempDir = path.join(
22
- os.tmpdir(),
23
- "adk_js_unsafe_code_executor",
24
- Date.now().toString() + "_" + Math.random().toString(36).slice(2)
32
+ const tempDir = await fs.mkdtemp(
33
+ path.join(os.tmpdir(), "adk_js_unsafe_code_executor_")
25
34
  );
26
- await fs.mkdir(tempDir, { recursive: true });
27
35
  const ext = getExtensionForLanguage(language, shellCommandPath) || ".js";
28
36
  const filePath = path.join(tempDir, `script${ext}`);
29
37
  await fs.writeFile(filePath, code);
@@ -43,6 +51,9 @@ function getExtensionForLanguage(language, shellCommandPath) {
43
51
  return ".bat";
44
52
  }
45
53
  if (language === CodeExecutionLanguage.SHELL) {
54
+ if (shellCommandPath && isPowerShellCommand(shellCommandPath)) {
55
+ return ".ps1";
56
+ }
46
57
  if (IS_WINDOWS) {
47
58
  if (shellCommandPath && shellCommandPath.toLowerCase().includes("cmd")) {
48
59
  return ".bat";
@@ -101,17 +112,17 @@ class UnsafeLocalCodeExecutor extends BaseCodeExecutor {
101
112
  command = this.pythonCommandPath;
102
113
  } else if (language === CodeExecutionLanguage.SHELL) {
103
114
  command = this.shellCommandPath;
104
- if (this.shellCommandPath.toLowerCase().includes("powershell")) {
105
- args = ["-NoLogo", "-ExecutionPolicy", "Bypass", "-File", filePath];
115
+ if (isPowerShellCommand(this.shellCommandPath)) {
116
+ args = [...POWERSHELL_BASE_ARGS, filePath];
106
117
  } else if (this.shellCommandPath.toLowerCase().includes("cmd")) {
107
- args = ["/c", filePath];
118
+ args = [...CMD_BASE_ARGS, filePath];
108
119
  }
109
120
  } else if (language === CodeExecutionLanguage.POWERSHELL) {
110
121
  command = IS_WINDOWS ? "powershell" : "pwsh";
111
- args = ["-NoLogo", "-ExecutionPolicy", "Bypass", "-File", filePath];
122
+ args = [...POWERSHELL_BASE_ARGS, filePath];
112
123
  } else if (language === CodeExecutionLanguage.WINDOWS_CMD) {
113
124
  command = "cmd.exe";
114
- args = ["/c", filePath];
125
+ args = [...CMD_BASE_ARGS, filePath];
115
126
  }
116
127
  if (params.codeExecutionInput.args) {
117
128
  if (Array.isArray(params.codeExecutionInput.args)) {
@@ -56,17 +56,22 @@ import {
56
56
  FileContentEncoding
57
57
  } from "./code_executors/code_execution_utils.js";
58
58
  import { AgentControlledContextCompactor } from "./context/agent_controlled_context_compactor.js";
59
+ import { AnchoredContextCompactor } from "./context/anchored_context_compactor.js";
59
60
  import { LlmSummarizer } from "./context/summarizers/llm_summarizer.js";
60
61
  import { TokenBasedContextCompactor } from "./context/token_based_context_compactor.js";
61
62
  import { TrajectoryThoughtPruningCompactor } from "./context/trajectory_thought_pruning_compactor.js";
62
63
  import { TruncatingContextCompactor } from "./context/truncating_context_compactor.js";
63
- import { isCompactedEvent } from "./events/compacted_event.js";
64
+ import { isCompactedEvent, isScratchpadEvent } from "./events/compacted_event.js";
64
65
  import {
65
66
  createEvent,
67
+ generateClientFunctionCallId,
66
68
  getFunctionCalls,
67
69
  getFunctionResponses,
70
+ hasThoughts,
68
71
  hasTrailingCodeExecutionResult,
69
72
  isFinalResponse,
73
+ populateClientFunctionCallId,
74
+ pruneThoughts,
70
75
  stringifyContent
71
76
  } from "./events/event.js";
72
77
  import { createEventActions } from "./events/event_actions.js";
@@ -83,6 +88,7 @@ import { Gemini, geminiInitParams } from "./models/google_llm.js";
83
88
  import { LLMRegistry } from "./models/registry.js";
84
89
  import { RoutedLlm } from "./models/routed_llm.js";
85
90
  import { BasePlugin, ContextCompactionTrigger } from "./plugins/base_plugin.js";
91
+ import { GlobalInstructionPlugin } from "./plugins/global_instruction_plugin.js";
86
92
  import { LoggingPlugin } from "./plugins/logging_plugin.js";
87
93
  import { PluginManager } from "./plugins/plugin_manager.js";
88
94
  import {
@@ -108,8 +114,14 @@ import { AgentTool, isAgentTool } from "./tools/agent_tool.js";
108
114
  import { BaseTool, isBaseTool } from "./tools/base_tool.js";
109
115
  import { BaseToolset, isBaseToolset } from "./tools/base_toolset.js";
110
116
  import { ConsolidateContextTool } from "./tools/consolidate_context_tool.js";
117
+ import {
118
+ ENTERPRISE_WEB_SEARCH,
119
+ EnterpriseWebSearchTool
120
+ } from "./tools/enterprise_web_search_tool.js";
121
+ import { ExampleTool } from "./tools/example_tool.js";
111
122
  import { EXIT_LOOP, ExitLoopTool } from "./tools/exit_loop_tool.js";
112
123
  import { FunctionTool, isFunctionTool } from "./tools/function_tool.js";
124
+ import { getUserChoiceTool } from "./tools/get_user_choice_tool.js";
113
125
  import {
114
126
  GOOGLE_MAPS_GROUNDING,
115
127
  GoogleMapsGroundingTool
@@ -120,11 +132,13 @@ import {
120
132
  LoadArtifactsTool
121
133
  } from "./tools/load_artifacts_tool.js";
122
134
  import { LOAD_MEMORY, LoadMemoryTool } from "./tools/load_memory_tool.js";
135
+ import { LOAD_WEB_PAGE, loadWebPage } from "./tools/load_web_page.js";
123
136
  import { LongRunningFunctionTool } from "./tools/long_running_tool.js";
124
137
  import {
125
138
  PRELOAD_MEMORY,
126
139
  PreloadMemoryTool
127
140
  } from "./tools/preload_memory_tool.js";
141
+ import { requestInputTool } from "./tools/request_input_tool.js";
128
142
  import { ToolConfirmation } from "./tools/tool_confirmation.js";
129
143
  import { URL_CONTEXT, UrlContextTool } from "./tools/url_context_tool.js";
130
144
  import { VertexAiSearchTool } from "./tools/vertex_ai_search_tool.js";
@@ -174,6 +188,7 @@ export {
174
188
  AgentControlledContextCompactor,
175
189
  AgentTool,
176
190
  AgentTransferLlmRequestProcessor,
191
+ AnchoredContextCompactor,
177
192
  ApigeeLlm,
178
193
  AuthCredentialTypes,
179
194
  AuthHandler,
@@ -199,8 +214,11 @@ export {
199
214
  ContextCompactorRequestProcessor,
200
215
  CredentialExchangeError,
201
216
  CredentialRefresherRegistry,
217
+ ENTERPRISE_WEB_SEARCH,
202
218
  EXIT_LOOP,
219
+ EnterpriseWebSearchTool,
203
220
  EventType,
221
+ ExampleTool,
204
222
  ExitLoopTool,
205
223
  FileContentEncoding,
206
224
  FunctionTool,
@@ -208,6 +226,7 @@ export {
208
226
  GOOGLE_MAPS_GROUNDING,
209
227
  GOOGLE_SEARCH,
210
228
  Gemini,
229
+ GlobalInstructionPlugin,
211
230
  GoogleLLMVariant,
212
231
  GoogleMapsGroundingTool,
213
232
  GoogleSearchTool,
@@ -223,6 +242,7 @@ export {
223
242
  LLMRegistry,
224
243
  LOAD_ARTIFACTS,
225
244
  LOAD_MEMORY,
245
+ LOAD_WEB_PAGE,
226
246
  ListSkillsTool,
227
247
  LiveRequestQueue,
228
248
  LlmAgent2 as LlmAgent,
@@ -281,11 +301,14 @@ export {
281
301
  findMatchingFunctionCall,
282
302
  functionsExportedForTestingOnly,
283
303
  geminiInitParams,
304
+ generateClientFunctionCallId,
284
305
  getAskUserConfirmationFunctionCalls,
285
306
  getClientLabels,
286
307
  getFunctionCalls,
287
308
  getFunctionResponses,
288
309
  getLogger,
310
+ getUserChoiceTool,
311
+ hasThoughts,
289
312
  hasTrailingCodeExecutionResult,
290
313
  isAgentTool,
291
314
  isBaseAgent,
@@ -304,10 +327,15 @@ export {
304
327
  isRoutableLlmAgent,
305
328
  isRoutedAgent,
306
329
  isRunner,
330
+ isScratchpadEvent,
307
331
  isSequentialAgent,
308
332
  loadAllSkillsInDir,
309
333
  loadSkillFromDir,
310
334
  loadSkillFromZipBuffer,
335
+ loadWebPage,
336
+ populateClientFunctionCallId,
337
+ pruneThoughts,
338
+ requestInputTool,
311
339
  runWithClientLabel,
312
340
  setLogLevel,
313
341
  setLogger,
@@ -5,9 +5,9 @@ const require = topLevelCreateRequire(import.meta.url);
5
5
  * Copyright 2026 Google LLC
6
6
  * SPDX-License-Identifier: Apache-2.0
7
7
  */
8
- import { isCompactedEvent } from "../events/compacted_event.js";
9
8
  import { createEvent } from "../events/event.js";
10
9
  import { ContextCompactionTrigger } from "../plugins/base_plugin.js";
10
+ import { getActiveEvents } from "./compaction_utils.js";
11
11
  class AgentControlledContextCompactor {
12
12
  constructor(options) {
13
13
  this.trigger = ContextCompactionTrigger.AgentControlled;
@@ -18,7 +18,7 @@ class AgentControlledContextCompactor {
18
18
  }
19
19
  async compact(invocationContext) {
20
20
  const events = invocationContext.session.events;
21
- const activeEvents = this.getActiveEvents(events);
21
+ const activeEvents = getActiveEvents(events);
22
22
  const consolidateToolCallIndex = activeEvents.reduce(
23
23
  (acc, e, idx) => {
24
24
  var _a, _b;
@@ -66,15 +66,6 @@ class AgentControlledContextCompactor {
66
66
  delete invocationContext.session.state["temp:consolidate_context"];
67
67
  delete invocationContext.session.state["temp:consolidate_context_detail"];
68
68
  }
69
- getActiveEvents(events) {
70
- const latest = events.filter(isCompactedEvent).pop();
71
- return latest ? [
72
- latest,
73
- ...events.filter(
74
- (e) => !isCompactedEvent(e) && e.timestamp > latest.endTime
75
- )
76
- ] : events;
77
- }
78
69
  }
79
70
  export {
80
71
  AgentControlledContextCompactor