@google/adk 1.2.0 → 1.3.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 (190) hide show
  1. package/dist/cjs/agents/base_agent.js +19 -1
  2. package/dist/cjs/agents/instructions.js +81 -33
  3. package/dist/cjs/agents/invocation_context.js +0 -1
  4. package/dist/cjs/agents/llm_agent.js +52 -5
  5. package/dist/cjs/agents/processors/agent_transfer_llm_request_processor.js +7 -0
  6. package/dist/cjs/agents/processors/basic_llm_request_processor.js +8 -1
  7. package/dist/cjs/agents/processors/content_processor_utils.js +37 -24
  8. package/dist/cjs/agents/processors/content_request_processor.js +7 -0
  9. package/dist/cjs/agents/processors/context_compactor_request_processor.js +12 -0
  10. package/dist/cjs/agents/processors/identity_llm_request_processor.js +7 -0
  11. package/dist/cjs/agents/processors/instructions_llm_request_processor.js +5 -0
  12. package/dist/cjs/agents/processors/request_confirmation_llm_request_processor.js +9 -1
  13. package/dist/cjs/agents/processors/tool_filter_request_processor.js +7 -1
  14. package/dist/cjs/auth/auth_preprocessor.js +12 -10
  15. package/dist/cjs/auth/oauth2/oauth2_discovery.js +1 -1
  16. package/dist/cjs/code_executors/code_executor_context.js +7 -7
  17. package/dist/cjs/common.js +39 -0
  18. package/dist/cjs/context/summarizers/llm_summarizer.js +11 -0
  19. package/dist/cjs/context/token_based_context_compactor.js +1 -1
  20. package/dist/cjs/events/event.js +1 -1
  21. package/dist/cjs/integrations/agent_registry/agent_registry_mcp_toolset.js +21 -2
  22. package/dist/cjs/models/gemini_llm_connection.js +62 -19
  23. package/dist/cjs/models/google_llm.js +26 -8
  24. package/dist/cjs/plugins/security_plugin.js +16 -0
  25. package/dist/cjs/sessions/base_session_service.js +13 -2
  26. package/dist/cjs/sessions/database_session_service.js +2 -2
  27. package/dist/cjs/sessions/db/schema.js +45 -10
  28. package/dist/cjs/sessions/in_memory_session_service.js +2 -1
  29. package/dist/cjs/sessions/vertex_ai_session_service.js +2 -1
  30. package/dist/cjs/skills/gcp_skill_registry.js +104 -0
  31. package/dist/cjs/skills/loader.js +65 -0
  32. package/dist/cjs/skills/skill_registry.js +27 -0
  33. package/dist/cjs/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js +232 -0
  34. package/dist/cjs/tools/openapi_tool/openapi_spec_parser/operation_parser.js +224 -0
  35. package/dist/cjs/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +127 -0
  36. package/dist/cjs/tools/openapi_tool/openapi_toolset.js +133 -0
  37. package/dist/cjs/tools/openapi_tool/rest_api_tool.js +256 -0
  38. package/dist/cjs/tools/skill/load_skill_resource_tool.js +25 -3
  39. package/dist/cjs/tools/skill/load_skill_tool.js +12 -1
  40. package/dist/cjs/tools/skill/run_skill_script_tool.js +12 -1
  41. package/dist/cjs/tools/skill/search_skills_tool.js +108 -0
  42. package/dist/cjs/tools/skill/skill_toolset.js +40 -5
  43. package/dist/cjs/utils/async_queue.js +88 -0
  44. package/dist/cjs/utils/case_utils.js +53 -0
  45. package/dist/cjs/utils/env_aware_utils.js +4 -0
  46. package/dist/cjs/utils/live_connection_utils.js +284 -0
  47. package/dist/cjs/utils/model_name.js +9 -0
  48. package/dist/cjs/utils/streaming_utils.js +9 -8
  49. package/dist/cjs/version.js +1 -1
  50. package/dist/esm/agents/base_agent.js +19 -1
  51. package/dist/esm/agents/instructions.js +81 -33
  52. package/dist/esm/agents/invocation_context.js +0 -1
  53. package/dist/esm/agents/llm_agent.js +53 -5
  54. package/dist/esm/agents/processors/agent_transfer_llm_request_processor.js +7 -0
  55. package/dist/esm/agents/processors/basic_llm_request_processor.js +8 -1
  56. package/dist/esm/agents/processors/content_processor_utils.js +35 -23
  57. package/dist/esm/agents/processors/content_request_processor.js +7 -0
  58. package/dist/esm/agents/processors/context_compactor_request_processor.js +12 -0
  59. package/dist/esm/agents/processors/identity_llm_request_processor.js +7 -0
  60. package/dist/esm/agents/processors/instructions_llm_request_processor.js +5 -0
  61. package/dist/esm/agents/processors/request_confirmation_llm_request_processor.js +9 -1
  62. package/dist/esm/agents/processors/tool_filter_request_processor.js +7 -1
  63. package/dist/esm/auth/auth_preprocessor.js +12 -10
  64. package/dist/esm/auth/oauth2/oauth2_discovery.js +1 -1
  65. package/dist/esm/code_executors/code_executor_context.js +7 -7
  66. package/dist/esm/common.js +33 -1
  67. package/dist/esm/context/summarizers/llm_summarizer.js +11 -0
  68. package/dist/esm/context/token_based_context_compactor.js +1 -1
  69. package/dist/esm/events/event.js +1 -1
  70. package/dist/esm/integrations/agent_registry/agent_registry_mcp_toolset.js +21 -2
  71. package/dist/esm/models/gemini_llm_connection.js +62 -19
  72. package/dist/esm/models/google_llm.js +26 -8
  73. package/dist/esm/plugins/security_plugin.js +16 -0
  74. package/dist/esm/sessions/base_session_service.js +11 -1
  75. package/dist/esm/sessions/database_session_service.js +2 -2
  76. package/dist/esm/sessions/db/schema.js +44 -10
  77. package/dist/esm/sessions/in_memory_session_service.js +4 -2
  78. package/dist/esm/sessions/vertex_ai_session_service.js +4 -2
  79. package/dist/esm/skills/gcp_skill_registry.js +78 -0
  80. package/dist/esm/skills/loader.js +64 -0
  81. package/dist/esm/skills/skill_registry.js +7 -0
  82. package/dist/esm/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js +206 -0
  83. package/dist/esm/tools/openapi_tool/openapi_spec_parser/operation_parser.js +198 -0
  84. package/dist/esm/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +101 -0
  85. package/dist/esm/tools/openapi_tool/openapi_toolset.js +97 -0
  86. package/dist/esm/tools/openapi_tool/rest_api_tool.js +229 -0
  87. package/dist/esm/tools/skill/load_skill_resource_tool.js +25 -3
  88. package/dist/esm/tools/skill/load_skill_tool.js +12 -1
  89. package/dist/esm/tools/skill/run_skill_script_tool.js +12 -1
  90. package/dist/esm/tools/skill/search_skills_tool.js +82 -0
  91. package/dist/esm/tools/skill/skill_toolset.js +40 -5
  92. package/dist/esm/utils/async_queue.js +60 -0
  93. package/dist/esm/utils/case_utils.js +25 -0
  94. package/dist/esm/utils/env_aware_utils.js +4 -0
  95. package/dist/esm/utils/live_connection_utils.js +256 -0
  96. package/dist/esm/utils/model_name.js +8 -0
  97. package/dist/esm/utils/streaming_utils.js +9 -8
  98. package/dist/esm/version.js +1 -1
  99. package/dist/types/a2a/a2a_remote_agent_utils.d.ts +29 -4
  100. package/dist/types/a2a/event_converter_utils.d.ts +14 -1
  101. package/dist/types/a2a/metadata_converter_utils.d.ts +18 -0
  102. package/dist/types/a2a/part_converter_utils.d.ts +51 -6
  103. package/dist/types/agents/invocation_context.d.ts +0 -9
  104. package/dist/types/agents/llm_agent.d.ts +14 -0
  105. package/dist/types/agents/processors/agent_transfer_llm_request_processor.d.ts +14 -0
  106. package/dist/types/agents/processors/basic_llm_request_processor.d.ts +7 -0
  107. package/dist/types/agents/processors/content_processor_utils.d.ts +26 -0
  108. package/dist/types/agents/processors/content_request_processor.d.ts +16 -0
  109. package/dist/types/agents/processors/context_compactor_request_processor.d.ts +12 -0
  110. package/dist/types/agents/processors/identity_llm_request_processor.d.ts +7 -0
  111. package/dist/types/agents/processors/request_confirmation_llm_request_processor.d.ts +9 -1
  112. package/dist/types/agents/processors/tool_filter_request_processor.d.ts +12 -1
  113. package/dist/types/common.d.ts +15 -1
  114. package/dist/types/context/summarizers/llm_summarizer.d.ts +17 -0
  115. package/dist/types/events/event_actions.d.ts +1 -2
  116. package/dist/types/integrations/agent_registry/agent_registry_mcp_toolset.d.ts +21 -2
  117. package/dist/types/models/base_llm_connection.d.ts +10 -0
  118. package/dist/types/models/gemini_llm_connection.d.ts +15 -4
  119. package/dist/types/models/llm_response.d.ts +10 -1
  120. package/dist/types/plugins/security_plugin.d.ts +30 -0
  121. package/dist/types/sessions/base_session_service.d.ts +4 -0
  122. package/dist/types/sessions/db/schema.d.ts +1 -0
  123. package/dist/types/skills/gcp_skill_registry.d.ts +24 -0
  124. package/dist/types/skills/loader.d.ts +7 -0
  125. package/dist/types/skills/skill.d.ts +1 -1
  126. package/dist/types/skills/skill_registry.d.ts +29 -0
  127. package/dist/types/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.d.ts +34 -0
  128. package/dist/types/tools/openapi_tool/openapi_spec_parser/operation_parser.d.ts +59 -0
  129. package/dist/types/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.d.ts +23 -0
  130. package/dist/types/tools/openapi_tool/openapi_toolset.d.ts +27 -0
  131. package/dist/types/tools/openapi_tool/rest_api_tool.d.ts +50 -0
  132. package/dist/types/tools/skill/load_skill_resource_tool.d.ts +1 -1
  133. package/dist/types/tools/skill/search_skills_tool.d.ts +14 -0
  134. package/dist/types/tools/skill/skill_toolset.d.ts +5 -0
  135. package/dist/types/utils/async_queue.d.ts +18 -0
  136. package/dist/types/utils/case_utils.d.ts +12 -0
  137. package/dist/types/utils/live_connection_utils.d.ts +30 -0
  138. package/dist/types/utils/model_name.d.ts +7 -0
  139. package/dist/types/utils/streaming_utils.d.ts +0 -1
  140. package/dist/types/version.d.ts +1 -1
  141. package/dist/web/agents/base_agent.js +31 -1
  142. package/dist/web/agents/instructions.js +81 -33
  143. package/dist/web/agents/invocation_context.js +0 -1
  144. package/dist/web/agents/llm_agent.js +53 -5
  145. package/dist/web/agents/processors/agent_transfer_llm_request_processor.js +7 -0
  146. package/dist/web/agents/processors/basic_llm_request_processor.js +8 -1
  147. package/dist/web/agents/processors/content_processor_utils.js +53 -23
  148. package/dist/web/agents/processors/content_request_processor.js +7 -0
  149. package/dist/web/agents/processors/context_compactor_request_processor.js +12 -0
  150. package/dist/web/agents/processors/identity_llm_request_processor.js +7 -0
  151. package/dist/web/agents/processors/instructions_llm_request_processor.js +5 -0
  152. package/dist/web/agents/processors/request_confirmation_llm_request_processor.js +9 -1
  153. package/dist/web/agents/processors/tool_filter_request_processor.js +7 -1
  154. package/dist/web/auth/auth_preprocessor.js +12 -10
  155. package/dist/web/auth/oauth2/oauth2_discovery.js +1 -1
  156. package/dist/web/code_executors/code_executor_context.js +7 -7
  157. package/dist/web/common.js +33 -1
  158. package/dist/web/context/summarizers/llm_summarizer.js +11 -0
  159. package/dist/web/context/token_based_context_compactor.js +1 -1
  160. package/dist/web/events/event.js +1 -1
  161. package/dist/web/integrations/agent_registry/agent_registry_mcp_toolset.js +21 -2
  162. package/dist/web/models/gemini_llm_connection.js +75 -19
  163. package/dist/web/models/google_llm.js +26 -8
  164. package/dist/web/plugins/security_plugin.js +16 -0
  165. package/dist/web/sessions/base_session_service.js +11 -1
  166. package/dist/web/sessions/database_session_service.js +2 -2
  167. package/dist/web/sessions/db/schema.js +44 -10
  168. package/dist/web/sessions/in_memory_session_service.js +4 -2
  169. package/dist/web/sessions/vertex_ai_session_service.js +4 -2
  170. package/dist/web/skills/gcp_skill_registry.js +78 -0
  171. package/dist/web/skills/loader.js +64 -0
  172. package/dist/web/skills/skill_registry.js +7 -0
  173. package/dist/web/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js +221 -0
  174. package/dist/web/tools/openapi_tool/openapi_spec_parser/operation_parser.js +198 -0
  175. package/dist/web/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +101 -0
  176. package/dist/web/tools/openapi_tool/openapi_toolset.js +97 -0
  177. package/dist/web/tools/openapi_tool/rest_api_tool.js +229 -0
  178. package/dist/web/tools/skill/load_skill_resource_tool.js +25 -3
  179. package/dist/web/tools/skill/load_skill_tool.js +12 -1
  180. package/dist/web/tools/skill/run_skill_script_tool.js +12 -1
  181. package/dist/web/tools/skill/search_skills_tool.js +82 -0
  182. package/dist/web/tools/skill/skill_toolset.js +40 -5
  183. package/dist/web/utils/async_queue.js +60 -0
  184. package/dist/web/utils/case_utils.js +25 -0
  185. package/dist/web/utils/env_aware_utils.js +4 -0
  186. package/dist/web/utils/live_connection_utils.js +254 -0
  187. package/dist/web/utils/model_name.js +8 -0
  188. package/dist/web/utils/streaming_utils.js +9 -8
  189. package/dist/web/version.js +1 -1
  190. package/package.json +3 -1
