@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
@@ -130,7 +130,12 @@ class RemoteA2AAgent extends import_base_agent.BaseAgent {
130
130
  await callback(context, chunk);
131
131
  }
132
132
  }
133
- const adkEvent = (0, import_event_converter_utils.toAdkEvent)(chunk, context.invocationId, this.name);
133
+ const adkEvent = (0, import_event_converter_utils.toAdkEvent)(
134
+ chunk,
135
+ context.invocationId,
136
+ this.name,
137
+ context.branch
138
+ );
134
139
  if (!adkEvent) {
135
140
  continue;
136
141
  }
@@ -151,7 +156,12 @@ class RemoteA2AAgent extends import_base_agent.BaseAgent {
151
156
  await callback(context, result);
152
157
  }
153
158
  }
154
- const adkEvent = (0, import_event_converter_utils.toAdkEvent)(result, context.invocationId, this.name);
159
+ const adkEvent = (0, import_event_converter_utils.toAdkEvent)(
160
+ result,
161
+ context.invocationId,
162
+ this.name,
163
+ context.branch
164
+ );
155
165
  if (adkEvent) {
156
166
  processor.updateCustomMetadata(adkEvent, result);
157
167
  yield adkEvent;
@@ -43,6 +43,7 @@ var import_express = require("@a2a-js/sdk/server/express");
43
43
  var import_express2 = __toESM(require("express"), 1);
44
44
  var import_run_config = require("../agents/run_config.js");
45
45
  var import_in_memory_session_service = require("../sessions/in_memory_session_service.js");
46
+ var import_logger = require("../utils/logger.js");
46
47
  var import_agent_card = require("./agent_card.js");
47
48
  var import_agent_executor = require("./agent_executor.js");
48
49
  /**
@@ -50,8 +51,23 @@ var import_agent_executor = require("./agent_executor.js");
50
51
  * Copyright 2026 Google LLC
51
52
  * SPDX-License-Identifier: Apache-2.0
52
53
  */
54
+ function resolveA2aUserBuilder(options) {
55
+ if (options.authentication) {
56
+ return options.authentication;
57
+ }
58
+ if (options.allowUnauthenticated === true) {
59
+ import_logger.logger.warn(
60
+ "SECURITY WARNING: Mounting the A2A server WITHOUT authentication because `allowUnauthenticated: true` was set. The agent and all of its tools are exposed to any network-reachable caller, which can invoke them with arbitrary input and read the output. Do NOT use this outside of local, trusted development."
61
+ );
62
+ return import_express.UserBuilder.noAuthentication;
63
+ }
64
+ throw new Error(
65
+ "toA2a: refusing to mount the A2A server without authentication. The A2A surface lets any network-reachable caller invoke this agent and its tools with arbitrary input and read the output, so it must be authenticated. Provide `authentication` (a UserBuilder that validates the request, e.g. a bearer token or OIDC credential) or, only for local/trusted development, explicitly set `allowUnauthenticated: true`."
66
+ );
67
+ }
53
68
  async function toA2a(agent, options = {}) {
54
69
  var _a, _b, _c, _d;
70
+ const userBuilder = resolveA2aUserBuilder(options);
55
71
  const host = (_a = options.host) != null ? _a : "localhost";
56
72
  const port = (_b = options.port) != null ? _b : 8e3;
57
73
  const protocol = (_c = options.protocol) != null ? _c : "http";
@@ -86,7 +102,6 @@ async function toA2a(agent, options = {}) {
86
102
  );
87
103
  const app = (_d = options.app) != null ? _d : (0, import_express2.default)();
88
104
  if (!options.app) {
89
- app.use(import_express2.default.urlencoded({ limit: "50mb", extended: true }));
90
105
  app.use(import_express2.default.json({ limit: "50mb" }));
91
106
  }
92
107
  app.use(
@@ -97,14 +112,14 @@ async function toA2a(agent, options = {}) {
97
112
  `${basePath}/rest`,
98
113
  (0, import_express.restHandler)({
99
114
  requestHandler,
100
- userBuilder: import_express.UserBuilder.noAuthentication
115
+ userBuilder
101
116
  })
102
117
  );
103
118
  app.use(
104
119
  `${basePath}/jsonrpc`,
105
120
  (0, import_express.jsonRpcHandler)({
106
121
  requestHandler,
107
- userBuilder: import_express.UserBuilder.noAuthentication
122
+ userBuilder
108
123
  })
109
124
  );
110
125
  return app;
@@ -0,0 +1,65 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ "use strict";
8
+ var __defProp = Object.defineProperty;
9
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
10
+ var __getOwnPropNames = Object.getOwnPropertyNames;
11
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
12
+ var __export = (target, all) => {
13
+ for (var name in all)
14
+ __defProp(target, name, { get: all[name], enumerable: true });
15
+ };
16
+ var __copyProps = (to, from, except, desc) => {
17
+ if (from && typeof from === "object" || typeof from === "function") {
18
+ for (let key of __getOwnPropNames(from))
19
+ if (!__hasOwnProp.call(to, key) && key !== except)
20
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
21
+ }
22
+ return to;
23
+ };
24
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
+ var auth_exports = {};
26
+ __export(auth_exports, {
27
+ bearerTokenUserBuilder: () => bearerTokenUserBuilder
28
+ });
29
+ module.exports = __toCommonJS(auth_exports);
30
+ var import_node_crypto = require("node:crypto");
31
+ /**
32
+ * @license
33
+ * Copyright 2026 Google LLC
34
+ * SPDX-License-Identifier: Apache-2.0
35
+ */
36
+ const AUTHENTICATED_USER_NAME = "a2a-bearer-token";
37
+ const BEARER_SCHEME_PREFIX = "bearer ";
38
+ function timingSafeEqualStrings(a, b) {
39
+ const left = Buffer.from(a, "utf8");
40
+ const right = Buffer.from(b, "utf8");
41
+ return left.length === right.length && (0, import_node_crypto.timingSafeEqual)(left, right);
42
+ }
43
+ function bearerTokenUserBuilder(token) {
44
+ const expected = token.trim();
45
+ if (!expected) {
46
+ throw new Error(
47
+ "bearerTokenUserBuilder: an empty A2A bearer token is not a valid authenticator. Supply a real shared secret, or configure no token at all to run the A2A surface unauthenticated."
48
+ );
49
+ }
50
+ return async (req) => {
51
+ var _a;
52
+ const header = (_a = req.headers.authorization) != null ? _a : "";
53
+ const credential = header.toLowerCase().startsWith(BEARER_SCHEME_PREFIX) ? header.slice(BEARER_SCHEME_PREFIX.length) : "";
54
+ if (!timingSafeEqualStrings(credential, expected)) {
55
+ throw new Error(
56
+ "A2A request rejected: missing or invalid `Authorization: Bearer` credential."
57
+ );
58
+ }
59
+ return { isAuthenticated: true, userName: AUTHENTICATED_USER_NAME };
60
+ };
61
+ }
62
+ // Annotate the CommonJS export names for ESM import in node:
63
+ 0 && (module.exports = {
64
+ bearerTokenUserBuilder
65
+ });
@@ -54,33 +54,35 @@ function toA2AMessage(event, {
54
54
  metadata: (0, import_metadata_converter_utils.getA2AEventMetadata)(event, { appName, userId, sessionId })
55
55
  };
56
56
  }
57
- function toAdkEvent(event, invocationId, agentName) {
57
+ function toAdkEvent(event, invocationId, agentName, branch) {
58
58
  if ((0, import_a2a_event.isMessage)(event)) {
59
- return messageToAdkEvent(event, invocationId, agentName);
59
+ return messageToAdkEvent(event, invocationId, agentName, branch);
60
60
  }
61
61
  if ((0, import_a2a_event.isTask)(event)) {
62
- return taskToAdkEvent(event, invocationId, agentName);
62
+ return taskToAdkEvent(event, invocationId, agentName, branch);
63
63
  }
64
64
  if ((0, import_a2a_event.isTaskArtifactUpdateEvent)(event)) {
65
- return artifactUpdateToAdkEvent(event, invocationId, agentName);
65
+ return artifactUpdateToAdkEvent(event, invocationId, agentName, branch);
66
66
  }
67
67
  if ((0, import_a2a_event.isTaskStatusUpdateEvent)(event)) {
68
- return event.final ? finalTaskStatusUpdateToAdkEvent(event, invocationId, agentName) : taskStatusUpdateToAdkEvent(event, invocationId, agentName);
68
+ return event.final ? finalTaskStatusUpdateToAdkEvent(event, invocationId, agentName, branch) : taskStatusUpdateToAdkEvent(event, invocationId, agentName, branch);
69
69
  }
70
70
  return void 0;
71
71
  }
72
- function messageToAdkEvent(msg, invocationId, agentName, parentEvent) {
72
+ function messageToAdkEvent(msg, invocationId, agentName, branch) {
73
73
  const parts = (0, import_part_converter_utils.toGenAIParts)(msg.parts);
74
+ const content = parts.length === 0 ? void 0 : msg.role === import_a2a_event.MessageRole.USER ? (0, import_genai.createUserContent)(parts) : (0, import_genai.createModelContent)(parts);
74
75
  return {
75
- ...createAdkEventFromMetadata(parentEvent || msg),
76
+ ...createAdkEventFromMetadata(msg),
76
77
  invocationId,
77
78
  author: msg.role === import_a2a_event.MessageRole.USER ? import_a2a_event.MessageRole.USER : agentName,
78
- content: msg.role === import_a2a_event.MessageRole.USER ? (0, import_genai.createUserContent)(parts) : (0, import_genai.createModelContent)(parts),
79
+ branch,
80
+ content,
79
81
  turnComplete: true,
80
82
  partial: false
81
83
  };
82
84
  }
83
- function artifactUpdateToAdkEvent(a2aEvent, invocationId, agentName) {
85
+ function artifactUpdateToAdkEvent(a2aEvent, invocationId, agentName, branch) {
84
86
  var _a;
85
87
  const partsToConvert = ((_a = a2aEvent.artifact) == null ? void 0 : _a.parts) || [];
86
88
  if (partsToConvert.length === 0) {
@@ -91,12 +93,13 @@ function artifactUpdateToAdkEvent(a2aEvent, invocationId, agentName) {
91
93
  ...createAdkEventFromMetadata(a2aEvent),
92
94
  invocationId,
93
95
  author: agentName,
96
+ branch,
94
97
  content: (0, import_genai.createModelContent)((0, import_part_converter_utils.toGenAIParts)(partsToConvert)),
95
98
  longRunningToolIds: getLongRunningToolIDs(partsToConvert),
96
99
  partial
97
100
  };
98
101
  }
99
- function finalTaskStatusUpdateToAdkEvent(a2aEvent, invocationId, agentName) {
102
+ function finalTaskStatusUpdateToAdkEvent(a2aEvent, invocationId, agentName, branch) {
100
103
  var _a;
101
104
  const partsToConvert = ((_a = a2aEvent.status.message) == null ? void 0 : _a.parts) || [];
102
105
  if (partsToConvert.length === 0) {
@@ -109,28 +112,33 @@ function finalTaskStatusUpdateToAdkEvent(a2aEvent, invocationId, agentName) {
109
112
  ...createAdkEventFromMetadata(a2aEvent),
110
113
  invocationId,
111
114
  author: agentName,
115
+ branch,
112
116
  errorMessage: isFailedTask ? (0, import_a2a_event.getFailedTaskStatusUpdateEventError)(a2aEvent) : void 0,
113
117
  content: hasContent ? (0, import_genai.createModelContent)(parts) : void 0,
114
118
  longRunningToolIds: getLongRunningToolIDs(partsToConvert),
115
119
  turnComplete: true
116
120
  };
117
121
  }
118
- function taskStatusUpdateToAdkEvent(a2aEvent, invocationId, agentName) {
122
+ function taskStatusUpdateToAdkEvent(a2aEvent, invocationId, agentName, branch) {
119
123
  const msg = a2aEvent.status.message;
120
124
  if (!msg) {
121
125
  return void 0;
122
126
  }
123
127
  const parts = (0, import_part_converter_utils.toGenAIParts)(msg.parts);
128
+ if (parts.length === 0) {
129
+ return void 0;
130
+ }
124
131
  return {
125
132
  ...createAdkEventFromMetadata(a2aEvent),
126
133
  invocationId,
127
134
  author: agentName,
135
+ branch,
128
136
  content: (0, import_genai.createModelContent)(parts),
129
137
  turnComplete: false,
130
138
  partial: true
131
139
  };
132
140
  }
133
- function taskToAdkEvent(a2aTask, invocationId, agentName) {
141
+ function taskToAdkEvent(a2aTask, invocationId, agentName, branch) {
134
142
  var _a, _b;
135
143
  const parts = [];
136
144
  const longRunningToolIds = [];
@@ -151,23 +159,33 @@ function taskToAdkEvent(a2aTask, invocationId, agentName) {
151
159
  }
152
160
  const isTerminal = (0, import_a2a_event.isTerminalTaskStatusUpdateEvent)(a2aTask) || (0, import_a2a_event.isInputRequiredTaskStatusUpdateEvent)(a2aTask);
153
161
  const isFailed = (0, import_a2a_event.isFailedTaskStatusUpdateEvent)(a2aTask);
154
- if (parts.length === 0 && !isTerminal) {
162
+ if (parts.length === 0 && !isFailed) {
155
163
  return void 0;
156
164
  }
157
165
  return {
158
166
  ...createAdkEventFromMetadata(a2aTask),
159
167
  invocationId,
160
168
  author: agentName,
169
+ branch,
161
170
  content: isFailed ? void 0 : (0, import_genai.createModelContent)(parts),
162
171
  errorMessage: isFailed ? (0, import_a2a_event.getFailedTaskStatusUpdateEventError)(a2aTask) : void 0,
163
172
  longRunningToolIds,
164
173
  turnComplete: isTerminal
165
174
  };
166
175
  }
176
+ const PEER_SETTABLE_ACTION_FIELDS = /* @__PURE__ */ new Set(["escalate"]);
167
177
  function createAdkEventFromMetadata(a2aEvent) {
168
178
  const metadata = a2aEvent.metadata || {};
169
179
  return (0, import_event.createEvent)({
170
- branch: metadata[import_metadata_converter_utils.A2AMetadataKeys.BRANCH],
180
+ // `branch` is intentionally NOT restored from peer metadata here (unlike
181
+ // the other fields below): it is the mechanism getContents() (see
182
+ // content_processor_utils.ts) uses to keep sibling sub-agent branches'
183
+ // conversation contexts isolated from each other. A remote A2A peer that
184
+ // controls its own outgoing metadata could otherwise forge `adk_branch`
185
+ // (set it to a shared ancestor branch, or omit it) to leak its content
186
+ // into an unrelated sibling agent's LLM context. Every caller of the
187
+ // `*ToAdkEvent` functions in this file force-sets `branch` from its own
188
+ // local `InvocationContext` instead, the same way `author` is handled.
171
189
  author: metadata[import_metadata_converter_utils.A2AMetadataKeys.AUTHOR],
172
190
  partial: metadata[import_metadata_converter_utils.A2AMetadataKeys.PARTIAL],
173
191
  errorCode: metadata[import_metadata_converter_utils.A2AMetadataKeys.ERROR_CODE],
@@ -176,10 +194,21 @@ function createAdkEventFromMetadata(a2aEvent) {
176
194
  groundingMetadata: metadata[import_metadata_converter_utils.A2AMetadataKeys.GROUNDING_METADATA],
177
195
  usageMetadata: metadata[import_metadata_converter_utils.A2AMetadataKeys.USAGE_METADATA],
178
196
  customMetadata: metadata[import_metadata_converter_utils.A2AMetadataKeys.CUSTOM_METADATA],
179
- actions: (0, import_event_actions.createEventActions)({
180
- escalate: !!metadata[import_metadata_converter_utils.A2AMetadataKeys.ESCALATE],
181
- transferToAgent: metadata[import_metadata_converter_utils.A2AMetadataKeys.TRANSFER_TO_AGENT]
182
- })
197
+ // Only fields in PEER_SETTABLE_ACTION_FIELDS may be restored from
198
+ // metadata a remote A2A peer controls. Every other action field either
199
+ // mutates the caller's own session or drives the caller's own control
200
+ // flow (e.g. `transferToAgent`, see llm_agent.ts), so it must never be
201
+ // rebuilt from peer-supplied data. Filtering through an allowlist here
202
+ // (rather than just omitting the unsafe field) means a future action
203
+ // field is unsafe-by-default: adding it to `candidateActions` alone
204
+ // does nothing until it's also added to the allowlist.
205
+ actions: (0, import_event_actions.createEventActions)(
206
+ Object.fromEntries(
207
+ Object.entries({
208
+ escalate: !!metadata[import_metadata_converter_utils.A2AMetadataKeys.ESCALATE]
209
+ }).filter(([key]) => PEER_SETTABLE_ACTION_FIELDS.has(key))
210
+ )
211
+ )
183
212
  });
184
213
  }
185
214
  function getLongRunningToolIDs(parts) {
@@ -88,7 +88,7 @@ function getA2AEventMetadata(adkEvent, {
88
88
  [A2AMetadataKeys.INVOCATION_ID]: adkEvent.invocationId,
89
89
  [A2AMetadataKeys.AUTHOR]: adkEvent.author,
90
90
  [A2AMetadataKeys.BRANCH]: adkEvent.branch,
91
- [A2AMetadataKeys.ERROR_CODE]: adkEvent.errorMessage,
91
+ [A2AMetadataKeys.ERROR_CODE]: adkEvent.errorCode,
92
92
  [A2AMetadataKeys.ERROR_MESSAGE]: adkEvent.errorMessage,
93
93
  [A2AMetadataKeys.CITATION_METADATA]: adkEvent.citationMetadata,
94
94
  [A2AMetadataKeys.GROUNDING_METADATA]: adkEvent.groundingMetadata,
@@ -51,6 +51,7 @@ class BaseAgent {
51
51
  * A unique symbol to identify ADK agent classes.
52
52
  */
53
53
  this[_a] = true;
54
+ this.config = { ...config };
54
55
  this.name = validateAgentName(config.name);
55
56
  this.description = config.description;
56
57
  this.parentAgent = config.parentAgent;
@@ -68,6 +69,44 @@ class BaseAgent {
68
69
  get rootAgent() {
69
70
  return getRootAgent(this);
70
71
  }
72
+ /**
73
+ * Creates a copy of this agent with the given config fields overridden.
74
+ *
75
+ * Mirrors adk-python's `BaseAgent.clone(update=...)`. The clone is a detached
76
+ * root: its `parentAgent` is always `undefined`. Sub-agents are recursively
77
+ * cloned (and re-parented to the clone) unless `subAgents` is overridden.
78
+ * Rebuilding via the concrete constructor re-derives all state, so a cloned
79
+ * `LlmAgent` gets a fresh `requestProcessors` array rather than sharing the
80
+ * original's. See google/adk-js#534.
81
+ *
82
+ * @param overrides Config fields to override on the clone. Overriding
83
+ * `parentAgent` is rejected, matching adk-python.
84
+ * @returns A new detached agent instance of the same concrete class.
85
+ */
86
+ clone(overrides) {
87
+ if (overrides && "parentAgent" in overrides) {
88
+ throw new Error(
89
+ "Cannot update `parentAgent` field in clone. Parent agent is set only when the parent agent is instantiated with the sub-agents."
90
+ );
91
+ }
92
+ const merged = { ...this.config, ...overrides };
93
+ merged.parentAgent = void 0;
94
+ const mergedRecord = merged;
95
+ for (const key of Object.keys(mergedRecord)) {
96
+ if (key === "subAgents" || overrides && key in overrides) {
97
+ continue;
98
+ }
99
+ const value = mergedRecord[key];
100
+ if (Array.isArray(value)) {
101
+ mergedRecord[key] = value.slice();
102
+ }
103
+ }
104
+ if (!overrides || !("subAgents" in overrides)) {
105
+ merged.subAgents = this.subAgents.map((subAgent) => subAgent.clone());
106
+ }
107
+ const ctor = this.constructor;
108
+ return new ctor(merged);
109
+ }
71
110
  /**
72
111
  * Entry method to run an agent via text-based conversation.
73
112
  *
@@ -24,36 +24,35 @@ var __copyProps = (to, from, except, desc) => {
24
24
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
25
  var functions_exports = {};
26
26
  __export(functions_exports, {
27
- AF_FUNCTION_CALL_ID_PREFIX: () => AF_FUNCTION_CALL_ID_PREFIX,
27
+ AF_FUNCTION_CALL_ID_PREFIX: () => import_event2.AF_FUNCTION_CALL_ID_PREFIX,
28
28
  REQUEST_CONFIRMATION_FUNCTION_CALL_NAME: () => REQUEST_CONFIRMATION_FUNCTION_CALL_NAME,
29
29
  REQUEST_EUC_FUNCTION_CALL_NAME: () => REQUEST_EUC_FUNCTION_CALL_NAME,
30
30
  findEventByFunctionCallId: () => findEventByFunctionCallId,
31
31
  findMatchingFunctionCall: () => findMatchingFunctionCall,
32
32
  functionsExportedForTestingOnly: () => functionsExportedForTestingOnly,
33
33
  generateAuthEvent: () => generateAuthEvent,
34
- generateClientFunctionCallId: () => generateClientFunctionCallId,
34
+ generateClientFunctionCallId: () => import_event2.generateClientFunctionCallId,
35
35
  generateRequestConfirmationEvent: () => generateRequestConfirmationEvent,
36
36
  getLongRunningFunctionCalls: () => getLongRunningFunctionCalls,
37
37
  handleFunctionCallList: () => handleFunctionCallList,
38
38
  handleFunctionCallsAsync: () => handleFunctionCallsAsync,
39
39
  mergeParallelFunctionResponseEvents: () => mergeParallelFunctionResponseEvents,
40
- populateClientFunctionCallId: () => populateClientFunctionCallId
40
+ populateClientFunctionCallId: () => import_event2.populateClientFunctionCallId
41
41
  });
42
42
  module.exports = __toCommonJS(functions_exports);
43
43
  var import_genai = require("@google/genai");
44
44
  var import_lodash_es = require("lodash-es");
45
45
  var import_event = require("../events/event.js");
46
46
  var import_event_actions = require("../events/event_actions.js");
47
- var import_env_aware_utils = require("../utils/env_aware_utils.js");
48
47
  var import_logger = require("../utils/logger.js");
49
48
  var import_context = require("./context.js");
50
49
  var import_tracing = require("../telemetry/tracing.js");
50
+ var import_event2 = require("../events/event.js");
51
51
  /**
52
52
  * @license
53
53
  * Copyright 2025 Google LLC
54
54
  * SPDX-License-Identifier: Apache-2.0
55
55
  */
56
- const AF_FUNCTION_CALL_ID_PREFIX = "adk-";
57
56
  const REQUEST_EUC_FUNCTION_CALL_NAME = "adk_request_credential";
58
57
  const REQUEST_CONFIRMATION_FUNCTION_CALL_NAME = "adk_request_confirmation";
59
58
  const functionsExportedForTestingOnly = {
@@ -61,20 +60,6 @@ const functionsExportedForTestingOnly = {
61
60
  generateAuthEvent,
62
61
  generateRequestConfirmationEvent
63
62
  };
64
- function generateClientFunctionCallId() {
65
- return `${AF_FUNCTION_CALL_ID_PREFIX}${(0, import_env_aware_utils.randomUUID)()}`;
66
- }
67
- function populateClientFunctionCallId(modelResponseEvent) {
68
- const functionCalls = (0, import_event.getFunctionCalls)(modelResponseEvent);
69
- if (!functionCalls) {
70
- return;
71
- }
72
- for (const functionCall of functionCalls) {
73
- if (!functionCall.id) {
74
- functionCall.id = generateClientFunctionCallId();
75
- }
76
- }
77
- }
78
63
  function getLongRunningFunctionCalls(functionCalls, toolsDict) {
79
64
  const longRunningToolIds = /* @__PURE__ */ new Set();
80
65
  for (const functionCall of functionCalls) {
@@ -100,7 +85,7 @@ function generateAuthEvent(invocationContext, functionResponseEvent) {
100
85
  "function_call_id": functionCallId,
101
86
  "auth_config": authConfig
102
87
  },
103
- id: generateClientFunctionCallId()
88
+ id: (0, import_event.generateClientFunctionCallId)()
104
89
  };
105
90
  longRunningToolIds.add(requestEucFunctionCall.id);
106
91
  parts.push({ functionCall: requestEucFunctionCall });
@@ -141,7 +126,7 @@ function generateRequestConfirmationEvent({
141
126
  "originalFunctionCall": originalFunctionCall,
142
127
  "toolConfirmation": toolConfirmation
143
128
  },
144
- id: generateClientFunctionCallId()
129
+ id: (0, import_event.generateClientFunctionCallId)()
145
130
  };
146
131
  longRunningToolIds.add(requestConfirmationFunctionCall.id);
147
132
  parts.push({ functionCall: requestConfirmationFunctionCall });
@@ -227,6 +212,18 @@ async function handleFunctionCallsAsync({
227
212
  toolConfirmationDict
228
213
  });
229
214
  }
215
+ function normalizeCallbackResponse(response) {
216
+ if (response == null) {
217
+ return void 0;
218
+ }
219
+ if (typeof response !== "object") {
220
+ return { result: response };
221
+ }
222
+ if (Array.isArray(response)) {
223
+ return { results: response };
224
+ }
225
+ return response;
226
+ }
230
227
  async function handleFunctionCallList({
231
228
  invocationContext,
232
229
  functionCalls,
@@ -273,6 +270,7 @@ async function handleFunctionCallList({
273
270
  }
274
271
  }
275
272
  }
273
+ functionResponse = normalizeCallbackResponse(functionResponse);
276
274
  if (functionResponse == null) {
277
275
  try {
278
276
  functionResponse = await callToolAsync(tool, functionArgs, toolContext);
@@ -284,8 +282,8 @@ async function handleFunctionCallList({
284
282
  toolContext,
285
283
  error: e
286
284
  });
287
- if (onToolErrorResponse) {
288
- functionResponse = onToolErrorResponse;
285
+ if (onToolErrorResponse != null) {
286
+ functionResponse = normalizeCallbackResponse(onToolErrorResponse);
289
287
  } else {
290
288
  functionResponseError = e.message;
291
289
  }
@@ -314,17 +312,17 @@ async function handleFunctionCallList({
314
312
  }
315
313
  }
316
314
  if (alteredFunctionResponse != null) {
317
- functionResponse = alteredFunctionResponse;
315
+ functionResponse = normalizeCallbackResponse(alteredFunctionResponse);
318
316
  }
319
- if (tool.isLongRunning && !functionResponse) {
317
+ if (tool.isLongRunning && functionResponse == null) {
320
318
  continue;
321
319
  }
322
320
  if (functionResponseError) {
323
321
  functionResponse = { error: functionResponseError };
324
- } else if (typeof functionResponse !== "object" || functionResponse == null) {
322
+ } else if (functionResponse == null) {
325
323
  functionResponse = { result: functionResponse };
326
- } else if (Array.isArray(functionResponse)) {
327
- functionResponse = { results: functionResponse };
324
+ } else {
325
+ functionResponse = normalizeCallbackResponse(functionResponse);
328
326
  }
329
327
  const functionResponseEvent = (0, import_event.createEvent)({
330
328
  invocationId: invocationContext.invocationId,
@@ -35,6 +35,7 @@ var import_base_llm = require("../models/base_llm.js");
35
35
  var import_registry = require("../models/registry.js");
36
36
  var import_base_tool = require("../tools/base_tool.js");
37
37
  var import_logger = require("../utils/logger.js");
38
+ var import_output_schema_utils = require("../utils/output_schema_utils.js");
38
39
  var import_context = require("./context.js");
39
40
  var import_tracing = require("../telemetry/tracing.js");
40
41
  var import_simple_zod_to_json = require("../utils/simple_zod_to_json.js");
@@ -195,6 +196,7 @@ class LlmAgent extends (_b = import_base_agent.BaseAgent, _a = LLM_AGENT_SIGNATU
195
196
  * This method is only for use by Agent Development Kit.
196
197
  * @param context The context to retrieve the session state.
197
198
  * @returns The resolved globalInstruction field.
199
+ * @deprecated Use GlobalInstructionPlugin instead.
198
200
  */
199
201
  async canonicalGlobalInstruction(context2) {
200
202
  if (typeof this.globalInstruction === "string") {
@@ -403,7 +405,7 @@ class LlmAgent extends (_b = import_base_agent.BaseAgent, _a = LLM_AGENT_SIGNATU
403
405
  }
404
406
  }
405
407
  const allTools = [...this.tools];
406
- if (this.outputSchema && allTools.length > 0) {
408
+ if (this.outputSchema && allTools.length > 0 && !(0, import_output_schema_utils.canUseOutputSchemaWithTools)(this.canonicalModel.model)) {
407
409
  const setModelResponseTool = new import_function_tool.FunctionTool({
408
410
  name: "set_model_response",
409
411
  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.",
@@ -511,7 +513,7 @@ class LlmAgent extends (_b = import_base_agent.BaseAgent, _a = LLM_AGENT_SIGNATU
511
513
  mergedEvent.content.parts = [{ text: JSON.stringify(args) }];
512
514
  mergedEvent.actions.skipSummarization = true;
513
515
  } else if (functionCalls && functionCalls.length) {
514
- (0, import_functions.populateClientFunctionCallId)(mergedEvent);
516
+ (0, import_event.populateClientFunctionCallId)(mergedEvent);
515
517
  mergedEvent.longRunningToolIds = Array.from(
516
518
  (0, import_functions.getLongRunningFunctionCalls)(functionCalls, llmRequest.toolsDict)
517
519
  );
@@ -72,9 +72,21 @@ class LoopAgent extends (_b = import_base_agent.BaseAgent, _a = LOOP_AGENT_SIGNA
72
72
  }
73
73
  return;
74
74
  }
75
- // eslint-disable-next-line require-yield
76
- async *runLiveImpl(_context) {
77
- throw new Error("This is not supported yet for LoopAgent.");
75
+ async *runLiveImpl(context) {
76
+ var _a2, _b2;
77
+ for (let iteration = 0; iteration < this.maxIterations; iteration++) {
78
+ for (const subAgent of this.subAgents) {
79
+ for await (const event of subAgent.runLive(context)) {
80
+ if ((_a2 = context.abortSignal) == null ? void 0 : _a2.aborted) {
81
+ return;
82
+ }
83
+ yield event;
84
+ if ((_b2 = event.actions) == null ? void 0 : _b2.escalate) {
85
+ return;
86
+ }
87
+ }
88
+ }
89
+ }
78
90
  }
79
91
  }
80
92
  // Annotate the CommonJS export names for ESM import in node:
@@ -29,6 +29,7 @@ __export(basic_llm_request_processor_exports, {
29
29
  });
30
30
  module.exports = __toCommonJS(basic_llm_request_processor_exports);
31
31
  var import_llm_request = require("../../models/llm_request.js");
32
+ var import_output_schema_utils = require("../../utils/output_schema_utils.js");
32
33
  var import_llm_agent = require("../llm_agent.js");
33
34
  var import_base_llm_processor = require("./base_llm_processor.js");
34
35
  /**
@@ -46,14 +47,14 @@ class BasicLlmRequestProcessor extends import_base_llm_processor.BaseLlmRequestP
46
47
  */
47
48
  // eslint-disable-next-line require-yield
48
49
  async *runAsync(invocationContext, llmRequest) {
49
- var _a;
50
+ var _a, _b;
50
51
  const agent = invocationContext.agent;
51
52
  if (!(0, import_llm_agent.isLlmAgent)(agent)) {
52
53
  return;
53
54
  }
54
55
  llmRequest.model = agent.canonicalModel.model;
55
56
  llmRequest.config = { ...(_a = agent.generateContentConfig) != null ? _a : {} };
56
- if (agent.outputSchema && (!agent.tools || agent.tools.length === 0)) {
57
+ if (agent.outputSchema && (!((_b = agent.tools) == null ? void 0 : _b.length) || (0, import_output_schema_utils.canUseOutputSchemaWithTools)(agent.canonicalModel.model))) {
57
58
  (0, import_llm_request.setOutputSchema)(llmRequest, agent.outputSchema);
58
59
  }
59
60
  if (invocationContext.runConfig) {
@@ -34,6 +34,7 @@ var import_genai = require("@google/genai");
34
34
  var import_lodash_es = require("lodash-es");
35
35
  var import_compacted_event = require("../../events/compacted_event.js");
36
36
  var import_event = require("../../events/event.js");
37
+ var import_branch_trie = require("../../utils/branch_trie.js");
37
38
  var import_functions = require("../functions.js");
38
39
  /**
39
40
  * @license
@@ -62,7 +63,7 @@ function getContents(events, agentName, currentBranch) {
62
63
  if (!((_a = event.content) == null ? void 0 : _a.role) || ((_c = (_b = event.content.parts) == null ? void 0 : _b[0]) == null ? void 0 : _c.text) === "") {
63
64
  continue;
64
65
  }
65
- if (currentBranch && event.branch && !currentBranch.startsWith(event.branch)) {
66
+ if (currentBranch && event.branch && !(0, import_branch_trie.isSegmentPrefix)(currentBranch, event.branch)) {
66
67
  continue;
67
68
  }
68
69
  if (isAuthEvent(event)) {
@@ -28,7 +28,7 @@ __export(content_request_processor_exports, {
28
28
  ContentRequestProcessor: () => ContentRequestProcessor
29
29
  });
30
30
  module.exports = __toCommonJS(content_request_processor_exports);
31
- var import_compacted_event = require("../../events/compacted_event.js");
31
+ var import_compaction_utils = require("../../context/compaction_utils.js");
32
32
  var import_llm_agent = require("../llm_agent.js");
33
33
  var import_content_processor_utils = require("./content_processor_utils.js");
34
34
  /**
@@ -50,26 +50,7 @@ class ContentRequestProcessor {
50
50
  if (!agent || !(0, import_llm_agent.isLlmAgent)(agent)) {
51
51
  return;
52
52
  }
53
- let events = invocationContext.session.events;
54
- const compactedEvents = events.filter(import_compacted_event.isCompactedEvent);
55
- const latestCompactedEvent = compactedEvents.length > 0 ? compactedEvents.reduce(
56
- (latest, current) => current.endTime > latest.endTime ? current : latest
57
- ) : void 0;
58
- if (latestCompactedEvent) {
59
- const remainingEvents = events.filter((event) => {
60
- if (event === latestCompactedEvent) {
61
- return false;
62
- }
63
- if ((0, import_compacted_event.isCompactedEvent)(event)) {
64
- return false;
65
- }
66
- if (event.timestamp <= latestCompactedEvent.endTime) {
67
- return false;
68
- }
69
- return true;
70
- });
71
- events = [latestCompactedEvent, ...remainingEvents];
72
- }
53
+ const events = (0, import_compaction_utils.getActiveEvents)(invocationContext.session.events);
73
54
  if (agent.includeContents === "default") {
74
55
  llmRequest.contents = (0, import_content_processor_utils.getContents)(
75
56
  events,