@google/adk 1.3.0 → 1.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 (248) hide show
  1. package/dist/cjs/a2a/agent_to_a2a.js +18 -2
  2. package/dist/cjs/a2a/event_converter_utils.js +8 -4
  3. package/dist/cjs/a2a/metadata_converter_utils.js +1 -1
  4. package/dist/cjs/agents/active_streaming_tool.js +6 -1
  5. package/dist/cjs/agents/base_agent.js +39 -0
  6. package/dist/cjs/agents/context.js +1 -11
  7. package/dist/cjs/agents/functions.js +39 -35
  8. package/dist/cjs/agents/instructions.js +23 -5
  9. package/dist/cjs/agents/invocation_context.js +2 -5
  10. package/dist/cjs/agents/llm_agent.js +10 -7
  11. package/dist/cjs/agents/loop_agent.js +15 -3
  12. package/dist/cjs/agents/processors/code_execution_request_processor.js +0 -3
  13. package/dist/cjs/agents/processors/content_processor_utils.js +18 -4
  14. package/dist/cjs/agents/processors/context_compactor_request_processor.js +4 -2
  15. package/dist/cjs/agents/processors/interactions_request_processor.js +63 -0
  16. package/dist/cjs/agents/routed_agent.js +31 -0
  17. package/dist/cjs/agents/run_config.js +3 -2
  18. package/dist/cjs/apps/app.js +79 -0
  19. package/dist/cjs/apps/resumability_config.js +44 -0
  20. package/dist/cjs/artifacts/file_artifact_service.js +14 -1
  21. package/dist/cjs/artifacts/gcs_artifact_service.js +57 -15
  22. package/dist/cjs/artifacts/in_memory_artifact_service.js +12 -1
  23. package/dist/cjs/artifacts/scoped_artifact_service.js +101 -0
  24. package/dist/cjs/artifacts/session_artifact_service.js +27 -0
  25. package/dist/cjs/auth/oauth2/oauth2_discovery.js +17 -5
  26. package/dist/cjs/auth/oauth2/oauth2_utils.js +12 -1
  27. package/dist/cjs/common.js +76 -0
  28. package/dist/cjs/context/agent_controlled_context_compactor.js +109 -0
  29. package/dist/cjs/context/anchored_context_compactor.js +127 -0
  30. package/dist/cjs/context/compaction_utils.js +52 -0
  31. package/dist/cjs/context/token_based_context_compactor.js +52 -33
  32. package/dist/cjs/context/trajectory_thought_pruning_compactor.js +71 -0
  33. package/dist/cjs/events/compacted_event.js +9 -3
  34. package/dist/cjs/events/event.js +52 -0
  35. package/dist/cjs/index.js +4 -0
  36. package/dist/cjs/integrations/agent_registry/agent_registry_mcp_toolset.js +9 -1
  37. package/dist/cjs/models/google_llm.js +25 -10
  38. package/dist/cjs/models/interactions_utils.js +732 -0
  39. package/dist/cjs/plugins/base_plugin.js +1 -0
  40. package/dist/cjs/plugins/global_instruction_plugin.js +97 -0
  41. package/dist/cjs/runner/in_memory_runner.js +13 -2
  42. package/dist/cjs/runner/runner.js +143 -83
  43. package/dist/cjs/sessions/base_session_service.js +6 -1
  44. package/dist/cjs/sessions/database_session_service.js +24 -7
  45. package/dist/cjs/sessions/vertex_ai_session_service.js +19 -4
  46. package/dist/cjs/skills/loader.js +2 -2
  47. package/dist/cjs/tools/base_toolset.js +1 -1
  48. package/dist/cjs/tools/consolidate_context_tool.js +79 -0
  49. package/dist/cjs/tools/enterprise_web_search_tool.js +81 -0
  50. package/dist/cjs/tools/example_tool.js +68 -0
  51. package/dist/cjs/tools/forwarding_artifact_service.js +16 -28
  52. package/dist/cjs/tools/load_web_page.js +250 -0
  53. package/dist/cjs/tools/mcp/load_mcp_resource_tool.js +140 -0
  54. package/dist/cjs/tools/mcp/mcp_toolset.js +63 -0
  55. package/dist/cjs/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +15 -22
  56. package/dist/cjs/tools/skill/run_skill_inline_script_tool.js +54 -4
  57. package/dist/cjs/tools/skill/skill_toolset.js +4 -2
  58. package/dist/cjs/utils/async_hooks_shim.js +52 -0
  59. package/dist/cjs/utils/branch_trie.js +41 -0
  60. package/dist/cjs/utils/client_labels.js +41 -3
  61. package/dist/cjs/utils/env_aware_utils.js +10 -1
  62. package/dist/cjs/utils/streaming_utils.js +15 -9
  63. package/dist/cjs/utils/task.js +62 -0
  64. package/dist/cjs/version.js +1 -1
  65. package/dist/esm/a2a/agent_to_a2a.js +18 -2
  66. package/dist/esm/a2a/event_converter_utils.js +8 -4
  67. package/dist/esm/a2a/metadata_converter_utils.js +1 -1
  68. package/dist/esm/agents/active_streaming_tool.js +6 -1
  69. package/dist/esm/agents/base_agent.js +39 -0
  70. package/dist/esm/agents/context.js +1 -11
  71. package/dist/esm/agents/functions.js +43 -32
  72. package/dist/esm/agents/instructions.js +23 -5
  73. package/dist/esm/agents/invocation_context.js +2 -5
  74. package/dist/esm/agents/llm_agent.js +12 -9
  75. package/dist/esm/agents/loop_agent.js +15 -3
  76. package/dist/esm/agents/processors/code_execution_request_processor.js +0 -3
  77. package/dist/esm/agents/processors/content_processor_utils.js +16 -3
  78. package/dist/esm/agents/processors/context_compactor_request_processor.js +4 -2
  79. package/dist/esm/agents/processors/interactions_request_processor.js +34 -0
  80. package/dist/esm/agents/routed_agent.js +31 -0
  81. package/dist/esm/agents/run_config.js +3 -2
  82. package/dist/esm/apps/app.js +49 -0
  83. package/dist/esm/apps/resumability_config.js +16 -0
  84. package/dist/esm/artifacts/file_artifact_service.js +14 -1
  85. package/dist/esm/artifacts/gcs_artifact_service.js +57 -15
  86. package/dist/esm/artifacts/in_memory_artifact_service.js +12 -1
  87. package/dist/esm/artifacts/scoped_artifact_service.js +73 -0
  88. package/dist/esm/artifacts/session_artifact_service.js +7 -0
  89. package/dist/esm/auth/oauth2/oauth2_discovery.js +14 -4
  90. package/dist/esm/auth/oauth2/oauth2_utils.js +12 -1
  91. package/dist/esm/common.js +67 -3
  92. package/dist/esm/context/agent_controlled_context_compactor.js +81 -0
  93. package/dist/esm/context/anchored_context_compactor.js +99 -0
  94. package/dist/esm/context/compaction_utils.js +27 -0
  95. package/dist/esm/context/token_based_context_compactor.js +52 -33
  96. package/dist/esm/context/trajectory_thought_pruning_compactor.js +43 -0
  97. package/dist/esm/events/compacted_event.js +7 -2
  98. package/dist/esm/events/event.js +46 -0
  99. package/dist/esm/index.js +6 -1
  100. package/dist/esm/integrations/agent_registry/agent_registry_mcp_toolset.js +9 -1
  101. package/dist/esm/models/google_llm.js +23 -9
  102. package/dist/esm/models/interactions_utils.js +697 -0
  103. package/dist/esm/plugins/base_plugin.js +1 -0
  104. package/dist/esm/plugins/global_instruction_plugin.js +69 -0
  105. package/dist/esm/runner/in_memory_runner.js +13 -2
  106. package/dist/esm/runner/runner.js +141 -84
  107. package/dist/esm/sessions/base_session_service.js +6 -1
  108. package/dist/esm/sessions/database_session_service.js +24 -7
  109. package/dist/esm/sessions/vertex_ai_session_service.js +17 -3
  110. package/dist/esm/skills/loader.js +2 -2
  111. package/dist/esm/tools/base_toolset.js +1 -1
  112. package/dist/esm/tools/consolidate_context_tool.js +51 -0
  113. package/dist/esm/tools/enterprise_web_search_tool.js +55 -0
  114. package/dist/esm/tools/example_tool.js +42 -0
  115. package/dist/esm/tools/forwarding_artifact_service.js +16 -28
  116. package/dist/esm/tools/load_web_page.js +221 -0
  117. package/dist/esm/tools/mcp/load_mcp_resource_tool.js +114 -0
  118. package/dist/esm/tools/mcp/mcp_toolset.js +63 -0
  119. package/dist/esm/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +15 -22
  120. package/dist/esm/tools/skill/run_skill_inline_script_tool.js +53 -4
  121. package/dist/esm/tools/skill/skill_toolset.js +4 -2
  122. package/dist/esm/utils/async_hooks_shim.js +24 -0
  123. package/dist/esm/utils/branch_trie.js +13 -0
  124. package/dist/esm/utils/client_labels.js +38 -2
  125. package/dist/esm/utils/env_aware_utils.js +10 -1
  126. package/dist/esm/utils/streaming_utils.js +11 -5
  127. package/dist/esm/utils/task.js +34 -0
  128. package/dist/esm/version.js +1 -1
  129. package/dist/types/a2a/a2a_remote_agent.d.ts +5 -1
  130. package/dist/types/a2a/agent_to_a2a.d.ts +38 -0
  131. package/dist/types/agents/active_streaming_tool.d.ts +3 -4
  132. package/dist/types/agents/base_agent.d.ts +29 -1
  133. package/dist/types/agents/functions.d.ts +12 -17
  134. package/dist/types/agents/invocation_context.d.ts +7 -3
  135. package/dist/types/agents/llm_agent.d.ts +5 -1
  136. package/dist/types/agents/loop_agent.d.ts +2 -2
  137. package/dist/types/agents/processors/content_processor_utils.d.ts +8 -0
  138. package/dist/types/agents/processors/interactions_request_processor.d.ts +17 -0
  139. package/dist/types/agents/routed_agent.d.ts +24 -1
  140. package/dist/types/agents/run_config.d.ts +1 -1
  141. package/dist/types/apps/app.d.ts +52 -0
  142. package/dist/types/apps/resumability_config.d.ts +27 -0
  143. package/dist/types/artifacts/base_artifact_service.d.ts +6 -36
  144. package/dist/types/artifacts/gcs_artifact_service.d.ts +2 -1
  145. package/dist/types/artifacts/scoped_artifact_service.d.ts +25 -0
  146. package/dist/types/artifacts/session_artifact_service.d.ts +25 -0
  147. package/dist/types/auth/oauth2/oauth2_discovery.d.ts +11 -0
  148. package/dist/types/common.d.ts +29 -5
  149. package/dist/types/context/agent_controlled_context_compactor.d.ts +24 -0
  150. package/dist/types/context/anchored_context_compactor.d.ts +35 -0
  151. package/dist/types/context/base_context_compactor.d.ts +3 -0
  152. package/dist/types/context/compaction_utils.d.ts +15 -0
  153. package/dist/types/context/token_based_context_compactor.d.ts +6 -1
  154. package/dist/types/context/trajectory_thought_pruning_compactor.d.ts +27 -0
  155. package/dist/types/events/compacted_event.d.ts +10 -0
  156. package/dist/types/events/event.d.ts +21 -0
  157. package/dist/types/index.d.ts +3 -2
  158. package/dist/types/models/google_llm.d.ts +15 -1
  159. package/dist/types/models/interactions_utils.d.ts +92 -0
  160. package/dist/types/models/llm_request.d.ts +4 -0
  161. package/dist/types/models/llm_response.d.ts +4 -0
  162. package/dist/types/plugins/base_plugin.d.ts +2 -1
  163. package/dist/types/plugins/global_instruction_plugin.d.ts +38 -0
  164. package/dist/types/runner/in_memory_runner.d.ts +7 -1
  165. package/dist/types/runner/runner.d.ts +44 -10
  166. package/dist/types/sessions/base_session_service.d.ts +3 -16
  167. package/dist/types/sessions/session.d.ts +11 -0
  168. package/dist/types/sessions/vertex_ai_session_service.d.ts +9 -1
  169. package/dist/types/tools/consolidate_context_tool.d.ts +19 -0
  170. package/dist/types/tools/enterprise_web_search_tool.d.ts +26 -0
  171. package/dist/types/tools/example_tool.d.ts +21 -0
  172. package/dist/types/tools/forwarding_artifact_service.d.ts +3 -2
  173. package/dist/types/tools/load_web_page.d.ts +33 -0
  174. package/dist/types/tools/mcp/load_mcp_resource_tool.d.ts +26 -0
  175. package/dist/types/tools/mcp/mcp_toolset.d.ts +27 -0
  176. package/dist/types/tools/skill/run_skill_inline_script_tool.d.ts +25 -0
  177. package/dist/types/tools/skill/skill_toolset.d.ts +9 -0
  178. package/dist/types/utils/async_hooks_shim.d.ts +10 -0
  179. package/dist/types/utils/branch_trie.d.ts +14 -0
  180. package/dist/types/utils/client_labels.d.ts +10 -0
  181. package/dist/types/utils/env_aware_utils.d.ts +3 -3
  182. package/dist/types/utils/task.d.ts +24 -0
  183. package/dist/types/version.d.ts +1 -1
  184. package/dist/web/a2a/agent_to_a2a.js +18 -2
  185. package/dist/web/a2a/event_converter_utils.js +8 -4
  186. package/dist/web/a2a/metadata_converter_utils.js +1 -1
  187. package/dist/web/agents/active_streaming_tool.js +6 -1
  188. package/dist/web/agents/base_agent.js +39 -0
  189. package/dist/web/agents/context.js +1 -11
  190. package/dist/web/agents/functions.js +43 -32
  191. package/dist/web/agents/instructions.js +23 -5
  192. package/dist/web/agents/invocation_context.js +2 -5
  193. package/dist/web/agents/llm_agent.js +12 -9
  194. package/dist/web/agents/loop_agent.js +27 -3
  195. package/dist/web/agents/processors/code_execution_request_processor.js +0 -3
  196. package/dist/web/agents/processors/content_processor_utils.js +16 -3
  197. package/dist/web/agents/processors/context_compactor_request_processor.js +4 -2
  198. package/dist/web/agents/processors/interactions_request_processor.js +52 -0
  199. package/dist/web/agents/routed_agent.js +31 -0
  200. package/dist/web/agents/run_config.js +8 -3
  201. package/dist/web/apps/app.js +49 -0
  202. package/dist/web/apps/resumability_config.js +31 -0
  203. package/dist/web/artifacts/file_artifact_service.js +14 -1
  204. package/dist/web/artifacts/gcs_artifact_service.js +55 -15
  205. package/dist/web/artifacts/in_memory_artifact_service.js +12 -1
  206. package/dist/web/artifacts/scoped_artifact_service.js +86 -0
  207. package/dist/web/artifacts/session_artifact_service.js +7 -0
  208. package/dist/web/auth/oauth2/oauth2_discovery.js +14 -4
  209. package/dist/web/auth/oauth2/oauth2_utils.js +12 -1
  210. package/dist/web/common.js +67 -3
  211. package/dist/web/context/agent_controlled_context_compactor.js +81 -0
  212. package/dist/web/context/anchored_context_compactor.js +117 -0
  213. package/dist/web/context/compaction_utils.js +27 -0
  214. package/dist/web/context/token_based_context_compactor.js +52 -33
  215. package/dist/web/context/trajectory_thought_pruning_compactor.js +43 -0
  216. package/dist/web/events/compacted_event.js +7 -2
  217. package/dist/web/events/event.js +44 -0
  218. package/dist/web/index.js +6 -1
  219. package/dist/web/integrations/agent_registry/agent_registry_mcp_toolset.js +9 -1
  220. package/dist/web/models/google_llm.js +54 -9
  221. package/dist/web/models/interactions_utils.js +728 -0
  222. package/dist/web/plugins/base_plugin.js +1 -0
  223. package/dist/web/plugins/global_instruction_plugin.js +67 -0
  224. package/dist/web/runner/in_memory_runner.js +13 -2
  225. package/dist/web/runner/runner.js +157 -84
  226. package/dist/web/sessions/base_session_service.js +6 -1
  227. package/dist/web/sessions/database_session_service.js +24 -7
  228. package/dist/web/sessions/vertex_ai_session_service.js +17 -3
  229. package/dist/web/skills/loader.js +2 -2
  230. package/dist/web/tools/base_toolset.js +1 -1
  231. package/dist/web/tools/consolidate_context_tool.js +51 -0
  232. package/dist/web/tools/enterprise_web_search_tool.js +55 -0
  233. package/dist/web/tools/example_tool.js +42 -0
  234. package/dist/web/tools/forwarding_artifact_service.js +16 -28
  235. package/dist/web/tools/load_web_page.js +221 -0
  236. package/dist/web/tools/mcp/load_mcp_resource_tool.js +107 -0
  237. package/dist/web/tools/mcp/mcp_toolset.js +63 -0
  238. package/dist/web/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +15 -22
  239. package/dist/web/tools/skill/run_skill_inline_script_tool.js +51 -4
  240. package/dist/web/tools/skill/skill_toolset.js +4 -2
  241. package/dist/web/utils/async_hooks_shim.js +24 -0
  242. package/dist/web/utils/branch_trie.js +13 -0
  243. package/dist/web/utils/client_labels.js +38 -2
  244. package/dist/web/utils/env_aware_utils.js +10 -1
  245. package/dist/web/utils/streaming_utils.js +11 -5
  246. package/dist/web/utils/task.js +34 -0
  247. package/dist/web/version.js +1 -1
  248. package/package.json +2 -2
