@google/adk 1.2.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (294) hide show
  1. package/dist/cjs/agents/active_streaming_tool.js +6 -1
  2. package/dist/cjs/agents/base_agent.js +19 -1
  3. package/dist/cjs/agents/context.js +1 -11
  4. package/dist/cjs/agents/functions.js +35 -16
  5. package/dist/cjs/agents/instructions.js +99 -33
  6. package/dist/cjs/agents/invocation_context.js +2 -6
  7. package/dist/cjs/agents/llm_agent.js +60 -11
  8. package/dist/cjs/agents/processors/agent_transfer_llm_request_processor.js +7 -0
  9. package/dist/cjs/agents/processors/basic_llm_request_processor.js +8 -1
  10. package/dist/cjs/agents/processors/code_execution_request_processor.js +0 -3
  11. package/dist/cjs/agents/processors/content_processor_utils.js +51 -25
  12. package/dist/cjs/agents/processors/content_request_processor.js +7 -0
  13. package/dist/cjs/agents/processors/context_compactor_request_processor.js +16 -2
  14. package/dist/cjs/agents/processors/identity_llm_request_processor.js +7 -0
  15. package/dist/cjs/agents/processors/instructions_llm_request_processor.js +5 -0
  16. package/dist/cjs/agents/processors/interactions_request_processor.js +63 -0
  17. package/dist/cjs/agents/processors/request_confirmation_llm_request_processor.js +9 -1
  18. package/dist/cjs/agents/processors/tool_filter_request_processor.js +7 -1
  19. package/dist/cjs/apps/app.js +79 -0
  20. package/dist/cjs/apps/resumability_config.js +44 -0
  21. package/dist/cjs/artifacts/file_artifact_service.js +14 -1
  22. package/dist/cjs/artifacts/gcs_artifact_service.js +57 -15
  23. package/dist/cjs/artifacts/in_memory_artifact_service.js +5 -1
  24. package/dist/cjs/artifacts/scoped_artifact_service.js +101 -0
  25. package/dist/cjs/artifacts/session_artifact_service.js +27 -0
  26. package/dist/cjs/auth/auth_preprocessor.js +12 -10
  27. package/dist/cjs/auth/oauth2/oauth2_discovery.js +17 -5
  28. package/dist/cjs/auth/oauth2/oauth2_utils.js +12 -1
  29. package/dist/cjs/code_executors/code_executor_context.js +7 -7
  30. package/dist/cjs/common.js +86 -0
  31. package/dist/cjs/context/agent_controlled_context_compactor.js +109 -0
  32. package/dist/cjs/context/summarizers/llm_summarizer.js +11 -0
  33. package/dist/cjs/context/token_based_context_compactor.js +43 -11
  34. package/dist/cjs/context/trajectory_thought_pruning_compactor.js +71 -0
  35. package/dist/cjs/events/event.js +25 -1
  36. package/dist/cjs/integrations/agent_registry/agent_registry_mcp_toolset.js +21 -2
  37. package/dist/cjs/models/gemini_llm_connection.js +62 -19
  38. package/dist/cjs/models/google_llm.js +51 -18
  39. package/dist/cjs/models/interactions_utils.js +732 -0
  40. package/dist/cjs/plugins/base_plugin.js +1 -0
  41. package/dist/cjs/plugins/security_plugin.js +16 -0
  42. package/dist/cjs/runner/in_memory_runner.js +13 -2
  43. package/dist/cjs/runner/runner.js +93 -72
  44. package/dist/cjs/sessions/base_session_service.js +19 -3
  45. package/dist/cjs/sessions/database_session_service.js +26 -9
  46. package/dist/cjs/sessions/db/schema.js +45 -10
  47. package/dist/cjs/sessions/in_memory_session_service.js +2 -1
  48. package/dist/cjs/sessions/vertex_ai_session_service.js +21 -5
  49. package/dist/cjs/skills/gcp_skill_registry.js +104 -0
  50. package/dist/cjs/skills/loader.js +67 -2
  51. package/dist/cjs/skills/skill_registry.js +27 -0
  52. package/dist/cjs/tools/base_toolset.js +1 -1
  53. package/dist/cjs/tools/consolidate_context_tool.js +79 -0
  54. package/dist/cjs/tools/forwarding_artifact_service.js +16 -28
  55. package/dist/cjs/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js +232 -0
  56. package/dist/cjs/tools/openapi_tool/openapi_spec_parser/operation_parser.js +224 -0
  57. package/dist/cjs/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +117 -0
  58. package/dist/cjs/tools/openapi_tool/openapi_toolset.js +133 -0
  59. package/dist/cjs/tools/openapi_tool/rest_api_tool.js +256 -0
  60. package/dist/cjs/tools/skill/load_skill_resource_tool.js +25 -3
  61. package/dist/cjs/tools/skill/load_skill_tool.js +12 -1
  62. package/dist/cjs/tools/skill/run_skill_script_tool.js +12 -1
  63. package/dist/cjs/tools/skill/search_skills_tool.js +108 -0
  64. package/dist/cjs/tools/skill/skill_toolset.js +40 -5
  65. package/dist/cjs/utils/async_hooks_shim.js +52 -0
  66. package/dist/cjs/utils/async_queue.js +88 -0
  67. package/dist/cjs/utils/case_utils.js +53 -0
  68. package/dist/cjs/utils/client_labels.js +41 -3
  69. package/dist/cjs/utils/env_aware_utils.js +14 -1
  70. package/dist/cjs/utils/live_connection_utils.js +284 -0
  71. package/dist/cjs/utils/model_name.js +9 -0
  72. package/dist/cjs/utils/streaming_utils.js +18 -11
  73. package/dist/cjs/utils/task.js +62 -0
  74. package/dist/cjs/version.js +1 -1
  75. package/dist/esm/agents/active_streaming_tool.js +6 -1
  76. package/dist/esm/agents/base_agent.js +19 -1
  77. package/dist/esm/agents/context.js +1 -11
  78. package/dist/esm/agents/functions.js +36 -15
  79. package/dist/esm/agents/instructions.js +99 -33
  80. package/dist/esm/agents/invocation_context.js +2 -6
  81. package/dist/esm/agents/llm_agent.js +61 -11
  82. package/dist/esm/agents/processors/agent_transfer_llm_request_processor.js +7 -0
  83. package/dist/esm/agents/processors/basic_llm_request_processor.js +8 -1
  84. package/dist/esm/agents/processors/code_execution_request_processor.js +0 -3
  85. package/dist/esm/agents/processors/content_processor_utils.js +48 -24
  86. package/dist/esm/agents/processors/content_request_processor.js +7 -0
  87. package/dist/esm/agents/processors/context_compactor_request_processor.js +16 -2
  88. package/dist/esm/agents/processors/identity_llm_request_processor.js +7 -0
  89. package/dist/esm/agents/processors/instructions_llm_request_processor.js +5 -0
  90. package/dist/esm/agents/processors/interactions_request_processor.js +34 -0
  91. package/dist/esm/agents/processors/request_confirmation_llm_request_processor.js +9 -1
  92. package/dist/esm/agents/processors/tool_filter_request_processor.js +7 -1
  93. package/dist/esm/apps/app.js +49 -0
  94. package/dist/esm/apps/resumability_config.js +16 -0
  95. package/dist/esm/artifacts/file_artifact_service.js +14 -1
  96. package/dist/esm/artifacts/gcs_artifact_service.js +57 -15
  97. package/dist/esm/artifacts/in_memory_artifact_service.js +5 -1
  98. package/dist/esm/artifacts/scoped_artifact_service.js +73 -0
  99. package/dist/esm/artifacts/session_artifact_service.js +7 -0
  100. package/dist/esm/auth/auth_preprocessor.js +12 -10
  101. package/dist/esm/auth/oauth2/oauth2_discovery.js +14 -4
  102. package/dist/esm/auth/oauth2/oauth2_utils.js +12 -1
  103. package/dist/esm/code_executors/code_executor_context.js +7 -7
  104. package/dist/esm/common.js +75 -3
  105. package/dist/esm/context/agent_controlled_context_compactor.js +81 -0
  106. package/dist/esm/context/summarizers/llm_summarizer.js +11 -0
  107. package/dist/esm/context/token_based_context_compactor.js +43 -11
  108. package/dist/esm/context/trajectory_thought_pruning_compactor.js +43 -0
  109. package/dist/esm/events/event.js +23 -1
  110. package/dist/esm/integrations/agent_registry/agent_registry_mcp_toolset.js +21 -2
  111. package/dist/esm/models/gemini_llm_connection.js +62 -19
  112. package/dist/esm/models/google_llm.js +49 -17
  113. package/dist/esm/models/interactions_utils.js +697 -0
  114. package/dist/esm/plugins/base_plugin.js +1 -0
  115. package/dist/esm/plugins/security_plugin.js +16 -0
  116. package/dist/esm/runner/in_memory_runner.js +13 -2
  117. package/dist/esm/runner/runner.js +91 -73
  118. package/dist/esm/sessions/base_session_service.js +17 -2
  119. package/dist/esm/sessions/database_session_service.js +26 -9
  120. package/dist/esm/sessions/db/schema.js +44 -10
  121. package/dist/esm/sessions/in_memory_session_service.js +4 -2
  122. package/dist/esm/sessions/vertex_ai_session_service.js +21 -5
  123. package/dist/esm/skills/gcp_skill_registry.js +78 -0
  124. package/dist/esm/skills/loader.js +66 -2
  125. package/dist/esm/skills/skill_registry.js +7 -0
  126. package/dist/esm/tools/base_toolset.js +1 -1
  127. package/dist/esm/tools/consolidate_context_tool.js +51 -0
  128. package/dist/esm/tools/forwarding_artifact_service.js +16 -28
  129. package/dist/esm/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js +206 -0
  130. package/dist/esm/tools/openapi_tool/openapi_spec_parser/operation_parser.js +198 -0
  131. package/dist/esm/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +91 -0
  132. package/dist/esm/tools/openapi_tool/openapi_toolset.js +97 -0
  133. package/dist/esm/tools/openapi_tool/rest_api_tool.js +229 -0
  134. package/dist/esm/tools/skill/load_skill_resource_tool.js +25 -3
  135. package/dist/esm/tools/skill/load_skill_tool.js +12 -1
  136. package/dist/esm/tools/skill/run_skill_script_tool.js +12 -1
  137. package/dist/esm/tools/skill/search_skills_tool.js +82 -0
  138. package/dist/esm/tools/skill/skill_toolset.js +40 -5
  139. package/dist/esm/utils/async_hooks_shim.js +24 -0
  140. package/dist/esm/utils/async_queue.js +60 -0
  141. package/dist/esm/utils/case_utils.js +25 -0
  142. package/dist/esm/utils/client_labels.js +38 -2
  143. package/dist/esm/utils/env_aware_utils.js +14 -1
  144. package/dist/esm/utils/live_connection_utils.js +256 -0
  145. package/dist/esm/utils/model_name.js +8 -0
  146. package/dist/esm/utils/streaming_utils.js +18 -11
  147. package/dist/esm/utils/task.js +34 -0
  148. package/dist/esm/version.js +1 -1
  149. package/dist/types/a2a/a2a_remote_agent_utils.d.ts +29 -4
  150. package/dist/types/a2a/event_converter_utils.d.ts +14 -1
  151. package/dist/types/a2a/metadata_converter_utils.d.ts +18 -0
  152. package/dist/types/a2a/part_converter_utils.d.ts +51 -6
  153. package/dist/types/agents/active_streaming_tool.d.ts +3 -4
  154. package/dist/types/agents/functions.d.ts +12 -9
  155. package/dist/types/agents/invocation_context.d.ts +7 -12
  156. package/dist/types/agents/llm_agent.d.ts +14 -0
  157. package/dist/types/agents/processors/agent_transfer_llm_request_processor.d.ts +14 -0
  158. package/dist/types/agents/processors/basic_llm_request_processor.d.ts +7 -0
  159. package/dist/types/agents/processors/content_processor_utils.d.ts +34 -0
  160. package/dist/types/agents/processors/content_request_processor.d.ts +16 -0
  161. package/dist/types/agents/processors/context_compactor_request_processor.d.ts +12 -0
  162. package/dist/types/agents/processors/identity_llm_request_processor.d.ts +7 -0
  163. package/dist/types/agents/processors/interactions_request_processor.d.ts +17 -0
  164. package/dist/types/agents/processors/request_confirmation_llm_request_processor.d.ts +9 -1
  165. package/dist/types/agents/processors/tool_filter_request_processor.d.ts +12 -1
  166. package/dist/types/apps/app.d.ts +52 -0
  167. package/dist/types/apps/resumability_config.d.ts +27 -0
  168. package/dist/types/artifacts/base_artifact_service.d.ts +6 -36
  169. package/dist/types/artifacts/gcs_artifact_service.d.ts +2 -1
  170. package/dist/types/artifacts/scoped_artifact_service.d.ts +25 -0
  171. package/dist/types/artifacts/session_artifact_service.d.ts +25 -0
  172. package/dist/types/auth/oauth2/oauth2_discovery.d.ts +11 -0
  173. package/dist/types/common.d.ts +35 -4
  174. package/dist/types/context/agent_controlled_context_compactor.d.ts +24 -0
  175. package/dist/types/context/base_context_compactor.d.ts +3 -0
  176. package/dist/types/context/summarizers/llm_summarizer.d.ts +17 -0
  177. package/dist/types/context/token_based_context_compactor.d.ts +6 -1
  178. package/dist/types/context/trajectory_thought_pruning_compactor.d.ts +27 -0
  179. package/dist/types/events/event.d.ts +8 -0
  180. package/dist/types/events/event_actions.d.ts +1 -2
  181. package/dist/types/integrations/agent_registry/agent_registry_mcp_toolset.d.ts +21 -2
  182. package/dist/types/models/base_llm_connection.d.ts +10 -0
  183. package/dist/types/models/gemini_llm_connection.d.ts +15 -4
  184. package/dist/types/models/google_llm.d.ts +15 -1
  185. package/dist/types/models/interactions_utils.d.ts +92 -0
  186. package/dist/types/models/llm_request.d.ts +4 -0
  187. package/dist/types/models/llm_response.d.ts +14 -1
  188. package/dist/types/plugins/base_plugin.d.ts +2 -1
  189. package/dist/types/plugins/security_plugin.d.ts +30 -0
  190. package/dist/types/runner/in_memory_runner.d.ts +7 -1
  191. package/dist/types/runner/runner.d.ts +43 -9
  192. package/dist/types/sessions/base_session_service.d.ts +7 -16
  193. package/dist/types/sessions/db/schema.d.ts +1 -0
  194. package/dist/types/sessions/session.d.ts +11 -0
  195. package/dist/types/sessions/vertex_ai_session_service.d.ts +9 -1
  196. package/dist/types/skills/gcp_skill_registry.d.ts +24 -0
  197. package/dist/types/skills/loader.d.ts +7 -0
  198. package/dist/types/skills/skill.d.ts +1 -1
  199. package/dist/types/skills/skill_registry.d.ts +29 -0
  200. package/dist/types/tools/consolidate_context_tool.d.ts +19 -0
  201. package/dist/types/tools/forwarding_artifact_service.d.ts +3 -2
  202. package/dist/types/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.d.ts +34 -0
  203. package/dist/types/tools/openapi_tool/openapi_spec_parser/operation_parser.d.ts +59 -0
  204. package/dist/types/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.d.ts +23 -0
  205. package/dist/types/tools/openapi_tool/openapi_toolset.d.ts +27 -0
  206. package/dist/types/tools/openapi_tool/rest_api_tool.d.ts +50 -0
  207. package/dist/types/tools/skill/load_skill_resource_tool.d.ts +1 -1
  208. package/dist/types/tools/skill/search_skills_tool.d.ts +14 -0
  209. package/dist/types/tools/skill/skill_toolset.d.ts +5 -0
  210. package/dist/types/utils/async_hooks_shim.d.ts +10 -0
  211. package/dist/types/utils/async_queue.d.ts +18 -0
  212. package/dist/types/utils/case_utils.d.ts +12 -0
  213. package/dist/types/utils/client_labels.d.ts +10 -0
  214. package/dist/types/utils/env_aware_utils.d.ts +3 -3
  215. package/dist/types/utils/live_connection_utils.d.ts +30 -0
  216. package/dist/types/utils/model_name.d.ts +7 -0
  217. package/dist/types/utils/streaming_utils.d.ts +0 -1
  218. package/dist/types/utils/task.d.ts +24 -0
  219. package/dist/types/version.d.ts +1 -1
  220. package/dist/web/agents/active_streaming_tool.js +6 -1
  221. package/dist/web/agents/base_agent.js +31 -1
  222. package/dist/web/agents/context.js +1 -11
  223. package/dist/web/agents/functions.js +36 -15
  224. package/dist/web/agents/instructions.js +99 -33
  225. package/dist/web/agents/invocation_context.js +2 -6
  226. package/dist/web/agents/llm_agent.js +61 -11
  227. package/dist/web/agents/processors/agent_transfer_llm_request_processor.js +7 -0
  228. package/dist/web/agents/processors/basic_llm_request_processor.js +8 -1
  229. package/dist/web/agents/processors/code_execution_request_processor.js +0 -3
  230. package/dist/web/agents/processors/content_processor_utils.js +66 -24
  231. package/dist/web/agents/processors/content_request_processor.js +7 -0
  232. package/dist/web/agents/processors/context_compactor_request_processor.js +16 -2
  233. package/dist/web/agents/processors/identity_llm_request_processor.js +7 -0
  234. package/dist/web/agents/processors/instructions_llm_request_processor.js +5 -0
  235. package/dist/web/agents/processors/interactions_request_processor.js +52 -0
  236. package/dist/web/agents/processors/request_confirmation_llm_request_processor.js +9 -1
  237. package/dist/web/agents/processors/tool_filter_request_processor.js +7 -1
  238. package/dist/web/apps/app.js +49 -0
  239. package/dist/web/apps/resumability_config.js +31 -0
  240. package/dist/web/artifacts/file_artifact_service.js +14 -1
  241. package/dist/web/artifacts/gcs_artifact_service.js +55 -15
  242. package/dist/web/artifacts/in_memory_artifact_service.js +5 -1
  243. package/dist/web/artifacts/scoped_artifact_service.js +86 -0
  244. package/dist/web/artifacts/session_artifact_service.js +7 -0
  245. package/dist/web/auth/auth_preprocessor.js +12 -10
  246. package/dist/web/auth/oauth2/oauth2_discovery.js +14 -4
  247. package/dist/web/auth/oauth2/oauth2_utils.js +12 -1
  248. package/dist/web/code_executors/code_executor_context.js +7 -7
  249. package/dist/web/common.js +75 -3
  250. package/dist/web/context/agent_controlled_context_compactor.js +81 -0
  251. package/dist/web/context/summarizers/llm_summarizer.js +11 -0
  252. package/dist/web/context/token_based_context_compactor.js +43 -11
  253. package/dist/web/context/trajectory_thought_pruning_compactor.js +43 -0
  254. package/dist/web/events/event.js +21 -1
  255. package/dist/web/integrations/agent_registry/agent_registry_mcp_toolset.js +21 -2
  256. package/dist/web/models/gemini_llm_connection.js +75 -19
  257. package/dist/web/models/google_llm.js +80 -17
  258. package/dist/web/models/interactions_utils.js +728 -0
  259. package/dist/web/plugins/base_plugin.js +1 -0
  260. package/dist/web/plugins/security_plugin.js +16 -0
  261. package/dist/web/runner/in_memory_runner.js +13 -2
  262. package/dist/web/runner/runner.js +111 -75
  263. package/dist/web/sessions/base_session_service.js +17 -2
  264. package/dist/web/sessions/database_session_service.js +26 -9
  265. package/dist/web/sessions/db/schema.js +44 -10
  266. package/dist/web/sessions/in_memory_session_service.js +4 -2
  267. package/dist/web/sessions/vertex_ai_session_service.js +21 -5
  268. package/dist/web/skills/gcp_skill_registry.js +78 -0
  269. package/dist/web/skills/loader.js +66 -2
  270. package/dist/web/skills/skill_registry.js +7 -0
  271. package/dist/web/tools/base_toolset.js +1 -1
  272. package/dist/web/tools/consolidate_context_tool.js +51 -0
  273. package/dist/web/tools/forwarding_artifact_service.js +16 -28
  274. package/dist/web/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js +221 -0
  275. package/dist/web/tools/openapi_tool/openapi_spec_parser/operation_parser.js +198 -0
  276. package/dist/web/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +91 -0
  277. package/dist/web/tools/openapi_tool/openapi_toolset.js +97 -0
  278. package/dist/web/tools/openapi_tool/rest_api_tool.js +229 -0
  279. package/dist/web/tools/skill/load_skill_resource_tool.js +25 -3
  280. package/dist/web/tools/skill/load_skill_tool.js +12 -1
  281. package/dist/web/tools/skill/run_skill_script_tool.js +12 -1
  282. package/dist/web/tools/skill/search_skills_tool.js +82 -0
  283. package/dist/web/tools/skill/skill_toolset.js +40 -5
  284. package/dist/web/utils/async_hooks_shim.js +24 -0
  285. package/dist/web/utils/async_queue.js +60 -0
  286. package/dist/web/utils/case_utils.js +25 -0
  287. package/dist/web/utils/client_labels.js +38 -2
  288. package/dist/web/utils/env_aware_utils.js +14 -1
  289. package/dist/web/utils/live_connection_utils.js +254 -0
  290. package/dist/web/utils/model_name.js +8 -0
  291. package/dist/web/utils/streaming_utils.js +18 -11
  292. package/dist/web/utils/task.js +34 -0
  293. package/dist/web/version.js +1 -1
  294. package/package.json +4 -2