@@ -1,5 +1,24 @@
1
1
  import {createRequire as topLevelCreateRequire} from 'module';
2
2
  const require = topLevelCreateRequire(import.meta.url);
3
+ var __defProp = Object.defineProperty;
4
+ var __defProps = Object.defineProperties;
5
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
9
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
10
+ var __spreadValues = (a, b) => {
11
+ for (var prop in b || (b = {}))
12
+ if (__hasOwnProp.call(b, prop))
13
+ __defNormalProp(a, prop, b[prop]);
14
+ if (__getOwnPropSymbols)
15
+ for (var prop of __getOwnPropSymbols(b)) {
16
+ if (__propIsEnum.call(b, prop))
17
+ __defNormalProp(a, prop, b[prop]);
18
+ }
19
+ return a;
20
+ };
21
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
3
22
  /**
4
23
  * @license
5
24
  * Copyright 2025 Google LLC
@@ -109,17 +128,19 @@ function convertForeignEvent(event) {
109
128
  text: "[".concat(event.author, "] said: ").concat(part.text)
110
129
  });
111
130
  } else if (part.functionCall) {
112
- const argsText = safeStringify(part.functionCall.args);
113
131
  (_d = content.parts) == null ? void 0 : _d.push({
114
- text: "[".concat(event.author, "] called tool `").concat(part.functionCall.name, "` with parameters: ").concat(argsText)
132
+ text: "[".concat(event.author, "] called tool `").concat(part.functionCall.name, "` with parameters: ").concat(safeStringify(
133
+ part.functionCall.args
134
+ ))
115
135
  });
116
136
  } else if (part.functionResponse) {
117
- const responseText = safeStringify(part.functionResponse.response);
118
137
  (_e = content.parts) == null ? void 0 : _e.push({
119
- text: "[".concat(event.author, "] tool `").concat(part.functionResponse.name, "` returned result: ").concat(responseText)
138
+ text: "[".concat(event.author, "] tool `").concat(part.functionResponse.name, "` returned result: ").concat(safeStringify(
139
+ part.functionResponse.response
140
+ ))
120
141
  });
121
142
  } else {
122
- (_f = content.parts) == null ? void 0 : _f.push(part);
143
+ (_f = content.parts) == null ? void 0 : _f.push(cloneDeep(part));
123
144
  }
124
145
  }
125
146
  return createEvent({
@@ -135,9 +156,11 @@ function mergeFunctionResponseEvents(events) {
135
156
  if (events.length === 0) {
136
157
  throw new Error("Cannot merge an empty list of events.");
137
158
  }
138
- const mergedEvent = createEvent(events[0]);
139
- const partsInMergedEvent = ((_a = mergedEvent.content) == null ? void 0 : _a.parts) || [];
140
- if (partsInMergedEvent.length === 0) {
159
+ const mergedEvent = createEvent(__spreadProps(__spreadValues({}, events[0]), {
160
+ content: events[0].content ? cloneDeep(events[0].content) : void 0
161
+ }));
162
+ const partsInMergedEvent = (_a = mergedEvent.content) == null ? void 0 : _a.parts;
163
+ if (!partsInMergedEvent || partsInMergedEvent.length === 0) {
141
164
  throw new Error("There should be at least one function_response part.");
142
165
  }
143
166
  const partIndicesInMergedEvent = {};
@@ -152,16 +175,17 @@ function mergeFunctionResponseEvents(events) {
152
175
  throw new Error("There should be at least one function_response part.");
153
176
  }
154
177
  for (const part of event.content.parts) {
155
- if (part.functionResponse && part.functionResponse.id) {
156
- const functionCallId = part.functionResponse.id;
178
+ const clonedPart = cloneDeep(part);
179
+ if (clonedPart.functionResponse && clonedPart.functionResponse.id) {
180
+ const functionCallId = clonedPart.functionResponse.id;
157
181
  if (functionCallId in partIndicesInMergedEvent) {
158
- partsInMergedEvent[partIndicesInMergedEvent[functionCallId]] = part;
182
+ partsInMergedEvent[partIndicesInMergedEvent[functionCallId]] = clonedPart;
159
183
  } else {
160
- partsInMergedEvent.push(part);
184
+ partsInMergedEvent.push(clonedPart);
161
185
  partIndicesInMergedEvent[functionCallId] = partsInMergedEvent.length - 1;
162
186
  }
163
187
  } else {
164
- partsInMergedEvent.push(part);
188
+ partsInMergedEvent.push(clonedPart);
165
189
  }
166
190
  }
167
191
  }
@@ -176,7 +200,7 @@ function rearrangeEventsForLatestFunctionResponse(events) {
176
200
  if (!(functionResponses == null ? void 0 : functionResponses.length)) {
177
201
  return events;
178
202
  }
179
- let functionResponsesIds = new Set(
203
+ const functionResponsesIds = new Set(
180
204
  functionResponses.filter((response) => !!response.id).map((response) => response.id)
181
205
  );
182
206
  const secondLatestEvent = events.at(-2);
@@ -190,16 +214,16 @@ function rearrangeEventsForLatestFunctionResponse(events) {
190
214
  }
191
215
  }
192
216
  }
193
- let functionCallEventIdx = -1;
217
+ let match;
194
218
  for (let idx = events.length - 2; idx >= 0; idx--) {
195
219
  const event = events[idx];
196
220
  const functionCalls = getFunctionCalls(event);
197
221
  if (!(functionCalls == null ? void 0 : functionCalls.length)) {
198
222
  continue;
199
223
  }
224
+ let matchedInEvent = false;
200
225
  for (const functionCall of functionCalls) {
201
226
  if (functionCall.id && functionResponsesIds.has(functionCall.id)) {
202
- functionCallEventIdx = idx;
203
227
  const functionCallIds = new Set(
204
228
  functionCalls.map((fc) => fc.id).filter((id) => !!id)
205
229
  );
@@ -213,12 +237,16 @@ function rearrangeEventsForLatestFunctionResponse(events) {
213
237
  ), ", function response") + " ids provided: ".concat(Array.from(functionResponsesIds).join(", "))
214
238
  );
215
239
  }
216
- functionResponsesIds = functionCallIds;
240
+ match = { eventIdx: idx, responseIds: functionCallIds };
241
+ matchedInEvent = true;
217
242
  break;
218
243
  }
219
244
  }
245
+ if (matchedInEvent) {
246
+ break;
247
+ }
220
248
  }
221
- if (functionCallEventIdx === -1) {
249
+ if (!match) {
222
250
  throw new Error(
223
251
  "No function call event found for function responses ids: ".concat(Array.from(
224
252
  functionResponsesIds
@@ -226,17 +254,18 @@ function rearrangeEventsForLatestFunctionResponse(events) {
226
254
  );
227
255
  }
228
256
  const functionResponseEvents = [];
229
- for (let idx = functionCallEventIdx + 1; idx < events.length - 1; idx++) {
257
+ const activeResponses = match.responseIds;
258
+ for (let idx = match.eventIdx + 1; idx < events.length - 1; idx++) {
230
259
  const event = events[idx];
231
260
  const responses = getFunctionResponses(event);
232
261
  if (responses && responses.some(
233
- (response) => response.id && functionResponsesIds.has(response.id)
262
+ (response) => response.id && activeResponses.has(response.id)
234
263
  )) {
235
264
  functionResponseEvents.push(event);
236
265
  }
237
266
  }
238
267
  functionResponseEvents.push(events[events.length - 1]);
239
- const resultEvents = events.slice(0, functionCallEventIdx + 1);
268
+ const resultEvents = events.slice(0, match.eventIdx + 1);
240
269
  resultEvents.push(mergeFunctionResponseEvents(functionResponseEvents));
241
270
  return resultEvents;
242
271
  }
@@ -275,7 +304,7 @@ function rearrangeEventsForAsyncFunctionResponsesInHistory(events) {
275
304
  continue;
276
305
  }
277
306
  if (functionResponseEventsIndices.size === 1) {
278
- const [responseIndex] = [...functionResponseEventsIndices];
307
+ const [responseIndex] = Array.from(functionResponseEventsIndices);
279
308
  resultEvents.push(events[responseIndex]);
280
309
  } else {
281
310
  const indicesArray = Array.from(functionResponseEventsIndices).sort(
@@ -314,5 +343,6 @@ function convertCompactedEvent(event) {
314
343
  }
315
344
  export {
316
345
  getContents,
317
- getCurrentTurnContents
346
+ getCurrentTurnContents,
347
+ mergeFunctionResponseEvents
318
348
  };
@@ -28,6 +28,13 @@ import {
28
28
  getCurrentTurnContents
29
29
  } from "./content_processor_utils.js";
30
30
  class ContentRequestProcessor {
31
+ /**
32
+ * Fills {@link LlmRequest.contents} based on the session event history and
33
+ * agent configuration.
34
+ *
35
+ * @param invocationContext - The current invocation context.
36
+ * @param llmRequest - The request whose contents field will be populated.
37
+ */
31
38
  // eslint-disable-next-line require-yield