@@ -0,0 +1,24 @@
1
+ import {createRequire as topLevelCreateRequire} from 'module';
2
+ const require = topLevelCreateRequire(import.meta.url);
3
+ /**
4
+ * @license
5
+ * Copyright 2026 Google LLC
6
+ * SPDX-License-Identifier: Apache-2.0
7
+ */
8
+ class AsyncLocalStorage {
9
+ run(store, callback) {
10
+ const previous = this.store;
11
+ this.store = store;
12
+ try {
13
+ return callback();
14
+ } finally {
15
+ this.store = previous;
16
+ }
17
+ }
18
+ getStore() {
19
+ return this.store;
20
+ }
21
+ }
22
+ export {
23
+ AsyncLocalStorage
24
+ };
@@ -0,0 +1,13 @@
1
+ import {createRequire as topLevelCreateRequire} from 'module';
2
+ const require = topLevelCreateRequire(import.meta.url);
3
+ /**
4
+ * @license
5
+ * Copyright 2026 Google LLC
6
+ * SPDX-License-Identifier: Apache-2.0
7
+ */
8
+ function isSegmentPrefix(currentBranch, targetBranch) {
9
+ return !targetBranch || targetBranch === currentBranch || !!currentBranch && currentBranch.startsWith(`${targetBranch}.`);
10
+ }
11
+ export {
12
+ isSegmentPrefix
13
+ };
@@ -5,24 +5,60 @@ const require = topLevelCreateRequire(import.meta.url);
5
5
  * Copyright 2025 Google LLC
