@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
@@ -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";
@@ -97,14 +113,14 @@ async function toA2a(agent, options = {}) {
97
113
  `${basePath}/rest`,
98
114
  (0, import_express.restHandler)({
99
115
  requestHandler,
100
- userBuilder: import_express.UserBuilder.noAuthentication
116
+ userBuilder
101
117
  })
102
118
  );
103
119
  app.use(
104
120
  `${basePath}/jsonrpc`,
105
121
  (0, import_express.jsonRpcHandler)({
106
122
  requestHandler,
107
- userBuilder: import_express.UserBuilder.noAuthentication
123
+ userBuilder
108
124
  })
109
125
  );
110
126
  return app;
@@ -69,13 +69,14 @@ function toAdkEvent(event, invocationId, agentName) {
69
69
  }
70
70
  return void 0;
71
71
  }
72
- function messageToAdkEvent(msg, invocationId, agentName, parentEvent) {
72
+ function messageToAdkEvent(msg, invocationId, agentName) {
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
+ content,
79
80
  turnComplete: true,
80
81
  partial: false
81
82
  };
@@ -121,6 +122,9 @@ function taskStatusUpdateToAdkEvent(a2aEvent, invocationId, agentName) {
121
122
  return void 0;
122
123
  }
123
124
  const parts = (0, import_part_converter_utils.toGenAIParts)(msg.parts);
125
+ if (parts.length === 0) {
126
+ return void 0;
127
+ }
124
128
  return {
125
129
  ...createAdkEventFromMetadata(a2aEvent),
126
130
  invocationId,
@@ -151,7 +155,7 @@ function taskToAdkEvent(a2aTask, invocationId, agentName) {
151
155
  }
152
156
  const isTerminal = (0, import_a2a_event.isTerminalTaskStatusUpdateEvent)(a2aTask) || (0, import_a2a_event.isInputRequiredTaskStatusUpdateEvent)(a2aTask);
153
157
  const isFailed = (0, import_a2a_event.isFailedTaskStatusUpdateEvent)(a2aTask);
154
- if (parts.length === 0 && !isTerminal) {
158
+ if (parts.length === 0 && !isFailed) {
155
159
  return void 0;
156
160
  }
157
161
  return {
@@ -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,
@@ -27,6 +27,7 @@ __export(active_streaming_tool_exports, {
27
27
  ActiveStreamingTool: () => ActiveStreamingTool
28
28
  });
29
29
  module.exports = __toCommonJS(active_streaming_tool_exports);
30
+ var import_task = require("../utils/task.js");
30
31
  /**
31
32
  * @license
32
33
  * Copyright 2025 Google LLC
@@ -34,7 +35,11 @@ module.exports = __toCommonJS(active_streaming_tool_exports);
34
35
  */
35
36
  class ActiveStreamingTool {
36
37
  constructor(params = {}) {
37
- this.task = params.task;
38
+ if (params.task instanceof Promise) {
39
+ this.task = new import_task.Task(() => params.task);
40
+ } else {
41
+ this.task = params.task;
42
+ }
38
43
  this.stream = params.stream;
39
44
  }
40
45
  }
@@ -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
  *
@@ -83,9 +83,6 @@ class Context extends import_readonly_context.ReadonlyContext {
83
83
  throw new Error("Artifact service is not initialized.");
84
84
  }
85
85
  return this.invocationContext.artifactService.loadArtifact({
86
- appName: this.invocationContext.appName,
87
- userId: this.invocationContext.userId,
88
- sessionId: this.invocationContext.session.id,
89
86
  filename,
90
87
  version
91
88
  });
@@ -102,9 +99,6 @@ class Context extends import_readonly_context.ReadonlyContext {
102
99
  throw new Error("Artifact service is not initialized.");
103
100
  }
104
101
  const version = await this.invocationContext.artifactService.saveArtifact({
105
- appName: this.invocationContext.appName,
106
- userId: this.invocationContext.userId,
107
- sessionId: this.invocationContext.session.id,
108
102
  filename,
109
103
  artifact
110
104
  });
@@ -137,11 +131,7 @@ class Context extends import_readonly_context.ReadonlyContext {
137
131
  if (!this.invocationContext.artifactService) {
138
132
  throw new Error("Artifact service is not initialized.");
139
133
  }
140
- return this.invocationContext.artifactService.listArtifactKeys({
141
- appName: this.invocationContext.session.appName,
142
- userId: this.invocationContext.session.userId,
143
- sessionId: this.invocationContext.session.id
144
- });
134
+ return this.invocationContext.artifactService.listArtifactKeys();
145
135
  }
146
136
  /**
147
137
  * Searches the memory of the current user.
@@ -24,34 +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: () => import_event2.AF_FUNCTION_CALL_ID_PREFIX,
27
28
  REQUEST_CONFIRMATION_FUNCTION_CALL_NAME: () => REQUEST_CONFIRMATION_FUNCTION_CALL_NAME,
28
29
  REQUEST_EUC_FUNCTION_CALL_NAME: () => REQUEST_EUC_FUNCTION_CALL_NAME,
30
+ findEventByFunctionCallId: () => findEventByFunctionCallId,
31
+ findMatchingFunctionCall: () => findMatchingFunctionCall,
29
32
  functionsExportedForTestingOnly: () => functionsExportedForTestingOnly,
30
33
  generateAuthEvent: () => generateAuthEvent,
31
- generateClientFunctionCallId: () => generateClientFunctionCallId,
34
+ generateClientFunctionCallId: () => import_event2.generateClientFunctionCallId,
32
35
  generateRequestConfirmationEvent: () => generateRequestConfirmationEvent,
33
36
  getLongRunningFunctionCalls: () => getLongRunningFunctionCalls,
34
37
  handleFunctionCallList: () => handleFunctionCallList,
35
38
  handleFunctionCallsAsync: () => handleFunctionCallsAsync,
36
39
  mergeParallelFunctionResponseEvents: () => mergeParallelFunctionResponseEvents,
37
- populateClientFunctionCallId: () => populateClientFunctionCallId,
38
- removeClientFunctionCallId: () => removeClientFunctionCallId
40
+ populateClientFunctionCallId: () => import_event2.populateClientFunctionCallId
39
41
  });
40
42
  module.exports = __toCommonJS(functions_exports);
41
43
  var import_genai = require("@google/genai");
42
44
  var import_lodash_es = require("lodash-es");
43
45
  var import_event = require("../events/event.js");
44
46
  var import_event_actions = require("../events/event_actions.js");
45
- var import_env_aware_utils = require("../utils/env_aware_utils.js");
46
47
  var import_logger = require("../utils/logger.js");
47
48
  var import_context = require("./context.js");
48
49
  var import_tracing = require("../telemetry/tracing.js");
50
+ var import_event2 = require("../events/event.js");
49
51
  /**
50
52
  * @license
51
53
  * Copyright 2025 Google LLC
52
54
  * SPDX-License-Identifier: Apache-2.0
53
55
  */
54
- const AF_FUNCTION_CALL_ID_PREFIX = "adk-";
55
56
  const REQUEST_EUC_FUNCTION_CALL_NAME = "adk_request_credential";
56
57
  const REQUEST_CONFIRMATION_FUNCTION_CALL_NAME = "adk_request_confirmation";
57
58
  const functionsExportedForTestingOnly = {
@@ -59,32 +60,6 @@ const functionsExportedForTestingOnly = {
59
60
  generateAuthEvent,
60
61
  generateRequestConfirmationEvent
61
62
  };
62
- function generateClientFunctionCallId() {
63
- return `${AF_FUNCTION_CALL_ID_PREFIX}${(0, import_env_aware_utils.randomUUID)()}`;
64
- }
65
- function populateClientFunctionCallId(modelResponseEvent) {
66
- const functionCalls = (0, import_event.getFunctionCalls)(modelResponseEvent);
67
- if (!functionCalls) {
68
- return;
69
- }
70
- for (const functionCall of functionCalls) {
71
- if (!functionCall.id) {
72
- functionCall.id = generateClientFunctionCallId();
73
- }
74
- }
75
- }
76
- function removeClientFunctionCallId(content) {
77
- if (content && content.parts) {
78
- for (const part of content.parts) {
79
- if (part.functionCall && part.functionCall.id && part.functionCall.id.startsWith(AF_FUNCTION_CALL_ID_PREFIX)) {
80
- part.functionCall.id = void 0;
81
- }
82
- if (part.functionResponse && part.functionResponse.id && part.functionResponse.id.startsWith(AF_FUNCTION_CALL_ID_PREFIX)) {
83
- part.functionResponse.id = void 0;
84
- }
85
- }
86
- }
87
- }
88
63
  function getLongRunningFunctionCalls(functionCalls, toolsDict) {
89
64
  const longRunningToolIds = /* @__PURE__ */ new Set();
90
65
  for (const functionCall of functionCalls) {
@@ -110,7 +85,7 @@ function generateAuthEvent(invocationContext, functionResponseEvent) {
110
85
  "function_call_id": functionCallId,
111
86
  "auth_config": authConfig
112
87
  },
113
- id: generateClientFunctionCallId()
88
+ id: (0, import_event.generateClientFunctionCallId)()
114
89
  };
115
90
  longRunningToolIds.add(requestEucFunctionCall.id);
116
91
  parts.push({ functionCall: requestEucFunctionCall });
@@ -151,7 +126,7 @@ function generateRequestConfirmationEvent({
151
126
  "originalFunctionCall": originalFunctionCall,
152
127
  "toolConfirmation": toolConfirmation
153
128
  },
154
- id: generateClientFunctionCallId()
129
+ id: (0, import_event.generateClientFunctionCallId)()
155
130
  };
156
131
  longRunningToolIds.add(requestConfirmationFunctionCall.id);
157
132
  parts.push({ functionCall: requestConfirmationFunctionCall });
@@ -427,10 +402,40 @@ function mergeParallelFunctionResponseEvents(functionResponseEvents) {
427
402
  timestamp: baseEvent.timestamp
428
403
  });
429
404
  }
405
+ function findEventByFunctionCallId(events, functionCallId, endIndex = events.length) {
406
+ for (let i = endIndex - 1; i >= 0; i--) {
407
+ const event = events[i];
408
+ const functionCalls = (0, import_event.getFunctionCalls)(event);
409
+ for (const functionCall of functionCalls) {
410
+ if (functionCall.id === functionCallId) {
411
+ return event;
412
+ }
413
+ }
414
+ }
415
+ return void 0;
416
+ }
417
+ function findMatchingFunctionCall(events) {
418
+ if (!events.length) {
419
+ return void 0;
420
+ }
421
+ const lastEvent = events[events.length - 1];
422
+ const functionResponses = (0, import_event.getFunctionResponses)(lastEvent);
423
+ if (!functionResponses.length || !functionResponses[0].id) {
424
+ return void 0;
425
+ }
426
+ return findEventByFunctionCallId(
427
+ events,
428
+ functionResponses[0].id,
429
+ events.length - 1
430
+ );
431
+ }
430
432
  // Annotate the CommonJS export names for ESM import in node:
431
433
  0 && (module.exports = {
434
+ AF_FUNCTION_CALL_ID_PREFIX,
432
435
  REQUEST_CONFIRMATION_FUNCTION_CALL_NAME,
433
436
  REQUEST_EUC_FUNCTION_CALL_NAME,
437
+ findEventByFunctionCallId,
438
+ findMatchingFunctionCall,
434
439
  functionsExportedForTestingOnly,
435
440
  generateAuthEvent,
436
441
  generateClientFunctionCallId,
@@ -439,6 +444,5 @@ function mergeParallelFunctionResponseEvents(functionResponseEvents) {
439
444
  handleFunctionCallList,
440
445
  handleFunctionCallsAsync,
441
446
  mergeParallelFunctionResponseEvents,
442
- populateClientFunctionCallId,
443
- removeClientFunctionCallId
447
+ populateClientFunctionCallId
444
448
  });
@@ -42,9 +42,6 @@ async function resolveKey(key, isOptional, rawMatch, readonlyContext) {
42
42
  throw new Error("Artifact service is not initialized.");
43
43
  }
44
44
  const artifact = await invocationContext.artifactService.loadArtifact({
45
- appName: invocationContext.session.appName,
46
- userId: invocationContext.session.userId,
47
- sessionId: invocationContext.session.id,
48
45
  filename: fileName
49
46
  });
50
47
  if (!artifact) {
@@ -53,19 +50,40 @@ async function resolveKey(key, isOptional, rawMatch, readonlyContext) {
53
50
  }
54
51
  throw new Error(`Artifact ${fileName} not found.`);
55
52
  }
56
- return String(artifact);
53
+ return formatValue(artifact, true);
57
54
  }
58
55
  if (!isValidStateName(key)) {
59
56
  return rawMatch;
60
57
  }
61
58
  if (key in invocationContext.session.state) {
62
- return String(invocationContext.session.state[key]);
59
+ return formatValue(invocationContext.session.state[key], false);
63
60
  }
64
61
  if (isOptional) {
65
62
  return "";
66
63
  }
67
64
  throw new Error(`Context variable not found: \`${key}\`.`);
68
65
  }
66
+ function formatValue(value, isArtifact = false) {
67
+ if (typeof value === "string") {
68
+ return value;
69
+ }
70
+ if (typeof value === "object" && value !== null) {
71
+ if (isArtifact && "text" in value && typeof value.text === "string") {
72
+ return value.text;
73
+ }
74
+ try {
75
+ const json = JSON.stringify(value);
76
+ if (json !== void 0) {
77
+ return json;
78
+ }
79
+ } catch (e) {
80
+ throw new Error(
81
+ `Failed to serialize value for instruction template: ${e instanceof Error ? e.message : String(e)}`
82
+ );
83
+ }
84
+ }
85
+ return String(value);
86
+ }
69
87
  async function injectSessionState(template, readonlyContext) {
70
88
  const pattern = /\{+[^{}]*}+/g;
71
89
  const matches = Array.from(template.matchAll(pattern));
@@ -58,11 +58,7 @@ class InvocationContext {
58
58
  * @param params The parameters for creating an invocation context.
59
59
  */
60
60
  constructor(params) {
61
- /**
62
- * A container to keep track of different kinds of costs incurred as a part of
63
- * this invocation.
64
- */
65
- this.invocationCostManager = new InvocationCostManager();
61
+ var _a;
66
62
  this.artifactService = params.artifactService;
67
63
  this.sessionService = params.sessionService;
68
64
  this.memoryService = params.memoryService;
@@ -77,6 +73,7 @@ class InvocationContext {
77
73
  this.activeStreamingTools = params.activeStreamingTools;
78
74
  this.pluginManager = params.pluginManager;
79
75
  this.abortSignal = params.abortSignal;
76
+ this.invocationCostManager = (_a = params.invocationCostManager) != null ? _a : new InvocationCostManager();
80
77
  }
81
78
  /**
82
79
  * The app name of the current session.
@@ -48,6 +48,7 @@ var import_content_request_processor = require("./processors/content_request_pro
48
48
  var import_context_compactor_request_processor = require("./processors/context_compactor_request_processor.js");
49
49
  var import_identity_llm_request_processor = require("./processors/identity_llm_request_processor.js");
50
50
  var import_instructions_llm_request_processor = require("./processors/instructions_llm_request_processor.js");
51
+ var import_interactions_request_processor = require("./processors/interactions_request_processor.js");
51
52
  var import_request_confirmation_llm_request_processor = require("./processors/request_confirmation_llm_request_processor.js");
52
53
  var import_tool_filter_request_processor = require("./processors/tool_filter_request_processor.js");
53
54
  var import_readonly_context = require("./readonly_context.js");
@@ -98,6 +99,7 @@ class LlmAgent extends (_b = import_base_agent.BaseAgent, _a = LLM_AGENT_SIGNATU
98
99
  import_instructions_llm_request_processor.INSTRUCTIONS_LLM_REQUEST_PROCESSOR,
99
100
  import_request_confirmation_llm_request_processor.REQUEST_CONFIRMATION_LLM_REQUEST_PROCESSOR,
100
101
  import_content_request_processor.CONTENT_REQUEST_PROCESSOR,
102
+ import_interactions_request_processor.INTERACTIONS_REQUEST_PROCESSOR,
101
103
  import_code_execution_request_processor.CODE_EXECUTION_REQUEST_PROCESSOR,
102
104
  import_tool_filter_request_processor.TOOL_FILTER_REQUEST_PROCESSOR
103
105
  ];
@@ -193,6 +195,7 @@ class LlmAgent extends (_b = import_base_agent.BaseAgent, _a = LLM_AGENT_SIGNATU
193
195
  * This method is only for use by Agent Development Kit.
194
196
  * @param context The context to retrieve the session state.
195
197
  * @returns The resolved globalInstruction field.
198
+ * @deprecated Use GlobalInstructionPlugin instead.
196
199
  */
197
200
  async canonicalGlobalInstruction(context2) {
198
201
  if (typeof this.globalInstruction === "string") {
@@ -480,7 +483,7 @@ class LlmAgent extends (_b = import_base_agent.BaseAgent, _a = LLM_AGENT_SIGNATU
480
483
  span.end();
481
484
  }
482
485
  async *postprocess(invocationContext, llmRequest, llmResponse, modelResponseEvent) {
483
- var _a2, _b2, _c, _d, _e;
486
+ var _a2, _b2, _c, _d, _e, _f;
484
487
  for (const processor of this.responseProcessors) {
485
488
  for await (const event of processor.runAsync(
486
489
  invocationContext,
@@ -492,7 +495,7 @@ class LlmAgent extends (_b = import_base_agent.BaseAgent, _a = LLM_AGENT_SIGNATU
492
495
  yield event;
493
496
  }
494
497
  }
495
- if (!llmResponse.content && !llmResponse.errorCode && !llmResponse.interrupted) {
498
+ if ((!llmResponse.content || ((_b2 = llmResponse.content.parts) == null ? void 0 : _b2.length) === 0) && !llmResponse.errorCode && !llmResponse.interrupted) {
496
499
  return;
497
500
  }
498
501
  const mergedEvent = (0, import_event.createEvent)({
@@ -509,17 +512,17 @@ class LlmAgent extends (_b = import_base_agent.BaseAgent, _a = LLM_AGENT_SIGNATU
509
512
  mergedEvent.content.parts = [{ text: JSON.stringify(args) }];
510
513
  mergedEvent.actions.skipSummarization = true;
511
514
  } else if (functionCalls && functionCalls.length) {
512
- (0, import_functions.populateClientFunctionCallId)(mergedEvent);
515
+ (0, import_event.populateClientFunctionCallId)(mergedEvent);
513
516
  mergedEvent.longRunningToolIds = Array.from(
514
517
  (0, import_functions.getLongRunningFunctionCalls)(functionCalls, llmRequest.toolsDict)
515
518
  );
516
519
  }
517
520
  }
518
521
  yield mergedEvent;
519
- if (!((_b2 = (0, import_event.getFunctionCalls)(mergedEvent)) == null ? void 0 : _b2.length)) {
522
+ if (!((_c = (0, import_event.getFunctionCalls)(mergedEvent)) == null ? void 0 : _c.length)) {
520
523
  return;
521
524
  }
522
- if ((_c = invocationContext.runConfig) == null ? void 0 : _c.pauseOnToolCalls) {
525
+ if ((_d = invocationContext.runConfig) == null ? void 0 : _d.pauseOnToolCalls) {
523
526
  invocationContext.endInvocation = true;
524
527
  return;
525
528
  }
@@ -530,7 +533,7 @@ class LlmAgent extends (_b = import_base_agent.BaseAgent, _a = LLM_AGENT_SIGNATU
530
533
  beforeToolCallbacks: this.canonicalBeforeToolCallbacks,
531
534
  afterToolCallbacks: this.canonicalAfterToolCallbacks
532
535
  });
533
- if (!functionResponseEvent || ((_d = invocationContext.abortSignal) == null ? void 0 : _d.aborted)) {
536
+ if (!functionResponseEvent || ((_e = invocationContext.abortSignal) == null ? void 0 : _e.aborted)) {
534
537
  return;
535
538
  }
536
539
  const authEvent = (0, import_functions.generateAuthEvent)(
@@ -555,7 +558,7 @@ class LlmAgent extends (_b = import_base_agent.BaseAgent, _a = LLM_AGENT_SIGNATU
555
558
  if (nextAgentName) {
556
559
  const nextAgent = this.getAgentByName(invocationContext, nextAgentName);
557
560
  for await (const event of nextAgent.runAsync(invocationContext)) {
558
- if ((_e = invocationContext.abortSignal) == null ? void 0 : _e.aborted) {
561
+ if ((_f = invocationContext.abortSignal) == null ? void 0 : _f.aborted) {
559
562
  return;
560
563
  }
561
564
  yield event;
@@ -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:
@@ -339,9 +339,6 @@ async function postProcessCodeExecutionResult(invocationContext, codeExecutorCon
339
339
  }
340
340
  for (const outputFile of codeExecutionResult.outputFiles) {
341
341
  const version = await invocationContext.artifactService.saveArtifact({
342
- appName: invocationContext.appName || "",
343
- userId: invocationContext.userId || "",
344
- sessionId: invocationContext.session.id,
345
342
  filename: outputFile.name,
346
343
  artifact: {
347
344
  inlineData: { data: outputFile.content, mimeType: outputFile.mimeType }
@@ -26,19 +26,32 @@ var content_processor_utils_exports = {};
26
26
  __export(content_processor_utils_exports, {
27
27
  getContents: () => getContents,
28
28
  getCurrentTurnContents: () => getCurrentTurnContents,
29
- mergeFunctionResponseEvents: () => mergeFunctionResponseEvents
29
+ mergeFunctionResponseEvents: () => mergeFunctionResponseEvents,
30
+ removeClientFunctionCallId: () => removeClientFunctionCallId
30
31
  });
31
32
  module.exports = __toCommonJS(content_processor_utils_exports);
32
33
  var import_genai = require("@google/genai");
33
34
  var import_lodash_es = require("lodash-es");
34
35
  var import_compacted_event = require("../../events/compacted_event.js");
35
36
  var import_event = require("../../events/event.js");
37
+ var import_branch_trie = require("../../utils/branch_trie.js");
36
38
  var import_functions = require("../functions.js");
37
39
  /**
38
40
  * @license
39
41
  * Copyright 2025 Google LLC
40
42
  * SPDX-License-Identifier: Apache-2.0
41
43
  */
44
+ function removeClientFunctionCallId(content) {
45
+ var _a, _b, _c, _d, _e;
46
+ for (const part of (_a = content == null ? void 0 : content.parts) != null ? _a : []) {
47
+ if ((_c = (_b = part.functionCall) == null ? void 0 : _b.id) == null ? void 0 : _c.startsWith(import_functions.AF_FUNCTION_CALL_ID_PREFIX)) {
48
+ part.functionCall.id = void 0;
49
+ }
50
+ if ((_e = (_d = part.functionResponse) == null ? void 0 : _d.id) == null ? void 0 : _e.startsWith(import_functions.AF_FUNCTION_CALL_ID_PREFIX)) {
51
+ part.functionResponse.id = void 0;
52
+ }
53
+ }
54
+ }
42
55
  function getContents(events, agentName, currentBranch) {
43
56
  var _a, _b, _c;
44
57
  const filteredEvents = [];
@@ -50,7 +63,7 @@ function getContents(events, agentName, currentBranch) {
50
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) === "") {
51
64
  continue;
52
65
  }
53
- if (currentBranch && event.branch && !currentBranch.startsWith(event.branch)) {
66
+ if (currentBranch && event.branch && !(0, import_branch_trie.isSegmentPrefix)(currentBranch, event.branch)) {
54
67
  continue;
55
68
  }
56
69
  if (isAuthEvent(event)) {
@@ -68,7 +81,7 @@ function getContents(events, agentName, currentBranch) {
68
81
  const contents = [];
69
82
  for (const event of resultEvents) {
70
83
  const content = (0, import_lodash_es.cloneDeep)(event.content);
71
- (0, import_functions.removeClientFunctionCallId)(content);
84
+ removeClientFunctionCallId(content);
72
85
  contents.push(content);
73
86
  }
74
87
  return contents;
@@ -347,5 +360,6 @@ ${event.compactedContent}`
347
360
  0 && (module.exports = {
348
361
  getContents,
349
362
  getCurrentTurnContents,
350
- mergeFunctionResponseEvents
363
+ mergeFunctionResponseEvents,
364
+ removeClientFunctionCallId
351
365
  });
@@ -50,20 +50,22 @@ class ContextCompactorRequestProcessor {
50
50
  * @param _llmRequest - Unused; present to satisfy the {@link BaseLlmRequestProcessor} interface.
51
51
  */
52
52
  async *runAsync(invocationContext, _llmRequest) {
53
+ var _a;
53
54
  for (const compactor of this.compactors) {
54
55
  const shouldCompact = await Promise.resolve(
55
56
  compactor.shouldCompact(invocationContext)
56
57
  );
57
58
  if (shouldCompact) {
59
+ const trigger = (_a = compactor.trigger) != null ? _a : import_base_plugin.ContextCompactionTrigger.Auto;
58
60
  await invocationContext.pluginManager.runBeforeContextCompaction({
59
61
  invocationContext,
60
- trigger: import_base_plugin.ContextCompactionTrigger.Auto
62
+ trigger
61
63
  });
62
64
  const oldEvents = new Set(invocationContext.session.events);
63
65
  await Promise.resolve(compactor.compact(invocationContext));
64
66
  await invocationContext.pluginManager.runAfterContextCompaction({
65
67
  invocationContext,
66
- trigger: import_base_plugin.ContextCompactionTrigger.Auto
68
+ trigger
67
69
  });
68
70
  const newEvents = invocationContext.session.events.filter(
69
71
  (e) => !oldEvents.has(e)