32
39
  runAsync(invocationContext, llmRequest) {
33
40
  return __asyncGenerator(this, null, function* () {
@@ -23,9 +23,21 @@ var __asyncGenerator = (__this, __arguments, generator) => {
23
23
  */
24
24
  import { ContextCompactionTrigger } from "../../plugins/base_plugin.js";
25
25
  class ContextCompactorRequestProcessor {
26
+ /**
27
+ * @param compactors - Ordered list of compactors to evaluate; the first one
28
+ * that reports it should compact will perform the compaction.
29
+ */
26
30
  constructor(compactors) {
27
31
  this.compactors = compactors;
28
32
  }
33
+ /**
34
+ * Evaluates compactors in priority order. The first compactor that indicates
35
+ * it should compact will compact the session history, fire plugin hooks, and
36
+ * yield any newly generated events. Iteration stops after one compaction.
37
+ *
38
+ * @param invocationContext - The current invocation context.
39
+ * @param _llmRequest - Unused; present to satisfy the {@link BaseLlmRequestProcessor} interface.
40
+ */
29
41
  runAsync(invocationContext, _llmRequest) {
30
42
  return __asyncGenerator(this, null, function* () {
31
43
  for (const compactor of this.compactors) {
@@ -24,6 +24,13 @@ var __asyncGenerator = (__this, __arguments, generator) => {
24
24
  import { appendInstructions } from "../../models/llm_request.js";
25
25
  import { BaseLlmRequestProcessor } from "./base_llm_processor.js";
26
26
  class IdentityLlmRequestProcessor extends BaseLlmRequestProcessor {
27
+ /**
28
+ * Appends agent name and description as identity instructions to the system
29
+ * prompt of the request.
30
+ *
31
+ * @param invocationContext - The current invocation context.
32
+ * @param llmRequest - The request object to append instructions to.
33
+ */
27
34
  // eslint-disable-next-line require-yield
28
35
  runAsync(invocationContext, llmRequest) {
29
36
  return __asyncGenerator(this, null, function* () {
@@ -64,6 +64,11 @@ class InstructionsLlmRequestProcessor extends BaseLlmRequestProcessor {
64
64
  }
65
65
  appendInstructions(llmRequest, [instructionWithState]);
66
66
  }
67
+ if (agent.outputSchema && agent.tools && agent.tools.length > 0) {
68
+ appendInstructions(llmRequest, [
69
+ 'To output the final result, you must call the "set_model_response" function with the appropriate values. Do not output anything else.'
70
+ ]);
71
+ }
67
72
  });
68
73
  }
69
74
  }
@@ -34,7 +34,15 @@ import { isLlmAgent } from "../llm_agent.js";
34
34
  import { ReadonlyContext } from "../readonly_context.js";
35
35
  import { BaseLlmRequestProcessor } from "./base_llm_processor.js";
36
36
  class RequestConfirmationLlmRequestProcessor extends BaseLlmRequestProcessor {
37
- /** Handles tool confirmation information to build the LLM request. */
37
+ /**
38
+ * Resumes tool calls that were paused for user confirmation, re-invoking
39
+ * them with the confirmed or denied decision before the next LLM turn.
40
+ *
41
+ * @param invocationContext - The current invocation context, including the
42
+ * session event history used to locate pending confirmation responses.
43
+ * @yields Function response events for tools that have been confirmed and
44
+ * are ready to resume.
45
+ */
38
46
  runAsync(invocationContext) {
39
47
  return __asyncGenerator(this, null, function* () {
40
48
  const agent = invocationContext.agent;
@@ -26,7 +26,13 @@ import { isLlmAgent } from "../llm_agent.js";
26
26
  import { ReadonlyContext } from "../readonly_context.js";
27
27
  import { BaseLlmRequestProcessor } from "./base_llm_processor.js";
28
28
  class ToolFilterRequestProcessor extends BaseLlmRequestProcessor {
29
- /** Filters the set of tools on the request based on plugins. */
29
+ /**
30
+ * Invokes plugin-based tool filtering and updates {@link LlmRequest.allowedTools}
31
+ * with the reduced tool set if any plugin returns a filtered result.
32
+ *
33
+ * @param invocationContext - The current invocation context.
34
+ * @param llmRequest - The request whose allowed tools may be restricted.
35
+ */
30
36
  // eslint-disable-next-line require-yield
31
37
  runAsync(invocationContext, llmRequest) {
32
38
  return __asyncGenerator(this, null, function* () {
@@ -33,6 +33,7 @@ import {
33
33
  getFunctionResponses
34
34
  } from "../events/event.js";
35
35
  import { State } from "../sessions/state.js";
36
+ import { camelCaseKeys } from "../utils/case_utils.js";
36
37
  import { AuthHandler } from "./auth_handler.js";
37
38
  const TOOLSET_AUTH_CREDENTIAL_ID_PREFIX = "_adk_toolset_auth_";
38
39
  async function storeAuthAndCollectResumeTargets(events, authFcIds, authResponses, state) {
@@ -41,17 +42,15 @@ async function storeAuthAndCollectResumeTargets(events, authFcIds, authResponses
41
42
  const eventFunctionCalls = getFunctionCalls(event);
42
43
  for (const functionCall of eventFunctionCalls) {
43
44
  if (functionCall.id && authFcIds.has(functionCall.id) && functionCall.name === REQUEST_EUC_FUNCTION_CALL_NAME) {
44
- const args = functionCall.args;
45
- if (args && args.authConfig) {
46
- requestedAuthConfigById[functionCall.id] = args.authConfig;
45
+ const args = camelCaseKeys(functionCall.args);
46
+ const authConfig = args == null ? void 0 : args.authConfig;
47
+ if (authConfig) {
48
+ requestedAuthConfigById[functionCall.id] = authConfig;
47
49
  }
48
50
  }
49
51
  }
50
52
  }
51
53
  for (const fcId of authFcIds) {
52
- if (!(fcId in authResponses)) {
53
- continue;
54
- }
55
54
  const authConfig = authResponses[fcId];
56
55
  const requestedAuthConfig = requestedAuthConfigById[fcId];
57
56
  if (requestedAuthConfig && requestedAuthConfig.credentialKey) {
@@ -69,12 +68,15 @@ async function storeAuthAndCollectResumeTargets(events, authFcIds, authResponses
69
68
  const eventFunctionCalls = getFunctionCalls(event);
70
69
  for (const functionCall of eventFunctionCalls) {
71
70
  if (functionCall.id === fcId && functionCall.name === REQUEST_EUC_FUNCTION_CALL_NAME) {
72
- const args = functionCall.args;
73
- if (args && args.functionCallId) {
74
- if (args.functionCallId.startsWith(TOOLSET_AUTH_CREDENTIAL_ID_PREFIX)) {
71
+ const args = camelCaseKeys(
72
+ functionCall.args
73
+ );
74
+ const functionCallId = args == null ? void 0 : args.functionCallId;
75
+ if (functionCallId) {
76
+ if (functionCallId.startsWith(TOOLSET_AUTH_CREDENTIAL_ID_PREFIX)) {
75
77
  continue;
76
78
  }
77
- toolsToResume.add(args.functionCallId);
79
+ toolsToResume.add(functionCallId);
78
80
  }
79
81
  }
80
82
  }
@@ -143,7 +143,7 @@ function validateDiscoveryUrl(urlStr) {
143
143
  return false;
144
144
  }
145
145
  const host = normaliseHostname(url.hostname.toLowerCase());
146
- if (host === "localhost" || host === "127.0.0.1" || host === "[::1]" || host === "0.0.0.0" || host.startsWith("10.") || host.startsWith("192.168.") || host.startsWith("169.254.")) {
146
+ if (host === "localhost" || host === "metadata.google.internal" || host === "metadata.goog" || host.startsWith("127.") || host === "[::1]" || host === "0.0.0.0" || host.startsWith("10.") || host.startsWith("192.168.") || host.startsWith("169.254.")) {
147
147
  logger.warn("Unsafe host for discovery URL: ".concat(host));
148
148
  return false;
149
149
  }
@@ -70,7 +70,7 @@ class CodeExecutorContext {
70
70
  * @return A list of input files in the code executor context.
71
71
  */
72
72
  getInputFiles() {
73
- if (!(INPUT_FILE_KEY in this.sessionState)) {
73
+ if (!this.sessionState.has(INPUT_FILE_KEY)) {
74
74
  return [];
75
75
  }
76
76
  return this.sessionState.get(INPUT_FILE_KEY);
@@ -80,13 +80,13 @@ class CodeExecutorContext {
80
80
  * @param inputFiles The input files to add to the session state.
81
81
  */
82
82
  addInputFiles(inputFiles) {
83
- if (!(INPUT_FILE_KEY in this.sessionState)) {
83
+ if (!this.sessionState.has(INPUT_FILE_KEY)) {
84
84
  this.sessionState.set(INPUT_FILE_KEY, []);
85
85
  }
86
86
  this.sessionState.get(INPUT_FILE_KEY).push(...inputFiles);
87
87
  }
88
88
  clearInputFiles() {
89
- if (INPUT_FILE_KEY in this.sessionState) {
89
+ if (this.sessionState.has(INPUT_FILE_KEY)) {
90
90
  this.sessionState.set(INPUT_FILE_KEY, []);
91
91
  }
92
92
  if (PROCESSED_FILE_NAMES_KEY in this.context) {
@@ -99,7 +99,7 @@ class CodeExecutorContext {
99
99
  * @return The error count for the given invocation ID.
100
100
  */
101
101
  getErrorCount(invocationId) {
102
- if (!(ERROR_COUNT_KEY in this.sessionState)) {
102
+ if (!this.sessionState.has(ERROR_COUNT_KEY)) {
103
103
  return 0;
104
104
  }
105
105
  return this.sessionState.get(ERROR_COUNT_KEY)[invocationId] || 0;
@@ -109,7 +109,7 @@ class CodeExecutorContext {
109
109
  * @param invocationId The invocation ID to increment the error count for.
110
110
  */
111
111
  incrementErrorCount(invocationId) {
112
- if (!(ERROR_COUNT_KEY in this.sessionState)) {
112
+ if (!this.sessionState.has(ERROR_COUNT_KEY)) {
113
113
  this.sessionState.set(ERROR_COUNT_KEY, {});
114
114
  }
115
115
  this.sessionState.get(ERROR_COUNT_KEY)[invocationId] = this.getErrorCount(invocationId) + 1;
@@ -119,7 +119,7 @@ class CodeExecutorContext {
119
119
  * @param invocationId The invocation ID to reset the error count for.
120
120
  */
121
121
  resetErrorCount(invocationId) {
122
- if (!(ERROR_COUNT_KEY in this.sessionState)) {
122
+ if (!this.sessionState.has(ERROR_COUNT_KEY)) {
123
123
  return;
124
124
  }
125
125
  const errorCounts = this.sessionState.get(ERROR_COUNT_KEY);
@@ -141,7 +141,7 @@ class CodeExecutorContext {
141
141
  resultStdout,
142
142
  resultStderr
143
143
  }) {
144
- if (!(CODE_EXECUTION_RESULTS_KEY in this.sessionState)) {
144
+ if (!this.sessionState.has(CODE_EXECUTION_RESULTS_KEY)) {
145
145
  this.sessionState.set(CODE_EXECUTION_RESULTS_KEY, {});
146
146
  }
147
147
  const codeExecutionResults = this.sessionState.get(
@@ -31,6 +31,7 @@ import { SequentialAgent, isSequentialAgent } from "./agents/sequential_agent.js
31
31
  import { InMemoryArtifactService } from "./artifacts/in_memory_artifact_service.js";
32
32
  import { AuthCredentialTypes } from "./auth/auth_credential.js";
33
33
  import { AuthHandler } from "./auth/auth_handler.js";
34
+ import { AUTH_PREPROCESSOR, AuthPreprocessor } from "./auth/auth_preprocessor.js";
34
35
  import { AuthProviderRegistry } from "./auth/auth_provider_registry.js";
35
36
  import { OAuthGrantType } from "./auth/auth_schemes.js";
36
37
  import { InMemoryCredentialService } from "./auth/credential_service/in_memory_credential_service.js";
@@ -111,20 +112,37 @@ import { URL_CONTEXT, UrlContextTool } from "./tools/url_context_tool.js";
111
112
  import { VertexAiSearchTool } from "./tools/vertex_ai_search_tool.js";
112
113
  import { VertexRagRetrievalTool } from "./tools/vertex_rag_retrieval_tool.js";
113
114
  import { LogLevel, getLogger, setLogLevel, setLogger } from "./utils/logger.js";
114
- import { isGemini2OrAbove } from "./utils/model_name.js";
115
+ import { isGemini2OrAbove, isGemini3xFlashLive } from "./utils/model_name.js";
115
116
  import { zodObjectToSchema } from "./utils/simple_zod_to_json.js";
116
117
  import { GoogleLLMVariant } from "./utils/variant_utils.js";
117
118
  import { version } from "./version.js";
119
+ import { GCPSkillRegistry } from "./skills/gcp_skill_registry.js";
120
+ import {
121
+ loadAllSkillsInDir,
122
+ loadSkillFromDir,
123
+ loadSkillFromZipBuffer,
124
+ validateSkillDir
125
+ } from "./skills/loader.js";
118
126
  import { ListSkillsTool } from "./tools/skill/list_skills_tool.js";
119
127
  import { LoadSkillResourceTool } from "./tools/skill/load_skill_resource_tool.js";
120
128
  import { LoadSkillTool } from "./tools/skill/load_skill_tool.js";
129
+ import { SearchSkillsTool } from "./tools/skill/search_skills_tool.js";
121
130
  import { SkillToolset } from "./tools/skill/skill_toolset.js";
131
+ import { OpenApiSpecParser } from "./tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js";
132
+ import { OperationParser } from "./tools/openapi_tool/openapi_spec_parser/operation_parser.js";
133
+ import { ToolAuthHandler } from "./tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js";
134
+ import { OpenAPIToolset } from "./tools/openapi_tool/openapi_toolset.js";
135
+ import {
136
+ RestApiTool,
137
+ createRestApiTool
138
+ } from "./tools/openapi_tool/rest_api_tool.js";
122
139
  export * from "./artifacts/base_artifact_service.js";
123
140
  export * from "./features/feature_registry.js";
124
141
  export * from "./memory/base_memory_service.js";
125
142
  export * from "./sessions/base_session_service.js";
126
143
  export * from "./tools/base_tool.js";
127
144
  export {
145
+ AUTH_PREPROCESSOR,
128
146
  ActiveStreamingTool,
129
147
  LlmAgent as Agent,
130
148
  AgentTool,
@@ -132,6 +150,7 @@ export {
132
150
  ApigeeLlm,
133
151
  AuthCredentialTypes,
134
152
  AuthHandler,
153
+ AuthPreprocessor,
135
154
  AuthProviderRegistry,
136
155
  BaseAgent,
137
156
  BaseCodeExecutor,
@@ -157,6 +176,7 @@ export {
157
176
  ExitLoopTool,
158
177
  FileContentEncoding,
159
178
  FunctionTool,
179
+ GCPSkillRegistry,
160
180
  GOOGLE_MAPS_GROUNDING,
161
181
  GOOGLE_SEARCH,
162
182
  Gemini,
@@ -188,6 +208,9 @@ export {
188
208
  OAuth2CredentialExchanger,
189
209
  OAuth2DiscoveryManager,
190
210
  OAuthGrantType,
211
+ OpenAPIToolset,
212
+ OpenApiSpecParser,
213
+ OperationParser,
191
214
  PRELOAD_MEMORY,
192
215
  ParallelAgent,
193
216
  PluginManager,
@@ -195,9 +218,11 @@ export {
195
218
  PreloadMemoryTool,
196
219
  REQUEST_CONFIRMATION_FUNCTION_CALL_NAME,
197
220
  ReadonlyContext,
221
+ RestApiTool,
198
222
  RoutedAgent,
199
223
  RoutedLlm,
200
224
  Runner,
225
+ SearchSkillsTool,
201
226
  SecurityPlugin,
202
227
  SequentialAgent,
203
228
  SessionStateCredentialService,
@@ -205,6 +230,7 @@ export {
205
230
  State,
206
231
  StreamingMode,
207
232
  TokenBasedContextCompactor,
233
+ ToolAuthHandler,
208
234
  ToolConfirmation,
209
235
  TruncatingContextCompactor,
210
236
  URL_CONTEXT,
@@ -214,6 +240,7 @@ export {
214
240
  VertexRagRetrievalTool,
215
241
  createEvent,
216
242
  createEventActions,
243
+ createRestApiTool,
217
244
  createSession,
218
245
  functionsExportedForTestingOnly,
219
246
  geminiInitParams,
@@ -232,16 +259,21 @@ export {
232
259
  isFinalResponse,
233
260
  isFunctionTool,
234
261
  isGemini2OrAbove,
262
+ isGemini3xFlashLive,
235
263
  isLlmAgent,
236
264
  isLoopAgent,
237
265
  isParallelAgent,
238
266
  isRoutedAgent,
239
267
  isRunner,
240
268
  isSequentialAgent,
269
+ loadAllSkillsInDir,
270
+ loadSkillFromDir,
271
+ loadSkillFromZipBuffer,
241
272
  setLogLevel,
242
273
  setLogger,
243
274
  stringifyContent,
244
275
  toStructuredEvents,
276
+ validateSkillDir,
245
277
  version,
246
278
  zodObjectToSchema
247
279
  };
@@ -13,10 +13,21 @@ import {
13
13
  import { stringifyContent } from "../../events/event.js";
14
14
  const DEFAULT_PROMPT = "The following is a conversation history between a user and an AI agent. Please summarize the conversation, focusing on key information and decisions made, as well as any unresolved questions or tasks. The summary should be concise and capture the essence of the interaction.";
15
15
  class LlmSummarizer {
16
+ /**
17
+ * @param options - Configuration specifying the LLM and optional prompt.
18
+ */
16
19
  constructor(options) {
17
20
  this.llm = options.llm;
18
21
  this.prompt = options.prompt || DEFAULT_PROMPT;
19
22
  }
23
+ /**
24
+ * Summarizes a list of events into a single {@link CompactedEvent} using the
25
+ * configured LLM.
26
+ *
27
+ * @param events - The events to summarize. Must be non-empty.
28
+ * @returns A promise resolving to the compacted representation.
29
+ * @throws {Error} If `events` is empty or the LLM returns no content.
30
+ */
20
31
  async summarize(events) {
21
32
  var _a, _b, _c, _d, _e, _f;
22
33
  if (events.length === 0) {
@@ -75,7 +75,7 @@ class TokenBasedContextCompactor {
75
75
  compactedEvent.actions = {
76
76
  stateDelta: {},
77
77
  artifactDelta: {},
78
- requestedAuthConfigs: [],
78
+ requestedAuthConfigs: {},
79
79
  requestedToolConfirmations: {}
80
80
  };
81
81
  }
@@ -38,7 +38,7 @@ function createEvent(params = {}) {
38
38
  });
39
39
  }
40
40
  function isFinalResponse(event) {
41
- if (event.actions.skipSummarization || event.longRunningToolIds && event.longRunningToolIds.length > 0) {
41
+ if (event.actions.skipSummarization || event.longRunningToolIds && event.longRunningToolIds.length > 0 || event.actions.requestedAuthConfigs && Object.keys(event.actions.requestedAuthConfigs).length > 0) {
42
42
  return true;
43
43
  }
44
44
  return getFunctionCalls(event).length === 0 && getFunctionResponses(event).length === 0 && !event.partial && !hasTrailingCodeExecutionResult(event);
@@ -31,6 +31,19 @@ import {
31
31
  import { MCPTool } from "../../tools/mcp/mcp_tool.js";
32
32
  import { GCP_MCP_SERVER_DESTINATION_ID } from "./types.js";
33
33
  class AgentRegistrySingleMCPToolset extends BaseToolset {
34
+ /**
35
+ * @param options - Configuration for the MCP toolset.
36
+ * @param options.destinationResourceId - Telemetry identifier injected as
37
+ * `gcp.mcp.server.destination.id` into each resolved tool's custom metadata.
38
+ * @param options.connectionParams - HTTP connection parameters for the MCP server.
39
+ * @param options.toolFilter - Optional predicate or list of tool names to include.
40
+ * When omitted, all tools from the server are returned.
41
+ * @param options.prefix - Optional prefix prepended to each tool name (e.g. `myServer_toolName`).
42
+ * @param options.headerProvider - Optional async function called immediately before each
43
+ * {@link getTools} invocation to supply or refresh request headers (e.g. GCP auth tokens).
44
+ * @param options.authScheme - Optional auth scheme forwarded to each resolved tool.
45
+ * @param options.authCredential - Optional credential forwarded to each resolved tool.
46
+ */
34
47
  constructor(options) {
35
48
  super(options.toolFilter || [], options.prefix);
36
49
  this.destinationResourceId = options.destinationResourceId;
@@ -40,8 +53,14 @@ class AgentRegistrySingleMCPToolset extends BaseToolset {
40
53
  this.authCredential = options.authCredential;
41
54
  }
42
55
  /**
43
- * Connects to the underlying MCP server, retrieves tool definitions, prefixes tool names,
44
- * and injects destination telemetry metadata.
56
+ * Connects to the underlying MCP server, retrieves tool definitions, prefixes
57
+ * tool names, and injects destination telemetry metadata into each tool.
58
+ *
59
+ * The `headerProvider`, if configured, is invoked immediately before the
60
+ * connection is established so that tokens are always fresh.
61
+ *
62
+ * @param context - Optional readonly agent context passed to the header provider.
63
+ * @returns The resolved and optionally filtered list of {@link MCPTool} instances.
45
64
  */
46
65
  async getTools(context) {
47
66
  var _a, _b, _c;