6
6
  * SPDX-License-Identifier: Apache-2.0
7
7
  */
8
+ import { AsyncLocalStorage } from "node:async_hooks";
8
9
  import { version } from "../version.js";
9
10
  import { isBrowser } from "./env_aware_utils.js";
10
11
  const ADK_LABEL = "google-adk";
11
12
  const LANGUAGE_LABEL = "gl-typescript";
12
13
  const AGENT_ENGINE_TELEMETRY_TAG = "remote_reasoning_engine";
13
14
  const AGENT_ENGINE_TELEMETRY_ENV_VARIABLE_NAME = "GOOGLE_CLOUD_AGENT_ENGINE_ID";
15
+ const clientLabelLocalStorage = new AsyncLocalStorage();
16
+ const USER_AGENT_PATTERNS = [
17
+ ["Edge", /(?:Edg|Edge|EdgA)\/([0-9.]+)/i],
18
+ ["Firefox", /(?:Firefox|FxiOS)\/([0-9.]+)/i],
19
+ ["Chrome", /(?:Chrome|CriOS)\/([0-9.]+)/i],
20
+ ["Safari", /Version\/([0-9.]+).*Safari/i]
21
+ ];
22
+ function parseUserAgent(userAgent) {
23
+ if (!userAgent) {
24
+ return "Browser";
25
+ }
26
+ for (const [name, regex] of USER_AGENT_PATTERNS) {
27
+ const match = userAgent.match(regex);
28
+ if (match) {
29
+ return `${name}/${match[1]}`;
30
+ }
31
+ }
32
+ return "Browser";
33
+ }
14
34
  function _getDefaultLabels() {
15
35
  let frameworkLabel = `${ADK_LABEL}/${version}`;
16
36
  if (!isBrowser() && process.env[AGENT_ENGINE_TELEMETRY_ENV_VARIABLE_NAME]) {
17
37
  frameworkLabel = `${frameworkLabel}+${AGENT_ENGINE_TELEMETRY_TAG}`;
18
38
  }
19
- const languageLabel = `${LANGUAGE_LABEL}/${isBrowser() ? window.navigator.userAgent : process.version}`;
39
+ const languageLabelDetail = isBrowser() ? (
40
+ // eslint-disable-next-line no-undef
41
+ parseUserAgent(window.navigator.userAgent)
42
+ ) : process.version;
43
+ const languageLabel = `${LANGUAGE_LABEL}/${languageLabelDetail}`;
20
44
  return [frameworkLabel, languageLabel];
21
45
  }