@@ -12,6 +12,7 @@ import { JSONPath } from "jsonpath-plus";
12
12
  import { generateClientFunctionCallId } from "../agents/functions.js";
13
13
  import { FeatureName, isFeatureEnabled } from "../features/feature_registry.js";
14
14
  import { createLlmResponse } from "../models/llm_response.js";
15
+ const UNSAFE_PROPERTY_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
15
16
  class ProgressiveStrategy {
16
17
  constructor() {
17
18
  this.partsSequence = [];
@@ -78,10 +79,13 @@ class ProgressiveStrategy {
78
79
  const pathParts = JSONPath.toPathArray(jsonPath).filter(
79
80
  (p) => p !== "$" && p !== "$["
80
81
  );
82
+ if (pathParts.some((part) => UNSAFE_PROPERTY_KEYS.has(String(part)))) {
83
+ return;
84
+ }
81
85
  let current = this.currentFcArgs;
82
86
  for (let i = 0; i < pathParts.length - 1; i++) {
83
87
  const part = pathParts[i];
84
- if (!(part in current)) {
88
+ if (!Object.prototype.hasOwnProperty.call(current, part)) {
85
89
  current[part] = {};
86
90
  }
87
91
  current = current[part];
@@ -273,17 +277,13 @@ class StreamingResponseAggregator {
273
277
  )) {
274
278
  this.isProgressiveMode = isProgressiveMode;
275
279
  this.lastThoughtSignature = {};
276
- this.sawFunctionCall = false;
277
280
  this.strategy = this.isProgressiveMode ? new ProgressiveStrategy() : new NonProgressiveStrategy();
278
281
  }
279
282
  async *processResponse(response) {
280
283
  var _a, _b;
281
284
  const llmResponse = createLlmResponse(response);
282
285
  const parts = (_b = (_a = llmResponse.content) == null ? void 0 : _a.parts) != null ? _b : [];
283
- if (parts.some((part) => part.functionCall)) {
284
- this.sawFunctionCall = true;
285
- }
286
- if (this.sawFunctionCall && llmResponse.finishReason === FinishReason.STOP && parts.length > 0 && parts.every(isEmptyContentPart)) {
286
+ if (parts.every(isEmptyContentPart) && (llmResponse.finishReason === void 0 || llmResponse.finishReason === FinishReason.STOP)) {
287
287
  if (llmResponse.usageMetadata) {
288
288
  this.usageMetadata = llmResponse.usageMetadata;
289
289
  }
@@ -323,16 +323,23 @@ class StreamingResponseAggregator {
323
323
  close() {
324
324
  var _a, _b, _c;
325
325
  const finalParts = this.strategy.close();
326
- if (!finalParts) {
326
+ const hasMetadata = this.usageMetadata !== void 0 || this.groundingMetadata !== void 0 || this.citationMetadata !== void 0;
327
+ if (!finalParts && !hasMetadata) {
327
328
  return void 0;
328
329
  }
329
330
  const candidate = (_b = (_a = this.response) == null ? void 0 : _a.candidates) == null ? void 0 : _b[0];
330
331
  const finishReason = (_c = this.finishReason) != null ? _c : candidate == null ? void 0 : candidate.finishReason;
331
332
  return {
332
- content: {
333
- role: "model",
334
- parts: finalParts
335
- },
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,
336
343
  groundingMetadata: this.groundingMetadata,
337
344
  citationMetadata: this.citationMetadata,
338
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.2.0";
8
+ const version = "1.4.0";
9
9
  export {
10
10
  version
11
11
  };
@@ -13,26 +13,51 @@ export interface UserFunctionCall {
13
13
  contextId: string;
14
14
  }
15
15
  /**
16
- * Returns a UserFunctionCall when the event at index has a FunctionResponse.
16
+ * Returns a UserFunctionCall when the event at `index` contains a
17
+ * FunctionResponse that can be traced back to a preceding FunctionCall event.
18
+ *
19
+ * @param session - The session whose event history to inspect.
20
+ * @param index - Index of the candidate event to examine.
21
+ * @returns The matching `UserFunctionCall`, or `undefined` if the event at
22
+ * `index` is not a user function-response event or has no preceding call.
17
23
  */
18
24
  export declare function getUserFunctionCallAt(session: Session, index: number): UserFunctionCall | undefined;
19
25
  /**
20
26
  * Checks if an event contains a function call with the given ID.
27
+ *
28
+ * @param event - The event to inspect.
29
+ * @param callId - The function call ID to look for.
30
+ * @returns `true` if a part in the event has a matching `functionCall.id`.
21
31
  */
22
32
  export declare function isFunctionCallEvent(event: AdkEvent, callId: string): boolean;
23
33
  /**
24
34
  * Finds the first part with a FunctionResponse and returns the call ID.
35
+ *
36
+ * @param event - The event to inspect.
37
+ * @returns The `id` of the first FunctionResponse part, or `undefined` if
38
+ * none is found.
25
39
  */
26
40
  export declare function getFunctionResponseCallId(event: AdkEvent): string | undefined;
27
41
  /**
28
- * Returns content parts for all events not present in the remote session
29
- * and a2a contextId if found in a remote agent event metadata.
42
+ * Returns A2A content parts for all events not yet seen by the remote agent,
43
+ * along with the A2A context ID found in the most recent remote agent event.
44
+ *
45
+ * @param ctx - The current invocation context, used to identify the remote
46
+ * agent's authored events.
47
+ * @param session - The local session whose event history to diff.
48
+ * @returns An object with the missing `parts` and an optional `contextId`.
30
49
  */
31
50
  export declare function toMissingRemoteSessionParts(ctx: InvocationContext, session: Session): {
32
51
  parts: A2APart[];
33
52
  contextId?: string;
34
53
  };
35
54
  /**
36
- * Wraps an agent event as a user message for context.
55
+ * Wraps an agent event as a user message so it can be sent as context to a
56
+ * remote agent that only accepts user-role messages.
57
+ *
58
+ * @param ctx - The current invocation context.
59
+ * @param agentEvent - The agent-authored event to reframe as a user message.
60
+ * @returns A new event with `author: 'user'` whose parts summarise the
61
+ * original agent event's text, function calls, and function responses.
37
62
  */
38
63
  export declare function presentAsUserMessage(ctx: InvocationContext, agentEvent: AdkEvent): AdkEvent;
@@ -8,6 +8,12 @@ import { Event as AdkEvent } from '../events/event.js';
8
8
  import { A2AEvent } from './a2a_event.js';
9
9
  /**
10
10
  * Converts a session Event to an A2A Message.
11
+ *
12
+ * @param event - The ADK event to convert.
13
+ * @param appName - The name of the ADK application.
14
+ * @param userId - The ID of the current user.
15
+ * @param sessionId - The ID of the current session.
16
+ * @returns An A2A message with the event's parts and metadata.
11
17
  */
12
18
  export declare function toA2AMessage(event: AdkEvent, { appName, userId, sessionId, }: {
13
19
  appName: string;
@@ -15,6 +21,13 @@ export declare function toA2AMessage(event: AdkEvent, { appName, userId, session
15
21
  sessionId: string;
16
22
  }): Message;
17
23
  /**
18
- * Converts an A2A Event to a Session Event.
24
+ * Converts an A2A Event to an ADK Session Event.
25
+ *
26
+ * @param event - The A2A event to convert (message, task, artifact update, or
27
+ * status update).
28
+ * @param invocationId - The ADK invocation ID to attach to the resulting event.
29
+ * @param agentName - The name of the agent to use as the event author.
30
+ * @returns The converted ADK event, or `undefined` if the A2A event type
31
+ * produces no content.
19
32
  */
20
33
  export declare function toAdkEvent(event: A2AEvent, invocationId: string, agentName: string): AdkEvent | undefined;
@@ -39,10 +39,19 @@ export declare enum AdkMetadataKeys {
39
39
  }
40
40
  /**
41
41
  * Creates ADK Event metadata from an A2A Event.
42
+ *
43
+ * @param a2aEvent - The A2A event to extract metadata from.
44
+ * @returns A record containing the ADK task ID and context ID keys.
42
45
  */
43
46
  export declare function getAdkEventMetadata(a2aEvent: A2AEvent): Record<string, unknown>;
44
47
  /**
45
48
  * Creates A2A Event metadata from an ADK Event.
49
+ *
50
+ * @param adkEvent - The ADK event to extract metadata from.
51
+ * @param appName - The name of the ADK application.
52
+ * @param userId - The ID of the current user.
53
+ * @param sessionId - The ID of the current session.
54
+ * @returns A record of A2A metadata keys populated from the ADK event.
46
55
  */
47
56
  export declare function getA2AEventMetadata(adkEvent: AdkEvent, { appName, userId, sessionId, }: {
48
57
  appName: string;
@@ -51,6 +60,11 @@ export declare function getA2AEventMetadata(adkEvent: AdkEvent, { appName, userI
51
60
  }): Record<string, unknown>;
52
61
  /**
53
62
  * Creates A2A Session metadata from ADK Event invocation metadata.
63
+ *
64
+ * @param appName - The name of the ADK application.
65
+ * @param userId - The ID of the current user.
66
+ * @param sessionId - The ID of the current session.
67
+ * @returns A record of A2A metadata keys for app name, user ID, and session ID.
54
68
  */
55
69
  export declare function getA2ASessionMetadata({ appName, userId, sessionId, }: {
56
70
  appName: string;
@@ -59,5 +73,9 @@ export declare function getA2ASessionMetadata({ appName, userId, sessionId, }: {
59
73
  }): Record<string, unknown>;
60
74
  /**
61
75
  * Creates A2A Event metadata from ADK Event actions.
76
+ *
77
+ * @param actions - The ADK event actions to extract escalation and transfer
78
+ * metadata from.
79
+ * @returns A record with escalate and transfer-to-agent A2A metadata keys.
62
80
  */
63
81
  export declare function getA2AEventMetadataFromActions(actions: AdkEventActions): Record<string, unknown>;
@@ -6,43 +6,88 @@
6
6
  import { DataPart as A2ADataPart, FilePart as A2AFilePart, Part as A2APart, TextPart as A2ATextPart, Message } from '@a2a-js/sdk';
7
7
  import { Content as GenAIContent, Part as GenAIPart } from '@google/genai';
8
8
  /**
9
- * Converts GenAI Parts to A2A Parts.
9
+ * Converts an array of GenAI Parts to A2A Parts.
10
+ *
11
+ * @param parts - The GenAI parts to convert. Defaults to an empty array.
12
+ * @param longRunningToolIDs - IDs of function calls that are long-running.
13
+ * @returns An array of A2A parts.
10
14
  */
11
15
  export declare function toA2AParts(parts?: GenAIPart[], longRunningToolIDs?: string[]): A2APart[];
12
16
  /**
13
- * Converts a GenAI Part to an A2A Part.
17
+ * Converts a single GenAI Part to the appropriate A2A Part type.
18
+ *
19
+ * @param part - The GenAI part to convert.
20
+ * @param longRunningToolIDs - IDs of function calls that are long-running.
21
+ * @returns The corresponding A2A part (text, file, or data).
14
22
  */
15
23
  export declare function toA2APart(part: GenAIPart, longRunningToolIDs?: string[]): A2APart;
16
24
  /**
17
25
  * Converts a GenAI Text Part to an A2A Text Part.
26
+ *
27
+ * @param part - The GenAI part containing a text field.
28
+ * @returns An A2A text part, with thought metadata attached if applicable.
18
29
  */
19
30
  export declare function toA2ATextPart(part: GenAIPart): A2APart;
20
31
  /**
21
32
  * Converts a GenAI File Part to an A2A File Part.
33
+ *
34
+ * @param part - The GenAI part containing `fileData` or `inlineData`.
35
+ * @returns An A2A file part with URI or bytes depending on the source.
36
+ * @throws {Error} If the part contains neither `fileData` nor `inlineData`.
22
37
  */
23
38
  export declare function toA2AFilePart(part: GenAIPart): A2APart;
24
39
  /**
25
- * Converts a GenAI Data Part to an A2A Data Part.
40
+ * Converts a GenAI Data Part (function call/response or code) to an A2A Data Part.
41
+ *
42
+ * @param part - The GenAI part containing structured data.
43
+ * @param longRunningToolIDs - IDs of function calls that are long-running.
44
+ * @returns An A2A data part with the appropriate type metadata.
26
45
  */
27
46
  export declare function toA2ADataPart(part: GenAIPart, longRunningToolIDs?: string[]): A2APart;
47
+ /**
48
+ * Converts an A2A Message to a GenAI Content object.
49
+ *
50
+ * @param a2aMessage - The A2A message to convert.
51
+ * @returns A GenAI user or model content object based on the message role.
52
+ */
28
53
  export declare function toGenAIContent(a2aMessage: Message): GenAIContent;
29
54
  /**
30
- * Converts an A2A Part to a GenAI Part.
55
+ * Converts an array of A2A Parts to GenAI Parts.
56
+ *
57
+ * @param a2aParts - The A2A parts to convert.
58
+ * @returns An array of GenAI parts.
31
59
  */
32
60
  export declare function toGenAIParts(a2aParts: A2APart[]): GenAIPart[];
33
61
  /**
34
- * Converts an A2A Part to a GenAI Part.
62
+ * Converts a single A2A Part to the appropriate GenAI Part type.
63
+ *
64
+ * @param a2aPart - The A2A part to convert.
65
+ * @returns The corresponding GenAI part.
66
+ * @throws {Error} If the A2A part has an unrecognized `kind`.
35
67
  */
36
68
  export declare function toGenAIPart(a2aPart: A2APart): GenAIPart;
37
69
  /**
38
70
  * Converts an A2A Text Part to a GenAI Part.
71
+ *
72
+ * @param a2aPart - The A2A text part to convert.
73
+ * @returns A GenAI part with `text` and optional `thought` flag.
39
74
  */
40
75
  export declare function toGenAIPartText(a2aPart: A2ATextPart): GenAIPart;
41
76
  /**
42
77
  * Converts an A2A File Part to a GenAI Part.
78
+ *
79
+ * @param a2aPart - The A2A file part containing bytes or a URI.
80
+ * @returns A GenAI part with `inlineData` or `fileData` depending on the
81
+ * source, with optional video metadata attached.
82
+ * @throws {Error} If the file part contains neither bytes nor a URI.
43
83
  */
44
84
  export declare function toGenAIPartFile(a2aPart: A2AFilePart): GenAIPart;
45
85
  /**
46
- * Converts an A2A Data Part to a GenAI Part.
86
+ * Converts an A2A Data Part to the appropriate GenAI Part.
87
+ *
88
+ * @param a2aPart - The A2A data part containing structured data and type metadata.
89
+ * @returns A GenAI part with the appropriate function call, function response,
90
+ * or code execution fields, falling back to a JSON text part if the type is
91
+ * unrecognized.
47
92
  */
48
93
  export declare function toGenAIPartData(a2aPart: A2ADataPart): GenAIPart;
@@ -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
  */
@@ -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 declare const AF_FUNCTION_CALL_ID_PREFIX = "adk-";
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: {
@@ -24,14 +25,6 @@ export declare function generateClientFunctionCallId(): string;
24
25
  * unique client-side ID to each one that doesn't already have an ID.
25
26
  */
26
27
  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
28
  /**
36
29
  * Returns a set of function call ids of the long running tools.
37
30
  */
@@ -90,3 +83,13 @@ export declare function handleFunctionCallList({ invocationContext, functionCall
90
83
  * Merges a list of function response events into a single event.
91
84
  */
92
85
  export declare function mergeParallelFunctionResponseEvents(functionResponseEvents: Event[]): Event;
86
+ /**
87
+ * Finds the function call event that matches the function call ID.
88
+ * Mirrors Python ADK's `find_event_by_function_call_id`.
89
+ */
90
+ export declare function findEventByFunctionCallId(events: Event[], functionCallId: string, endIndex?: number): Event | undefined;
91
+ /**
92
+ * Finds the function call event that matches the function response ID of the last event.
93
+ * Mirrors Python ADK's `find_matching_function_call`.
94
+ */
95
+ 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';
@@ -12,14 +12,13 @@ import { BaseSessionService } from '../sessions/base_session_service.js';
12
12
  import { Session } from '../sessions/session.js';
13
13
  import { ActiveStreamingTool } from './active_streaming_tool.js';
14
14
  import { BaseAgent } from './base_agent.js';
15
- import { LiveRequestQueue } from './live_request_queue.js';
16
15
  import { RunConfig } from './run_config.js';
17
16
  import { TranscriptionEntry } from './transcription_entry.js';
18
17
  /**
19
18
  * The parameters for creating an invocation context.
20
19
  */
21
20
  export interface InvocationContextParams {
22
- artifactService?: BaseArtifactService;
21
+ artifactService?: SessionArtifactService;
23
22
  sessionService?: BaseSessionService;
24
23
  memoryService?: BaseMemoryService;
25
24
  credentialService?: BaseCredentialService;
@@ -31,7 +30,6 @@ export interface InvocationContextParams {
31
30
  endInvocation?: boolean;
32
31
  transcriptionCache?: TranscriptionEntry[];
33
32
  runConfig?: RunConfig;
34
- liveRequestQueue?: LiveRequestQueue;
35
33
  activeStreamingTools?: Record<string, ActiveStreamingTool>;
36
34
  pluginManager: PluginManager;
37
35
  abortSignal?: AbortSignal;
@@ -76,7 +74,7 @@ export interface InvocationContextParams {
76
74
  * ```
77
75
  */
78
76
  export declare class InvocationContext {
79
- readonly artifactService?: BaseArtifactService;
77
+ readonly artifactService?: SessionArtifactService;
80
78
  readonly sessionService?: BaseSessionService;
81
79
  readonly memoryService?: BaseMemoryService;
82
80
  readonly credentialService?: BaseCredentialService;
@@ -122,12 +120,12 @@ export declare class InvocationContext {
122
120
  /**
123
121
  * A container to keep track of different kinds of costs incurred as a part of
124
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.
125
127
  */
126
128
  private readonly invocationCostManager;
127
- /**
128
- * The queue to receive live requests.
129
- */
130
- liveRequestQueue?: LiveRequestQueue;
131
129
  /**
132
130
  * The running streaming tools of this invocation.
133
131
  */
@@ -136,9 +134,6 @@ export declare class InvocationContext {
136
134
  * The manager for keeping track of plugins in this invocation.
137
135
  */
138
136
  pluginManager: PluginManager;
139
- /**
140
- * The abort signal for the invocation.
141
- */
142
137
  readonly abortSignal?: AbortSignal;
143
138
  /**
144
139
  * @param params The parameters for creating an invocation context.
@@ -327,6 +327,20 @@ export declare class LlmAgent extends BaseAgent {
327
327
  private maybeSaveOutputToState;
328
328
  protected runAsyncImpl(context: InvocationContext): AsyncGenerator<Event, void, void>;
329
329
  protected runLiveImpl(context: InvocationContext): AsyncGenerator<Event, void, void>;
330
+ /**
331
+ * Runs the bidirectional (live) flow for this agent.
332
+ *
333
+ * Establishes a live connection to the model, drains the invocation's
334
+ * `liveRequestQueue` into the connection on a parallel task, and yields
335
+ * events derived from server messages until the queue closes, the model
336
+ * finishes, or an agent transfer occurs.
337
+ *
338
+ * If the live connection drops (network failure, server `goAway`) and a
339
+ * session resumption handle has been observed, the flow transparently
340
+ * reconnects using that handle up to {@link MAX_LIVE_RECONNECT_ATTEMPTS}
341
+ * times. Subsequent reconnects skip `sendHistory` because the server
342
+ * already holds the conversation state associated with the handle.
343
+ */
330
344
  private runLiveFlow;
331
345
  private runOneStepAsync;
332
346
  private postprocess;
@@ -7,9 +7,23 @@ import { Event } from '../../events/event.js';
7
7
  import { LlmRequest } from '../../models/llm_request.js';
8
8
  import { InvocationContext } from '../invocation_context.js';
9
9
  import { BaseLlmRequestProcessor } from './base_llm_processor.js';
10
+ /**
11
+ * Augments the {@link LlmRequest} to support agent transfer. When the current
12
+ * agent has reachable transfer targets (sub-agents, peer agents, or a parent
13
+ * agent), this processor registers a `transfer_to_agent` function tool and
14
+ * appends instructions describing each candidate so the model can choose to
15
+ * hand off control.
16
+ */
10
17
  export declare class AgentTransferLlmRequestProcessor extends BaseLlmRequestProcessor {
11
18
  private readonly toolName;
12
19
  private readonly tool;
20
+ /**
21
+ * Appends transfer instructions and registers the `transfer_to_agent` tool
22
+ * when the agent has reachable transfer targets.
23
+ *
24
+ * @param invocationContext - The current invocation context.
25
+ * @param llmRequest - The request to augment with transfer instructions and the transfer tool.
26
+ */
13
27
  runAsync(invocationContext: InvocationContext, llmRequest: LlmRequest): AsyncGenerator<Event, void, void>;
14
28
  private buildTargetAgentsInfo;
15
29
  private buildTargetAgentsInstructions;
@@ -13,6 +13,13 @@ import { BaseLlmRequestProcessor } from './base_llm_processor.js';
13
13
  * connect settings.
14
14
  */
15
15
  export declare class BasicLlmRequestProcessor extends BaseLlmRequestProcessor {
16
+ /**
17
+ * Populates model name, generation config, output schema, and live connect
18
+ * settings on the request from the agent and run config.
19
+ *
20
+ * @param invocationContext - The current invocation context.
21
+ * @param llmRequest - The request object to populate in place.
22
+ */
16
23
  runAsync(invocationContext: InvocationContext, llmRequest: LlmRequest): AsyncGenerator<Event, void, void>;
17
24
  }
18
25
  export declare const BASIC_LLM_REQUEST_PROCESSOR: BasicLlmRequestProcessor;
@@ -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
  *
@@ -34,3 +42,29 @@ export declare function getContents(events: Event[], agentName: string, currentB
34
42
  * needed for proper tool execution while excluding conversation history.
35
43
  */
36
44
  export declare function getCurrentTurnContents(events: Event[], agentName: string, currentBranch?: string): Content[];
45
+ /**
46
+ * Merges a list of function_response events into one event.
47
+ *
48
+ * The key goal is to ensure:
49
+ * 1. function_call and function_response are always of the same number.
50
+ * 2. The function_call and function_response are consecutively in the content.
51
+ *
52
+ * @param events: A list of function_response events.
53
+ *
54
+ * NOTE:
55
+ * function_response_events must fulfill these requirements:
56
+ * 1. The list is in increasing order of timestamp;
57
+ * 2. the first event is the initial function_response event;
58
+ * 3. all later events should contain at least one function_response part that
59
+ * related to the function_call event. Caveat: This implementation doesn't
60
+ * support when a parallel function_call event contains async function_call of
61
+ * the same name.
62
+ *
63
+ * @returns
64
+ * A merged event, that is
65
+ * 1. All later function_response will replace function_response part in
66
+ * the initial function_response event.
67
+ * 2. All non-function_response parts will be appended to the part list of
68
+ * the initial function_response event.
69
+ */
70
+ export declare function mergeFunctionResponseEvents(events: Event[]): Event;
@@ -7,7 +7,23 @@ import { Event } from '../../events/event.js';
7
7
  import { LlmRequest } from '../../models/llm_request.js';
8
8
  import { InvocationContext } from '../invocation_context.js';
9
9
  import { BaseLlmRequestProcessor } from './base_llm_processor.js';
10
+ /**
11
+ * Populates {@link LlmRequest.contents} from the session event history.
12
+ *
13
+ * When a {@link CompactedEvent} exists in the session, only the most recent
14
+ * compacted event and the raw events that follow it are included, eliding
15
+ * earlier history. The extent of context included depends on the agent's
16
+ * `includeContents` setting: `'default'` sends the full visible history while
17
+ * any other value sends only the current-turn context.
18
+ */
10
19
  export declare class ContentRequestProcessor implements BaseLlmRequestProcessor {
20
+ /**
21
+ * Fills {@link LlmRequest.contents} based on the session event history and
22
+ * agent configuration.
23
+ *
24
+ * @param invocationContext - The current invocation context.
25
+ * @param llmRequest - The request whose contents field will be populated.
26
+ */
11
27
  runAsync(invocationContext: InvocationContext, llmRequest: LlmRequest): AsyncGenerator<Event, void, void>;
12
28
  }
13
29
  export declare const CONTENT_REQUEST_PROCESSOR: ContentRequestProcessor;
@@ -17,6 +17,18 @@ import { BaseLlmRequestProcessor } from './base_llm_processor.js';
17
17
  */
18
18
  export declare class ContextCompactorRequestProcessor implements BaseLlmRequestProcessor {
19
19
  private compactors;
20
+ /**
21
+ * @param compactors - Ordered list of compactors to evaluate; the first one
22
+ * that reports it should compact will perform the compaction.
23
+ */
20
24
  constructor(compactors: BaseContextCompactor[]);
25
+ /**
26
+ * Evaluates compactors in priority order. The first compactor that indicates
27
+ * it should compact will compact the session history, fire plugin hooks, and
28
+ * yield any newly generated events. Iteration stops after one compaction.
29
+ *
30
+ * @param invocationContext - The current invocation context.
31
+ * @param _llmRequest - Unused; present to satisfy the {@link BaseLlmRequestProcessor} interface.
32
+ */
21
33
  runAsync(invocationContext: InvocationContext, _llmRequest: LlmRequest): AsyncGenerator<Event, void, void>;
22
34
  }
@@ -12,6 +12,13 @@ import { BaseLlmRequestProcessor } from './base_llm_processor.js';
12
12
  * informing the model of the agent's name and description.
13
13
  */
14
14
  export declare class IdentityLlmRequestProcessor extends BaseLlmRequestProcessor {
15
+ /**
16
+ * Appends agent name and description as identity instructions to the system
17
+ * prompt of the request.
18
+ *
19
+ * @param invocationContext - The current invocation context.
20
+ * @param llmRequest - The request object to append instructions to.
21
+ */
15
22
  runAsync(invocationContext: InvocationContext, llmRequest: LlmRequest): AsyncGenerator<Event, void, undefined>;
16
23
  }
17
24
  export declare const IDENTITY_LLM_REQUEST_PROCESSOR: IdentityLlmRequestProcessor;
@@ -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;