46
+ function runWithClientLabel(clientLabel, callback) {
47
+ if (typeof clientLabel !== "string" || clientLabel.trim() === "") {
48
+ throw new Error("Client label must be a non-empty string.");
49
+ }
50
+ return clientLabelLocalStorage.run(clientLabel, callback);
51
+ }
22
52
  function getClientLabels() {
23
53
  const labels = _getDefaultLabels();
54
+ const contextLabel = clientLabelLocalStorage.getStore();
55
+ if (contextLabel) {
56
+ labels.push(contextLabel);
57
+ }
24
58
  return labels;
25
59
  }
26
60
  export {
27
- getClientLabels
61
+ getClientLabels,
62
+ parseUserAgent,
63
+ runWithClientLabel
28
64
  };
@@ -29,7 +29,16 @@ function randomUUID() {
29
29
  }
30
30
  function base64Encode(data) {
31
31
  if (isBrowser()) {
32
- return window.btoa(data);
32
+ let strData = "";
33
+ if (typeof data === "string") {
34
+ strData = data;
35
+ } else {
36
+ const len = data.byteLength;
37
+ for (let i = 0; i < len; i++) {
38
+ strData += String.fromCharCode(data[i]);
39
+ }
40
+ }
41
+ return window.btoa(strData);
33
42
  }
34
43
  return Buffer.from(data).toString("base64");
35
44
  }
@@ -9,7 +9,7 @@ import {
9
9
  FinishReason
10
10
  } from "@google/genai";
11
11
  import { JSONPath } from "jsonpath-plus";
12
- import { generateClientFunctionCallId } from "../agents/functions.js";
12
+ import { generateClientFunctionCallId } from "../events/event.js";
13
13
  import { FeatureName, isFeatureEnabled } from "../features/feature_registry.js";
14
14
  import { createLlmResponse } from "../models/llm_response.js";
15
15
  const UNSAFE_PROPERTY_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
@@ -330,10 +330,16 @@ class StreamingResponseAggregator {
330
330
  const candidate = (_b = (_a = this.response) == null ? void 0 : _a.candidates) == null ? void 0 : _b[0];
331
331
  const finishReason = (_c = this.finishReason) != null ? _c : candidate == null ? void 0 : candidate.finishReason;
332
332
  return {
333
- content: {
334
- role: "model",
335
- parts: finalParts != null ? finalParts : []
336
- },
333
+ // Only attach a model `content` when there are actual parts to emit. When
334
+ // the turn accumulated no parts (e.g. a function call that was already
335
+ // flushed, followed by a trailing STOP chunk that carries only usage
336
+ // metadata) we still surface that trailing metadata, but MUST NOT emit
337
+ // `content: { parts: [] }`. An empty-parts model turn corrupts the session
338
+ // history: on the next request the Vertex AI backend rejects the whole
339
+ // call with HTTP 400 "Unable to submit request because it must include at
340
+ // least one parts field", which breaks multi-turn tool-using sessions
341
+ // right after the first tool call (google/adk-js#21, #22).
342
+ content: finalParts ? { role: "model", parts: finalParts } : void 0,
337
343
  groundingMetadata: this.groundingMetadata,
338
344
  citationMetadata: this.citationMetadata,
339
345
  errorCode: finishReason === FinishReason.STOP ? void 0 : finishReason,
@@ -0,0 +1,34 @@
1
+ import {createRequire as topLevelCreateRequire} from 'module';
2
+ const require = topLevelCreateRequire(import.meta.url);
3
+ /**
4
+ * @license
5
+ * Copyright 2026 Google LLC
6
+ * SPDX-License-Identifier: Apache-2.0
7
+ */
8
+ class Task {
9
+ constructor(executable) {
10
+ this.executable = executable;
11
+ this.isDone = false;
12
+ this.abortController = new AbortController();
13
+ const markDone = () => {
14
+ this.isDone = true;
15
+ };
16
+ this.promise = executable(this.abortController.signal);
17
+ this.promise.then(markDone).catch(markDone);
18
+ }
19
+ /**
20
+ * Cancels the task execution.
21
+ */
22
+ cancel() {
23
+ this.abortController.abort();
24
+ }
25
+ /**
26
+ * Returns true if the task has completed (either resolved or rejected).
27
+ */
28
+ done() {
29
+ return this.isDone;
30
+ }
31
+ }
32
+ export {
33
+ Task
34
+ };
@@ -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
- const version = "1.3.0";
8
+ const version = "1.5.0";
9
9
  export {
10
10
  version
11
11
  };
@@ -68,8 +68,12 @@ export interface RemoteA2AAgentConfig extends BaseAgentConfig {
68
68
  }
69
69
  /**
70
70
  * RemoteA2AAgent delegates execution to a remote agent using the A2A protocol.
71
+ *
72
+ * @remarks
73
+ * A cloned `RemoteA2AAgent` (via {@link BaseAgent.clone}) is a fresh,
74
+ * uninitialized instance that re-resolves its client and card on first use.
71
75
  */
72
- export declare class RemoteA2AAgent extends BaseAgent {
76
+ export declare class RemoteA2AAgent extends BaseAgent<RemoteA2AAgentConfig> {
73
77
  private readonly a2aConfig;
74
78
  private client?;
75
79
  private card?;
@@ -4,12 +4,25 @@
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
  import { AgentCard } from '@a2a-js/sdk';
7
+ import { UserBuilder } from '@a2a-js/sdk/server/express';
7
8
  import express from 'express';
8
9
  import { BaseAgent } from '../agents/base_agent.js';
9
10
  import { BaseArtifactService } from '../artifacts/base_artifact_service.js';
10
11
  import { BaseMemoryService } from '../memory/base_memory_service.js';
11
12
  import { Runner } from '../runner/runner.js';
12
13
  import { BaseSessionService } from '../sessions/base_session_service.js';
14
+ /**
15
+ * A request authenticator for the A2A surface.
16
+ *
17
+ * This is the `UserBuilder` hook from `@a2a-js/sdk`: an async function that
18
+ * receives the incoming Express request, validates its credentials (for
19
+ * example a bearer token or an OIDC ID token) and resolves to the
20
+ * authenticated `User`. Implementations should reject unauthenticated
21
+ * requests by throwing (or by resolving to a user whose `isAuthenticated` is
22
+ * `false`), which prevents the underlying agent and its tools from being
23
+ * invoked by anonymous callers.
24
+ */
25
+ export type A2aUserBuilder = UserBuilder;
13
26
  /**
14
27
  * Options for the `toA2a` function.
15
28
  */
@@ -34,6 +47,31 @@ export interface ToA2aOptions {
34
47
  artifactService?: BaseArtifactService;
35
48
  /** Optional existing express application */
36
49
  app?: express.Application;
50
+ /**
51
+ * Authenticator used to validate incoming A2A requests.
52
+ *
53
+ * A2A is the production-intended inter-agent surface: any network-reachable
54
+ * caller that can reach it can invoke the agent and its tools with arbitrary
55
+ * input and read the output. Provide a `UserBuilder` (from
56
+ * `@a2a-js/sdk/server/express`) that validates the request's credentials —
57
+ * for example a bearer token or an OIDC ID token — and it will be wired into
58
+ * both the REST and JSON-RPC handlers.
59
+ *
60
+ * When omitted, `toA2a` fails closed and throws unless
61
+ * {@link ToA2aOptions.allowUnauthenticated} is explicitly set to `true`.
62
+ */
63
+ authentication?: A2aUserBuilder;
64
+ /**
65
+ * Explicit escape hatch to mount the A2A surface WITHOUT authentication.
66
+ *
67
+ * This is intentionally insecure and must only be used for local, trusted
68
+ * development where the surface is not network reachable. When set to
69
+ * `true` (and no {@link ToA2aOptions.authentication} is provided), a loud
70
+ * warning is logged and the handlers are mounted with no authentication.
71
+ *
72
+ * Defaults to `false`, which makes `toA2a` fail closed.
73
+ */
74
+ allowUnauthenticated?: boolean;
37
75
  }
38
76
  /**
39
77
  * Converts an ADK agent to an Express application with A2A handlers.
@@ -3,12 +3,13 @@
3
3
  * Copyright 2025 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
+ import { Task } from '../utils/task.js';
6
7
  import { LiveRequestQueue } from './live_request_queue.js';
7
8
  /**
8
9
  * The parameters for creating an ActiveStreamingTool.
9
10
  */
10
11
  export interface ActiveStreamingToolParams {
11
- task?: Promise<void>;
12
+ task?: Task<void> | Promise<void>;
12
13
  stream?: LiveRequestQueue;
13
14
  }
14
15
  /**
@@ -17,10 +18,8 @@ export interface ActiveStreamingToolParams {
17
18
  export declare class ActiveStreamingTool {
18
19
  /**
19
20
  * The active task of this streaming tool.
20
- * TODO: Replace 'Promise<void>' with a proper Task type if available in this
21
- * env.
22
21
  */
23
- task?: Promise<void>;
22
+ task?: Task<void>;
24
23
  /**
25
24
  * The active (input) streams of this streaming tool.
26
25
  */
@@ -45,12 +45,25 @@ declare const BASE_AGENT_SIGNATURE_SYMBOL: unique symbol;
45
45
  export declare function isBaseAgent(obj: unknown): obj is BaseAgent;
46
46
  /**
47
47
  * Base class for all agents in Agent Development Kit.
48
+ *
49
+ * The class is generic over its config type so that {@link clone} can be typed
50
+ * per subclass (e.g. `LlmAgent.clone({instruction})`). The default keeps bare
51
+ * `BaseAgent` references valid as `BaseAgent<BaseAgentConfig>`.
48
52
  */
49
- export declare abstract class BaseAgent {
53
+ export declare abstract class BaseAgent<TConfig extends BaseAgentConfig = BaseAgentConfig> {
50
54
  /**
51
55
  * A unique symbol to identify ADK agent classes.
52
56
  */
53
57
  readonly [BASE_AGENT_SIGNATURE_SYMBOL] = true;
58
+ /**
59
+ * The config this agent was constructed from.
60
+ *
61
+ * Stored so {@link clone} can rebuild the agent by re-running the concrete
62
+ * constructor with overrides applied, which re-derives all state correctly
63
+ * instead of copying an already-mutated instance. Shallow-copied so later
64
+ * external mutation of the caller's object does not leak into clones.
65
+ */
66
+ protected readonly config: TConfig;
54
67
  /**
55
68
  * The agent's name.
56
69
  * Agent name must be a JS identifier and unique within the agent tree.
@@ -112,6 +125,21 @@ export declare abstract class BaseAgent {
112
125
  */
113
126
  readonly afterAgentCallback: SingleAgentCallback[];
114
127
  constructor(config: BaseAgentConfig);
128
+ /**
129
+ * Creates a copy of this agent with the given config fields overridden.
130
+ *
131
+ * Mirrors adk-python's `BaseAgent.clone(update=...)`. The clone is a detached
132
+ * root: its `parentAgent` is always `undefined`. Sub-agents are recursively
133
+ * cloned (and re-parented to the clone) unless `subAgents` is overridden.
134
+ * Rebuilding via the concrete constructor re-derives all state, so a cloned
135
+ * `LlmAgent` gets a fresh `requestProcessors` array rather than sharing the
136
+ * original's. See google/adk-js#534.
137
+ *
138
+ * @param overrides Config fields to override on the clone. Overriding
139
+ * `parentAgent` is rejected, matching adk-python.
140
+ * @returns A new detached agent instance of the same concrete class.
141
+ */
142
+ clone(overrides?: Partial<TConfig>): this;
115
143
  /**
116
144
  * Entry method to run an agent via text-based conversation.
117
145
  *
@@ -3,12 +3,13 @@
3
3
  * Copyright 2025 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
- import { Content, FunctionCall } from '@google/genai';
6
+ import { FunctionCall } from '@google/genai';
7
7
  import { InvocationContext } from '../agents/invocation_context.js';
8
8
  import { Event } from '../events/event.js';
9
9
  import { BaseTool } from '../tools/base_tool.js';
10
10
  import { ToolConfirmation } from '../tools/tool_confirmation.js';
11
11
  import { SingleAfterToolCallback, SingleBeforeToolCallback } from './llm_agent.js';
12
+ export { AF_FUNCTION_CALL_ID_PREFIX, generateClientFunctionCallId, populateClientFunctionCallId, } from '../events/event.js';
12
13
  export declare const REQUEST_EUC_FUNCTION_CALL_NAME = "adk_request_credential";
13
14
  export declare const REQUEST_CONFIRMATION_FUNCTION_CALL_NAME = "adk_request_confirmation";
14
15
  export declare const functionsExportedForTestingOnly: {
@@ -16,22 +17,6 @@ export declare const functionsExportedForTestingOnly: {
16
17
  generateAuthEvent: typeof generateAuthEvent;
17
18
  generateRequestConfirmationEvent: typeof generateRequestConfirmationEvent;
18
19
  };
19
- export declare function generateClientFunctionCallId(): string;
20
- /**
21
- * Populates client-side function call IDs.
22
- *
23
- * It iterates through all function calls in the event and assigns a
24
- * unique client-side ID to each one that doesn't already have an ID.
25
- */
26
- export declare function populateClientFunctionCallId(modelResponseEvent: Event): void;
27
- /**
28
- * Removes the client-generated function call IDs from a given content object.
29
- *
30
- * When sending content back to the server, these IDs are
31
- * specific to the client-side and should not be included in requests to the
32
- * model.
33
- */
34
- export declare function removeClientFunctionCallId(content: Content): void;
35
20
  /**
36
21
  * Returns a set of function call ids of the long running tools.
37
22
  */
@@ -90,3 +75,13 @@ export declare function handleFunctionCallList({ invocationContext, functionCall
90
75
  * Merges a list of function response events into a single event.
91
76
  */
92
77
  export declare function mergeParallelFunctionResponseEvents(functionResponseEvents: Event[]): Event;
78
+ /**
79
+ * Finds the function call event that matches the function call ID.
80
+ * Mirrors Python ADK's `find_event_by_function_call_id`.
81
+ */
82
+ export declare function findEventByFunctionCallId(events: Event[], functionCallId: string, endIndex?: number): Event | undefined;
83
+ /**
84
+ * Finds the function call event that matches the function response ID of the last event.
85
+ * Mirrors Python ADK's `find_matching_function_call`.
86
+ */
87
+ export declare function findMatchingFunctionCall(events: Event[]): Event | undefined;
@@ -4,7 +4,7 @@
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
  import { Content } from '@google/genai';
7
- import { BaseArtifactService } from '../artifacts/base_artifact_service.js';
7
+ import { SessionArtifactService } from '../artifacts/session_artifact_service.js';
8
8
  import { BaseCredentialService } from '../auth/credential_service/base_credential_service.js';
9
9
  import { BaseMemoryService } from '../memory/base_memory_service.js';
10
10
  import { PluginManager } from '../plugins/plugin_manager.js';
@@ -18,7 +18,7 @@ import { TranscriptionEntry } from './transcription_entry.js';
18
18
  * The parameters for creating an invocation context.
19
19
  */
20
20
  export interface InvocationContextParams {
21
- artifactService?: BaseArtifactService;
21
+ artifactService?: SessionArtifactService;
22
22
  sessionService?: BaseSessionService;
23
23
  memoryService?: BaseMemoryService;
24
24
  credentialService?: BaseCredentialService;
@@ -74,7 +74,7 @@ export interface InvocationContextParams {
74
74
  * ```
75
75
  */
76
76
  export declare class InvocationContext {
77
- readonly artifactService?: BaseArtifactService;
77
+ readonly artifactService?: SessionArtifactService;
78
78
  readonly sessionService?: BaseSessionService;
79
79
  readonly memoryService?: BaseMemoryService;
80
80
  readonly credentialService?: BaseCredentialService;
@@ -120,6 +120,10 @@ export declare class InvocationContext {
120
120
  /**
121
121
  * A container to keep track of different kinds of costs incurred as a part of
122
122
  * this invocation.
123
+ *
124
+ * This is shared across every agent context of the same invocation (see the
125
+ * constructor) so run-wide limits such as `maxLlmCalls` are enforced for the
126
+ * whole invocation rather than resetting for each agent/sub-agent.
123
127
  */
124
128
  private readonly invocationCostManager;
125
129
  /**
@@ -130,6 +130,8 @@ export interface LlmAgentConfig extends BaseAgentConfig {
130
130
  *
131
131
  * For example: use globalInstruction to make all agents have a stable
132
132
  * identity or personality.
133
+ *
134
+ * @deprecated Use GlobalInstructionPlugin instead.
133
135
  */
134
136
  globalInstruction?: string | InstructionProvider;
135
137
  /** Tools available to this agent. */
@@ -224,11 +226,12 @@ export declare function isLlmAgent(obj: unknown): obj is LlmAgent;
224
226
  /**
225
227
  * An agent that uses a large language model to generate responses.
226
228
  */
227
- export declare class LlmAgent extends BaseAgent {
229
+ export declare class LlmAgent extends BaseAgent<LlmAgentConfig> {
228
230
  /** A unique symbol to identify ADK LLM agent class. */
229
231
  readonly [LLM_AGENT_SIGNATURE_SYMBOL] = true;
230
232
  model?: string | BaseLlm;
231
233
  instruction: string | InstructionProvider;
234
+ /** @deprecated Use GlobalInstructionPlugin instead. */
232
235
  globalInstruction: string | InstructionProvider;
233
236
  tools: ToolUnion[];
234
237
  generateContentConfig?: GenerateContentConfig;
@@ -270,6 +273,7 @@ export declare class LlmAgent extends BaseAgent {
270
273
  * This method is only for use by Agent Development Kit.
271
274
  * @param context The context to retrieve the session state.
272
275
  * @returns The resolved globalInstruction field.
276
+ * @deprecated Use GlobalInstructionPlugin instead.
273
277
  */
274
278
  canonicalGlobalInstruction(context: ReadonlyContext): Promise<{
275
279
  instruction: string;
@@ -34,7 +34,7 @@ export declare function isLoopAgent(obj: unknown): obj is LoopAgent;
34
34
  * When sub-agent generates an event with escalate or max_iterations are
35
35
  * reached, the loop agent will stop.
36
36
  */
37
- export declare class LoopAgent extends BaseAgent {
37
+ export declare class LoopAgent extends BaseAgent<LoopAgentConfig> {
38
38
  /**
39
39
  * A unique symbol to identify ADK loop agent class.
40
40
  */
@@ -42,6 +42,6 @@ export declare class LoopAgent extends BaseAgent {
42
42
  readonly maxIterations: number;
43
43
  constructor(config: LoopAgentConfig);
44
44
  protected runAsyncImpl(context: InvocationContext): AsyncGenerator<Event, void, void>;
45
- protected runLiveImpl(_context: InvocationContext): AsyncGenerator<Event, void, void>;
45
+ protected runLiveImpl(context: InvocationContext): AsyncGenerator<Event, void, void>;
46
46
  }
47
47
  export {};
@@ -5,6 +5,14 @@
5
5
  */
6
6
  import { Content } from '@google/genai';
7
7
  import { Event } from '../../events/event.js';
8
+ /**
9
+ * Removes the client-generated function call IDs from a given content object.
10
+ *
11
+ * When sending content back to the server, these IDs are
12
+ * specific to the client-side and should not be included in requests to the
13
+ * model.
14
+ */
15
+ export declare function removeClientFunctionCallId(content: Content): void;
8
16
  /**
9
17
  * Get the contents for the LLM request.
10
18
  *
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { Event } from '../../events/event.js';
7
+ import { LlmRequest } from '../../models/llm_request.js';
8
+ import { InvocationContext } from '../invocation_context.js';
9
+ import { BaseLlmRequestProcessor } from './base_llm_processor.js';
10
+ /**
11
+ * Request processor for Gemini Interactions API.
12
+ * Resolves the previous interaction ID from the session history.
13
+ */
14
+ export declare class InteractionsRequestProcessor implements BaseLlmRequestProcessor {
15
+ runAsync(invocationContext: InvocationContext, llmRequest: LlmRequest): AsyncGenerator<Event, void, void>;
16
+ }
17
+ export declare const INTERACTIONS_REQUEST_PROCESSOR: InteractionsRequestProcessor;
@@ -41,12 +41,35 @@ export interface RoutedAgentConfig extends BaseAgentConfig {
41
41
  /**
42
42
  * A BaseAgent implementation that delegates to one of multiple agents based on a router function.
43
43
  * Routing is strictly limited to the agents passed in the config.
44
+ *
45
+ * @remarks
46
+ * Cloning is supported: {@link RoutedAgent.clone} deep-clones the routing
47
+ * targets from `config.agents` and re-parents the fresh copies onto the clone,
48
+ * so the clone is a detached root that routes identically to the original while
49
+ * leaving the original agent tree untouched.
44
50
  */
45
- export declare class RoutedAgent extends BaseAgent {
51
+ export declare class RoutedAgent extends BaseAgent<RoutedAgentConfig> {
46
52
  readonly [ROUTED_AGENT_SIGNATURE_SYMBOL] = true;
47
53
  private readonly agents;
48
54
  private readonly router;
49
55
  constructor(config: RoutedAgentConfig);
56
+ /**
57
+ * Creates a detached copy of this routed agent.
58
+ *
59
+ * The inherited {@link BaseAgent.clone} only deep-clones `subAgents`, but a
60
+ * `RoutedAgent` derives its routing targets from `config.agents`. Rebuilding
61
+ * through the base clone alone would re-read the already-parented original
62
+ * agents and throw "already has a parent agent". This override deep-clones the
63
+ * routing targets (unless the caller overrides `agents`) so the rebuilt
64
+ * constructor re-parents fresh, detached copies. The array-vs-record shape
65
+ * and, for records, the keys are preserved so the router keeps selecting the
66
+ * same targets.
67
+ *
68
+ * @param overrides Config fields to override on the clone. Overriding
69
+ * `parentAgent` is rejected by the base implementation.
70
+ * @returns A new detached `RoutedAgent` of the same concrete class.
71
+ */
72
+ clone(overrides?: Partial<RoutedAgentConfig>): this;
50
73
  /**
51
74
  * Runs the selected agent via text-based conversation.
52
75
  */
@@ -94,6 +94,7 @@ export interface RunConfig {
94
94
  * @throws {Error} When `params.maxLlmCalls` exceeds `Number.MAX_SAFE_INTEGER`.
95
95
  */
96
96
  export declare function createRunConfig(params?: Partial<RunConfig>): {
97
+ maxLlmCalls: number;
97
98
  speechConfig?: SpeechConfig | undefined;
98
99
  responseModalities?: Modality[] | undefined;
99
100
  saveInputBlobsAsArtifacts: boolean;
@@ -104,6 +105,5 @@ export declare function createRunConfig(params?: Partial<RunConfig>): {
104
105
  enableAffectiveDialog: boolean;
105
106
  proactivity?: ProactivityConfig | undefined;
106
107
  realtimeInputConfig?: RealtimeInputConfig | undefined;
107
- maxLlmCalls: number;
108
108
  pauseOnToolCalls: boolean;
109
109
  };
@@ -0,0 +1,52 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { BaseAgent } from '../agents/base_agent.js';
7
+ import { BasePlugin } from '../plugins/base_plugin.js';
8
+ import { ResumabilityConfig } from './resumability_config.js';
9
+ /**
10
+ * Ensures the provided application name is safe and intuitive.
11
+ */
12
+ export declare function validateAppName(name: string): void;
13
+ /**
14
+ * A unique symbol to identify ADK App classes.
15
+ * Defined once and shared by all App instances.
16
+ */
17
+ declare const APP_SIGNATURE_SYMBOL: unique symbol;
18
+ /**
19
+ * Type guard to check if an object is an instance of App.
20
+ * @param obj The object to check.
21
+ * @returns True if the object is an instance of App, false otherwise.
22
+ */
23
+ export declare function isApp(obj: unknown): obj is App;
24
+ /**
25
+ * Options for initializing an App.
26
+ */
27
+ export interface AppOptions {
28
+ name: string;
29
+ rootAgent: BaseAgent;
30
+ plugins?: BasePlugin[];
31
+ resumabilityConfig?: ResumabilityConfig;
32
+ }
33
+ /**
34
+ * Represents an LLM-backed agentic application.
35
+ *
36
+ * An `App` is the top-level container for an agentic system powered by LLMs.
37
+ * It manages a root agent (`rootAgent`), which serves as the entry point for execution.
38
+ *
39
+ * Exactly one `rootAgent` must be provided.
40
+ *
41
+ * The `plugins` are application-wide components that provide shared capabilities
42
+ * and services to the entire system.
43
+ */
44
+ export declare class App {
45
+ readonly [APP_SIGNATURE_SYMBOL] = true;
46
+ readonly name: string;
47
+ readonly rootAgent: BaseAgent | any;
48
+ readonly plugins: BasePlugin[];
49
+ readonly resumabilityConfig?: ResumabilityConfig;
50
+ constructor(options: AppOptions);
51
+ }
52
+ export {};
@@ -0,0 +1,27 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ /**
7
+ * The configuration of resumability for an application or runner.
8
+ *
9
+ * The "resumability" in ADK refers to the ability to:
10
+ * 1. pause an invocation upon a long-running function call.
11
+ * 2. resume an invocation from the last event, if it's paused or failed midway
12
+ * through.
13
+ */
14
+ export interface ResumabilityConfig {
15
+ /**
16
+ * Whether the app/runner supports agent resumption.
17
+ * If enabled, resumption routing based on matching function responses will be active.
18
+ */
19
+ isResumable: boolean;
20
+ }
21
+ /**
22
+ * Creates a {@link ResumabilityConfig} with default values.
23
+ *
24
+ * @param params Optional partial {@link ResumabilityConfig} overriding defaults.
25
+ * @returns A merged {@link ResumabilityConfig} object.
26
+ */
27
+ export declare function createResumabilityConfig(params?: Partial<ResumabilityConfig>): ResumabilityConfig;